Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/mipsco Re-implement bus_space(9) functions:
details: https://anonhg.NetBSD.org/src/rev/38738e3e1868
branches: trunk
changeset: 507746:38738e3e1868
user: wdk <wdk%NetBSD.org@localhost>
date: Fri Mar 30 23:17:03 2001 +0000
description:
Re-implement bus_space(9) functions:
- Correctly handle striding of data
- Better support for endian neutral access
- Correctly implement _stream variants of bus_space functions that can
byte swap. This reverses the automatic byte swapping done in hardware
for 16 bit ISA bus cards
diffstat:
sys/arch/mipsco/include/bus.h | 448 +++++++++++++++++++++---------------
sys/arch/mipsco/mipsco/bus_space.c | 42 +-
2 files changed, 277 insertions(+), 213 deletions(-)
diffs (truncated from 689 to 300 lines):
diff -r 22207423abc7 -r 38738e3e1868 sys/arch/mipsco/include/bus.h
--- a/sys/arch/mipsco/include/bus.h Fri Mar 30 22:56:15 2001 +0000
+++ b/sys/arch/mipsco/include/bus.h Fri Mar 30 23:17:03 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bus.h,v 1.4 2001/03/07 22:42:19 thorpej Exp $ */
+/* $NetBSD: bus.h,v 1.5 2001/03/30 23:17:03 wdk Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -131,11 +131,13 @@
paddr_t bs_pbase;
vaddr_t bs_vbase;
- /* sparse addressing shift count */
- u_int8_t bs_stride_1;
- u_int8_t bs_stride_2;
- u_int8_t bs_stride_4;
- u_int8_t bs_stride_8;
+ u_int8_t bs_stride; /* log2(stride) */
+ u_int8_t bs_bswap; /* byte swap in stream methods */
+
+ u_int8_t bs_offset_1;
+ u_int8_t bs_offset_2;
+ u_int8_t bs_offset_4;
+ u_int8_t bs_offset_8;
/* compose a bus_space handle from tag/handle/addr/size/flags (MD) */
int (*bs_compose_handle) __P((bus_space_tag_t, bus_addr_t,
@@ -332,6 +334,22 @@
#define bus_intr_establish(t, i, c, f, ihf, iha) \
(*(t)->bs_intr_establish)((t), (i), (c), (f), (ihf), (iha))
+
+/*
+ * Utility macros; do not use outside this file.
+ */
+#define __BS_TYPENAME(BITS) __CONCAT3(u_int,BITS,_t)
+#define __BS_OFFSET(t, o, BYTES) ((o) << (t)->bs_stride)
+#define __BS_FUNCTION(func,BYTES) __CONCAT3(func,_,BYTES)
+
+/*
+ * Calculate the target address using the bus_space parameters
+ */
+#define __BS_ADDR(t, h, offset, BITS, BYTES) \
+ ((volatile __CONCAT3(u_int,BITS,_t) *) \
+ ((h) + __BS_OFFSET(t, offset, BYTES) + \
+ (t)->__CONCAT(bs_offset_,BYTES)))
+
/*
* u_intN_t bus_space_read_N __P((bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset));
@@ -340,19 +358,18 @@
* described by tag/handle/offset.
*/
-#define bus_space_read(BYTES,BITS) \
+#define __bus_space_read(BYTES,BITS) \
static __inline __CONCAT3(u_int,BITS,_t) \
__CONCAT(bus_space_read_,BYTES)(bus_space_tag_t bst, \
bus_space_handle_t bsh, bus_size_t offset) \
{ \
- return (*(volatile __CONCAT3(u_int,BITS,_t) *) \
- (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES)))); \
+ return (*__BS_ADDR(bst, bsh, offset, BITS, BYTES)); \
}
-bus_space_read(1,8)
-bus_space_read(2,16)
-bus_space_read(4,32)
-bus_space_read(8,64)
+__bus_space_read(1,8)
+__bus_space_read(2,16)
+__bus_space_read(4,32)
+__bus_space_read(8,64)
/*
* void bus_space_read_multi_N __P((bus_space_tag_t tag,
@@ -363,24 +380,29 @@
* described by tag/handle/offset and copy into buffer provided.
*/
-#define bus_space_read_multi(BYTES,BITS) \
+#define __bus_space_read_multi(BYTES,BITS) \
+static __inline void __BS_FUNCTION(bus_space_read_multi,BYTES) \
+ __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
+ __BS_TYPENAME(BITS) *, size_t)); \
+ \
static __inline void \
-__CONCAT(bus_space_read_multi_,BYTES)(bus_space_tag_t bst, \
- bus_space_handle_t bsh, bus_size_t offset, \
- __CONCAT3(u_int,BITS,_t) *datap, bus_size_t count) \
+__BS_FUNCTION(bus_space_read_multi,BYTES)(t, h, o, a, c) \
+ bus_space_tag_t t; \
+ bus_space_handle_t h; \
+ bus_size_t o; \
+ __BS_TYPENAME(BITS) *a; \
+ size_t c; \
{ \
- volatile __CONCAT3(u_int,BITS,_t) *p = \
- (volatile __CONCAT3(u_int,BITS,_t) *) \
- (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))); \
\
- for (; count > 0; --count) \
- *datap++ = *p; \
+ while (c--) \
+ *a++ = __BS_FUNCTION(bus_space_read,BYTES)(t, h, o); \
}
-bus_space_read_multi(1,8)
-bus_space_read_multi(2,16)
-bus_space_read_multi(4,32)
-bus_space_read_multi(8,64)
+__bus_space_read_multi(1,8)
+__bus_space_read_multi(2,16)
+__bus_space_read_multi(4,32)
+__bus_space_read_multi(8,64)
+
/*
* void bus_space_read_region_N __P((bus_space_tag_t tag,
@@ -392,27 +414,31 @@
* buffer provided.
*/
-#define bus_space_read_region(BYTES,BITS) \
+#define __bus_space_read_region(BYTES,BITS) \
+static __inline void __BS_FUNCTION(bus_space_read_region,BYTES) \
+ __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
+ __BS_TYPENAME(BITS) *, size_t)); \
+ \
static __inline void \
-__CONCAT(bus_space_read_region_,BYTES)(bus_space_tag_t bst, \
- bus_space_handle_t bsh, bus_size_t offset, \
- __CONCAT3(u_int,BITS,_t) *datap, bus_size_t count) \
+__BS_FUNCTION(bus_space_read_region,BYTES)(t, h, o, a, c) \
+ bus_space_tag_t t; \
+ bus_space_handle_t h; \
+ bus_size_t o; \
+ __BS_TYPENAME(BITS) *a; \
+ size_t c; \
{ \
- int stride = 1 << __CONCAT(bst->bs_stride_,BYTES); \
- volatile __CONCAT3(u_int,BITS,_t) *p = \
- (volatile __CONCAT3(u_int,BITS,_t) *) \
- (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))); \
\
- for (; count > 0; --count) { \
- *datap++ = *p; \
- p += stride; \
+ while (c--) { \
+ *a++ = __BS_FUNCTION(bus_space_read,BYTES)(t, h, o); \
+ o += BYTES; \
} \
}
-bus_space_read_region(1,8)
-bus_space_read_region(2,16)
-bus_space_read_region(4,32)
-bus_space_read_region(8,64)
+__bus_space_read_region(1,8)
+__bus_space_read_region(2,16)
+__bus_space_read_region(4,32)
+__bus_space_read_region(8,64)
+
/*
* void bus_space_write_N __P((bus_space_tag_t tag,
@@ -423,21 +449,20 @@
* described by tag/handle/offset.
*/
-#define bus_space_write(BYTES,BITS) \
+#define __bus_space_write(BYTES,BITS) \
static __inline void \
__CONCAT(bus_space_write_,BYTES)(bus_space_tag_t bst, \
bus_space_handle_t bsh, \
bus_size_t offset, __CONCAT3(u_int,BITS,_t) data) \
{ \
- *(volatile __CONCAT3(u_int,BITS,_t) *) \
- (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))) = data; \
+ *__BS_ADDR(bst, bsh, offset, BITS, BYTES) = data; \
wbflush(); \
}
-bus_space_write(1,8)
-bus_space_write(2,16)
-bus_space_write(4,32)
-bus_space_write(8,64)
+__bus_space_write(1,8)
+__bus_space_write(2,16)
+__bus_space_write(4,32)
+__bus_space_write(8,64)
/*
* void bus_space_write_multi_N __P((bus_space_tag_t tag,
@@ -448,26 +473,29 @@
* provided to bus space described by tag/handle/offset.
*/
-#define bus_space_write_multi(BYTES,BITS) \
+#define __bus_space_write_multi(BYTES,BITS) \
+static __inline void __BS_FUNCTION(bus_space_write_multi,BYTES) \
+ __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
+ __BS_TYPENAME(BITS) *, size_t)); \
+ \
static __inline void \
-__CONCAT(bus_space_write_multi_,BYTES)(bus_space_tag_t bst, \
- bus_space_handle_t bsh, bus_size_t offset, \
- const __CONCAT3(u_int,BITS,_t) *datap, bus_size_t count) \
+__BS_FUNCTION(bus_space_write_multi,BYTES)(t, h, o, a, c) \
+ bus_space_tag_t t; \
+ bus_space_handle_t h; \
+ bus_size_t o; \
+ __BS_TYPENAME(BITS) *a; \
+ size_t c; \
{ \
- volatile __CONCAT3(u_int,BITS,_t) *p = \
- (volatile __CONCAT3(u_int,BITS,_t) *) \
- (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))); \
\
- while (count--) { \
- *p = *datap++; \
- wbflush(); \
- } \
+ while (c--) \
+ __BS_FUNCTION(bus_space_write,BYTES)(t, h, o, *a++); \
}
-bus_space_write_multi(1,8)
-bus_space_write_multi(2,16)
-bus_space_write_multi(4,32)
-bus_space_write_multi(8,64)
+__bus_space_write_multi(1,8)
+__bus_space_write_multi(2,16)
+__bus_space_write_multi(4,32)
+__bus_space_write_multi(8,64)
+
/*
* void bus_space_write_region_N __P((bus_space_tag_t tag,
@@ -478,28 +506,31 @@
* to bus space described by tag/handle starting at `offset'.
*/
-#define bus_space_write_region(BYTES,BITS) \
+#define __bus_space_write_region(BYTES,BITS) \
+static __inline void __BS_FUNCTION(bus_space_write_region,BYTES) \
+ __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
+ const __BS_TYPENAME(BITS) *, size_t)); \
+ \
static __inline void \
-__CONCAT(bus_space_write_region_,BYTES)(bus_space_tag_t bst, \
- bus_space_handle_t bsh, bus_size_t offset, \
- const __CONCAT3(u_int,BITS,_t) *datap, bus_size_t count) \
+__BS_FUNCTION(bus_space_write_region,BYTES)(t, h, o, a, c) \
+ bus_space_tag_t t; \
+ bus_space_handle_t h; \
+ bus_size_t o; \
+ const __BS_TYPENAME(BITS) *a; \
+ size_t c; \
{ \
- int stride = 1 << __CONCAT(bst->bs_stride_,BYTES); \
- volatile __CONCAT3(u_int,BITS,_t) *p = \
- (volatile __CONCAT3(u_int,BITS,_t) *) \
- (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))); \
\
- while (count--) { \
- *p = *datap++; \
- p += stride; \
+ while (c--) { \
+ __BS_FUNCTION(bus_space_write,BYTES)(t, h, o, *a++); \
+ o += BYTES; \
} \
- wbflush(); \
}
-bus_space_write_region(1,8)
-bus_space_write_region(2,16)
-bus_space_write_region(4,32)
-bus_space_write_region(8,64)
+__bus_space_write_region(1,8)
+__bus_space_write_region(2,16)
+__bus_space_write_region(4,32)
+__bus_space_write_region(8,64)
+
/*
* void bus_space_set_multi_N __P((bus_space_tag_t tag,
@@ -510,24 +541,29 @@
* by tag/handle/offset `count' times.
*/
-#define bus_space_set_multi(BYTES,BITS) \
+#define __bus_space_set_multi(BYTES,BITS) \
+static __inline void __BS_FUNCTION(bus_space_set_multi,BYTES) \
+ __P((bus_space_tag_t, bus_space_handle_t, bus_size_t, \
+ __BS_TYPENAME(BITS), size_t)); \
+ \
static __inline void \
-__CONCAT(bus_space_set_multi_,BYTES)(bus_space_tag_t bst, \
Home |
Main Index |
Thread Index |
Old Index