From 365a9fe7089a7724c4c25ecbf13d0326fe98f275 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sat, 23 Dec 2017 13:28:00 +0100
Subject: [PATCH 1/3] WIP X86_64_BUS_SPACE_* -> X86_BUS_SPACE_*

---
 sys/cpu/x86_64/include/bus_dma.h          | 64 +++++++++++++++----------------
 sys/dev/acpica/Osd/OsdHardware.c          |  2 +-
 sys/dev/misc/kbd/atkbdc.c                 |  6 +--
 sys/dev/netif/re/re.c                     |  4 --
 sys/dev/netif/sis/if_sis.c                |  2 +-
 sys/emulation/ndis/hal_var.h              |  9 +----
 sys/platform/pc64/x86_64/busdma_machdep.c |  4 +-
 sys/platform/pc64/x86_64/nexus.c          | 11 ++----
 8 files changed, 43 insertions(+), 59 deletions(-)

diff --git a/sys/cpu/x86_64/include/bus_dma.h b/sys/cpu/x86_64/include/bus_dma.h
index c99fbab336..26b4901ba5 100644
--- a/sys/cpu/x86_64/include/bus_dma.h
+++ b/sys/cpu/x86_64/include/bus_dma.h
@@ -51,8 +51,8 @@ typedef uint64_t bus_space_handle_t;
 /*
  * Values for the amd64 bus space tag, not to be used directly by MI code.
  */
-#define X86_64_BUS_SPACE_IO	0	/* space is i/o space */
-#define X86_64_BUS_SPACE_MEM	1	/* space is mem space */
+#define X86_BUS_SPACE_IO	0	/* space is i/o space */
+#define X86_BUS_SPACE_MEM	1	/* space is mem space */
 
 /*
  * Map a region of device bus space into CPU virtual address space.
@@ -87,7 +87,7 @@ bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t bsh,
 static __inline void *
 bus_space_kva(bus_space_tag_t tag, bus_space_handle_t handle, bus_size_t offset)
 {
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		return ((void *)0);
 	return ((void *)(handle + offset));
 }
@@ -136,7 +136,7 @@ bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
 		 bus_size_t offset)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		return (inb(handle + offset));
 	return (*(volatile u_int8_t *)(handle + offset));
 }
@@ -146,7 +146,7 @@ bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
 		 bus_size_t offset)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		return (inw(handle + offset));
 	return (*(volatile u_int16_t *)(handle + offset));
 }
@@ -156,7 +156,7 @@ bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
 		 bus_size_t offset)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		return (inl(handle + offset));
 	return (*(volatile u_int32_t *)(handle + offset));
 }
@@ -166,7 +166,7 @@ static __inline u_int64_t
 bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle,
 		 bus_size_t offset)
 {
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		panic("bus_space_read_8: illegal on I/O space");
 	return (*(volatile u_int64_t *)(handle + offset));
 }
@@ -196,7 +196,7 @@ bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
 		       bus_size_t offset, u_int8_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		insb(bsh + offset, addr, count);
 	else {
 		__asm __volatile("				\n\
@@ -215,7 +215,7 @@ bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
 		       bus_size_t offset, u_int16_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		insw(bsh + offset, addr, count);
 	else {
 		__asm __volatile("				\n\
@@ -234,7 +234,7 @@ bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
 		       bus_size_t offset, u_int32_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		insl(bsh + offset, addr, count);
 	else {
 		__asm __volatile("				\n\
@@ -278,7 +278,7 @@ bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
 			bus_size_t offset, u_int8_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO) {
+	if (tag == X86_BUS_SPACE_IO) {
 		int _port_ = bsh + offset;
 		__asm __volatile("				\n\
 			cld					\n\
@@ -306,7 +306,7 @@ bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
 			bus_size_t offset, u_int16_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO) {
+	if (tag == X86_BUS_SPACE_IO) {
 		int _port_ = bsh + offset;
 		__asm __volatile("				\n\
 			cld					\n\
@@ -334,7 +334,7 @@ bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
 			bus_size_t offset, u_int32_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO) {
+	if (tag == X86_BUS_SPACE_IO) {
 		int _port_ = bsh + offset;
 		__asm __volatile("				\n\
 			cld					\n\
@@ -383,7 +383,7 @@ bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
 		       bus_size_t offset, u_int8_t value)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		outb(bsh + offset, value);
 	else
 		*(volatile u_int8_t *)(bsh + offset) = value;
@@ -394,7 +394,7 @@ bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh,
 		       bus_size_t offset, u_int16_t value)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		outw(bsh + offset, value);
 	else
 		*(volatile u_int16_t *)(bsh + offset) = value;
@@ -405,7 +405,7 @@ bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
 		       bus_size_t offset, u_int32_t value)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		outl(bsh + offset, value);
 	else
 		*(volatile u_int32_t *)(bsh + offset) = value;
@@ -416,7 +416,7 @@ static __inline void
 bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh,
 		       bus_size_t offset, u_int64_t value)
 {
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		panic("bus_space_write_8: illegal on I/O space");
 	*(volatile u_int64_t *)(bsh + offset) = value;
 }
@@ -449,7 +449,7 @@ bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
 			bus_size_t offset, const u_int8_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		outsb(bsh + offset, addr, count);
 	else {
 		__asm __volatile("				\n\
@@ -468,7 +468,7 @@ bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
 			bus_size_t offset, const u_int16_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		outsw(bsh + offset, addr, count);
 	else {
 		__asm __volatile("				\n\
@@ -487,7 +487,7 @@ bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
 			bus_size_t offset, const u_int32_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		outsl(bsh + offset, addr, count);
 	else {
 		__asm __volatile("				\n\
@@ -532,7 +532,7 @@ bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
 			 bus_size_t offset, const u_int8_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO) {
+	if (tag == X86_BUS_SPACE_IO) {
 		int _port_ = bsh + offset;
 		__asm __volatile("				\n\
 			cld					\n\
@@ -560,7 +560,7 @@ bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
 			 bus_size_t offset, const u_int16_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO) {
+	if (tag == X86_BUS_SPACE_IO) {
 		int _port_ = bsh + offset;
 		__asm __volatile("				\n\
 			cld					\n\
@@ -588,7 +588,7 @@ bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
 			 bus_size_t offset, const u_int32_t *addr, size_t count)
 {
 
-	if (tag == X86_64_BUS_SPACE_IO) {
+	if (tag == X86_BUS_SPACE_IO) {
 		int _port_ = bsh + offset;
 		__asm __volatile("				\n\
 			cld					\n\
@@ -640,7 +640,7 @@ bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
 {
 	bus_space_handle_t addr = bsh + offset;
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		while (count--)
 			outb(addr, value);
 	else
@@ -654,7 +654,7 @@ bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
 {
 	bus_space_handle_t addr = bsh + offset;
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		while (count--)
 			outw(addr, value);
 	else
@@ -668,7 +668,7 @@ bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
 {
 	bus_space_handle_t addr = bsh + offset;
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		while (count--)
 			outl(addr, value);
 	else
@@ -704,7 +704,7 @@ bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
 {
 	bus_space_handle_t addr = bsh + offset;
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		for (; count != 0; count--, addr++)
 			outb(addr, value);
 	else
@@ -718,7 +718,7 @@ bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
 {
 	bus_space_handle_t addr = bsh + offset;
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		for (; count != 0; count--, addr += 2)
 			outw(addr, value);
 	else
@@ -732,7 +732,7 @@ bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
 {
 	bus_space_handle_t addr = bsh + offset;
 
-	if (tag == X86_64_BUS_SPACE_IO)
+	if (tag == X86_BUS_SPACE_IO)
 		for (; count != 0; count--, addr += 4)
 			outl(addr, value);
 	else
@@ -775,7 +775,7 @@ bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1,
 	bus_space_handle_t addr1 = bsh1 + off1;
 	bus_space_handle_t addr2 = bsh2 + off2;
 
-	if (tag == X86_64_BUS_SPACE_IO) {
+	if (tag == X86_BUS_SPACE_IO) {
 		if (addr1 >= addr2) {
 			/* src after dest: copy forward */
 			for (; count != 0; count--, addr1++, addr2++)
@@ -810,7 +810,7 @@ bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1,
 	bus_space_handle_t addr1 = bsh1 + off1;
 	bus_space_handle_t addr2 = bsh2 + off2;
 
-	if (tag == X86_64_BUS_SPACE_IO) {
+	if (tag == X86_BUS_SPACE_IO) {
 		if (addr1 >= addr2) {
 			/* src after dest: copy forward */
 			for (; count != 0; count--, addr1 += 2, addr2 += 2)
@@ -845,7 +845,7 @@ bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
 	bus_space_handle_t addr1 = bsh1 + off1;
 	bus_space_handle_t addr2 = bsh2 + off2;
 
-	if (tag == X86_64_BUS_SPACE_IO) {
+	if (tag == X86_BUS_SPACE_IO) {
 		if (addr1 >= addr2) {
 			/* src after dest: copy forward */
 			for (; count != 0; count--, addr1 += 4, addr2 += 4)
diff --git a/sys/dev/acpica/Osd/OsdHardware.c b/sys/dev/acpica/Osd/OsdHardware.c
index 52753db103..1157f5bcd6 100644
--- a/sys/dev/acpica/Osd/OsdHardware.c
+++ b/sys/dev/acpica/Osd/OsdHardware.c
@@ -49,7 +49,7 @@
  */
 
 #ifdef __x86_64__
-#define ACPI_BUS_SPACE_IO	X86_64_BUS_SPACE_IO
+#define ACPI_BUS_SPACE_IO	X86_BUS_SPACE_IO
 #define ACPI_BUS_HANDLE		0
 #endif
 
diff --git a/sys/dev/misc/kbd/atkbdc.c b/sys/dev/misc/kbd/atkbdc.c
index 0e615068dd..361f90a123 100644
--- a/sys/dev/misc/kbd/atkbdc.c
+++ b/sys/dev/misc/kbd/atkbdc.c
@@ -161,11 +161,7 @@ atkbdc_configure(void)
 #endif
 
 	/* XXX: tag should be passed from the caller */
-#if defined(__i386__)
-	tag = I386_BUS_SPACE_IO;
-#else
-	tag = 0;	/* XXX */
-#endif
+	tag = X86_BUS_SPACE_IO;
 
 #if 0 /* notyet */
 	bus_space_map(tag, port0, IO_KBDSIZE, 0, &h0);
diff --git a/sys/dev/netif/re/re.c b/sys/dev/netif/re/re.c
index 16958e8335..4e910af144 100644
--- a/sys/dev/netif/re/re.c
+++ b/sys/dev/netif/re/re.c
@@ -3892,11 +3892,7 @@ static void re_init_software_variable(struct re_softc *sc)
 
                                 CmacMemPhysAddress &=  0xFFFFFFF0;
                                 /* ioremap MMIO region */
-#ifndef __DragonFly__
                                 sc->re_mapped_cmac_tag = X86_BUS_SPACE_MEM;
-#else
-				sc->re_mapped_cmac_tag = X86_64_BUS_SPACE_MEM;
-#endif
                                 if (bus_space_map(sc->re_mapped_cmac_tag, CmacMemPhysAddress, RE_REGS_SIZE, 0,
                                                   &cmac_ioaddr))
                                         sc->re_dash = 0;
diff --git a/sys/dev/netif/sis/if_sis.c b/sys/dev/netif/sis/if_sis.c
index 5e0c2b565e..bcd15f3f12 100644
--- a/sys/dev/netif/sis/if_sis.c
+++ b/sys/dev/netif/sis/if_sis.c
@@ -403,7 +403,7 @@ sis_read_cmos(struct sis_softc *sc, device_t dev, caddr_t dest, int off,
 	pci_write_config(bridge, 0x48, reg|0x40, 1);
 
 	/* XXX */
-	btag = I386_BUS_SPACE_IO;
+	btag = X86_BUS_SPACE_IO;
 
 	for (i = 0; i < cnt; i++) {
 		bus_space_write_1(btag, 0x0, 0x70, i + off);
diff --git a/sys/emulation/ndis/hal_var.h b/sys/emulation/ndis/hal_var.h
index a3580a19e7..4d1905e627 100644
--- a/sys/emulation/ndis/hal_var.h
+++ b/sys/emulation/ndis/hal_var.h
@@ -35,13 +35,8 @@
 #ifndef _HAL_VAR_H_
 #define _HAL_VAR_H_
 
-#ifdef __x86_64__
-#define NDIS_BUS_SPACE_IO	X86_64_BUS_SPACE_IO
-#define NDIS_BUS_SPACE_MEM	X86_64_BUS_SPACE_MEM
-#else
-#define NDIS_BUS_SPACE_IO	I386_BUS_SPACE_IO
-#define NDIS_BUS_SPACE_MEM	I386_BUS_SPACE_MEM
-#endif
+#define NDIS_BUS_SPACE_IO	X86_BUS_SPACE_IO
+#define NDIS_BUS_SPACE_MEM	X86_BUS_SPACE_MEM
 
 extern image_patch_table hal_functbl[];
 
diff --git a/sys/platform/pc64/x86_64/busdma_machdep.c b/sys/platform/pc64/x86_64/busdma_machdep.c
index 62e1163589..e68ab43a2a 100644
--- a/sys/platform/pc64/x86_64/busdma_machdep.c
+++ b/sys/platform/pc64/x86_64/busdma_machdep.c
@@ -1485,7 +1485,7 @@ bus_space_map(bus_space_tag_t t __unused, bus_addr_t addr, bus_size_t size,
     int flags __unused, bus_space_handle_t *bshp)
 {
 
-	if (t == X86_64_BUS_SPACE_MEM)
+	if (t == X86_BUS_SPACE_MEM)
 		*bshp = (uintptr_t)pmap_mapdev(addr, size);
 	else
 		*bshp = addr;
@@ -1495,6 +1495,6 @@ bus_space_map(bus_space_tag_t t __unused, bus_addr_t addr, bus_size_t size,
 void
 bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, bus_size_t size)
 {
-	if (t == X86_64_BUS_SPACE_MEM)
+	if (t == X86_BUS_SPACE_MEM)
 		pmap_unmapdev(bsh, size);
 }
diff --git a/sys/platform/pc64/x86_64/nexus.c b/sys/platform/pc64/x86_64/nexus.c
index 0a86399e75..1daadf70d4 100644
--- a/sys/platform/pc64/x86_64/nexus.c
+++ b/sys/platform/pc64/x86_64/nexus.c
@@ -71,9 +71,6 @@
 #include "pcib_if.h"
 #endif
 
-#define I386_BUS_SPACE_IO       0       /* space is i/o space */
-#define I386_BUS_SPACE_MEM      1       /* space is mem space */
-
 #define ELF_KERN_STR    ("elf"__XSTRING(__ELF_WORD_SIZE)" kernel")
 
 static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device");
@@ -404,9 +401,9 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
 	rman_set_rid(rv, *rid);
 
 	if (type == SYS_RES_MEMORY) {
-		rman_set_bustag(rv, I386_BUS_SPACE_MEM);
+		rman_set_bustag(rv, X86_BUS_SPACE_MEM);
 	} else if (type == SYS_RES_IOPORT) {
-		rman_set_bustag(rv, I386_BUS_SPACE_IO);
+		rman_set_bustag(rv, X86_BUS_SPACE_IO);
 		rman_set_bushandle(rv, rv->r_start);
 	}
 
@@ -427,7 +424,7 @@ nexus_activate_resource(device_t bus, device_t child, int type, int rid,
 	/*
 	 * If this is a memory resource, map it into the kernel.
 	 */
-	if (rman_get_bustag(r) == I386_BUS_SPACE_MEM) {
+	if (rman_get_bustag(r) == X86_BUS_SPACE_MEM) {
 		caddr_t vaddr = 0;
 
 		if (rman_get_end(r) < 1024 * 1024) {
@@ -460,7 +457,7 @@ nexus_deactivate_resource(device_t bus, device_t child, int type, int rid,
 	/*
 	 * If this is a memory resource, unmap it.
 	 */
-	if ((rman_get_bustag(r) == I386_BUS_SPACE_MEM) &&
+	if ((rman_get_bustag(r) == X86_BUS_SPACE_MEM) &&
 	    (rman_get_end(r) >= 1024 * 1024)) {
 		u_int32_t psize;
 
-- 
2.15.0

