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