1572ff6f6SMatthew Dillon /*- 2572ff6f6SMatthew Dillon * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting 3572ff6f6SMatthew Dillon * All rights reserved. 4572ff6f6SMatthew Dillon * 5572ff6f6SMatthew Dillon * Redistribution and use in source and binary forms, with or without 6572ff6f6SMatthew Dillon * modification, are permitted provided that the following conditions 7572ff6f6SMatthew Dillon * are met: 8572ff6f6SMatthew Dillon * 1. Redistributions of source code must retain the above copyright 9572ff6f6SMatthew Dillon * notice, this list of conditions and the following disclaimer, 10572ff6f6SMatthew Dillon * without modification. 11572ff6f6SMatthew Dillon * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12572ff6f6SMatthew Dillon * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13572ff6f6SMatthew Dillon * redistribution must be conditioned upon including a substantially 14572ff6f6SMatthew Dillon * similar Disclaimer requirement for further binary redistribution. 15572ff6f6SMatthew Dillon * 16572ff6f6SMatthew Dillon * NO WARRANTY 17572ff6f6SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18572ff6f6SMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19*df052c2aSSascha Wildner * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY 20572ff6f6SMatthew Dillon * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21572ff6f6SMatthew Dillon * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22572ff6f6SMatthew Dillon * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23572ff6f6SMatthew Dillon * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24572ff6f6SMatthew Dillon * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25572ff6f6SMatthew Dillon * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26572ff6f6SMatthew Dillon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27572ff6f6SMatthew Dillon * THE POSSIBILITY OF SUCH DAMAGES. 28572ff6f6SMatthew Dillon * 29572ff6f6SMatthew Dillon * $FreeBSD$ 30572ff6f6SMatthew Dillon */ 31572ff6f6SMatthew Dillon #ifndef _ATH_AH_OSDEP_H_ 32572ff6f6SMatthew Dillon #define _ATH_AH_OSDEP_H_ 33572ff6f6SMatthew Dillon /* 34572ff6f6SMatthew Dillon * Atheros Hardware Access Layer (HAL) OS Dependent Definitions. 35572ff6f6SMatthew Dillon */ 36572ff6f6SMatthew Dillon #include <sys/cdefs.h> 37572ff6f6SMatthew Dillon #include <sys/param.h> 38572ff6f6SMatthew Dillon #include <sys/systm.h> 39572ff6f6SMatthew Dillon #include <sys/endian.h> 40572ff6f6SMatthew Dillon #include <sys/linker_set.h> 41b14ca477SMatthew Dillon 42dc249793SMatthew Dillon #if defined(__DragonFly__) 43dc249793SMatthew Dillon 44dc249793SMatthew Dillon #include <sys/bus.h> 45dc249793SMatthew Dillon 46dc249793SMatthew Dillon #ifndef true 47dc249793SMatthew Dillon #define true 1 48dc249793SMatthew Dillon #endif 49dc249793SMatthew Dillon 50dc249793SMatthew Dillon #ifndef false 51dc249793SMatthew Dillon #define false 0 52dc249793SMatthew Dillon #endif 53dc249793SMatthew Dillon 54dc249793SMatthew Dillon #endif 553133c5e3SMatthew Dillon 56572ff6f6SMatthew Dillon /* 57572ff6f6SMatthew Dillon * Bus i/o type definitions. 58572ff6f6SMatthew Dillon */ 59572ff6f6SMatthew Dillon typedef void *HAL_SOFTC; 60572ff6f6SMatthew Dillon typedef bus_space_tag_t HAL_BUS_TAG; 61572ff6f6SMatthew Dillon typedef bus_space_handle_t HAL_BUS_HANDLE; 62572ff6f6SMatthew Dillon 63572ff6f6SMatthew Dillon /* 64572ff6f6SMatthew Dillon * Although the underlying hardware may support 64 bit DMA, the 65572ff6f6SMatthew Dillon * current Atheros hardware only supports 32 bit addressing. 66572ff6f6SMatthew Dillon */ 67572ff6f6SMatthew Dillon typedef uint32_t HAL_DMA_ADDR; 68572ff6f6SMatthew Dillon 69572ff6f6SMatthew Dillon /* 70572ff6f6SMatthew Dillon * Linker set writearounds for chip and RF backend registration. 71572ff6f6SMatthew Dillon */ 72572ff6f6SMatthew Dillon #define OS_DATA_SET(set, item) DATA_SET(set, item) 73572ff6f6SMatthew Dillon #define OS_SET_DECLARE(set, ptype) SET_DECLARE(set, ptype) 74572ff6f6SMatthew Dillon #define OS_SET_FOREACH(pvar, set) SET_FOREACH(pvar, set) 75572ff6f6SMatthew Dillon 76572ff6f6SMatthew Dillon /* 77572ff6f6SMatthew Dillon * Delay n microseconds. 78572ff6f6SMatthew Dillon */ 79572ff6f6SMatthew Dillon #define OS_DELAY(_n) DELAY(_n) 80572ff6f6SMatthew Dillon 81572ff6f6SMatthew Dillon #define OS_INLINE __inline 82572ff6f6SMatthew Dillon #define OS_MEMZERO(_a, _n) bzero((_a), (_n)) 83572ff6f6SMatthew Dillon #define OS_MEMCPY(_d, _s, _n) memcpy(_d,_s,_n) 84572ff6f6SMatthew Dillon #define OS_MEMCMP(_a, _b, _l) memcmp((_a), (_b), (_l)) 85572ff6f6SMatthew Dillon 86572ff6f6SMatthew Dillon #define abs(_a) __builtin_abs(_a) 87572ff6f6SMatthew Dillon 88572ff6f6SMatthew Dillon struct ath_hal; 89572ff6f6SMatthew Dillon 90572ff6f6SMatthew Dillon /* 91572ff6f6SMatthew Dillon * The hardware registers are native little-endian byte order. 92572ff6f6SMatthew Dillon * Big-endian hosts are handled by enabling hardware byte-swap 93572ff6f6SMatthew Dillon * of register reads and writes at reset. But the PCI clock 94572ff6f6SMatthew Dillon * domain registers are not byte swapped! Thus, on big-endian 95572ff6f6SMatthew Dillon * platforms we have to explicitly byte-swap those registers. 96572ff6f6SMatthew Dillon * OS_REG_UNSWAPPED identifies the registers that need special handling. 97572ff6f6SMatthew Dillon * 98572ff6f6SMatthew Dillon * This is not currently used by the FreeBSD HAL osdep code; the HAL 99572ff6f6SMatthew Dillon * currently does not configure hardware byteswapping for register space 100572ff6f6SMatthew Dillon * accesses and instead does it through the FreeBSD bus space code. 101572ff6f6SMatthew Dillon */ 102572ff6f6SMatthew Dillon #if _BYTE_ORDER == _BIG_ENDIAN 103572ff6f6SMatthew Dillon #define OS_REG_UNSWAPPED(_reg) \ 104572ff6f6SMatthew Dillon (((_reg) >= 0x4000 && (_reg) < 0x5000) || \ 105572ff6f6SMatthew Dillon ((_reg) >= 0x7000 && (_reg) < 0x8000)) 106572ff6f6SMatthew Dillon #else /* _BYTE_ORDER == _LITTLE_ENDIAN */ 107572ff6f6SMatthew Dillon #define OS_REG_UNSWAPPED(_reg) (0) 108572ff6f6SMatthew Dillon #endif /* _BYTE_ORDER */ 109572ff6f6SMatthew Dillon 110572ff6f6SMatthew Dillon /* 111572ff6f6SMatthew Dillon * For USB/SDIO support (where access latencies are quite high); 112572ff6f6SMatthew Dillon * some write accesses may be buffered and then flushed when 113572ff6f6SMatthew Dillon * either a read is done, or an explicit flush is done. 114572ff6f6SMatthew Dillon * 115572ff6f6SMatthew Dillon * These are simply placeholders for now. 116572ff6f6SMatthew Dillon */ 117572ff6f6SMatthew Dillon #define OS_REG_WRITE_BUFFER_ENABLE(_ah) \ 118572ff6f6SMatthew Dillon do { } while (0) 119572ff6f6SMatthew Dillon #define OS_REG_WRITE_BUFFER_DISABLE(_ah) \ 120572ff6f6SMatthew Dillon do { } while (0) 121572ff6f6SMatthew Dillon #define OS_REG_WRITE_BUFFER_FLUSH(_ah) \ 122572ff6f6SMatthew Dillon do { } while (0) 123572ff6f6SMatthew Dillon 124572ff6f6SMatthew Dillon /* 125b14ca477SMatthew Dillon * Read and write barriers. Some platforms require more strongly ordered 126b14ca477SMatthew Dillon * operations and unfortunately most of the HAL is written assuming everything 127b14ca477SMatthew Dillon * is either an x86 or the bus layer will do the barriers for you. 128b14ca477SMatthew Dillon * 129b14ca477SMatthew Dillon * Read barriers should occur before each read, and write barriers 130b14ca477SMatthew Dillon * occur after each write. 131b14ca477SMatthew Dillon * 132b14ca477SMatthew Dillon * Later on for SDIO/USB parts we will methodize this and make them no-ops; 133b14ca477SMatthew Dillon * register accesses will go via USB commands. 134572ff6f6SMatthew Dillon */ 135b14ca477SMatthew Dillon #define OS_BUS_BARRIER_READ BUS_SPACE_BARRIER_READ 136b14ca477SMatthew Dillon #define OS_BUS_BARRIER_WRITE BUS_SPACE_BARRIER_WRITE 137b14ca477SMatthew Dillon #define OS_BUS_BARRIER_RW \ 138b14ca477SMatthew Dillon (BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE) 139b14ca477SMatthew Dillon #define OS_BUS_BARRIER(_ah, _start, _len, _t) \ 140b14ca477SMatthew Dillon bus_space_barrier((bus_space_tag_t)(_ah)->ah_st, \ 141b14ca477SMatthew Dillon (bus_space_handle_t)(_ah)->ah_sh, (_start), (_len), (_t)) 142b14ca477SMatthew Dillon #define OS_BUS_BARRIER_REG(_ah, _reg, _t) \ 143b14ca477SMatthew Dillon OS_BUS_BARRIER((_ah), (_reg), 4, (_t)) 144b14ca477SMatthew Dillon 145b14ca477SMatthew Dillon /* 146b14ca477SMatthew Dillon * Register read/write operations are handled through 147b14ca477SMatthew Dillon * platform-dependent routines. 148b14ca477SMatthew Dillon */ 149572ff6f6SMatthew Dillon #define OS_REG_WRITE(_ah, _reg, _val) ath_hal_reg_write(_ah, _reg, _val) 150572ff6f6SMatthew Dillon #define OS_REG_READ(_ah, _reg) ath_hal_reg_read(_ah, _reg) 151572ff6f6SMatthew Dillon 152572ff6f6SMatthew Dillon extern void ath_hal_reg_write(struct ath_hal *ah, u_int reg, u_int32_t val); 153572ff6f6SMatthew Dillon extern u_int32_t ath_hal_reg_read(struct ath_hal *ah, u_int reg); 154572ff6f6SMatthew Dillon 155572ff6f6SMatthew Dillon #ifdef AH_DEBUG_ALQ 156572ff6f6SMatthew Dillon extern void OS_MARK(struct ath_hal *, u_int id, u_int32_t value); 157572ff6f6SMatthew Dillon #else 158572ff6f6SMatthew Dillon #define OS_MARK(_ah, _id, _v) 159572ff6f6SMatthew Dillon #endif 160572ff6f6SMatthew Dillon 161572ff6f6SMatthew Dillon #endif /* _ATH_AH_OSDEP_H_ */ 162