Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 03 Jul 1999 15:24:40 -0600
From:      Warner Losh <imp@harmony.village.org>
To:        hackers@freebsd.org
Subject:   The busspace modernization initiative.
Message-ID:  <199907032124.PAA33313@harmony.village.org>

next in thread | raw e-mail | index | archive | help

I'm trying to update the bus-space routines to match more closely the
NetBSD routines.  The new-config project has already done this, so
I've been moving their code into a relatively pure -current tree.

I'm finding that there are many places that assume that
bus_space_handle_t is the same thing as u_int or that
bus_space_handles can be compared with !=.  Some of this code I even
wrote :-(.

These strike me as unwise assumptions.  Fortunately, it appears that
there are only 4 files impacted (at least in my config, I've not tried
GENERIC yet):
	../../pci/bt_pci.c
	../../i386/i386/nexus.c
	../../i386/isa/aha_isa.c
	../../pci/es1370.c
It strikes me as unwise to make these assumptions, even if they should
generally prove to be true.

Comments?

Warner

P.S.  Here's the diffs which are what I'm trying to do.  Please feel
free to comment on them.  I'm unsure why there is a struct resource *
in bus_space_handle_t in this implementation.  I'll have to ask on the
new-config lists, since if it isn't needed, it would best be
removed...

--- /home/imp/FreeBSD/src/sys/i386/include/bus.h	Sat Jul  3 14:14:08 1999
+++ ./bus.h	Mon Apr 26 00:11:18 1999
@@ -107,8 +101,11 @@
 /*
  * Access methods for bus resources and address space.
  */
-typedef	int bus_space_tag_t;
-typedef	u_int bus_space_handle_t;
+typedef u_int bus_space_tag_t;
+typedef struct {
+    u_int addr;
+    struct resource *resource;
+} bus_space_handle_t;
 
 /*
  * Map a region of device bus space into CPU virtual address space.
@@ -177,10 +174,10 @@
 #if defined (_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
 #endif
-		return (inb(handle + offset));
+		return (inb(handle.addr + offset));
 #endif
 #if defined (_I386_BUS_MEMIO_H_)
-	return (*(volatile u_int8_t *)(handle + offset));
+	return (*(volatile u_int8_t *)(handle.addr + offset));
 #endif
 }
 
@@ -192,10 +189,10 @@
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
 #endif
-		return (inw(handle + offset));
+		return (inw(handle.addr + offset));
 #endif
 #if defined(_I386_BUS_MEMIO_H_)
-	return (*(volatile u_int16_t *)(handle + offset));
+	return (*(volatile u_int16_t *)(handle.addr + offset));
 #endif
 }
 
@@ -207,10 +204,10 @@
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
 #endif
-		return (inl(handle + offset));
+		return (inl(handle.addr + offset));
 #endif
 #if defined(_I386_BUS_MEMIO_H_)
-	return (*(volatile u_int32_t *)(handle + offset));
+	return (*(volatile u_int32_t *)(handle.addr + offset));
 #endif
 }
 
@@ -238,9 +235,10 @@
 					    size_t count);
 
 static __inline void
-bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsht,
 		       bus_size_t offset, u_int8_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -266,9 +264,10 @@
 }
 
 static __inline void
-bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsht,
 		       bus_size_t offset, u_int16_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -294,9 +293,10 @@
 }
 
 static __inline void
-bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsht,
 		       bus_size_t offset, u_int32_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -347,9 +347,10 @@
 
 
 static __inline void
-bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsht,
 			bus_size_t offset, u_int8_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -384,9 +385,10 @@
 }
 
 static __inline void
-bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsht,
 			bus_size_t offset, u_int16_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -421,9 +423,10 @@
 }
 
 static __inline void
-bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsht,
 			bus_size_t offset, u_int32_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -479,9 +482,10 @@
 				       bus_size_t offset, u_int32_t value);
 
 static __inline void
-bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsht,
 		       bus_size_t offset, u_int8_t value)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -497,9 +501,10 @@
 }
 
 static __inline void
-bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsht,
 		       bus_size_t offset, u_int16_t value)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -515,9 +520,10 @@
 }
 
 static __inline void
-bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsht,
 		       bus_size_t offset, u_int32_t value)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -559,9 +565,10 @@
 					     size_t count);
 
 static __inline void
-bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsht,
 			bus_size_t offset, const u_int8_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -587,9 +594,10 @@
 }
 
 static __inline void
-bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsht,
 			bus_size_t offset, const u_int16_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -615,9 +623,10 @@
 }
 
 static __inline void
-bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsht,
 			bus_size_t offset, const u_int32_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -669,9 +678,10 @@
 					      size_t count);
 
 static __inline void
-bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsht,
 			 bus_size_t offset, const u_int8_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -706,9 +716,10 @@
 }
 
 static __inline void
-bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsht,
 			 bus_size_t offset, const u_int16_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -743,9 +754,10 @@
 }
 
 static __inline void
-bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsht,
 			 bus_size_t offset, const u_int32_t *addr, size_t count)
 {
+	u_int bsh = bsht.addr;
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
 	if (tag == I386_BUS_SPACE_IO)
@@ -803,10 +815,10 @@
 					   u_int32_t value, size_t count);
 
 static __inline void
-bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsht,
 		      bus_size_t offset, u_int8_t value, size_t count)
 {
-	bus_addr_t addr = bsh + offset;
+	bus_addr_t addr = bsht.addr + offset;
 
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
@@ -825,10 +837,10 @@
 }
 
 static __inline void
-bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsht,
 		     bus_size_t offset, u_int16_t value, size_t count)
 {
-	bus_addr_t addr = bsh + offset;
+	bus_addr_t addr = bsht.addr + offset;
 
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
@@ -847,10 +859,10 @@
 }
 
 static __inline void
-bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsht,
 		      bus_size_t offset, u_int32_t value, size_t count)
 {
-	bus_addr_t addr = bsh + offset;
+	bus_addr_t addr = bsht.addr + offset;
 
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
@@ -878,23 +890,23 @@
  */
 
 static __inline void bus_space_set_region_1(bus_space_tag_t tag,
-					    bus_space_handle_t bsh,
+					    bus_space_handle_t bsht,
 					    bus_size_t offset, u_int8_t value,
 					    size_t count);
 static __inline void bus_space_set_region_2(bus_space_tag_t tag,
-					    bus_space_handle_t bsh,
+					    bus_space_handle_t bsht,
 					    bus_size_t offset, u_int16_t value,
 					    size_t count);
 static __inline void bus_space_set_region_4(bus_space_tag_t tag,
-					    bus_space_handle_t bsh,
+					    bus_space_handle_t bsht,
 					    bus_size_t offset, u_int32_t value,
 					    size_t count);
 
 static __inline void
-bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsht,
 		       bus_size_t offset, u_int8_t value, size_t count)
 {
-	bus_addr_t addr = bsh + offset;
+	bus_addr_t addr = bsht.addr + offset;
 
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
@@ -913,10 +925,10 @@
 }
 
 static __inline void
-bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsht,
 		       bus_size_t offset, u_int16_t value, size_t count)
 {
-	bus_addr_t addr = bsh + offset;
+	bus_addr_t addr = bsht.addr + offset;
 
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
@@ -935,10 +947,10 @@
 }
 
 static __inline void
-bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
+bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsht,
 		       bus_size_t offset, u_int32_t value, size_t count)
 {
-	bus_addr_t addr = bsh + offset;
+	bus_addr_t addr = bsht.addr + offset;
 
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
@@ -966,30 +978,30 @@
  */
 
 static __inline void bus_space_copy_region_1(bus_space_tag_t tag,
-					     bus_space_handle_t bsh1,
+					     bus_space_handle_t bsht1,
 					     bus_size_t off1,
-					     bus_space_handle_t bsh2,
+					     bus_space_handle_t bsht2,
 					     bus_size_t off2, size_t count);
 
 static __inline void bus_space_copy_region_2(bus_space_tag_t tag,
-					     bus_space_handle_t bsh1,
+					     bus_space_handle_t bsht1,
 					     bus_size_t off1,
-					     bus_space_handle_t bsh2,
+					     bus_space_handle_t bsht2,
 					     bus_size_t off2, size_t count);
 
 static __inline void bus_space_copy_region_4(bus_space_tag_t tag,
-					     bus_space_handle_t bsh1,
+					     bus_space_handle_t bsht1,
 					     bus_size_t off1,
-					     bus_space_handle_t bsh2,
+					     bus_space_handle_t bsht2,
 					     bus_size_t off2, size_t count);
 
 static __inline void
-bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1,
-			bus_size_t off1, bus_space_handle_t bsh2,
+bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsht1,
+			bus_size_t off1, bus_space_handle_t bsht2,
 			bus_size_t off2, size_t count)
 {
-	bus_addr_t addr1 = bsh1 + off1;
-	bus_addr_t addr2 = bsh2 + off2;
+	bus_addr_t addr1 = bsht1.addr + off1;
+	bus_addr_t addr2 = bsht2.addr + off2;
 
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
@@ -1030,12 +1042,12 @@
 }
 
 static __inline void
-bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1,
-			bus_size_t off1, bus_space_handle_t bsh2,
+bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsht1,
+			bus_size_t off1, bus_space_handle_t bsht2,
 			bus_size_t off2, size_t count)
 {
-	bus_addr_t addr1 = bsh1 + off1;
-	bus_addr_t addr2 = bsh2 + off2;
+	bus_addr_t addr1 = bsht1.addr + off1;
+	bus_addr_t addr2 = bsht2.addr + off2;
 
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)
@@ -1076,12 +1088,12 @@
 }
 
 static __inline void
-bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
-			bus_size_t off1, bus_space_handle_t bsh2,
+bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsht1,
+			bus_size_t off1, bus_space_handle_t bsht2,
 			bus_size_t off2, size_t count)
 {
-	bus_addr_t addr1 = bsh1 + off1;
-	bus_addr_t addr2 = bsh2 + off2;
+	bus_addr_t addr1 = bsht1.addr + off1;
+	bus_addr_t addr2 = bsht2.addr + off2;
 
 #if defined(_I386_BUS_PIO_H_)
 #if defined(_I386_BUS_MEMIO_H_)


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907032124.PAA33313>