summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2009-04-11 17:13:34 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2009-04-11 17:13:34 +0000
commit08fa0b17d91348290772c5b75bc60e38f8d42bad (patch)
tree360afea18afde97fe9e2a50a6fcee1db7d0581d7
parenteccb04705ac1a9a387c0e27658f1ddf8f9c131ea (diff)
Create extents for resource accounting on the root PCI bus and populate them
based on the BIOS memory map.
-rw-r--r--sys/arch/amd64/amd64/mainbus.c6
-rw-r--r--sys/arch/amd64/include/pci_machdep.h6
-rw-r--r--sys/arch/amd64/pci/pci_machdep.c42
-rw-r--r--sys/arch/i386/i386/mainbus.c6
-rw-r--r--sys/arch/i386/pci/pci_machdep.c43
-rw-r--r--sys/arch/i386/pci/pci_machdep.h6
6 files changed, 102 insertions, 7 deletions
diff --git a/sys/arch/amd64/amd64/mainbus.c b/sys/arch/amd64/amd64/mainbus.c
index 9d643bc9e94..bffd3b32e32 100644
--- a/sys/arch/amd64/amd64/mainbus.c
+++ b/sys/arch/amd64/amd64/mainbus.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mainbus.c,v 1.17 2009/03/31 22:19:57 kettenis Exp $ */
+/* $OpenBSD: mainbus.c,v 1.18 2009/04/11 17:13:33 kettenis Exp $ */
/* $NetBSD: mainbus.c,v 1.1 2003/04/26 18:39:29 fvdl Exp $ */
/*
@@ -196,11 +196,15 @@ mainbus_attach(struct device *parent, struct device *self, void *aux)
#if NPCI > 0
if (pci_mode != 0) {
+ pci_init_extents();
+
bzero(&mba.mba_pba, sizeof(mba.mba_pba));
mba.mba_pba.pba_busname = "pci";
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_ioex = pciio_ex;
+ mba.mba_pba.pba_memex = pcimem_ex;
mba.mba_pba.pba_domain = pci_ndomains++;
mba.mba_pba.pba_bus = 0;
config_found(self, &mba.mba_pba, mainbus_print);
diff --git a/sys/arch/amd64/include/pci_machdep.h b/sys/arch/amd64/include/pci_machdep.h
index de5e88d3146..f9e754a32df 100644
--- a/sys/arch/amd64/include/pci_machdep.h
+++ b/sys/arch/amd64/include/pci_machdep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pci_machdep.h,v 1.9 2009/04/04 16:03:17 kettenis Exp $ */
+/* $OpenBSD: pci_machdep.h,v 1.10 2009/04/11 17:13:33 kettenis Exp $ */
/* $NetBSD: pci_machdep.h,v 1.1 2003/02/26 21:26:11 fvdl Exp $ */
/*
@@ -78,6 +78,10 @@ extern int pci_mode;
int pci_mode_detect(void);
struct pci_attach_args;
+extern struct extent *pciio_ex;
+extern struct extent *pcimem_ex;
+void pci_init_extents(void);
+
/*
* Functions provided to machine-independent PCI code.
*/
diff --git a/sys/arch/amd64/pci/pci_machdep.c b/sys/arch/amd64/pci/pci_machdep.c
index 96b62150d83..e91d7e8215f 100644
--- a/sys/arch/amd64/pci/pci_machdep.c
+++ b/sys/arch/amd64/pci/pci_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pci_machdep.c,v 1.24 2009/04/04 16:03:17 kettenis Exp $ */
+/* $OpenBSD: pci_machdep.c,v 1.25 2009/04/11 17:13:33 kettenis Exp $ */
/* $NetBSD: pci_machdep.c,v 1.3 2003/05/07 21:33:58 fvdl Exp $ */
/*-
@@ -79,6 +79,8 @@
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/device.h>
+#include <sys/extent.h>
+#include <sys/malloc.h>
#include <uvm/uvm_extern.h>
@@ -86,6 +88,7 @@
#include <machine/pio.h>
#include <machine/intr.h>
+#include <machine/biosvar.h>
#include <dev/isa/isareg.h>
#include <dev/isa/isavar.h>
@@ -549,3 +552,40 @@ pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
{
intr_disestablish(cookie);
}
+
+struct extent *pciio_ex;
+struct extent *pcimem_ex;
+
+void
+pci_init_extents(void)
+{
+ bios_memmap_t *bmp;
+ u_int64_t size;
+
+ if (pciio_ex == NULL)
+ pciio_ex = extent_create("pciio", 0, 0xffff, M_DEVBUF,
+ NULL, 0, EX_NOWAIT);
+
+ if (pcimem_ex == NULL) {
+ pcimem_ex = extent_create("pcimem", 0, 0xffffffff, M_DEVBUF,
+ NULL, 0, EX_NOWAIT);
+ if (pcimem_ex == NULL)
+ return;
+
+ for (bmp = bios_memmap; bmp->type != BIOS_MAP_END; bmp++) {
+ /*
+ * Ignore address space beyond 4G.
+ */
+ if (bmp->addr >= 0x100000000ULL)
+ continue;
+ size = bmp->size;
+ if (bmp->addr + size >= 0x100000000ULL)
+ size = 0x100000000ULL - bmp->addr;
+
+ if (extent_alloc_region(pcimem_ex, bmp->addr, size,
+ EX_NOWAIT))
+ printf("memory map conflict 0x%llx/0x%llx\n",
+ bmp->addr, bmp->size);
+ }
+ }
+}
diff --git a/sys/arch/i386/i386/mainbus.c b/sys/arch/i386/i386/mainbus.c
index 6abffc03463..eeaa040ca42 100644
--- a/sys/arch/i386/i386/mainbus.c
+++ b/sys/arch/i386/i386/mainbus.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mainbus.c,v 1.44 2009/03/31 21:57:57 kettenis Exp $ */
+/* $OpenBSD: mainbus.c,v 1.45 2009/04/11 17:13:32 kettenis Exp $ */
/* $NetBSD: mainbus.c,v 1.21 1997/06/06 23:14:20 thorpej Exp $ */
/*
@@ -231,11 +231,15 @@ mainbus_attach(struct device *parent, struct device *self, void *aux)
*/
#if NPCI > 0
if (pci_mode_detect() != 0) {
+ pci_init_extents();
+
bzero(&mba.mba_pba, sizeof(mba.mba_pba));
mba.mba_pba.pba_busname = "pci";
mba.mba_pba.pba_iot = I386_BUS_SPACE_IO;
mba.mba_pba.pba_memt = I386_BUS_SPACE_MEM;
mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
+ mba.mba_pba.pba_ioex = pciio_ex;
+ mba.mba_pba.pba_memex = pcimem_ex;
mba.mba_pba.pba_domain = pci_ndomains++;
mba.mba_pba.pba_bus = 0;
config_found(self, &mba.mba_pba, mainbus_print);
diff --git a/sys/arch/i386/pci/pci_machdep.c b/sys/arch/i386/pci/pci_machdep.c
index f37a299fe33..de60d8500d2 100644
--- a/sys/arch/i386/pci/pci_machdep.c
+++ b/sys/arch/i386/pci/pci_machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pci_machdep.c,v 1.45 2009/03/10 15:03:17 oga Exp $ */
+/* $OpenBSD: pci_machdep.c,v 1.46 2009/04/11 17:13:33 kettenis Exp $ */
/* $NetBSD: pci_machdep.c,v 1.28 1997/06/06 23:29:17 thorpej Exp $ */
/*-
@@ -79,16 +79,18 @@
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/device.h>
+#include <sys/extent.h>
+#include <sys/malloc.h>
#include <uvm/uvm_extern.h>
#include <machine/bus.h>
#include <machine/pio.h>
#include <machine/i8259.h>
+#include <machine/biosvar.h>
#include "bios.h"
#if NBIOS > 0
-#include <machine/biosvar.h>
extern bios_pciinfo_t *bios_pciinfo;
#endif
@@ -600,3 +602,40 @@ pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
/* XXX oh, unroute the pci int link? */
isa_intr_disestablish(NULL, cookie);
}
+
+struct extent *pciio_ex;
+struct extent *pcimem_ex;
+
+void
+pci_init_extents(void)
+{
+ bios_memmap_t *bmp;
+ u_int64_t size;
+
+ if (pciio_ex == NULL)
+ pciio_ex = extent_create("pciio", 0, 0xffff, M_DEVBUF,
+ NULL, 0, EX_NOWAIT);
+
+ if (pcimem_ex == NULL) {
+ pcimem_ex = extent_create("pcimem", 0, 0xffffffff, M_DEVBUF,
+ NULL, 0, EX_NOWAIT);
+ if (pcimem_ex == NULL)
+ return;
+
+ for (bmp = bios_memmap; bmp->type != BIOS_MAP_END; bmp++) {
+ /*
+ * Ignore address space beyond 4G.
+ */
+ if (bmp->addr >= 0x100000000ULL)
+ continue;
+ size = bmp->size;
+ if (bmp->addr + size >= 0x100000000ULL)
+ size = 0x100000000ULL - bmp->addr;
+
+ if (extent_alloc_region(pcimem_ex, bmp->addr, size,
+ EX_NOWAIT))
+ printf("memory map conflict 0x%llx/0x%llx\n",
+ bmp->addr, bmp->size);
+ }
+ }
+}
diff --git a/sys/arch/i386/pci/pci_machdep.h b/sys/arch/i386/pci/pci_machdep.h
index 778e632e5bc..0e840843711 100644
--- a/sys/arch/i386/pci/pci_machdep.h
+++ b/sys/arch/i386/pci/pci_machdep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pci_machdep.h,v 1.14 2008/12/06 19:59:38 tedu Exp $ */
+/* $OpenBSD: pci_machdep.h,v 1.15 2009/04/11 17:13:33 kettenis Exp $ */
/* $NetBSD: pci_machdep.h,v 1.7 1997/06/06 23:29:18 thorpej Exp $ */
/*
@@ -77,6 +77,10 @@ struct {
extern int pci_mode;
int pci_mode_detect(void);
+extern struct extent *pciio_ex;
+extern struct extent *pcimem_ex;
+void pci_init_extents(void);
+
/*
* Functions provided to machine-independent PCI code.
*/