summaryrefslogtreecommitdiff
path: root/sys/arch/amd64
diff options
context:
space:
mode:
Diffstat (limited to 'sys/arch/amd64')
-rw-r--r--sys/arch/amd64/amd64/bus_space.c571
-rw-r--r--sys/arch/amd64/include/bus.h614
2 files changed, 633 insertions, 552 deletions
diff --git a/sys/arch/amd64/amd64/bus_space.c b/sys/arch/amd64/amd64/bus_space.c
index ea2f4844b2c..cdf735a7d4f 100644
--- a/sys/arch/amd64/amd64/bus_space.c
+++ b/sys/arch/amd64/amd64/bus_space.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bus_space.c,v 1.9 2008/06/26 05:42:09 ray Exp $ */
+/* $OpenBSD: bus_space.c,v 1.10 2008/11/21 23:16:16 oga Exp $ */
/* $NetBSD: bus_space.c,v 1.2 2003/03/14 18:47:53 christos Exp $ */
/*-
@@ -358,3 +358,572 @@ bus_space_mmap(bus_space_tag_t t, bus_addr_t addr, off_t off, int prot, int flag
*/
return (atop(addr + off));
}
+
+u_int8_t
+bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
+{
+ return (t == X86_BUS_SPACE_IO ? (inb(h + o)) :
+ (*(volatile u_int8_t *)(h + o)));
+}
+
+u_int16_t
+bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
+{
+ return (t == X86_BUS_SPACE_IO ? (inw(h + o)) :
+ (*(volatile u_int16_t *)(h + o)));
+}
+
+u_int32_t
+bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
+{
+ return (t == X86_BUS_SPACE_IO ? (inl(h + o)) :
+ (*(volatile u_int32_t *)(h + o)));
+}
+
+void
+bus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int8_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ insb(h + o, ptr, cnt);
+ } else {
+ void *dummy1;
+ int dummy2;
+ void *dummy3;
+ int __x;
+ __asm __volatile(" cld ;"
+ "1: movb (%2),%%al ;"
+ " stosb ;"
+ " loop 1b" :
+ "=D" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) :
+ "0" ((ptr)), "1" ((cnt)), "2" (h + o) :
+ "memory");
+ }
+}
+
+void
+bus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int16_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ insw(h + o, ptr, cnt);
+ } else {
+ void *dummy1;
+ int dummy2;
+ void *dummy3;
+ int __x;
+ __asm __volatile(" cld ;"
+ "1: movw (%2),%%ax ;"
+ " stosw ;"
+ " loop 1b" :
+ "=D" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) :
+ "0" ((ptr)), "1" ((cnt)), "2" (h + o) :
+ "memory");
+ }
+}
+
+void
+bus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int32_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ insl(h + o, ptr, cnt);
+ } else {
+ void *dummy1;
+ int dummy2;
+ void *dummy3;
+ int __x;
+ __asm __volatile(" cld ;"
+ "1: movl (%2),%%eax ;"
+ " stosl ;"
+ " loop 1b" :
+ "=D" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) :
+ "0" ((ptr)), "1" ((cnt)), "2" (h + o) :
+ "memory");
+ }
+}
+
+void
+bus_space_read_region_1(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, u_int8_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ int __x;
+ __asm __volatile(" cld ;"
+ "1: inb %w1,%%al ;"
+ " stosb ;"
+ " incl %1 ;"
+ " loop 1b" :
+ "=&a" (__x), "=d" (dummy1), "=D" (dummy2),
+ "=c" (dummy3) :
+ "1" (h + o), "2" (ptr), "3" (cnt) :
+ "memory");
+ } else {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ __asm __volatile(" cld ;"
+ " repne ;"
+ " movsb" :
+ "=S" (dummy1), "=D" (dummy2), "=c" (dummy3) :
+ "0" (h + o), "1" (ptr), "2" (cnt) :
+ "memory");
+ }
+}
+
+void
+bus_space_read_region_2(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, u_int16_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ int __x;
+ __asm __volatile(" cld ;"
+ "1: inw %w1,%%ax ;"
+ " stosw ;"
+ " addl $2,%1 ;"
+ " loop 1b" :
+ "=&a" (__x), "=d" (dummy1), "=D" (dummy2),
+ "=c" (dummy3) :
+ "1" ((h) + (o)), "2" ((ptr)), "3" ((cnt)) :
+ "memory");
+ } else {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ __asm __volatile(" cld ;"
+ " repne ;"
+ " movsw" :
+ "=S" (dummy1), "=D" (dummy2), "=c" (dummy3) :
+ "0" (h + o), "1" (ptr), "2" (cnt) :
+ "memory");
+ }
+}
+
+void
+bus_space_read_region_4(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, u_int32_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ int __x;
+ __asm __volatile("cld ;"
+ "1: inl %w1,%%eax ;"
+ " stosl ;"
+ " addl $4,%1 ;"
+ " loop 1b" :
+ "=&a" (__x), "=d" (dummy1), "=D" (dummy2),
+ "=c" (dummy3) :
+ "1" (h + o), "2" (ptr), "3" (cnt) :
+ "memory");
+ } else {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ __asm __volatile("cld ;"
+ " repne ;"
+ " movsl" :
+ "=S" (dummy1), "=D" (dummy2), "=c" (dummy3) :
+ "0" (h + o), "1" (ptr), "2" (cnt) :
+ "memory");
+ }
+}
+/*
+ * void bus_space_write_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.
+ */
+void
+bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, u_int8_t v)
+{
+ if (t == X86_BUS_SPACE_IO)
+ outb(h + o, v);
+ else
+ ((void)(*(volatile u_int8_t *)(h + o) = v));
+}
+
+void
+bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int16_t v)
+{
+ if ((t) == X86_BUS_SPACE_IO)
+ outw(h + o, v);
+ else
+ ((void)(*(volatile u_int16_t *)(h + o) = v));
+}
+
+void
+bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int32_t v)
+{
+ if ((t) == X86_BUS_SPACE_IO)
+ outl(h + o, v);
+ else
+ ((void)(*(volatile u_int32_t *)(h + o) = v));
+}
+
+void
+bus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, const u_int8_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ outsb(h + o, ptr, cnt);
+ } else {
+ void *dummy1;
+ int dummy2;
+ void *dummy3;
+ int __x;
+ __asm __volatile("cld ;"
+ "1: lodsb ;"
+ " movb %%al,(%2) ;"
+ " loop 1b" :
+ "=S" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) :
+ "0" (ptr), "1" (cnt), "2" (h + o));
+ }
+}
+
+void
+bus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, const u_int16_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ outsw(h + o, ptr, cnt);
+ } else {
+ void *dummy1;
+ int dummy2;
+ void *dummy3;
+ int __x;
+ __asm __volatile("cld ;"
+ "1: lodsw ;"
+ " movw %%ax,(%2) ;"
+ " loop 1b" :
+ "=S" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) :
+ "0" (ptr), "1" (cnt), "2" (h + o));
+ }
+}
+
+void
+bus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, const u_int32_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ outsl(h + o, ptr, cnt);
+ } else {
+ void *dummy1;
+ int dummy2;
+ void *dummy3;
+ int __x;
+ __asm __volatile("cld ;"
+ "1: lodsl ;"
+ " movl %%eax,(%2) ;"
+ " loop 1b" :
+ "=S" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) :
+ "0" (ptr), "1" (cnt), "2" (h + o));
+ }
+}
+
+void
+bus_space_write_region_1(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, const u_int8_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ int __x;
+ __asm __volatile("cld ;"
+ "1: lodsb ;"
+ " outb %%al,%w1 ;"
+ " incl %1 ;"
+ " loop 1b" :
+ "=&a" (__x), "=d" (dummy1), "=S" (dummy2),
+ "=c" (dummy3) :
+ "1" (h + o), "2" (ptr), "3" (cnt) :
+ "memory");
+ } else {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ __asm __volatile("cld ;"
+ " repne ;"
+ " movsb" :
+ "=D" (dummy1), "=S" (dummy2), "=c" (dummy3) :
+ "0" (h + o), "1" (ptr), "2" (cnt) :
+ "memory");
+ }
+}
+
+void
+bus_space_write_region_2(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, const u_int16_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ int __x;
+ __asm __volatile("cld ;"
+ "1: lodsw ;"
+ " outw %%ax,%w1 ;"
+ " addl $2,%1 ;"
+ " loop 1b" :
+ "=&a" (__x), "=d" (dummy1), "=S" (dummy2),
+ "=c" (dummy3) :
+ "1" (h + o), "2" (ptr), "3" (cnt) :
+ "memory");
+ } else {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ __asm __volatile("cld ;"
+ " repne ;"
+ " movsw" :
+ "=D" (dummy1), "=S" (dummy2), "=c" (dummy3) :
+ "0" (h + o), "1" (ptr), "2" (cnt) :
+ "memory");
+ }
+}
+
+void
+bus_space_write_region_4(bus_space_tag_t t, bus_space_handle_t h,
+ bus_size_t o, const u_int32_t *ptr, bus_size_t cnt)
+{
+ if ((t) == X86_BUS_SPACE_IO) {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ int __x;
+ __asm __volatile(" cld ;"
+ "1: lodsl ;"
+ " outl %%eax,%w1 ;"
+ " addl $4,%1 ;"
+ " loop 1b" :
+ "=&a" (__x), "=d" (dummy1), "=S" (dummy2),
+ "=c" (dummy3) :
+ "1" (h + o), "2" (ptr), "3" (cnt) :
+ "memory");
+ } else {
+ int dummy1;
+ void *dummy2;
+ int dummy3;
+ __asm __volatile("cld ;"
+ " repne ;"
+ " movsl" :
+ "=D" (dummy1), "=S" (dummy2), "=c" (dummy3) :
+ "0" (h + o), "1" (ptr), "2" (cnt) :
+ "memory");
+ }
+}
+
+void
+bus_space_set_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int8_t v, size_t c)
+{
+ bus_addr_t addr = h + o;
+
+ if (t == X86_BUS_SPACE_IO)
+ while (c--)
+ outb(addr, v);
+ else
+ while (c--)
+ *(volatile u_int8_t *)(addr) = v;
+}
+
+void
+bus_space_set_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int16_t v, size_t c)
+{
+ bus_addr_t addr = h + o;
+
+ if (t == X86_BUS_SPACE_IO)
+ while (c--)
+ outw(addr, v);
+ else
+ while (c--)
+ *(volatile u_int16_t *)(addr) = v;
+}
+
+void
+bus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int32_t v, size_t c)
+{
+ bus_addr_t addr = h + o;
+
+ if (t == X86_BUS_SPACE_IO)
+ while (c--)
+ outl(addr, v);
+ else
+ while (c--)
+ *(volatile u_int32_t *)(addr) = v;
+}
+
+void
+bus_space_set_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int8_t v, size_t c)
+{
+ bus_addr_t addr = h + o;
+
+ if (t == X86_BUS_SPACE_IO)
+ for (; c != 0; c--, addr++)
+ outb(addr, v);
+ else
+ for (; c != 0; c--, addr++)
+ *(volatile u_int8_t *)(addr) = v;
+}
+
+void
+bus_space_set_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int16_t v, size_t c)
+{
+ bus_addr_t addr = h + o;
+
+ if (t == X86_BUS_SPACE_IO)
+ for (; c != 0; c--, addr += 2)
+ outw(addr, v);
+ else
+ for (; c != 0; c--, addr += 2)
+ *(volatile u_int16_t *)(addr) = v;
+}
+
+void
+bus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
+ u_int32_t v, size_t c)
+{
+ bus_addr_t addr = h + o;
+
+ if (t == X86_BUS_SPACE_IO)
+ for (; c != 0; c--, addr += 4)
+ outl(addr, v);
+ else
+ for (; c != 0; c--, addr += 4)
+ *(volatile u_int32_t *)(addr) = v;
+}
+
+void
+bus_space_copy_region_1(bus_space_tag_t t,
+ bus_space_handle_t h1, bus_size_t o1,
+ bus_space_handle_t h2, bus_size_t o2, size_t c)
+{
+ bus_addr_t addr1 = h1 + o1;
+ bus_addr_t addr2 = h2 + o2;
+
+ if (t == X86_BUS_SPACE_IO) {
+ if (addr1 >= addr2) {
+ /* src after dest: copy forward */
+ for (; c != 0; c--, addr1++, addr2++)
+ outb(addr2, inb(addr1));
+ } else {
+ /* dest after src: copy backwards */
+ for (addr1 += (c - 1), addr2 += (c - 1);
+ c != 0; c--, addr1--, addr2--)
+ outb(addr2, inb(addr1));
+ }
+ } else {
+ if (addr1 >= addr2) {
+ /* src after dest: copy forward */
+ for (; c != 0; c--, addr1++, addr2++)
+ *(volatile u_int8_t *)(addr2) =
+ *(volatile u_int8_t *)(addr1);
+ } else {
+ /* dest after src: copy backwards */
+ for (addr1 += (c - 1), addr2 += (c - 1);
+ c != 0; c--, addr1--, addr2--)
+ *(volatile u_int8_t *)(addr2) =
+ *(volatile u_int8_t *)(addr1);
+ }
+ }
+}
+
+void
+bus_space_copy_region_2(bus_space_tag_t t,
+ bus_space_handle_t h1, bus_size_t o1,
+ bus_space_handle_t h2, bus_size_t o2, size_t c)
+{
+ bus_addr_t addr1 = h1 + o1;
+ bus_addr_t addr2 = h2 + o2;
+
+ if (t == X86_BUS_SPACE_IO) {
+ if (addr1 >= addr2) {
+ /* src after dest: copy forward */
+ for (; c != 0; c--, addr1 += 2, addr2 += 2)
+ outw(addr2, inw(addr1));
+ } else {
+ /* dest after src: copy backwards */
+ for (addr1 += 2 * (c - 1), addr2 += 2 * (c - 1);
+ c != 0; c--, addr1 -= 2, addr2 -= 2)
+ outw(addr2, inw(addr1));
+ }
+ } else {
+ if (addr1 >= addr2) {
+ /* src after dest: copy forward */
+ for (; c != 0; c--, addr1 += 2, addr2 += 2)
+ *(volatile u_int16_t *)(addr2) =
+ *(volatile u_int16_t *)(addr1);
+ } else {
+ /* dest after src: copy backwards */
+ for (addr1 += 2 * (c - 1), addr2 += 2 * (c - 1);
+ c != 0; c--, addr1 -= 2, addr2 -= 2)
+ *(volatile u_int16_t *)(addr2) =
+ *(volatile u_int16_t *)(addr1);
+ }
+ }
+}
+
+void
+bus_space_copy_region_4(bus_space_tag_t t,
+ bus_space_handle_t h1, bus_size_t o1,
+ bus_space_handle_t h2, bus_size_t o2, size_t c)
+{
+ bus_addr_t addr1 = h1 + o1;
+ bus_addr_t addr2 = h2 + o2;
+
+ if (t == X86_BUS_SPACE_IO) {
+ if (addr1 >= addr2) {
+ /* src after dest: copy forward */
+ for (; c != 0; c--, addr1 += 4, addr2 += 4)
+ outl(addr2, inl(addr1));
+ } else {
+ /* dest after src: copy backwards */
+ for (addr1 += 4 * (c - 1), addr2 += 4 * (c - 1);
+ c != 0; c--, addr1 -= 4, addr2 -= 4)
+ outl(addr2, inl(addr1));
+ }
+ } else {
+ if (addr1 >= addr2) {
+ /* src after dest: copy forward */
+ for (; c != 0; c--, addr1 += 4, addr2 += 4)
+ *(volatile u_int32_t *)(addr2) =
+ *(volatile u_int32_t *)(addr1);
+ } else {
+ /* dest after src: copy backwards */
+ for (addr1 += 4 * (c - 1), addr2 += 4 * (c - 1);
+ c != 0; c--, addr1 -= 4, addr2 -= 4)
+ *(volatile u_int32_t *)(addr2) =
+ *(volatile u_int32_t *)(addr1);
+ }
+ }
+}
+
+void
+bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
+ bus_size_t offset, bus_size_t len, int flags)
+{
+ if (flags == (BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE))
+ __asm __volatile("mfence");
+ else if (flags == BUS_SPACE_BARRIER_WRITE)
+ __asm __volatile("sfence");
+ else
+ __asm __volatile("lfence");
+}
+
diff --git a/sys/arch/amd64/include/bus.h b/sys/arch/amd64/include/bus.h
index f83050835ea..d566a285691 100644
--- a/sys/arch/amd64/include/bus.h
+++ b/sys/arch/amd64/include/bus.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bus.h,v 1.10 2008/06/26 05:42:09 ray Exp $ */
+/* $OpenBSD: bus.h,v 1.11 2008/11/21 23:16:16 oga Exp $ */
/* $NetBSD: bus.h,v 1.6 1996/11/10 03:19:25 thorpej Exp $ */
/*-
@@ -133,18 +133,14 @@ int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
* Read a 1, 2, 4, or 8 byte quantity from bus space
* described by tag/handle/offset.
*/
+u_int8_t bus_space_read_1(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t);
-#define bus_space_read_1(t, h, o) \
- ((t) == X86_BUS_SPACE_IO ? (inb((h) + (o))) : \
- (*(volatile u_int8_t *)((h) + (o))))
+u_int16_t bus_space_read_2(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t);
-#define bus_space_read_2(t, h, o) \
- ((t) == X86_BUS_SPACE_IO ? (inw((h) + (o))) : \
- (*(volatile u_int16_t *)((h) + (o))))
-
-#define bus_space_read_4(t, h, o) \
- ((t) == X86_BUS_SPACE_IO ? (inl((h) + (o))) : \
- (*(volatile u_int32_t *)((h) + (o))))
+u_int32_t bus_space_read_4(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t);
#if 0 /* Cause a link error for bus_space_read_8 */
#define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
@@ -159,65 +155,14 @@ int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
* described by tag/handle/offset and copy into buffer provided.
*/
-#define bus_space_read_multi_1(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- insb((h) + (o), (ptr), (cnt)); \
- } else { \
- void *dummy1; \
- int dummy2; \
- void *dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: movb (%2),%%al ; \
- stosb ; \
- loop 1b" : \
- "=D" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) : \
- "0" ((ptr)), "1" ((cnt)), "2" ((h) + (o)) : \
- "memory"); \
- } \
-} while (/* CONSTCOND */ 0)
-
-#define bus_space_read_multi_2(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- insw((h) + (o), (ptr), (cnt)); \
- } else { \
- void *dummy1; \
- int dummy2; \
- void *dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: movw (%2),%%ax ; \
- stosw ; \
- loop 1b" : \
- "=D" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) : \
- "0" ((ptr)), "1" ((cnt)), "2" ((h) + (o)) : \
- "memory"); \
- } \
-} while (/* CONSTCOND */ 0)
-
-#define bus_space_read_multi_4(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- insl((h) + (o), (ptr), (cnt)); \
- } else { \
- void *dummy1; \
- int dummy2; \
- void *dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: movl (%2),%%eax ; \
- stosl ; \
- loop 1b" : \
- "=D" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) : \
- "0" ((ptr)), "1" ((cnt)), "2" ((h) + (o)) : \
- "memory"); \
- } \
-} while (/* CONSTCOND */ 0)
+void bus_space_read_multi_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
+ u_int8_t *, bus_size_t);
+
+void bus_space_read_multi_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
+ u_int16_t *, bus_size_t);
+
+void bus_space_read_multi_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
+ u_int32_t *, bus_size_t);
#if 0 /* Cause a link error for bus_space_read_multi_8 */
#define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
@@ -254,98 +199,13 @@ do { \
* buffer provided.
*/
-#define bus_space_read_region_1(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: inb %w1,%%al ; \
- stosb ; \
- incl %1 ; \
- loop 1b" : \
- "=&a" (__x), "=d" (dummy1), "=D" (dummy2), \
- "=c" (dummy3) : \
- "1" ((h) + (o)), "2" ((ptr)), "3" ((cnt)) : \
- "memory"); \
- } else { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- __asm __volatile(" \
- cld ; \
- repne ; \
- movsb" : \
- "=S" (dummy1), "=D" (dummy2), "=c" (dummy3) : \
- "0" ((h) + (o)), "1" ((ptr)), "2" ((cnt)) : \
- "memory"); \
- } \
-} while (/* CONSTCOND */ 0)
-
-#define bus_space_read_region_2(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: inw %w1,%%ax ; \
- stosw ; \
- addl $2,%1 ; \
- loop 1b" : \
- "=&a" (__x), "=d" (dummy1), "=D" (dummy2), \
- "=c" (dummy3) : \
- "1" ((h) + (o)), "2" ((ptr)), "3" ((cnt)) : \
- "memory"); \
- } else { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- __asm __volatile(" \
- cld ; \
- repne ; \
- movsw" : \
- "=S" (dummy1), "=D" (dummy2), "=c" (dummy3) : \
- "0" ((h) + (o)), "1" ((ptr)), "2" ((cnt)) : \
- "memory"); \
- } \
-} while (/* CONSTCOND */ 0)
-
-#define bus_space_read_region_4(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: inl %w1,%%eax ; \
- stosl ; \
- addl $4,%1 ; \
- loop 1b" : \
- "=&a" (__x), "=d" (dummy1), "=D" (dummy2), \
- "=c" (dummy3) : \
- "1" ((h) + (o)), "2" ((ptr)), "3" ((cnt)) : \
- "memory"); \
- } else { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- __asm __volatile(" \
- cld ; \
- repne ; \
- movsl" : \
- "=S" (dummy1), "=D" (dummy2), "=c" (dummy3) : \
- "0" ((h) + (o)), "1" ((ptr)), "2" ((cnt)) : \
- "memory"); \
- } \
-} while (/* CONSTCOND */ 0)
+void bus_space_read_region_1(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int8_t *, bus_size_t);
+
+void bus_space_read_region_2(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int16_t *, bus_size_t);
+void bus_space_read_region_4(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int32_t *, bus_size_t);
#define bus_space_read_region_stream_1 bus_space_read_region_1
#if 0 /* Cause a link error for bus_space_read_region_8 */
@@ -383,26 +243,14 @@ do { \
* described by tag/handle/offset.
*/
-#define bus_space_write_1(t, h, o, v) do { \
- if ((t) == X86_BUS_SPACE_IO) \
- outb((h) + (o), (v)); \
- else \
- ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))); \
-} while (0)
-
-#define bus_space_write_2(t, h, o, v) do { \
- if ((t) == X86_BUS_SPACE_IO) \
- outw((h) + (o), (v)); \
- else \
- ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))); \
-} while (0)
-
-#define bus_space_write_4(t, h, o, v) do { \
- if ((t) == X86_BUS_SPACE_IO) \
- outl((h) + (o), (v)); \
- else \
- ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))); \
-} while (0)
+void bus_space_write_1(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int8_t);
+
+void bus_space_write_2(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int16_t);
+
+void bus_space_write_4(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int32_t);
#if 0 /* Cause a link error for bus_space_write_8 */
#define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
@@ -417,62 +265,12 @@ do { \
* provided to bus space described by tag/handle/offset.
*/
-#define bus_space_write_multi_1(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- outsb((h) + (o), (ptr), (cnt)); \
- } else { \
- void *dummy1; \
- int dummy2; \
- void *dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: lodsb ; \
- movb %%al,(%2) ; \
- loop 1b" : \
- "=S" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) : \
- "0" ((ptr)), "1" ((cnt)), "2" ((h) + (o))); \
- } \
-} while (/* CONSTCOND */ 0)
-
-#define bus_space_write_multi_2(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- outsw((h) + (o), (ptr), (cnt)); \
- } else { \
- void *dummy1; \
- int dummy2; \
- void *dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: lodsw ; \
- movw %%ax,(%2) ; \
- loop 1b" : \
- "=S" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) : \
- "0" ((ptr)), "1" ((cnt)), "2" ((h) + (o))); \
- } \
-} while (/* CONSTCOND */ 0)
-
-#define bus_space_write_multi_4(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- outsl((h) + (o), (ptr), (cnt)); \
- } else { \
- void *dummy1; \
- int dummy2; \
- void *dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: lodsl ; \
- movl %%eax,(%2) ; \
- loop 1b" : \
- "=S" (dummy1), "=c" (dummy2), "=r" (dummy3), "=&a" (__x) : \
- "0" ((ptr)), "1" ((cnt)), "2" ((h) + (o))); \
- } \
-} while (/* CONSTCOND */ 0)
+void bus_space_write_multi_1(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, const u_int8_t *, bus_size_t);
+void bus_space_write_multi_2(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, const u_int16_t *, bus_size_t);
+void bus_space_write_multi_4(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, const u_int32_t *, bus_size_t);
#if 0 /* Cause a link error for bus_space_write_multi_8 */
#define bus_space_write_multi_8(t, h, o, a, c) \
@@ -509,98 +307,13 @@ do { \
* to bus space described by tag/handle starting at `offset'.
*/
-#define bus_space_write_region_1(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: lodsb ; \
- outb %%al,%w1 ; \
- incl %1 ; \
- loop 1b" : \
- "=&a" (__x), "=d" (dummy1), "=S" (dummy2), \
- "=c" (dummy3) : \
- "1" ((h) + (o)), "2" ((ptr)), "3" ((cnt)) : \
- "memory"); \
- } else { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- __asm __volatile(" \
- cld ; \
- repne ; \
- movsb" : \
- "=D" (dummy1), "=S" (dummy2), "=c" (dummy3) : \
- "0" ((h) + (o)), "1" ((ptr)), "2" ((cnt)) : \
- "memory"); \
- } \
-} while (/* CONSTCOND */ 0)
-
-#define bus_space_write_region_2(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: lodsw ; \
- outw %%ax,%w1 ; \
- addl $2,%1 ; \
- loop 1b" : \
- "=&a" (__x), "=d" (dummy1), "=S" (dummy2), \
- "=c" (dummy3) : \
- "1" ((h) + (o)), "2" ((ptr)), "3" ((cnt)) : \
- "memory"); \
- } else { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- __asm __volatile(" \
- cld ; \
- repne ; \
- movsw" : \
- "=D" (dummy1), "=S" (dummy2), "=c" (dummy3) : \
- "0" ((h) + (o)), "1" ((ptr)), "2" ((cnt)) : \
- "memory"); \
- } \
-} while (/* CONSTCOND */ 0)
-
-#define bus_space_write_region_4(t, h, o, ptr, cnt) \
-do { \
- if ((t) == X86_BUS_SPACE_IO) { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- int __x; \
- __asm __volatile(" \
- cld ; \
- 1: lodsl ; \
- outl %%eax,%w1 ; \
- addl $4,%1 ; \
- loop 1b" : \
- "=&a" (__x), "=d" (dummy1), "=S" (dummy2), \
- "=c" (dummy3) : \
- "1" ((h) + (o)), "2" ((ptr)), "3" ((cnt)) : \
- "memory"); \
- } else { \
- int dummy1; \
- void *dummy2; \
- int dummy3; \
- __asm __volatile(" \
- cld ; \
- repne ; \
- movsl" : \
- "=D" (dummy1), "=S" (dummy2), "=c" (dummy3) : \
- "0" ((h) + (o)), "1" ((ptr)), "2" ((cnt)) : \
- "memory"); \
- } \
-} while (/* CONSTCOND */ 0)
+void bus_space_write_region_1(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, const u_int8_t *, bus_size_t);
+void bus_space_write_region_2(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, const u_int16_t *, bus_size_t);
+void bus_space_write_region_4(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, const u_int32_t *, bus_size_t);
+
#if 0 /* Cause a link error for bus_space_write_region_8 */
#define bus_space_write_region_8 \
@@ -638,54 +351,12 @@ do { \
* by tag/handle/offset `count' times.
*/
-static __inline void bus_space_set_multi_1(bus_space_tag_t,
- bus_space_handle_t, bus_size_t, u_int8_t, size_t);
-static __inline void bus_space_set_multi_2(bus_space_tag_t,
- bus_space_handle_t, bus_size_t, u_int16_t, size_t);
-static __inline void bus_space_set_multi_4(bus_space_tag_t,
- bus_space_handle_t, bus_size_t, u_int32_t, size_t);
-
-static __inline void
-bus_space_set_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
- u_int8_t v, size_t c)
-{
- bus_addr_t addr = h + o;
-
- if (t == X86_BUS_SPACE_IO)
- while (c--)
- outb(addr, v);
- else
- while (c--)
- *(volatile u_int8_t *)(addr) = v;
-}
-
-static __inline void
-bus_space_set_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
- u_int16_t v, size_t c)
-{
- bus_addr_t addr = h + o;
-
- if (t == X86_BUS_SPACE_IO)
- while (c--)
- outw(addr, v);
- else
- while (c--)
- *(volatile u_int16_t *)(addr) = v;
-}
-
-static __inline void
-bus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
- u_int32_t v, size_t c)
-{
- bus_addr_t addr = h + o;
-
- if (t == X86_BUS_SPACE_IO)
- while (c--)
- outl(addr, v);
- else
- while (c--)
- *(volatile u_int32_t *)(addr) = v;
-}
+void bus_space_set_multi_1(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int8_t, size_t);
+void bus_space_set_multi_2(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int16_t, size_t);
+void bus_space_set_multi_4(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int32_t, size_t);
#if 0 /* Cause a link error for bus_space_set_multi_8 */
#define bus_space_set_multi_8 \
@@ -701,54 +372,12 @@ bus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
* by tag/handle starting at `offset'.
*/
-static __inline void bus_space_set_region_1(bus_space_tag_t,
- bus_space_handle_t, bus_size_t, u_int8_t, size_t);
-static __inline void bus_space_set_region_2(bus_space_tag_t,
- bus_space_handle_t, bus_size_t, u_int16_t, size_t);
-static __inline void bus_space_set_region_4(bus_space_tag_t,
- bus_space_handle_t, bus_size_t, u_int32_t, size_t);
-
-static __inline void
-bus_space_set_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
- u_int8_t v, size_t c)
-{
- bus_addr_t addr = h + o;
-
- if (t == X86_BUS_SPACE_IO)
- for (; c != 0; c--, addr++)
- outb(addr, v);
- else
- for (; c != 0; c--, addr++)
- *(volatile u_int8_t *)(addr) = v;
-}
-
-static __inline void
-bus_space_set_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
- u_int16_t v, size_t c)
-{
- bus_addr_t addr = h + o;
-
- if (t == X86_BUS_SPACE_IO)
- for (; c != 0; c--, addr += 2)
- outw(addr, v);
- else
- for (; c != 0; c--, addr += 2)
- *(volatile u_int16_t *)(addr) = v;
-}
-
-static __inline void
-bus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
- u_int32_t v, size_t c)
-{
- bus_addr_t addr = h + o;
-
- if (t == X86_BUS_SPACE_IO)
- for (; c != 0; c--, addr += 4)
- outl(addr, v);
- else
- for (; c != 0; c--, addr += 4)
- *(volatile u_int32_t *)(addr) = v;
-}
+void bus_space_set_region_1(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int8_t, size_t);
+void bus_space_set_region_2(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int16_t, size_t);
+void bus_space_set_region_4(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, u_int32_t, size_t);
#if 0 /* Cause a link error for bus_space_set_region_8 */
#define bus_space_set_region_8 \
@@ -770,120 +399,12 @@ bus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
#define bus_space_copy_4 bus_space_copy_region_4
#define bus_space_copy_8 bus_space_copy_region_8
-static __inline void bus_space_copy_region_1(bus_space_tag_t,
- bus_space_handle_t, bus_size_t, bus_space_handle_t,
- bus_size_t, size_t);
-static __inline void bus_space_copy_region_2(bus_space_tag_t,
- bus_space_handle_t, bus_size_t, bus_space_handle_t,
- bus_size_t, size_t);
-static __inline void bus_space_copy_region_4(bus_space_tag_t,
- bus_space_handle_t, bus_size_t, bus_space_handle_t,
- bus_size_t, size_t);
-
-static __inline void
-bus_space_copy_region_1(bus_space_tag_t t,
- bus_space_handle_t h1, bus_size_t o1,
- bus_space_handle_t h2, bus_size_t o2, size_t c)
-{
- bus_addr_t addr1 = h1 + o1;
- bus_addr_t addr2 = h2 + o2;
-
- if (t == X86_BUS_SPACE_IO) {
- if (addr1 >= addr2) {
- /* src after dest: copy forward */
- for (; c != 0; c--, addr1++, addr2++)
- outb(addr2, inb(addr1));
- } else {
- /* dest after src: copy backwards */
- for (addr1 += (c - 1), addr2 += (c - 1);
- c != 0; c--, addr1--, addr2--)
- outb(addr2, inb(addr1));
- }
- } else {
- if (addr1 >= addr2) {
- /* src after dest: copy forward */
- for (; c != 0; c--, addr1++, addr2++)
- *(volatile u_int8_t *)(addr2) =
- *(volatile u_int8_t *)(addr1);
- } else {
- /* dest after src: copy backwards */
- for (addr1 += (c - 1), addr2 += (c - 1);
- c != 0; c--, addr1--, addr2--)
- *(volatile u_int8_t *)(addr2) =
- *(volatile u_int8_t *)(addr1);
- }
- }
-}
-
-static __inline void
-bus_space_copy_region_2(bus_space_tag_t t,
- bus_space_handle_t h1, bus_size_t o1,
- bus_space_handle_t h2, bus_size_t o2, size_t c)
-{
- bus_addr_t addr1 = h1 + o1;
- bus_addr_t addr2 = h2 + o2;
-
- if (t == X86_BUS_SPACE_IO) {
- if (addr1 >= addr2) {
- /* src after dest: copy forward */
- for (; c != 0; c--, addr1 += 2, addr2 += 2)
- outw(addr2, inw(addr1));
- } else {
- /* dest after src: copy backwards */
- for (addr1 += 2 * (c - 1), addr2 += 2 * (c - 1);
- c != 0; c--, addr1 -= 2, addr2 -= 2)
- outw(addr2, inw(addr1));
- }
- } else {
- if (addr1 >= addr2) {
- /* src after dest: copy forward */
- for (; c != 0; c--, addr1 += 2, addr2 += 2)
- *(volatile u_int16_t *)(addr2) =
- *(volatile u_int16_t *)(addr1);
- } else {
- /* dest after src: copy backwards */
- for (addr1 += 2 * (c - 1), addr2 += 2 * (c - 1);
- c != 0; c--, addr1 -= 2, addr2 -= 2)
- *(volatile u_int16_t *)(addr2) =
- *(volatile u_int16_t *)(addr1);
- }
- }
-}
-
-static __inline void
-bus_space_copy_region_4(bus_space_tag_t t,
- bus_space_handle_t h1, bus_size_t o1,
- bus_space_handle_t h2, bus_size_t o2, size_t c)
-{
- bus_addr_t addr1 = h1 + o1;
- bus_addr_t addr2 = h2 + o2;
-
- if (t == X86_BUS_SPACE_IO) {
- if (addr1 >= addr2) {
- /* src after dest: copy forward */
- for (; c != 0; c--, addr1 += 4, addr2 += 4)
- outl(addr2, inl(addr1));
- } else {
- /* dest after src: copy backwards */
- for (addr1 += 4 * (c - 1), addr2 += 4 * (c - 1);
- c != 0; c--, addr1 -= 4, addr2 -= 4)
- outl(addr2, inl(addr1));
- }
- } else {
- if (addr1 >= addr2) {
- /* src after dest: copy forward */
- for (; c != 0; c--, addr1 += 4, addr2 += 4)
- *(volatile u_int32_t *)(addr2) =
- *(volatile u_int32_t *)(addr1);
- } else {
- /* dest after src: copy backwards */
- for (addr1 += 4 * (c - 1), addr2 += 4 * (c - 1);
- c != 0; c--, addr1 -= 4, addr2 -= 4)
- *(volatile u_int32_t *)(addr2) =
- *(volatile u_int32_t *)(addr1);
- }
- }
-}
+void bus_space_copy_region_1(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, bus_space_handle_t, bus_size_t, size_t);
+void bus_space_copy_region_2(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, bus_space_handle_t, bus_size_t, size_t);
+void bus_space_copy_region_4(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, bus_space_handle_t, bus_size_t, size_t);
#if 0 /* Cause a link error for bus_space_copy_8 */
#define bus_space_copy_8 \
@@ -899,17 +420,8 @@ bus_space_copy_region_4(bus_space_tag_t t,
#define BUS_BARRIER_READ BUS_SPACE_BARRIER_READ
#define BUS_BARRIER_WRITE BUS_SPACE_BARRIER_WRITE
-static __inline void
-bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
- bus_size_t offset, bus_size_t len, int flags)
-{
- if (flags == (BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE))
- __asm __volatile("mfence");
- else if (flags == BUS_SPACE_BARRIER_WRITE)
- __asm __volatile("sfence");
- else
- __asm __volatile("lfence");
-}
+void bus_space_barrier(bus_space_tag_t, bus_space_handle_t,
+ bus_size_t, bus_size_t, int);
#define BUS_SPACE_MAP_CACHEABLE 0x0001
#define BUS_SPACE_MAP_LINEAR 0x0002