diff options
author | imp <imp@FreeBSD.org> | 2002-11-02 23:00:28 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 2002-11-02 23:00:28 +0000 |
commit | fd4399a908b17ed3577975df34051640916d35f4 (patch) | |
tree | 046b8dea6a0aac813e511aa6c7d3ea6b37bb59d8 | |
parent | b3cfb0145e43e4745858853a8baa5616bc1eff3c (diff) | |
download | FreeBSD-src-fd4399a908b17ed3577975df34051640916d35f4.zip FreeBSD-src-fd4399a908b17ed3577975df34051640916d35f4.tar.gz |
MFp4:
o Always release the resources on device detach.
o Attach resources the same with driver added as we do we do in the insert
case (maybe this should be a routine).
o signal the wakeup of the thread on resume instead of trying to force an
interrupt.
o Minor debug hacks.
o use 0xffffffff instead of -1 for uint32_t items.
o Don't complain when we're asked to detach no cards. This is normal.
o Eliminate the now worthless second parameter to card_detach_card.
o minor style(9)isms
Some of these patches may be from: iwasaki-san, jhb, iadowse
-rw-r--r-- | sys/dev/cardbus/cardbus.c | 61 | ||||
-rw-r--r-- | sys/dev/pccard/card_if.m | 5 | ||||
-rw-r--r-- | sys/dev/pccard/pccard.c | 8 | ||||
-rw-r--r-- | sys/dev/pccbb/pccbb.c | 13 |
4 files changed, 38 insertions, 49 deletions
diff --git a/sys/dev/cardbus/cardbus.c b/sys/dev/cardbus/cardbus.c index 3e5580b..7c227af 100644 --- a/sys/dev/cardbus/cardbus.c +++ b/sys/dev/cardbus/cardbus.c @@ -95,7 +95,7 @@ static void cardbus_delete_resource(device_t cbdev, device_t child, static void cardbus_delete_resource_method(device_t cbdev, device_t child, int type, int rid); static int cardbus_detach(device_t cbdev); -static int cardbus_detach_card(device_t cbdev, int flags); +static int cardbus_detach_card(device_t cbdev); static void cardbus_device_setup_regs(device_t brdev, int b, int s, int f, pcicfgregs *cfg); static void cardbus_disable_busmaster_method(device_t cbdev, device_t child); @@ -168,14 +168,14 @@ cardbus_attach(device_t cbdev) static int cardbus_detach(device_t cbdev) { - cardbus_detach_card(cbdev, DETACH_FORCE); + cardbus_detach_card(cbdev); return 0; } static int cardbus_suspend(device_t self) { - cardbus_detach_card(self, DETACH_FORCE); + cardbus_detach_card(self); return (0); } @@ -209,8 +209,6 @@ cardbus_device_setup_regs(device_t brdev, int b, int s, int f, pcicfgregs *cfg) cfg->maxlat = PCIB_READ_CONFIG(brdev, b, s, f, PCIR_MAXLAT, 1); } -#define DETACH_NOWARN 0x800 - static int cardbus_attach_card(device_t cbdev) { @@ -219,7 +217,7 @@ cardbus_attach_card(device_t cbdev) static int curr_bus_number = 2; /* XXX EVILE BAD (see below) */ int bus, slot, func; - cardbus_detach_card(cbdev, DETACH_NOWARN); /* detach existing cards */ + cardbus_detach_card(cbdev); /* detach existing cards */ POWER_ENABLE_SOCKET(brdev, cbdev); bus = pcib_get_bus(cbdev); @@ -246,6 +244,7 @@ cardbus_attach_card(device_t cbdev) continue; if (dinfo->pci.cfg.mfdev) cardbusfunchigh = CARDBUS_FUNCMAX; + cardbus_device_setup_regs(brdev, bus, slot, func, &dinfo->pci.cfg); cardbus_print_verbose(dinfo); @@ -258,22 +257,21 @@ cardbus_attach_card(device_t cbdev) resource_list_init(&dinfo->pci.resources); device_set_ivars(dinfo->pci.cfg.dev, dinfo); cardbus_do_cis(cbdev, dinfo->pci.cfg.dev); - if (device_probe_and_attach(dinfo->pci.cfg.dev) != 0) { - /* when fail, release all resources */ + if (device_probe_and_attach(dinfo->pci.cfg.dev) != 0) cardbus_release_all_resources(cbdev, dinfo); - } else + else cardattached++; } } if (cardattached > 0) - return 0; + return (0); POWER_DISABLE_SOCKET(brdev, cbdev); - return ENOENT; + return (ENOENT); } static int -cardbus_detach_card(device_t cbdev, int flags) +cardbus_detach_card(device_t cbdev) { int numdevs; device_t *devlist; @@ -283,12 +281,8 @@ cardbus_detach_card(device_t cbdev, int flags) device_get_children(cbdev, &devlist, &numdevs); if (numdevs == 0) { - if (!(flags & DETACH_NOWARN)) { - DEVPRINTF((cbdev, "detach_card: no card to detach!\n")); - POWER_DISABLE_SOCKET(device_get_parent(cbdev), cbdev); - } free(devlist, M_TEMP); - return ENOENT; + return (ENOENT); } for (tmp = 0; tmp < numdevs; tmp++) { @@ -296,13 +290,9 @@ cardbus_detach_card(device_t cbdev, int flags) int status = device_get_state(devlist[tmp]); if (status == DS_ATTACHED || status == DS_BUSY) { - if (device_detach(dinfo->pci.cfg.dev) == 0 || - flags & DETACH_FORCE) { - cardbus_release_all_resources(cbdev, dinfo); - device_delete_child(cbdev, devlist[tmp]); - } else { - err++; - } + device_detach(dinfo->pci.cfg.dev); + cardbus_release_all_resources(cbdev, dinfo); + device_delete_child(cbdev, devlist[tmp]); cardbus_freecfg(dinfo); } else { cardbus_release_all_resources(cbdev, dinfo); @@ -310,28 +300,31 @@ cardbus_detach_card(device_t cbdev, int flags) cardbus_freecfg(dinfo); } } - if (err == 0) - POWER_DISABLE_SOCKET(device_get_parent(cbdev), cbdev); + POWER_DISABLE_SOCKET(device_get_parent(cbdev), cbdev); free(devlist, M_TEMP); - return err; + return (err); } static void cardbus_driver_added(device_t cbdev, driver_t *driver) { - /* XXX check if 16-bit or cardbus! */ int numdevs; device_t *devlist; int tmp; + struct cardbus_devinfo *dinfo; device_get_children(cbdev, &devlist, &numdevs); DEVICE_IDENTIFY(driver, cbdev); + POWER_ENABLE_SOCKET(device_get_parent(cbdev), cbdev); for (tmp = 0; tmp < numdevs; tmp++) { if (device_get_state(devlist[tmp]) == DS_NOTPRESENT) { - struct cardbus_devinfo *dinfo; dinfo = device_get_ivars(devlist[tmp]); - cardbus_release_all_resources(cbdev, dinfo); +#ifdef notyet + cardbus_device_setup_regs(brdev, bus, slot, func, + &dinfo->pci.cfg); +#endif + cardbus_print_verbose(dinfo); resource_list_init(&dinfo->pci.resources); cardbus_do_cis(cbdev, dinfo->pci.cfg.dev); if (device_probe_and_attach(dinfo->pci.cfg.dev) != 0) { @@ -432,7 +425,7 @@ cardbus_read_device(device_t brdev, int b, int s, int f) pcicfgregs *cfg = NULL; struct cardbus_devinfo *devlist_entry = NULL; - if (REG(PCIR_DEVVENDOR, 4) != -1) { + if (REG(PCIR_DEVVENDOR, 4) != 0xffffffff) { devlist_entry = malloc(sizeof(struct cardbus_devinfo), M_DEVBUF, M_WAITOK | M_ZERO); if (devlist_entry == NULL) @@ -500,9 +493,7 @@ cardbus_freecfg(struct cardbus_devinfo *dinfo) static void cardbus_print_verbose(struct cardbus_devinfo *dinfo) { -#ifndef CARDBUS_DEBUG - if (bootverbose) -#endif /* CARDBUS_DEBUG */ + if (bootverbose || cardbus_debug > 0) { pcicfgregs *cfg = &dinfo->pci.cfg; @@ -511,7 +502,6 @@ cardbus_print_verbose(struct cardbus_devinfo *dinfo) printf("\tclass=%02x-%02x-%02x, hdrtype=0x%02x, mfdev=%d\n", cfg->baseclass, cfg->subclass, cfg->progif, cfg->hdrtype, cfg->mfdev); -#ifdef CARDBUS_DEBUG printf("\tcmdreg=0x%04x, statreg=0x%04x, " "cachelnsz=%d (dwords)\n", cfg->cmdreg, cfg->statreg, cfg->cachelnsz); @@ -520,7 +510,6 @@ cardbus_print_verbose(struct cardbus_devinfo *dinfo) cfg->lattimer, cfg->lattimer * 30, cfg->mingnt, cfg->mingnt * 250, cfg->maxlat, cfg->maxlat * 250); -#endif /* CARDBUS_DEBUG */ if (cfg->intpin > 0) printf("\tintpin=%c, irq=%d\n", cfg->intpin + 'a' - 1, cfg->intline); diff --git a/sys/dev/pccard/card_if.m b/sys/dev/pccard/card_if.m index 176249f..f246751 100644 --- a/sys/dev/pccard/card_if.m +++ b/sys/dev/pccard/card_if.m @@ -90,11 +90,6 @@ METHOD int attach_card { # METHOD int detach_card { device_t dev; - int flags; -} - -HEADER { - #define DETACH_FORCE 0x01 } # diff --git a/sys/dev/pccard/pccard.c b/sys/dev/pccard/pccard.c index e874774..338c039 100644 --- a/sys/dev/pccard/pccard.c +++ b/sys/dev/pccard/pccard.c @@ -83,7 +83,7 @@ SYSCTL_INT(_hw_pccard, OID_AUTO, cis_debug, CTLFLAG_RW, static int pccard_ccr_read(struct pccard_function *pf, int ccr); static void pccard_ccr_write(struct pccard_function *pf, int ccr, int val); static int pccard_attach_card(device_t dev); -static int pccard_detach_card(device_t dev, int flags); +static int pccard_detach_card(device_t dev); static int pccard_card_gettype(device_t dev, int *type); static void pccard_function_init(struct pccard_function *pf); static void pccard_function_free(struct pccard_function *pf); @@ -259,7 +259,7 @@ pccard_attach_card(device_t dev) } static int -pccard_detach_card(device_t dev, int flags) +pccard_detach_card(device_t dev) { struct pccard_softc *sc = PCCARD_SOFTC(dev); struct pccard_function *pf; @@ -776,14 +776,14 @@ pccard_attach(device_t dev) static int pccard_detach(device_t dev) { - pccard_detach_card(dev, 0); + pccard_detach_card(dev); return 0; } static int pccard_suspend(device_t self) { - pccard_detach_card(self, 0); + pccard_detach_card(self); return (0); } diff --git a/sys/dev/pccbb/pccbb.c b/sys/dev/pccbb/pccbb.c index bef8215..461c39d 100644 --- a/sys/dev/pccbb/pccbb.c +++ b/sys/dev/pccbb/pccbb.c @@ -843,11 +843,13 @@ cbb_driver_added(device_t brdev, driver_t *driver) if (devlist[tmp] == NULL) /* NOTHING */; else if (strcmp(driver->name, "cardbus") == 0) { + printf("Adding cardbus\n"); sc->cbdev = devlist[tmp]; if (((sockstate & CBB_SOCKET_STAT_CD) == 0) && (sockstate & CBB_SOCKET_STAT_CB)) wake++; } else if (strcmp(driver->name, "pccard") == 0) { + printf("Adding pccard\n"); sc->pccarddev = devlist[tmp]; if (((sockstate & CBB_SOCKET_STAT_CD) == 0) && (sockstate & CBB_SOCKET_STAT_16BIT)) @@ -991,9 +993,9 @@ static void cbb_removal(struct cbb_softc *sc) { if (sc->flags & CBB_16BIT_CARD && sc->pccarddev != NULL) - CARD_DETACH_CARD(sc->pccarddev, DETACH_FORCE); + CARD_DETACH_CARD(sc->cbdev); else if ((!(sc->flags & CBB_16BIT_CARD)) && sc->cbdev != NULL) - CARD_DETACH_CARD(sc->cbdev, DETACH_FORCE); + CARD_DETACH_CARD(sc->cbdev); cbb_destroy_res(sc); } @@ -1872,6 +1874,7 @@ cbb_suspend(device_t self) cbb_setb(sc, CBB_SOCKET_MASK, 0); /* Quiet hardware */ bus_teardown_intr(self, sc->irq_res, sc->intrhand); + sc->flags &= ~CBB_CARD_OK; /* Card is bogus now */ error = bus_generic_suspend(self); return (error); } @@ -1917,8 +1920,10 @@ cbb_resume(device_t self) /* CSC Interrupt: Card detect interrupt on */ cbb_setb(sc, CBB_SOCKET_MASK, CBB_SOCKET_MASK_CD); - /* Force us to go query the socket state */ - cbb_setb(sc, CBB_SOCKET_FORCE, CBB_SOCKET_EVENT_CD); + /* Signal the thread to wakeup. */ + mtx_lock(&sc->mtx); + cv_signal(&sc->cv); + mtx_unlock(&sc->mtx); error = bus_generic_resume(self); |