pci_host_generic : move activate/release to generic code
Now that the ACPI and FDT implementations for activating and deactivating resources are the same, we can move it to pci_host_generic.c. No functional changes. Reviewed by: andrew Differential Revision: https://reviews.freebsd.org/D17793
This commit is contained in:
parent
f916d05797
commit
bd158cddc4
@ -340,6 +340,82 @@ pci_host_generic_core_alloc_resource(device_t dev, device_t child, int type,
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
generic_pcie_activate_resource(device_t dev, device_t child, int type,
|
||||
int rid, struct resource *r)
|
||||
{
|
||||
struct generic_pcie_core_softc *sc;
|
||||
uint64_t phys_base;
|
||||
uint64_t pci_base;
|
||||
uint64_t size;
|
||||
int found;
|
||||
int res;
|
||||
int i;
|
||||
|
||||
sc = device_get_softc(dev);
|
||||
|
||||
if ((res = rman_activate_resource(r)) != 0)
|
||||
return (res);
|
||||
|
||||
switch (type) {
|
||||
case SYS_RES_IOPORT:
|
||||
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))) {
|
||||
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);
|
||||
res = BUS_ACTIVATE_RESOURCE(device_get_parent(dev),
|
||||
child, type, rid, r);
|
||||
} else {
|
||||
device_printf(dev,
|
||||
"Failed to activate IOPORT resource\n");
|
||||
res = 0;
|
||||
}
|
||||
break;
|
||||
case SYS_RES_MEMORY:
|
||||
case SYS_RES_IRQ:
|
||||
res = BUS_ACTIVATE_RESOURCE(device_get_parent(dev), child,
|
||||
type, rid, r);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
static int
|
||||
generic_pcie_deactivate_resource(device_t dev, device_t child, int type,
|
||||
int rid, struct resource *r)
|
||||
{
|
||||
int res;
|
||||
|
||||
if ((res = rman_deactivate_resource(r)) != 0)
|
||||
return (res);
|
||||
|
||||
switch (type) {
|
||||
case SYS_RES_IOPORT:
|
||||
case SYS_RES_MEMORY:
|
||||
case SYS_RES_IRQ:
|
||||
res = BUS_DEACTIVATE_RESOURCE(device_get_parent(dev), child,
|
||||
type, rid, r);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
static int
|
||||
generic_pcie_adjust_resource(device_t dev, device_t child, int type,
|
||||
struct resource *res, rman_res_t start, rman_res_t end)
|
||||
@ -375,6 +451,8 @@ static device_method_t generic_pcie_methods[] = {
|
||||
DEVMETHOD(bus_write_ivar, generic_pcie_write_ivar),
|
||||
DEVMETHOD(bus_alloc_resource, pci_host_generic_core_alloc_resource),
|
||||
DEVMETHOD(bus_adjust_resource, generic_pcie_adjust_resource),
|
||||
DEVMETHOD(bus_activate_resource, generic_pcie_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource, generic_pcie_deactivate_resource),
|
||||
DEVMETHOD(bus_release_resource, pci_host_generic_core_release_resource),
|
||||
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
|
||||
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
||||
|
@ -348,85 +348,6 @@ generic_pcie_acpi_route_interrupt(device_t bus, device_t dev, int pin)
|
||||
return (acpi_pcib_route_interrupt(bus, dev, pin, &sc->ap_prt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Follow logic of FDT activate
|
||||
*/
|
||||
static int
|
||||
generic_pcie_acpi_activate_resource(device_t dev, device_t child, int type,
|
||||
int rid, struct resource *r)
|
||||
{
|
||||
struct generic_pcie_acpi_softc *sc;
|
||||
uint64_t phys_base;
|
||||
uint64_t pci_base;
|
||||
uint64_t size;
|
||||
int found;
|
||||
int res;
|
||||
int i;
|
||||
|
||||
sc = device_get_softc(dev);
|
||||
|
||||
if ((res = rman_activate_resource(r)) != 0)
|
||||
return (res);
|
||||
|
||||
switch (type) {
|
||||
case SYS_RES_IOPORT:
|
||||
found = 0;
|
||||
for (i = 0; i < MAX_RANGES_TUPLES; i++) {
|
||||
pci_base = sc->base.ranges[i].pci_base;
|
||||
phys_base = sc->base.ranges[i].phys_base;
|
||||
size = sc->base.ranges[i].size;
|
||||
|
||||
if ((rid > pci_base) && (rid < (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);
|
||||
res = BUS_ACTIVATE_RESOURCE(device_get_parent(dev),
|
||||
child, type, rid, r);
|
||||
} else {
|
||||
device_printf(dev,
|
||||
"Failed to activate IOPORT resource\n");
|
||||
res = 0;
|
||||
}
|
||||
break;
|
||||
case SYS_RES_MEMORY:
|
||||
case SYS_RES_IRQ:
|
||||
res = BUS_ACTIVATE_RESOURCE(device_get_parent(dev), child,
|
||||
type, rid, r);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
static int
|
||||
generic_pcie_acpi_deactivate_resource(device_t dev, device_t child, int type,
|
||||
int rid, struct resource *r)
|
||||
{
|
||||
int res;
|
||||
|
||||
if ((res = rman_deactivate_resource(r)) != 0)
|
||||
return (res);
|
||||
|
||||
switch (type) {
|
||||
case SYS_RES_IOPORT:
|
||||
case SYS_RES_MEMORY:
|
||||
case SYS_RES_IRQ:
|
||||
res = BUS_DEACTIVATE_RESOURCE(device_get_parent(dev), child,
|
||||
type, rid, r);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
static int
|
||||
generic_pcie_acpi_alloc_msi(device_t pci, device_t child, int count,
|
||||
int maxcount, int *irqs)
|
||||
@ -507,8 +428,6 @@ static device_method_t generic_pcie_acpi_methods[] = {
|
||||
DEVMETHOD(device_probe, generic_pcie_acpi_probe),
|
||||
DEVMETHOD(device_attach, pci_host_generic_acpi_attach),
|
||||
DEVMETHOD(bus_read_ivar, generic_pcie_acpi_read_ivar),
|
||||
DEVMETHOD(bus_activate_resource, generic_pcie_acpi_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource,generic_pcie_acpi_deactivate_resource),
|
||||
|
||||
/* pcib interface */
|
||||
DEVMETHOD(pcib_route_interrupt, generic_pcie_acpi_route_interrupt),
|
||||
|
@ -384,82 +384,6 @@ pci_host_generic_alloc_resource(device_t dev, device_t child, int type,
|
||||
end, count, flags));
|
||||
}
|
||||
|
||||
static int
|
||||
generic_pcie_fdt_activate_resource(device_t dev, device_t child, int type,
|
||||
int rid, struct resource *r)
|
||||
{
|
||||
struct generic_pcie_fdt_softc *sc;
|
||||
uint64_t phys_base;
|
||||
uint64_t pci_base;
|
||||
uint64_t size;
|
||||
int found;
|
||||
int res;
|
||||
int i;
|
||||
|
||||
sc = device_get_softc(dev);
|
||||
|
||||
if ((res = rman_activate_resource(r)) != 0)
|
||||
return (res);
|
||||
|
||||
switch(type) {
|
||||
case SYS_RES_IOPORT:
|
||||
found = 0;
|
||||
for (i = 0; i < MAX_RANGES_TUPLES; i++) {
|
||||
pci_base = sc->base.ranges[i].pci_base;
|
||||
phys_base = sc->base.ranges[i].phys_base;
|
||||
size = sc->base.ranges[i].size;
|
||||
|
||||
if ((rid > pci_base) && (rid < (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);
|
||||
res = BUS_ACTIVATE_RESOURCE(device_get_parent(dev),
|
||||
child, type, rid, r);
|
||||
} else {
|
||||
device_printf(dev,
|
||||
"Failed to activate IOPORT resource\n");
|
||||
res = 0;
|
||||
}
|
||||
break;
|
||||
case SYS_RES_MEMORY:
|
||||
case SYS_RES_IRQ:
|
||||
res = BUS_ACTIVATE_RESOURCE(device_get_parent(dev), child,
|
||||
type, rid, r);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
static int
|
||||
generic_pcie_fdt_deactivate_resource(device_t dev, device_t child, int type,
|
||||
int rid, struct resource *r)
|
||||
{
|
||||
int res;
|
||||
|
||||
if ((res = rman_deactivate_resource(r)) != 0)
|
||||
return (res);
|
||||
|
||||
switch(type) {
|
||||
case SYS_RES_IOPORT:
|
||||
case SYS_RES_MEMORY:
|
||||
case SYS_RES_IRQ:
|
||||
res = BUS_DEACTIVATE_RESOURCE(device_get_parent(dev), child,
|
||||
type, rid, r);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
static int
|
||||
generic_pcie_fdt_alloc_msi(device_t pci, device_t child, int count,
|
||||
int maxcount, int *irqs)
|
||||
@ -630,8 +554,6 @@ static device_method_t generic_pcie_fdt_methods[] = {
|
||||
DEVMETHOD(device_attach, pci_host_generic_attach),
|
||||
DEVMETHOD(bus_alloc_resource, pci_host_generic_alloc_resource),
|
||||
DEVMETHOD(bus_release_resource, generic_pcie_fdt_release_resource),
|
||||
DEVMETHOD(bus_activate_resource, generic_pcie_fdt_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource,generic_pcie_fdt_deactivate_resource),
|
||||
|
||||
/* pcib interface */
|
||||
DEVMETHOD(pcib_route_interrupt, generic_pcie_fdt_route_interrupt),
|
||||
|
Loading…
Reference in New Issue
Block a user