Identify subversion snapshots as being from trunk
[madwifi/.git] / ath_hal / ah_os.h
1 /*-
2  * Copyright (c) 2002-2006 Sam Leffler, Errno Consulting
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  * 3. Neither the names of the above-listed copyright holders nor the names
16  *    of any contributors may be used to endorse or promote products derived
17  *    from this software without specific prior written permission.
18  *
19  * Alternatively, this software may be distributed under the terms of the
20  * GNU General Public License ("GPL") version 2 as published by the Free
21  * Software Foundation.
22  *
23  * NO WARRANTY
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
27  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
29  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
32  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34  * THE POSSIBILITY OF SUCH DAMAGES.
35  *
36  * $Id$
37  */
38 #ifndef _ATH_AH_OS_H_
39 #define _ATH_AH_OS_H_
40
41 /*
42  * Atheros Hardware Access Layer (HAL) OS Dependent Definitions.
43  */
44
45 /*
46    MadWifi safe register operations:
47
48         When hacking on registers directly, we need to use the macros below to
49         avoid concurrent PCI access and abort mode errors.
50
51         * ath_reg_read
52         * ATH_REG_WRITE
53
54    HAL-ONLY register operations:
55
56         * _OS_REG_READ
57         * _OS_REG_WRITE
58         * OS_REG_READ
59         * OS_REG_WRITE
60         * ath_hal_reg_read.
61         * ath_hal_reg_write
62
63     When compiled in HAL:
64         * We don't require locking overhead and function call except for
65           debugging.
66         * All HAL operations are executed in the context of a MadWifi wrapper
67           call that holds the HAL lock.
68         * Normally HAL is built with the non-modified version of this file, so
69           it doesn't have our funny macros anyway.
70
71     When compiled in MadWifi:
72         * The HAL wrapper API takes the HAL lock before invoking the HAL.
73         * HAL access is already protected, and MadWifi must NOT access the
74           functions listed above.
75 */
76
77 /*
78  * When building the HAL proper, we use no GPL-licensed include files and must
79  * define Linux types ourselves.  Please note that the definitions below don't
80  * exactly match those in <linux/types.h>
81  */
82 #ifndef _LINUX_TYPES_H
83 /* NB: ARM defaults to unsigned, so be explicit */
84 typedef signed char             int8_t;
85 typedef short                   int16_t;
86 typedef int                     int32_t;
87 typedef long long               int64_t;
88
89 typedef unsigned char           u_int8_t;
90 typedef unsigned short          u_int16_t;
91 typedef unsigned int            u_int32_t;
92 typedef unsigned long long      u_int64_t;
93
94 typedef unsigned int            size_t;
95 typedef unsigned int            u_int;
96 typedef void*                   va_list;
97 #endif                          /* !_LINUX_TYPES_H */
98
99 struct ath_hal;
100
101 extern int ath_hal_dma_beacon_response_time;
102 extern int ath_hal_sw_beacon_response_time;
103 extern int ath_hal_additional_swba_backoff;
104
105 void __ahdecl ath_hal_printf(struct ath_hal *ah, HAL_BOOL prefer_alq, const char *fmt, ...)
106         __attribute__ ((__format__ (__printf__, 3, 4)));
107 #ifdef AH_DEBUG_ALQ
108 void __ahdecl ath_hal_logprintf(struct ath_hal *ah, const char *fmt, ...)
109         __attribute__ ((__format__ (__printf__, 2, 3)));
110 #endif
111
112 int __ahdecl ath_hal_memcmp(const void *a, const void *b, size_t n);
113 void *__ahdecl ath_hal_malloc(size_t size);
114 void __ahdecl ath_hal_free(void *p);
115
116 #ifndef abs
117 #define abs(_a)                 __builtin_abs(_a)
118 #endif
119
120 #ifndef labs
121 #define labs(_a)                __builtin_labs(_a)
122 #endif
123
124 /* XXX: This should be stored per-device for proper multi-radio support */
125 extern const char *ath_hal_func;
126 extern const char *ath_hal_device;
127 extern int ath_hal_debug;
128 static inline void ath_hal_set_function(const char *name)
129 {
130 #ifdef AH_DEBUG
131         ath_hal_func = name;
132 #endif
133 }
134 static inline void ath_hal_set_device(const char *name)
135 {
136 #ifdef AH_DEBUG
137         ath_hal_device = name;
138 #endif
139 }
140
141 /*
142  * Linux-specific attach/detach methods needed for module reference counting.
143  *
144  * NB: These are intentionally not marked __ahdecl since they are
145  *     compiled with the default calling convention and are not called
146  *     from within the HAL.
147  */
148 extern struct ath_hal *_ath_hal_attach(u_int16_t devid, HAL_SOFTC,
149                                        HAL_BUS_TAG, HAL_BUS_HANDLE,
150                                        HAL_STATUS *);
151 extern void _ath_hal_detach(struct ath_hal *);
152
153 void
154 ath_hal_print_decoded_register(struct ath_hal *ah, 
155                                const char *device_name,
156                                u_int32_t address, u_int32_t oldval, 
157                                u_int32_t newval, HAL_BOOL bitfields);
158 void
159 ath_hal_print_register(struct ath_hal *ah, 
160                                const char *device_name,
161                                u_int32_t address, u_int32_t value);
162
163 HAL_BOOL
164 ath_hal_lookup_register_name(struct ath_hal *ah, char *buf, int buflen, 
165                 u_int32_t address);
166
167 #endif                          /* _ATH_AH_OSDEP_H_ */
168