Home | History | Annotate | Line # | Download | only in ic
      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.2  joerg  * $Id: ah_osdep.h,v 1.2 2011/07/17 20:54:51 joerg 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 /*
     43  1.1    alc  * Delay n microseconds.
     44  1.1    alc  */
     45  1.1    alc extern	void ath_hal_delay(int);
     46  1.1    alc #define	OS_DELAY(_n)	ath_hal_delay(_n)
     47  1.1    alc 
     48  1.1    alc #define	OS_INLINE	__inline
     49  1.1    alc #define	OS_MEMZERO(_a, _n)	ath_hal_memzero((_a), (_n))
     50  1.1    alc extern void ath_hal_memzero(void *, size_t);
     51  1.1    alc #define	OS_MEMCPY(_d, _s, _n)	ath_hal_memcpy(_d,_s,_n)
     52  1.1    alc extern void *ath_hal_memcpy(void *, const void *, size_t);
     53  1.1    alc 
     54  1.1    alc #define	abs(_a)		__builtin_abs(_a)
     55  1.1    alc 
     56  1.1    alc struct ath_hal;
     57  1.1    alc extern	u_int32_t ath_hal_getuptime(struct ath_hal *);
     58  1.1    alc #define	OS_GETUPTIME(_ah)	ath_hal_getuptime(_ah)
     59  1.1    alc 
     60  1.1    alc /*
     61  1.1    alc  * WiSoC boards overload the bus tag with information about the
     62  1.1    alc  * board layout.  We must extract the bus space tag from that
     63  1.1    alc  * indirect structure.  For everyone else the tag is passed in
     64  1.1    alc  * directly.
     65  1.1    alc  * XXX cache indirect ref privately
     66  1.1    alc  */
     67  1.1    alc #ifdef AH_SUPPORT_AR5312
     68  1.1    alc #define	BUSTAG(ah) \
     69  1.1    alc 	((bus_space_tag_t) ((struct ar531x_config *)((ah)->ah_st))->tag)
     70  1.1    alc #define	BUSHANDLE(ah)	((bus_space_handle_t)((ah)->ah_sh))
     71  1.1    alc 
     72  1.1    alc #elif defined(AH_REGOPS_FUNC)
     73  1.1    alc #define	BUSTAG(ah)	(*(bus_space_tag_t *) (ah)->ah_st)
     74  1.1    alc #define	BUSHANDLE(ah)	(*(bus_space_handle_t *)((ah)->ah_sh))
     75  1.1    alc #define	HALTAG(t)	(HAL_BUS_TAG) &(t)
     76  1.1    alc #define	HALHANDLE(h)	(HAL_BUS_HANDLE) &(h)
     77  1.1    alc #else
     78  1.1    alc #define	BUSTAG(ah)	((bus_space_tag_t) (ah)->ah_st)
     79  1.1    alc #define	BUSHANDLE(ah)	((bus_space_handle_t) ((ah)->ah_sh))
     80  1.1    alc #define	HALTAG(t)	(HAL_BUS_TAG) (t)
     81  1.1    alc #define	HALHANDLE(h)	(HAL_BUS_HANDLE) (h)
     82  1.1    alc #endif
     83  1.1    alc 
     84  1.1    alc /*
     85  1.1    alc  * Register read/write; we assume the registers will always
     86  1.1    alc  * be memory-mapped.  Note that register accesses are done
     87  1.1    alc  * using target-specific functions when debugging is enabled
     88  1.1    alc  * (ATHHAL_DEBUG) or we are explicitly configured this way.  The
     89  1.1    alc  * latter is used on some platforms where the full i/o space
     90  1.1    alc  * cannot be directly mapped.
     91  1.1    alc  */
     92  1.1    alc #if defined(ATHHAL_DEBUG) || defined(AH_REGOPS_FUNC) || defined(ATHHAL_DEBUG_ALQ)
     93  1.1    alc #define	OS_REG_WRITE(_ah, _reg, _val)	ath_hal_reg_write(_ah, _reg, _val)
     94  1.1    alc #define	OS_REG_READ(_ah, _reg)		ath_hal_reg_read(_ah, _reg)
     95  1.1    alc 
     96  1.1    alc extern	void ath_hal_reg_write(struct ath_hal *ah, u_int reg, u_int32_t val);
     97  1.1    alc extern	u_int32_t ath_hal_reg_read(struct ath_hal *ah, u_int reg);
     98  1.1    alc #else
     99  1.1    alc /*
    100  1.1    alc  * The hardware registers are native little-endian byte order.
    101  1.1    alc  * Big-endian hosts are handled by enabling hardware byte-swap
    102  1.1    alc  * of register reads and writes at reset.  But the PCI clock
    103  1.1    alc  * domain registers are not byte swapped!  Thus, on big-endian
    104  1.1    alc  * platforms we have to byte-swap thoese registers specifically.
    105  1.1    alc  * Most of this code is collapsed at compile time because the
    106  1.1    alc  * register values are constants.
    107  1.1    alc  */
    108  1.1    alc #define	AH_LITTLE_ENDIAN	1234
    109  1.1    alc #define	AH_BIG_ENDIAN		4321
    110  1.1    alc 
    111  1.1    alc #if _BYTE_ORDER == _BIG_ENDIAN
    112  1.1    alc #define OS_REG_WRITE(_ah, _reg, _val) do {				\
    113  1.1    alc 	if ( (_reg) >= 0x4000 && (_reg) < 0x5000)			\
    114  1.1    alc 		bus_space_write_4((_ah)->ah_st, (_ah)->ah_sh,		\
    115  1.1    alc 			(_reg), (_val));				\
    116  1.1    alc 	else								\
    117  1.1    alc 		bus_space_write_stream_4((_ah)->ah_st, (_ah)->ah_sh,	\
    118  1.1    alc 			(_reg), (_val));				\
    119  1.1    alc } while (0)
    120  1.1    alc #define OS_REG_READ(_ah, _reg)						\
    121  1.1    alc 	(((_reg) >= 0x4000 && (_reg) < 0x5000) ?			\
    122  1.1    alc 		bus_space_read_4((_ah)->ah_st, (_ah)->ah_sh, (_reg)) :	\
    123  1.1    alc 		bus_space_read_stream_4((_ah)->ah_st, (_ah)->ah_sh, (_reg)))
    124  1.1    alc #else /* _BYTE_ORDER == _LITTLE_ENDIAN */
    125  1.1    alc #define	OS_REG_WRITE(_ah, _reg, _val)					\
    126  1.1    alc 	bus_space_write_4((_ah)->ah_st, (_ah)->ah_sh, (_reg), (_val))
    127  1.1    alc #define	OS_REG_READ(_ah, _reg)						\
    128  1.1    alc 	((u_int32_t) bus_space_read_4((_ah)->ah_st, (_ah)->ah_sh, (_reg)))
    129  1.1    alc #endif /* _BYTE_ORDER */
    130  1.1    alc #endif /* ATHHAL_DEBUG || AH_REGFUNC || ATHHAL_DEBUG_ALQ */
    131  1.1    alc 
    132  1.1    alc #ifdef ATHHAL_DEBUG_ALQ
    133  1.1    alc extern	void OS_MARK(struct ath_hal *, u_int id, u_int32_t value);
    134  1.1    alc #else
    135  1.1    alc #define	OS_MARK(_ah, _id, _v)
    136  1.1    alc #endif
    137  1.1    alc 
    138  1.1    alc typedef void *	HAL_SOFTC;		/* pointer to driver/OS state */
    139  1.1    alc typedef bus_space_tag_t		HAL_BUS_TAG;	/* opaque bus i/o id tag */
    140  1.1    alc typedef bus_space_handle_t	HAL_BUS_HANDLE;	/* opaque bus i/o handle */
    141  1.1    alc 
    142  1.1    alc #define OS_SET_DECLARE(set, ptype)	__link_set_decl(set, ptype)
    143  1.1    alc #define OS_DATA_SET(set, sym)		__link_set_add_rodata(set, sym)
    144  1.1    alc #define OS_SET_FOREACH(pvar, set)	__link_set_foreach(pvar, set)
    145  1.1    alc 
    146  1.1    alc #define __bswap16(x)			bswap16(x)
    147  1.1    alc #define __bswap32(x)			bswap32(x)
    148  1.1    alc 
    149  1.1    alc #endif /* _ATH_AH_OSDEP_H_ */
    150