isahint.c revision 136520
1208747Sraj/*- 2208747Sraj * Copyright (c) 1999 Doug Rabson 3208747Sraj * All rights reserved. 4208747Sraj * 5208747Sraj * Redistribution and use in source and binary forms, with or without 6208747Sraj * modification, are permitted provided that the following conditions 7208747Sraj * are met: 8208747Sraj * 1. Redistributions of source code must retain the above copyright 9208747Sraj * notice, this list of conditions and the following disclaimer. 10208747Sraj * 2. Redistributions in binary form must reproduce the above copyright 11208747Sraj * notice, this list of conditions and the following disclaimer in the 12208747Sraj * documentation and/or other materials provided with the distribution. 13208747Sraj * 14208747Sraj * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15208747Sraj * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16208747Sraj * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17208747Sraj * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18208747Sraj * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19208747Sraj * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20208747Sraj * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21208747Sraj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22208747Sraj * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23208747Sraj * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24208747Sraj * SUCH DAMAGE. 25208747Sraj */ 26208747Sraj 27208747Sraj#include <sys/cdefs.h> 28208747Sraj__FBSDID("$FreeBSD: head/sys/isa/isahint.c 136520 2004-10-14 22:21:59Z njl $"); 29208747Sraj 30208747Sraj#include <sys/param.h> 31208747Sraj#include <sys/systm.h> 32208747Sraj#include <sys/kernel.h> 33208747Sraj#include <sys/bus.h> 34208747Sraj#include <sys/module.h> 35208747Sraj#include <isa/isavar.h> 36208747Sraj#include <machine/resource.h> 37208747Sraj 38208747Srajstatic void 39208747Srajisahint_add_device(device_t parent, const char *name, int unit) 40208747Sraj{ 41208747Sraj device_t child; 42208747Sraj int sensitive, start, count; 43208747Sraj int order; 44208747Sraj 45208747Sraj /* device-specific flag overrides any wildcard */ 46208747Sraj sensitive = 0; 47208747Sraj if (resource_int_value(name, unit, "sensitive", &sensitive) != 0) 48208747Sraj resource_int_value(name, -1, "sensitive", &sensitive); 49208747Sraj 50208747Sraj if (sensitive) 51208747Sraj order = ISA_ORDER_SENSITIVE; 52208747Sraj else 53208747Sraj order = ISA_ORDER_SPECULATIVE; 54208747Sraj 55208747Sraj child = BUS_ADD_CHILD(parent, order, name, unit); 56208747Sraj if (child == 0) 57208747Sraj return; 58208747Sraj 59208747Sraj start = 0; 60208747Sraj count = 0; 61208747Sraj resource_int_value(name, unit, "port", &start); 62208747Sraj resource_int_value(name, unit, "portsize", &count); 63208747Sraj if (start > 0 || count > 0) 64208747Sraj bus_set_resource(child, SYS_RES_IOPORT, 0, start, count); 65208747Sraj 66208747Sraj start = 0; 67208747Sraj count = 0; 68208747Sraj resource_int_value(name, unit, "maddr", &start); 69208747Sraj resource_int_value(name, unit, "msize", &count); 70208747Sraj if (start > 0 || count > 0) 71208747Sraj bus_set_resource(child, SYS_RES_MEMORY, 0, start, count); 72208747Sraj 73208747Sraj if (resource_int_value(name, unit, "irq", &start) == 0 && start > 0) 74208747Sraj bus_set_resource(child, SYS_RES_IRQ, 0, start, 1); 75208747Sraj 76208747Sraj if (resource_int_value(name, unit, "drq", &start) == 0 && start >= 0) 77208747Sraj bus_set_resource(child, SYS_RES_DRQ, 0, start, 1); 78208747Sraj 79208747Sraj if (resource_disabled(name, unit)) 80208747Sraj device_disable(child); 81208747Sraj} 82208747Sraj 83208747Srajstatic void 84208747Srajisahint_identify(driver_t *driver, device_t parent) 85208747Sraj{ 86208747Sraj int i; 87208747Sraj static char buf[] = "isaXXX"; 88208747Sraj const char *dname; 89208747Sraj int dunit; 90208747Sraj 91208747Sraj /* 92208747Sraj * Add all devices configured to be attached to parent. 93208747Sraj */ 94208747Sraj sprintf(buf, "isa%d", device_get_unit(parent)); 95208747Sraj i = 0; 96208747Sraj while ((resource_find_match(&i, &dname, &dunit, "at", buf)) == 0) { 97208747Sraj if (strcmp(dname, "atkbd") == 0) 98208747Sraj continue; /* old GENERIC kludge */ 99208747Sraj isahint_add_device(parent, dname, dunit); 100208747Sraj } 101208747Sraj 102208747Sraj /* 103208747Sraj * and isa? 104208747Sraj */ 105208747Sraj i = 0; 106208747Sraj while ((resource_find_match(&i, &dname, &dunit, "at", "isa")) == 0) { 107208747Sraj if (strcmp(dname, "atkbd") == 0) 108208747Sraj continue; /* old GENERIC kludge */ 109208747Sraj isahint_add_device(parent, dname, dunit); 110208747Sraj } 111208747Sraj} 112208747Sraj 113208747Srajstatic device_method_t isahint_methods[] = { 114208747Sraj /* Device interface */ 115208747Sraj DEVMETHOD(device_identify, isahint_identify), 116208747Sraj 117208747Sraj { 0, 0 } 118208747Sraj}; 119208747Sraj 120208747Srajstatic driver_t isahint_driver = { 121208747Sraj "hint", 122208747Sraj isahint_methods, 123208747Sraj 1, /* no softc */ 124208747Sraj}; 125208747Sraj 126208747Srajstatic devclass_t hint_devclass; 127208747Sraj 128208747SrajDRIVER_MODULE(isahint, isa, isahint_driver, hint_devclass, 0, 0); 129208747Sraj