ah_osdep.h revision 1.1 1 1.1 alc /*-
2 1.1 alc * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 1.1 alc * All rights reserved.
4 1.1 alc *
5 1.1 alc * Redistribution and use in source and binary forms, with or without
6 1.1 alc * modification, are permitted provided that the following conditions
7 1.1 alc * are met:
8 1.1 alc * 1. Redistributions of source code must retain the above copyright
9 1.1 alc * notice, this list of conditions and the following disclaimer,
10 1.1 alc * without modification.
11 1.1 alc * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 1.1 alc * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 1.1 alc * redistribution must be conditioned upon including a substantially
14 1.1 alc * similar Disclaimer requirement for further binary redistribution.
15 1.1 alc *
16 1.1 alc * NO WARRANTY
17 1.1 alc * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 1.1 alc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 1.1 alc * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 1.1 alc * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 1.1 alc * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 1.1 alc * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 1.1 alc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 1.1 alc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 1.1 alc * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 1.1 alc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 1.1 alc * THE POSSIBILITY OF SUCH DAMAGES.
28 1.1 alc *
29 1.1 alc * $Id: ah_osdep.h,v 1.1 2008/12/11 05:37:40 alc Exp $
30 1.1 alc */
31 1.1 alc
32 1.1 alc #ifndef _ATH_AH_OSDEP_H_
33 1.1 alc #define _ATH_AH_OSDEP_H_
34 1.1 alc /*
35 1.1 alc * Atheros Hardware Access Layer (HAL) OS Dependent Definitions.
36 1.1 alc */
37 1.1 alc #include <sys/param.h>
38 1.1 alc #include <sys/systm.h>
39 1.1 alc #include <sys/endian.h>
40 1.1 alc #include <sys/bus.h>
41 1.1 alc
42 1.1 alc #include <machine/stdarg.h>
43 1.1 alc
44 1.1 alc /*
45 1.1 alc * Delay n microseconds.
46 1.1 alc */
47 1.1 alc extern void ath_hal_delay(int);
48 1.1 alc #define OS_DELAY(_n) ath_hal_delay(_n)
49 1.1 alc
50 1.1 alc #define OS_INLINE __inline
51 1.1 alc #define OS_MEMZERO(_a, _n) ath_hal_memzero((_a), (_n))
52 1.1 alc extern void ath_hal_memzero(void *, size_t);
53 1.1 alc #define OS_MEMCPY(_d, _s, _n) ath_hal_memcpy(_d,_s,_n)
54 1.1 alc extern void *ath_hal_memcpy(void *, const void *, size_t);
55 1.1 alc
56 1.1 alc #define abs(_a) __builtin_abs(_a)
57 1.1 alc
58 1.1 alc struct ath_hal;
59 1.1 alc extern u_int32_t ath_hal_getuptime(struct ath_hal *);
60 1.1 alc #define OS_GETUPTIME(_ah) ath_hal_getuptime(_ah)
61 1.1 alc
62 1.1 alc /*
63 1.1 alc * WiSoC boards overload the bus tag with information about the
64 1.1 alc * board layout. We must extract the bus space tag from that
65 1.1 alc * indirect structure. For everyone else the tag is passed in
66 1.1 alc * directly.
67 1.1 alc * XXX cache indirect ref privately
68 1.1 alc */
69 1.1 alc #ifdef AH_SUPPORT_AR5312
70 1.1 alc #define BUSTAG(ah) \
71 1.1 alc ((bus_space_tag_t) ((struct ar531x_config *)((ah)->ah_st))->tag)
72 1.1 alc #define BUSHANDLE(ah) ((bus_space_handle_t)((ah)->ah_sh))
73 1.1 alc
74 1.1 alc #elif defined(AH_REGOPS_FUNC)
75 1.1 alc #define BUSTAG(ah) (*(bus_space_tag_t *) (ah)->ah_st)
76 1.1 alc #define BUSHANDLE(ah) (*(bus_space_handle_t *)((ah)->ah_sh))
77 1.1 alc #define HALTAG(t) (HAL_BUS_TAG) &(t)
78 1.1 alc #define HALHANDLE(h) (HAL_BUS_HANDLE) &(h)
79 1.1 alc #else
80 1.1 alc #define BUSTAG(ah) ((bus_space_tag_t) (ah)->ah_st)
81 1.1 alc #define BUSHANDLE(ah) ((bus_space_handle_t) ((ah)->ah_sh))
82 1.1 alc #define HALTAG(t) (HAL_BUS_TAG) (t)
83 1.1 alc #define HALHANDLE(h) (HAL_BUS_HANDLE) (h)
84 1.1 alc #endif
85 1.1 alc
86 1.1 alc /*
87 1.1 alc * Register read/write; we assume the registers will always
88 1.1 alc * be memory-mapped. Note that register accesses are done
89 1.1 alc * using target-specific functions when debugging is enabled
90 1.1 alc * (ATHHAL_DEBUG) or we are explicitly configured this way. The
91 1.1 alc * latter is used on some platforms where the full i/o space
92 1.1 alc * cannot be directly mapped.
93 1.1 alc */
94 1.1 alc #if defined(ATHHAL_DEBUG) || defined(AH_REGOPS_FUNC) || defined(ATHHAL_DEBUG_ALQ)
95 1.1 alc #define OS_REG_WRITE(_ah, _reg, _val) ath_hal_reg_write(_ah, _reg, _val)
96 1.1 alc #define OS_REG_READ(_ah, _reg) ath_hal_reg_read(_ah, _reg)
97 1.1 alc
98 1.1 alc extern void ath_hal_reg_write(struct ath_hal *ah, u_int reg, u_int32_t val);
99 1.1 alc extern u_int32_t ath_hal_reg_read(struct ath_hal *ah, u_int reg);
100 1.1 alc #else
101 1.1 alc /*
102 1.1 alc * The hardware registers are native little-endian byte order.
103 1.1 alc * Big-endian hosts are handled by enabling hardware byte-swap
104 1.1 alc * of register reads and writes at reset. But the PCI clock
105 1.1 alc * domain registers are not byte swapped! Thus, on big-endian
106 1.1 alc * platforms we have to byte-swap thoese registers specifically.
107 1.1 alc * Most of this code is collapsed at compile time because the
108 1.1 alc * register values are constants.
109 1.1 alc */
110 1.1 alc #define AH_LITTLE_ENDIAN 1234
111 1.1 alc #define AH_BIG_ENDIAN 4321
112 1.1 alc
113 1.1 alc #if _BYTE_ORDER == _BIG_ENDIAN
114 1.1 alc #define OS_REG_WRITE(_ah, _reg, _val) do { \
115 1.1 alc if ( (_reg) >= 0x4000 && (_reg) < 0x5000) \
116 1.1 alc bus_space_write_4((_ah)->ah_st, (_ah)->ah_sh, \
117 1.1 alc (_reg), (_val)); \
118 1.1 alc else \
119 1.1 alc bus_space_write_stream_4((_ah)->ah_st, (_ah)->ah_sh, \
120 1.1 alc (_reg), (_val)); \
121 1.1 alc } while (0)
122 1.1 alc #define OS_REG_READ(_ah, _reg) \
123 1.1 alc (((_reg) >= 0x4000 && (_reg) < 0x5000) ? \
124 1.1 alc bus_space_read_4((_ah)->ah_st, (_ah)->ah_sh, (_reg)) : \
125 1.1 alc bus_space_read_stream_4((_ah)->ah_st, (_ah)->ah_sh, (_reg)))
126 1.1 alc #else /* _BYTE_ORDER == _LITTLE_ENDIAN */
127 1.1 alc #define OS_REG_WRITE(_ah, _reg, _val) \
128 1.1 alc bus_space_write_4((_ah)->ah_st, (_ah)->ah_sh, (_reg), (_val))
129 1.1 alc #define OS_REG_READ(_ah, _reg) \
130 1.1 alc ((u_int32_t) bus_space_read_4((_ah)->ah_st, (_ah)->ah_sh, (_reg)))
131 1.1 alc #endif /* _BYTE_ORDER */
132 1.1 alc #endif /* ATHHAL_DEBUG || AH_REGFUNC || ATHHAL_DEBUG_ALQ */
133 1.1 alc
134 1.1 alc #ifdef ATHHAL_DEBUG_ALQ
135 1.1 alc extern void OS_MARK(struct ath_hal *, u_int id, u_int32_t value);
136 1.1 alc #else
137 1.1 alc #define OS_MARK(_ah, _id, _v)
138 1.1 alc #endif
139 1.1 alc
140 1.1 alc typedef void * HAL_SOFTC; /* pointer to driver/OS state */
141 1.1 alc typedef bus_space_tag_t HAL_BUS_TAG; /* opaque bus i/o id tag */
142 1.1 alc typedef bus_space_handle_t HAL_BUS_HANDLE; /* opaque bus i/o handle */
143 1.1 alc
144 1.1 alc #define OS_SET_DECLARE(set, ptype) __link_set_decl(set, ptype)
145 1.1 alc #define OS_DATA_SET(set, sym) __link_set_add_rodata(set, sym)
146 1.1 alc #define OS_SET_FOREACH(pvar, set) __link_set_foreach(pvar, set)
147 1.1 alc
148 1.1 alc #define __bswap16(x) bswap16(x)
149 1.1 alc #define __bswap32(x) bswap32(x)
150 1.1 alc
151 1.1 alc #endif /* _ATH_AH_OSDEP_H_ */
152