comdef.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #ifndef _COMDEF_H_
  2. #define _COMDEF_H_
  3. typedef unsigned char UINT8;
  4. typedef unsigned char UCHAR;
  5. typedef unsigned short UINT16;
  6. typedef unsigned int UINT32;
  7. typedef unsigned short int WCHAR;
  8. typedef unsigned short int UNICODE;
  9. typedef unsigned long UINT64;
  10. typedef int INT64;
  11. typedef int INT32;
  12. typedef short int INT16;
  13. typedef char INT8;
  14. typedef char CHAR;
  15. typedef unsigned short int bool;
  16. typedef unsigned short int STATUS_T;
  17. typedef signed char s8;
  18. typedef unsigned char u8;
  19. typedef signed short s16;
  20. typedef unsigned short u16;
  21. typedef signed int s32;
  22. typedef unsigned int u32;
  23. typedef unsigned long u64;
  24. //typedef int ssize_t;
  25. typedef unsigned char uint8_t;
  26. typedef unsigned short uint16_t;
  27. typedef unsigned int uint32_t;
  28. typedef unsigned long uintptr_t;
  29. typedef unsigned long uint64_t;
  30. typedef signed long s64;
  31. typedef unsigned long size_t;
  32. #define NULL 0
  33. #define FALSE 0
  34. #define TRUE 1
  35. #define typeof __typeof__
  36. #define ARCH_DMA_MINALIGN 32
  37. #define BIT_0 0x00000001
  38. #define BIT_1 0x00000002
  39. #define BIT_2 0x00000004
  40. #define BIT_3 0x00000008
  41. #define BIT_4 0x00000010
  42. #define BIT_5 0x00000020
  43. #define BIT_6 0x00000040
  44. #define BIT_7 0x00000080
  45. #define BIT_8 0x00000100
  46. #define BIT_9 0x00000200
  47. #define BIT_10 0x00000400
  48. #define BIT_11 0x00000800
  49. #define BIT_12 0x00001000
  50. #define BIT_13 0x00002000
  51. #define BIT_14 0x00004000
  52. #define BIT_15 0x00008000
  53. #define BIT_16 0x00010000
  54. #define BIT_17 0x00020000
  55. #define BIT_18 0x00040000
  56. #define BIT_19 0x00080000
  57. #define BIT_20 0x00100000
  58. #define BIT_21 0x00200000
  59. #define BIT_22 0x00400000
  60. #define BIT_23 0x00800000
  61. #define BIT_24 0x01000000
  62. #define BIT_25 0x02000000
  63. #define BIT_26 0x04000000
  64. #define BIT_27 0x08000000
  65. #define BIT_28 0x10000000
  66. #define BIT_29 0x20000000
  67. #define BIT_30 0x40000000
  68. #define BIT_31 0x80000000
  69. #define RSP_SUCCESS 0
  70. #define RSP_GENERAL_FAIL 1
  71. #ifndef BIT
  72. #define BIT(x) (1UL << (x))
  73. #endif
  74. #ifndef writeq
  75. static inline void writeq(u64 val, volatile void *addr)
  76. {
  77. asm volatile("sd %0, 0(%1)" : : "r" (val), "r" (addr));
  78. }
  79. #endif
  80. #ifndef readq
  81. static inline u64 readq(volatile void *addr)
  82. {
  83. u64 val;
  84. asm volatile("ld %0, 0(%1)" : "=r" (val) : "r" (addr));
  85. return val;
  86. }
  87. #endif
  88. #ifndef writel
  89. static inline void writel(u32 val, volatile void *addr)
  90. {
  91. asm volatile("sw %0, 0(%1)" : : "r" (val), "r" (addr));
  92. }
  93. #endif
  94. #ifndef readl
  95. static inline u32 readl(volatile void *addr)
  96. {
  97. u32 val;
  98. asm volatile("lw %0, 0(%1)" : "=r" (val) : "r" (addr));
  99. return val;
  100. }
  101. #endif
  102. #ifndef writew
  103. static inline void writew(u16 val, volatile void *addr)
  104. {
  105. asm volatile("sh %0, 0(%1)" : : "r" (val), "r" (addr));
  106. }
  107. #endif
  108. #ifndef readw
  109. static inline u16 readw(const volatile void *addr)
  110. {
  111. u16 val;
  112. asm volatile("lh %0, 0(%1)" : "=r" (val) : "r" (addr));
  113. return val;
  114. }
  115. #endif
  116. #define inpb(port) (*((volatile UINT8 *) (port)))
  117. #define inph(port) (*((volatile UINT16*) (port)))
  118. #define inpw(port) (*((volatile UINT32*) (port)))
  119. #define outpb(port, val) (*((volatile UINT8 *) (port)) = ((UINT8 ) (val)))
  120. #define outph(port, val) (*((volatile UINT16*) (port)) = ((UINT16) (val)))
  121. #define outpw(port, val) (*((volatile UINT32*) (port)) = ((UINT32) (val)))
  122. #define MA_INB( io ) (UINT8 ) inpb( io )
  123. #define MA_INH( io ) (UINT16) inph( io )
  124. #define MA_INW( io ) (UINT32) inpw( io )
  125. #define MA_INBM( io, mask ) ( inpb( io ) & (mask) )
  126. #define MA_INHM( io, mask ) ( inph( io ) & (mask) )
  127. #define MA_INWM( io, mask ) ( inpw( io ) & (mask) )
  128. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  129. /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */
  130. #define roundup(x, y) ( \
  131. { \
  132. const typeof(y) __y = y; \
  133. (((x) + (__y - 1)) / __y) * __y; \
  134. } \
  135. )
  136. #define LOG2(x) (((x & 0xaaaaaaaa) ? 1 : 0) + ((x & 0xcccccccc) ? 2 : 0) + \
  137. ((x & 0xf0f0f0f0) ? 4 : 0) + ((x & 0xff00ff00) ? 8 : 0) + \
  138. ((x & 0xffff0000) ? 16 : 0))
  139. #define ___swab32(x) \
  140. ((u32)( \
  141. (((u32)(x) & (u32)0x000000ffUL) << 24) | \
  142. (((u32)(x) & (u32)0x0000ff00UL) << 8) | \
  143. (((u32)(x) & (u32)0x00ff0000UL) >> 8) | \
  144. (((u32)(x) & (u32)0xff000000UL) >> 24) ))
  145. #define __be32_to_cpu(x) ___swab32((u32)(x))
  146. #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  147. #define MA_OUTB( io, val )\
  148. {\
  149. outpb( io, val );\
  150. }
  151. #define MA_OUTH( io, val )\
  152. {\
  153. outph( io, val );\
  154. }
  155. #define MA_OUTW( io, val )\
  156. {\
  157. outpw( io, val );\
  158. }
  159. #define MA_OUTBM( io, mask, val ) \
  160. {\
  161. UINT8 temp;\
  162. (temp) =(((MA_INW(io) & (UINT8)(~(mask))) | ((UINT8)((val) & (mask)))));\
  163. outpb( io, temp );\
  164. }
  165. #define MA_OUTHM( io, mask, val ) \
  166. {\
  167. UINT16 temp;\
  168. (temp) =(((MA_INH(io) & (UINT16)(~(mask))) |((UINT16)((val) & (mask)))));\
  169. outph( io, temp );\
  170. }
  171. #define MA_OUTWM( io, mask, val ) \
  172. {\
  173. UINT32 temp;\
  174. (temp) =(((MA_INW(io) & (UINT32)(~(mask))) |((UINT32)((val) & (mask)))));\
  175. outpw( io, temp );\
  176. }
  177. #define min(x,y) ((x)<(y)?(x):(y))
  178. #define min3(x, y, z) min(min(x, y), z)
  179. #define max(x, y) ((x)>(y)?(x):(y))
  180. #define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1))
  181. #define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1)
  182. #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
  183. #define PAD_COUNT(s, pad) (((s) - 1) / (pad) + 1)
  184. #define PAD_SIZE(s, pad) (PAD_COUNT(s, pad) * pad)
  185. #define ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, pad) \
  186. char __##name[ROUND(PAD_SIZE((size) * sizeof(type), pad), align) \
  187. + (align - 1)]; \
  188. \
  189. type *name = (type *)ALIGN((uintptr_t)__##name, align)
  190. #define ALLOC_ALIGN_BUFFER(type, name, size, align) \
  191. ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, 1)
  192. #define ALLOC_CACHE_ALIGN_BUFFER_PAD(type, name, size, pad) \
  193. ALLOC_ALIGN_BUFFER_PAD(type, name, size, ARCH_DMA_MINALIGN, pad)
  194. #define ALLOC_CACHE_ALIGN_BUFFER(type, name, size) \
  195. ALLOC_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
  196. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  197. static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
  198. {
  199. *remainder = dividend % divisor;
  200. return dividend / divisor;
  201. }
  202. #ifndef false
  203. #define false (0)
  204. #endif
  205. #ifndef true
  206. #define true (1)
  207. #endif
  208. #endif