atheros5000: reverted 54902 as requested
[AROS.git] / workbench / devs / networks / atheros5000 / hal / linux / ah_osdep.h
blobd0c361e1a52f2212b8b0e1013305d393a0789253
1 /*
2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2008 Atheros Communications, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * $Id$
19 #ifndef _ATH_AH_OSDEP_H_
20 #define _ATH_AH_OSDEP_H_
22 * Atheros Hardware Access Layer (HAL) OS Dependent Definitions.
26 * Starting with 2.6.4 the kernel supports a configuration option
27 * to pass parameters in registers. If this is enabled we must
28 * mark all function interfaces in+out of the HAL to pass parameters
29 * on the stack as this is the convention used internally (for
30 * maximum portability).
32 #ifdef CONFIG_REGPARM
33 #define __ahdecl __attribute__((regparm(0)))
34 #else
35 #define __ahdecl
36 #endif
37 #ifndef __packed
38 #define __packed __attribute__((__packed__))
39 #endif
42 * Beware of these being mismatched against the contents of <linux/types.h>
44 #ifndef _LINUX_TYPES_H
45 /* NB: arm defaults to unsigned so be explicit */
46 typedef signed char int8_t;
47 typedef short int16_t;
48 typedef int int32_t;
49 typedef long long int64_t;
51 typedef unsigned char uint8_t;
52 typedef unsigned short uint16_t;
53 typedef unsigned int uint32_t;
54 typedef unsigned long long uint64_t;
56 typedef unsigned int size_t;
57 typedef unsigned int u_int;
58 typedef void *va_list;
59 #endif
62 * Linux/BSD gcc compatibility shims.
64 #define __printflike(_a,_b) \
65 __attribute__ ((__format__ (__printf__, _a, _b)))
66 #define __va_list va_list
67 #define OS_INLINE __inline
70 * Delay n microseconds.
72 extern void __ahdecl ath_hal_delay(int);
73 #define OS_DELAY(_n) ath_hal_delay(_n)
75 #define OS_MEMZERO(_a, _n) ath_hal_memzero((_a), (_n))
76 extern void __ahdecl ath_hal_memzero(void *, size_t);
77 #define OS_MEMCPY(_d, _s, _n) ath_hal_memcpy(_d,_s,_n)
78 extern void * __ahdecl ath_hal_memcpy(void *, const void *, size_t);
80 #ifndef abs
81 #define abs(_a) __builtin_abs(_a)
82 #endif
84 struct ath_hal;
85 extern uint32_t __ahdecl ath_hal_getuptime(struct ath_hal *);
86 #define OS_GETUPTIME(_ah) ath_hal_getuptime(_ah)
89 * Byte order/swapping support.
91 #define AH_LITTLE_ENDIAN 1234
92 #define AH_BIG_ENDIAN 4321
94 #ifndef AH_BYTE_ORDER
96 * When the .inc file is not available (e.g. when building
97 * in a kernel source tree); look for some other way to
98 * setup the host byte order.
100 #ifdef __LITTLE_ENDIAN
101 #define AH_BYTE_ORDER AH_LITTLE_ENDIAN
102 #endif
103 #ifdef __BIG_ENDIAN
104 #define AH_BYTE_ORDER AH_BIG_ENDIAN
105 #endif
106 #ifndef AH_BYTE_ORDER
107 #error "Do not know host byte order"
108 #endif
109 #endif /* AH_BYTE_ORDER */
111 #if AH_BYTE_ORDER == AH_BIG_ENDIAN
113 * This could be optimized but since we only use it for
114 * a few registers there's little reason to do so.
116 static __inline__ uint32_t
117 __bswap32(uint32_t _x)
119 return ((uint32_t)(
120 (((const uint8_t *)(&_x))[0] ) |
121 (((const uint8_t *)(&_x))[1]<< 8) |
122 (((const uint8_t *)(&_x))[2]<<16) |
123 (((const uint8_t *)(&_x))[3]<<24))
126 #else
127 #define __bswap32(_x) (_x)
128 #endif
131 * Register read/write; we assume the registers will always
132 * be memory-mapped. Note that register accesses are done
133 * using target-specific functions when debugging is enabled
134 * (AH_DEBUG) or we are explicitly configured this way. The
135 * latter is used on some platforms where the full i/o space
136 * cannot be directly mapped.
138 * The hardware registers are native little-endian byte order.
139 * Big-endian hosts are handled by enabling hardware byte-swap
140 * of register reads and writes at reset. But the PCI clock
141 * domain registers are not byte swapped! Thus, on big-endian
142 * platforms we have to byte-swap thoese registers specifically.
143 * Most of this code is collapsed at compile time because the
144 * register values are constants.
146 #if AH_BYTE_ORDER == AH_BIG_ENDIAN
147 #define OS_REG_UNSWAPPED(_reg) \
148 (((_reg) >= 0x4000 && (_reg) < 0x5000) || \
149 ((_reg) >= 0x7000 && (_reg) < 0x8000))
150 #define _OS_REG_WRITE(_ah, _reg, _val) do { \
151 if (OS_REG_UNSWAPPED(_reg)) \
152 *((volatile uint32_t *)((_ah)->ah_sh + (_reg))) = \
153 __bswap32((_val)); \
154 else \
155 *((volatile uint32_t *)((_ah)->ah_sh + (_reg))) = (_val); \
156 } while (0)
157 #define _OS_REG_READ(_ah, _reg) \
158 (OS_REG_UNSWAPPED(_reg) ? \
159 __bswap32(*((volatile uint32_t *)((_ah)->ah_sh + (_reg)))) : \
160 *((volatile uint32_t *)((_ah)->ah_sh + (_reg))))
161 #else /* AH_LITTLE_ENDIAN */
162 #define OS_REG_UNSWAPPED(_reg) (0)
163 #define _OS_REG_WRITE(_ah, _reg, _val) do { \
164 *((volatile uint32_t *)((_ah)->ah_sh + (_reg))) = (_val); \
165 } while (0)
166 #define _OS_REG_READ(_ah, _reg) \
167 *((volatile uint32_t *)((_ah)->ah_sh + (_reg)))
168 #endif /* AH_BYTE_ORDER */
170 #if defined(AH_DEBUG) || defined(AH_REGOPS_FUNC) || defined(AH_DEBUG_ALQ)
171 /* use functions to do register operations */
172 #define OS_REG_WRITE(_ah, _reg, _val) ath_hal_reg_write(_ah, _reg, _val)
173 #define OS_REG_READ(_ah, _reg) ath_hal_reg_read(_ah, _reg)
175 extern void __ahdecl ath_hal_reg_write(struct ath_hal *ah,
176 u_int reg, uint32_t val);
177 extern uint32_t __ahdecl ath_hal_reg_read(struct ath_hal *ah, u_int reg);
178 #else
179 /* inline register operations */
180 #define OS_REG_WRITE(_ah, _reg, _val) _OS_REG_WRITE(_ah, _reg, _val)
181 #define OS_REG_READ(_ah, _reg) _OS_REG_READ(_ah, _reg)
182 #endif /* AH_DEBUG || AH_REGFUNC || AH_DEBUG_ALQ */
184 #ifdef AH_DEBUG_ALQ
185 extern void __ahdecl OS_MARK(struct ath_hal *, u_int id, uint32_t value);
186 #else
187 #define OS_MARK(_ah, _id, _v)
188 #endif
191 * Linux-specific attach/detach methods needed for module reference counting.
193 * XXX We can't use HAL_STATUS because the type isn't defined at this
194 * point (circular dependency); we wack the type and patch things
195 * up in the function.
197 * NB: These are intentionally not marked __ahdecl since they are
198 * compiled with the default calling convetion and are not called
199 * from within the HAL.
201 extern struct ath_hal *_ath_hal_attach(uint16_t devid, HAL_SOFTC,
202 HAL_BUS_TAG, HAL_BUS_HANDLE, void* status);
203 extern void ath_hal_detach(struct ath_hal *);
205 #endif /* _ATH_AH_OSDEP_H_ */