Subject: Re: port-alpha/4595: Fix for NE2000 on alpha architecture
To: None <ajo@wopr.campus.luth.se>
From: Chris G. Demetriou <cgd@pa.dec.com>
List: netbsd-bugs
Date: 11/28/1997 23:59:54
> --- arch/alpha/pci/pci_swiz_bus_io_chipdep.c.orig Wed Nov 26 16:47:51 1997
> +++ arch/alpha/pci/pci_swiz_bus_io_chipdep.c Fri Nov 28 15:25:43 1997
> @@ -646,11 +646,44 @@
> bus_size_t o, c; \
> const TYPE *a; \
> { \
> + /* Check for unaligned access to memory */ \
> + if ((BYTES > 1) && ( ((u_int64_t)a) & (BYTES-1) ) ) { \
> + TYPE d; \
> + int i; \
> \
> - while (c-- > 0) { \
> - __C(__C(CHIP,_io_write_),BYTES)(v, h, o, *a++); \
> - __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
> - BUS_BARRIER_WRITE); \
> + if (((u_int64_t)a) & 1) { \
> + while (c-- > 0) { \
> + for (i = 0; i < BYTES; i++) \
> + ((u_int8_t *)&d)[i] = *((u_int8_t *)a)++; \
> + __C(__C(CHIP,_io_write_),BYTES)(v, h, o, d); \
> + __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
> + BUS_BARRIER_WRITE); \
> + } \
> + } \
> + else if ((BYTES > 2) && (((u_int64_t)a) & 2)) { \
> + while (c-- > 0) { \
> + for (i = 0; i < BYTES/2; i++) \
> + ((u_int16_t *)&d)[i] = *((u_int16_t *)a)++; \
> + __C(__C(CHIP,_io_write_),BYTES)(v, h, o, d); \
> + __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
> + BUS_BARRIER_WRITE); \
> + } \
> + } \
> + else if ((BYTES > 4) && (((u_int64_t)a) & 4)) { \
> + while (c-- > 0) { \
> + for (i = 0; i < BYTES/4; i++) \
> + ((u_int32_t *)&d)[i] = *((u_int32_t *)a)++; \
> + __C(__C(CHIP,_io_write_),BYTES)(v, h, o, d); \
> + __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
> + BUS_BARRIER_WRITE); \
> + } \
> + } \
> + } else { \
> + while (c-- > 0) { \
> + __C(__C(CHIP,_io_write_),BYTES)(v, h, o, *a++); \
> + __C(CHIP,_io_barrier)(v, h, o, sizeof *a, \
> + BUS_BARRIER_WRITE); \
> + } \
> } \
> }
> CHIP_io_write_multi_N(1,u_int8_t)
This is not appropriate, and should not be necessary.
It is a driver bug to call the bus_space_* macros with an
improperly-aligned pointer. It should not have to be, and should not
be, worked around in the bus_space_* implementation. Rather, it
should be fixed in the driver.
cgd