1a3be63b3SDoug Rabson /*- 2a3be63b3SDoug Rabson * Copyright (c) 1999 Doug Rabson 3a3be63b3SDoug Rabson * All rights reserved. 4a3be63b3SDoug Rabson * 5a3be63b3SDoug Rabson * Redistribution and use in source and binary forms, with or without 6a3be63b3SDoug Rabson * modification, are permitted provided that the following conditions 7a3be63b3SDoug Rabson * are met: 8a3be63b3SDoug Rabson * 1. Redistributions of source code must retain the above copyright 9a3be63b3SDoug Rabson * notice, this list of conditions and the following disclaimer. 10a3be63b3SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 11a3be63b3SDoug Rabson * notice, this list of conditions and the following disclaimer in the 12a3be63b3SDoug Rabson * documentation and/or other materials provided with the distribution. 13a3be63b3SDoug Rabson * 14a3be63b3SDoug Rabson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15a3be63b3SDoug Rabson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16a3be63b3SDoug Rabson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17a3be63b3SDoug Rabson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18a3be63b3SDoug Rabson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19a3be63b3SDoug Rabson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20a3be63b3SDoug Rabson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21a3be63b3SDoug Rabson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22a3be63b3SDoug Rabson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23a3be63b3SDoug Rabson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24a3be63b3SDoug Rabson * SUCH DAMAGE. 25a3be63b3SDoug Rabson * 26c3aac50fSPeter Wemm * $FreeBSD$ 27a3be63b3SDoug Rabson */ 28a3be63b3SDoug Rabson /* 29a3be63b3SDoug Rabson * Modifications for Intel architecture by Garrett A. Wollman. 30a3be63b3SDoug Rabson * Copyright 1998 Massachusetts Institute of Technology 31a3be63b3SDoug Rabson * 32a3be63b3SDoug Rabson * Permission to use, copy, modify, and distribute this software and 33a3be63b3SDoug Rabson * its documentation for any purpose and without fee is hereby 34a3be63b3SDoug Rabson * granted, provided that both the above copyright notice and this 35a3be63b3SDoug Rabson * permission notice appear in all copies, that both the above 36a3be63b3SDoug Rabson * copyright notice and this permission notice appear in all 37a3be63b3SDoug Rabson * supporting documentation, and that the name of M.I.T. not be used 38a3be63b3SDoug Rabson * in advertising or publicity pertaining to distribution of the 39a3be63b3SDoug Rabson * software without specific, written prior permission. M.I.T. makes 40a3be63b3SDoug Rabson * no representations about the suitability of this software for any 41a3be63b3SDoug Rabson * purpose. It is provided "as is" without express or implied 42a3be63b3SDoug Rabson * warranty. 43a3be63b3SDoug Rabson * 44a3be63b3SDoug Rabson * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 45a3be63b3SDoug Rabson * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 46a3be63b3SDoug Rabson * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 47a3be63b3SDoug Rabson * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 48a3be63b3SDoug Rabson * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 49a3be63b3SDoug Rabson * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 50a3be63b3SDoug Rabson * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 51a3be63b3SDoug Rabson * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 52a3be63b3SDoug Rabson * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 53a3be63b3SDoug Rabson * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 54a3be63b3SDoug Rabson * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 55a3be63b3SDoug Rabson * SUCH DAMAGE. 56a3be63b3SDoug Rabson */ 57a3be63b3SDoug Rabson 58a3be63b3SDoug Rabson /* 59a3be63b3SDoug Rabson * Parts of the ISA bus implementation common to all architectures. 60a3be63b3SDoug Rabson */ 61a3be63b3SDoug Rabson 62a3be63b3SDoug Rabson #include <sys/param.h> 63a3be63b3SDoug Rabson #include <sys/systm.h> 64a3be63b3SDoug Rabson #include <sys/kernel.h> 65a3be63b3SDoug Rabson #include <sys/bus.h> 66a3be63b3SDoug Rabson #include <sys/malloc.h> 67a3be63b3SDoug Rabson #include <sys/module.h> 68a3be63b3SDoug Rabson #include <machine/bus.h> 69a3be63b3SDoug Rabson #include <sys/rman.h> 70a3be63b3SDoug Rabson 71a3be63b3SDoug Rabson #include <machine/resource.h> 72a3be63b3SDoug Rabson 73a3be63b3SDoug Rabson #include <isa/isavar.h> 74a3be63b3SDoug Rabson #include <isa/isa_common.h> 75a3be63b3SDoug Rabson #ifdef __alpha__ /* XXX workaround a stupid warning */ 76a3be63b3SDoug Rabson #include <alpha/isa/isavar.h> 77a3be63b3SDoug Rabson #endif 78a3be63b3SDoug Rabson 792b2b44c9SJohn Baldwin static int isa_print_child(device_t bus, device_t dev); 802b2b44c9SJohn Baldwin 81959b7375SPoul-Henning Kamp static MALLOC_DEFINE(M_ISADEV, "isadev", "ISA device"); 82a3be63b3SDoug Rabson 83a3be63b3SDoug Rabson static devclass_t isa_devclass; 84ec22663bSDoug Rabson static int isa_running; 85a3be63b3SDoug Rabson 86a3be63b3SDoug Rabson /* 87a3be63b3SDoug Rabson * At 'probe' time, we add all the devices which we know about to the 88a3be63b3SDoug Rabson * bus. The generic attach routine will probe and attach them if they 89a3be63b3SDoug Rabson * are alive. 90a3be63b3SDoug Rabson */ 91a3be63b3SDoug Rabson static int 92a3be63b3SDoug Rabson isa_probe(device_t dev) 93a3be63b3SDoug Rabson { 94a3be63b3SDoug Rabson device_set_desc(dev, "ISA bus"); 95a3be63b3SDoug Rabson isa_init(); /* Allow machdep code to initialise */ 96ec22663bSDoug Rabson return 0; 97a3be63b3SDoug Rabson } 98a3be63b3SDoug Rabson 99a3be63b3SDoug Rabson extern device_t isa_bus_device; 100a3be63b3SDoug Rabson 101a3be63b3SDoug Rabson static int 102a3be63b3SDoug Rabson isa_attach(device_t dev) 103a3be63b3SDoug Rabson { 104a3be63b3SDoug Rabson /* 1054249382dSDoug Rabson * Arrange for isa_probe_children(dev) to be called later. XXX 106a3be63b3SDoug Rabson */ 107a3be63b3SDoug Rabson isa_bus_device = dev; 108a3be63b3SDoug Rabson return 0; 109a3be63b3SDoug Rabson } 110a3be63b3SDoug Rabson 111a3be63b3SDoug Rabson /* 1124249382dSDoug Rabson * Find a working set of memory regions for a child using the ranges 1134249382dSDoug Rabson * in *config and return the regions in *result. Returns non-zero if 1144249382dSDoug Rabson * a set of ranges was found. 1154249382dSDoug Rabson */ 1164249382dSDoug Rabson static int 1174249382dSDoug Rabson isa_find_memory(device_t child, 1184249382dSDoug Rabson struct isa_config *config, 1194249382dSDoug Rabson struct isa_config *result) 1204249382dSDoug Rabson { 1214249382dSDoug Rabson int success, i; 1224249382dSDoug Rabson struct resource *res[ISA_NMEM]; 1234249382dSDoug Rabson 1244249382dSDoug Rabson /* 1254249382dSDoug Rabson * First clear out any existing resource definitions. 1264249382dSDoug Rabson */ 1274249382dSDoug Rabson for (i = 0; i < ISA_NMEM; i++) { 12825afb89bSDoug Rabson bus_delete_resource(child, SYS_RES_MEMORY, i); 1294249382dSDoug Rabson res[i] = NULL; 1304249382dSDoug Rabson } 1314249382dSDoug Rabson 1324249382dSDoug Rabson success = 1; 1334249382dSDoug Rabson result->ic_nmem = config->ic_nmem; 1344249382dSDoug Rabson for (i = 0; i < config->ic_nmem; i++) { 1354249382dSDoug Rabson u_int32_t start, end, size, align; 1364249382dSDoug Rabson for (start = config->ic_mem[i].ir_start, 1374249382dSDoug Rabson end = config->ic_mem[i].ir_end, 1384249382dSDoug Rabson size = config->ic_mem[i].ir_size, 1394249382dSDoug Rabson align = config->ic_mem[i].ir_align; 1404249382dSDoug Rabson start + size - 1 <= end; 1414249382dSDoug Rabson start += align) { 14225afb89bSDoug Rabson bus_set_resource(child, SYS_RES_MEMORY, i, 1434249382dSDoug Rabson start, size); 1444249382dSDoug Rabson res[i] = bus_alloc_resource(child, 1454249382dSDoug Rabson SYS_RES_MEMORY, &i, 146208cc52fSMike Smith 0, ~0, 1, 0 /* !RF_ACTIVE */); 1474249382dSDoug Rabson if (res[i]) { 1484249382dSDoug Rabson result->ic_mem[i].ir_start = start; 1494249382dSDoug Rabson result->ic_mem[i].ir_end = start + size - 1; 1504249382dSDoug Rabson result->ic_mem[i].ir_size = size; 1514249382dSDoug Rabson result->ic_mem[i].ir_align = align; 1524249382dSDoug Rabson break; 1534249382dSDoug Rabson } 1544249382dSDoug Rabson } 1554249382dSDoug Rabson 1564249382dSDoug Rabson /* 1574249382dSDoug Rabson * If we didn't find a place for memory range i, then 1584249382dSDoug Rabson * give up now. 1594249382dSDoug Rabson */ 1604249382dSDoug Rabson if (!res[i]) { 1614249382dSDoug Rabson success = 0; 1624249382dSDoug Rabson break; 1634249382dSDoug Rabson } 1644249382dSDoug Rabson } 1654249382dSDoug Rabson 1664249382dSDoug Rabson for (i = 0; i < ISA_NMEM; i++) { 1674249382dSDoug Rabson if (res[i]) 1684249382dSDoug Rabson bus_release_resource(child, SYS_RES_MEMORY, 1694249382dSDoug Rabson i, res[i]); 1704249382dSDoug Rabson } 1714249382dSDoug Rabson 1724249382dSDoug Rabson return success; 1734249382dSDoug Rabson } 1744249382dSDoug Rabson 1754249382dSDoug Rabson /* 1764249382dSDoug Rabson * Find a working set of port regions for a child using the ranges 1774249382dSDoug Rabson * in *config and return the regions in *result. Returns non-zero if 1784249382dSDoug Rabson * a set of ranges was found. 1794249382dSDoug Rabson */ 1804249382dSDoug Rabson static int 1814249382dSDoug Rabson isa_find_port(device_t child, 1824249382dSDoug Rabson struct isa_config *config, 1834249382dSDoug Rabson struct isa_config *result) 1844249382dSDoug Rabson { 1854249382dSDoug Rabson int success, i; 1864249382dSDoug Rabson struct resource *res[ISA_NPORT]; 1874249382dSDoug Rabson 1884249382dSDoug Rabson /* 1894249382dSDoug Rabson * First clear out any existing resource definitions. 1904249382dSDoug Rabson */ 1914249382dSDoug Rabson for (i = 0; i < ISA_NPORT; i++) { 19225afb89bSDoug Rabson bus_delete_resource(child, SYS_RES_IOPORT, i); 1934249382dSDoug Rabson res[i] = NULL; 1944249382dSDoug Rabson } 1954249382dSDoug Rabson 1964249382dSDoug Rabson success = 1; 1974249382dSDoug Rabson result->ic_nport = config->ic_nport; 1984249382dSDoug Rabson for (i = 0; i < config->ic_nport; i++) { 1994249382dSDoug Rabson u_int32_t start, end, size, align; 2004249382dSDoug Rabson for (start = config->ic_port[i].ir_start, 2014249382dSDoug Rabson end = config->ic_port[i].ir_end, 2024249382dSDoug Rabson size = config->ic_port[i].ir_size, 2034249382dSDoug Rabson align = config->ic_port[i].ir_align; 2044249382dSDoug Rabson start + size - 1 <= end; 2054249382dSDoug Rabson start += align) { 20625afb89bSDoug Rabson bus_set_resource(child, SYS_RES_IOPORT, i, 2074249382dSDoug Rabson start, size); 2084249382dSDoug Rabson res[i] = bus_alloc_resource(child, 2094249382dSDoug Rabson SYS_RES_IOPORT, &i, 210208cc52fSMike Smith 0, ~0, 1, 0 /* !RF_ACTIVE */); 2114249382dSDoug Rabson if (res[i]) { 2124249382dSDoug Rabson result->ic_port[i].ir_start = start; 2134249382dSDoug Rabson result->ic_port[i].ir_end = start + size - 1; 2144249382dSDoug Rabson result->ic_port[i].ir_size = size; 2154249382dSDoug Rabson result->ic_port[i].ir_align = align; 2164249382dSDoug Rabson break; 2174249382dSDoug Rabson } 2184249382dSDoug Rabson } 2194249382dSDoug Rabson 2204249382dSDoug Rabson /* 2214249382dSDoug Rabson * If we didn't find a place for port range i, then 2224249382dSDoug Rabson * give up now. 2234249382dSDoug Rabson */ 2244249382dSDoug Rabson if (!res[i]) { 2254249382dSDoug Rabson success = 0; 2264249382dSDoug Rabson break; 2274249382dSDoug Rabson } 2284249382dSDoug Rabson } 2294249382dSDoug Rabson 2304249382dSDoug Rabson for (i = 0; i < ISA_NPORT; i++) { 2314249382dSDoug Rabson if (res[i]) 2324249382dSDoug Rabson bus_release_resource(child, SYS_RES_IOPORT, 2334249382dSDoug Rabson i, res[i]); 2344249382dSDoug Rabson } 2354249382dSDoug Rabson 2364249382dSDoug Rabson return success; 2374249382dSDoug Rabson } 2384249382dSDoug Rabson 2394249382dSDoug Rabson /* 2404249382dSDoug Rabson * Return the index of the first bit in the mask (or -1 if mask is empty. 2414249382dSDoug Rabson */ 2424249382dSDoug Rabson static int 2434249382dSDoug Rabson find_first_bit(u_int32_t mask) 2444249382dSDoug Rabson { 2454249382dSDoug Rabson return ffs(mask) - 1; 2464249382dSDoug Rabson } 2474249382dSDoug Rabson 2484249382dSDoug Rabson /* 2494249382dSDoug Rabson * Return the index of the next bit in the mask, or -1 if there are no more. 2504249382dSDoug Rabson */ 2514249382dSDoug Rabson static int 2524249382dSDoug Rabson find_next_bit(u_int32_t mask, int bit) 2534249382dSDoug Rabson { 2544249382dSDoug Rabson bit++; 2554249382dSDoug Rabson while (bit < 32 && !(mask & (1 << bit))) 2564249382dSDoug Rabson bit++; 2574249382dSDoug Rabson if (bit != 32) 2584249382dSDoug Rabson return bit; 2594249382dSDoug Rabson return -1; 2604249382dSDoug Rabson } 2614249382dSDoug Rabson 2624249382dSDoug Rabson /* 2634249382dSDoug Rabson * Find a working set of irqs for a child using the masks in *config 2644249382dSDoug Rabson * and return the regions in *result. Returns non-zero if a set of 2654249382dSDoug Rabson * irqs was found. 2664249382dSDoug Rabson */ 2674249382dSDoug Rabson static int 2684249382dSDoug Rabson isa_find_irq(device_t child, 2694249382dSDoug Rabson struct isa_config *config, 2704249382dSDoug Rabson struct isa_config *result) 2714249382dSDoug Rabson { 2724249382dSDoug Rabson int success, i; 2734249382dSDoug Rabson struct resource *res[ISA_NIRQ]; 2744249382dSDoug Rabson 2754249382dSDoug Rabson /* 2764249382dSDoug Rabson * First clear out any existing resource definitions. 2774249382dSDoug Rabson */ 2784249382dSDoug Rabson for (i = 0; i < ISA_NIRQ; i++) { 27925afb89bSDoug Rabson bus_delete_resource(child, SYS_RES_IRQ, i); 2804249382dSDoug Rabson res[i] = NULL; 2814249382dSDoug Rabson } 2824249382dSDoug Rabson 2834249382dSDoug Rabson success = 1; 2844249382dSDoug Rabson result->ic_nirq = config->ic_nirq; 2854249382dSDoug Rabson for (i = 0; i < config->ic_nirq; i++) { 2864249382dSDoug Rabson u_int32_t mask = config->ic_irqmask[i]; 2874249382dSDoug Rabson int irq; 2884249382dSDoug Rabson for (irq = find_first_bit(mask); 2894249382dSDoug Rabson irq != -1; 2904249382dSDoug Rabson irq = find_next_bit(mask, irq)) { 29125afb89bSDoug Rabson bus_set_resource(child, SYS_RES_IRQ, i, 2924249382dSDoug Rabson irq, 1); 2934249382dSDoug Rabson res[i] = bus_alloc_resource(child, 2944249382dSDoug Rabson SYS_RES_IRQ, &i, 295208cc52fSMike Smith 0, ~0, 1, 0 /* !RF_ACTIVE */ ); 2964249382dSDoug Rabson if (res[i]) { 2974249382dSDoug Rabson result->ic_irqmask[i] = (1 << irq); 2984249382dSDoug Rabson break; 2994249382dSDoug Rabson } 3004249382dSDoug Rabson } 3014249382dSDoug Rabson 3024249382dSDoug Rabson /* 3034249382dSDoug Rabson * If we didn't find a place for irq range i, then 3044249382dSDoug Rabson * give up now. 3054249382dSDoug Rabson */ 3064249382dSDoug Rabson if (!res[i]) { 3074249382dSDoug Rabson success = 0; 3084249382dSDoug Rabson break; 3094249382dSDoug Rabson } 3104249382dSDoug Rabson } 3114249382dSDoug Rabson 3124249382dSDoug Rabson for (i = 0; i < ISA_NIRQ; i++) { 3134249382dSDoug Rabson if (res[i]) 3144249382dSDoug Rabson bus_release_resource(child, SYS_RES_IRQ, 3154249382dSDoug Rabson i, res[i]); 3164249382dSDoug Rabson } 3174249382dSDoug Rabson 3184249382dSDoug Rabson return success; 3194249382dSDoug Rabson } 3204249382dSDoug Rabson 3214249382dSDoug Rabson /* 3224249382dSDoug Rabson * Find a working set of drqs for a child using the masks in *config 3234249382dSDoug Rabson * and return the regions in *result. Returns non-zero if a set of 3244249382dSDoug Rabson * drqs was found. 3254249382dSDoug Rabson */ 3264249382dSDoug Rabson static int 3274249382dSDoug Rabson isa_find_drq(device_t child, 3284249382dSDoug Rabson struct isa_config *config, 3294249382dSDoug Rabson struct isa_config *result) 3304249382dSDoug Rabson { 3314249382dSDoug Rabson int success, i; 3324249382dSDoug Rabson struct resource *res[ISA_NDRQ]; 3334249382dSDoug Rabson 3344249382dSDoug Rabson /* 3354249382dSDoug Rabson * First clear out any existing resource definitions. 3364249382dSDoug Rabson */ 3374249382dSDoug Rabson for (i = 0; i < ISA_NDRQ; i++) { 33825afb89bSDoug Rabson bus_delete_resource(child, SYS_RES_DRQ, i); 3394249382dSDoug Rabson res[i] = NULL; 3404249382dSDoug Rabson } 3414249382dSDoug Rabson 3424249382dSDoug Rabson success = 1; 3434249382dSDoug Rabson result->ic_ndrq = config->ic_ndrq; 3444249382dSDoug Rabson for (i = 0; i < config->ic_ndrq; i++) { 3454249382dSDoug Rabson u_int32_t mask = config->ic_drqmask[i]; 3464249382dSDoug Rabson int drq; 3474249382dSDoug Rabson for (drq = find_first_bit(mask); 3484249382dSDoug Rabson drq != -1; 3494249382dSDoug Rabson drq = find_next_bit(mask, drq)) { 35025afb89bSDoug Rabson bus_set_resource(child, SYS_RES_DRQ, i, 3514249382dSDoug Rabson drq, 1); 3524249382dSDoug Rabson res[i] = bus_alloc_resource(child, 3534249382dSDoug Rabson SYS_RES_DRQ, &i, 354208cc52fSMike Smith 0, ~0, 1, 0 /* !RF_ACTIVE */); 3554249382dSDoug Rabson if (res[i]) { 3564249382dSDoug Rabson result->ic_drqmask[i] = (1 << drq); 3574249382dSDoug Rabson break; 3584249382dSDoug Rabson } 3594249382dSDoug Rabson } 3604249382dSDoug Rabson 3614249382dSDoug Rabson /* 3624249382dSDoug Rabson * If we didn't find a place for drq range i, then 3634249382dSDoug Rabson * give up now. 3644249382dSDoug Rabson */ 3654249382dSDoug Rabson if (!res[i]) { 3664249382dSDoug Rabson success = 0; 3674249382dSDoug Rabson break; 3684249382dSDoug Rabson } 3694249382dSDoug Rabson } 3704249382dSDoug Rabson 3714249382dSDoug Rabson for (i = 0; i < ISA_NDRQ; i++) { 3724249382dSDoug Rabson if (res[i]) 3734249382dSDoug Rabson bus_release_resource(child, SYS_RES_DRQ, 3744249382dSDoug Rabson i, res[i]); 3754249382dSDoug Rabson } 3764249382dSDoug Rabson 3774249382dSDoug Rabson return success; 3784249382dSDoug Rabson } 3794249382dSDoug Rabson 3804249382dSDoug Rabson /* 3814249382dSDoug Rabson * Attempt to find a working set of resources for a device. Return 3824249382dSDoug Rabson * non-zero if a working configuration is found. 3834249382dSDoug Rabson */ 3844249382dSDoug Rabson static int 3854249382dSDoug Rabson isa_assign_resources(device_t child) 3864249382dSDoug Rabson { 3874249382dSDoug Rabson struct isa_device *idev = DEVTOISA(child); 3884249382dSDoug Rabson struct isa_config_entry *ice; 3893b82ede0SJulian Elischer struct isa_config *cfg; 3904249382dSDoug Rabson 3913b82ede0SJulian Elischer cfg = malloc(sizeof(struct isa_config), M_TEMP, M_NOWAIT|M_ZERO); 3923b82ede0SJulian Elischer if (cfg == NULL) 3933b82ede0SJulian Elischer return(0); 3944249382dSDoug Rabson TAILQ_FOREACH(ice, &idev->id_configs, ice_link) { 3953b82ede0SJulian Elischer if (!isa_find_memory(child, &ice->ice_config, cfg)) 3964249382dSDoug Rabson continue; 3973b82ede0SJulian Elischer if (!isa_find_port(child, &ice->ice_config, cfg)) 3984249382dSDoug Rabson continue; 3993b82ede0SJulian Elischer if (!isa_find_irq(child, &ice->ice_config, cfg)) 4004249382dSDoug Rabson continue; 4013b82ede0SJulian Elischer if (!isa_find_drq(child, &ice->ice_config, cfg)) 4024249382dSDoug Rabson continue; 4034249382dSDoug Rabson 4044249382dSDoug Rabson /* 4054249382dSDoug Rabson * A working configuration was found enable the device 4064249382dSDoug Rabson * with this configuration. 4074249382dSDoug Rabson */ 4084249382dSDoug Rabson if (idev->id_config_cb) { 4094249382dSDoug Rabson idev->id_config_cb(idev->id_config_arg, 4103b82ede0SJulian Elischer cfg, 1); 4113b82ede0SJulian Elischer free(cfg, M_TEMP); 4124249382dSDoug Rabson return 1; 4134249382dSDoug Rabson } 4144249382dSDoug Rabson } 4154249382dSDoug Rabson 4164249382dSDoug Rabson /* 4174249382dSDoug Rabson * Disable the device. 4184249382dSDoug Rabson */ 4192b2b44c9SJohn Baldwin bus_print_child_header(device_get_parent(child), child); 4202b2b44c9SJohn Baldwin printf(" can't assign resources\n"); 4212b2b44c9SJohn Baldwin if (bootverbose) 4222b2b44c9SJohn Baldwin isa_print_child(device_get_parent(child), child); 4233b82ede0SJulian Elischer bzero(cfg, sizeof (*cfg)); 4244249382dSDoug Rabson if (idev->id_config_cb) 4253b82ede0SJulian Elischer idev->id_config_cb(idev->id_config_arg, cfg, 0); 4264249382dSDoug Rabson device_disable(child); 4274249382dSDoug Rabson 4283b82ede0SJulian Elischer free(cfg, M_TEMP); 4294249382dSDoug Rabson return 0; 4304249382dSDoug Rabson } 4314249382dSDoug Rabson 4324249382dSDoug Rabson /* 4334249382dSDoug Rabson * Called after other devices have initialised to probe for isa devices. 4344249382dSDoug Rabson */ 4354249382dSDoug Rabson void 4364249382dSDoug Rabson isa_probe_children(device_t dev) 4374249382dSDoug Rabson { 4384249382dSDoug Rabson device_t *children; 4393b82ede0SJulian Elischer struct isa_config *cfg; 4404249382dSDoug Rabson int nchildren, i; 4414249382dSDoug Rabson 442ec22663bSDoug Rabson /* 443ec22663bSDoug Rabson * Create all the children by calling driver's identify methods. 444ec22663bSDoug Rabson */ 445ec22663bSDoug Rabson bus_generic_probe(dev); 446ec22663bSDoug Rabson 4474249382dSDoug Rabson if (device_get_children(dev, &children, &nchildren)) 4484249382dSDoug Rabson return; 4494249382dSDoug Rabson 4504249382dSDoug Rabson /* 451a2e6dbb3SDoug Rabson * First disable all pnp devices so that they don't get 452a2e6dbb3SDoug Rabson * matched by legacy probes. 453a2e6dbb3SDoug Rabson */ 454ec22663bSDoug Rabson if (bootverbose) 455ec22663bSDoug Rabson printf("isa_probe_children: disabling PnP devices\n"); 4563b82ede0SJulian Elischer 4573b82ede0SJulian Elischer cfg = malloc(sizeof(*cfg), M_TEMP, M_NOWAIT|M_ZERO); 4583b82ede0SJulian Elischer if (cfg == NULL) { 4593b82ede0SJulian Elischer free(children, M_TEMP); 4603b82ede0SJulian Elischer return; 4613b82ede0SJulian Elischer } 4623b82ede0SJulian Elischer 463a2e6dbb3SDoug Rabson for (i = 0; i < nchildren; i++) { 464a2e6dbb3SDoug Rabson device_t child = children[i]; 465a2e6dbb3SDoug Rabson struct isa_device *idev = DEVTOISA(child); 466a2e6dbb3SDoug Rabson 4673b82ede0SJulian Elischer bzero(cfg, sizeof(*cfg)); 468a2e6dbb3SDoug Rabson if (idev->id_config_cb) 4693b82ede0SJulian Elischer idev->id_config_cb(idev->id_config_arg, cfg, 0); 470a2e6dbb3SDoug Rabson } 471a2e6dbb3SDoug Rabson 4723b82ede0SJulian Elischer free(cfg, M_TEMP); 4733b82ede0SJulian Elischer 474a2e6dbb3SDoug Rabson /* 475a2e6dbb3SDoug Rabson * Next probe all non-pnp devices so that they claim their 4764249382dSDoug Rabson * resources first. 4774249382dSDoug Rabson */ 478ec22663bSDoug Rabson if (bootverbose) 479ec22663bSDoug Rabson printf("isa_probe_children: probing non-PnP devices\n"); 4804249382dSDoug Rabson for (i = 0; i < nchildren; i++) { 4814249382dSDoug Rabson device_t child = children[i]; 4824249382dSDoug Rabson struct isa_device *idev = DEVTOISA(child); 4834249382dSDoug Rabson 4844249382dSDoug Rabson if (TAILQ_FIRST(&idev->id_configs)) 4854249382dSDoug Rabson continue; 4864249382dSDoug Rabson 4874249382dSDoug Rabson device_probe_and_attach(child); 4884249382dSDoug Rabson } 4894249382dSDoug Rabson 4904249382dSDoug Rabson /* 491a2e6dbb3SDoug Rabson * Finally assign resource to pnp devices and probe them. 4924249382dSDoug Rabson */ 493ec22663bSDoug Rabson if (bootverbose) 494ec22663bSDoug Rabson printf("isa_probe_children: probing PnP devices\n"); 4954249382dSDoug Rabson for (i = 0; i < nchildren; i++) { 4964249382dSDoug Rabson device_t child = children[i]; 4974249382dSDoug Rabson struct isa_device* idev = DEVTOISA(child); 4984249382dSDoug Rabson 4994249382dSDoug Rabson if (!TAILQ_FIRST(&idev->id_configs)) 5004249382dSDoug Rabson continue; 5014249382dSDoug Rabson 5024249382dSDoug Rabson if (isa_assign_resources(child)) { 50325afb89bSDoug Rabson struct resource_list *rl = &idev->id_resources; 5044249382dSDoug Rabson struct resource_list_entry *rle; 5054249382dSDoug Rabson 5064249382dSDoug Rabson device_probe_and_attach(child); 5074249382dSDoug Rabson 5084249382dSDoug Rabson /* 5094249382dSDoug Rabson * Claim any unallocated resources to keep other 5104249382dSDoug Rabson * devices from using them. 5114249382dSDoug Rabson */ 51225afb89bSDoug Rabson SLIST_FOREACH(rle, rl, link) { 5134249382dSDoug Rabson if (!rle->res) { 5144249382dSDoug Rabson int rid = rle->rid; 51525afb89bSDoug Rabson resource_list_alloc(rl, dev, child, 5164249382dSDoug Rabson rle->type, 5174249382dSDoug Rabson &rid, 518328d36e9SDoug Rabson 0, ~0, 1, 0); 5194249382dSDoug Rabson } 5204249382dSDoug Rabson } 5214249382dSDoug Rabson } 5224249382dSDoug Rabson } 5234249382dSDoug Rabson 5244249382dSDoug Rabson free(children, M_TEMP); 525ec22663bSDoug Rabson 526ec22663bSDoug Rabson isa_running = 1; 5274249382dSDoug Rabson } 5284249382dSDoug Rabson 5294249382dSDoug Rabson /* 530a3be63b3SDoug Rabson * Add a new child with default ivars. 531a3be63b3SDoug Rabson */ 532a3be63b3SDoug Rabson static device_t 533bea6af4dSDoug Rabson isa_add_child(device_t dev, int order, const char *name, int unit) 534a3be63b3SDoug Rabson { 535fe0d4089SMatthew N. Dodd device_t child; 536a3be63b3SDoug Rabson struct isa_device *idev; 537a3be63b3SDoug Rabson 5387cc0979fSDavid Malone idev = malloc(sizeof(struct isa_device), M_ISADEV, M_NOWAIT | M_ZERO); 539a3be63b3SDoug Rabson if (!idev) 540a3be63b3SDoug Rabson return 0; 541a3be63b3SDoug Rabson 542a3be63b3SDoug Rabson resource_list_init(&idev->id_resources); 5434249382dSDoug Rabson TAILQ_INIT(&idev->id_configs); 544a3be63b3SDoug Rabson 545fe0d4089SMatthew N. Dodd child = device_add_child_ordered(dev, order, name, unit); 546fe0d4089SMatthew N. Dodd device_set_ivars(child, idev); 547fe0d4089SMatthew N. Dodd 548fe0d4089SMatthew N. Dodd return child; 549a3be63b3SDoug Rabson } 550a3be63b3SDoug Rabson 551328d36e9SDoug Rabson static int 552a3be63b3SDoug Rabson isa_print_resources(struct resource_list *rl, const char *name, int type, 55325afb89bSDoug Rabson int count, const char *format) 554a3be63b3SDoug Rabson { 5554249382dSDoug Rabson struct resource_list_entry *rle; 5564249382dSDoug Rabson int printed; 557328d36e9SDoug Rabson int i, retval = 0;; 558a3be63b3SDoug Rabson 5594249382dSDoug Rabson printed = 0; 56025afb89bSDoug Rabson for (i = 0; i < count; i++) { 5614249382dSDoug Rabson rle = resource_list_find(rl, type, i); 5624249382dSDoug Rabson if (rle) { 5634249382dSDoug Rabson if (printed == 0) 564328d36e9SDoug Rabson retval += printf(" %s ", name); 5654249382dSDoug Rabson else if (printed > 0) 566328d36e9SDoug Rabson retval += printf(","); 5674249382dSDoug Rabson printed++; 568328d36e9SDoug Rabson retval += printf(format, rle->start); 5694249382dSDoug Rabson if (rle->count > 1) { 570328d36e9SDoug Rabson retval += printf("-"); 571328d36e9SDoug Rabson retval += printf(format, 572328d36e9SDoug Rabson rle->start + rle->count - 1); 573a3be63b3SDoug Rabson } 5744249382dSDoug Rabson } else if (i > 3) { 5754249382dSDoug Rabson /* check the first few regardless */ 5764249382dSDoug Rabson break; 577a3be63b3SDoug Rabson } 578a3be63b3SDoug Rabson } 579328d36e9SDoug Rabson return retval; 580a3be63b3SDoug Rabson } 581a3be63b3SDoug Rabson 58215317dd8SMatthew N. Dodd static int 583328d36e9SDoug Rabson isa_print_all_resources(device_t dev) 584a3be63b3SDoug Rabson { 585a3be63b3SDoug Rabson struct isa_device *idev = DEVTOISA(dev); 586a3be63b3SDoug Rabson struct resource_list *rl = &idev->id_resources; 58715317dd8SMatthew N. Dodd int retval = 0; 58815317dd8SMatthew N. Dodd 589062acdb7SDoug Rabson if (SLIST_FIRST(rl) || device_get_flags(dev)) 59015317dd8SMatthew N. Dodd retval += printf(" at"); 591a3be63b3SDoug Rabson 592328d36e9SDoug Rabson retval += isa_print_resources(rl, "port", SYS_RES_IOPORT, 593328d36e9SDoug Rabson ISA_NPORT, "%#lx"); 594328d36e9SDoug Rabson retval += isa_print_resources(rl, "iomem", SYS_RES_MEMORY, 595328d36e9SDoug Rabson ISA_NMEM, "%#lx"); 596328d36e9SDoug Rabson retval += isa_print_resources(rl, "irq", SYS_RES_IRQ, 597328d36e9SDoug Rabson ISA_NIRQ, "%ld"); 598328d36e9SDoug Rabson retval += isa_print_resources(rl, "drq", SYS_RES_DRQ, 599328d36e9SDoug Rabson ISA_NDRQ, "%ld"); 600062acdb7SDoug Rabson if (device_get_flags(dev)) 601062acdb7SDoug Rabson retval += printf(" flags %#x", device_get_flags(dev)); 602a3be63b3SDoug Rabson 603328d36e9SDoug Rabson return retval; 604328d36e9SDoug Rabson } 605328d36e9SDoug Rabson 606328d36e9SDoug Rabson static int 607328d36e9SDoug Rabson isa_print_child(device_t bus, device_t dev) 608328d36e9SDoug Rabson { 609328d36e9SDoug Rabson int retval = 0; 610328d36e9SDoug Rabson 611328d36e9SDoug Rabson retval += bus_print_child_header(bus, dev); 612328d36e9SDoug Rabson retval += isa_print_all_resources(dev); 61315317dd8SMatthew N. Dodd retval += bus_print_child_footer(bus, dev); 61415317dd8SMatthew N. Dodd 61515317dd8SMatthew N. Dodd return (retval); 616a3be63b3SDoug Rabson } 617a3be63b3SDoug Rabson 618328d36e9SDoug Rabson static void 619328d36e9SDoug Rabson isa_probe_nomatch(device_t dev, device_t child) 620328d36e9SDoug Rabson { 6212b2b44c9SJohn Baldwin if (bootverbose) { 6222b2b44c9SJohn Baldwin bus_print_child_header(dev, child); 6232b2b44c9SJohn Baldwin printf(" failed to probe"); 624328d36e9SDoug Rabson isa_print_all_resources(child); 6252b2b44c9SJohn Baldwin bus_print_child_footer(dev, child); 6262b2b44c9SJohn Baldwin } 627328d36e9SDoug Rabson 628328d36e9SDoug Rabson return; 629328d36e9SDoug Rabson } 630328d36e9SDoug Rabson 631a3be63b3SDoug Rabson static int 632a3be63b3SDoug Rabson isa_read_ivar(device_t bus, device_t dev, int index, uintptr_t * result) 633a3be63b3SDoug Rabson { 634a3be63b3SDoug Rabson struct isa_device* idev = DEVTOISA(dev); 635a3be63b3SDoug Rabson struct resource_list *rl = &idev->id_resources; 636a3be63b3SDoug Rabson struct resource_list_entry *rle; 637a3be63b3SDoug Rabson 638a3be63b3SDoug Rabson switch (index) { 639a3be63b3SDoug Rabson case ISA_IVAR_PORT_0: 640a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_IOPORT, 0); 641a3be63b3SDoug Rabson if (rle) 642a3be63b3SDoug Rabson *result = rle->start; 643a3be63b3SDoug Rabson else 644a3be63b3SDoug Rabson *result = -1; 645a3be63b3SDoug Rabson break; 646a3be63b3SDoug Rabson 647a3be63b3SDoug Rabson case ISA_IVAR_PORT_1: 648a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_IOPORT, 1); 649a3be63b3SDoug Rabson if (rle) 650a3be63b3SDoug Rabson *result = rle->start; 651a3be63b3SDoug Rabson else 652a3be63b3SDoug Rabson *result = -1; 653a3be63b3SDoug Rabson break; 654a3be63b3SDoug Rabson 655a3be63b3SDoug Rabson case ISA_IVAR_PORTSIZE_0: 656a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_IOPORT, 0); 657a3be63b3SDoug Rabson if (rle) 658a3be63b3SDoug Rabson *result = rle->count; 659a3be63b3SDoug Rabson else 660a3be63b3SDoug Rabson *result = 0; 661a3be63b3SDoug Rabson break; 662a3be63b3SDoug Rabson 663a3be63b3SDoug Rabson case ISA_IVAR_PORTSIZE_1: 664a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_IOPORT, 1); 665a3be63b3SDoug Rabson if (rle) 666a3be63b3SDoug Rabson *result = rle->count; 667a3be63b3SDoug Rabson else 668a3be63b3SDoug Rabson *result = 0; 669a3be63b3SDoug Rabson break; 670a3be63b3SDoug Rabson 671a3be63b3SDoug Rabson case ISA_IVAR_MADDR_0: 672a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_MEMORY, 0); 673a3be63b3SDoug Rabson if (rle) 674a3be63b3SDoug Rabson *result = rle->start; 675a3be63b3SDoug Rabson else 676a3be63b3SDoug Rabson *result = -1; 677a3be63b3SDoug Rabson break; 678a3be63b3SDoug Rabson 679a3be63b3SDoug Rabson case ISA_IVAR_MADDR_1: 680a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_MEMORY, 1); 681a3be63b3SDoug Rabson if (rle) 682a3be63b3SDoug Rabson *result = rle->start; 683a3be63b3SDoug Rabson else 684a3be63b3SDoug Rabson *result = -1; 685a3be63b3SDoug Rabson break; 686a3be63b3SDoug Rabson 687a3be63b3SDoug Rabson case ISA_IVAR_MSIZE_0: 688a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_MEMORY, 0); 689a3be63b3SDoug Rabson if (rle) 690a3be63b3SDoug Rabson *result = rle->count; 691a3be63b3SDoug Rabson else 692a3be63b3SDoug Rabson *result = 0; 693a3be63b3SDoug Rabson break; 694a3be63b3SDoug Rabson 695a3be63b3SDoug Rabson case ISA_IVAR_MSIZE_1: 696a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_MEMORY, 1); 697a3be63b3SDoug Rabson if (rle) 698a3be63b3SDoug Rabson *result = rle->count; 699a3be63b3SDoug Rabson else 700a3be63b3SDoug Rabson *result = 0; 701a3be63b3SDoug Rabson break; 702a3be63b3SDoug Rabson 703a3be63b3SDoug Rabson case ISA_IVAR_IRQ_0: 704a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_IRQ, 0); 705a3be63b3SDoug Rabson if (rle) 706a3be63b3SDoug Rabson *result = rle->start; 707a3be63b3SDoug Rabson else 708a3be63b3SDoug Rabson *result = -1; 709a3be63b3SDoug Rabson break; 710a3be63b3SDoug Rabson 711a3be63b3SDoug Rabson case ISA_IVAR_IRQ_1: 712a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_IRQ, 1); 713a3be63b3SDoug Rabson if (rle) 714a3be63b3SDoug Rabson *result = rle->start; 715a3be63b3SDoug Rabson else 716a3be63b3SDoug Rabson *result = -1; 717a3be63b3SDoug Rabson break; 718a3be63b3SDoug Rabson 719a3be63b3SDoug Rabson case ISA_IVAR_DRQ_0: 720a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_DRQ, 0); 721a3be63b3SDoug Rabson if (rle) 722a3be63b3SDoug Rabson *result = rle->start; 723a3be63b3SDoug Rabson else 724a3be63b3SDoug Rabson *result = -1; 725a3be63b3SDoug Rabson break; 726a3be63b3SDoug Rabson 727a3be63b3SDoug Rabson case ISA_IVAR_DRQ_1: 728a3be63b3SDoug Rabson rle = resource_list_find(rl, SYS_RES_DRQ, 1); 729a3be63b3SDoug Rabson if (rle) 730a3be63b3SDoug Rabson *result = rle->start; 731a3be63b3SDoug Rabson else 732a3be63b3SDoug Rabson *result = -1; 733a3be63b3SDoug Rabson break; 734a3be63b3SDoug Rabson 735cfa84f46SDoug Rabson case ISA_IVAR_VENDORID: 736cfa84f46SDoug Rabson *result = idev->id_vendorid; 737cfa84f46SDoug Rabson break; 738cfa84f46SDoug Rabson 739cfa84f46SDoug Rabson case ISA_IVAR_SERIAL: 740cfa84f46SDoug Rabson *result = idev->id_serial; 741cfa84f46SDoug Rabson break; 742cfa84f46SDoug Rabson 743cfa84f46SDoug Rabson case ISA_IVAR_LOGICALID: 744cfa84f46SDoug Rabson *result = idev->id_logicalid; 745cfa84f46SDoug Rabson break; 746cfa84f46SDoug Rabson 747cfa84f46SDoug Rabson case ISA_IVAR_COMPATID: 748cfa84f46SDoug Rabson *result = idev->id_compatid; 749cfa84f46SDoug Rabson break; 750cfa84f46SDoug Rabson 751cfa84f46SDoug Rabson default: 752a3be63b3SDoug Rabson return ENOENT; 753a3be63b3SDoug Rabson } 754a3be63b3SDoug Rabson 755cfa84f46SDoug Rabson return 0; 756cfa84f46SDoug Rabson } 757cfa84f46SDoug Rabson 758a3be63b3SDoug Rabson static int 759a3be63b3SDoug Rabson isa_write_ivar(device_t bus, device_t dev, 760a3be63b3SDoug Rabson int index, uintptr_t value) 761a3be63b3SDoug Rabson { 762a3be63b3SDoug Rabson struct isa_device* idev = DEVTOISA(dev); 763a3be63b3SDoug Rabson 764a3be63b3SDoug Rabson switch (index) { 765a3be63b3SDoug Rabson case ISA_IVAR_PORT_0: 766a3be63b3SDoug Rabson case ISA_IVAR_PORT_1: 767a3be63b3SDoug Rabson case ISA_IVAR_PORTSIZE_0: 768a3be63b3SDoug Rabson case ISA_IVAR_PORTSIZE_1: 769a3be63b3SDoug Rabson case ISA_IVAR_MADDR_0: 770a3be63b3SDoug Rabson case ISA_IVAR_MADDR_1: 771a3be63b3SDoug Rabson case ISA_IVAR_MSIZE_0: 772a3be63b3SDoug Rabson case ISA_IVAR_MSIZE_1: 773a3be63b3SDoug Rabson case ISA_IVAR_IRQ_0: 774a3be63b3SDoug Rabson case ISA_IVAR_IRQ_1: 775a3be63b3SDoug Rabson case ISA_IVAR_DRQ_0: 776a3be63b3SDoug Rabson case ISA_IVAR_DRQ_1: 777a3be63b3SDoug Rabson return EINVAL; 778a3be63b3SDoug Rabson 779cfa84f46SDoug Rabson case ISA_IVAR_VENDORID: 780cfa84f46SDoug Rabson idev->id_vendorid = value; 781cfa84f46SDoug Rabson break; 782cfa84f46SDoug Rabson 783cfa84f46SDoug Rabson case ISA_IVAR_SERIAL: 784cfa84f46SDoug Rabson idev->id_serial = value; 785cfa84f46SDoug Rabson break; 786cfa84f46SDoug Rabson 787cfa84f46SDoug Rabson case ISA_IVAR_LOGICALID: 788cfa84f46SDoug Rabson idev->id_logicalid = value; 789cfa84f46SDoug Rabson break; 790cfa84f46SDoug Rabson 791cfa84f46SDoug Rabson case ISA_IVAR_COMPATID: 792cfa84f46SDoug Rabson idev->id_compatid = value; 793cfa84f46SDoug Rabson break; 794cfa84f46SDoug Rabson 795a3be63b3SDoug Rabson default: 796a3be63b3SDoug Rabson return (ENOENT); 797a3be63b3SDoug Rabson } 798cfa84f46SDoug Rabson 799a3be63b3SDoug Rabson return (0); 800a3be63b3SDoug Rabson } 801a3be63b3SDoug Rabson 8024249382dSDoug Rabson /* 8034249382dSDoug Rabson * Free any resources which the driver missed or which we were holding for 8044249382dSDoug Rabson * it (see isa_probe_children). 8054249382dSDoug Rabson */ 8064249382dSDoug Rabson static void 8074249382dSDoug Rabson isa_child_detached(device_t dev, device_t child) 8084249382dSDoug Rabson { 8094249382dSDoug Rabson struct isa_device* idev = DEVTOISA(child); 81025afb89bSDoug Rabson struct resource_list *rl = &idev->id_resources; 8114249382dSDoug Rabson struct resource_list_entry *rle; 8124249382dSDoug Rabson 813328d36e9SDoug Rabson if (TAILQ_FIRST(&idev->id_configs)) { 814328d36e9SDoug Rabson /* 815328d36e9SDoug Rabson * Claim any unallocated resources to keep other 816328d36e9SDoug Rabson * devices from using them. 817328d36e9SDoug Rabson */ 818328d36e9SDoug Rabson SLIST_FOREACH(rle, rl, link) { 819328d36e9SDoug Rabson if (!rle->res) { 820328d36e9SDoug Rabson int rid = rle->rid; 821328d36e9SDoug Rabson resource_list_alloc(rl, dev, child, 8224249382dSDoug Rabson rle->type, 823328d36e9SDoug Rabson &rid, 0, ~0, 1, 0); 824328d36e9SDoug Rabson } 825328d36e9SDoug Rabson } 8264249382dSDoug Rabson } 8274249382dSDoug Rabson } 8284249382dSDoug Rabson 829ec22663bSDoug Rabson static void 830ec22663bSDoug Rabson isa_driver_added(device_t dev, driver_t *driver) 831ec22663bSDoug Rabson { 832ec22663bSDoug Rabson device_t *children; 833ec22663bSDoug Rabson int nchildren, i; 834ec22663bSDoug Rabson 835ec22663bSDoug Rabson /* 836ec22663bSDoug Rabson * Don't do anything if drivers are dynamically 837ec22663bSDoug Rabson * added during autoconfiguration (cf. ymf724). 838ec22663bSDoug Rabson * since that would end up calling identify 839ec22663bSDoug Rabson * twice. 840ec22663bSDoug Rabson */ 841ec22663bSDoug Rabson if (!isa_running) 842ec22663bSDoug Rabson return; 843ec22663bSDoug Rabson 844ec22663bSDoug Rabson DEVICE_IDENTIFY(driver, dev); 845ec22663bSDoug Rabson if (device_get_children(dev, &children, &nchildren)) 846ec22663bSDoug Rabson return; 847ec22663bSDoug Rabson 848ec22663bSDoug Rabson for (i = 0; i < nchildren; i++) { 849ec22663bSDoug Rabson device_t child = children[i]; 850ec22663bSDoug Rabson struct isa_device *idev = DEVTOISA(child); 851ec22663bSDoug Rabson struct resource_list *rl = &idev->id_resources; 852ec22663bSDoug Rabson struct resource_list_entry *rle; 853ec22663bSDoug Rabson 854ec22663bSDoug Rabson if (device_get_state(child) != DS_NOTPRESENT) 855ec22663bSDoug Rabson continue; 856328d36e9SDoug Rabson if (!device_is_enabled(child)) 857328d36e9SDoug Rabson continue; 858328d36e9SDoug Rabson 859328d36e9SDoug Rabson /* 860328d36e9SDoug Rabson * Free resources which we were holding on behalf of 861328d36e9SDoug Rabson * the device. 862328d36e9SDoug Rabson */ 863328d36e9SDoug Rabson SLIST_FOREACH(rle, &idev->id_resources, link) { 864328d36e9SDoug Rabson if (rle->res) 865328d36e9SDoug Rabson resource_list_release(rl, dev, child, 866328d36e9SDoug Rabson rle->type, 867328d36e9SDoug Rabson rle->rid, 868328d36e9SDoug Rabson rle->res); 869328d36e9SDoug Rabson } 870ec22663bSDoug Rabson 871ec22663bSDoug Rabson if (TAILQ_FIRST(&idev->id_configs)) 872ec22663bSDoug Rabson if (!isa_assign_resources(child)) 873ec22663bSDoug Rabson continue; 874ec22663bSDoug Rabson 875ec22663bSDoug Rabson device_probe_and_attach(child); 876ec22663bSDoug Rabson 877ec22663bSDoug Rabson if (TAILQ_FIRST(&idev->id_configs)) { 878ec22663bSDoug Rabson /* 879ec22663bSDoug Rabson * Claim any unallocated resources to keep other 880ec22663bSDoug Rabson * devices from using them. 881ec22663bSDoug Rabson */ 882ec22663bSDoug Rabson SLIST_FOREACH(rle, rl, link) { 883ec22663bSDoug Rabson if (!rle->res) { 884ec22663bSDoug Rabson int rid = rle->rid; 885ec22663bSDoug Rabson resource_list_alloc(rl, dev, child, 886ec22663bSDoug Rabson rle->type, 887328d36e9SDoug Rabson &rid, 0, ~0, 1, 0); 888ec22663bSDoug Rabson } 889ec22663bSDoug Rabson } 890ec22663bSDoug Rabson } 891ec22663bSDoug Rabson } 892ec22663bSDoug Rabson 893ec22663bSDoug Rabson free(children, M_TEMP); 894ec22663bSDoug Rabson } 895ec22663bSDoug Rabson 896a3be63b3SDoug Rabson static int 897a3be63b3SDoug Rabson isa_set_resource(device_t dev, device_t child, int type, int rid, 898a3be63b3SDoug Rabson u_long start, u_long count) 899a3be63b3SDoug Rabson { 900a3be63b3SDoug Rabson struct isa_device* idev = DEVTOISA(child); 901a3be63b3SDoug Rabson struct resource_list *rl = &idev->id_resources; 902a3be63b3SDoug Rabson 903a3be63b3SDoug Rabson if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY 904a3be63b3SDoug Rabson && type != SYS_RES_IRQ && type != SYS_RES_DRQ) 905a3be63b3SDoug Rabson return EINVAL; 9064249382dSDoug Rabson if (rid < 0) 9074249382dSDoug Rabson return EINVAL; 9084249382dSDoug Rabson if (type == SYS_RES_IOPORT && rid >= ISA_NPORT) 9094249382dSDoug Rabson return EINVAL; 9104249382dSDoug Rabson if (type == SYS_RES_MEMORY && rid >= ISA_NMEM) 9114249382dSDoug Rabson return EINVAL; 9124249382dSDoug Rabson if (type == SYS_RES_IRQ && rid >= ISA_NIRQ) 9134249382dSDoug Rabson return EINVAL; 9144249382dSDoug Rabson if (type == SYS_RES_DRQ && rid >= ISA_NDRQ) 915a3be63b3SDoug Rabson return EINVAL; 916a3be63b3SDoug Rabson 917a3be63b3SDoug Rabson resource_list_add(rl, type, rid, start, start + count - 1, count); 918a3be63b3SDoug Rabson 919a3be63b3SDoug Rabson return 0; 920a3be63b3SDoug Rabson } 921a3be63b3SDoug Rabson 9221581afb3SMatthew N. Dodd static struct resource_list * 9231581afb3SMatthew N. Dodd isa_get_resource_list (device_t dev, device_t child) 924a3be63b3SDoug Rabson { 925a3be63b3SDoug Rabson struct isa_device* idev = DEVTOISA(child); 926a3be63b3SDoug Rabson struct resource_list *rl = &idev->id_resources; 927a3be63b3SDoug Rabson 9281581afb3SMatthew N. Dodd if (!rl) 9291581afb3SMatthew N. Dodd return (NULL); 930a3be63b3SDoug Rabson 9311581afb3SMatthew N. Dodd return (rl); 932cfa84f46SDoug Rabson } 933cfa84f46SDoug Rabson 9344249382dSDoug Rabson static int 9354249382dSDoug Rabson isa_add_config(device_t dev, device_t child, 9364249382dSDoug Rabson int priority, struct isa_config *config) 9374249382dSDoug Rabson { 9384249382dSDoug Rabson struct isa_device* idev = DEVTOISA(child); 9394249382dSDoug Rabson struct isa_config_entry *newice, *ice; 9404249382dSDoug Rabson 9414249382dSDoug Rabson newice = malloc(sizeof *ice, M_DEVBUF, M_NOWAIT); 9424249382dSDoug Rabson if (!newice) 9434249382dSDoug Rabson return ENOMEM; 9444249382dSDoug Rabson 9454249382dSDoug Rabson newice->ice_priority = priority; 9464249382dSDoug Rabson newice->ice_config = *config; 9474249382dSDoug Rabson 9484249382dSDoug Rabson TAILQ_FOREACH(ice, &idev->id_configs, ice_link) { 9494249382dSDoug Rabson if (ice->ice_priority > priority) 9504249382dSDoug Rabson break; 9514249382dSDoug Rabson } 9524249382dSDoug Rabson if (ice) 9534249382dSDoug Rabson TAILQ_INSERT_BEFORE(ice, newice, ice_link); 9544249382dSDoug Rabson else 9554249382dSDoug Rabson TAILQ_INSERT_TAIL(&idev->id_configs, newice, ice_link); 9564249382dSDoug Rabson 9574249382dSDoug Rabson return 0; 9584249382dSDoug Rabson } 9594249382dSDoug Rabson 9604249382dSDoug Rabson static void 9614249382dSDoug Rabson isa_set_config_callback(device_t dev, device_t child, 9624249382dSDoug Rabson isa_config_cb *fn, void *arg) 9634249382dSDoug Rabson { 9644249382dSDoug Rabson struct isa_device* idev = DEVTOISA(child); 9654249382dSDoug Rabson 9664249382dSDoug Rabson idev->id_config_cb = fn; 9674249382dSDoug Rabson idev->id_config_arg = arg; 9684249382dSDoug Rabson } 9694249382dSDoug Rabson 9704249382dSDoug Rabson static int 9714249382dSDoug Rabson isa_pnp_probe(device_t dev, device_t child, struct isa_pnp_id *ids) 9724249382dSDoug Rabson { 9734249382dSDoug Rabson struct isa_device* idev = DEVTOISA(child); 9744249382dSDoug Rabson 9754249382dSDoug Rabson if (!idev->id_vendorid) 9764249382dSDoug Rabson return ENOENT; 9774249382dSDoug Rabson 9782e5bbc3fSMike Smith while (ids && ids->ip_id) { 9794249382dSDoug Rabson /* 9804249382dSDoug Rabson * Really ought to support >1 compat id per device. 9814249382dSDoug Rabson */ 9824249382dSDoug Rabson if (idev->id_logicalid == ids->ip_id 9834249382dSDoug Rabson || idev->id_compatid == ids->ip_id) { 9842aadbbb6SDoug Rabson if (ids->ip_desc) 9854249382dSDoug Rabson device_set_desc(child, ids->ip_desc); 9864249382dSDoug Rabson return 0; 9874249382dSDoug Rabson } 9884249382dSDoug Rabson ids++; 9894249382dSDoug Rabson } 9904249382dSDoug Rabson 9914249382dSDoug Rabson return ENXIO; 9924249382dSDoug Rabson } 9934249382dSDoug Rabson 994a3be63b3SDoug Rabson static device_method_t isa_methods[] = { 995a3be63b3SDoug Rabson /* Device interface */ 996a3be63b3SDoug Rabson DEVMETHOD(device_probe, isa_probe), 997a3be63b3SDoug Rabson DEVMETHOD(device_attach, isa_attach), 998a3be63b3SDoug Rabson DEVMETHOD(device_detach, bus_generic_detach), 999a3be63b3SDoug Rabson DEVMETHOD(device_shutdown, bus_generic_shutdown), 1000a3be63b3SDoug Rabson DEVMETHOD(device_suspend, bus_generic_suspend), 1001a3be63b3SDoug Rabson DEVMETHOD(device_resume, bus_generic_resume), 1002a3be63b3SDoug Rabson 1003a3be63b3SDoug Rabson /* Bus interface */ 1004a3be63b3SDoug Rabson DEVMETHOD(bus_add_child, isa_add_child), 1005a3be63b3SDoug Rabson DEVMETHOD(bus_print_child, isa_print_child), 1006328d36e9SDoug Rabson DEVMETHOD(bus_probe_nomatch, isa_probe_nomatch), 1007a3be63b3SDoug Rabson DEVMETHOD(bus_read_ivar, isa_read_ivar), 1008a3be63b3SDoug Rabson DEVMETHOD(bus_write_ivar, isa_write_ivar), 10094249382dSDoug Rabson DEVMETHOD(bus_child_detached, isa_child_detached), 1010ec22663bSDoug Rabson DEVMETHOD(bus_driver_added, isa_driver_added), 1011a3be63b3SDoug Rabson DEVMETHOD(bus_setup_intr, isa_setup_intr), 1012a3be63b3SDoug Rabson DEVMETHOD(bus_teardown_intr, isa_teardown_intr), 10131581afb3SMatthew N. Dodd 10141581afb3SMatthew N. Dodd DEVMETHOD(bus_get_resource_list,isa_get_resource_list), 10151581afb3SMatthew N. Dodd DEVMETHOD(bus_alloc_resource, isa_alloc_resource), 10161581afb3SMatthew N. Dodd DEVMETHOD(bus_release_resource, isa_release_resource), 101725afb89bSDoug Rabson DEVMETHOD(bus_set_resource, isa_set_resource), 10181581afb3SMatthew N. Dodd DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), 10191581afb3SMatthew N. Dodd DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource), 10201581afb3SMatthew N. Dodd DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 10211581afb3SMatthew N. Dodd DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 1022a3be63b3SDoug Rabson 1023a3be63b3SDoug Rabson /* ISA interface */ 10244249382dSDoug Rabson DEVMETHOD(isa_add_config, isa_add_config), 10254249382dSDoug Rabson DEVMETHOD(isa_set_config_callback, isa_set_config_callback), 10264249382dSDoug Rabson DEVMETHOD(isa_pnp_probe, isa_pnp_probe), 1027a3be63b3SDoug Rabson 1028a3be63b3SDoug Rabson { 0, 0 } 1029a3be63b3SDoug Rabson }; 1030a3be63b3SDoug Rabson 1031a3be63b3SDoug Rabson static driver_t isa_driver = { 1032a3be63b3SDoug Rabson "isa", 1033a3be63b3SDoug Rabson isa_methods, 1034a3be63b3SDoug Rabson 1, /* no softc */ 1035a3be63b3SDoug Rabson }; 1036a3be63b3SDoug Rabson 1037a3be63b3SDoug Rabson /* 1038a3be63b3SDoug Rabson * ISA can be attached to a PCI-ISA bridge or directly to the nexus. 1039a3be63b3SDoug Rabson */ 1040a3be63b3SDoug Rabson DRIVER_MODULE(isa, isab, isa_driver, isa_devclass, 0, 0); 10415aea03b0SMike Smith DRIVER_MODULE(isa, eisab, isa_driver, isa_devclass, 0, 0); 1042a3be63b3SDoug Rabson #ifdef __i386__ 1043a3be63b3SDoug Rabson DRIVER_MODULE(isa, nexus, isa_driver, isa_devclass, 0, 0); 1044a3be63b3SDoug Rabson #endif 1045