Date: Wed, 24 May 2000 18:31:09 -0600 From: Warner Losh <imp@village.org> To: new-bus@freebsd.org Subject: Identify routines Message-ID: <200005250031.SAA81399@harmony.village.org>
next in thread | raw e-mail | index | archive | help
OK. I'm pushing the envelope on isa drivers. I'm abusing the identify routine to go out and find boards. The following usually works, but sometimes fails. Is there a good way to activate the resources (or at least check to make sure that the resources are not used by someone else) in the identify routine? static void foo_identify(driver_t *driver, device_t parent) int i; u_long ports[] = { 0x100, 0x110, 0x120, 0x130, 0x140, 0x150, 0x160, 0x170, 0x180, 0x1a0, 0x1b0, 0x1c0, 0x300, 0x310 }; int nports = sizeof(ports) / sizeof(ports[0]); int rid; int ok; struct resource *res; u_long addr = 0; foo_softc sc; if (!devclass_get_device(devclass_find(DRIVERNAME), 0)) { /* * Find where config says this device is at */ for (i = 0; i < nports; i++) { rid = 0; res = bus_alloc_resource(parent, SYS_RES_IOPORT, &rid, ports[i], ports[i], PORTS_PER_BOARD, RF_ACTIVE); if (!res) continue; addr = rman_get_start(res); sc.bst = rman_get_bustag(res); sc.bsh = rman_get_bushandle(res); ok = foo_card_present(&sc); bus_release_resource(parent, SYS_RES_IOPORT, rid, res); if (!ok) continue; child = BUS_ADD_CHILD(parent, 0, DRIVERNAME, 0); if (child == NULL) panic("foo_identify"); bus_set_resource(child, SYS_RES_IOPORT, 0, addr, PORTS_PER_BOARD); } } } I've noticed that sometimes I've found that this works great. Other times I get strange panics after this function has been called and the alloc/release were done. If I replace it with something whose heart looks more like: sc.bst = I386_BUS_SPACE_IO; sc.bsh = ports[i]; ok = foo_card_present(&sc); if (!ok) continue child = BUS_ADD_CHILD(...) .../* same */ then I see no panics and everything is suddenly cool. My questions are: Is this a cool thing to do? If not, how do I do what I'm trying to do? I'd love for this hardware to be plug and play, but it was built in the late 1980s and the design hasn't changed much in all that time (I'm writing support for some legacy hardware, so changing it isn't an option). Comments? Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-new-bus" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200005250031.SAA81399>