⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gen_typs.h

📁 RAID卡的测试程序
💻 H
📖 第 1 页 / 共 2 页
字号:
#if !defined(GEN_DATA_TYPES_H)
#define GEN_DATA_TYPES_H


/** */

/** 
predefined macros:

 Platform definitions:

  Only one (and at least one) of following macros can be defined at the same time.

	_X8616B	
	Specify 16bit x86 platform, this is used for BIOS and DOS utility

	_X8632B
	Specify 32bit x86 platform, this is used for most OS drivers.

	_IA64B
	Specify 64bit IA64 platform, this is used for IA64 OS drivers.

	_AMD64B
	Specify 64bit AMD64 platform, this is used for AMD64 OS drivers.

	_IAEFI
	Specify EFI driver for IA64 (and IA32, if avaible). This is used for EFI BIOS for IA32/64.

 Abstraction definition
	_16BPLATFORM	for all 16 bit platforms, actually we don't support any 16 bit platforms 
					other than 16bit x86 platform now.
	_32BPLATFORM	for all 32 bit platforms, actually we don't support any 32 bit platforms 
					other than 32bit x86 platform now.
	_64BPLATFORM	for all 64 bit platforms, so far we need to support both AMD64 and IA64.

 OS definitions for OS drivers:

  Only one (and at least one) of following macros can be defined at the same time.

	_OS_WINDOWS
	_OS_LINUX
	_OS_FREEBSD

 Add compiler definition here if necessary.
	_COMPILER_GCC_COMPATIBLE
	_COMPILER_MS_C_COMPATIBLE
*/

/********************************************************************************/
/* basic data type definitions */
typedef unsigned char U8;
typedef   signed char I8;

typedef unsigned short U16;
typedef   signed short I16;

#if defined(_OS_LINUX)
#ifndef FREEBSD
	#include <linux/types.h>
#endif
	/** unsigned/signed long is 64bit for AMD64, so use unsigned int instead */
	typedef unsigned int U32;
	//typedef u32 U32;
	typedef   signed int I32;
	//typedef s32 I32;
#else
	/** unsigned/signed long is 32bit for x86, IA64 and AMD64 */
	typedef unsigned long U32;
	typedef   signed long I32;
#endif

#if defined(_OS_WINDOWS)

	typedef unsigned __int64 _U64;
	typedef   signed __int64 _I64;
	#define DT64BSUPPORTED

#elif defined(_OS_LINUX)
	typedef unsigned long long _U64;
	//typedef u64 _U64;
	typedef   signed long long _I64;
	//typedef s64 _I64;
	#define DT64BSUPPORTED
	#define FAR

	#if defined(_X8632B)
	/*
 	* do_div() is NOT a C function. It wants to return
	* two values (the quotient and the remainder), but
	* since that doesn't work very well in C, what it
 	* does is:
 	*
 	* - modifies the 64-bit dividend _in_place_
	* - returns the 32-bit remainder
 	*
 	* This ends up being the most efficient "calling
 	* convention" on x86.
 	*/
	#define do_div(n,base) ({ \
		unsigned long __upper, __low, __high, __mod, __base; \
		__base = (base); \
		asm("":"=a" (__low), "=d" (__high):"A" (n)); \
		__upper = __high; \
		if (__high) { \
			__upper = __high % (__base); \
			__high = __high / (__base); \
		} \
		asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (__base), "0" (__low), "1" (__upper)); \
		asm("":"=A" (n):"a" (__low),"d" (__high)); \
		__mod; \
	})
	#endif
#elif defined(_SHASTAFW)

	typedef unsigned long long _U64;
	typedef   signed long long _I64;
	#define DT64BSUPPORTED

#elif defined(_OS_FREEBSD)

	/** define _U64/_I64/DT64BSUPPORTED if your compiler support 64b integer data type */

#else

	/** define _U64/_I64/DT64BSUPPORTED if your compiler support 64b integer data type */

#endif

#if !defined(DT64BSUPPORTED)

typedef struct {
	U32 Low;
	U32 High;
} U64;

typedef struct {
	U32 Low;
	I32 High;
} I64;

#else	/* !DT64BSUPPORTED */

typedef union {
	struct {
		U32 Low;
		U32 High;
	};
	_U64 Value;
} U64;

typedef union {
	struct {
		U32 Low;
		I32 High;
	};
	_I64 Value;
} I64; /* we should never use I64 though */

#endif /* DT64BSUPPORTED */

/* GEN_FAR is needed by BIOS only */
#if defined(_X8616B)

	#define GEN_FAR  __far		/* GEN_FAR/GEN_NEAR is meaningful for BIOS/DOS APP only */
	#define GEN_NEAR __near

	#define app_space GEN_FAR
	#define buf_space GEN_NEAR
	#define dat_space GEN_NEAR
	#define str_space GEN_FAR

#else
	#define GEN_FAR 
	#define GEN_NEAR
	#define app_space
	#define buf_space
	#define dat_space
	#define str_space

#endif

typedef U8 GEN_FAR* LPU8, GEN_NEAR* PU8, buf_space* bpU8, app_space* apU8, str_space* spU8, dat_space* dpU8;
typedef I8 GEN_FAR* LPI8, GEN_NEAR* PI8, buf_space* bpI8, app_space* apI8, str_space* spI8, dat_space* dpI8;

typedef U16 GEN_FAR* LPU16, GEN_NEAR* PU16, buf_space* bpU16, app_space* apU16, str_space* spU16, dat_space* dpU16;
typedef I16 GEN_FAR* LPI16, GEN_NEAR* PI16, buf_space* bpI16, app_space* apI16, str_space* spI16, dat_space* dpI16;

typedef U32 GEN_FAR* LPU32, GEN_NEAR* PU32, buf_space* bpU32, app_space* apU32, str_space* spU32, dat_space* dpU32;
typedef I32 GEN_FAR* LPI32, GEN_NEAR* PI32, buf_space* bpI32, app_space* apI32, str_space* spI32, dat_space* dpI32;

typedef U64 GEN_FAR* LPU64, GEN_NEAR* PU64, buf_space* bpU64, app_space* apU64, str_space* spU64, dat_space* dpU64;
typedef I64 GEN_FAR* LPI64, GEN_NEAR* PI64, buf_space* bpI64, app_space* apI64, str_space* spI64, dat_space* dpI64;


typedef void GEN_FAR* LPVOID, buf_space* bpVOID, str_space* spVOID, dat_space* dpVOID;

/** 
	if you want to defined pointer determined by compiler mode, just define as DataType instead of
	pre-defined types above. 
 */

#if !defined(NULL)
#define NULL 0
#endif 

/** PTR_SIZE is necessary to convert a pointer to/from integer safely, please always use PTR_SIZE
    to define an integer if you want to save a pointer to this integer. This is important for 32/64
	bit compatibility. */

#if defined(_OS_WINDOWS)
	#if !defined(_W64)
	#define _W64	/* this is defined for Windows 32/64 bit compatible, otherwise MS C/C++ compiler complains... */
	#endif
#endif

#if defined(_64BPLATFORM)
	typedef _U64 PTR_SIZE;
#else
	#if defined(_OS_WINDOWS)
		typedef _W64 U32 PTR_SIZE;
	#else
		typedef unsigned long PTR_SIZE;
	#endif
#endif

typedef U8	ByTE;
typedef U16	HALF;
/* please avoid using WORD since it is conflict with Windows definition */
//typedef U32	WORD;
typedef int	BoOL;

#if !defined(TRUE)
	#define TRUE	1
#endif

#if !defined(FALSE)
	#define FALSE	0
#endif

/** LBA is defined for array level LBA, which should be 64 bit */
typedef U64 LBA;

/** I am struggling if I should define the disk LBA as 32 bit or 64 bit. 32 bit 
    disk LBA is as large as 2TB disk capability which should be enough for several
	years in the future. But ATA spec already defined 48 bit LBA for disk. 
	BIOS can benefit from 32 bit disk LBA since the 16bit compiler doesn't support
	64 bit operation ...
 */
typedef U32 DISKLBA;

/* DIMMADDR is actually an offset into DIMM */
typedef U32 DIMMADDR;

#if defined(_X8616B)
	/* 32 bit physical address should be appropriate for BIOS/DOS APP */
	typedef U32 PHYADDR;
#else
	/* for 32/64 bit OS, we will define PHYADDR as 64 bit */
	typedef U64 PHYADDR;
#endif

#if !defined(IN)
#define IN
#endif

#if !defined(OUT)
#define OUT
#endif

#if !defined(OPTIONAL)
#define OPTIONAL
#endif


/* End of basic data type definitions */
/********************************************************************************/

/********************************************************************************/
/**
	Hardware independent SG format. PBM/Raid Engine/DM will all operate on this format.
	CAM should translate it into HW compliant format.
 */
struct _SG32;
typedef struct _SG32 SG32, buf_space* bpSG32;

struct _SG64;
typedef struct _SG64 SG64, buf_space* bpSG64;

/* Please note that the 1st byte of _SGxx is always the control flag byte. It is important
   for this so we can know if it is a 32 bit or 64 bit SG format. */
struct _SG32
{
	U8 CtrlFlag;	/* see below SG_CF_xxx */
	U8 Reserved[3];	/* it is extended to be used as high 8 bit of a 24 bit Count */
	U32 Count;
	U32 StartAddress;
};

struct _SG64
{
	U8 CtrlFlag;	/* see below SG_CF_xxx */
	U8 Reserved[3];
	U32 Count;
	U64 StartAddress;
};

#if defined(_X8616B) || defined(SIMULATE_BIOS_ENV) || defined(__CC_ARM) //|| defined(_SHASTAFW) || defined(NAPA_MARVELL)
#define USE_32BIT_SG_DEFAULT
#endif

/** Things becoming complex if we support mixed SG32 and SG64...
	finally I decided BIOS to use SG32 format and driver use SG64 exclusively. */

#if defined(USE_32BIT_SG_DEFAULT)
	/* BIOS/DOSAPP will use 32 bit SG format */
	typedef SG32 SG;
	#define SG_CF_DEFAULT 0
	#define SG_ASSIGN_STARTADDRESS(StartAddress,Addr) ((StartAddress) = (U32)(Addr))
	#define SG_STARTADDRESS(StartAddress)	(StartAddress)
#else /* !_X8616B */
	/* otherwise we will use 64 bit SG format for convinience */
	typedef SG64 SG;
	#define SG_CF_DEFAULT SG_CF_64B
	#define SG_STARTADDRESS(StartAddress)	((StartAddress).Value)
	#define SG_ASSIGN_STARTADDRESS(StartAddress,Addr) ((StartAddress).Value = (_U64)(Addr))
#endif /* _X8616B */

typedef SG buf_space *bpSG, str_space *spSG;

/* SG table definition */
struct _SGTABLE;
typedef struct _SGTABLE SGTABLE, buf_space* bpSGTABLE;

#if !defined(MAX_SG_ITEM_PER_TABLE)
/* MAX_SG_ITEM_PER_TABLE can be override in cfg_xxx.h */
#if defined(_X8616B) || defined(SIMULATE_BIOS_ENV)
#define MAX_SG_ITEM_PER_TABLE	4	/* can be even smaller? */
#else
#define MAX_SG_ITEM_PER_TABLE	32
#endif

#endif	/*MAX_SG_ITEM_PER_TABLE*/

struct _SGTABLE
{
	/* actual SG item count, of course, you can get the count 
	   by enumerating the table, but it's convinient to have a count here... */
	U16 SGCount;

	/* you can define your own SG table to save memory, just set 
	   MaxSGCount correctly. */
	U16 MaxSGCount; 

	/* indicates size in byte */
	U32 SizeInByte;

	SG table[MAX_SG_ITEM_PER_TABLE];
};

/* you can use SGTABLE_SIZE to calculate memory requirement if you want to 
   define a non-standard SG table */
#define SGTABLE_SIZE(itemCount) ((itemCount)*sizeof(SG) + OFFSET_OF(SGTABLE,table))

#define SG_CF_EOT	0x80	/* End of table */
#define SG_CF_64B	0x40	/* 64 bit format item */
#define SG_CF_HOST	0x20	/* address in the SG is in host address space */
#define SG_CF_RAW	0x10	/* The address in the SG is un-translated, CAM needs to translate it before passing it to ASIC */
#define SG_CF_DMA	0x08

#define EndOfSgTable(pSg)		(*((U8*)(pSg))&SG_CF_EOT)
#define MarkEndOfSgTable(pSg)	(*((U8*)(pSg))|=SG_CF_EOT)
#define ClearEndOfSgTable(pSg)	(*((U8*)(pSg))&=(~SG_CF_EOT))
#define SGTableGetSG(pTbl)		((pTbl)->table)
/**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -