/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer,11* without modification.12* 2. Redistributions in binary form must reproduce at minimum a disclaimer13* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any14* redistribution must be conditioned upon including a substantially15* similar Disclaimer requirement for further binary redistribution.16*17* NO WARRANTY18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY21* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL22* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,23* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF24* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS25* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER26* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF28* THE POSSIBILITY OF SUCH DAMAGES.29*/30#ifndef _ATH_AH_OSDEP_H_31#define _ATH_AH_OSDEP_H_32/*33* Atheros Hardware Access Layer (HAL) OS Dependent Definitions.34*/3536#include <sys/param.h>37#include <sys/systm.h>38#include <sys/endian.h>39#include <sys/linker_set.h>4041#include <machine/bus.h>4243/*44* Bus i/o type definitions.45*/46typedef void *HAL_SOFTC;47typedef bus_space_tag_t HAL_BUS_TAG;48typedef bus_space_handle_t HAL_BUS_HANDLE;4950/*51* Although the underlying hardware may support 64 bit DMA, the52* current Atheros hardware only supports 32 bit addressing.53*/54typedef uint32_t HAL_DMA_ADDR;5556/*57* Linker set writearounds for chip and RF backend registration.58*/59#define OS_DATA_SET(set, item) DATA_SET(set, item)60#define OS_SET_DECLARE(set, ptype) SET_DECLARE(set, ptype)61#define OS_SET_FOREACH(pvar, set) SET_FOREACH(pvar, set)6263/*64* Delay n microseconds.65*/66#define OS_DELAY(_n) DELAY(_n)6768#define OS_INLINE __inline69#define OS_MEMZERO(_a, _n) bzero((_a), (_n))70#define OS_MEMCPY(_d, _s, _n) memcpy(_d,_s,_n)71#define OS_MEMCMP(_a, _b, _l) memcmp((_a), (_b), (_l))7273#define abs(_a) __builtin_abs(_a)7475struct ath_hal;7677/*78* The hardware registers are native little-endian byte order.79* Big-endian hosts are handled by enabling hardware byte-swap80* of register reads and writes at reset. But the PCI clock81* domain registers are not byte swapped! Thus, on big-endian82* platforms we have to explicitly byte-swap those registers.83* OS_REG_UNSWAPPED identifies the registers that need special handling.84*85* This is not currently used by the FreeBSD HAL osdep code; the HAL86* currently does not configure hardware byteswapping for register space87* accesses and instead does it through the FreeBSD bus space code.88*/89#if _BYTE_ORDER == _BIG_ENDIAN90#define OS_REG_UNSWAPPED(_reg) \91(((_reg) >= 0x4000 && (_reg) < 0x5000) || \92((_reg) >= 0x7000 && (_reg) < 0x8000))93#else /* _BYTE_ORDER == _LITTLE_ENDIAN */94#define OS_REG_UNSWAPPED(_reg) (0)95#endif /* _BYTE_ORDER */9697/*98* For USB/SDIO support (where access latencies are quite high);99* some write accesses may be buffered and then flushed when100* either a read is done, or an explicit flush is done.101*102* These are simply placeholders for now.103*/104#define OS_REG_WRITE_BUFFER_ENABLE(_ah) \105do { } while (0)106#define OS_REG_WRITE_BUFFER_DISABLE(_ah) \107do { } while (0)108#define OS_REG_WRITE_BUFFER_FLUSH(_ah) \109do { } while (0)110111/*112* Read and write barriers. Some platforms require more strongly ordered113* operations and unfortunately most of the HAL is written assuming everything114* is either an x86 or the bus layer will do the barriers for you.115*116* Read barriers should occur before each read, and write barriers117* occur after each write.118*119* Later on for SDIO/USB parts we will methodize this and make them no-ops;120* register accesses will go via USB commands.121*/122#define OS_BUS_BARRIER_READ BUS_SPACE_BARRIER_READ123#define OS_BUS_BARRIER_WRITE BUS_SPACE_BARRIER_WRITE124#define OS_BUS_BARRIER_RW \125(BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE)126#define OS_BUS_BARRIER(_ah, _start, _len, _t) \127bus_space_barrier((bus_space_tag_t)(_ah)->ah_st, \128(bus_space_handle_t)(_ah)->ah_sh, (_start), (_len), (_t))129#define OS_BUS_BARRIER_REG(_ah, _reg, _t) \130OS_BUS_BARRIER((_ah), (_reg), 4, (_t))131132/*133* Register read/write operations are handled through134* platform-dependent routines.135*/136#define OS_REG_WRITE(_ah, _reg, _val) ath_hal_reg_write(_ah, _reg, _val)137#define OS_REG_READ(_ah, _reg) ath_hal_reg_read(_ah, _reg)138139extern void ath_hal_reg_write(struct ath_hal *ah, u_int reg, u_int32_t val);140extern u_int32_t ath_hal_reg_read(struct ath_hal *ah, u_int reg);141142#ifdef AH_DEBUG_ALQ143extern void OS_MARK(struct ath_hal *, u_int id, u_int32_t value);144#else145#define OS_MARK(_ah, _id, _v)146#endif147148#endif /* _ATH_AH_OSDEP_H_ */149150151