static int fdc_cbus_alloc_resources(device_t dev, struct fdc_data *fdc) { int rid; fdc->fdc_dev = dev; fdc->rid_ioport = 0; fdc->rid_irq = 0; fdc->rid_drq = 0; fdc->res_irq = 0; fdc->res_drq = 0; fdc->res_ioport = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &fdc->rid_ioport, fdc_iat, 3, RF_ACTIVE); if (fdc->res_ioport == 0) { device_printf(dev, "cannot reserve I/O port range\n"); return ENXIO; } isa_load_resourcev(fdc->res_ioport, fdc_iat, 3); fdc->portt = rman_get_bustag(fdc->res_ioport); fdc->porth = rman_get_bushandle(fdc->res_ioport); rid = 3; bus_set_resource(dev, SYS_RES_IOPORT, rid, IO_FDPORT, 1); fdc->res_fdsio = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); if (fdc->res_fdsio == 0) return ENXIO; fdc->sc_fdsiot = rman_get_bustag(fdc->res_fdsio); fdc->sc_fdsioh = rman_get_bushandle(fdc->res_fdsio); rid = 4; bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x4be, 1); fdc->res_fdemsio = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); if (fdc->res_fdemsio == 0) return ENXIO; fdc->sc_fdemsiot = rman_get_bustag(fdc->res_fdemsio); fdc->sc_fdemsioh = rman_get_bushandle(fdc->res_fdemsio); fdc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &fdc->rid_irq, RF_ACTIVE); if (fdc->res_irq == 0) { device_printf(dev, "cannot reserve interrupt line\n"); return ENXIO; } if ((fdc->flags & FDC_NODMA) == 0) { fdc->res_drq = bus_alloc_resource_any(dev, SYS_RES_DRQ, &fdc->rid_drq, RF_ACTIVE); if (fdc->res_drq == 0) { device_printf(dev, "cannot reserve DMA request line\n"); return ENXIO; } fdc->dmachan = rman_get_start(fdc->res_drq); } return 0; }
static int pckbdattach(device_t dev) { keyboard_t *kbd; void *ih; struct resource *res; int error, rid; rid = 0; res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, pckbd_iat, 2, RF_ACTIVE); if (res == NULL) return ENXIO; isa_load_resourcev(res, pckbd_iat, 2); error = pckbd_attach_unit(dev, &kbd, isa_get_port(dev), (1 << isa_get_irq(dev)), device_get_flags(dev)); rid = 0; res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); if (res == NULL) return ENXIO; bus_setup_intr(dev, res, INTR_TYPE_TTY, NULL, pckbd_isa_intr, kbd, &ih); return 0; }
static int pckbdprobe(device_t dev) { struct resource *res; int error, rid; /* Check isapnp ids */ if (isa_get_vendorid(dev)) return (ENXIO); device_set_desc(dev, "PC-98 Keyboard"); rid = 0; res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, pckbd_iat, 2, RF_ACTIVE); if (res == NULL) return ENXIO; isa_load_resourcev(res, pckbd_iat, 2); error = pckbd_probe_unit(dev, isa_get_port(dev), (1 << isa_get_irq(dev)), device_get_flags(dev)); bus_release_resource(dev, SYS_RES_IOPORT, rid, res); return (error); }
static int sbc_probe(device_t dev) { char *s = NULL; u_int32_t lid, vid; lid = isa_get_logicalid(dev); vid = isa_get_vendorid(dev); if (lid) { if (lid == 0x01000000 && vid != 0x01009305) /* ALS0001 */ return ENXIO; /* Check pnp ids */ return ISA_PNP_PROBE(device_get_parent(dev), dev, sbc_ids); } else { int rid = 0, ver; struct resource *io; #ifdef PC98 io = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, pcm_iat, 16, RF_ACTIVE); #else io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 16, RF_ACTIVE); #endif if (!io) goto bad; #ifdef PC98 isa_load_resourcev(io, pcm_iat, 16); #endif if (sb_reset_dsp(io)) goto bad2; ver = sb_identify_board(io); if (ver == 0) goto bad2; switch ((ver & 0x00000f00) >> 8) { case 1: device_set_desc(dev, "SoundBlaster 1.0 (not supported)"); s = NULL; break; case 2: s = "SoundBlaster 2.0"; break; case 3: s = (ver & 0x0000f000)? "ESS 488" : "SoundBlaster Pro"; break; case 4: s = "SoundBlaster 16"; break; case 5: s = (ver & 0x00000008)? "ESS 688" : "ESS 1688"; break; } if (s) device_set_desc(dev, s); bad2: bus_release_resource(dev, SYS_RES_IOPORT, rid, io); bad: return s? 0 : ENXIO; } }
/* XXX Todo - try and detect if interrupt is working */ int lpt_attach(device_t dev) { int rid, unit; struct lpt_softc *sc; struct cdev *cdev; unit = device_get_unit(dev); sc = device_get_softc(dev); callout_init(&sc->timer, 0); rid = 0; sc->res_port = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, lpt_iat, 4, RF_ACTIVE); if (sc->res_port == NULL) return ENXIO; isa_load_resourcev(sc->res_port, lpt_iat, 4); sc->sc_port = rman_get_start(sc->res_port); sc->sc_primed = 0; /* not primed yet */ outb(sc->sc_port+lpt_pstb_ctrl, LPC_DIS_PSTB); /* PSTB disable */ outb(sc->sc_port+lpt_control, LPC_MODE8255); /* 8255 mode set */ outb(sc->sc_port+lpt_control, LPC_NIRQ8); /* IRQ8 inactive */ outb(sc->sc_port+lpt_control, LPC_NPSTB); /* PSTB inactive */ outb(sc->sc_port+lpt_pstb_ctrl, LPC_EN_PSTB); /* PSTB enable */ sc->sc_irq = 0; if (isa_get_irq(dev) != -1) { rid = 0; sc->res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); if (sc->res_irq == NULL) { bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->res_port); return ENXIO; } if (bus_setup_intr(dev, sc->res_irq, INTR_TYPE_TTY, NULL, lpt_intr, sc, &sc->sc_ih)) { bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->res_port); bus_release_resource(dev, SYS_RES_IRQ, 0, sc->res_irq); return ENXIO; } sc->sc_irq = LP_HAS_IRQ | LP_USE_IRQ | LP_ENABLE_IRQ; device_printf(dev, "Interrupt-driven port"); } cdev = make_dev(&lpt_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "lpt%d", unit); cdev->si_drv1 = sc; cdev = make_dev(&lpt_cdevsw, LP_BYPASS, UID_ROOT, GID_WHEEL, 0600, "lpctl%d", unit); cdev->si_drv1 = sc; return 0; }
/* XXX Todo - try and detect if interrupt is working */ int lpt_attach(device_t dev) { int rid, unit; struct lpt_softc *sc; unit = device_get_unit(dev); sc = device_get_softc(dev); rid = 0; sc->res_port = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, lpt_iat, 4, RF_ACTIVE); if (sc->res_port == NULL) return ENXIO; isa_load_resourcev(sc->res_port, lpt_iat, 4); sc->sc_port = rman_get_start(sc->res_port); sc->sc_primed = 0; /* not primed yet */ #ifdef PC98 outb(sc->sc_port+lpt_pstb_ctrl, LPC_DIS_PSTB); /* PSTB disable */ outb(sc->sc_port+lpt_control, LPC_MODE8255); /* 8255 mode set */ outb(sc->sc_port+lpt_control, LPC_NIRQ8); /* IRQ8 inactive */ outb(sc->sc_port+lpt_control, LPC_NPSTB); /* PSTB inactive */ outb(sc->sc_port+lpt_pstb_ctrl, LPC_EN_PSTB); /* PSTB enable */ #else outb(sc->sc_port+lpt_control, LPC_NINIT); #endif sc->sc_irq = 0; if (isa_get_irq(dev) != -1) { rid = 0; sc->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE); if (sc->res_irq == NULL) { bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->res_port); return ENXIO; } if (bus_setup_intr(dev, sc->res_irq, INTR_TYPE_TTY, lpt_intr, sc, &sc->sc_ih)) { bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->res_port); bus_release_resource(dev, SYS_RES_IRQ, 0, sc->res_irq); return ENXIO; } sc->sc_irq = LP_HAS_IRQ | LP_USE_IRQ | LP_ENABLE_IRQ; device_printf(dev, "Interrupt-driven port"); } /* XXX what to do about the flags in the minor number? */ make_dev(&lpt_cdevsw, unit, UID_ROOT, GID_WHEEL, 0600, "lpt%d", unit); make_dev(&lpt_cdevsw, unit | LP_BYPASS, UID_ROOT, GID_WHEEL, 0600, "lpctl%d", unit); return 0; }
static int fe98_alloc_port(device_t dev, int type) { struct fe_softc *sc = device_get_softc(dev); struct resource *res; bus_addr_t *iat; int size, rid; switch (type) { case FE_TYPE_RE1000: iat = ioaddr_re1000; size = MAXREGISTERS; break; case FE_TYPE_CNET9NE: iat = ioaddr_cnet9ne; size = MAXREGISTERS; break; case FE_TYPE_SSI: iat = ioaddr_generic; size = MAXREGISTERS; break; case FE_TYPE_LNX: iat = ioaddr_lnx; size = MAXREGISTERS; break; case FE_TYPE_GWY: iat = ioaddr_generic; size = MAXREGISTERS; break; case FE_TYPE_UBN: iat = ioaddr_ubn; size = MAXREGISTERS; break; case FE_TYPE_REX: iat = ioaddr_rex; size = MAXREGISTERS; break; default: iat = ioaddr_generic; size = MAXREGISTERS; break; } rid = 0; res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, iat, size, RF_ACTIVE); if (res == NULL) return ENOENT; isa_load_resourcev(res, iat, size); sc->type = type; sc->port_used = size; sc->port_res = res; return (0); }
static int alloc_resource(struct sbc_softc *scp) { int i; for (i = 0 ; i < IO_MAX ; i++) { if (scp->io[i] == NULL) { #ifdef PC98 scp->io_rid[i] = i > 0 ? scp->io_rid[i - 1] + io_range[i - 1] : 0; scp->io[i] = isa_alloc_resourcev(scp->dev, SYS_RES_IOPORT, &scp->io_rid[i], sb_iat[i], io_range[i], RF_ACTIVE); if (scp->io[i] != NULL) isa_load_resourcev(scp->io[i], sb_iat[i], io_range[i]); #else scp->io_rid[i] = i; scp->io[i] = bus_alloc_resource(scp->dev, SYS_RES_IOPORT, &scp->io_rid[i], 0, ~0, io_range[i], RF_ACTIVE); #endif if (i == 0 && scp->io[i] == NULL) return (1); scp->io_alloced[i] = 0; } } for (i = 0 ; i < DRQ_MAX ; i++) { if (scp->drq[i] == NULL) { scp->drq_rid[i] = i; scp->drq[i] = bus_alloc_resource_any(scp->dev, SYS_RES_DRQ, &scp->drq_rid[i], RF_ACTIVE); if (i == 0 && scp->drq[i] == NULL) return (1); scp->drq_alloced[i] = 0; } } for (i = 0 ; i < IRQ_MAX ; i++) { if (scp->irq[i] == NULL) { scp->irq_rid[i] = i; scp->irq[i] = bus_alloc_resource_any(scp->dev, SYS_RES_IRQ, &scp->irq_rid[i], RF_ACTIVE); if (i == 0 && scp->irq[i] == NULL) return (1); scp->irq_alloced[i] = 0; } } return (0); }
static int aic_isa_alloc_resources(device_t dev) { struct aic_isa_softc *sc = device_get_softc(dev); int rid; bus_addr_t *bs_iat; if ((isa_get_logicalid(dev) == 0xa180a3b8) || (AIC_TYPE98(device_get_flags(dev)) == AIC98_NEC100)) bs_iat = aicport_100; else bs_iat = aicport_generic; sc->sc_port = sc->sc_irq = sc->sc_drq = NULL; rid = 0; sc->sc_port = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, bs_iat, AIC_ISA_PORTSIZE, RF_ACTIVE); if (!sc->sc_port) { device_printf(dev, "I/O port allocation failed\n"); return (ENOMEM); } isa_load_resourcev(sc->sc_port, bs_iat, AIC_ISA_PORTSIZE); mtx_init(&sc->sc_aic.lock, "aic", NULL, MTX_DEF); if (isa_get_irq(dev) != -1) { rid = 0; sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); if (!sc->sc_irq) { device_printf(dev, "IRQ allocation failed\n"); aic_isa_release_resources(dev); return (ENOMEM); } } if (isa_get_drq(dev) != -1) { rid = 0; sc->sc_drq = bus_alloc_resource_any(dev, SYS_RES_DRQ, &rid, RF_ACTIVE); if (!sc->sc_drq) { device_printf(dev, "DRQ allocation failed\n"); aic_isa_release_resources(dev); return (ENOMEM); } } sc->sc_aic.dev = dev; sc->sc_aic.res = sc->sc_port; return (0); }
int lpt_probe(device_t dev) { #define PC98_OLD_LPT 0x40 #define PC98_IEEE_1284_FUNCTION 0x149 int rid; struct resource *res; /* Check isapnp ids */ if (isa_get_vendorid(dev)) return ENXIO; rid = 0; res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, lpt_iat, 4, RF_ACTIVE); if (res == NULL) return ENXIO; isa_load_resourcev(res, lpt_iat, 4); if (isa_get_port(dev) == PC98_OLD_LPT) { unsigned int pc98_ieee_mode, tmp; tmp = inb(PC98_IEEE_1284_FUNCTION); pc98_ieee_mode = tmp; if ((tmp & 0x10) == 0x10) { outb(PC98_IEEE_1284_FUNCTION, tmp & ~0x10); tmp = inb(PC98_IEEE_1284_FUNCTION); if ((tmp & 0x10) != 0x10) { outb(PC98_IEEE_1284_FUNCTION, pc98_ieee_mode); bus_release_resource(dev, SYS_RES_IOPORT, rid, res); return ENXIO; } } } bus_release_resource(dev, SYS_RES_IOPORT, rid, res); return 0; }
static int gdc_alloc_resource(device_t dev) { int rid; gdc_softc_t *sc; sc = device_get_softc(dev); /* TEXT GDC */ rid = 0; bus_set_resource(dev, SYS_RES_IOPORT, rid, TEXT_GDC, 1); sc->res_tgdc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_tgdc == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_tgdc, gdc_iat, 8); /* GRAPHIC GDC */ rid = 8; bus_set_resource(dev, SYS_RES_IOPORT, rid, GRAPHIC_GDC, 1); sc->res_ggdc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_ggdc == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_ggdc, gdc_iat, 8); /* EGC */ rid = 16; bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x4a0, 1); sc->res_egc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_egc == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_egc, gdc_iat, 8); /* PEGC */ rid = 24; bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x9a0, 1); sc->res_pegc = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_pegc == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_pegc, gdc_iat, 8); /* CRTC/GRCG */ rid = 32; bus_set_resource(dev, SYS_RES_IOPORT, rid, 0x70, 1); sc->res_grcg = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_grcg == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_grcg, gdc_iat, 8); /* KCG */ rid = 40; bus_set_resource(dev, SYS_RES_IOPORT, rid, 0xa1, 1); sc->res_kcg = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, gdc_iat, 8, RF_ACTIVE); if (sc->res_kcg == NULL) { gdc_release_resource(dev); return (ENXIO); } isa_load_resourcev(sc->res_kcg, gdc_iat, 8); /* TEXT Memory */ rid = 0; sc->res_tmem = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0xa0000, 0xa4fff, 0x5000, RF_ACTIVE); if (sc->res_tmem == NULL) { gdc_release_resource(dev); return (ENXIO); } /* GRAPHIC Memory */ rid = 1; sc->res_gmem1 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0xa8000, 0xbffff, 0x18000, RF_ACTIVE); if (sc->res_gmem1 == NULL) { gdc_release_resource(dev); return (ENXIO); } rid = 2; sc->res_gmem2 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0xe0000, 0xe7fff, 0x8000, RF_ACTIVE); if (sc->res_gmem2 == NULL) { gdc_release_resource(dev); return (ENXIO); } return (0); }
int lpt_probe(device_t dev) { #ifdef PC98 #define PC98_OLD_LPT 0x40 #define PC98_IEEE_1284_FUNCTION 0x149 int rid; struct resource *res; /* Check isapnp ids */ if (isa_get_vendorid(dev)) return ENXIO; rid = 0; res = isa_alloc_resourcev(dev, SYS_RES_IOPORT, &rid, lpt_iat, 4, RF_ACTIVE); if (res == NULL) return ENXIO; isa_load_resourcev(res, lpt_iat, 4); if (isa_get_port(dev) == PC98_OLD_LPT) { unsigned int pc98_ieee_mode, tmp; tmp = inb(PC98_IEEE_1284_FUNCTION); pc98_ieee_mode = tmp; if ((tmp & 0x10) == 0x10) { outb(PC98_IEEE_1284_FUNCTION, tmp & ~0x10); tmp = inb(PC98_IEEE_1284_FUNCTION); if ((tmp & 0x10) != 0x10) { outb(PC98_IEEE_1284_FUNCTION, pc98_ieee_mode); bus_release_resource(dev, SYS_RES_IOPORT, rid, res); return ENXIO; } } } bus_release_resource(dev, SYS_RES_IOPORT, rid, res); return 0; #else int port; static short next_bios_lpt = 0; int status; static u_char testbyte[18] = { 0x55, /* alternating zeros */ 0xaa, /* alternating ones */ 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f, /* walking zero */ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 /* walking one */ }; int i; /* * Make sure there is some way for lptopen to see that * the port is not configured * This 0 will remain if the port isn't attached */ (lpt_sc + dvp->id_unit)->sc_port = 0; status = IO_LPTSIZE; /* If port not specified, use bios list */ if(dvp->id_iobase < 0) { /* port? */ if((next_bios_lpt < BIOS_MAX_LPT) && (*(BIOS_PORTS+next_bios_lpt) != 0) ) { dvp->id_iobase = *(BIOS_PORTS+next_bios_lpt++); goto end_probe; } else return (0); } /* Port was explicitly specified */ /* This allows probing of ports unknown to the BIOS */ port = dvp->id_iobase + lpt_data; for (i = 0; i < 18; i++) { if (!lpt_port_test(port, testbyte[i], 0xff)) { status = 0; goto end_probe; } } end_probe: /* write 0's to control and data ports */ outb(dvp->id_iobase+lpt_data, 0); outb(dvp->id_iobase+lpt_control, 0); return (status); #endif }