Main Page | Data Structures | Directories | File List | Data Fields | Globals

ah_osdep.h

Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 2002-2004 Sam Leffler, Errno Consulting, Atheros
00003  * Communications, Inc.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms are permitted
00006  * provided that the following conditions are met:
00007  * 1. The materials contained herein are unmodified and are used
00008  *    unmodified.
00009  * 2. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following NO
00011  *    ''WARRANTY'' disclaimer below (''Disclaimer''), without
00012  *    modification.
00013  * 3. Redistributions in binary form must reproduce at minimum a
00014  *    disclaimer similar to the Disclaimer below and any redistribution
00015  *    must be conditioned upon including a substantially similar
00016  *    Disclaimer requirement for further binary redistribution.
00017  * 4. Neither the names of the above-listed copyright holders nor the
00018  *    names of any contributors may be used to endorse or promote
00019  *    product derived from this software without specific prior written
00020  *    permission.
00021  *
00022  * NO WARRANTY
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  * ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT,
00026  * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00027  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
00028  * FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00030  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00033  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00034  * SUCH DAMAGES.
00035  *
00036  * $Id: ah_osdep.h,v 1.3 2005/02/22 19:07:25 jbicket Exp $
00037  */
00038 #ifndef _ATH_AH_OSDEP_H_
00039 #define _ATH_AH_OSDEP_H_
00040 /*
00041  * Atheros Hardware Access Layer (HAL) OS Dependent Definitions.
00042  */
00043 
00044 /*
00045  * Starting with 2.6.4 the kernel supports a configuration option
00046  * to pass parameters in registers.  If this is enabled we must
00047  * mark all function interfaces in+out of the HAL to pass parameters
00048  * on the stack as this is the convention used internally (for
00049  * maximum portability).
00050  */
00051 #ifdef CONFIG_REGPARM
00052 #define __ahdecl        __attribute__((regparm(0)))
00053 #else
00054 #define __ahdecl
00055 #endif
00056 #ifndef __packed
00057 #define __packed        __attribute__((__packed__))
00058 #endif
00059 
00060 /*
00061  * When building the HAL proper we use no GPL-contaminated include
00062  * files and must define these types ourself.  Beware of these being
00063  * mismatched against the contents of <linux/types.h>
00064  */
00065 #ifndef _LINUX_TYPES_H
00066 /* NB: arm defaults to unsigned so be explicit */
00067 typedef signed char int8_t;
00068 typedef short int16_t;
00069 typedef int int32_t;
00070 typedef long long int64_t;
00071 
00072 typedef unsigned char u_int8_t;
00073 typedef unsigned short u_int16_t;
00074 typedef unsigned int u_int32_t;
00075 typedef unsigned long long u_int64_t;
00076 
00077 typedef unsigned int size_t;
00078 typedef unsigned int u_int;
00079 typedef void *va_list;
00080 #endif
00081 
00082 /*
00083  * Linux/BSD gcc compatibility shims.
00084  */
00085 #define __printflike(_a,_b) \
00086         __attribute__ ((__format__ (__printf__, _a, _b)))
00087 #define __va_list       va_list 
00088 #define OS_INLINE       __inline
00089 
00090 typedef void* HAL_SOFTC;
00091 typedef int HAL_BUS_TAG;
00092 typedef void* HAL_BUS_HANDLE;
00093 typedef u_int32_t HAL_BUS_ADDR;                 /* XXX architecture dependent */
00094 
00095 /*
00096  * Delay n microseconds.
00097  */
00098 extern  void __ahdecl ath_hal_delay(int);
00099 #define OS_DELAY(_n)    ath_hal_delay(_n)
00100 
00101 #define OS_MEMZERO(_a, _n)      ath_hal_memzero((_a), (_n))
00102 extern void __ahdecl ath_hal_memzero(void *, size_t);
00103 #define OS_MEMCPY(_d, _s, _n)   ath_hal_memcpy(_d,_s,_n)
00104 extern void * __ahdecl ath_hal_memcpy(void *, const void *, size_t);
00105 
00106 #ifndef abs
00107 #define abs(_a)         __builtin_abs(_a)
00108 #endif
00109 
00110 struct ath_hal;
00111 extern  u_int32_t __ahdecl ath_hal_getuptime(struct ath_hal *);
00112 #define OS_GETUPTIME(_ah)       ath_hal_getuptime(_ah)
00113 
00114 /*
00115  * Byte order/swapping support.
00116  */
00117 #define AH_LITTLE_ENDIAN        1234
00118 #define AH_BIG_ENDIAN           4321
00119 
00120 #if AH_BYTE_ORDER == AH_BIG_ENDIAN
00121 /*
00122  * This could be optimized but since we only use it for
00123  * a few registers there's little reason to do so.
00124  */
00125 static inline u_int32_t
00126 __bswap32(u_int32_t _x)
00127 {
00128         return ((u_int32_t)(
00129               (((const u_int8_t *)(&_x))[0]    ) |
00130               (((const u_int8_t *)(&_x))[1]<< 8) |
00131               (((const u_int8_t *)(&_x))[2]<<16) |
00132               (((const u_int8_t *)(&_x))[3]<<24))
00133         );
00134 }
00135 #else
00136 #define __bswap32(_x)   (_x)
00137 #endif
00138 
00139 /*
00140  * Register read/write; we assume the registers will always
00141  * be memory-mapped.  Note that register accesses are done
00142  * using target-specific functions when debugging is enabled
00143  * (AH_DEBUG) or we are explicitly configured this way.  The
00144  * latter is used on some platforms where the full i/o space
00145  * cannot be directly mapped.
00146  *
00147  * The hardware registers are native little-endian byte order.
00148  * Big-endian hosts are handled by enabling hardware byte-swap
00149  * of register reads and writes at reset.  But the PCI clock
00150  * domain registers are not byte swapped!  Thus, on big-endian
00151  * platforms we have to byte-swap thoese registers specifically.
00152  * Most of this code is collapsed at compile time because the
00153  * register values are constants.
00154  */
00155 #if AH_BYTE_ORDER == AH_BIG_ENDIAN
00156 #define _OS_REG_WRITE(_ah, _reg, _val) do {                                 \
00157         if ( (_reg) >= 0x4000 && (_reg) < 0x5000)                           \
00158                 *((volatile u_int32_t *)((_ah)->ah_sh + (_reg))) =          \
00159                         __bswap32((_val));                                  \
00160         else                                                                \
00161                 *((volatile u_int32_t *)((_ah)->ah_sh + (_reg))) = (_val);  \
00162 } while (0)
00163 #define _OS_REG_READ(_ah, _reg) \
00164         (((_reg) >= 0x4000 && (_reg) < 0x5000) ? \
00165                 __bswap32(*((volatile u_int32_t *)((_ah)->ah_sh + (_reg)))) : \
00166                 *((volatile u_int32_t *)((_ah)->ah_sh + (_reg))))
00167 #else /* AH_LITTLE_ENDIAN */
00168 #define _OS_REG_WRITE(_ah, _reg, _val) do { \
00169         *((volatile u_int32_t *)((_ah)->ah_sh + (_reg))) = (_val); \
00170 } while (0)
00171 #define _OS_REG_READ(_ah, _reg) \
00172         *((volatile u_int32_t *)((_ah)->ah_sh + (_reg)))
00173 #endif /* AH_BYTE_ORDER */
00174 
00175 #if defined(AH_DEBUG) || defined(AH_REGOPS_FUNC) || defined(AH_DEBUG_ALQ)
00176 /* use functions to do register operations */
00177 #define OS_REG_WRITE(_ah, _reg, _val)   ath_hal_reg_write(_ah, _reg, _val)
00178 #define OS_REG_READ(_ah, _reg)          ath_hal_reg_read(_ah, _reg)
00179 
00180 extern  void __ahdecl ath_hal_reg_write(struct ath_hal *ah,
00181                 u_int reg, u_int32_t val);
00182 extern  u_int32_t __ahdecl ath_hal_reg_read(struct ath_hal *ah, u_int reg);
00183 #else
00184 /* inline register operations */
00185 #define OS_REG_WRITE(_ah, _reg, _val)   _OS_REG_WRITE(_ah, _reg, _val)
00186 #define OS_REG_READ(_ah, _reg)          _OS_REG_READ(_ah, _reg)
00187 #endif /* AH_DEBUG || AH_REGFUNC || AH_DEBUG_ALQ */
00188 
00189 #ifdef AH_DEBUG_ALQ
00190 extern  void __ahdecl OS_MARK(struct ath_hal *, u_int id, u_int32_t value);
00191 #else
00192 #define OS_MARK(_ah, _id, _v)
00193 #endif
00194 
00195 /*
00196  * Linux-specific attach/detach methods needed for module reference counting.
00197  *
00198  * XXX We can't use HAL_STATUS because the type isn't defined at this
00199  *     point (circular dependency); we wack the type and patch things
00200  *     up in the function.
00201  *
00202  * NB: These are intentionally not marked __ahdecl since they are
00203  *     compiled with the default calling convetion and are not called
00204  *     from within the HAL.
00205  */
00206 extern  struct ath_hal *_ath_hal_attach(u_int16_t devid, HAL_SOFTC,
00207                 HAL_BUS_TAG, HAL_BUS_HANDLE, void* status);
00208 extern  void ath_hal_detach(struct ath_hal *);
00209 
00210 #endif /* _ATH_AH_OSDEP_H_ */

Generated on Mon Nov 21 15:58:09 2005 for openwifi by  doxygen 1.4.1