static int bt_pci_alloc_resources(device_t dev) { int type = 0, rid, zero; struct resource *regs = 0; struct resource *irq = 0; #if 0 /* XXX Memory Mapped I/O seems to cause problems */ type = SYS_RES_MEMORY; rid = BT_PCI_MEMADDR; regs = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE); #else type = SYS_RES_IOPORT; rid = BT_PCI_IOADDR; regs = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE); #endif if (!regs) return (ENOMEM); zero = 0; irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &zero, RF_ACTIVE | RF_SHAREABLE); if (!irq) { bus_release_resource(dev, type, rid, regs); return (ENOMEM); } bt_init_softc(dev, regs, irq, 0); return (0); }
static int bt_isa_alloc_resources(device_t dev, u_long portstart, u_long portend) { int rid; struct resource *port; struct resource *irq; struct resource *drq; rid = 0; port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, portstart, portend, BT_NREGS, RF_ACTIVE); if (!port) return (ENOMEM); if (isa_get_irq(dev) != -1) { rid = 0; irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE); if (!irq) { if (port) bus_release_resource(dev, SYS_RES_IOPORT, 0, port); return (ENOMEM); } } else irq = NULL; if (isa_get_drq(dev) != -1) { rid = 0; drq = bus_alloc_resource(dev, SYS_RES_DRQ, &rid, 0, ~0, 1, RF_ACTIVE); if (!drq) { if (port) bus_release_resource(dev, SYS_RES_IOPORT, 0, port); if (irq) bus_release_resource(dev, SYS_RES_IRQ, 0, irq); return (ENOMEM); } } else drq = NULL; bt_init_softc(dev, port, irq, drq); return (0); }
static int bt_mca_alloc_resources(device_t dev, int mode) { struct resource * io = NULL; struct resource * irq = NULL; struct resource * drq = NULL; int rid; rid = 0; io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE); if (io == NULL) { printf("bt_mca_alloc_resources() failed to allocate IOPORT\n"); return (ENOMEM); } if (mode == BT_MCA_ATTACH) { rid = 0; irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE); if (irq == NULL) { printf("bt_mca_alloc_resources() failed to allocate IRQ\n"); goto bad; } rid = 0; drq = bus_alloc_resource(dev, SYS_RES_DRQ, &rid, 0, ~0, 1, RF_ACTIVE); if (drq == NULL) { printf("bt_mca_alloc_resources() failed to allocate DRQ\n"); goto bad; } } bt_init_softc(dev, io, irq, drq); return (0); bad: bt_mca_release_resources(dev); return (ENOMEM); }
static int bt_pci_alloc_resources(device_t dev) { int command, type = 0, rid, zero; struct resource *regs = NULL; struct resource *irq = NULL; command = pci_read_config(dev, PCIR_COMMAND, /*bytes*/1); #if 0 /* XXX Memory Mapped I/O seems to cause problems */ if (command & PCIM_CMD_MEMEN) { type = SYS_RES_MEMORY; rid = BT_PCI_MEMADDR; regs = bus_alloc_resource(dev, type, &rid, 0, ~0, 1, RF_ACTIVE); } #else if (!regs && (command & PCIM_CMD_PORTEN)) { type = SYS_RES_IOPORT; rid = BT_PCI_IOADDR; regs = bus_alloc_resource(dev, type, &rid, 0, ~0, 1, RF_ACTIVE); } #endif if (!regs) return (ENOMEM); zero = 0; irq = bus_alloc_resource(dev, SYS_RES_IRQ, &zero, 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE); if (!irq) { bus_release_resource(dev, type, rid, regs); return (ENOMEM); } bt_init_softc(dev, regs, irq, 0); return (0); }
static int bt_eisa_alloc_resources(device_t dev) { struct bt_softc *bt = device_get_softc(dev); int rid; struct resource *port; struct resource *irq; int shared; /* * XXX assumes that the iospace ranges are sorted in increasing * order. */ rid = 0; port = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); if (!port) return (ENOMEM); bt_init_softc(dev, port, 0, 0); if (eisa_get_irq(dev) != -1) { shared = bt->level_trigger_ints ? RF_SHAREABLE : 0; rid = 0; irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, shared | RF_ACTIVE); if (!irq) { if (port) bus_release_resource(dev, SYS_RES_IOPORT, 0, port); return (ENOMEM); } } else irq = 0; bt->irq = irq; return (0); }