Port-xen archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

splitting mainbus.c



Hello,

Please find below a patch to split up our mainbus.c entry points into
separate entry points for amd64, i386, xen.

The rationale is to allow for "platform" specific combinations of busses
whose config(9) traversal are constrained in specific ways to be
separated out from the minimum set of bus attachments common to all
"platform"s (cpubus and ioapicbus).

This allows us to dynamically decide combinations of "platform" specific
traversals.

Here's a specific potential usecase.

With a xen PVHVM kernel, there could be two ways to attach pci.

pci*            at hypervisor? bus ?

and

pci*    at mainbus? bus ?

The former route could be chosen when a hypervisor is detected, while
the latter fallback route could be chosen when this is not the case -
ie; the PVHVM kernel decides it's running on 'native'.

This could be accomplished by deciding to run:

x86_cpubus_attach() followed by xen_mainbus_attach() in the case of a
detected hypervisor, whereas in the second case it could run
x86_cpubus_attach() followed by amd64_mainbus_attach(), for eg: to
follow the regular 'native' device configuration path.

Thoughts ?

-- 
~cherry

diff -r 34587dc62568 sys/arch/amd64/amd64/amd64_mainbus.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amd64/amd64/amd64_mainbus.c	Sat Dec 22 02:30:45 2018 +0530
@@ -0,0 +1,250 @@
+/*	$NetBSD: mainbus.c,v 1.39 2018/12/02 08:19:44 cherry Exp $	*/
+
+/*
+ * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Christopher G. Demetriou
+ *	for the NetBSD Project.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.39 2018/12/02 08:19:44 cherry Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/reboot.h>
+#include <sys/bus.h>
+
+#include <dev/isa/isavar.h>
+#include <dev/pci/pcivar.h>
+
+#include <dev/isa/isareg.h>
+
+#include "pci.h"
+#include "isa.h"
+#include "isadma.h"
+#include "acpica.h"
+#include "ipmi.h"
+
+#include "opt_acpi.h"
+#include "opt_mpbios.h"
+#include "opt_pcifixup.h"
+
+#include <machine/cpuvar.h>
+#include <machine/i82093var.h>
+#include <machine/mpbiosvar.h>
+#include <machine/mpacpi.h>
+
+#if NACPICA > 0
+#include <dev/acpi/acpivar.h>
+#endif
+
+#if NIPMI > 0
+#include <x86/ipmivar.h>
+#endif
+
+#if NPCI > 0
+#if defined(PCI_BUS_FIXUP)
+#include <arch/x86/pci/pci_bus_fixup.h>
+#if defined(PCI_ADDR_FIXUP)
+#include <arch/x86/pci/pci_addr_fixup.h>
+#endif
+#endif
+#ifdef __HAVE_PCI_MSI_MSIX
+#include <arch/x86/pci/msipic.h>
+#endif /* __HAVE_PCI_MSI_MSIX */
+#endif
+
+/*
+ * XXXfvdl ACPI
+ */
+
+int	amd64_mainbus_match(device_t, cfdata_t, void *);
+void	amd64_mainbus_attach(device_t, device_t, void *);
+int	amd64_mainbus_print(void *, const char *);
+
+union amd64_mainbus_attach_args {
+	const char *mba_busname;		/* first elem of all */
+	struct pcibus_attach_args mba_pba;
+	struct isabus_attach_args mba_iba;
+	struct cpu_attach_args mba_caa;
+#if NACPICA > 0
+	struct acpibus_attach_args mba_acpi;
+#endif
+	struct apic_attach_args aaa_caa;
+#if NIPMI > 0
+	struct ipmi_attach_args mba_ipmi;
+#endif
+};
+
+/*
+ * This is set when the ISA bus is attached.  If it's not set by the
+ * time it's checked below, then mainbus attempts to attach an ISA.
+ */
+int	isa_has_been_seen;
+struct x86_isa_chipset x86_isa_chipset;
+#if NISA > 0
+static const struct isabus_attach_args mba_iba = {
+	._iba_busname = "isa",
+	.iba_dmat = &isa_bus_dma_tag,
+	.iba_ic = &x86_isa_chipset
+};
+#endif
+
+#if defined(MPBIOS) || NACPICA > 0
+struct mp_bus *mp_busses;
+int mp_nbus;
+struct mp_intr_map *mp_intrs;
+int mp_nintr;
+ 
+int mp_isa_bus = -1;
+int mp_eisa_bus = -1;
+
+extern bool acpi_present;
+extern bool mpacpi_active;
+
+# ifdef MPVERBOSE
+#  if MPVERBOSE > 0
+int mp_verbose = MPVERBOSE;
+#  else
+int mp_verbose = 1;
+#  endif
+# else
+int mp_verbose = 0;
+# endif
+#endif
+
+
+/*
+ * Probe for the mainbus; always succeeds.
+ */
+int
+amd64_mainbus_match(device_t parent, cfdata_t match, void *aux)
+{
+
+	return 1;
+}
+
+/*
+ * Attach the mainbus.
+ */
+void
+amd64_mainbus_attach(device_t parent, device_t self, void *aux)
+{
+#if NPCI > 0 || NACPICA > 0 || NIPMI > 0
+	union amd64_mainbus_attach_args mba;
+#endif
+
+#if NISADMA > 0 && NACPICA > 0
+	/*
+	 * ACPI needs ISA DMA initialized before they start probing.
+	 */
+	isa_dmainit(&x86_isa_chipset, x86_bus_space_io, &isa_bus_dma_tag,
+	    self);
+#endif
+
+#if NACPICA > 0
+	if (acpi_present) {
+		mba.mba_acpi.aa_iot = x86_bus_space_io;
+		mba.mba_acpi.aa_memt = x86_bus_space_mem;
+		mba.mba_acpi.aa_pc = NULL;
+		mba.mba_acpi.aa_pciflags =
+		    PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
+		    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
+		    PCI_FLAGS_MWI_OKAY;
+		mba.mba_acpi.aa_ic = &x86_isa_chipset;
+		mba.mba_acpi.aa_dmat = &pci_bus_dma_tag;
+		mba.mba_acpi.aa_dmat64 = &pci_bus_dma64_tag;
+		config_found_ia(self, "acpibus", &mba.mba_acpi, 0);
+	}
+#endif
+
+#if NIPMI > 0
+	memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
+	mba.mba_ipmi.iaa_iot = x86_bus_space_io;
+	mba.mba_ipmi.iaa_memt = x86_bus_space_mem;
+	if (ipmi_probe(&mba.mba_ipmi))
+		config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
+#endif
+
+#if NPCI > 0
+	if (pci_mode_detect() != 0) {
+		int npcibus = 0;
+
+		mba.mba_pba.pba_iot = x86_bus_space_io;
+		mba.mba_pba.pba_memt = x86_bus_space_mem;
+		mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
+		mba.mba_pba.pba_dmat64 = &pci_bus_dma64_tag;
+		mba.mba_pba.pba_pc = NULL;
+		mba.mba_pba.pba_flags =
+		    PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
+		    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
+		    PCI_FLAGS_MWI_OKAY;
+		mba.mba_pba.pba_bus = 0;
+		mba.mba_pba.pba_bridgetag = NULL;
+#if NACPICA > 0 && defined(ACPI_SCANPCI)
+		if (npcibus == 0 && mpacpi_active)
+			npcibus = mp_pci_scan(self, &mba.mba_pba, pcibusprint);
+#endif
+#if defined(MPBIOS) && defined(MPBIOS_SCANPCI)
+		if (npcibus == 0 && mpbios_scanned != 0)
+			npcibus = mp_pci_scan(self, &mba.mba_pba, pcibusprint);
+#endif
+		if (npcibus == 0)
+			config_found_ia(self, "pcibus", &mba.mba_pba,
+			    pcibusprint);
+
+#if NACPICA > 0
+		if (mp_verbose)
+			acpi_pci_link_state();
+#endif
+
+	}
+#endif
+
+#if NISA > 0
+	if (isa_has_been_seen == 0) {
+		mba.mba_iba = mba_iba;
+		mba.mba_iba.iba_iot = x86_bus_space_io;
+		mba.mba_iba.iba_memt = x86_bus_space_mem;
+		config_found_ia(self, "isabus", &mba.mba_iba, isabusprint);
+	}
+#endif
+
+	if (!pmf_device_register(self, NULL, NULL))
+		aprint_error_dev(self, "couldn't establish power handler\n");
+}
+
+int
+amd64_mainbus_print(void *aux, const char *pnp)
+{
+	union amd64_mainbus_attach_args *mba = aux;
+
+	if (pnp)
+		aprint_normal("%s at %s", mba->mba_busname, pnp);
+	return (UNCONF);
+}
diff -r 34587dc62568 sys/arch/amd64/amd64/mainbus.c
--- a/sys/arch/amd64/amd64/mainbus.c	Thu Dec 20 16:18:32 2018 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,326 +0,0 @@
-/*	$NetBSD: mainbus.c,v 1.39 2018/12/02 08:19:44 cherry Exp $	*/
-
-/*
- * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by Christopher G. Demetriou
- *	for the NetBSD Project.
- * 4. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.39 2018/12/02 08:19:44 cherry Exp $");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/device.h>
-#include <sys/reboot.h>
-#include <sys/bus.h>
-
-#include <dev/isa/isavar.h>
-#include <dev/pci/pcivar.h>
-
-#include <dev/isa/isareg.h>
-
-#include "pci.h"
-#include "isa.h"
-#include "isadma.h"
-#include "acpica.h"
-#include "ipmi.h"
-
-#include "opt_acpi.h"
-#include "opt_mpbios.h"
-#include "opt_pcifixup.h"
-
-#include <machine/cpuvar.h>
-#include <machine/i82093var.h>
-#include <machine/mpbiosvar.h>
-#include <machine/mpacpi.h>
-
-#if NACPICA > 0
-#include <dev/acpi/acpivar.h>
-#endif
-
-#if NIPMI > 0
-#include <x86/ipmivar.h>
-#endif
-
-#if NPCI > 0
-#if defined(PCI_BUS_FIXUP)
-#include <arch/x86/pci/pci_bus_fixup.h>
-#if defined(PCI_ADDR_FIXUP)
-#include <arch/x86/pci/pci_addr_fixup.h>
-#endif
-#endif
-#ifdef __HAVE_PCI_MSI_MSIX
-#include <arch/x86/pci/msipic.h>
-#endif /* __HAVE_PCI_MSI_MSIX */
-#endif
-
-/*
- * XXXfvdl ACPI
- */
-
-int	mainbus_match(device_t, cfdata_t, void *);
-void	mainbus_attach(device_t, device_t, void *);
-
-CFATTACH_DECL_NEW(mainbus, 0,
-    mainbus_match, mainbus_attach, NULL, NULL);
-
-int	mainbus_print(void *, const char *);
-
-union mainbus_attach_args {
-	const char *mba_busname;		/* first elem of all */
-	struct pcibus_attach_args mba_pba;
-	struct isabus_attach_args mba_iba;
-	struct cpu_attach_args mba_caa;
-#if NACPICA > 0
-	struct acpibus_attach_args mba_acpi;
-#endif
-	struct apic_attach_args aaa_caa;
-#if NIPMI > 0
-	struct ipmi_attach_args mba_ipmi;
-#endif
-};
-
-/*
- * This is set when the ISA bus is attached.  If it's not set by the
- * time it's checked below, then mainbus attempts to attach an ISA.
- */
-int	isa_has_been_seen;
-struct x86_isa_chipset x86_isa_chipset;
-#if NISA > 0
-static const struct isabus_attach_args mba_iba = {
-	._iba_busname = "isa",
-	.iba_dmat = &isa_bus_dma_tag,
-	.iba_ic = &x86_isa_chipset
-};
-#endif
-
-#if defined(MPBIOS) || NACPICA > 0
-struct mp_bus *mp_busses;
-int mp_nbus;
-struct mp_intr_map *mp_intrs;
-int mp_nintr;
- 
-int mp_isa_bus = -1;
-int mp_eisa_bus = -1;
-
-bool acpi_present;
-bool mpacpi_active;
-
-# ifdef MPVERBOSE
-#  if MPVERBOSE > 0
-int mp_verbose = MPVERBOSE;
-#  else
-int mp_verbose = 1;
-#  endif
-# else
-int mp_verbose = 0;
-# endif
-#endif
-
-
-/*
- * Probe for the mainbus; always succeeds.
- */
-int
-mainbus_match(device_t parent, cfdata_t match, void *aux)
-{
-
-	return 1;
-}
-
-/*
- * Attach the mainbus.
- */
-void
-mainbus_attach(device_t parent, device_t self, void *aux)
-{
-#if NPCI > 0 || NACPICA > 0 || NIPMI > 0
-	union mainbus_attach_args mba;
-#endif
-#if NPCI > 0
-	int mode;
-#endif
-#ifdef MPBIOS
-	int mpbios_present = 0;
-#endif
-	int numcpus = 0;
-#if defined(PCI_BUS_FIXUP)
-	int pci_maxbus = 0;
-#endif
-
-	aprint_naive("\n");
-	aprint_normal("\n");
-
-#ifdef MPBIOS
-	mpbios_present = mpbios_probe(self);
-#endif
-
-#if NPCI > 0
-#ifdef __HAVE_PCI_MSI_MSIX
-	msipic_init();
-#endif
-
-	/*
-	 * ACPI needs to be able to access PCI configuration space.
-	 */
-	mode = pci_mode_detect();
-#if defined(PCI_BUS_FIXUP)
-	if (mode != 0) {
-		pci_maxbus = pci_bus_fixup(NULL, 0);
-		aprint_debug("PCI bus max, after pci_bus_fixup: %i\n",
-		    pci_maxbus);
-#if defined(PCI_ADDR_FIXUP)
-		pciaddr.extent_port = NULL;
-		pciaddr.extent_mem = NULL;
-		pci_addr_fixup(NULL, pci_maxbus);
-#endif
-	}
-#endif
-#endif
-
-#if NACPICA > 0
-	if ((boothowto & RB_MD2) == 0 && acpi_check(self, "acpibus"))
-		acpi_present = acpi_probe() != 0;
-	/*
-	 * First, see if the MADT contains CPUs, and possibly I/O APICs.
-	 * Building the interrupt routing structures can only
-	 * be done later (via a callback).
-	 */
-	if (acpi_present)
-		mpacpi_active = mpacpi_scan_apics(self, &numcpus) != 0;
-
-	if (!mpacpi_active) {
-#endif		
-#ifdef MPBIOS
-		if (mpbios_present)
-			mpbios_scan(self, &numcpus);
-		else
-#endif
-		if (numcpus == 0) {
-			struct cpu_attach_args caa;
-                        
-			memset(&caa, 0, sizeof(caa));
-			caa.cpu_number = 0;
-			caa.cpu_role = CPU_ROLE_SP;
-			caa.cpu_func = 0;
-                        
-			config_found_ia(self, "cpubus", &caa, mainbus_print);
-		}
-#if NACPICA > 0		
-	}
-#endif
-
-#if NISADMA > 0 && NACPICA > 0
-	/*
-	 * ACPI needs ISA DMA initialized before they start probing.
-	 */
-	isa_dmainit(&x86_isa_chipset, x86_bus_space_io, &isa_bus_dma_tag,
-	    self);
-#endif
-
-#if NACPICA > 0
-	if (acpi_present) {
-		mba.mba_acpi.aa_iot = x86_bus_space_io;
-		mba.mba_acpi.aa_memt = x86_bus_space_mem;
-		mba.mba_acpi.aa_pc = NULL;
-		mba.mba_acpi.aa_pciflags =
-		    PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
-		    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
-		    PCI_FLAGS_MWI_OKAY;
-		mba.mba_acpi.aa_ic = &x86_isa_chipset;
-		mba.mba_acpi.aa_dmat = &pci_bus_dma_tag;
-		mba.mba_acpi.aa_dmat64 = &pci_bus_dma64_tag;
-		config_found_ia(self, "acpibus", &mba.mba_acpi, 0);
-	}
-#endif
-
-#if NIPMI > 0
-	memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
-	mba.mba_ipmi.iaa_iot = x86_bus_space_io;
-	mba.mba_ipmi.iaa_memt = x86_bus_space_mem;
-	if (ipmi_probe(&mba.mba_ipmi))
-		config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
-#endif
-
-#if NPCI > 0
-	if (mode != 0) {
-		int npcibus = 0;
-
-		mba.mba_pba.pba_iot = x86_bus_space_io;
-		mba.mba_pba.pba_memt = x86_bus_space_mem;
-		mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
-		mba.mba_pba.pba_dmat64 = &pci_bus_dma64_tag;
-		mba.mba_pba.pba_pc = NULL;
-		mba.mba_pba.pba_flags =
-		    PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
-		    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
-		    PCI_FLAGS_MWI_OKAY;
-		mba.mba_pba.pba_bus = 0;
-		mba.mba_pba.pba_bridgetag = NULL;
-#if NACPICA > 0 && defined(ACPI_SCANPCI)
-		if (npcibus == 0 && mpacpi_active)
-			npcibus = mp_pci_scan(self, &mba.mba_pba, pcibusprint);
-#endif
-#if defined(MPBIOS) && defined(MPBIOS_SCANPCI)
-		if (npcibus == 0 && mpbios_scanned != 0)
-			npcibus = mp_pci_scan(self, &mba.mba_pba, pcibusprint);
-#endif
-		if (npcibus == 0)
-			config_found_ia(self, "pcibus", &mba.mba_pba,
-			    pcibusprint);
-
-#if NACPICA > 0
-		if (mp_verbose)
-			acpi_pci_link_state();
-#endif
-
-	}
-#endif
-
-#if NISA > 0
-	if (isa_has_been_seen == 0) {
-		mba.mba_iba = mba_iba;
-		mba.mba_iba.iba_iot = x86_bus_space_io;
-		mba.mba_iba.iba_memt = x86_bus_space_mem;
-		config_found_ia(self, "isabus", &mba.mba_iba, isabusprint);
-	}
-#endif
-
-	if (!pmf_device_register(self, NULL, NULL))
-		aprint_error_dev(self, "couldn't establish power handler\n");
-}
-
-int
-mainbus_print(void *aux, const char *pnp)
-{
-	union mainbus_attach_args *mba = aux;
-
-	if (pnp)
-		aprint_normal("%s at %s", mba->mba_busname, pnp);
-	return (UNCONF);
-}
diff -r 34587dc62568 sys/arch/amd64/conf/XEN3_DOM0
--- a/sys/arch/amd64/conf/XEN3_DOM0	Thu Dec 20 16:18:32 2018 +0530
+++ b/sys/arch/amd64/conf/XEN3_DOM0	Sat Dec 22 02:30:45 2018 +0530
@@ -202,7 +202,9 @@ xenbus* 	at hypervisor?		# Xen virtual b
 xencons*	at hypervisor?		# Xen virtual console
 balloon*	at xenbus?		# Xen balloon device
 
-acpi0		at hypervisor?
+acpi0		at hypervisor?		# ACPI access in PV mode
+acpi0		at mainbus?		# ACPI access in PVH(VM) mode
+
 #options 	ACPI_ACTIVATE_DEV	# If set, activate inactive devices
 options 	ACPI_SCANPCI		# find PCI roots using ACPI
 #options 	ACPICA_PEDANTIC		# force strict conformance to the Spec.
diff -r 34587dc62568 sys/arch/amd64/conf/files.amd64
--- a/sys/arch/amd64/conf/files.amd64	Thu Dec 20 16:18:32 2018 +0530
+++ b/sys/arch/amd64/conf/files.amd64	Sat Dec 22 02:30:45 2018 +0530
@@ -94,7 +94,8 @@ include	"dev/i2o/files.i2o"
 # XXX BIOS32 only if something that uses it is configured!
 device	mainbus: isabus, pcibus, bios32, acpibus, cpubus, ioapicbus, ipmibus
 attach	mainbus at root
-file	arch/amd64/amd64/mainbus.c		mainbus
+file	arch/amd64/amd64/amd64_mainbus.c	mainbus
+file	arch/x86/x86/mainbus.c			mainbus
 
 #
 # PCI-only drivers
diff -r 34587dc62568 sys/arch/i386/conf/files.i386
--- a/sys/arch/i386/conf/files.i386	Thu Dec 20 16:18:32 2018 +0530
+++ b/sys/arch/i386/conf/files.i386	Sat Dec 22 02:30:45 2018 +0530
@@ -129,7 +129,8 @@ device	mainbus: isabus, eisabus, mcabus,
 	cpubus, ioapicbus, apmbus, pnpbiosbus, ipmibus,
 	bioscall
 attach	mainbus at root
-file	arch/i386/i386/mainbus.c	mainbus
+file	arch/i386/i386/i386_mainbus.c	mainbus
+file	arch/x86/x86/mainbus.c		mainbus
 
 #
 # PCI-only drivers
diff -r 34587dc62568 sys/arch/i386/i386/i386_mainbus.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/i386/i386/i386_mainbus.c	Sat Dec 22 02:30:45 2018 +0530
@@ -0,0 +1,372 @@
+/*	$NetBSD: mainbus.c,v 1.104 2018/12/02 08:19:44 cherry Exp $	*/
+
+/*
+ * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Christopher G. Demetriou
+ *	for the NetBSD Project.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.104 2018/12/02 08:19:44 cherry Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/reboot.h>
+#include <sys/bus.h>
+
+#include <dev/isa/isavar.h>
+#include <dev/eisa/eisavar.h>
+#include <dev/pci/pcivar.h>
+
+#include <dev/isa/isareg.h>		/* for ISA_HOLE_VADDR */
+
+#include "pci.h"
+#include "eisa.h"
+#include "isa.h"
+#include "isadma.h"
+#include "mca.h"
+#include "pnpbios.h"
+#include "acpica.h"
+#include "ipmi.h"
+
+#include "opt_acpi.h"
+#include "opt_mpbios.h"
+#include "opt_pcifixup.h"
+
+#include <machine/cpuvar.h>
+#include <machine/i82093var.h>
+#include <machine/mpbiosvar.h>
+#include <machine/mpacpi.h>
+
+#if NPNPBIOS > 0
+#include <arch/i386/pnpbios/pnpbiosvar.h>
+#endif
+
+#if NACPICA > 0
+#include <dev/acpi/acpivar.h>
+#endif
+
+#if NMCA > 0
+#include <dev/mca/mcavar.h>
+#endif
+
+#include <x86/autoconf.h>
+
+#if NIPMI > 0
+#include <x86/ipmivar.h>
+#endif
+
+#if NPCI > 0
+#if defined(PCI_BUS_FIXUP)
+#include <arch/x86/pci/pci_bus_fixup.h>
+#if defined(PCI_ADDR_FIXUP)
+#include <arch/x86/pci/pci_addr_fixup.h>
+#endif
+#endif
+#ifdef __HAVE_PCI_MSI_MSIX
+#include <arch/x86/pci/msipic.h>
+#endif /* __HAVE_PCI_MSI_MSIX */
+#endif
+
+void	i386_mainbus_childdetached(device_t, device_t);
+int	i386_mainbus_match(device_t, cfdata_t, void *);
+void	i386_mainbus_attach(device_t, device_t, void *);
+int	i386_mainbus_rescan(device_t, const char *, const int *);
+
+union i386_mainbus_attach_args {
+	const char *mba_busname;		/* first elem of all */
+	struct pcibus_attach_args mba_pba;
+	struct eisabus_attach_args mba_eba;
+	struct isabus_attach_args mba_iba;
+#if NMCA > 0
+	struct mcabus_attach_args mba_mba;
+#endif
+#if NPNPBIOS > 0
+	struct pnpbios_attach_args mba_paa;
+#endif
+	struct cpu_attach_args mba_caa;
+	struct apic_attach_args aaa_caa;
+#if NACPICA > 0
+	struct acpibus_attach_args mba_acpi;
+#endif
+#if NIPMI > 0
+	struct ipmi_attach_args mba_ipmi;
+#endif
+};
+
+/*
+ * This is set when the ISA bus is attached.  If it's not set by the
+ * time it's checked below, then mainbus attempts to attach an ISA.
+ */
+int	isa_has_been_seen;
+struct x86_isa_chipset x86_isa_chipset;
+#if NISA > 0
+static const struct isabus_attach_args mba_iba = {
+	._iba_busname = "isa",
+	.iba_dmat = &isa_bus_dma_tag,
+	.iba_ic = &x86_isa_chipset
+};
+#endif
+
+/*
+ * Same as above, but for EISA.
+ */
+int	eisa_has_been_seen;
+
+#if defined(MPBIOS) || NACPICA > 0
+struct mp_bus *mp_busses;
+int mp_nbus;
+struct mp_intr_map *mp_intrs;
+int mp_nintr;
+ 
+int mp_isa_bus = -1;            /* XXX */
+int mp_eisa_bus = -1;           /* XXX */
+
+extern bool acpi_present;
+extern bool mpacpi_active;
+
+# ifdef MPVERBOSE
+#  if MPVERBOSE > 0
+int mp_verbose = MPVERBOSE;
+#  else
+int mp_verbose = 1;
+#  endif
+# else
+int mp_verbose = 0;
+# endif
+#endif
+
+void
+i386_mainbus_childdetached(device_t self, device_t child)
+{
+	struct mainbus_softc *sc = device_private(self);
+
+	if (sc->sc_acpi == child)
+		sc->sc_acpi = NULL;
+	if (sc->sc_ipmi == child)
+		sc->sc_ipmi = NULL;
+	if (sc->sc_mca == child)
+		sc->sc_mca = NULL;
+	if (sc->sc_pnpbios == child)
+		sc->sc_pnpbios = NULL;
+	if (sc->sc_pci == child)
+		sc->sc_pci = NULL;
+
+#if NPCI > 0
+	mp_pci_childdetached(self, child);
+#endif
+}
+
+/*
+ * Probe for the mainbus; always succeeds.
+ */
+int
+i386_mainbus_match(device_t parent, cfdata_t match, void *aux)
+{
+
+	return 1;
+}
+
+/*
+ * Attach the mainbus.
+ */
+void
+i386_mainbus_attach(device_t parent, device_t self, void *aux)
+{
+	struct mainbus_softc *sc = device_private(self);
+	union i386_mainbus_attach_args mba;
+
+	sc->sc_dev = self;
+
+#if NISADMA > 0 && (NACPICA > 0 || NPNPBIOS > 0)
+	/*
+	 * ACPI and PNPBIOS need ISA DMA initialized before they start probing.
+	 */
+	isa_dmainit(&x86_isa_chipset, x86_bus_space_io, &isa_bus_dma_tag,
+	    self);
+#endif
+
+	i386_mainbus_rescan(self, "acpibus", NULL);
+
+	i386_mainbus_rescan(self, "pnpbiosbus", NULL);
+
+	i386_mainbus_rescan(self, "ipmibus", NULL);
+
+	i386_mainbus_rescan(self, "pcibus", NULL);
+
+	i386_mainbus_rescan(self, "mcabus", NULL);
+
+	if (memcmp(ISA_HOLE_VADDR(EISA_ID_PADDR), EISA_ID, EISA_ID_LEN) == 0 &&
+	    eisa_has_been_seen == 0) {
+		mba.mba_eba.eba_iot = x86_bus_space_io;
+		mba.mba_eba.eba_memt = x86_bus_space_mem;
+#if NEISA > 0
+		mba.mba_eba.eba_dmat = &eisa_bus_dma_tag;
+#endif
+		config_found_ia(self, "eisabus", &mba.mba_eba, eisabusprint);
+	}
+
+#if NISA > 0
+	if (isa_has_been_seen == 0) {
+		mba.mba_iba = mba_iba;
+		mba.mba_iba.iba_iot = x86_bus_space_io;
+		mba.mba_iba.iba_memt = x86_bus_space_mem;
+		config_found_ia(self, "isabus", &mba.mba_iba, isabusprint);
+	}
+#endif
+
+	if (!pmf_device_register(self, NULL, NULL))
+		aprint_error_dev(self, "couldn't establish power handler\n");
+}
+
+/* scan for new children */
+int
+i386_mainbus_rescan(device_t self, const char *ifattr, const int *locators)
+{
+	struct mainbus_softc *sc = device_private(self);
+#if NACPICA > 0 || NIPMI > 0 || NMCA > 0 || NPCI > 0 || NPNPBIOS > 0
+	union i386_mainbus_attach_args mba;
+#endif
+
+	if (ifattr_match(ifattr, "acpibus") && sc->sc_acpi == NULL &&
+	    acpi_present) {
+#if NACPICA > 0
+		mba.mba_acpi.aa_iot = x86_bus_space_io;
+		mba.mba_acpi.aa_memt = x86_bus_space_mem;
+		mba.mba_acpi.aa_pc = NULL;
+		mba.mba_acpi.aa_pciflags =
+		    PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
+		    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
+		    PCI_FLAGS_MWI_OKAY;
+		mba.mba_acpi.aa_ic = &x86_isa_chipset;
+		mba.mba_acpi.aa_dmat = &pci_bus_dma_tag;
+		mba.mba_acpi.aa_dmat64 = NULL;
+		sc->sc_acpi =
+		    config_found_ia(self, "acpibus", &mba.mba_acpi, 0);
+#if 0 /* XXXJRT not yet */
+		if (acpi_active) {
+			/*
+			 * ACPI already did all the work for us, there
+			 * is nothing more for us to do.
+			 */
+			return;
+		}
+#endif
+#endif
+	}
+
+	if (ifattr_match(ifattr, "pnpbiosbus") && sc->sc_pnpbios == NULL) {
+#if NPNPBIOS > 0
+#if NACPICA > 0
+		if (acpi_active == 0)
+#endif
+		if (pnpbios_probe()) {
+			mba.mba_paa.paa_ic = &x86_isa_chipset;
+			sc->sc_pnpbios = config_found_ia(self, "pnpbiosbus",
+			    &mba.mba_paa, 0);
+		}
+#endif
+	}
+
+	if (ifattr_match(ifattr, "ipmibus") && sc->sc_ipmi == NULL) {
+#if NIPMI > 0
+		memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
+		mba.mba_ipmi.iaa_iot = x86_bus_space_io;
+		mba.mba_ipmi.iaa_memt = x86_bus_space_mem;
+		if (ipmi_probe(&mba.mba_ipmi)) {
+			sc->sc_ipmi =
+			    config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
+		}
+#endif
+	}
+
+	/*
+	 * XXX Note also that the presence of a PCI bus should
+	 * XXX _always_ be checked, and if present the bus should be
+	 * XXX 'found'.  However, because of the structure of the code,
+	 * XXX that's not currently possible.
+	 */
+#if NPCI > 0
+	if (pci_mode_detect() != 0 && ifattr_match(ifattr, "pcibus")) {
+		int npcibus = 0;
+
+		mba.mba_pba.pba_iot = x86_bus_space_io;
+		mba.mba_pba.pba_memt = x86_bus_space_mem;
+		mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
+		mba.mba_pba.pba_dmat64 = NULL;
+		mba.mba_pba.pba_pc = NULL;
+		mba.mba_pba.pba_flags =
+		    PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
+		    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
+		    PCI_FLAGS_MWI_OKAY;
+		mba.mba_pba.pba_bus = 0;
+		/* XXX On those machines with >1 Host-PCI bridge,
+		 * XXX not every bus > pba_bus is subordinate to pba_bus,
+		 * XXX but this works on many machines, and pba_sub is
+		 * XXX not used today by any critical code, so it is safe
+		 * XXX to be so inclusive at this time.
+		 */
+		mba.mba_pba.pba_sub = 255;
+		mba.mba_pba.pba_bridgetag = NULL;
+#if NACPICA > 0 && defined(ACPI_SCANPCI)
+		if (npcibus == 0 && mpacpi_active)
+			npcibus = mp_pci_scan(self, &mba.mba_pba, pcibusprint);
+#endif
+#if defined(MPBIOS) && defined(MPBIOS_SCANPCI)
+		if (npcibus == 0 && mpbios_scanned != 0)
+			npcibus = mp_pci_scan(self, &mba.mba_pba, pcibusprint);
+#endif
+		if (npcibus == 0 && sc->sc_pci == NULL) {
+			sc->sc_pci = config_found_ia(self, "pcibus",
+			    &mba.mba_pba, pcibusprint);
+		}
+#if NACPICA > 0
+		if (mp_verbose)
+			acpi_pci_link_state();
+#endif
+	}
+#endif
+
+
+	if (ifattr_match(ifattr, "mcabus") && sc->sc_mca == NULL) {
+#if NMCA > 0
+	/* Note: MCA bus probe is done in i386/machdep.c */
+		if (MCA_system) {
+			mba.mba_mba.mba_iot = x86_bus_space_io;
+			mba.mba_mba.mba_memt = x86_bus_space_mem;
+			mba.mba_mba.mba_dmat = &mca_bus_dma_tag;
+			mba.mba_mba.mba_mc = NULL;
+			mba.mba_mba.mba_bus = 0;
+			sc->sc_mca = config_found_ia(self, "mcabus",
+			    &mba.mba_mba, mcabusprint);
+		}
+#endif
+	}
+	return 0;
+}
+
diff -r 34587dc62568 sys/arch/i386/i386/mainbus.c
--- a/sys/arch/i386/i386/mainbus.c	Thu Dec 20 16:18:32 2018 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,465 +0,0 @@
-/*	$NetBSD: mainbus.c,v 1.104 2018/12/02 08:19:44 cherry Exp $	*/
-
-/*
- * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by Christopher G. Demetriou
- *	for the NetBSD Project.
- * 4. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.104 2018/12/02 08:19:44 cherry Exp $");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/device.h>
-#include <sys/reboot.h>
-#include <sys/bus.h>
-
-#include <dev/isa/isavar.h>
-#include <dev/eisa/eisavar.h>
-#include <dev/pci/pcivar.h>
-
-#include <dev/isa/isareg.h>		/* for ISA_HOLE_VADDR */
-
-#include "pci.h"
-#include "eisa.h"
-#include "isa.h"
-#include "isadma.h"
-#include "mca.h"
-#include "pnpbios.h"
-#include "acpica.h"
-#include "ipmi.h"
-
-#include "opt_acpi.h"
-#include "opt_mpbios.h"
-#include "opt_pcifixup.h"
-
-#include <machine/cpuvar.h>
-#include <machine/i82093var.h>
-#include <machine/mpbiosvar.h>
-#include <machine/mpacpi.h>
-
-#if NPNPBIOS > 0
-#include <arch/i386/pnpbios/pnpbiosvar.h>
-#endif
-
-#if NACPICA > 0
-#include <dev/acpi/acpivar.h>
-#endif
-
-#if NMCA > 0
-#include <dev/mca/mcavar.h>
-#endif
-
-#if NIPMI > 0
-#include <x86/ipmivar.h>
-#endif
-
-#if NPCI > 0
-#if defined(PCI_BUS_FIXUP)
-#include <arch/x86/pci/pci_bus_fixup.h>
-#if defined(PCI_ADDR_FIXUP)
-#include <arch/x86/pci/pci_addr_fixup.h>
-#endif
-#endif
-#ifdef __HAVE_PCI_MSI_MSIX
-#include <arch/x86/pci/msipic.h>
-#endif /* __HAVE_PCI_MSI_MSIX */
-#endif
-
-void	mainbus_childdetached(device_t, device_t);
-int	mainbus_match(device_t, cfdata_t, void *);
-void	mainbus_attach(device_t, device_t, void *);
-
-static int	mainbus_rescan(device_t, const char *, const int *);
-
-struct mainbus_softc {
-	device_t	sc_acpi;
-	device_t	sc_dev;
-	device_t	sc_ipmi;
-	device_t	sc_pci;
-	device_t	sc_mca;
-	device_t	sc_pnpbios;
-};
-
-CFATTACH_DECL2_NEW(mainbus, sizeof(struct mainbus_softc),
-    mainbus_match, mainbus_attach, NULL, NULL, mainbus_rescan,
-    mainbus_childdetached);
-
-int	mainbus_print(void *, const char *);
-
-union mainbus_attach_args {
-	const char *mba_busname;		/* first elem of all */
-	struct pcibus_attach_args mba_pba;
-	struct eisabus_attach_args mba_eba;
-	struct isabus_attach_args mba_iba;
-#if NMCA > 0
-	struct mcabus_attach_args mba_mba;
-#endif
-#if NPNPBIOS > 0
-	struct pnpbios_attach_args mba_paa;
-#endif
-	struct cpu_attach_args mba_caa;
-	struct apic_attach_args aaa_caa;
-#if NACPICA > 0
-	struct acpibus_attach_args mba_acpi;
-#endif
-#if NIPMI > 0
-	struct ipmi_attach_args mba_ipmi;
-#endif
-};
-
-/*
- * This is set when the ISA bus is attached.  If it's not set by the
- * time it's checked below, then mainbus attempts to attach an ISA.
- */
-int	isa_has_been_seen;
-struct x86_isa_chipset x86_isa_chipset;
-#if NISA > 0
-static const struct isabus_attach_args mba_iba = {
-	._iba_busname = "isa",
-	.iba_dmat = &isa_bus_dma_tag,
-	.iba_ic = &x86_isa_chipset
-};
-#endif
-
-/*
- * Same as above, but for EISA.
- */
-int	eisa_has_been_seen;
-
-#if defined(MPBIOS) || NACPICA > 0
-struct mp_bus *mp_busses;
-int mp_nbus;
-struct mp_intr_map *mp_intrs;
-int mp_nintr;
- 
-int mp_isa_bus = -1;            /* XXX */
-int mp_eisa_bus = -1;           /* XXX */
-
-bool acpi_present;
-bool mpacpi_active;
-
-# ifdef MPVERBOSE
-#  if MPVERBOSE > 0
-int mp_verbose = MPVERBOSE;
-#  else
-int mp_verbose = 1;
-#  endif
-# else
-int mp_verbose = 0;
-# endif
-#endif
-
-void
-mainbus_childdetached(device_t self, device_t child)
-{
-	struct mainbus_softc *sc = device_private(self);
-
-	if (sc->sc_acpi == child)
-		sc->sc_acpi = NULL;
-	if (sc->sc_ipmi == child)
-		sc->sc_ipmi = NULL;
-	if (sc->sc_mca == child)
-		sc->sc_mca = NULL;
-	if (sc->sc_pnpbios == child)
-		sc->sc_pnpbios = NULL;
-	if (sc->sc_pci == child)
-		sc->sc_pci = NULL;
-
-#if NPCI > 0
-	mp_pci_childdetached(self, child);
-#endif
-}
-
-/*
- * Probe for the mainbus; always succeeds.
- */
-int
-mainbus_match(device_t parent, cfdata_t match, void *aux)
-{
-
-	return 1;
-}
-
-/*
- * Attach the mainbus.
- */
-void
-mainbus_attach(device_t parent, device_t self, void *aux)
-{
-#if NPCI > 0
-	int mode;
-#endif
-	struct mainbus_softc *sc = device_private(self);
-	union mainbus_attach_args mba;
-#ifdef MPBIOS
-	int mpbios_present = 0;
-#endif
-#if defined(PCI_BUS_FIXUP)
-	int pci_maxbus = 0;
-#endif
-	int numcpus = 0;
-
-	sc->sc_dev = self;
-
-	aprint_naive("\n");
-	aprint_normal("\n");
-
-#ifdef MPBIOS
-	mpbios_present = mpbios_probe(self);
-#endif
-
-#if NPCI > 0
-	msipic_init();
-
-	/*
-	 * ACPI needs to be able to access PCI configuration space.
-	 */
-	mode = pci_mode_detect();
-#if defined(PCI_BUS_FIXUP)
-	if (mode != 0) {
-		pci_maxbus = pci_bus_fixup(NULL, 0);
-		aprint_debug("PCI bus max, after pci_bus_fixup: %i\n",
-		    pci_maxbus);
-#if defined(PCI_ADDR_FIXUP)
-		pciaddr.extent_port = NULL;
-		pciaddr.extent_mem = NULL;
-		pci_addr_fixup(NULL, pci_maxbus);
-#endif
-	}
-#else
-	__USE(mode);
-#endif
-#endif
-
-#if NACPICA > 0
-	if ((boothowto & RB_MD2) == 0 && acpi_check(self, "acpibus"))
-		acpi_present = acpi_probe() != 0;
-	/*
-	 * First, see if the MADT contains CPUs, and possibly I/O APICs.
-	 * Building the interrupt routing structures can only
-	 * be done later (via a callback).
-	 */
-	if (acpi_present)
-		mpacpi_active = mpacpi_scan_apics(self, &numcpus) != 0;
-#endif
-
-	if (!mpacpi_active) {
-#ifdef MPBIOS
-		if (mpbios_present)
-			mpbios_scan(self, &numcpus);
-		else
-#endif
-		if (numcpus == 0) {
-			struct cpu_attach_args caa;
-
-			memset(&caa, 0, sizeof(caa));
-			caa.cpu_number = 0;
-			caa.cpu_role = CPU_ROLE_SP;
-			caa.cpu_func = 0;
-
-			config_found_ia(self, "cpubus", &caa, mainbus_print);
-		}
-	}
-
-#if NISADMA > 0 && (NACPICA > 0 || NPNPBIOS > 0)
-	/*
-	 * ACPI and PNPBIOS need ISA DMA initialized before they start probing.
-	 */
-	isa_dmainit(&x86_isa_chipset, x86_bus_space_io, &isa_bus_dma_tag,
-	    self);
-#endif
-
-	mainbus_rescan(self, "acpibus", NULL);
-
-	mainbus_rescan(self, "pnpbiosbus", NULL);
-
-	mainbus_rescan(self, "ipmibus", NULL);
-
-	mainbus_rescan(self, "pcibus", NULL);
-
-	mainbus_rescan(self, "mcabus", NULL);
-
-	if (memcmp(ISA_HOLE_VADDR(EISA_ID_PADDR), EISA_ID, EISA_ID_LEN) == 0 &&
-	    eisa_has_been_seen == 0) {
-		mba.mba_eba.eba_iot = x86_bus_space_io;
-		mba.mba_eba.eba_memt = x86_bus_space_mem;
-#if NEISA > 0
-		mba.mba_eba.eba_dmat = &eisa_bus_dma_tag;
-#endif
-		config_found_ia(self, "eisabus", &mba.mba_eba, eisabusprint);
-	}
-
-#if NISA > 0
-	if (isa_has_been_seen == 0) {
-		mba.mba_iba = mba_iba;
-		mba.mba_iba.iba_iot = x86_bus_space_io;
-		mba.mba_iba.iba_memt = x86_bus_space_mem;
-		config_found_ia(self, "isabus", &mba.mba_iba, isabusprint);
-	}
-#endif
-
-	if (!pmf_device_register(self, NULL, NULL))
-		aprint_error_dev(self, "couldn't establish power handler\n");
-}
-
-/* scan for new children */
-static int
-mainbus_rescan(device_t self, const char *ifattr, const int *locators)
-{
-	struct mainbus_softc *sc = device_private(self);
-#if NACPICA > 0 || NIPMI > 0 || NMCA > 0 || NPCI > 0 || NPNPBIOS > 0
-	union mainbus_attach_args mba;
-#endif
-
-	if (ifattr_match(ifattr, "acpibus") && sc->sc_acpi == NULL &&
-	    acpi_present) {
-#if NACPICA > 0
-		mba.mba_acpi.aa_iot = x86_bus_space_io;
-		mba.mba_acpi.aa_memt = x86_bus_space_mem;
-		mba.mba_acpi.aa_pc = NULL;
-		mba.mba_acpi.aa_pciflags =
-		    PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
-		    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
-		    PCI_FLAGS_MWI_OKAY;
-		mba.mba_acpi.aa_ic = &x86_isa_chipset;
-		mba.mba_acpi.aa_dmat = &pci_bus_dma_tag;
-		mba.mba_acpi.aa_dmat64 = NULL;
-		sc->sc_acpi =
-		    config_found_ia(self, "acpibus", &mba.mba_acpi, 0);
-#if 0 /* XXXJRT not yet */
-		if (acpi_active) {
-			/*
-			 * ACPI already did all the work for us, there
-			 * is nothing more for us to do.
-			 */
-			return;
-		}
-#endif
-#endif
-	}
-
-	if (ifattr_match(ifattr, "pnpbiosbus") && sc->sc_pnpbios == NULL) {
-#if NPNPBIOS > 0
-#if NACPICA > 0
-		if (acpi_active == 0)
-#endif
-		if (pnpbios_probe()) {
-			mba.mba_paa.paa_ic = &x86_isa_chipset;
-			sc->sc_pnpbios = config_found_ia(self, "pnpbiosbus",
-			    &mba.mba_paa, 0);
-		}
-#endif
-	}
-
-	if (ifattr_match(ifattr, "ipmibus") && sc->sc_ipmi == NULL) {
-#if NIPMI > 0
-		memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
-		mba.mba_ipmi.iaa_iot = x86_bus_space_io;
-		mba.mba_ipmi.iaa_memt = x86_bus_space_mem;
-		if (ipmi_probe(&mba.mba_ipmi)) {
-			sc->sc_ipmi =
-			    config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
-		}
-#endif
-	}
-
-	/*
-	 * XXX Note also that the presence of a PCI bus should
-	 * XXX _always_ be checked, and if present the bus should be
-	 * XXX 'found'.  However, because of the structure of the code,
-	 * XXX that's not currently possible.
-	 */
-#if NPCI > 0
-	if (pci_mode_detect() != 0 && ifattr_match(ifattr, "pcibus")) {
-		int npcibus = 0;
-
-		mba.mba_pba.pba_iot = x86_bus_space_io;
-		mba.mba_pba.pba_memt = x86_bus_space_mem;
-		mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
-		mba.mba_pba.pba_dmat64 = NULL;
-		mba.mba_pba.pba_pc = NULL;
-		mba.mba_pba.pba_flags =
-		    PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
-		    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY |
-		    PCI_FLAGS_MWI_OKAY;
-		mba.mba_pba.pba_bus = 0;
-		/* XXX On those machines with >1 Host-PCI bridge,
-		 * XXX not every bus > pba_bus is subordinate to pba_bus,
-		 * XXX but this works on many machines, and pba_sub is
-		 * XXX not used today by any critical code, so it is safe
-		 * XXX to be so inclusive at this time.
-		 */
-		mba.mba_pba.pba_sub = 255;
-		mba.mba_pba.pba_bridgetag = NULL;
-#if NACPICA > 0 && defined(ACPI_SCANPCI)
-		if (npcibus == 0 && mpacpi_active)
-			npcibus = mp_pci_scan(self, &mba.mba_pba, pcibusprint);
-#endif
-#if defined(MPBIOS) && defined(MPBIOS_SCANPCI)
-		if (npcibus == 0 && mpbios_scanned != 0)
-			npcibus = mp_pci_scan(self, &mba.mba_pba, pcibusprint);
-#endif
-		if (npcibus == 0 && sc->sc_pci == NULL) {
-			sc->sc_pci = config_found_ia(self, "pcibus",
-			    &mba.mba_pba, pcibusprint);
-		}
-#if NACPICA > 0
-		if (mp_verbose)
-			acpi_pci_link_state();
-#endif
-	}
-#endif
-
-
-	if (ifattr_match(ifattr, "mcabus") && sc->sc_mca == NULL) {
-#if NMCA > 0
-	/* Note: MCA bus probe is done in i386/machdep.c */
-		if (MCA_system) {
-			mba.mba_mba.mba_iot = x86_bus_space_io;
-			mba.mba_mba.mba_memt = x86_bus_space_mem;
-			mba.mba_mba.mba_dmat = &mca_bus_dma_tag;
-			mba.mba_mba.mba_mc = NULL;
-			mba.mba_mba.mba_bus = 0;
-			sc->sc_mca = config_found_ia(self, "mcabus",
-			    &mba.mba_mba, mcabusprint);
-		}
-#endif
-	}
-	return 0;
-}
-
-int
-mainbus_print(void *aux, const char *pnp)
-{
-	union mainbus_attach_args *mba = aux;
-
-	if (pnp)
-		aprint_normal("%s at %s", mba->mba_busname, pnp);
-	return (UNCONF);
-}
diff -r 34587dc62568 sys/arch/x86/include/autoconf.h
--- a/sys/arch/x86/include/autoconf.h	Thu Dec 20 16:18:32 2018 +0530
+++ b/sys/arch/x86/include/autoconf.h	Sat Dec 22 02:30:45 2018 +0530
@@ -4,6 +4,22 @@
 
 #include <sys/device.h>
 
+/*
+ * device private data for mainbus.
+ * subr_autoconf.c uses sizeof() to allocate private memory for this
+ * data structure.
+ */
+struct mainbus_softc {
+#if defined(__i386__)	
+	device_t	sc_acpi;
+	device_t	sc_dev;
+	device_t	sc_ipmi;
+	device_t	sc_pci;
+	device_t	sc_mca;
+	device_t	sc_pnpbios;
+#endif
+};
+
 void device_pci_props_register(device_t, void *);
 device_t device_pci_register(device_t, void *);
 device_t device_isa_register(device_t, void *);
diff -r 34587dc62568 sys/arch/x86/x86/mainbus.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/x86/x86/mainbus.c	Sat Dec 22 02:30:45 2018 +0530
@@ -0,0 +1,255 @@
+/* $NetBSD$ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+__KERNEL_RCSID(0, "$NetBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/reboot.h>
+
+#include <dev/pci/pcivar.h>
+
+#include <machine/cpuvar.h>
+#include <machine/mpbiosvar.h>
+#include <machine/mpacpi.h>
+
+#include "pci.h"
+#include "isa.h"
+#include "isadma.h"
+#include "acpica.h"
+#include "ipmi.h"
+
+#include "opt_acpi.h"
+#include "opt_mpbios.h"
+#include "opt_pcifixup.h"
+
+#if NACPICA > 0
+#include <dev/acpi/acpivar.h>
+#endif
+
+#include <x86/autoconf.h>
+
+#if NIPMI > 0
+#include <x86/ipmivar.h>
+#endif
+
+#if NPCI > 0
+#if defined(PCI_BUS_FIXUP)
+#include <arch/x86/pci/pci_bus_fixup.h>
+#if defined(PCI_ADDR_FIXUP)
+#include <arch/x86/pci/pci_addr_fixup.h>
+#endif
+#endif
+#ifdef __HAVE_PCI_MSI_MSIX
+#include <arch/x86/pci/msipic.h>
+#endif /* __HAVE_PCI_MSI_MSIX */
+#endif
+
+bool acpi_present = false;
+bool mpacpi_active = false;
+
+int	mainbus_rescan(device_t, const char *, const int *);
+void	mainbus_childdetached(device_t, device_t);
+void	mainbus_attach(device_t, device_t, void *);
+int	mainbus_match(device_t, cfdata_t, void *);
+
+CFATTACH_DECL2_NEW(mainbus, sizeof(struct mainbus_softc),
+    mainbus_match, mainbus_attach,
+    NULL, NULL,
+    mainbus_rescan, mainbus_childdetached);
+
+#if defined(__i386__) && !defined(XEN)
+void i386_mainbus_childdetached(device_t, device_t);
+int  i386_mainbus_rescan(device_t, const char *, const int *);
+void i386_mainbus_attach(device_t, device_t, void *);
+#endif
+
+#if defined(__x86_64__) && !defined(XEN)
+void
+amd64_mainbus_attach(device_t, device_t, void *);
+#endif
+
+#if defined(XEN)
+void xen_mainbus_attach(device_t, device_t, void *);
+#endif
+
+static int
+mainbus_cpu_print(void *aux, const char *busname)
+{
+	char *cpuname = aux;
+
+	if (busname)
+		aprint_normal("%s at %s", cpuname, busname);
+	return (UNCONF);
+}
+
+/*
+ * On x86, cpus can be enumerated and attached to mainbus in mainly
+ * two ways depending on the platform (configuration):
+ * via MP BIOS tables, and via ACPI tables. 
+ *
+ * Since cpus are not an optional part of computers, this attachment
+ * is made common across all x86 architectures and modes, and thus
+ * hard coded into the boot path, with the exception of XEN PV domU.
+ *
+ * Along with cpus, apics come in various shapes and forms, and to
+ * accommodate for the configurable ioapic topology, the "ioapicbus"
+ * is also enumerated here as part of the mpbios/mpacpi probe path.
+ *
+ * All other busses are attached variously depending on the
+ * platform architecture and config(5)
+ *
+ * These configurations and attach orderings are currently
+ * respectively driven in the functions:
+ *
+ * i386_mainbus_attach();
+ * amd64_mainbus_attach();
+ * xen_mainbus_attach();
+ *
+ * This arrangement gives us the flexibility to do things such as
+ * dynamic attach path traversal at boot time, depending on the
+ * "mode".
+ *
+ * For (a contrived) eg: XEN PVHVM would allow us to attach pci(9)
+ * either via hypervisorbus or mainbus depending on if the kernel is
+ * running under the hypervisor or not.
+ */
+
+static void
+x86_cpubus_attach(device_t self)
+{
+	int numcpus = 0;
+
+#if NPCI > 0
+
+#ifdef __HAVE_PCI_MSI_MSIX
+	msipic_init();
+#endif
+
+	/*
+	 * ACPI needs to be able to access PCI configuration space.
+	 */
+	pci_mode_detect();
+#if defined(PCI_BUS_FIXUP)
+	int pci_maxbus = 0;
+
+	if (pci_mode_detect() != 0) {
+		pci_maxbus = pci_bus_fixup(NULL, 0);
+		aprint_debug("PCI bus max, after pci_bus_fixup: %i\n",
+		    pci_maxbus);
+#if defined(PCI_ADDR_FIXUP)
+		pciaddr.extent_port = NULL;
+		pciaddr.extent_mem = NULL;
+		pci_addr_fixup(NULL, pci_maxbus);
+#endif
+	}
+#endif
+#endif /* NPCI */
+
+#if NACPICA > 0
+	if ((boothowto & RB_MD2) == 0 && acpi_check(self, "acpibus"))
+		acpi_present = acpi_probe() != 0;
+	/*
+	 * First, see if the MADT contains CPUs, and possibly I/O APICs.
+	 * Building the interrupt routing structures can only
+	 * be done later (via a callback).
+	 */
+	if (acpi_present)
+		mpacpi_active = mpacpi_scan_apics(self, &numcpus) != 0;
+
+	if (!mpacpi_active) {
+#endif
+#ifdef MPBIOS
+		if (mpbios_probe(self))
+			mpbios_scan(self, &numcpus);
+		else
+#endif
+		if (numcpus == 0) {
+			struct cpu_attach_args caa;
+                        
+			memset(&caa, 0, sizeof(caa));
+			caa.cpu_number = 0;
+			caa.cpu_role = CPU_ROLE_SP;
+			caa.cpu_func = 0;
+                        
+			config_found_ia(self, "cpubus", &caa, mainbus_cpu_print);
+		}
+#if NACPICA > 0		
+	}
+#endif
+
+}
+
+int
+mainbus_match(device_t parent, cfdata_t match, void *aux)
+{
+
+	return 1;
+}
+
+void
+mainbus_attach(device_t parent, device_t self, void *aux)
+{
+
+	aprint_naive("\n");
+	aprint_normal("\n");
+
+#if defined(XEN)
+	if (xendomain_is_dom0()) {
+#endif
+		x86_cpubus_attach(self);
+
+#if defined(__i386__) && !defined(XEN)
+		i386_mainbus_attach(parent, self, aux);
+#elif defined(__x86_64__) && !defined(XEN)
+		amd64_mainbus_attach(parent, self, aux);
+#endif
+#if defined(XEN)
+	}
+	xen_mainbus_attach(parent, self, aux);
+#endif
+}
+
+int	mainbus_rescan(device_t self, const char *ifattr, const int *locators)
+{
+#if defined(__i386__) && !defined(XEN)
+	return i386_mainbus_rescan(self, ifattr, locators);
+#endif
+	return ENOTTY; /* Inappropriate ioctl for this device */
+}
+
+void	mainbus_childdetached(device_t self, device_t child)
+{
+#if defined(__i386__) && !defined(XEN)
+	i386_mainbus_childdetached(self, child);
+#endif
+}
+
diff -r 34587dc62568 sys/arch/xen/conf/files.xen
--- a/sys/arch/xen/conf/files.xen	Thu Dec 20 16:18:32 2018 +0530
+++ b/sys/arch/xen/conf/files.xen	Sat Dec 22 02:30:45 2018 +0530
@@ -171,9 +171,11 @@ define ipmibus {}
 # System bus types
 #
 
-device mainbus: cpubus, ioapicbus, hypervisorbus, bios32, ipmibus
+device mainbus: cpubus, ioapicbus, hypervisorbus, bios32, ipmibus, acpibus
 attach	mainbus at root
-file	arch/xen/x86/mainbus.c		mainbus
+file	arch/xen/x86/xen_mainbus.c	mainbus
+file	arch/x86/x86/mainbus.c		mainbus
+
 
 # Xen hypervisor
 device	hypervisor { [apid = -1]}: isabus, pcibus, sysmon_power, xendevbus, acpibus
diff -r 34587dc62568 sys/arch/xen/x86/autoconf.c
--- a/sys/arch/xen/x86/autoconf.c	Thu Dec 20 16:18:32 2018 +0530
+++ b/sys/arch/xen/x86/autoconf.c	Sat Dec 22 02:30:45 2018 +0530
@@ -133,6 +133,9 @@ cpu_configure(void)
 	intr_printconfig();
 #endif
 
+#if NIOAPIC > 0
+	ioapic_enable();
+#endif
 	/* resync cr0 after FPU configuration */
 	pcb = lwp_getpcb(&lwp0);
 	pcb->pcb_cr0 = rcr0();
diff -r 34587dc62568 sys/arch/xen/x86/mainbus.c
--- a/sys/arch/xen/x86/mainbus.c	Thu Dec 20 16:18:32 2018 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,225 +0,0 @@
-/*	$NetBSD: mainbus.c,v 1.19 2017/05/23 08:54:39 nonaka Exp $	*/
-/*	NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp 	*/
-
-/*
- * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by Christopher G. Demetriou
- *	for the NetBSD Project.
- * 4. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.19 2017/05/23 08:54:39 nonaka Exp $");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/device.h>
-
-#include <sys/bus.h>
-
-#include "hypervisor.h"
-#include "pci.h"
-
-#include "opt_xen.h"
-#include "opt_mpbios.h"
-#include "opt_pcifixup.h"
-
-#include "acpica.h"
-#include "ioapic.h"
-
-#include "ipmi.h"
-
-#include <machine/cpuvar.h>
-#include <machine/i82093var.h>
-
-#include <xen/xen.h>
-#include <xen/hypervisor.h>
-
-#if NIPMI > 0
-#include <x86/ipmivar.h>
-#endif
-
-#if NPCI > 0
-#include <dev/pci/pcivar.h>
-#if NACPICA > 0
-#include <dev/acpi/acpivar.h>
-#include <xen/mpacpi.h>       
-#endif /* NACPICA > 0 */
-#ifdef MPBIOS
-#include <machine/mpbiosvar.h>       
-#endif /* MPBIOS */
-#ifdef PCI_BUS_FIXUP
-#include <arch/x86/pci/pci_bus_fixup.h>
-#ifdef PCI_ADDR_FIXUP
-#include <arch/x86/pci/pci_addr_fixup.h>
-#endif  
-#endif
-
-#if defined(MPBIOS) || NACPICA > 0
-struct mp_bus *mp_busses;
-int mp_nbus;
-struct mp_intr_map *mp_intrs;
-int mp_nintr;
- 
-int mp_isa_bus = -1;	    /* XXX */
-int mp_eisa_bus = -1;	   /* XXX */
-
-bool acpi_present;
-bool mpacpi_active;
-#ifdef MPVERBOSE
-int mp_verbose = 1;
-#else /* MPVERBOSE */
-int mp_verbose = 0;
-#endif /* MPVERBOSE */
-#endif /* defined(MPBIOS) || NACPICA > 0 */
-#endif /* NPCI > 0 */
-
-
-int	mainbus_match(device_t, cfdata_t, void *);
-void	mainbus_attach(device_t, device_t, void *);
-
-CFATTACH_DECL_NEW(mainbus, 0,
-    mainbus_match, mainbus_attach, NULL, NULL);
-
-int	mainbus_print(void *, const char *);
-
-union mainbus_attach_args {
-	const char *mba_busname;		/* first elem of all */
-	struct cpu_attach_args mba_caa;
-#if NHYPERVISOR > 0
-	struct hypervisor_attach_args mba_haa;
-#endif
-#if NIPMI > 0
-	struct ipmi_attach_args mba_ipmi;
-#endif
-};
-
-/*
- * Probe for the mainbus; always succeeds.
- */
-int
-mainbus_match(device_t parent, cfdata_t match, void *aux)
-{
-
-	return 1;
-}
-
-/*
- * Attach the mainbus.
- */
-void
-mainbus_attach(device_t parent, device_t self, void *aux)
-{
-	union mainbus_attach_args mba;
-#if defined(DOM0OPS)
-	int numcpus = 0;
-#ifdef MPBIOS
-	int mpbios_present = 0;
-#endif
-#ifdef PCI_BUS_FIXUP
-	int pci_maxbus = 0;
-#endif
-#endif /* defined(DOM0OPS) */
-
-	aprint_naive("\n");
-	aprint_normal("\n");
-
-#ifdef DOM0OPS
-	if (xendomain_is_dom0()) {
-#ifdef MPBIOS
-		mpbios_present = mpbios_probe(self);
-#endif
-#if NPCI > 0
-		/* ACPI needs to be able to access PCI configuration space. */
-		pci_mode_detect();
-#ifdef PCI_BUS_FIXUP
-		if (pci_mode != 0) {
-			pci_maxbus = pci_bus_fixup(NULL, 0);
-			aprint_debug_dev(self, "PCI bus max, after "
-			    "pci_bus_fixup: %i\n", pci_maxbus);
-#ifdef PCI_ADDR_FIXUP
-			pciaddr.extent_port = NULL;
-			pciaddr.extent_mem = NULL;
-			pci_addr_fixup(NULL, pci_maxbus);
-#endif /* PCI_ADDR_FIXUP */
-		}
-#endif /* PCI_BUS_FIXUP */
-#if NACPICA > 0
-		acpi_present = acpi_probe() != 0;
-		if (acpi_present)
-			mpacpi_active = mpacpi_scan_apics(self, &numcpus) != 0;
-		if (!mpacpi_active)
-#endif
-		{
-#ifdef MPBIOS
-			if (mpbios_present)
-				mpbios_scan(self, &numcpus);       
-			else
-#endif
-			if (numcpus == 0) {
-				memset(&mba.mba_caa, 0, sizeof(mba.mba_caa));
-				mba.mba_caa.cpu_number = 0;
-				mba.mba_caa.cpu_role = CPU_ROLE_SP;
-				mba.mba_caa.cpu_func = 0;
-				config_found_ia(self, "cpubus",
-				    &mba.mba_caa, mainbus_print);
-			}
-		}
-#if NIOAPIC > 0
-	ioapic_enable();
-#endif
-#endif /* NPCI */
-	}
-#endif /* DOM0OPS */
-
-#if NIPMI > 0
-	memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
-	mba.mba_ipmi.iaa_iot = x86_bus_space_io;
-	mba.mba_ipmi.iaa_memt = x86_bus_space_mem;
-	if (ipmi_probe(&mba.mba_ipmi))
-		config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
-#endif
-
-#if NHYPERVISOR > 0
-	mba.mba_haa.haa_busname = "hypervisor";
-	config_found_ia(self, "hypervisorbus", &mba.mba_haa, mainbus_print);
-#endif
-
-	/* save/restore for Xen */
-	if (!pmf_device_register(self, NULL, NULL))
-		aprint_error_dev(self, "couldn't establish power handler\n");
-
-}
-
-int
-mainbus_print(void *aux, const char *pnp)
-{
-	union mainbus_attach_args *mba = aux;
-
-	if (pnp)
-		aprint_normal("%s at %s", mba->mba_busname, pnp);
-	return (UNCONF);
-}


Home | Main Index | Thread Index | Old Index