static int wds_probe(device_t dev) { struct wds *wp; int error = 0; int irq; /* No pnp support */ if (isa_get_vendorid(dev)) return (ENXIO); wp = (struct wds *) device_get_softc(dev); wp->unit = device_get_unit(dev); wp->dev = dev; wp->addr = bus_get_resource_start(dev, SYS_RES_IOPORT, 0 /*rid*/); if (wp->addr == 0 || wp->addr <0x300 || wp->addr > 0x3f8 || wp->addr & 0x7) { device_printf(dev, "invalid port address 0x%x\n", wp->addr); return (ENXIO); } if (bus_set_resource(dev, SYS_RES_IOPORT, 0, wp->addr, WDS_NPORTS) < 0) return (ENXIO); /* get the DRQ */ wp->drq = bus_get_resource_start(dev, SYS_RES_DRQ, 0 /*rid*/); if (wp->drq < 5 || wp->drq > 7) { device_printf(dev, "invalid DRQ %d\n", wp->drq); return (ENXIO); } /* get the IRQ */ irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0 /*rid*/); if (irq < 3) { device_printf(dev, "invalid IRQ %d\n", irq); return (ENXIO); } wp->port_rid = 0; wp->port_r = bus_alloc_resource(dev, SYS_RES_IOPORT, &wp->port_rid, /*start*/ 0, /*end*/ ~0, /*count*/ 0, RF_ACTIVE); if (wp->port_r == NULL) return (ENXIO); error = wds_preinit(wp); /* * We cannot hold resources between probe and * attach as we may never be attached. */ wds_free_resources(wp); return (error); }
static int uart_isa_probe(device_t dev) { struct uart_softc *sc; device_t parent; parent = device_get_parent(dev); sc = device_get_softc(dev); /* Check PnP IDs */ if (ISA_PNP_PROBE(parent, dev, isa_ns8250_ids) == ENXIO) return (ENXIO); /* Probe PnP _and_ non-PnP ns8250 here. */ #ifdef PC98 if (isa_get_logicalid(dev)) sc->sc_class = &uart_ns8250_class; else sc->sc_class = uart_pc98_getdev(bus_get_resource_start(dev, SYS_RES_IOPORT, 0)); #else sc->sc_class = &uart_ns8250_class; #endif return (uart_bus_probe(dev, 0, 0, 0, 0)); }
static int dpt_isa_probe (device_t dev) { dpt_conf_t * conf; u_int32_t io_base; /* No pnp support */ if (isa_get_vendorid(dev)) return (ENXIO); if ((io_base = bus_get_resource_start(dev, SYS_RES_IOPORT, 0)) == 0) return (ENXIO); if (dpt_isa_valid_ioport(io_base)) ; conf = dpt_pio_get_conf(io_base); if (!conf) { printf("dpt: dpt_pio_get_conf() failed.\n"); return (ENXIO); } if (dpt_isa_valid_irq(conf->IRQ)) ; device_set_desc(dev, "ISA DPT SCSI controller"); bus_set_resource(dev, SYS_RES_IRQ, 0, conf->IRQ, 1); bus_set_resource(dev, SYS_RES_DRQ, 0, ((8 - conf->DMA_channel) & 7), 1); return 0; }
static int scd_isa_probe (device_t dev) { struct scd_softc * sc; int error; /* No pnp support */ if (isa_get_vendorid(dev)) return (ENXIO); /* IO port must be configured. */ if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0) return (ENXIO); sc = device_get_softc(dev); sc->dev = dev; sc->port_rid = 0; sc->port_type = SYS_RES_IOPORT; error = scd_alloc_resources(dev); if (error) goto fail; error = scd_probe(sc); if (error) { device_printf(dev, "Probe failed.\n"); goto fail; } device_set_desc(dev, sc->data.name); fail: scd_release_resources(dev); return (error); }
static int atkbdattach(device_t dev) { atkbd_softc_t *sc; keyboard_t *kbd; u_long irq; int flags; int rid; int error; sc = device_get_softc(dev); rid = KBDC_RID_KBD; irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid); flags = device_get_flags(dev); error = atkbd_attach_unit(dev, &kbd, irq, flags); if (error) return error; /* declare our interrupt handler */ sc->intr = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); if (sc->intr == NULL) return ENXIO; error = bus_setup_intr(dev, sc->intr, INTR_TYPE_TTY, NULL, atkbdintr, kbd, &sc->ih); if (error) bus_release_resource(dev, SYS_RES_IRQ, rid, sc->intr); return error; }
static int nspattach(device_t devi) { struct nsp_softc *sc; struct scsi_low_softc *slp; u_int32_t flags = device_get_flags(devi); u_int iobase = bus_get_resource_start(devi, SYS_RES_IOPORT, 0); intrmask_t s; char dvname[16]; strcpy(dvname,"nsp"); if (iobase == 0) { printf("%s: no ioaddr is given\n", dvname); return (0); } sc = device_get_softc(devi); if (sc == NULL) return (0); slp = &sc->sc_sclow; slp->sl_dev = devi; sc->sc_iot = rman_get_bustag(sc->port_res); sc->sc_ioh = rman_get_bushandle(sc->port_res); if (sc->mem_res == NULL) { printf("WARNING: CANNOT GET Memory RESOURCE going PIO mode"); flags |= PIO_MODE; } if ((flags & PIO_MODE) == 0) { sc->sc_memt = rman_get_bustag(sc->mem_res); sc->sc_memh = rman_get_bushandle(sc->mem_res); } else { sc->sc_memh = 0; } /* slp->sl_irq = devi->pd_irq; */ sc->sc_iclkdiv = CLKDIVR_20M; sc->sc_clkdiv = CLKDIVR_40M; slp->sl_hostid = NSP_HOSTID; slp->sl_cfgflags = flags; s = splcam(); nspattachsubr(sc); splx(s); return(NSP_IOSIZE); }
static int ex_pccard_probe(device_t dev) { u_int iobase; u_int irq; iobase = bus_get_resource_start(dev, SYS_RES_IOPORT, 0); if (!iobase) { kprintf("ex: no iobase?\n"); return(ENXIO); } if (bootverbose) kprintf("ex: ex_pccard_probe() found card at 0x%03x\n", iobase); irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0); if (irq == 0) { kprintf("ex: invalid IRQ.\n"); return(ENXIO); } return(0); }
static device_t atkbdc_isa_add_child(device_t bus, int order, char *name, int unit) { atkbdc_device_t *ivar; device_t child; int t; ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV, M_NOWAIT | M_ZERO); if (!ivar) return NULL; child = device_add_child_ordered(bus, order, name, unit); if (child == NULL) { free(ivar, M_ATKBDDEV); return child; } resource_list_init(&ivar->resources); ivar->rid = order; /* * If the device is not created by the PnP BIOS or ACPI, * refer to device hints for IRQ. */ if (ISA_PNP_PROBE(device_get_parent(bus), bus, atkbdc_ids) != 0) { if (resource_int_value(name, unit, "irq", &t) != 0) t = -1; } else { t = bus_get_resource_start(bus, SYS_RES_IRQ, ivar->rid); } if (t > 0) resource_list_add(&ivar->resources, SYS_RES_IRQ, ivar->rid, t, t, 1); if (resource_disabled(name, unit)) device_disable(child); device_set_ivars(child, ivar); return child; }
static int thunder_pcie_identify_pcib(device_t dev) { struct thunder_pcie_softc *sc; rman_res_t start; sc = device_get_softc(dev); start = bus_get_resource_start(dev, SYS_RES_MEMORY, 0); switch(start) { case THUNDER_ECAM0_CFG_BASE: sc->ecam = 0; break; case THUNDER_ECAM1_CFG_BASE: sc->ecam = 1; break; case THUNDER_ECAM2_CFG_BASE: sc->ecam = 2; break; case THUNDER_ECAM3_CFG_BASE: sc->ecam = 3; break; case THUNDER_ECAM4_CFG_BASE: sc->ecam = 4; break; case THUNDER_ECAM5_CFG_BASE: sc->ecam = 5; break; case THUNDER_ECAM6_CFG_BASE: sc->ecam = 6; break; case THUNDER_ECAM7_CFG_BASE: sc->ecam = 7; break; default: device_printf(dev, "error: incorrect resource address=%#lx.\n", start); return (ENXIO); } return (0); }
static int create_a_copy(device_t atkbdc, device_t me) { device_t psm; u_long irq; /* find the PS/2 mouse device instance under the keyboard controller */ psm = device_find_child(atkbdc, PSM_DRIVER_NAME, device_get_unit(atkbdc)); if (psm == NULL) return ENXIO; if (device_get_state(psm) != DS_NOTPRESENT) return 0; /* move our resource to the found device */ irq = bus_get_resource_start(me, SYS_RES_IRQ, 0); bus_set_resource(psm, SYS_RES_IRQ, KBDC_RID_AUX, irq, 1); /* ...then probe and attach it */ return device_probe_and_attach(psm); }
int atkbdc_print_child(device_t bus, device_t dev) { atkbdc_device_t *kbdcdev; u_long irq; int flags; int retval = 0; kbdcdev = (atkbdc_device_t *)device_get_ivars(dev); retval += bus_print_child_header(bus, dev); flags = device_get_flags(dev); if (flags != 0) retval += printf(" flags 0x%x", flags); irq = bus_get_resource_start(dev, SYS_RES_IRQ, kbdcdev->rid); if (irq != 0) retval += printf(" irq %ld", irq); retval += bus_print_child_footer(bus, dev); return (retval); }
static int stgattach(device_t devi) { struct stg_softc *sc; struct scsi_low_softc *slp; u_int32_t flags = device_get_flags(devi); u_int iobase = bus_get_resource_start(devi, SYS_RES_IOPORT, 0); intrmask_t s; char dvname[16]; strcpy(dvname,"stg"); if (iobase == 0) { printf("%s: no ioaddr is given\n", dvname); return (0); } sc = device_get_softc(devi); if (sc == NULL) { return(0); } slp = &sc->sc_sclow; slp->sl_dev = devi; sc->sc_iot = rman_get_bustag(sc->port_res); sc->sc_ioh = rman_get_bushandle(sc->port_res); slp->sl_hostid = STG_HOSTID; slp->sl_cfgflags = flags; s = splcam(); stgattachsubr(sc); splx(s); return(STGIOSZ); }
static int psmcpnp_probe(device_t dev) { struct resource *res; u_long irq; int rid; if (ISA_PNP_PROBE(device_get_parent(dev), dev, psmcpnp_ids)) return ENXIO; /* * The PnP BIOS and ACPI are supposed to assign an IRQ (12) * to the PS/2 mouse device node. But, some buggy PnP BIOS * declares the PS/2 mouse device node without an IRQ resource! * If this happens, we shall refer to device hints. * If we still don't find it there, use a hardcoded value... XXX */ rid = 0; irq = bus_get_resource_start(dev, SYS_RES_IRQ, rid); if (irq <= 0) { if (resource_long_value(PSM_DRIVER_NAME, device_get_unit(dev), "irq", &irq) != 0) irq = 12; /* XXX */ device_printf(dev, "irq resource info is missing; " "assuming irq %ld\n", irq); bus_set_resource(dev, SYS_RES_IRQ, rid, irq, 1); } res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_SHAREABLE); bus_release_resource(dev, SYS_RES_IRQ, rid, res); /* keep quiet */ if (!bootverbose) device_quiet(dev); return ((res == NULL) ? ENXIO : 0); }
/* Probe routine. See if the card is there and at the right place. */ static int el_probe(device_t dev) { struct el_softc *sc; u_short base; /* Just for convenience */ u_char station_addr[ETHER_ADDR_LEN]; int i, rid; /* Grab some info for our structure */ sc = device_get_softc(dev); if (isa_get_logicalid(dev)) /* skip PnP probes */ return (ENXIO); if ((base = bus_get_resource_start(dev, SYS_RES_IOPORT, 0)) == 0) return (ENXIO); /* First check the base */ if((base < 0x280) || (base > 0x3f0)) { device_printf(dev, "ioaddr must be between 0x280 and 0x3f0\n"); return(ENXIO); } /* Temporarily map the resources. */ rid = 0; sc->el_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, EL_IOSIZ, RF_ACTIVE); if (sc->el_res == NULL) return(ENXIO); sc->el_btag = rman_get_bustag(sc->el_res); sc->el_bhandle = rman_get_bushandle(sc->el_res); mtx_init(&sc->el_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, MTX_DEF | MTX_RECURSE); EL_LOCK(sc); /* Now attempt to grab the station address from the PROM * and see if it contains the 3com vendor code. */ dprintf(("Probing 3c501 at 0x%x...\n",base)); /* Reset the board */ dprintf(("Resetting board...\n")); CSR_WRITE_1(sc,EL_AC,EL_AC_RESET); DELAY(5); CSR_WRITE_1(sc,EL_AC,0); dprintf(("Reading station address...\n")); /* Now read the address */ for(i=0;i<ETHER_ADDR_LEN;i++) { CSR_WRITE_1(sc,EL_GPBL,i); station_addr[i] = CSR_READ_1(sc,EL_EAW); } /* Now release resources */ bus_release_resource(dev, SYS_RES_IOPORT, rid, sc->el_res); EL_UNLOCK(sc); mtx_destroy(&sc->el_mtx); dprintf(("Address is %6D\n",station_addr, ":")); /* If the vendor code is ok, return a 1. We'll assume that * whoever configured this system is right about the IRQ. */ if((station_addr[0] != 0x02) || (station_addr[1] != 0x60) || (station_addr[2] != 0x8c)) { dprintf(("Bad vendor code.\n")); return(ENXIO); } else { dprintf(("Vendor code ok.\n")); /* Copy the station address into the arpcom structure */ bcopy(station_addr,sc->arpcom.ac_enaddr,ETHER_ADDR_LEN); } device_set_desc(dev, "3Com 3c501 Ethernet"); return(0); }
static int atkbdc_probe(device_t dev) { struct resource *port0; struct resource *port1; int error; int rid; #if defined(__i386__) bus_space_tag_t tag; bus_space_handle_t ioh1; volatile int i; #endif /* check PnP IDs */ if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO) return ENXIO; device_set_desc(dev, "Keyboard controller (i8042)"); rid = 0; port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE); if (port0 == NULL) return ENXIO; /* XXX */ if (bus_get_resource_start(dev, SYS_RES_IOPORT, 1) <= 0) { bus_set_resource(dev, SYS_RES_IOPORT, 1, rman_get_start(port0) + KBD_STATUS_PORT, 1); } rid = 1; port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE); if (port1 == NULL) { bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); return ENXIO; } #if defined(__i386__) /* * Check if we really have AT keyboard controller. Poll status * register until we get "all clear" indication. If no such * indication comes, it probably means that there is no AT * keyboard controller present. Give up in such case. Check relies * on the fact that reading from non-existing in/out port returns * 0xff on i386. May or may not be true on other platforms. */ tag = rman_get_bustag(port0); ioh1 = rman_get_bushandle(port1); for (i = 65536; i != 0; --i) { if ((bus_space_read_1(tag, ioh1, 0) & 0x2) == 0) break; DELAY(16); } if (i == 0) { bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); return ENXIO; } #endif error = atkbdc_probe_unit(device_get_unit(dev), port0, port1); bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); return error; }
/* * Indirection support. The type of bus_space_handle_t is * defined in sys/i386/include/bus_pc98.h. */ struct resource * isa_alloc_resourcev(device_t child, int type, int *rid, bus_addr_t *res, bus_size_t count, u_int flags) { struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; device_t bus = device_get_parent(child); bus_addr_t start; bus_space_handle_t bh; struct resource *re; struct resource **bsre; int i, j, k, linear_cnt, ressz, bsrid; start = bus_get_resource_start(child, type, *rid); linear_cnt = count; ressz = 1; for (i = 1; i < count; ++i) { if (res[i] != res[i - 1] + 1) { if (i < linear_cnt) linear_cnt = i; ++ressz; } } re = isa_alloc_resource(bus, child, type, rid, start + res[0], start + res[linear_cnt - 1], linear_cnt, flags); if (re == NULL) return NULL; bsre = malloc(sizeof (struct resource *) * ressz, M_DEVBUF, M_NOWAIT); if (bsre == NULL) { resource_list_release(rl, bus, child, type, *rid, re); return NULL; } bsre[0] = re; for (i = linear_cnt, k = 1; i < count; i = j, k++) { for (j = i + 1; j < count; j++) { if (res[j] != res[j - 1] + 1) break; } bsrid = *rid + k; bsre[k] = isa_alloc_resource(bus, child, type, &bsrid, start + res[i], start + res[j - 1], j - i, flags); if (bsre[k] == NULL) { for (k--; k >= 0; k--) resource_list_release(rl, bus, child, type, *rid + k, bsre[k]); free(bsre, M_DEVBUF); return NULL; } } bh = rman_get_bushandle(re); bh->bsh_res = bsre; bh->bsh_ressz = ressz; return re; }
static int atkbdc_ebus_attach(device_t dev) { atkbdc_softc_t *sc; atkbdc_device_t *adi; device_t cdev; phandle_t child; u_long count, intr, start; int children, error, rid, unit; char *cname, *dname; unit = device_get_unit(dev); sc = *(atkbdc_softc_t **)device_get_softc(dev); if (sc == NULL) { /* * We have to maintain two copies of the kbdc_softc struct, * as the low-level console needs to have access to the * keyboard controller before kbdc is probed and attached. * kbdc_soft[] contains the default entry for that purpose. * See atkbdc.c. XXX */ sc = atkbdc_get_softc(unit); if (sc == NULL) return (ENOMEM); device_set_softc(dev, sc); } rid = 0; if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count) != 0) { device_printf(dev, "cannot determine command/data port resource\n"); return (ENXIO); } sc->retry = 5000; sc->port0 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, start, 1, RF_ACTIVE); if (sc->port0 == NULL) { device_printf(dev, "cannot allocate command/data port resource\n"); return (ENXIO); } rid = 1; if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count) != 0) { device_printf(dev, "cannot determine status port resource\n"); error = ENXIO; goto fail_port0; } start += KBD_STATUS_PORT; sc->port1 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, start, 1, RF_ACTIVE); if (sc->port1 == NULL) { device_printf(dev, "cannot allocate status port resource\n"); error = ENXIO; goto fail_port0; } error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1); if (error != 0) { device_printf(dev, "atkbdc_attach_unit failed\n"); goto fail_port1; } /* Attach children. */ children = 0; for (child = OF_child(ofw_bus_get_node(dev)); child != 0; child = OF_peer(child)) { if ((OF_getprop_alloc(child, "name", 1, (void **)&cname)) == -1) continue; if (children >= 2) { device_printf(dev, "<%s>: only two children per 8042 supported\n", cname); free(cname, M_OFWPROP); continue; } adi = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV, M_NOWAIT | M_ZERO); if (adi == NULL) { device_printf(dev, "<%s>: malloc failed\n", cname); free(cname, M_OFWPROP); continue; } if (strcmp(cname, "kb_ps2") == 0) { adi->rid = KBDC_RID_KBD; dname = ATKBD_DRIVER_NAME; } else if (strcmp(cname, "kdmouse") == 0) { adi->rid = KBDC_RID_AUX; dname = PSM_DRIVER_NAME; } else { device_printf(dev, "<%s>: unknown device\n", cname); free(adi, M_ATKBDDEV); free(cname, M_OFWPROP); continue; } intr = bus_get_resource_start(dev, SYS_RES_IRQ, adi->rid); if (intr == 0) { device_printf(dev, "<%s>: cannot determine interrupt resource\n", cname); free(adi, M_ATKBDDEV); free(cname, M_OFWPROP); continue; } resource_list_init(&adi->resources); resource_list_add(&adi->resources, SYS_RES_IRQ, adi->rid, intr, intr, 1); if ((cdev = device_add_child(dev, dname, -1)) == NULL) { device_printf(dev, "<%s>: device_add_child failed\n", cname); resource_list_free(&adi->resources); free(adi, M_ATKBDDEV); free(cname, M_OFWPROP); continue; } device_set_ivars(cdev, adi); children++; } error = bus_generic_attach(dev); if (error != 0) { device_printf(dev, "bus_generic_attach failed\n"); goto fail_port1; } return (0); fail_port1: bus_release_resource(dev, SYS_RES_MEMORY, 1, sc->port1); fail_port0: bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->port0); return (error); }
static int mecia_attach(device_t dev) { int error; int irq; void *ih; device_t kid; struct resource *r; int rid; struct slot *slt; struct mecia_slot *sp; sp = MECIA_DEVICE2SOFTC(dev); sp->unit = validunits++; kid = device_add_child(dev, NULL, -1); if (kid == NULL) { device_printf(dev, "Can't add pccard bus slot 0\n"); return (ENXIO); } device_probe_and_attach(kid); slt = pccard_init_slot(kid, &mecia_cinfo); if (slt == 0) { device_printf(dev, "Can't get pccard info slot 0\n"); return (ENXIO); } slt->cdata = sp; sp->slt = slt; validunits++; rid = 0; r = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE); if (!r) return (ENXIO); irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0); if (irq == 0) { /* See if the user has requested a specific IRQ */ if (!getenv_int("machdep.pccard.mecia_irq", &irq)) irq = 0; } rid = 0; r = 0; if (irq > 0) { r = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, irq, irq, 1, RF_ACTIVE); } if (r && ((1 << (rman_get_start(r))) & MECIA_INT_MASK_ALLOWED) == 0) { device_printf(dev, "Hardware does not support irq %d, trying polling.\n", irq); bus_release_resource(dev, SYS_RES_IRQ, rid, r); r = 0; irq = 0; } if (r) { error = bus_setup_intr(dev, r, INTR_TYPE_MISC, meciaintr, (void *) sp, &ih); if (error) { bus_release_resource(dev, SYS_RES_IRQ, rid, r); return (error); } irq = rman_get_start(r); device_printf(dev, "management irq %d\n", irq); } else { irq = 0; } if (irq == 0) { meciatimeout_ch = timeout(meciatimeout, (void *) sp, hz/2); device_printf(dev, "Polling mode\n"); } sp->last_reg1 = inb(MECIA_REG1); if (sp->last_reg1 & MECIA_CARDEXIST) { /* PCMCIA card exist */ sp->slt->laststate = sp->slt->state = filled; pccard_event(sp->slt, card_inserted); } else { sp->slt->laststate = sp->slt->state = empty; } sp->slt->irq = irq; return (bus_generic_attach(dev)); }
static int ex_isa_probe(device_t dev) { u_int iobase; u_int irq; char * irq2ee; u_char * ee2irq; u_char enaddr[6]; int tmp; int error; /* Check isapnp ids */ error = ISA_PNP_PROBE(device_get_parent(dev), dev, ex_ids); /* If the card had a PnP ID that didn't match any we know about */ if (error == ENXIO) { return(error); } /* If we had some other problem. */ if (!(error == 0 || error == ENOENT)) { return(error); } iobase = bus_get_resource_start(dev, SYS_RES_IOPORT, 0); if (!iobase) { printf("ex: no iobase?\n"); return(ENXIO); } if (!look_for_card(iobase)) { printf("ex: no card found at 0x%03x\n", iobase); return(ENXIO); } if (bootverbose) printf("ex: ex_isa_probe() found card at 0x%03x\n", iobase); /* * Reset the card. */ outb(iobase + CMD_REG, Reset_CMD); DELAY(800); ex_get_address(iobase, enaddr); /* work out which set of irq <-> internal tables to use */ if (ex_card_type(enaddr) == CARD_TYPE_EX_10_PLUS) { irq2ee = plus_irq2eemap; ee2irq = plus_ee2irqmap; } else { irq2ee = irq2eemap; ee2irq = ee2irqmap; } tmp = eeprom_read(iobase, EE_W1) & EE_W1_INT_SEL; irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0); if (irq > 0) { /* This will happen if board is in PnP mode. */ if (ee2irq[tmp] != irq) { printf("ex: WARNING: board's EEPROM is configured" " for IRQ %d, using %d\n", ee2irq[tmp], irq); } } else { irq = ee2irq[tmp]; bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1); } if (irq == 0) { printf("ex: invalid IRQ.\n"); return(ENXIO); } return(0); }
/****************************************************************************** agtiapi_InitResource() Purpose: Mapping PCI memory space Allocate and initialize per card based resource Parameters: ag_card_info_t *pCardInfo (IN) Return: AGTIAPI_SUCCESS - success AGTIAPI_FAIL - fail Note: ******************************************************************************/ STATIC agBOOLEAN agtiapi_InitResource( ag_card_info_t *thisCardInst ) { struct agtiapi_softc *pmsc = thisCardInst->pCard; device_t devx = thisCardInst->pPCIDev; //AGTIAPI_PRINTK( "agtiapi_InitResource: begin; pointer values %p / %p \n", // devx, thisCardInst ); // no IO mapped card implementation, we'll implement memory mapping if( agtiapi_typhAlloc( thisCardInst ) == AGTIAPI_FAIL ) { printf( "agtiapi_InitResource: failed call to agtiapi_typhAlloc \n" ); return AGTIAPI_FAIL; } AGTIAPI_PRINTK( "agtiapi_InitResource: dma alloc MemSpan %p -- %p\n", (void*) pmsc->typh_busaddr, (void*) ( (U32_64)pmsc->typh_busaddr + pmsc->typhn ) ); // logical BARs for SPC: // bar 0 and 1 - logical BAR0 // bar 2 and 3 - logical BAR1 // bar4 - logical BAR2 // bar5 - logical BAR3 // Skiping the assignments for bar 1 and bar 3 (making bar 0, 2 64-bit): U32 bar; U32 lBar = 0; // logicalBar for (bar = 0; bar < PCI_NUMBER_BARS; bar++) { if ((bar==1) || (bar==3)) continue; thisCardInst->pciMemBaseRIDSpc[lBar] = PCIR_BAR(bar); thisCardInst->pciMemBaseRscSpc[lBar] = bus_alloc_resource_any( devx, SYS_RES_MEMORY, &(thisCardInst->pciMemBaseRIDSpc[lBar]), RF_ACTIVE ); AGTIAPI_PRINTK( "agtiapi_InitResource: bus_alloc_resource_any rtn %p \n", thisCardInst->pciMemBaseRscSpc[lBar] ); if ( thisCardInst->pciMemBaseRscSpc[lBar] != NULL ) { thisCardInst->pciMemVirtAddrSpc[lBar] = (caddr_t)rman_get_virtual( thisCardInst->pciMemBaseRscSpc[lBar] ); thisCardInst->pciMemBaseSpc[lBar] = bus_get_resource_start( devx, SYS_RES_MEMORY, thisCardInst->pciMemBaseRIDSpc[lBar]); thisCardInst->pciMemSizeSpc[lBar] = bus_get_resource_count( devx, SYS_RES_MEMORY, thisCardInst->pciMemBaseRIDSpc[lBar] ); AGTIAPI_PRINTK( "agtiapi_InitResource: PCI: bar %d, lBar %d " "VirtAddr=%lx, len=%d\n", bar, lBar, (long unsigned int)thisCardInst->pciMemVirtAddrSpc[lBar], thisCardInst->pciMemSizeSpc[lBar] ); } else { thisCardInst->pciMemVirtAddrSpc[lBar] = 0; thisCardInst->pciMemBaseSpc[lBar] = 0; thisCardInst->pciMemSizeSpc[lBar] = 0; } lBar++; } thisCardInst->pciMemVirtAddr = thisCardInst->pciMemVirtAddrSpc[0]; thisCardInst->pciMemSize = thisCardInst->pciMemSizeSpc[0]; thisCardInst->pciMemBase = thisCardInst->pciMemBaseSpc[0]; // Allocate all TI data structure required resources. // tiLoLevelResource U32 numVal; ag_resource_info_t *pRscInfo; pRscInfo = &thisCardInst->tiRscInfo; pRscInfo->tiLoLevelResource.loLevelOption.pciFunctionNumber = pci_get_function( devx ); struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; int ticksPerSec; ticksPerSec = tvtohz( &tv ); int uSecPerTick = 1000000/USEC_PER_TICK; if (pRscInfo->tiLoLevelResource.loLevelMem.count != 0) { //AGTIAPI_INIT("agtiapi_InitResource: loLevelMem count = %d\n", // pRscInfo->tiLoLevelResource.loLevelMem.count); // adjust tick value to meet Linux requirement pRscInfo->tiLoLevelResource.loLevelOption.usecsPerTick = uSecPerTick; AGTIAPI_PRINTK( "agtiapi_InitResource: " "pRscInfo->tiLoLevelResource.loLevelOption.usecsPerTick" " 0x%x\n", pRscInfo->tiLoLevelResource.loLevelOption.usecsPerTick ); for( numVal = 0; numVal < pRscInfo->tiLoLevelResource.loLevelMem.count; numVal++ ) { if( pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].totalLength == 0 ) { AGTIAPI_PRINTK("agtiapi_InitResource: skip ZERO %d\n", numVal); continue; } // check for 64 bit alignment if ( pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].alignment < AGTIAPI_64BIT_ALIGN ) { AGTIAPI_PRINTK("agtiapi_InitResource: set ALIGN %d\n", numVal); pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].alignment = AGTIAPI_64BIT_ALIGN; } if( ((pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].type & (BIT(0) | BIT(1))) == TI_DMA_MEM) || ((pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].type & (BIT(0) | BIT(1))) == TI_CACHED_DMA_MEM)) { if ( thisCardInst->dmaIndex >= sizeof(thisCardInst->tiDmaMem) / sizeof(thisCardInst->tiDmaMem[0]) ) { AGTIAPI_PRINTK( "Invalid dmaIndex %d ERROR\n", thisCardInst->dmaIndex ); return AGTIAPI_FAIL; } thisCardInst->tiDmaMem[thisCardInst->dmaIndex].type = #ifdef CACHED_DMA pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].type & (BIT(0) | BIT(1)); #else TI_DMA_MEM; #endif if( agtiapi_MemAlloc( thisCardInst, &thisCardInst->tiDmaMem[thisCardInst->dmaIndex].dmaVirtAddr, &thisCardInst->tiDmaMem[thisCardInst->dmaIndex].dmaPhysAddr, &pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].virtPtr, &pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal]. physAddrUpper, &pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal]. physAddrLower, pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].totalLength, thisCardInst->tiDmaMem[thisCardInst->dmaIndex].type, pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].alignment) != AGTIAPI_SUCCESS ) { return AGTIAPI_FAIL; } thisCardInst->tiDmaMem[thisCardInst->dmaIndex].memSize = pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].totalLength; //AGTIAPI_INIT("agtiapi_InitResource: LoMem %d dmaIndex=%d DMA virt" // " %p, phys 0x%x, length %d align %d\n", // numVal, pCardInfo->dmaIndex, // pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].virtPtr, // pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].physAddrLower, // pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].totalLength, // pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].alignment); thisCardInst->dmaIndex++; } else if ( (pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].type & (BIT(0) | BIT(1))) == TI_CACHED_MEM) { if (thisCardInst->cacheIndex >= sizeof(thisCardInst->tiCachedMem) / sizeof(thisCardInst->tiCachedMem[0])) { AGTIAPI_PRINTK( "Invalid cacheIndex %d ERROR\n", thisCardInst->cacheIndex ); return AGTIAPI_FAIL; } if ( agtiapi_MemAlloc( thisCardInst, &thisCardInst->tiCachedMem[thisCardInst->cacheIndex], (vm_paddr_t *)agNULL, &pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].virtPtr, (U32 *)agNULL, (U32 *)agNULL, pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].totalLength, TI_CACHED_MEM, pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].alignment) != AGTIAPI_SUCCESS ) { return AGTIAPI_FAIL; } //AGTIAPI_INIT("agtiapi_InitResource: LoMem %d cacheIndex=%d CACHED " // "vaddr %p / %p, length %d align %d\n", // numVal, pCardInfo->cacheIndex, // pCardInfo->tiCachedMem[pCardInfo->cacheIndex], // pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].virtPtr, // pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].totalLength, // pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].alignment); thisCardInst->cacheIndex++; } else if ( ((pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].type & (BIT(0) | BIT(1))) == TI_DMA_MEM_CHIP)) { // not expecting this case, print warning that should get attention printf( "RED ALARM: we need a BAR for TI_DMA_MEM_CHIP, ignoring!" ); } else { printf( "agtiapi_InitResource: Unknown required memory type %d " "ERROR!\n", pRscInfo->tiLoLevelResource.loLevelMem.mem[numVal].type); return AGTIAPI_FAIL; } } } // end: TI data structure resources ... // begin: tiInitiatorResource if ( pmsc->flags & AGTIAPI_INITIATOR ) { if ( pRscInfo->tiInitiatorResource.initiatorMem.count != 0 ) { //AGTIAPI_INIT("agtiapi_InitResource: initiatorMem count = %d\n", // pRscInfo->tiInitiatorResource.initiatorMem.count); numVal = (U32)( pRscInfo->tiInitiatorResource.initiatorOption.usecsPerTick / uSecPerTick ); if( pRscInfo->tiInitiatorResource.initiatorOption.usecsPerTick % uSecPerTick > 0 ) pRscInfo->tiInitiatorResource.initiatorOption.usecsPerTick = (numVal + 1) * uSecPerTick; else pRscInfo->tiInitiatorResource.initiatorOption.usecsPerTick = numVal * uSecPerTick; for ( numVal = 0; numVal < pRscInfo->tiInitiatorResource.initiatorMem.count; numVal++ ) { // check for 64 bit alignment if( pRscInfo->tiInitiatorResource.initiatorMem.tdCachedMem[numVal]. alignment < AGTIAPI_64BIT_ALIGN ) { pRscInfo->tiInitiatorResource.initiatorMem.tdCachedMem[numVal]. alignment = AGTIAPI_64BIT_ALIGN; } if( thisCardInst->cacheIndex >= sizeof( thisCardInst->tiCachedMem) / sizeof( thisCardInst->tiCachedMem[0])) { AGTIAPI_PRINTK( "Invalid cacheIndex %d ERROR\n", thisCardInst->cacheIndex ); return AGTIAPI_FAIL; } // initiator memory is cached, no check is needed if( agtiapi_MemAlloc( thisCardInst, (void *)&thisCardInst->tiCachedMem[thisCardInst->cacheIndex], (vm_paddr_t *)agNULL, &pRscInfo->tiInitiatorResource.initiatorMem. tdCachedMem[numVal].virtPtr, (U32 *)agNULL, (U32 *)agNULL, pRscInfo->tiInitiatorResource.initiatorMem.tdCachedMem[numVal]. totalLength, TI_CACHED_MEM, pRscInfo->tiInitiatorResource.initiatorMem.tdCachedMem[numVal]. alignment) != AGTIAPI_SUCCESS) { return AGTIAPI_FAIL; } // AGTIAPI_INIT("agtiapi_InitResource: IniMem %d cacheIndex=%d CACHED " // "vaddr %p / %p, length %d align 0x%x\n", // numVal, // pCardInfo->cacheIndex, // pCardInfo->tiCachedMem[pCardInfo->cacheIndex], // pRscInfo->tiInitiatorResource.initiatorMem.tdCachedMem[numVal]. // virtPtr, //pRscInfo->tiInitiatorResource.initiatorMem.tdCachedMem[numVal]. // totalLength, // pRscInfo->tiInitiatorResource.initiatorMem.tdCachedMem[numVal]. // alignment); thisCardInst->cacheIndex++; } } } // end: tiInitiatorResource // begin: tiTdSharedMem if (pRscInfo->tiSharedMem.tdSharedCachedMem1.totalLength != 0) { // check for 64 bit alignment if( pRscInfo->tiSharedMem.tdSharedCachedMem1.alignment < AGTIAPI_64BIT_ALIGN ) { pRscInfo->tiSharedMem.tdSharedCachedMem1.alignment = AGTIAPI_64BIT_ALIGN; } if( (pRscInfo->tiSharedMem.tdSharedCachedMem1.type & (BIT(0) | BIT(1))) == TI_DMA_MEM ) { if( thisCardInst->dmaIndex >= sizeof(thisCardInst->tiDmaMem) / sizeof(thisCardInst->tiDmaMem[0]) ) { AGTIAPI_PRINTK( "Invalid dmaIndex %d ERROR\n", thisCardInst->dmaIndex); return AGTIAPI_FAIL; } if( agtiapi_MemAlloc( thisCardInst, (void *)&thisCardInst-> tiDmaMem[thisCardInst->dmaIndex].dmaVirtAddr, &thisCardInst->tiDmaMem[thisCardInst->dmaIndex]. dmaPhysAddr, &pRscInfo->tiSharedMem.tdSharedCachedMem1.virtPtr, &pRscInfo->tiSharedMem.tdSharedCachedMem1. physAddrUpper, &pRscInfo->tiSharedMem.tdSharedCachedMem1. physAddrLower, pRscInfo->tiSharedMem.tdSharedCachedMem1. totalLength, TI_DMA_MEM, pRscInfo->tiSharedMem.tdSharedCachedMem1.alignment) != AGTIAPI_SUCCESS ) return AGTIAPI_FAIL; thisCardInst->tiDmaMem[thisCardInst->dmaIndex].memSize = pRscInfo->tiSharedMem.tdSharedCachedMem1.totalLength + pRscInfo->tiSharedMem.tdSharedCachedMem1.alignment; // printf( "agtiapi_InitResource: SharedMem DmaIndex=%d DMA " // "virt %p / %p, phys 0x%x, align %d\n", // thisCardInst->dmaIndex, // thisCardInst->tiDmaMem[thisCardInst->dmaIndex].dmaVirtAddr, // pRscInfo->tiSharedMem.tdSharedCachedMem1.virtPtr, // pRscInfo->tiSharedMem.tdSharedCachedMem1.physAddrLower, // pRscInfo->tiSharedMem.tdSharedCachedMem1.alignment); thisCardInst->dmaIndex++; } else if( (pRscInfo->tiSharedMem.tdSharedCachedMem1.type & (BIT(0) | BIT(1))) == TI_CACHED_MEM ) { if( thisCardInst->cacheIndex >= sizeof(thisCardInst->tiCachedMem) / sizeof(thisCardInst->tiCachedMem[0]) ) { AGTIAPI_PRINTK( "Invalid cacheIndex %d ERROR\n", thisCardInst->cacheIndex); return AGTIAPI_FAIL; } if( agtiapi_MemAlloc( thisCardInst, (void *)&thisCardInst-> tiCachedMem[thisCardInst->cacheIndex], (vm_paddr_t *)agNULL, &pRscInfo->tiSharedMem.tdSharedCachedMem1.virtPtr, (U32 *)agNULL, (U32 *)agNULL, pRscInfo-> tiSharedMem.tdSharedCachedMem1.totalLength, TI_CACHED_MEM, pRscInfo->tiSharedMem.tdSharedCachedMem1.alignment) != AGTIAPI_SUCCESS ) return AGTIAPI_FAIL; // printf( "agtiapi_InitResource: SharedMem cacheIndex=%d CACHED " // "vaddr %p / %p, length %d align 0x%x\n", // thisCardInst->cacheIndex, // thisCardInst->tiCachedMem[thisCardInst->cacheIndex], // pRscInfo->tiSharedMem.tdSharedCachedMem1.virtPtr, // pRscInfo->tiSharedMem.tdSharedCachedMem1.totalLength, // pRscInfo->tiSharedMem.tdSharedCachedMem1.alignment); AGTIAPI_PRINTK( "agtiapi_InitResource: SharedMem cacheIndex=%d CACHED " "vaddr %p / %p, length %d align 0x%x\n", thisCardInst->cacheIndex, thisCardInst->tiCachedMem[thisCardInst->cacheIndex], pRscInfo->tiSharedMem.tdSharedCachedMem1.virtPtr, pRscInfo->tiSharedMem.tdSharedCachedMem1.totalLength, pRscInfo->tiSharedMem.tdSharedCachedMem1.alignment ); thisCardInst->cacheIndex++; } else { AGTIAPI_PRINTK( "agtiapi_InitResource: " "Unknown required memory type ERROR!\n" ); return AGTIAPI_FAIL; } } // end: tiTdSharedMem DELAY( 200000 ); // or use AGTIAPI_INIT_MDELAY(200); return AGTIAPI_SUCCESS; } // agtiapi_InitResource() ends here
static int ex_isa_probe(device_t dev) { bus_addr_t iobase; u_int irq; char * irq2ee; u_char * ee2irq; u_char enaddr[6]; int tmp; int error; struct ex_softc *sc = device_get_softc(dev); /* Check isapnp ids */ error = ISA_PNP_PROBE(device_get_parent(dev), dev, ex_ids); /* If the card had a PnP ID that didn't match any we know about */ if (error == ENXIO) return(error); /* If we had some other problem. */ if (!(error == 0 || error == ENOENT)) return(error); error = ex_alloc_resources(dev); if (error != 0) goto bad; iobase = bus_get_resource_start(dev, SYS_RES_IOPORT, 0); if (!ex_look_for_card(sc)) { if (bootverbose) printf("ex: no card found at 0x%03lx.\n", (unsigned long)iobase); error = ENXIO; goto bad; } if (bootverbose) printf("ex: ex_isa_probe() found card at 0x%03lx\n", (unsigned long)iobase); /* * Reset the card. */ CSR_WRITE_1(sc, CMD_REG, Reset_CMD); DELAY(800); ex_get_address(sc, enaddr); /* work out which set of irq <-> internal tables to use */ if (ex_card_type(enaddr) == CARD_TYPE_EX_10_PLUS) { irq2ee = plus_irq2eemap; ee2irq = plus_ee2irqmap; } else { irq2ee = irq2eemap; ee2irq = ee2irqmap; } tmp = ex_eeprom_read(sc, EE_W1) & EE_W1_INT_SEL; irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0); if (irq > 0) { /* This will happen if board is in PnP mode. */ if (ee2irq[tmp] != irq) { device_printf(dev, "WARNING: IRQ mismatch: EEPROM %d, using %d\n", ee2irq[tmp], irq); } } else { irq = ee2irq[tmp]; bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1); } if (irq == 0) { printf("ex: invalid IRQ.\n"); error = ENXIO; } bad:; ex_release_resources(dev); return (error); }