int isa_release_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; #ifdef PC98 /* * Indirection support. The type of bus_space_handle_t is * defined in sys/i386/include/bus_pc98.h. */ int i; bus_space_handle_t bh; if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { bh = rman_get_bushandle(r); if (bh != NULL) { for (i = 1; i < bh->bsh_ressz; i++) resource_list_release(rl, bus, child, type, rid + i, bh->bsh_res[i]); if (bh->bsh_res != NULL) free(bh->bsh_res, M_DEVBUF); } } #endif return resource_list_release(rl, bus, child, type, rid, r); }
struct resource * isa_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; int isdefault, passthrough, rids; isdefault = (start == 0UL && end == ~0UL) ? 1 : 0; passthrough = (device_get_parent(child) != bus) ? 1 : 0; if (!passthrough && !isdefault && resource_list_find(rl, type, *rid) == NULL) { switch (type) { case SYS_RES_IOPORT: rids = ISA_PNP_NPORT; break; case SYS_RES_IRQ: rids = ISA_PNP_NIRQ; break; case SYS_RES_MEMORY: rids = ISA_PNP_NMEM; break; default: rids = 0; break; } if (*rid < 0 || *rid >= rids) return (NULL); resource_list_add(rl, type, *rid, start, end, count); } return (resource_list_alloc(rl, bus, child, type, rid, start, end, count, flags)); }
int isa_release_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { int passthrough = (device_get_parent(child) != bus); struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; int error; if (type != SYS_RES_IRQ) return resource_list_release(rl, bus, child, type, rid, res); error = rman_release_resource(res); if (!passthrough && !error) { rle = resource_list_find(rl, SYS_RES_IRQ, rid); if (rle) rle->res = NULL; else error = ENOENT; } return error; }
int isa_release_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; return resource_list_release(rl, bus, child, type, rid, r); }
/* * This implementation simply passes the request up to the parent * bus, which in our case is the special i386 nexus, substituting any * configured values if the caller defaulted. We can get away with * this because there is no special mapping for ISA resources on an Intel * platform. When porting this code to another architecture, it may be * necessary to interpose a mapping layer here. */ struct resource * isa_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags, int cpuid) { /* * Consider adding a resource definition. We allow rid 0-1 for * irq and drq, 0-3 for memory and 0-7 for ports which is * sufficient for isapnp. */ int passthrough = (device_get_parent(child) != bus); int isdefault = (start == 0UL && end == ~0UL); struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; if (!passthrough && !isdefault) { rle = resource_list_find(rl, type, *rid); if (!rle) { if (*rid < 0) return 0; switch (type) { case SYS_RES_IRQ: if (*rid >= ISA_NIRQ) return 0; cpuid = machintr_legacy_intr_cpuid(start); break; case SYS_RES_DRQ: if (*rid >= ISA_NDRQ) return 0; break; case SYS_RES_MEMORY: if (*rid >= ISA_NMEM) return 0; break; case SYS_RES_IOPORT: if (*rid >= ISA_NPORT) return 0; break; default: return 0; } resource_list_add(rl, type, *rid, start, end, count, cpuid); } } return resource_list_alloc(rl, bus, child, type, rid, start, end, count, flags, cpuid); }
static int isa_match_resource_hint(device_t dev, int type, long value) { struct isa_device* idev = DEVTOISA(dev); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; STAILQ_FOREACH(rle, rl, link) { if (rle->type != type) continue; if (rle->start <= value && rle->end >= value) return (1); } return (0); }
/* * This implementation simply passes the request up to the parent * bus, which in our case is the special i386 nexus, substituting any * configured values if the caller defaulted. We can get away with * this because there is no special mapping for ISA resources on an Intel * platform. When porting this code to another architecture, it may be * necessary to interpose a mapping layer here. */ struct resource * isa_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { /* * Consider adding a resource definition. */ int passthrough = (device_get_parent(child) != bus); int isdefault = (start == 0UL && end == ~0UL); struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; if (!passthrough && !isdefault) { rle = resource_list_find(rl, type, *rid); if (!rle) { if (*rid < 0) return 0; switch (type) { case SYS_RES_IRQ: if (*rid >= ISA_NIRQ) return 0; break; case SYS_RES_DRQ: if (*rid >= ISA_NDRQ) return 0; break; case SYS_RES_MEMORY: if (*rid >= ISA_NMEM) return 0; break; case SYS_RES_IOPORT: if (*rid >= ISA_NPORT) return 0; break; default: return 0; } resource_list_add(rl, type, *rid, start, end, count); } } return resource_list_alloc(rl, bus, child, type, rid, start, end, count, flags); }
static void snc_isapnp_reconfig(device_t dev) { struct isa_device *idev = DEVTOISA(dev); struct isa_config config; u_long start, count; int rid; bzero(&config, sizeof(config)); for (rid = 0; rid < ISA_NMEM; rid++) { if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count)) break; config.ic_mem[rid].ir_start = start; config.ic_mem[rid].ir_end = start; config.ic_mem[rid].ir_size = count; } config.ic_nmem = rid; for (rid = 0; rid < ISA_NPORT; rid++) { if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count)) break; config.ic_port[rid].ir_start = start; config.ic_port[rid].ir_end = start; config.ic_port[rid].ir_size = count; } config.ic_nport = rid; for (rid = 0; rid < ISA_NIRQ; rid++) { if (bus_get_resource(dev, SYS_RES_IRQ, rid, &start, &count)) break; config.ic_irqmask[rid] = 1 << start; } config.ic_nirq = rid; for (rid = 0; rid < ISA_NDRQ; rid++) { if (bus_get_resource(dev, SYS_RES_DRQ, rid, &start, &count)) break; config.ic_drqmask[rid] = 1 << start; } config.ic_ndrq = rid; idev->id_config_cb(idev->id_config_arg, &config, 1); }
/* * 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; }
/* * This implementation simply passes the request up to the parent * bus, which in our case is the pci chipset device, substituting any * configured values if the caller defaulted. We can get away with * this because there is no special mapping for ISA resources on this * platform. When porting this code to another architecture, it may be * necessary to interpose a mapping layer here. * * We manage our own interrupt resources since ISA interrupts go through * the ISA PIC, not the PCI interrupt controller. */ struct resource * isa_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { /* * Consider adding a resource definition. We allow rid 0-1 for * irq and drq, 0-3 for memory and 0-7 for ports which is * sufficient for isapnp. */ int passthrough = (device_get_parent(child) != bus); int isdefault = (start == 0UL && end == ~0UL); struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; struct resource *res; if (!passthrough && !isdefault) { rle = resource_list_find(rl, type, *rid); if (!rle) { if (*rid < 0) return 0; switch (type) { case SYS_RES_IRQ: if (*rid >= ISA_NIRQ) return 0; break; case SYS_RES_DRQ: if (*rid >= ISA_NDRQ) return 0; break; case SYS_RES_MEMORY: if (*rid >= ISA_NMEM) return 0; break; case SYS_RES_IOPORT: if (*rid >= ISA_NPORT) return 0; break; default: return 0; } resource_list_add(rl, type, *rid, start, end, count); } } if (type != SYS_RES_IRQ && type != SYS_RES_DRQ) return resource_list_alloc(rl, bus, child, type, rid, start, end, count, flags); if (!passthrough) { rl = device_get_ivars(child); rle = resource_list_find(rl, type, *rid); if (!rle) return 0; if (rle->res) panic("isa_alloc_resource: resource entry is busy"); if (isdefault) { start = end = rle->start; count = 1; } } if (type == SYS_RES_IRQ) res = rman_reserve_resource(&isa_irq_rman, start, start, 1, 0, child); else res = rman_reserve_resource(&isa_drq_rman, start, start, 1, 0, child); if (res && !passthrough) { rle = resource_list_find(rl, type, *rid); rle->start = rman_get_start(res); rle->end = rman_get_end(res); rle->count = 1; rle->res = res; } return res; }
struct resource * isa_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { /* * Consider adding a resource definition. We allow rid 0-1 for * irq and drq, 0-3 for memory and 0-7 for ports which is * sufficient for isapnp. */ int passthrough = (device_get_parent(child) != bus); int isdefault = (start == 0UL && end == ~0UL); struct isa_device* idev = DEVTOISA(child); struct resource_list *rl = &idev->id_resources; struct resource_list_entry *rle; u_long base, limit; if (!passthrough && !isdefault) { rle = resource_list_find(rl, type, *rid); if (!rle) { if (*rid < 0) return 0; switch (type) { case SYS_RES_IRQ: if (*rid >= ISA_NIRQ) return 0; break; case SYS_RES_DRQ: if (*rid >= ISA_NDRQ) return 0; break; case SYS_RES_MEMORY: if (*rid >= ISA_NMEM) return 0; break; case SYS_RES_IOPORT: if (*rid >= ISA_NPORT) return 0; break; default: return 0; } resource_list_add(rl, type, *rid, start, end, count); } } /* * Add the base, change default allocations to be between base and * limit, and reject allocations if a resource type is not enabled. */ base = limit = 0; switch(type) { case SYS_RES_MEMORY: if (isa_mem_bt == NULL) return (NULL); base = isa_mem_base; limit = base + isa_mem_limit; break; case SYS_RES_IOPORT: if (isa_io_bt == NULL) return (NULL); base = isa_io_base; limit = base + isa_io_limit; break; case SYS_RES_IRQ: if (isdefault && passthrough) panic("isa_alloc_resource: cannot pass through default " "irq allocation"); if (!isdefault) { start = end = isa_route_intr_res(bus, start, end); if (start == 255) return (NULL); } break; default: panic("isa_alloc_resource: unsupported resource type %d", type); } if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { start = ulmin(start + base, limit); end = ulmin(end + base, limit); } /* * This inlines a modified resource_list_alloc(); this is needed * because the resources need to have offsets added to them, which * cannot be done beforehand without patching the resource list entries * (which is ugly). */ if (passthrough) { return (BUS_ALLOC_RESOURCE(device_get_parent(bus), child, type, rid, start, end, count, flags)); } rle = resource_list_find(rl, type, *rid); if (rle == NULL) return (NULL); /* no resource of that type/rid */ if (rle->res != NULL) panic("isa_alloc_resource: resource entry is busy"); if (isdefault) { start = rle->start; count = ulmax(count, rle->count); end = ulmax(rle->end, start + count - 1); switch (type) { case SYS_RES_MEMORY: case SYS_RES_IOPORT: start += base; end += base; if (!INRANGE(start, base, limit) || !INRANGE(end, base, limit)) return (NULL); break; case SYS_RES_IRQ: start = end = isa_route_intr_res(bus, start, end); if (start == 255) return (NULL); break; } } rle->res = BUS_ALLOC_RESOURCE(device_get_parent(bus), child, type, rid, start, end, count, flags); /* * Record the new range. */ if (rle->res != NULL) { rle->start = rman_get_start(rle->res) - base; rle->end = rman_get_end(rle->res) - base; rle->count = count; } return (rle->res); }