Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/ofw/ofw_pcib.c
- This file was moved from sys/dev/ofw/ofwpci.c.
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
#define PCI_MAP_INTR 4 | #define PCI_MAP_INTR 4 | ||||
#endif | #endif | ||||
#define PCI_INTR_PINS 4 | #define PCI_INTR_PINS 4 | ||||
/* | /* | ||||
* bus interface. | * bus interface. | ||||
*/ | */ | ||||
static struct resource * ofw_pci_alloc_resource(device_t, device_t, | static struct resource * ofw_pcib_alloc_resource(device_t, device_t, | ||||
int, int *, rman_res_t, rman_res_t, rman_res_t, u_int); | int, int *, rman_res_t, rman_res_t, rman_res_t, u_int); | ||||
static int ofw_pci_release_resource(device_t, device_t, int, int, | static int ofw_pcib_release_resource(device_t, device_t, int, int, | ||||
struct resource *); | struct resource *); | ||||
static int ofw_pci_activate_resource(device_t, device_t, int, int, | static int ofw_pcib_activate_resource(device_t, device_t, int, int, | ||||
struct resource *); | struct resource *); | ||||
static int ofw_pci_deactivate_resource(device_t, device_t, int, int, | static int ofw_pcib_deactivate_resource(device_t, device_t, int, int, | ||||
struct resource *); | struct resource *); | ||||
static int ofw_pci_adjust_resource(device_t, device_t, int, | static int ofw_pcib_adjust_resource(device_t, device_t, int, | ||||
struct resource *, rman_res_t, rman_res_t); | struct resource *, rman_res_t, rman_res_t); | ||||
static int ofw_pci_translate_resource(device_t bus, int type, | static int ofw_pcib_translate_resource(device_t bus, int type, | ||||
rman_res_t start, rman_res_t *newstart); | rman_res_t start, rman_res_t *newstart); | ||||
#ifdef __powerpc__ | #ifdef __powerpc__ | ||||
static bus_space_tag_t ofw_pci_bus_get_bus_tag(device_t, device_t); | static bus_space_tag_t ofw_pcib_bus_get_bus_tag(device_t, device_t); | ||||
#endif | #endif | ||||
/* | /* | ||||
* pcib interface | * pcib interface | ||||
*/ | */ | ||||
static int ofw_pci_maxslots(device_t); | static int ofw_pcib_maxslots(device_t); | ||||
/* | /* | ||||
* ofw_bus interface | * ofw_bus interface | ||||
*/ | */ | ||||
static phandle_t ofw_pci_get_node(device_t, device_t); | static phandle_t ofw_pcib_get_node(device_t, device_t); | ||||
/* | /* | ||||
* local methods | * local methods | ||||
*/ | */ | ||||
static int ofw_pci_fill_ranges(phandle_t, struct ofw_pci_range *); | static int ofw_pcib_fill_ranges(phandle_t, struct ofw_pci_range *); | ||||
static struct rman *ofw_pci_get_rman(struct ofw_pci_softc *, int, u_int); | static struct rman *ofw_pcib_get_rman(struct ofw_pci_softc *, int, u_int); | ||||
/* | /* | ||||
* Driver methods. | * Driver methods. | ||||
*/ | */ | ||||
static device_method_t ofw_pci_methods[] = { | static device_method_t ofw_pcib_methods[] = { | ||||
/* Device interface */ | /* Device interface */ | ||||
DEVMETHOD(device_attach, ofw_pci_attach), | DEVMETHOD(device_attach, ofw_pcib_attach), | ||||
/* Bus interface */ | /* Bus interface */ | ||||
DEVMETHOD(bus_print_child, bus_generic_print_child), | DEVMETHOD(bus_print_child, bus_generic_print_child), | ||||
DEVMETHOD(bus_read_ivar, ofw_pci_read_ivar), | DEVMETHOD(bus_read_ivar, ofw_pcib_read_ivar), | ||||
DEVMETHOD(bus_write_ivar, ofw_pci_write_ivar), | DEVMETHOD(bus_write_ivar, ofw_pcib_write_ivar), | ||||
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), | DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), | ||||
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), | DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), | ||||
DEVMETHOD(bus_alloc_resource, ofw_pci_alloc_resource), | DEVMETHOD(bus_alloc_resource, ofw_pcib_alloc_resource), | ||||
DEVMETHOD(bus_release_resource, ofw_pci_release_resource), | DEVMETHOD(bus_release_resource, ofw_pcib_release_resource), | ||||
DEVMETHOD(bus_activate_resource, ofw_pci_activate_resource), | DEVMETHOD(bus_activate_resource, ofw_pcib_activate_resource), | ||||
DEVMETHOD(bus_deactivate_resource, ofw_pci_deactivate_resource), | DEVMETHOD(bus_deactivate_resource, ofw_pcib_deactivate_resource), | ||||
DEVMETHOD(bus_adjust_resource, ofw_pci_adjust_resource), | DEVMETHOD(bus_adjust_resource, ofw_pcib_adjust_resource), | ||||
DEVMETHOD(bus_translate_resource, ofw_pci_translate_resource), | DEVMETHOD(bus_translate_resource, ofw_pcib_translate_resource), | ||||
#ifdef __powerpc__ | #ifdef __powerpc__ | ||||
DEVMETHOD(bus_get_bus_tag, ofw_pci_bus_get_bus_tag), | DEVMETHOD(bus_get_bus_tag, ofw_pcib_bus_get_bus_tag), | ||||
#endif | #endif | ||||
/* pcib interface */ | /* pcib interface */ | ||||
DEVMETHOD(pcib_maxslots, ofw_pci_maxslots), | DEVMETHOD(pcib_maxslots, ofw_pcib_maxslots), | ||||
DEVMETHOD(pcib_route_interrupt, ofw_pci_route_interrupt), | DEVMETHOD(pcib_route_interrupt, ofw_pcib_route_interrupt), | ||||
DEVMETHOD(pcib_request_feature, pcib_request_feature_allow), | DEVMETHOD(pcib_request_feature, pcib_request_feature_allow), | ||||
/* ofw_bus interface */ | /* ofw_bus interface */ | ||||
DEVMETHOD(ofw_bus_get_node, ofw_pci_get_node), | DEVMETHOD(ofw_bus_get_node, ofw_pcib_get_node), | ||||
DEVMETHOD_END | DEVMETHOD_END | ||||
}; | }; | ||||
DEFINE_CLASS_0(ofw_pci, ofw_pci_driver, ofw_pci_methods, 0); | DEFINE_CLASS_0(ofw_pcib, ofw_pcib_driver, ofw_pcib_methods, 0); | ||||
int | int | ||||
ofw_pci_init(device_t dev) | ofw_pcib_init(device_t dev) | ||||
{ | { | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
phandle_t node; | phandle_t node; | ||||
u_int32_t busrange[2]; | u_int32_t busrange[2]; | ||||
struct ofw_pci_range *rp; | struct ofw_pci_range *rp; | ||||
int i, error; | int i, error; | ||||
struct ofw_pci_cell_info *cell_info; | struct ofw_pci_cell_info *cell_info; | ||||
Show All 16 Lines | ofw_pcib_init(device_t dev) | ||||
sc->sc_bus = busrange[0]; | sc->sc_bus = busrange[0]; | ||||
if (sc->sc_quirks & OFW_PCI_QUIRK_RANGES_ON_CHILDREN) { | if (sc->sc_quirks & OFW_PCI_QUIRK_RANGES_ON_CHILDREN) { | ||||
phandle_t c; | phandle_t c; | ||||
int n, i; | int n, i; | ||||
sc->sc_nrange = 0; | sc->sc_nrange = 0; | ||||
for (c = OF_child(node); c != 0; c = OF_peer(c)) { | for (c = OF_child(node); c != 0; c = OF_peer(c)) { | ||||
n = ofw_pci_nranges(c, cell_info); | n = ofw_pcib_nranges(c, cell_info); | ||||
if (n > 0) | if (n > 0) | ||||
sc->sc_nrange += n; | sc->sc_nrange += n; | ||||
} | } | ||||
if (sc->sc_nrange == 0) { | if (sc->sc_nrange == 0) { | ||||
error = ENXIO; | error = ENXIO; | ||||
goto out; | goto out; | ||||
} | } | ||||
sc->sc_range = malloc(sc->sc_nrange * sizeof(sc->sc_range[0]), | sc->sc_range = malloc(sc->sc_nrange * sizeof(sc->sc_range[0]), | ||||
M_DEVBUF, M_WAITOK); | M_DEVBUF, M_WAITOK); | ||||
i = 0; | i = 0; | ||||
for (c = OF_child(node); c != 0; c = OF_peer(c)) { | for (c = OF_child(node); c != 0; c = OF_peer(c)) { | ||||
n = ofw_pci_fill_ranges(c, &sc->sc_range[i]); | n = ofw_pcib_fill_ranges(c, &sc->sc_range[i]); | ||||
if (n > 0) | if (n > 0) | ||||
i += n; | i += n; | ||||
} | } | ||||
KASSERT(i == sc->sc_nrange, ("range count mismatch")); | KASSERT(i == sc->sc_nrange, ("range count mismatch")); | ||||
} else { | } else { | ||||
sc->sc_nrange = ofw_pci_nranges(node, cell_info); | sc->sc_nrange = ofw_pcib_nranges(node, cell_info); | ||||
if (sc->sc_nrange <= 0) { | if (sc->sc_nrange <= 0) { | ||||
device_printf(dev, "could not getranges\n"); | device_printf(dev, "could not getranges\n"); | ||||
error = ENXIO; | error = ENXIO; | ||||
goto out; | goto out; | ||||
} | } | ||||
sc->sc_range = malloc(sc->sc_nrange * sizeof(sc->sc_range[0]), | sc->sc_range = malloc(sc->sc_nrange * sizeof(sc->sc_range[0]), | ||||
M_DEVBUF, M_WAITOK); | M_DEVBUF, M_WAITOK); | ||||
ofw_pci_fill_ranges(node, sc->sc_range); | ofw_pcib_fill_ranges(node, sc->sc_range); | ||||
} | } | ||||
sc->sc_io_rman.rm_type = RMAN_ARRAY; | sc->sc_io_rman.rm_type = RMAN_ARRAY; | ||||
sc->sc_io_rman.rm_descr = "PCI I/O Ports"; | sc->sc_io_rman.rm_descr = "PCI I/O Ports"; | ||||
error = rman_init(&sc->sc_io_rman); | error = rman_init(&sc->sc_io_rman); | ||||
if (error != 0) { | if (error != 0) { | ||||
device_printf(dev, "rman_init() failed. error = %d\n", error); | device_printf(dev, "rman_init() failed. error = %d\n", error); | ||||
goto out; | goto out; | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | out: | ||||
rman_fini(&sc->sc_io_rman); | rman_fini(&sc->sc_io_rman); | ||||
rman_fini(&sc->sc_mem_rman); | rman_fini(&sc->sc_mem_rman); | ||||
rman_fini(&sc->sc_pmem_rman); | rman_fini(&sc->sc_pmem_rman); | ||||
return (error); | return (error); | ||||
} | } | ||||
int | int | ||||
ofw_pci_attach(device_t dev) | ofw_pcib_attach(device_t dev) | ||||
{ | { | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
int error; | int error; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
if (!sc->sc_initialized) { | if (!sc->sc_initialized) { | ||||
error = ofw_pci_init(dev); | error = ofw_pcib_init(dev); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
} | } | ||||
device_add_child(dev, "pci", -1); | device_add_child(dev, "pci", -1); | ||||
return (bus_generic_attach(dev)); | return (bus_generic_attach(dev)); | ||||
} | } | ||||
static int | static int | ||||
ofw_pci_maxslots(device_t dev) | ofw_pcib_maxslots(device_t dev) | ||||
{ | { | ||||
return (PCI_SLOTMAX); | return (PCI_SLOTMAX); | ||||
} | } | ||||
int | int | ||||
ofw_pci_route_interrupt(device_t bus, device_t dev, int pin) | ofw_pcib_route_interrupt(device_t bus, device_t dev, int pin) | ||||
{ | { | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
struct ofw_pci_register reg; | struct ofw_pci_register reg; | ||||
uint32_t pintr, mintr[PCI_MAP_INTR]; | uint32_t pintr, mintr[PCI_MAP_INTR]; | ||||
int intrcells; | int intrcells; | ||||
phandle_t iparent; | phandle_t iparent; | ||||
sc = device_get_softc(bus); | sc = device_get_softc(bus); | ||||
Show All 20 Lines | if (pin > PCI_INTR_PINS) | ||||
return (pin); | return (pin); | ||||
device_printf(bus, "could not route pin %d for device %d.%d\n", | device_printf(bus, "could not route pin %d for device %d.%d\n", | ||||
pin, pci_get_slot(dev), pci_get_function(dev)); | pin, pci_get_slot(dev), pci_get_function(dev)); | ||||
return (PCI_INVALID_IRQ); | return (PCI_INVALID_IRQ); | ||||
} | } | ||||
int | int | ||||
ofw_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) | ofw_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) | ||||
{ | { | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
switch (which) { | switch (which) { | ||||
case PCIB_IVAR_DOMAIN: | case PCIB_IVAR_DOMAIN: | ||||
*result = sc->sc_pci_domain; | *result = sc->sc_pci_domain; | ||||
return (0); | return (0); | ||||
case PCIB_IVAR_BUS: | case PCIB_IVAR_BUS: | ||||
*result = sc->sc_bus; | *result = sc->sc_bus; | ||||
return (0); | return (0); | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
return (ENOENT); | return (ENOENT); | ||||
} | } | ||||
int | int | ||||
ofw_pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value) | ofw_pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value) | ||||
{ | { | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
switch (which) { | switch (which) { | ||||
case PCIB_IVAR_BUS: | case PCIB_IVAR_BUS: | ||||
sc->sc_bus = value; | sc->sc_bus = value; | ||||
return (0); | return (0); | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
return (ENOENT); | return (ENOENT); | ||||
} | } | ||||
int | int | ||||
ofw_pci_nranges(phandle_t node, struct ofw_pci_cell_info *info) | ofw_pcib_nranges(phandle_t node, struct ofw_pci_cell_info *info) | ||||
{ | { | ||||
ssize_t nbase_ranges; | ssize_t nbase_ranges; | ||||
if (info == NULL) | if (info == NULL) | ||||
return (-1); | return (-1); | ||||
info->host_address_cells = 1; | info->host_address_cells = 1; | ||||
info->size_cells = 2; | info->size_cells = 2; | ||||
Show All 11 Lines | if (nbase_ranges <= 0) | ||||
return (-1); | return (-1); | ||||
return (nbase_ranges / sizeof(cell_t) / | return (nbase_ranges / sizeof(cell_t) / | ||||
(info->pci_address_cell + info->host_address_cells + | (info->pci_address_cell + info->host_address_cells + | ||||
info->size_cells)); | info->size_cells)); | ||||
} | } | ||||
static struct resource * | static struct resource * | ||||
ofw_pci_alloc_resource(device_t bus, device_t child, int type, int *rid, | ofw_pcib_alloc_resource(device_t bus, device_t child, int type, int *rid, | ||||
rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) | rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) | ||||
{ | { | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
struct resource *rv; | struct resource *rv; | ||||
struct rman *rm; | struct rman *rm; | ||||
int needactivate; | int needactivate; | ||||
needactivate = flags & RF_ACTIVE; | needactivate = flags & RF_ACTIVE; | ||||
flags &= ~RF_ACTIVE; | flags &= ~RF_ACTIVE; | ||||
sc = device_get_softc(bus); | sc = device_get_softc(bus); | ||||
#if defined(NEW_PCIB) && defined(PCI_RES_BUS) | #if defined(NEW_PCIB) && defined(PCI_RES_BUS) | ||||
if (type == PCI_RES_BUS) { | if (type == PCI_RES_BUS) { | ||||
return (pci_domain_alloc_bus(sc->sc_pci_domain, child, rid, | return (pci_domain_alloc_bus(sc->sc_pci_domain, child, rid, | ||||
start, end, count, flags | needactivate)); | start, end, count, flags | needactivate)); | ||||
} | } | ||||
#endif | #endif | ||||
rm = ofw_pci_get_rman(sc, type, flags); | rm = ofw_pcib_get_rman(sc, type, flags); | ||||
if (rm == NULL) { | if (rm == NULL) { | ||||
return (bus_generic_alloc_resource(bus, child, type, rid, | return (bus_generic_alloc_resource(bus, child, type, rid, | ||||
start, end, count, flags | needactivate)); | start, end, count, flags | needactivate)); | ||||
} | } | ||||
rv = rman_reserve_resource(rm, start, end, count, flags, child); | rv = rman_reserve_resource(rm, start, end, count, flags, child); | ||||
if (rv == NULL) { | if (rv == NULL) { | ||||
device_printf(bus, "failed to reserve resource for %s\n", | device_printf(bus, "failed to reserve resource for %s\n", | ||||
Show All 12 Lines | if (bus_activate_resource(child, type, *rid, rv) != 0) { | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
} | } | ||||
return (rv); | return (rv); | ||||
} | } | ||||
static int | static int | ||||
ofw_pci_release_resource(device_t bus, device_t child, int type, int rid, | ofw_pcib_release_resource(device_t bus, device_t child, int type, int rid, | ||||
struct resource *res) | struct resource *res) | ||||
{ | { | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
struct rman *rm; | struct rman *rm; | ||||
int error; | int error; | ||||
sc = device_get_softc(bus); | sc = device_get_softc(bus); | ||||
#if defined(NEW_PCIB) && defined(PCI_RES_BUS) | #if defined(NEW_PCIB) && defined(PCI_RES_BUS) | ||||
if (type == PCI_RES_BUS) | if (type == PCI_RES_BUS) | ||||
return (pci_domain_release_bus(sc->sc_pci_domain, child, rid, | return (pci_domain_release_bus(sc->sc_pci_domain, child, rid, | ||||
res)); | res)); | ||||
#endif | #endif | ||||
rm = ofw_pci_get_rman(sc, type, rman_get_flags(res)); | rm = ofw_pcib_get_rman(sc, type, rman_get_flags(res)); | ||||
if (rm == NULL) { | if (rm == NULL) { | ||||
return (bus_generic_release_resource(bus, child, type, rid, | return (bus_generic_release_resource(bus, child, type, rid, | ||||
res)); | res)); | ||||
} | } | ||||
KASSERT(rman_is_region_manager(res, rm), ("rman mismatch")); | KASSERT(rman_is_region_manager(res, rm), ("rman mismatch")); | ||||
if (rman_get_flags(res) & RF_ACTIVE) { | if (rman_get_flags(res) & RF_ACTIVE) { | ||||
error = bus_deactivate_resource(child, type, rid, res); | error = bus_deactivate_resource(child, type, rid, res); | ||||
if (error != 0) | if (error != 0) | ||||
return (error); | return (error); | ||||
} | } | ||||
return (rman_release_resource(res)); | return (rman_release_resource(res)); | ||||
} | } | ||||
static int | static int | ||||
ofw_pci_translate_resource(device_t bus, int type, rman_res_t start, | ofw_pcib_translate_resource(device_t bus, int type, rman_res_t start, | ||||
rman_res_t *newstart) | rman_res_t *newstart) | ||||
{ | { | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
struct ofw_pci_range *rp; | struct ofw_pci_range *rp; | ||||
int space; | int space; | ||||
sc = device_get_softc(bus); | sc = device_get_softc(bus); | ||||
Show All 22 Lines | if (type == space) { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
*newstart = start; | *newstart = start; | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
ofw_pci_activate_resource(device_t bus, device_t child, int type, int rid, | ofw_pcib_activate_resource(device_t bus, device_t child, int type, int rid, | ||||
struct resource *res) | struct resource *res) | ||||
{ | { | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
bus_space_handle_t handle; | bus_space_handle_t handle; | ||||
bus_space_tag_t tag; | bus_space_tag_t tag; | ||||
struct ofw_pci_range *rp; | struct ofw_pci_range *rp; | ||||
vm_paddr_t start; | vm_paddr_t start; | ||||
int space; | int space; | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | ofw_pcib_activate_resource(device_t bus, device_t child, int type, int rid, | ||||
rman_set_bushandle(res, handle); | rman_set_bushandle(res, handle); | ||||
rman_set_virtual(res, (void *)handle); /* XXX for powerpc only ? */ | rman_set_virtual(res, (void *)handle); /* XXX for powerpc only ? */ | ||||
return (rman_activate_resource(res)); | return (rman_activate_resource(res)); | ||||
} | } | ||||
#ifdef __powerpc__ | #ifdef __powerpc__ | ||||
static bus_space_tag_t | static bus_space_tag_t | ||||
ofw_pci_bus_get_bus_tag(device_t bus, device_t child) | ofw_pcib_bus_get_bus_tag(device_t bus, device_t child) | ||||
{ | { | ||||
return (&bs_le_tag); | return (&bs_le_tag); | ||||
} | } | ||||
#endif | #endif | ||||
static int | static int | ||||
ofw_pci_deactivate_resource(device_t bus, device_t child, int type, int rid, | ofw_pcib_deactivate_resource(device_t bus, device_t child, int type, int rid, | ||||
struct resource *res) | struct resource *res) | ||||
{ | { | ||||
vm_size_t psize; | vm_size_t psize; | ||||
if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY) { | if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY) { | ||||
return (bus_generic_deactivate_resource(bus, child, type, rid, | return (bus_generic_deactivate_resource(bus, child, type, rid, | ||||
res)); | res)); | ||||
} | } | ||||
psize = rman_get_size(res); | psize = rman_get_size(res); | ||||
pmap_unmapdev((vm_offset_t)rman_get_virtual(res), psize); | pmap_unmapdev((vm_offset_t)rman_get_virtual(res), psize); | ||||
return (rman_deactivate_resource(res)); | return (rman_deactivate_resource(res)); | ||||
} | } | ||||
static int | static int | ||||
ofw_pci_adjust_resource(device_t bus, device_t child, int type, | ofw_pcib_adjust_resource(device_t bus, device_t child, int type, | ||||
struct resource *res, rman_res_t start, rman_res_t end) | struct resource *res, rman_res_t start, rman_res_t end) | ||||
{ | { | ||||
struct rman *rm; | struct rman *rm; | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
sc = device_get_softc(bus); | sc = device_get_softc(bus); | ||||
#if defined(NEW_PCIB) && defined(PCI_RES_BUS) | #if defined(NEW_PCIB) && defined(PCI_RES_BUS) | ||||
if (type == PCI_RES_BUS) | if (type == PCI_RES_BUS) | ||||
return (pci_domain_adjust_bus(sc->sc_pci_domain, child, res, | return (pci_domain_adjust_bus(sc->sc_pci_domain, child, res, | ||||
start, end)); | start, end)); | ||||
#endif | #endif | ||||
rm = ofw_pci_get_rman(sc, type, rman_get_flags(res)); | rm = ofw_pcib_get_rman(sc, type, rman_get_flags(res)); | ||||
if (rm == NULL) { | if (rm == NULL) { | ||||
return (bus_generic_adjust_resource(bus, child, type, res, | return (bus_generic_adjust_resource(bus, child, type, res, | ||||
start, end)); | start, end)); | ||||
} | } | ||||
KASSERT(rman_is_region_manager(res, rm), ("rman mismatch")); | KASSERT(rman_is_region_manager(res, rm), ("rman mismatch")); | ||||
KASSERT(!(rman_get_flags(res) & RF_ACTIVE), | KASSERT(!(rman_get_flags(res) & RF_ACTIVE), | ||||
("active resources cannot be adjusted")); | ("active resources cannot be adjusted")); | ||||
return (rman_adjust_resource(res, start, end)); | return (rman_adjust_resource(res, start, end)); | ||||
} | } | ||||
static phandle_t | static phandle_t | ||||
ofw_pci_get_node(device_t bus, device_t dev) | ofw_pcib_get_node(device_t bus, device_t dev) | ||||
{ | { | ||||
struct ofw_pci_softc *sc; | struct ofw_pci_softc *sc; | ||||
sc = device_get_softc(bus); | sc = device_get_softc(bus); | ||||
/* We only have one child, the PCI bus, which needs our own node. */ | /* We only have one child, the PCI bus, which needs our own node. */ | ||||
return (sc->sc_node); | return (sc->sc_node); | ||||
} | } | ||||
static int | static int | ||||
ofw_pci_fill_ranges(phandle_t node, struct ofw_pci_range *ranges) | ofw_pcib_fill_ranges(phandle_t node, struct ofw_pci_range *ranges) | ||||
{ | { | ||||
int host_address_cells = 1, pci_address_cells = 3, size_cells = 2; | int host_address_cells = 1, pci_address_cells = 3, size_cells = 2; | ||||
cell_t *base_ranges; | cell_t *base_ranges; | ||||
ssize_t nbase_ranges; | ssize_t nbase_ranges; | ||||
int nranges; | int nranges; | ||||
int i, j, k; | int i, j, k; | ||||
OF_getencprop(OF_parent(node), "#address-cells", &host_address_cells, | OF_getencprop(OF_parent(node), "#address-cells", &host_address_cells, | ||||
Show All 30 Lines | for (i = 0, j = 0; i < nranges; i++) { | ||||
} | } | ||||
} | } | ||||
free(base_ranges, M_DEVBUF); | free(base_ranges, M_DEVBUF); | ||||
return (nranges); | return (nranges); | ||||
} | } | ||||
static struct rman * | static struct rman * | ||||
ofw_pci_get_rman(struct ofw_pci_softc *sc, int type, u_int flags) | ofw_pcib_get_rman(struct ofw_pci_softc *sc, int type, u_int flags) | ||||
{ | { | ||||
switch (type) { | switch (type) { | ||||
case SYS_RES_IOPORT: | case SYS_RES_IOPORT: | ||||
return (&sc->sc_io_rman); | return (&sc->sc_io_rman); | ||||
case SYS_RES_MEMORY: | case SYS_RES_MEMORY: | ||||
if (sc->sc_have_pmem && (flags & RF_PREFETCHABLE)) | if (sc->sc_have_pmem && (flags & RF_PREFETCHABLE)) | ||||
return (&sc->sc_pmem_rman); | return (&sc->sc_pmem_rman); | ||||
else | else | ||||
return (&sc->sc_mem_rman); | return (&sc->sc_mem_rman); | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
return (NULL); | return (NULL); | ||||
} | } |