Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107493521
D43921.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D43921.diff
View Options
diff --git a/sys/dev/pci/pci_host_generic.h b/sys/dev/pci/pci_host_generic.h
--- a/sys/dev/pci/pci_host_generic.h
+++ b/sys/dev/pci/pci_host_generic.h
@@ -64,6 +64,7 @@
#define FLAG_TYPE_MEM 0x2
#define FLAG_TYPE_PMEM 0x3
struct resource *res;
+ int rid;
};
struct generic_pcie_core_softc {
diff --git a/sys/dev/pci/pci_host_generic.c b/sys/dev/pci/pci_host_generic.c
--- a/sys/dev/pci/pci_host_generic.c
+++ b/sys/dev/pci/pci_host_generic.c
@@ -59,6 +59,12 @@
#define PCI_RF_FLAGS 0
#endif
+/*
+ * We allocate "ranges" specified mappings higher up in the rid space to avoid
+ * conflicts with various definitions in the wild that may have other registers
+ * attributed to the controller besides just the config space.
+ */
+#define RANGE_RID(idx) ((idx) + 100)
/* Forward prototypes */
@@ -173,7 +179,7 @@
phys_base = sc->ranges[tuple].phys_base;
pci_base = sc->ranges[tuple].pci_base;
size = sc->ranges[tuple].size;
- rid = tuple + 1;
+ rid = RANGE_RID(tuple);
if (size == 0)
continue; /* empty range element */
switch (FLAG_TYPE(sc->ranges[tuple].flags)) {
@@ -210,6 +216,7 @@
error);
continue;
}
+ sc->ranges[tuple].rid = rid;
sc->ranges[tuple].res = bus_alloc_resource_any(dev, type, &rid,
RF_ACTIVE | RF_UNMAPPED | flags);
if (sc->ranges[tuple].res == NULL) {
@@ -246,7 +253,7 @@
pci_host_generic_core_detach(device_t dev)
{
struct generic_pcie_core_softc *sc;
- int error, tuple, type;
+ int error, rid, tuple, type;
sc = device_get_softc(dev);
@@ -255,8 +262,13 @@
return (error);
for (tuple = 0; tuple < MAX_RANGES_TUPLES; tuple++) {
- if (sc->ranges[tuple].size == 0)
+ rid = sc->ranges[tuple].rid;
+ if (sc->ranges[tuple].size == 0) {
+ MPASS(sc->ranges[tuple].res == NULL);
continue; /* empty range element */
+ }
+
+ MPASS(rid != -1);
switch (FLAG_TYPE(sc->ranges[tuple].flags)) {
case FLAG_TYPE_PMEM:
case FLAG_TYPE_MEM:
@@ -269,9 +281,9 @@
continue;
}
if (sc->ranges[tuple].res != NULL)
- bus_release_resource(dev, type, tuple + 1,
+ bus_release_resource(dev, type, rid,
sc->ranges[tuple].res);
- bus_delete_resource(dev, type, tuple + 1);
+ bus_delete_resource(dev, type, rid);
}
rman_fini(&sc->io_rman);
rman_fini(&sc->mem_rman);
diff --git a/sys/dev/pci/pci_host_generic_acpi.c b/sys/dev/pci/pci_host_generic_acpi.c
--- a/sys/dev/pci/pci_host_generic_acpi.c
+++ b/sys/dev/pci/pci_host_generic_acpi.c
@@ -182,6 +182,7 @@
/* Save detected ranges */
if (res->Data.Address.ResourceType == ACPI_MEMORY_RANGE ||
res->Data.Address.ResourceType == ACPI_IO_RANGE) {
+ sc->base.ranges[r].rid = -1;
sc->base.ranges[r].pci_base = min;
sc->base.ranges[r].phys_base = min + off;
sc->base.ranges[r].size = max - min + 1;
diff --git a/sys/dev/pci/pci_host_generic_fdt.c b/sys/dev/pci/pci_host_generic_fdt.c
--- a/sys/dev/pci/pci_host_generic_fdt.c
+++ b/sys/dev/pci/pci_host_generic_fdt.c
@@ -215,6 +215,7 @@
sc->ranges[i].flags |= FLAG_TYPE_MEM;
}
+ sc->ranges[i].rid = -1;
sc->ranges[i].pci_base = 0;
for (k = 0; k < (pci_addr_cells - 1); k++) {
sc->ranges[i].pci_base <<= 32;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 15, 11:47 PM (17 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15817437
Default Alt Text
D43921.diff (3 KB)
Attached To
Mode
D43921: pci: avoid accidental clobbering of regs on some fdt platforms
Attached
Detach File
Event Timeline
Log In to Comment