mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-17 10:26:15 +00:00
Cleanup the recent cardbus cleanups. This fixes some of the panics
that I introduced with -v. However, other problems still remain (including the loss of interrupts).
This commit is contained in:
parent
2cadc0a98e
commit
86d1f89423
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=92207
@ -159,6 +159,7 @@ cardbus_attach_card(device_t cbdev)
|
||||
int bus, slot, func;
|
||||
struct cardbus_devinfo *dinfo;
|
||||
int cardbusfunchigh = 0;
|
||||
device_t kid;
|
||||
|
||||
cardbus_detach_card(cbdev, 0); /* detach existing cards */
|
||||
|
||||
@ -181,25 +182,25 @@ cardbus_attach_card(device_t cbdev)
|
||||
cardbusfunchigh = 0;
|
||||
for (func = 0; func <= cardbusfunchigh; func++) {
|
||||
dinfo = (struct cardbus_devinfo *)
|
||||
pci_read_device(brdev, bus, slot, func);
|
||||
|
||||
pci_read_device(brdev, bus, slot, func,
|
||||
sizeof(struct cardbus_devinfo));
|
||||
if (dinfo == NULL)
|
||||
continue;
|
||||
if (dinfo->pci.cfg.mfdev)
|
||||
cardbusfunchigh = CARDBUS_FUNCMAX;
|
||||
device_setup_regs(brdev, bus, slot, func,
|
||||
&dinfo->pci.cfg);
|
||||
pci_print_verbose(&dinfo->pci);
|
||||
dinfo->pci.cfg.dev = device_add_child(cbdev, NULL, -1);
|
||||
if (!dinfo->pci.cfg.dev) {
|
||||
kid = device_add_child(cbdev, NULL, -1);
|
||||
if (kid == NULL) {
|
||||
DEVPRINTF((cbdev, "Cannot add child!\n"));
|
||||
pci_freecfg(&dinfo->pci);
|
||||
continue;
|
||||
}
|
||||
resource_list_init(&dinfo->pci.resources);
|
||||
device_set_ivars(dinfo->pci.cfg.dev, &dinfo->pci);
|
||||
cardbus_do_cis(cbdev, dinfo->pci.cfg.dev);
|
||||
if (device_probe_and_attach(dinfo->pci.cfg.dev) != 0) {
|
||||
dinfo->pci.cfg.dev = kid;
|
||||
device_set_ivars(kid, &dinfo->pci);
|
||||
cardbus_do_cis(cbdev, kid);
|
||||
pci_print_verbose(&dinfo->pci);
|
||||
if (device_probe_and_attach(kid) != 0) {
|
||||
/* when fail, release all resources */
|
||||
cardbus_release_all_resources(cbdev, dinfo);
|
||||
} else
|
||||
@ -245,12 +246,11 @@ cardbus_detach_card(device_t cbdev, int flags)
|
||||
} else {
|
||||
err++;
|
||||
}
|
||||
pci_freecfg(&dinfo->pci);
|
||||
} else {
|
||||
cardbus_release_all_resources(cbdev, dinfo);
|
||||
device_delete_child(cbdev, devlist[tmp]);
|
||||
pci_freecfg(&dinfo->pci);
|
||||
}
|
||||
pci_freecfg(&dinfo->pci);
|
||||
}
|
||||
if (err == 0)
|
||||
POWER_DISABLE_SOCKET(device_get_parent(cbdev), cbdev);
|
||||
@ -304,29 +304,6 @@ cardbus_driver_added(device_t cbdev, driver_t *driver)
|
||||
static void
|
||||
cardbus_release_all_resources(device_t cbdev, struct cardbus_devinfo *dinfo)
|
||||
{
|
||||
struct resource_list_entry *rle;
|
||||
|
||||
/* Free all allocated resources */
|
||||
SLIST_FOREACH(rle, &dinfo->pci.resources, link) {
|
||||
if (rle->res) {
|
||||
if (rle->res->r_dev != cbdev)
|
||||
device_printf(cbdev, "release_all_resource: "
|
||||
"Resource still owned by child, oops. "
|
||||
"(type=%d, rid=%d, addr=%lx)\n",
|
||||
rle->type, rle->rid,
|
||||
rman_get_start(rle->res));
|
||||
BUS_RELEASE_RESOURCE(device_get_parent(cbdev),
|
||||
rle->res->r_dev,
|
||||
rle->type, rle->rid,
|
||||
rle->res);
|
||||
rle->res = NULL;
|
||||
/*
|
||||
* zero out config so the card won't acknowledge
|
||||
* access to the space anymore
|
||||
*/
|
||||
pci_write_config(dinfo->pci.cfg.dev, rle->rid, 0, 4);
|
||||
}
|
||||
}
|
||||
resource_list_free(&dinfo->pci.resources);
|
||||
}
|
||||
|
||||
|
@ -595,23 +595,24 @@ cardbus_alloc_resources(device_t cbdev, device_t child)
|
||||
{
|
||||
struct cardbus_devinfo *dinfo = device_get_ivars(child);
|
||||
int count;
|
||||
struct resource_list *rl = &dinfo->pci.resources;
|
||||
struct resource_list_entry *rle;
|
||||
struct resource_list_entry **barlist;
|
||||
int tmp;
|
||||
u_int32_t mem_psize = 0, mem_nsize = 0, io_size = 0;
|
||||
struct resource *res;
|
||||
u_int32_t start,end;
|
||||
int rid, flags;
|
||||
u_int32_t start, end;
|
||||
int rid, flags, irq;
|
||||
|
||||
count = 0;
|
||||
SLIST_FOREACH(rle, &dinfo->pci.resources, link)
|
||||
SLIST_FOREACH(rle, rl, link)
|
||||
count++;
|
||||
if (count == 0)
|
||||
return (0);
|
||||
barlist = malloc(sizeof(struct resource_list_entry*) * count, M_DEVBUF,
|
||||
M_WAITOK);
|
||||
count = 0;
|
||||
SLIST_FOREACH(rle, &dinfo->pci.resources, link) {
|
||||
SLIST_FOREACH(rle, rl, link) {
|
||||
barlist[count] = rle;
|
||||
if (rle->type == SYS_RES_IOPORT) {
|
||||
io_size += rle->count;
|
||||
@ -840,10 +841,11 @@ cardbus_alloc_resources(device_t cbdev, device_t child)
|
||||
device_printf(cbdev, "Unable to allocate IRQ\n");
|
||||
return (ENOMEM);
|
||||
}
|
||||
resource_list_add(&dinfo->pci.resources, SYS_RES_IRQ, rid,
|
||||
rman_get_start(res), rman_get_end(res), 1);
|
||||
dinfo->pci.cfg.intline = rman_get_start(res);
|
||||
pci_write_config(child, PCIR_INTLINE, rman_get_start(res), 1);
|
||||
irq = rman_get_start(res);
|
||||
resource_list_add(rl, SYS_RES_IRQ, rid, irq, irq, 1);
|
||||
dinfo->pci.cfg.intline = irq;
|
||||
pci_write_config(child, PCIR_INTLINE, irq, 1);
|
||||
printf("Allocating IRQ %d\n", irq);
|
||||
bus_release_resource(cbdev, SYS_RES_IRQ, rid, res);
|
||||
|
||||
return (0);
|
||||
@ -857,15 +859,17 @@ static void
|
||||
cardbus_add_map(device_t cbdev, device_t child, int reg)
|
||||
{
|
||||
struct cardbus_devinfo *dinfo = device_get_ivars(child);
|
||||
struct resource_list_entry *rle;
|
||||
struct resource_list *rl = &dinfo->pci.resources;
|
||||
u_int32_t size;
|
||||
u_int32_t testval;
|
||||
int type;
|
||||
|
||||
SLIST_FOREACH(rle, &dinfo->pci.resources, link) {
|
||||
if (rle->rid == reg)
|
||||
return;
|
||||
}
|
||||
testval = pci_read_config(child, reg, 4);
|
||||
type = (testval & 1) ? SYS_RES_IOPORT : SYS_RES_MEMORY;
|
||||
if (resource_list_find(rl, type, reg) != NULL)
|
||||
return;
|
||||
|
||||
/* XXX Should just be able to use pci_add_map */
|
||||
|
||||
if (reg == CARDBUS_ROM_REG)
|
||||
testval = CARDBUS_ROM_ADDRMASK;
|
||||
@ -884,9 +888,9 @@ cardbus_add_map(device_t cbdev, device_t child, int reg)
|
||||
type = SYS_RES_IOPORT;
|
||||
|
||||
size = CARDBUS_MAPREG_MEM_SIZE(testval);
|
||||
device_printf(cbdev, "Resource not specified in CIS: id=%x, size=%x\n",
|
||||
reg, size);
|
||||
resource_list_add(&dinfo->pci.resources, type, reg, 0UL, ~0UL, size);
|
||||
device_printf(cbdev, "BAR not in CIS: type = %d, id=%x, size=%x\n",
|
||||
type, reg, size);
|
||||
resource_list_add(rl, type, reg, 0UL, ~0UL, size);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user