| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bgio_macro.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/2 $ |
|---|
| 12 | * $brcm_Date: 1/24/05 12:00p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * |
|---|
| 17 | * Revision History: |
|---|
| 18 | * $brcm_Log: /magnum/portinginterface/gio/7038/bgio_macro.h $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/2 1/24/05 12:00p syang |
|---|
| 21 | * PR 10548: fix a compiler warning |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/1 2/20/04 11:23a syang |
|---|
| 24 | * PR 9785: init version |
|---|
| 25 | * |
|---|
| 26 | ***************************************************************************/ |
|---|
| 27 | |
|---|
| 28 | #ifndef BGIO_MACRO_H__ |
|---|
| 29 | #define BGIO_MACRO_H__ |
|---|
| 30 | |
|---|
| 31 | #ifdef __cplusplus |
|---|
| 32 | extern "C" { |
|---|
| 33 | #endif |
|---|
| 34 | |
|---|
| 35 | /*************************************************************************** |
|---|
| 36 | * {private} |
|---|
| 37 | * |
|---|
| 38 | */ |
|---|
| 39 | |
|---|
| 40 | /* This macro take the check for a validity of a handle, and |
|---|
| 41 | * cast to context pointer. |
|---|
| 42 | */ |
|---|
| 43 | #define BGIO_GENERIC_GET_CONTEXT(handle, context, structname) \ |
|---|
| 44 | { \ |
|---|
| 45 | if(!(handle) || \ |
|---|
| 46 | (((structname*)(handle))->ulBlackMagic != \ |
|---|
| 47 | (sizeof(structname) & 0xbac98800))) \ |
|---|
| 48 | { \ |
|---|
| 49 | BDBG_ERR(("NULL context handle\n")); \ |
|---|
| 50 | (context) = NULL; \ |
|---|
| 51 | } \ |
|---|
| 52 | else \ |
|---|
| 53 | { \ |
|---|
| 54 | (context) = (handle); \ |
|---|
| 55 | } \ |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | /* This macro set the black magic for later handle validation |
|---|
| 59 | */ |
|---|
| 60 | #define BGIO_GENERIC_SET_BLACK_MAGIC(handle, structname) \ |
|---|
| 61 | { \ |
|---|
| 62 | ((structname*)(handle))->ulBlackMagic = sizeof(structname) & 0xbac98800; \ |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | /* This macro shred the garbage for BKNI managed buffer |
|---|
| 66 | */ |
|---|
| 67 | #if BDBG_DEBUG_BUILD |
|---|
| 68 | #define BGIO_GENERIC_DESTROY_CONTEXT(struct_ptr, structname) \ |
|---|
| 69 | { \ |
|---|
| 70 | BKNI_Memset((void*)struct_ptr, 0xA3, sizeof(structname)); \ |
|---|
| 71 | BKNI_Free((void*)struct_ptr); \ |
|---|
| 72 | /*(void*)struct_ptr = NULL;*/ \ |
|---|
| 73 | } |
|---|
| 74 | #else |
|---|
| 75 | #define BGIO_GENERIC_DESTROY_CONTEXT(struct_ptr, structname) \ |
|---|
| 76 | { \ |
|---|
| 77 | BKNI_Free((void*)struct_ptr); \ |
|---|
| 78 | } |
|---|
| 79 | #endif |
|---|
| 80 | |
|---|
| 81 | #define BGIO_RETURN_IF_ERR(result) \ |
|---|
| 82 | if ( BERR_SUCCESS != (result)) \ |
|---|
| 83 | {\ |
|---|
| 84 | return BERR_TRACE(result); \ |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | #define BGIO_END_IF_ERR(success, result, label) \ |
|---|
| 88 | if ( false == (success) ) \ |
|---|
| 89 | {\ |
|---|
| 90 | eResult = BERR_TRACE(result); \ |
|---|
| 91 | goto (label); \ |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | #ifdef __cplusplus |
|---|
| 95 | } |
|---|
| 96 | #endif |
|---|
| 97 | |
|---|
| 98 | #endif /* #ifndef BGIO_MACRO_H__ */ |
|---|
| 99 | |
|---|
| 100 | /* end of file */ |
|---|