Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/pccbb/pccbb_pci.c
Show First 20 Lines • Show All 273 Lines • ▼ Show 20 Lines | for (i = 0; i < 256; i += 4) { | ||||
printf("0x%08x ", pci_read_config(dev, i, 4)); | printf("0x%08x ", pci_read_config(dev, i, 4)); | ||||
} | } | ||||
printf("\n"); | printf("\n"); | ||||
} | } | ||||
static int | static int | ||||
cbb_pci_attach(device_t brdev) | cbb_pci_attach(device_t brdev) | ||||
{ | { | ||||
#if !defined(PCI_RES_BUS) | |||||
static int curr_bus_number = 2; /* XXX EVILE BAD (see below) */ | |||||
uint32_t pribus; | |||||
#endif | |||||
struct cbb_softc *sc = (struct cbb_softc *)device_get_softc(brdev); | struct cbb_softc *sc = (struct cbb_softc *)device_get_softc(brdev); | ||||
struct sysctl_ctx_list *sctx; | struct sysctl_ctx_list *sctx; | ||||
struct sysctl_oid *soid; | struct sysctl_oid *soid; | ||||
int rid; | int rid; | ||||
device_t parent; | device_t parent; | ||||
parent = device_get_parent(brdev); | parent = device_get_parent(brdev); | ||||
mtx_init(&sc->mtx, device_get_nameunit(brdev), "cbb", MTX_DEF); | mtx_init(&sc->mtx, device_get_nameunit(brdev), "cbb", MTX_DEF); | ||||
sc->chipset = cbb_chipset(pci_get_devid(brdev), NULL); | sc->chipset = cbb_chipset(pci_get_devid(brdev), NULL); | ||||
sc->dev = brdev; | sc->dev = brdev; | ||||
sc->cbdev = NULL; | sc->cbdev = NULL; | ||||
sc->domain = pci_get_domain(brdev); | sc->domain = pci_get_domain(brdev); | ||||
sc->pribus = pcib_get_bus(parent); | sc->pribus = pcib_get_bus(parent); | ||||
#if defined(PCI_RES_BUS) | |||||
pci_write_config(brdev, PCIR_PRIBUS_2, sc->pribus, 1); | pci_write_config(brdev, PCIR_PRIBUS_2, sc->pribus, 1); | ||||
pcib_setup_secbus(brdev, &sc->bus, 1); | pcib_setup_secbus(brdev, &sc->bus, 1); | ||||
#else | |||||
sc->bus.sec = pci_read_config(brdev, PCIR_SECBUS_2, 1); | |||||
sc->bus.sub = pci_read_config(brdev, PCIR_SUBBUS_2, 1); | |||||
imp: sc->bus can likely go away, no? | |||||
#endif | |||||
SLIST_INIT(&sc->rl); | SLIST_INIT(&sc->rl); | ||||
rid = CBBR_SOCKBASE; | rid = CBBR_SOCKBASE; | ||||
sc->base_res = bus_alloc_resource_any(brdev, SYS_RES_MEMORY, &rid, | sc->base_res = bus_alloc_resource_any(brdev, SYS_RES_MEMORY, &rid, | ||||
RF_ACTIVE); | RF_ACTIVE); | ||||
if (!sc->base_res) { | if (!sc->base_res) { | ||||
device_printf(brdev, "Could not map register memory\n"); | device_printf(brdev, "Could not map register memory\n"); | ||||
mtx_destroy(&sc->mtx); | mtx_destroy(&sc->mtx); | ||||
Show All 20 Lines | cbb_pci_attach(device_t brdev) | ||||
/*Sysctls*/ | /*Sysctls*/ | ||||
sctx = device_get_sysctl_ctx(brdev); | sctx = device_get_sysctl_ctx(brdev); | ||||
soid = device_get_sysctl_tree(brdev); | soid = device_get_sysctl_tree(brdev); | ||||
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "domain", | SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "domain", | ||||
CTLFLAG_RD, &sc->domain, 0, "Domain number"); | CTLFLAG_RD, &sc->domain, 0, "Domain number"); | ||||
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "pribus", | SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "pribus", | ||||
CTLFLAG_RD, &sc->pribus, 0, "Primary bus number"); | CTLFLAG_RD, &sc->pribus, 0, "Primary bus number"); | ||||
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "secbus", | SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "secbus", | ||||
CTLFLAG_RD, &sc->bus.sec, 0, "Secondary bus number"); | CTLFLAG_RD, &sc->bus.sec, 0, "Secondary bus number"); | ||||
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "subbus", | SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "subbus", | ||||
CTLFLAG_RD, &sc->bus.sub, 0, "Subordinate bus number"); | CTLFLAG_RD, &sc->bus.sub, 0, "Subordinate bus number"); | ||||
impUnsubmitted Not Done Inline ActionsThese likely can go away too.... They were part of the gross hack to allow people to set sec/sub bus numbers. This hack never worked very well... imp: These likely can go away too.... They were part of the gross hack to allow people to set… | |||||
#if 0 | #if 0 | ||||
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "memory", | SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "memory", | ||||
CTLFLAG_RD, &sc->subbus, 0, "Memory window open"); | CTLFLAG_RD, &sc->subbus, 0, "Memory window open"); | ||||
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "premem", | SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "premem", | ||||
CTLFLAG_RD, &sc->subbus, 0, "Prefetch memory window open"); | CTLFLAG_RD, &sc->subbus, 0, "Prefetch memory window open"); | ||||
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "io1", | SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "io1", | ||||
CTLFLAG_RD, &sc->subbus, 0, "io range 1 open"); | CTLFLAG_RD, &sc->subbus, 0, "io range 1 open"); | ||||
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "io2", | SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "io2", | ||||
CTLFLAG_RD, &sc->subbus, 0, "io range 2 open"); | CTLFLAG_RD, &sc->subbus, 0, "io range 2 open"); | ||||
#endif | #endif | ||||
impUnsubmitted Not Done Inline ActionsThis entire #if 0 likely can go... I never needed to finish stubbing it out... imp: This entire #if 0 likely can go... I never needed to finish stubbing it out...
| |||||
#if !defined(PCI_RES_BUS) | |||||
/* | |||||
* This is a gross hack. We should be scanning the entire pci | |||||
* tree, assigning bus numbers in a way such that we (1) can | |||||
* reserve 1 extra bus just in case and (2) all sub buses | |||||
* are in an appropriate range. | |||||
*/ | |||||
DEVPRINTF((brdev, "Secondary bus is %d\n", sc->bus.sec)); | |||||
pribus = pci_read_config(brdev, PCIR_PRIBUS_2, 1); | |||||
if (sc->bus.sec == 0 || sc->pribus != pribus) { | |||||
if (curr_bus_number <= sc->pribus) | |||||
curr_bus_number = sc->pribus + 1; | |||||
if (pribus != sc->pribus) { | |||||
DEVPRINTF((brdev, "Setting primary bus to %d\n", | |||||
sc->pribus)); | |||||
pci_write_config(brdev, PCIR_PRIBUS_2, sc->pribus, 1); | |||||
} | |||||
sc->bus.sec = curr_bus_number++; | |||||
sc->bus.sub = curr_bus_number++; | |||||
DEVPRINTF((brdev, "Secondary bus set to %d subbus %d\n", | |||||
sc->bus.sec, sc->bus.sub)); | |||||
pci_write_config(brdev, PCIR_SECBUS_2, sc->bus.sec, 1); | |||||
pci_write_config(brdev, PCIR_SUBBUS_2, sc->bus.sub, 1); | |||||
} | |||||
#endif | |||||
/* Map and establish the interrupt. */ | /* Map and establish the interrupt. */ | ||||
rid = 0; | rid = 0; | ||||
sc->irq_res = bus_alloc_resource_any(brdev, SYS_RES_IRQ, &rid, | sc->irq_res = bus_alloc_resource_any(brdev, SYS_RES_IRQ, &rid, | ||||
RF_SHAREABLE | RF_ACTIVE); | RF_SHAREABLE | RF_ACTIVE); | ||||
if (sc->irq_res == NULL) { | if (sc->irq_res == NULL) { | ||||
device_printf(brdev, "Unable to map IRQ...\n"); | device_printf(brdev, "Unable to map IRQ...\n"); | ||||
goto err; | goto err; | ||||
} | } | ||||
Show All 36 Lines | err: | ||||
} | } | ||||
mtx_destroy(&sc->mtx); | mtx_destroy(&sc->mtx); | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
static int | static int | ||||
cbb_pci_detach(device_t brdev) | cbb_pci_detach(device_t brdev) | ||||
{ | { | ||||
#if defined(PCI_RES_BUS) | |||||
struct cbb_softc *sc = device_get_softc(brdev); | struct cbb_softc *sc = device_get_softc(brdev); | ||||
#endif | |||||
int error; | int error; | ||||
error = cbb_detach(brdev); | error = cbb_detach(brdev); | ||||
#if defined(PCI_RES_BUS) | |||||
if (error == 0) | if (error == 0) | ||||
pcib_free_secbus(brdev, &sc->bus); | pcib_free_secbus(brdev, &sc->bus); | ||||
#endif | |||||
return (error); | return (error); | ||||
} | } | ||||
static void | static void | ||||
cbb_chipinit(struct cbb_softc *sc) | cbb_chipinit(struct cbb_softc *sc) | ||||
{ | { | ||||
uint32_t mux, sysctrl, reg; | uint32_t mux, sysctrl, reg; | ||||
▲ Show 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | #undef DELTA | ||||
*/ | */ | ||||
if (sockevent & CBB_SOCKET_EVENT_CSTS) | if (sockevent & CBB_SOCKET_EVENT_CSTS) | ||||
cbb_set(sc, CBB_SOCKET_EVENT, CBB_SOCKET_EVENT_CSTS); | cbb_set(sc, CBB_SOCKET_EVENT, CBB_SOCKET_EVENT_CSTS); | ||||
retval = FILTER_HANDLED; | retval = FILTER_HANDLED; | ||||
} | } | ||||
return retval; | return retval; | ||||
} | } | ||||
#if defined(PCI_RES_BUS) | |||||
static struct resource * | static struct resource * | ||||
cbb_pci_alloc_resource(device_t bus, device_t child, int type, int *rid, | cbb_pci_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 cbb_softc *sc; | struct cbb_softc *sc; | ||||
sc = device_get_softc(bus); | sc = device_get_softc(bus); | ||||
if (type == PCI_RES_BUS) | if (type == PCI_RES_BUS) | ||||
Show All 33 Lines | if (rman_get_flags(r) & RF_ACTIVE) { | ||||
error = bus_deactivate_resource(child, type, rid, r); | error = bus_deactivate_resource(child, type, rid, r); | ||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
} | } | ||||
return (rman_release_resource(r)); | return (rman_release_resource(r)); | ||||
} | } | ||||
return (cbb_release_resource(bus, child, type, rid, r)); | return (cbb_release_resource(bus, child, type, rid, r)); | ||||
} | } | ||||
#endif | |||||
/************************************************************************/ | /************************************************************************/ | ||||
/* PCI compat methods */ | /* PCI compat methods */ | ||||
/************************************************************************/ | /************************************************************************/ | ||||
static int | static int | ||||
cbb_maxslots(device_t brdev) | cbb_maxslots(device_t brdev) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | static device_method_t cbb_methods[] = { | ||||
DEVMETHOD(device_detach, cbb_pci_detach), | DEVMETHOD(device_detach, cbb_pci_detach), | ||||
DEVMETHOD(device_shutdown, cbb_pci_shutdown), | DEVMETHOD(device_shutdown, cbb_pci_shutdown), | ||||
DEVMETHOD(device_suspend, cbb_pci_suspend), | DEVMETHOD(device_suspend, cbb_pci_suspend), | ||||
DEVMETHOD(device_resume, cbb_pci_resume), | DEVMETHOD(device_resume, cbb_pci_resume), | ||||
/* bus methods */ | /* bus methods */ | ||||
DEVMETHOD(bus_read_ivar, cbb_read_ivar), | DEVMETHOD(bus_read_ivar, cbb_read_ivar), | ||||
DEVMETHOD(bus_write_ivar, cbb_write_ivar), | DEVMETHOD(bus_write_ivar, cbb_write_ivar), | ||||
#if defined(PCI_RES_BUS) | |||||
DEVMETHOD(bus_alloc_resource, cbb_pci_alloc_resource), | DEVMETHOD(bus_alloc_resource, cbb_pci_alloc_resource), | ||||
DEVMETHOD(bus_adjust_resource, cbb_pci_adjust_resource), | DEVMETHOD(bus_adjust_resource, cbb_pci_adjust_resource), | ||||
DEVMETHOD(bus_release_resource, cbb_pci_release_resource), | DEVMETHOD(bus_release_resource, cbb_pci_release_resource), | ||||
#else | |||||
DEVMETHOD(bus_alloc_resource, cbb_alloc_resource), | |||||
DEVMETHOD(bus_release_resource, cbb_release_resource), | |||||
#endif | |||||
DEVMETHOD(bus_activate_resource, cbb_activate_resource), | DEVMETHOD(bus_activate_resource, cbb_activate_resource), | ||||
DEVMETHOD(bus_deactivate_resource, cbb_deactivate_resource), | DEVMETHOD(bus_deactivate_resource, cbb_deactivate_resource), | ||||
DEVMETHOD(bus_driver_added, cbb_driver_added), | DEVMETHOD(bus_driver_added, cbb_driver_added), | ||||
DEVMETHOD(bus_child_detached, cbb_child_detached), | DEVMETHOD(bus_child_detached, cbb_child_detached), | ||||
DEVMETHOD(bus_setup_intr, cbb_setup_intr), | DEVMETHOD(bus_setup_intr, cbb_setup_intr), | ||||
DEVMETHOD(bus_teardown_intr, cbb_teardown_intr), | DEVMETHOD(bus_teardown_intr, cbb_teardown_intr), | ||||
DEVMETHOD(bus_child_present, cbb_child_present), | DEVMETHOD(bus_child_present, cbb_child_present), | ||||
Show All 27 Lines |
sc->bus can likely go away, no?