The entity passed to the HAL as a HAL_BUS_HANDLE needs to be an integral

or pointer type. So on sparc64 (and maybe others too?) where
bus_space_handle_t is a struct, pass the address of the bus_space_handle_t
and adjust the register access functions accordingly.

While there, slightly optimize the bus_space_* usage in the register
access functions and macros.
This commit is contained in:
martin 2005-09-13 05:50:29 +00:00
parent ebc4ea57cf
commit 30895fa9a4
3 changed files with 38 additions and 22 deletions

View File

@ -33,7 +33,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGES.
*
* $Id: athhal_osdep.c,v 1.3 2005/07/04 05:35:09 dyoung Exp $
* $Id: athhal_osdep.c,v 1.4 2005/09/13 05:50:29 martin Exp $
*/
#include "opt_ah.h"
@ -288,6 +288,8 @@ ath_hal_alq_get(struct ath_hal *ah)
void
ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val)
{
bus_space_handle_t h = ATH_HAL2BUSHDNLE(ah->ah_sh);
if (ath_hal_alq) {
struct ale *ale = ath_hal_alq_get(ah);
if (ale) {
@ -300,22 +302,25 @@ ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val)
}
#if _BYTE_ORDER == _BIG_ENDIAN
if (reg >= 0x4000 && reg < 0x5000)
bus_space_write_stream_4(ah->ah_st, ah->ah_sh, reg, htole32(val));
bus_space_write_4(ah->ah_st, h, reg, val);
else
#endif
bus_space_write_stream_4(ah->ah_st, ah->ah_sh, reg, val);
bus_space_write_stream_4(ah->ah_st, h, reg, val);
}
u_int32_t
ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg)
{
u_int32_t val;
bus_space_handle_t h = ATH_HAL2BUSHDNLE(ah->ah_sh);
val = bus_space_read_stream_4(ah->ah_st, ah->ah_sh, reg);
#if _BYTE_ORDER == _BIG_ENDIAN
if (reg >= 0x4000 && reg < 0x5000)
val = le32toh(val);
val = bus_space_read_4(ah->ah_st, h, reg);
else
#endif
val = bus_space_read_stream_4(ah->ah_st, h, reg);
if (ath_hal_alq) {
struct ale *ale = ath_hal_alq_get(ah);
if (ale) {
@ -358,25 +363,25 @@ OS_MARK(struct ath_hal *ah, u_int id, u_int32_t v)
void
ath_hal_reg_write(struct ath_hal *ah, u_int32_t reg, u_int32_t val)
{
bus_space_handle_t h = ATH_HAL2BUSHDNLE(ah->ah_sh);
#if _BYTE_ORDER == _BIG_ENDIAN
if (reg >= 0x4000 && reg < 0x5000)
bus_space_write_stream_4(ah->ah_st, ah->ah_sh, reg, htole32(val));
bus_space_write_4(ah->ah_st, h, reg, val);
else
#endif
bus_space_write_stream_4(ah->ah_st, ah->ah_sh, reg, val);
bus_space_write_stream_4(ah->ah_st, h, reg, val);
}
u_int32_t
ath_hal_reg_read(struct ath_hal *ah, u_int32_t reg)
{
u_int32_t val;
bus_space_handle_t h = ATH_HAL2BUSHDNLE(ah->ah_sh);
val = bus_space_read_stream_4(ah->ah_st, ah->ah_sh, reg);
#if _BYTE_ORDER == _BIG_ENDIAN
if (reg >= 0x4000 && reg < 0x5000)
val = le32toh(val);
return bus_space_read_4(ah->ah_st, h, reg);
#endif
return val;
return bus_space_read_stream_4(ah->ah_st, h, reg);
}
#endif /* AH_DEBUG || AH_REGOPS_FUNC */

View File

@ -33,7 +33,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGES.
*
* $Id: athhal_osdep.h,v 1.3 2005/07/04 05:35:09 dyoung Exp $
* $Id: athhal_osdep.h,v 1.4 2005/09/13 05:50:29 martin Exp $
*/
#ifndef _ATH_AH_OSDEP_H_
#define _ATH_AH_OSDEP_H_
@ -46,9 +46,19 @@
#include <machine/bus.h>
#ifdef __sparc64__
/* the HAL wants a pointer type, but bus_space_handle_t is a struct */
typedef bus_space_handle_t *HAL_BUS_HANDLE;
#define ATH_BUSHANDLE2HAL(HNDL) (&(HNDL))
#define ATH_HAL2BUSHDNLE(HH) (*(HH))
#else
typedef bus_space_handle_t HAL_BUS_HANDLE;
#define ATH_BUSHANDLE2HAL(HNDL) (HNDL)
#define ATH_HAL2BUSHDNLE(HH) (HH)
#endif
typedef void* HAL_SOFTC;
typedef bus_space_tag_t HAL_BUS_TAG;
typedef bus_space_handle_t HAL_BUS_HANDLE;
typedef bus_addr_t HAL_BUS_ADDR;
/*
@ -99,22 +109,22 @@ extern u_int32_t ath_hal_reg_read(struct ath_hal *ah, u_int reg);
#if _BYTE_ORDER == _BIG_ENDIAN
#define OS_REG_WRITE(_ah, _reg, _val) do { \
if ( (_reg) >= 0x4000 && (_reg) < 0x5000) \
bus_space_write_stream_4((_ah)->ah_st, (_ah)->ah_sh, \
(_reg), htole32(_val)); \
bus_space_write_4((_ah)->ah_st, (_ah)->ah_sh, \
(_reg), (_val)); \
else \
bus_space_write_stream_4((_ah)->ah_st, (_ah)->ah_sh, \
bus_space_write_stream_4((_ah)->ah_st, (_ah)->ah_sh, \
(_reg), (_val)); \
} while (0)
#define OS_REG_READ(_ah, _reg) \
(((_reg) >= 0x4000 && (_reg) < 0x5000) ? \
le32toh(bus_space_read_stream_4((_ah)->ah_st, (_ah)->ah_sh, \
bus_space_read_4((_ah)->ah_st, (_ah)->ah_sh, \
(_reg))) : \
bus_space_read_stream_4((_ah)->ah_st, (_ah)->ah_sh, (_reg)))
#else /* _BYTE_ORDER == _LITTLE_ENDIAN */
#define OS_REG_WRITE(_ah, _reg, _val) \
bus_space_write_stream_4((_ah)->ah_st, (_ah)->ah_sh, (_reg), (_val))
bus_space_write_4((_ah)->ah_st, (_ah)->ah_sh, (_reg), (_val))
#define OS_REG_READ(_ah, _reg) \
((u_int32_t) bus_space_read_stream_4((_ah)->ah_st, (_ah)->ah_sh, (_reg)))
((u_int32_t) bus_space_read_4((_ah)->ah_st, (_ah)->ah_sh, (_reg)))
#endif /* _BYTE_ORDER */
#endif /* AH_DEBUG || AH_REGFUNC || AH_DEBUG_ALQ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ath.c,v 1.58 2005/08/21 00:25:51 dyoung Exp $ */
/* $NetBSD: ath.c,v 1.59 2005/09/13 05:50:29 martin Exp $ */
/*-
* Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@ -41,7 +41,7 @@
__FBSDID("$FreeBSD: src/sys/dev/ath/if_ath.c,v 1.94 2005/07/07 00:04:50 sam Exp $");
#endif
#ifdef __NetBSD__
__KERNEL_RCSID(0, "$NetBSD: ath.c,v 1.58 2005/08/21 00:25:51 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: ath.c,v 1.59 2005/09/13 05:50:29 martin Exp $");
#endif
/*
@ -308,7 +308,8 @@ ath_attach(u_int16_t devid, struct ath_softc *sc)
memcpy(ifp->if_xname, sc->sc_dev.dv_xname, IFNAMSIZ);
ah = ath_hal_attach(devid, sc, sc->sc_st, sc->sc_sh, &status);
ah = ath_hal_attach(devid, sc, sc->sc_st, ATH_BUSHANDLE2HAL(sc->sc_sh),
&status);
if (ah == NULL) {
if_printf(ifp, "unable to attach hardware; HAL status %u\n",
status);