summaryrefslogtreecommitdiff
path: root/sys/dev/pci/pci_map.c
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2009-04-06 20:51:49 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2009-04-06 20:51:49 +0000
commit46990b14d260e53f3cc5476531b07d43c6381cf9 (patch)
tree082cc204b4b1486a2c2f5af388d98eef69ae8167 /sys/dev/pci/pci_map.c
parent28400fae1b342b9c5d57327c525ecf50b259761e (diff)
Set a first step on the road towards proper accounting of PCI resources by
keeping a per-bus extent containing the address space available to the bus. Address space assigned to devices will be removed from these extents when we attach a bus. And when we try to map a PCI BAR that hasn't had address space assigned to it, we will allocate free space from this extent. This won't do anything until the parent devices actually allocate and initialize the extents. ok oga@
Diffstat (limited to 'sys/dev/pci/pci_map.c')
-rw-r--r--sys/dev/pci/pci_map.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/sys/dev/pci/pci_map.c b/sys/dev/pci/pci_map.c
index f3544e0c80e..ae9677bf686 100644
--- a/sys/dev/pci/pci_map.c
+++ b/sys/dev/pci/pci_map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pci_map.c,v 1.23 2008/06/26 05:42:17 ray Exp $ */
+/* $OpenBSD: pci_map.c,v 1.24 2009/04/06 20:51:48 kettenis Exp $ */
/* $NetBSD: pci_map.c,v 1.7 2000/05/10 16:58:42 thorpej Exp $ */
/*-
@@ -320,8 +320,22 @@ pci_mapreg_map(struct pci_attach_args *pa, int reg, pcireg_t type, int busflags,
&base, &size, &flags)) != 0)
return (rv);
#if !defined(__sparc64__) && !defined(__socppc__)
- if (base == 0)
- return (EINVAL); /* disabled because of invalid BAR */
+ if (base == 0) {
+ struct extent *ex;
+
+ if (PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_IO)
+ ex = pa->pa_ioex;
+ else
+ ex = pa->pa_memex;
+
+ if (ex == NULL || extent_alloc(ex, size, size, 0, 0, 0, &base))
+ return (EINVAL); /* disabled because of invalid BAR */
+
+ pci_conf_write(pa->pa_pc, pa->pa_tag, reg, base);
+ if (PCI_MAPREG_MEM_TYPE(type) == PCI_MAPREG_MEM_TYPE_64BIT)
+ pci_conf_write(pa->pa_pc, pa->pa_tag, reg + 4,
+ (u_int64_t)base >> 32);
+ }
#endif
csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);