Index: sys/dev/pci/pci_resource.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/pci_resource.c,v
retrieving revision 1.5
diff -p -u -r1.5 pci_resource.c
--- sys/dev/pci/pci_resource.c	30 Jun 2024 09:30:45 -0000	1.5
+++ sys/dev/pci/pci_resource.c	2 Mar 2025 22:31:47 -0000
@@ -163,6 +163,8 @@ pci_create_vmem(const char *name, bus_ad
 	vmem_t *arena;
 	int error __diagused;
 
+	KASSERTMSG(start <= end && (end - start + 1 != 0),
+	    "start=%lx end=%lx", (long)start, (long)end);
 	arena = vmem_create(name, 0, 0, 1, NULL, NULL, NULL, 0, VM_SLEEP,
 	    IPL_NONE);
 	error = vmem_add(arena, start, end - start + 1, VM_SLEEP);
@@ -791,9 +793,13 @@ pci_resource_init_bus(struct pci_resourc
 		parent_bus = bridge->pd_bus;
 		PCI_RANGE_FOREACH(prtype) {
 			if (parent_bus->pb_res[prtype] == NULL ||
-			    !bridge->pd_bridge.ranges[prtype].end) {
+			    !bridge->pd_bridge.ranges[prtype].end)
 				continue;
-			}
+
+			if (bridge->pd_bridge.ranges[prtype].start >
+			    bridge->pd_bridge.ranges[prtype].end)
+				continue;
+
 			error = pci_resource_claim(
 			    parent_bus->pb_res[prtype],
 			    bridge->pd_bridge.ranges[prtype].start,
@@ -858,13 +864,17 @@ pci_resource_probe(struct pci_resources 
 	pr->pr_bus = kmem_zalloc(nbus * sizeof(struct pci_bus *), KM_SLEEP);
 	memcpy(pr->pr_ranges, info->ranges, sizeof(pr->pr_ranges));
 	PCI_RANGE_FOREACH(prtype) {
-		if (prtype == PCI_RANGE_BUS || info->ranges[prtype].end) {
-			pr->pr_res[prtype] = pci_create_vmem(
-			    pci_resource_typename(prtype),
-			    info->ranges[prtype].start,
-			    info->ranges[prtype].end);
-			KASSERT(pr->pr_res[prtype] != NULL);
-		}
+		if (!(prtype == PCI_RANGE_BUS || info->ranges[prtype].end))
+			continue;
+
+		if (info->ranges[prtype].start > info->ranges[prtype].end)
+			continue;
+
+		pr->pr_res[prtype] = pci_create_vmem(
+		    pci_resource_typename(prtype),
+		    info->ranges[prtype].start,
+		    info->ranges[prtype].end);
+		KASSERT(pr->pr_res[prtype] != NULL);
 	}
 
 	/* Scan devices */
Index: sys/dev/pci/pci_usrreq.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/pci_usrreq.c,v
retrieving revision 1.31
diff -p -u -r1.31 pci_usrreq.c
--- sys/dev/pci/pci_usrreq.c	5 Sep 2021 03:47:24 -0000	1.31
+++ sys/dev/pci/pci_usrreq.c	2 Mar 2025 22:31:47 -0000
@@ -132,7 +132,7 @@ pciioctl(dev_t dev, u_long cmd, void *da
 			if (sc->sc_bus == dnameonbus->bus)
 				break;	/* found the right bus */
 		}
-		if (i == pci_cd.cd_ndevs || sc == NULL)
+		if (i == pci_cd.cd_ndevs)
 			return ENXIO;
 		if (dnameonbus->device >= sc->sc_maxndevs ||
 		    dnameonbus->function > 7)
Index: sys/arch/x86/acpi/acpi_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/acpi/acpi_machdep.c,v
retrieving revision 1.38
diff -p -u -r1.38 acpi_machdep.c
--- sys/arch/x86/acpi/acpi_machdep.c	6 Dec 2024 10:53:41 -0000	1.38
+++ sys/arch/x86/acpi/acpi_machdep.c	2 Mar 2025 22:31:47 -0000
@@ -80,6 +80,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_machdep
 #include "opt_mpbios.h"
 #include "opt_acpi.h"
 #include "opt_vga.h"
+#include "opt_pci.h"
 
 #ifdef XEN
 #include <xen/hypervisor.h>
@@ -582,6 +583,7 @@ static const struct acpimcfg_ops acpi_md
 void
 acpi_md_callback(struct acpi_softc *sc)
 {
+printf("ACPI MD CALLBACK\n");
 #ifdef MPBIOS
 	if (!mpbios_scanned)
 #endif
@@ -592,6 +594,11 @@ acpi_md_callback(struct acpi_softc *sc)
 #endif
 
 	acpimcfg_init(x86_bus_space_mem, &acpi_md_mcfg_ops);
+
+printf("PCI_NETBSD_CONFIGURE ?\n");
+#ifdef PCI_NETBSD_CONFIGURE
+	mpacpi_configure_busses(sc);
+#endif
 }
 
 #ifndef XENPV
Index: sys/arch/x86/include/mpacpi.h
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/include/mpacpi.h,v
retrieving revision 1.11
diff -p -u -r1.11 mpacpi.h
--- sys/arch/x86/include/mpacpi.h	23 May 2017 08:54:39 -0000	1.11
+++ sys/arch/x86/include/mpacpi.h	2 Mar 2025 22:31:47 -0000
@@ -7,6 +7,7 @@ struct pcibus_attach_args;
 
 int mpacpi_scan_apics(device_t, int *);
 int mpacpi_find_interrupts(void *);
+int mpacpi_configure_busses(void *);
 int mpacpi_pci_attach_hook(device_t, device_t,
 			   struct pcibus_attach_args *);
 
Index: sys/arch/x86/x86/mpacpi.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/mpacpi.c,v
retrieving revision 1.111
diff -p -u -r1.111 mpacpi.c
--- sys/arch/x86/x86/mpacpi.c	30 Sep 2024 17:00:10 -0000	1.111
+++ sys/arch/x86/x86/mpacpi.c	2 Mar 2025 22:31:47 -0000
@@ -72,6 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: mpacpi.c,v 1
 #include <dev/acpi/acpica.h>
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
+#include <dev/acpi/acpi_mcfg.h>
 
 #include <dev/cons.h>
 
@@ -975,6 +976,8 @@ mpacpi_pci_attach_hook(device_t parent, 
 		return ENOENT;
 #endif
 
+printf("MPACPI PCI ATTACH HOOK bus %d\n", pba->pba_bus);
+
 	if (TAILQ_EMPTY(&mpacpi_pcibusses))
 		return 0;
 
@@ -1023,6 +1026,44 @@ mpacpi_pci_attach_hook(device_t parent, 
 #endif
 
 int
+mpacpi_configure_busses(void *self)
+{
+	struct acpi_softc *acpi = self;
+
+printf("MPACPI CONFIGURE BUSSES ? acpi = %p\n", acpi);
+
+#if NPCI > 0
+	struct mpacpi_pcibus *mpr;
+	struct mp_bus *mpb;
+
+	mpr = TAILQ_FIRST(&mpacpi_pcibusses);
+printf("MPACPI pcibus = %p\n", mpr);
+
+	if (mpr) {
+		ACPI_HANDLE hdl = devhandle_to_acpi(mpr->mpr_devhandle);
+		if (mp_verbose)
+			printf("MPACPI handle %s seg %d bus %d\n",
+				acpi_name(hdl),
+				mpr->mpr_seg,
+				mpr->mpr_bus);
+
+		if (mpr->mpr_bus < 0 || mpr->mpr_bus >= mpacpi_maxpci) {
+			printf("MPACPI bus number (%d) >= maxpci (%d)\n",
+				mpr->mpr_bus, mpacpi_maxpci);
+			return -1;
+		}
+
+		mpb = &mp_busses[mpr->mpr_bus]; /* XXX */
+
+		acpimcfg_configure_bus(mpb->mb_dev, mpb->mb_pci_chipset_tag,
+		    hdl, mpr->mpr_bus, true);
+	}
+#endif
+
+	return 0;
+}
+
+int
 mpacpi_findintr_linkdev(struct mp_intr_map *mip)
 {
 	int irq, line, pol, trig;
