diff options
author | imp <imp@FreeBSD.org> | 1999-10-15 03:10:13 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 1999-10-15 03:10:13 +0000 |
commit | 1be659671f9c8884733a59d933c65a1e4ad4b29d (patch) | |
tree | e8da801b86cd79e501dbbf9ff54aaa7576043a4e /sys | |
parent | 994d54d44fa7693d2e1e586c69bce38c9d8f9f42 (diff) | |
download | FreeBSD-src-1be659671f9c8884733a59d933c65a1e4ad4b29d.zip FreeBSD-src-1be659671f9c8884733a59d933c65a1e4ad4b29d.tar.gz |
Make it easier to have completely new bus attachment points for pccard
devices. There may still be problems with said drivers, if so please
let me know.
o Move attach-like functionality to the nbk attach compatibility code.
o Smarter probe code: for the compatibility code probe succeeds if
strcmp succeeds, for noncompatibility you can do anything you like.
o Get rid of some compiler warnings introduced in last commit.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/pccard/pccard.c | 35 | ||||
-rw-r--r-- | sys/pccard/pccard_nbk.c | 64 | ||||
-rw-r--r-- | sys/pccard/pccard_nbk.h | 3 |
3 files changed, 70 insertions, 32 deletions
diff --git a/sys/pccard/pccard.c b/sys/pccard/pccard.c index 5eac5ab..e3ad114 100644 --- a/sys/pccard/pccard.c +++ b/sys/pccard/pccard.c @@ -99,7 +99,6 @@ static void unregister_device_interrupt(struct pccard_devinfo *); static void disable_slot(struct slot *); static int invalid_io_memory(unsigned long, int); static struct pccard_device *find_driver(char *); -static void remove_device(struct pccard_devinfo *); static ointhand2_t slot_irq_handler; static void power_off_slot(void *); @@ -240,7 +239,7 @@ pccard_remove_driver(struct pccard_device *drv) for (devi = slt->devices; devi; devi = next) { next = devi->next; if (devi->drv == drv) - remove_device(devi); + pccard_remove_device(devi); } /* * Once all the devices belonging to this driver have been @@ -285,7 +284,7 @@ pccard_remove_controller(struct slot_ctrl *ctrl) * Unload the drivers attached to this slot. */ while ((devi = slt->devices) != NULL) - remove_device(devi); + pccard_remove_device(devi); /* * Disable the slot and unlink the slot from the * slot list. @@ -593,7 +592,7 @@ allocate_driver(struct slot *slt, struct dev_desc *desc) devi->drv->name, desc->unit); return(EBUSY); } - remove_device(devi); + pccard_remove_device(devi); break; } } @@ -674,32 +673,12 @@ allocate_driver(struct slot *slt, struct dev_desc *desc) free(devi, M_DEVBUF); return(err); } - snprintf(devnam, sizeof(devnam), "compat %s", desc->name); - device_set_desc(devi->isahd.id_device, devnam); - BUS_PRINT_CHILD(pccarddev, devi->isahd.id_device); - - devi->next = slt->devices; - slt->devices = devi; - s = splhigh(); - err = drv->enable(devi); - splx(s); - /* - * If the enable functions returns no error, then the - * device has been successfully installed. If so, then - * attach it to the slot, otherwise free it and return - * the error. We assume that when we free the device, - * it will also set 'running' to off. - */ - if (err) { - printf("pccard: %s%d Enable failed %d\n", devi->drv->name, - devi->isahd.id_unit, err); - remove_device(devi); - } - return(err); + err = device_probe_and_attach(devi->isahd.id_device); + return err; } -static void -remove_device(struct pccard_devinfo *devi) +void +pccard_remove_device(struct pccard_devinfo *devi) { struct slot *slt = devi->slt; struct pccard_devinfo *list; diff --git a/sys/pccard/pccard_nbk.c b/sys/pccard/pccard_nbk.c index d7bb317..6c0853a 100644 --- a/sys/pccard/pccard_nbk.c +++ b/sys/pccard/pccard_nbk.c @@ -120,10 +120,22 @@ pccard_print_child(device_t dev, device_t child) return (retval); } +/* + * Create "connection point" + */ +static void +pccard_identify(driver_t *driver, device_t parent) +{ + device_t child; + child = BUS_ADD_CHILD(parent, 0, "pccard", 0); + if (child == NULL) + panic("pccard_identify"); +} static device_method_t pccard_methods[] = { /* Device interface */ + DEVMETHOD(device_identify, pccard_identify), DEVMETHOD(device_probe, pccard_probe), DEVMETHOD(device_attach, bus_generic_attach), DEVMETHOD(device_shutdown, bus_generic_shutdown), @@ -155,14 +167,56 @@ DRIVER_MODULE(pccard, nexus, pccard_driver, pccard_devclass, 0, 0); /* ============================================================ */ -static devclass_t pccnbk_devclass; - static int pccnbk_probe(device_t dev) { + char devnam[128]; + const char *name; + struct pccard_devinfo *devi = device_get_ivars(dev); + + if (devi) { + name = device_get_name(dev); + snprintf(devnam, sizeof(devnam), "pccard-%s", + devi->drv->name); + if (!name || strcmp(name, devnam) != 0) + return ENXIO; + device_set_desc(dev, devi->drv->name); + return 0; + } return ENXIO; } +static int +pccnbk_attach(device_t dev) +{ + struct pccard_devinfo *devi = device_get_ivars(dev); + struct pccard_device *drv; + struct slot *slt; + int err; + int s; + + slt = devi->slt; + drv = devi->drv; + devi->next = slt->devices; + slt->devices = devi; + s = splhigh(); + err = drv->enable(devi); + splx(s); + /* + * If the enable functions returns no error, then the + * device has been successfully installed. If so, then + * attach it to the slot, otherwise free it and return + * the error. We assume that when we free the device, + * it will also set 'running' to off. + */ + if (err) { + printf("pccard: %s%d Enable failed %d\n", devi->drv->name, + devi->isahd.id_unit, err); + pccard_remove_device(devi); + } + return(err); +} + /* * Allocate resources for this device in the rman system. */ @@ -224,7 +278,7 @@ pccnbk_release_resources(device_t dev) static device_method_t pccnbk_methods[] = { /* Device interface */ DEVMETHOD(device_probe, pccnbk_probe), - DEVMETHOD(device_attach, bus_generic_attach), + DEVMETHOD(device_attach, pccnbk_attach), DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD(device_suspend, bus_generic_suspend), DEVMETHOD(device_resume, bus_generic_resume), @@ -254,7 +308,7 @@ pccnbk_wrap_old_driver(struct pccard_device *drv) if (!driver) return; bzero(driver, sizeof(driver_t)); - /* XXX May create a memory leak :-( XXX */ + /* XXX May create a memory leak for load/unload :-( XXX */ nm = malloc(strlen(devnam) + 1, M_DEVBUF, M_NOWAIT); strcpy(nm, devnam); driver->name = nm; @@ -266,6 +320,8 @@ pccnbk_wrap_old_driver(struct pccard_device *drv) } #if 0 +static devclass_t pccnbk_devclass; + static driver_t pccnbk_driver = { "pccnbk", pccnbk_methods, diff --git a/sys/pccard/pccard_nbk.h b/sys/pccard/pccard_nbk.h index ef6397e..971191e 100644 --- a/sys/pccard/pccard_nbk.h +++ b/sys/pccard/pccard_nbk.h @@ -35,4 +35,7 @@ extern int pccnbk_alloc_resources(device_t); extern void pccnbk_release_resources(device_t); extern void pccnbk_wrap_old_driver(struct pccard_device *); +/* kludges */ +extern void pccard_remove_device(struct pccard_devinfo *); + #endif /* ! PCCARD_PCCARD_NBK_H */ |