static void aps_identify(driver_t *driver, struct device *parent) { struct device *child; child = device_find_child(parent, driver->name, -1); if (child != NULL) { if (isa_get_portsize(child) == 0) { // aps(4) must have been compiled into the kernel if (bootverbose) kprintf("%s: will specify the port\n", __func__); } else if (isa_get_port(child) != APS_ADDR_BASE) kprintf("%s: will overwrite specified port\n", __func__); else { if (isa_get_portsize(child) == APS_ADDR_SIZE) { // aps.ko must have been reloaded kprintf("%s: already have been invoked\n", __func__); return; } else kprintf("%s: will amend the portsize\n", __func__); } } else { // first invocation of `kldload aps.ko` kprintf("%s: creating a new %s\n", __func__, driver->name); child = BUS_ADD_CHILD(parent, parent, ISA_ORDER_PNP, driver->name, -1); if (child == NULL) { kprintf("%s: cannot add child\n", __func__); return; } } if (bus_set_resource(child, SYS_RES_IOPORT, 0, APS_ADDR_BASE, APS_ADDR_SIZE, -1)) kprintf("%s: cannot set resource\n", __func__); }
static int snc_isa_probe(device_t dev) { struct snc_softc *sc = device_get_softc(dev); int type; int error = 0; bzero(sc, sizeof(struct snc_softc)); /* Check isapnp ids */ error = ISA_PNP_PROBE(device_get_parent(dev), dev, snc_ids); /* If the card had a PnP ID that didn't match any we know about */ if (error == ENXIO) { return(error); } switch (error) { case 0: /* Matched PnP */ type = SNEC_TYPE_PNP; break; case ENOENT: /* Legacy ISA */ type = SNEC_TYPE_LEGACY; break; default: /* If we had some other problem. */ return(error); } if (type == SNEC_TYPE_PNP && isa_get_portsize(dev) == 0) { int port; int rid = 0; struct resource *res = NULL; for (port = 0x0888; port <= 0x3888; port += 0x1000) { bus_set_resource(dev, SYS_RES_IOPORT, rid, port, SNEC_NREGS); res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0ul, ~0ul, SNEC_NREGS, 0 /* !RF_ACTIVE */); if (res) break; } printf("snc_isa_probe: broken PnP resource, "); if (res) { printf("use port 0x%x\n", port); bus_release_resource(dev, SYS_RES_IOPORT, rid, res); snc_isapnp_reconfig(dev); } else { printf("and can't find port\n"); } } error = snc_alloc_port(dev, 0); error = max(error, snc_alloc_memory(dev, 0)); error = max(error, snc_alloc_irq(dev, 0, 0)); if (!error && !snc_probe(dev, type)) error = ENOENT; snc_release_resources(dev); return (error); }