/* Header file for porting cdbc to new platforms/os. This file is owned by the OS/driver module and can be customized. Various definitions defined through this file is used by the core dump parser to interract with the OS/driver module. */ #ifndef _CDBC_DEFS_ #define _CDBC_DEFS_ #include #include #include /* * Core Dump byte code parser should be customized using the following defines. */ #define CDBC_CFG_CPU_LITTLE_ENDIAN (1) /* Set this if the CPU is little endian */ #define CDBC_CFG_DEBUG_BUILD (1) /* set this for debug build, cdbc will produce some debug info */ #if defined(__x86_64__) || defined(__aarch64__) # define CDBC_CFG_SYSTEM_64BIT (1) /* set this if this is a 64-bit build and pointers are 64 bit */ #else # define CDBC_CFG_SYSTEM_64BIT (0) /* set this if this is a 64-bit build and pointers are 64 bit */ #endif /* * Following are data types used by the core dump parser. The data types * are abstracted using the following to make this code platform and compiler * independent */ /* Define 8 bit data types and their pointers */ typedef char CDBC_S8, *PCDBC_S8; typedef unsigned char CDBC_U8, *PCDBC_U8; /* Define 16 bit data types and their pointers */ typedef short CDBC_S16, *PCDBC_S16; typedef unsigned short CDBC_U16, *PCDBC_U16; /* Define 32 bit data types and their pointers */ typedef int CDBC_S32, *PCDBC_S32; typedef unsigned CDBC_U32, *PCDBC_U32; /* Define 64 bit data types and their pointers */ /* * 64-bit data types have been introduced in C for some time now * (See ISO C99 Section 6.10.8). We are using it so that we can * use compiler and CPU enhancements in handling 64-bit data instead * of handling multiple 32-bit data types in our code. This may be * a problem if this code needs to be compiled under an old compiler * that does not support a native 64-bit data type (embedded platforms). */ typedef int64_t CDBC_S64, *PCDBC_S64; typedef uint64_t CDBC_U64, *PCDBC_U64; /* * types that are 32-bit on 32 bit platforms and 64-bit on 64-bit * platforms */ typedef intptr_t CDBC_SPTR, *PCDBC_SPTR; typedef uintptr_t CDBC_UPTR, *PCDBC_UPTR; /* Define double and float data types and their pointers */ /* Not supported: CDBC will not use these data types. typedef double CDBC_DOUBLE, *PCDBC_DOUBLE; typedef float CDBC_FLOAT, *PCDBC_FLOAT; */ #if CDBC_CFG_SYSTEM_64BIT == 1 // // for 64 bit system it is 64 bit // typedef CDBC_S64 CDBC_PTR; /* Size of a pointer on given platform */ #else//#if CDBC_CFG_SYSTEM_64BIT == 0 // // for 32 bit system it is one ulong size // typedef CDBC_S32 CDBC_PTR; /* Size of a pointer on given platform */ #endif//#else CDBC_CFG_SYSTEM_64BIT == 1 typedef void CDBC_VOID, *PCDBC_VOID; #define CDBC_NULL ((PCDBC_VOID)0) /* Only to be used with pointers data types */ /* Boolean definitions */ #define CDBC_TRUE (1) #define CDBC_FALSE (0) /* Compiler intrinsic functions, these may be mapped to OSM desired locations */ #define CDBC_MEMSET memset #define CDBC_MEMCPY memcpy #define CDBC_MEMCMP memcmp /* Debug support */ #if CDBC_CFG_DEBUG_BUILD #define OS_ASSERT(_CONDITION_, _MESSAGE_) if(!(_CONDITION_)) os_assert(_MESSAGE_, __LINE__, __FILE__) #else /* CDBC_CFG_DEBUG_BUILD */ #define OS_ASSERT #endif /* CDBC_CFG_DEBUG_BUILD */ /* * Provide OS specific routines for use by core dump parser. The core dump * parser will call these routines as necessary. */ /* * Following routines are used to read and write BAR space. * BAR # is provided with each call. * Example for BE3: BAR # 0 is mirror of PCI CFG space. * Example for BE3: BAR # 1 is CSR space. * Example for BE3: BAR # 2 is doorbell space. */ #define OS_BAR_READ8(ctx, ...) os_bar_read8(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) #define OS_BAR_READ16(ctx, ...) os_bar_read16(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) #define OS_BAR_READ32(ctx, ...) os_bar_read32(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) #define OS_BAR_WRITE8(ctx, ...) os_bar_write8(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) #define OS_BAR_WRITE16(ctx, ...) os_bar_write16(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) #define OS_BAR_WRITE32(ctx, ...) os_bar_write32(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) /* * Following routines are used to read and write PCI Config space. */ #define OS_CFG_READ8(ctx, ...) os_cfg_read8(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) #define OS_CFG_READ16(ctx, ...) os_cfg_read16(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) #define OS_CFG_READ32(ctx, ...) os_cfg_read32(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) #define OS_CFG_WRITE8(ctx, ...) os_cfg_write8(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) #define OS_CFG_WRITE16(ctx, ...) os_cfg_write16(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) #define OS_CFG_WRITE32(ctx, ...) os_cfg_write32(((PCDBC_CONTEXT)ctx)->osContext, ##__VA_ARGS__) /* * Following routines are used to write data dump generated by the * core dump parser. A offset is reported at each write. OS should * write provided data to the IOCTL buffer provided to extract the * specific segment. */ #define OS_DUMP_WRITE8 os_dump_write8 #define OS_DUMP_WRITE16 os_dump_write16 #define OS_DUMP_WRITE32 os_dump_write32 /* * Following routines are used to stall the processor for a specified * amount of time, this is used to implement timing specific hardware * read/write */ #define OS_STALL os_stall /* * Endian macros */ /* Endian byte swapping macros */ #define CDBC_SWAP16(data) (CDBC_UEXACT16) ( \ (((CDBC_UEXACT16)data & 0x00FF) << 8) | \ (((CDBC_UEXACT16)data & 0xFF00) >> 8) ) #define CDBC_SWAP24(data) (CDBC_UEXACT32) ( \ (((CDBC_UEXACT32)data & 0x000000FF) << 16) | \ (((CDBC_UEXACT32)data & 0x0000FF00) ) | \ (((CDBC_UEXACT32)data & 0x00FF0000) >> 16) ) #define CDBC_SWAP32(data) (CDBC_UEXACT32) ( \ (((CDBC_UEXACT32)data & 0x000000FF) << 24) | \ (((CDBC_UEXACT32)data & 0x0000FF00) << 8) | \ (((CDBC_UEXACT32)data & 0x00FF0000) >> 8) | \ (((CDBC_UEXACT32)data & 0xFF000000) >> 24) ) #define CDBC_SWAP64(data) (CDBC_U64) ( \ (((CDBC_U64)data & 0x00000000000000FF) << 56) | \ (((CDBC_U64)data & 0x000000000000FF00) << 40) | \ (((CDBC_U64)data & 0x0000000000FF0000) << 24) | \ (((CDBC_U64)data & 0x00000000FF000000) << 8) | \ (((CDBC_U64)data & 0x000000FF00000000) >> 8) | \ (((CDBC_U64)data & 0x0000FF0000000000) >> 24) | \ (((CDBC_U64)data & 0x00FF000000000000) >> 40) | \ (((CDBC_U64)data & 0xFF00000000000000) >> 56) ) #if CDBC_CFG_CPU_LITTLE_ENDIAN /* Endian store macros */ #define CDBC_PUT_LE8(newval, oldval) \ newval = (CDBC_UEXACT8)(oldval) #define CDBC_PUT_LE16(newval, oldval) \ newval = (CDBC_UEXACT16)(oldval) #define CDBC_PUT_LE32(newval, oldval) \ newval = (CDBC_UEXACT32)(oldval) #define CDBC_PUT_LE64(newval, oldval) \ newval = (CDBC_UEXACT64)(oldval) #define CDBC_PUT_BE8(newval, oldval) \ newval = (CDBC_UEXACT8)oldval #define CDBC_PUT_BE16(newval, oldval) \ newval = CDBC_SWAP16(oldval) #define CDBC_PUT_BE32(newval, oldval) \ newval = CDBC_SWAP32(oldval) #define CDBC_PUT_BE64(newval, oldval) \ newval = CDBC_SWAP64(oldval) /* Endian load macros */ #define CDBC_GET_LE8(plocation) \ *((PCDBC_UEXACT8) (plocation)) #define CDBC_GET_LE16(plocation) \ *((PCDBC_UEXACT16) (plocation)) #define CDBC_GET_LE32(plocation) \ *((PCDBC_UEXACT32) (plocation)) #define CDBC_GET_LE64(plocation) \ *((PCDBC_UEXACT64) (plocation)) #define CDBC_GET_BE8(plocation) \ *((PCDBC_UEXACT8) (plocation)) #define CDBC_GET_BE16(plocation) \ CDBC_SWAP16(*((PCDBC_UEXACT16) (plocation))) #define CDBC_GET_BE32(plocation) \ CDBC_SWAP32(*((PCDBC_UEXACT32) (plocation))) #define CDBC_GET_BE64(plocation) \ CDBC_SWAP64(*((PCDBC_UEXACT64) (plocation))) #elif CDBC_CFG_CPU_BIG_ENDIAN #error "Unsupported get/set endian macros" #endif typedef struct _CDBC_BAR{ PCDBC_VOID VABase; CDBC_U32 Length; } CDBC_BAR, *PCDBC_BAR; #define CDBC_BAR_NUM_MAX 3 typedef struct _CDBC_CONTEXT{ PVOID osContext; // Context passed to cfg/bar helper functions CDBC_BAR BarArray[CDBC_BAR_NUM_MAX]; CDBC_U32 Offset; CDBC_U32 Length; PCDBC_VOID Buffer; CDBC_U32 Written; } CDBC_CONTEXT, *PCDBC_CONTEXT; #ifdef __cplusplus extern "C" { #endif CDBC_VOID os_bar_read8(PCDBC_VOID ctx, CDBC_U32 bar, CDBC_U32 offset, PCDBC_U32 pdata); CDBC_VOID os_bar_read16(PCDBC_VOID ctx, CDBC_U32 bar, CDBC_U32 offset, PCDBC_U32 pdata); CDBC_VOID os_bar_read32(PCDBC_VOID ctx, CDBC_U32 bar, CDBC_U32 offset, PCDBC_U32 pdata); CDBC_VOID os_bar_write8(PCDBC_VOID ctx, CDBC_U32 bar, CDBC_U32 offset, CDBC_U32 data); CDBC_VOID os_bar_write16(PCDBC_VOID ctx, CDBC_U32 bar, CDBC_U32 offset, CDBC_U32 data); CDBC_VOID os_bar_write32(PCDBC_VOID ctx, CDBC_U32 bar, CDBC_U32 offset, CDBC_U32 data); CDBC_VOID os_cfg_read8(PCDBC_VOID ctx, CDBC_U32 offset, PCDBC_U32 pdata); CDBC_VOID os_cfg_read16(PCDBC_VOID ctx, CDBC_U32 offset, PCDBC_U32 pdata); CDBC_VOID os_cfg_read32(PCDBC_VOID ctx, CDBC_U32 offset, PCDBC_U32 pdata); CDBC_VOID os_cfg_write8(PCDBC_VOID ctx, CDBC_U32 offset, CDBC_U32 data); CDBC_VOID os_cfg_write16(PCDBC_VOID ctx, CDBC_U32 offset, CDBC_U32 data); CDBC_VOID os_cfg_write32(PCDBC_VOID ctx, CDBC_U32 offset, CDBC_U32 data); CDBC_VOID os_dump_write8(PCDBC_VOID ctx, CDBC_U32 offset, CDBC_U32 data); CDBC_VOID os_dump_write16(PCDBC_VOID ctx, CDBC_U32 offset, CDBC_U32 data); CDBC_VOID os_dump_write32(PCDBC_VOID ctx, CDBC_U32 offset, CDBC_U32 data); CDBC_VOID os_assert(PCDBC_S8 Message, CDBC_U32 Line, PCDBC_S8 File); CDBC_VOID os_stall(PCDBC_VOID ctx, CDBC_U32 time); #ifdef __cplusplus } #endif #endif /* _CDBC_DEFS_ */