Subject: Re: Missing bus_space_* things
To: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
From: Martin Husemann <martin@duskware.de>
List: port-sgimips
Date: 06/07/2006 20:20:37
--Dxnq1zWXvFF0Q93v
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Wed, Jun 07, 2006 at 07:11:06PM +0900, Izumi Tsutsui wrote:
> but it depends on your motivation ;-)
Heh, this is as far as I get for now - should I commit it or is anyone
going for the big cleanup?
Martin
--Dxnq1zWXvFF0Q93v
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch
Index: include/bus.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/include/bus.h,v
retrieving revision 1.20
diff -c -u -p -r1.20 bus.h
--- include/bus.h 26 May 2006 13:23:34 -0000 1.20
+++ include/bus.h 7 Jun 2006 18:17:44 -0000
@@ -151,6 +151,27 @@ u_int32_t bus_space_read_4(bus_space_tag
u_int64_t bus_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t);
/*
+ * u_intN_t bus_space_read_stream_N(bus_space_tag_t tag,
+ * bus_space_handle_t bsh, bus_size_t offset);
+ *
+ * Read a 1, 2, 4, or 8 byte quantity from bus space
+ * described by tag/handle/offset, but w/o any byte order changes.
+ */
+
+static __inline u_int8_t
+bus_space_read_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
+{
+ return bus_space_read_1(t, h, o);
+}
+
+u_int16_t bus_space_read_stream_2(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t);
+u_int32_t bus_space_read_stream_4(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t);
+u_int64_t bus_space_read_stream_8(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t);
+
+/*
* void bus_space_read_multi_N(bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset,
* u_intN_t *addr, size_t count);
@@ -159,7 +180,7 @@ u_int64_t bus_space_read_8(bus_space_tag
* described by tag/handle/offset and copy into buffer provided.
*/
-#define __SGIMIPS_bus_space_read_multi(BYTES,BITS) \
+#define __SGIMIPS_bus_space_read_multi(BYTES,BITS) \
static __inline void __CONCAT(bus_space_read_multi_,BYTES) \
(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
__PB_TYPENAME(BITS) *, size_t); \
@@ -187,6 +208,29 @@ __SGIMIPS_bus_space_read_multi(4,32)
#undef __SGIMIPS_bus_space_read_multi
+#define __SGIMIPS_bus_space_read_multi_stream(BYTES,BITS) \
+static __inline void __CONCAT(bus_space_read_multi_stream_,BYTES) \
+ (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
+ __PB_TYPENAME(BITS) *, size_t); \
+ \
+static __inline void \
+__CONCAT(bus_space_read_multi_stream_,BYTES)(t, h, o, a, c) \
+ bus_space_tag_t t; \
+ bus_space_handle_t h; \
+ bus_size_t o; \
+ __PB_TYPENAME(BITS) *a; \
+ size_t c; \
+{ \
+ \
+ while (c--) \
+ *a++ = __CONCAT(bus_space_read_stream_,BYTES)(t, h, o); \
+}
+
+__SGIMIPS_bus_space_read_multi_stream(1,8)
+__SGIMIPS_bus_space_read_multi_stream(2,16)
+__SGIMIPS_bus_space_read_multi_stream(4,32)
+#undef __SGIMIPS_bus_space_read_multi_stream
+
/*
* void bus_space_read_region_N(bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset,
@@ -246,6 +290,29 @@ void bus_space_write_8(bus_space_tag_t,
u_int64_t);
/*
+ * void bus_space_write_stream_N(bus_space_tag_t tag,
+ * bus_space_handle_t bsh, bus_size_t offset,
+ * u_intN_t value);
+ *
+ * Write the 1, 2, 4, or 8 byte value `value' to bus space
+ * described by tag/handle/offset. Do not adjust byte order.
+ */
+
+static __inline void
+bus_space_write_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int8_t v)
+{
+ bus_space_write_1(t, h, o, v);
+}
+
+void bus_space_write_stream_2(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int16_t);
+void bus_space_write_stream_4(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int32_t);
+void bus_space_write_stream_8(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int64_t);
+
+/*
* void bus_space_write_multi_N(bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset,
* const u_intN_t *addr, size_t count);
@@ -283,6 +350,30 @@ __SGIMIPS_bus_space_write_multi(4,32)
#undef __SGIMIPS_bus_space_write_multi
+#define __SGIMIPS_bus_space_write_multi_stream(BYTES,BITS) \
+static __inline void __CONCAT(bus_space_write_multi_stream_,BYTES) \
+ (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
+ const __PB_TYPENAME(BITS) *, size_t); \
+ \
+static __inline void \
+__CONCAT(bus_space_write_multi_stream_,BYTES)(t, h, o, a, c) \
+ bus_space_tag_t t; \
+ bus_space_handle_t h; \
+ bus_size_t o; \
+ const __PB_TYPENAME(BITS) *a; \
+ size_t c; \
+{ \
+ \
+ while (c--) \
+ __CONCAT(bus_space_write_stream_,BYTES)(t, h, o, *a++); \
+}
+
+__SGIMIPS_bus_space_write_multi_stream(1,8)
+__SGIMIPS_bus_space_write_multi_stream(2,16)
+__SGIMIPS_bus_space_write_multi_stream(4,32)
+
+#undef __SGIMIPS_bus_space_write_multi_stream
+
/*
* void bus_space_write_region_N(bus_space_tag_t tag,
* bus_space_handle_t bsh, bus_size_t offset,
@@ -332,7 +423,7 @@ __SGIMIPS_bus_space_write_region(4,32)
* by tag/handle/offset `count' times.
*/
-#define __SGIMIPS_bus_space_set_multi(BYTES,BITS) \
+#define __SGIMIPS_bus_space_set_multi(BYTES,BITS) \
static __inline void __CONCAT(bus_space_set_multi_,BYTES) \
(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
__PB_TYPENAME(BITS), size_t); \
@@ -370,7 +461,7 @@ __SGIMIPS_bus_space_set_multi(4,32)
* by tag/handle starting at `offset'.
*/
-#define __SGIMIPS_bus_space_set_region(BYTES,BITS) \
+#define __SGIMIPS_bus_space_set_region(BYTES,BITS) \
static __inline void __CONCAT(bus_space_set_region_,BYTES) \
(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
__PB_TYPENAME(BITS), size_t); \
Index: sgimips/bus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/sgimips/bus.c,v
retrieving revision 1.45
diff -c -u -p -r1.45 bus.c
--- sgimips/bus.c 16 Apr 2006 16:39:37 -0000 1.45
+++ sgimips/bus.c 7 Jun 2006 18:17:44 -0000
@@ -212,8 +212,104 @@ bus_space_read_4(bus_space_tag_t tag, bu
return reg;
}
+
+void
+bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
+ bus_size_t o, u_int32_t v)
+{
+ int s;
+
+ switch (tag) {
+ case SGIMIPS_BUS_SPACE_MACE:
+ s = splhigh();
+ delay(10);
+ *(volatile u_int32_t *)((bsh) + (o)) = (v);
+ delay(10);
+ splx(s);
+ break;
+ default:
+ *(volatile u_int32_t *)((bsh) + (o)) = (v);
+ wbflush(); /* XXX */
+ break;
+ }
+}
+
+u_int16_t
+bus_space_read_stream_2(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o)
+{
+ u_int16_t v;
+ wbflush(); /* XXX ? */
+
+ switch (t) {
+ case SGIMIPS_BUS_SPACE_NORMAL:
+ return *(volatile u_int16_t *)(h + o);
+ case SGIMIPS_BUS_SPACE_HPC:
+ return *(volatile u_int16_t *)(h + (o << 2) + 1);
+ case SGIMIPS_BUS_SPACE_MEM:
+ case SGIMIPS_BUS_SPACE_IO:
+ v = *(volatile u_int16_t *)(h + (o | 2) - (o & 3));
+ return htole16(v);
+ default:
+ panic("no bus tag");
+ }
+}
+
+u_int32_t
+bus_space_read_stream_4(bus_space_tag_t t, bus_space_handle_t bsh,
+ bus_size_t o)
+{
+ u_int32_t reg;
+ int s;
+
+ switch (t) {
+ case SGIMIPS_BUS_SPACE_MACE:
+ s = splhigh();
+ delay(10);
+ reg = (*(volatile u_int32_t *)(bsh + o));
+ delay(10);
+ splx(s);
+ break;
+ case SGIMIPS_BUS_SPACE_MEM:
+ case SGIMIPS_BUS_SPACE_IO:
+ wbflush();
+ reg = (*(volatile u_int32_t *)(bsh + o));
+ reg = htole32(reg);
+ break;
+ default:
+ wbflush();
+ reg = (*(volatile u_int32_t *)(bsh + o));
+ break;
+ }
+ return reg;
+}
+
void
-bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t o, u_int32_t v)
+bus_space_write_stream_2(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, u_int16_t v)
+{
+ switch (t) {
+ case SGIMIPS_BUS_SPACE_NORMAL:
+ *(volatile u_int16_t *)(h + o) = v;
+ break;
+ case SGIMIPS_BUS_SPACE_HPC:
+ *(volatile u_int16_t *)(h + (o << 2) + 1) = v;
+ break;
+ case SGIMIPS_BUS_SPACE_MEM:
+ case SGIMIPS_BUS_SPACE_IO:
+ v = le16toh(v);
+ *(volatile u_int16_t *)(h + (o | 2) - (o & 3)) = v;
+ break;
+ default:
+ panic("no bus tag");
+ }
+
+ wbflush(); /* XXX */
+}
+
+void
+bus_space_write_stream_4(bus_space_tag_t tag, bus_space_handle_t bsh,
+ bus_size_t o, u_int32_t v)
{
int s;
@@ -225,6 +321,12 @@ bus_space_write_4(bus_space_tag_t tag, b
delay(10);
splx(s);
break;
+ case SGIMIPS_BUS_SPACE_IO:
+ case SGIMIPS_BUS_SPACE_MEM:
+ v = le32toh(v);
+ *(volatile u_int32_t *)((bsh) + (o)) = (v);
+ wbflush(); /* XXX */
+ break;
default:
*(volatile u_int32_t *)((bsh) + (o)) = (v);
wbflush(); /* XXX */
--Dxnq1zWXvFF0Q93v--