pci: ecam: Correctly parse memory and IO region

When activating a resource do not compare the resource id to the adress.
Treat IO region as MEMORY region too.

Submitted by:	Tuan Phan <tphan@amperecomputing.com> (Original Version)
Sponsored by:	Ampere Computing, LLC
Differential Revision:	https://reviews.freebsd.org/D20214
This commit is contained in:
Emmanuel Vadot 2019-05-17 17:05:16 +00:00
parent aa95512f35
commit ec55b6c5f5
2 changed files with 7 additions and 8 deletions

View File

@ -359,29 +359,30 @@ generic_pcie_activate_resource(device_t dev, device_t child, int type,
switch (type) {
case SYS_RES_IOPORT:
case SYS_RES_MEMORY:
found = 0;
for (i = 0; i < MAX_RANGES_TUPLES; i++) {
pci_base = sc->ranges[i].pci_base;
phys_base = sc->ranges[i].phys_base;
size = sc->ranges[i].size;
if ((rid > pci_base) && (rid < (pci_base + size))) {
if ((rman_get_start(r) >= pci_base) && (rman_get_start(r) < (pci_base + size))) {
found = 1;
break;
}
}
if (found) {
rman_set_start(r, rman_get_start(r) + phys_base);
rman_set_end(r, rman_get_end(r) + phys_base);
rman_set_start(r, rman_get_start(r) - pci_base + phys_base);
rman_set_end(r, rman_get_end(r) - pci_base + phys_base);
res = BUS_ACTIVATE_RESOURCE(device_get_parent(dev),
child, type, rid, r);
} else {
device_printf(dev,
"Failed to activate IOPORT resource\n");
"Failed to activate %s resource\n",
type == SYS_RES_IOPORT ? "IOPORT" : "MEMORY");
res = 0;
}
break;
case SYS_RES_MEMORY:
case SYS_RES_IRQ:
res = BUS_ACTIVATE_RESOURCE(device_get_parent(dev), child,
type, rid, r);

View File

@ -148,8 +148,6 @@ pci_host_generic_acpi_parse_resource(ACPI_RESOURCE *res, void *arg)
off = res->Data.Address32.Address.TranslationOffset;
break;
case ACPI_RESOURCE_TYPE_ADDRESS64:
if (res->Data.Address.ResourceType != ACPI_MEMORY_RANGE)
break;
min = res->Data.Address64.Address.Minimum;
max = res->Data.Address64.Address.Maximum;
off = res->Data.Address64.Address.TranslationOffset;
@ -293,7 +291,7 @@ pci_host_generic_acpi_attach(device_t dev)
continue; /* empty range element */
if (sc->base.ranges[tuple].flags & FLAG_MEM) {
error = rman_manage_region(&sc->base.mem_rman,
phys_base, phys_base + size - 1);
pci_base, pci_base + size - 1);
} else if (sc->base.ranges[tuple].flags & FLAG_IO) {
error = rman_manage_region(&sc->base.io_rman,
pci_base + PCI_IO_WINDOW_OFFSET,