From owner-freebsd-new-bus Wed May 24 17:32:22 2000 Delivered-To: freebsd-new-bus@freebsd.org Received: from rover.village.org (rover.village.org [204.144.255.49]) by hub.freebsd.org (Postfix) with ESMTP id C766D37B5B1 for ; Wed, 24 May 2000 17:32:18 -0700 (PDT) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (harmony.village.org [10.0.0.6]) by rover.village.org (8.9.3/8.9.3) with ESMTP id SAA16926 for ; Wed, 24 May 2000 18:32:17 -0600 (MDT) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (localhost.village.org [127.0.0.1]) by harmony.village.org (8.9.3/8.8.3) with ESMTP id SAA81399 for ; Wed, 24 May 2000 18:31:09 -0600 (MDT) Message-Id: <200005250031.SAA81399@harmony.village.org> To: new-bus@freebsd.org Subject: Identify routines Date: Wed, 24 May 2000 18:31:09 -0600 From: Warner Losh Sender: owner-freebsd-new-bus@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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