xref: /freebsd/sys/isa/isahint.c (revision 0197892d6a55f2f4be1da7aad71f52d94e4366cd)
16c2e3ddeSDoug Rabson /*-
26c2e3ddeSDoug Rabson  * Copyright (c) 1999 Doug Rabson
36c2e3ddeSDoug Rabson  * All rights reserved.
46c2e3ddeSDoug Rabson  *
56c2e3ddeSDoug Rabson  * Redistribution and use in source and binary forms, with or without
66c2e3ddeSDoug Rabson  * modification, are permitted provided that the following conditions
76c2e3ddeSDoug Rabson  * are met:
86c2e3ddeSDoug Rabson  * 1. Redistributions of source code must retain the above copyright
96c2e3ddeSDoug Rabson  *    notice, this list of conditions and the following disclaimer.
106c2e3ddeSDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
116c2e3ddeSDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
126c2e3ddeSDoug Rabson  *    documentation and/or other materials provided with the distribution.
136c2e3ddeSDoug Rabson  *
146c2e3ddeSDoug Rabson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
156c2e3ddeSDoug Rabson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
166c2e3ddeSDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
176c2e3ddeSDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
186c2e3ddeSDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
196c2e3ddeSDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
206c2e3ddeSDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
216c2e3ddeSDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
226c2e3ddeSDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
236c2e3ddeSDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
246c2e3ddeSDoug Rabson  * SUCH DAMAGE.
256c2e3ddeSDoug Rabson  *
26c3aac50fSPeter Wemm  * $FreeBSD$
276c2e3ddeSDoug Rabson  */
286c2e3ddeSDoug Rabson 
296c2e3ddeSDoug Rabson #include <sys/param.h>
306c2e3ddeSDoug Rabson #include <sys/systm.h>
316c2e3ddeSDoug Rabson #include <sys/kernel.h>
326c2e3ddeSDoug Rabson #include <sys/bus.h>
336c2e3ddeSDoug Rabson #include <sys/module.h>
346c2e3ddeSDoug Rabson #include <isa/isavar.h>
35a3be63b3SDoug Rabson #include <machine/resource.h>
366c2e3ddeSDoug Rabson 
376c2e3ddeSDoug Rabson static void
386c2e3ddeSDoug Rabson isahint_add_device(device_t parent, const char *name, int unit)
396c2e3ddeSDoug Rabson {
406c2e3ddeSDoug Rabson 	device_t	child;
41a3be63b3SDoug Rabson 	int		sensitive, start, count, t;
42bea6af4dSDoug Rabson 	int		order;
436c2e3ddeSDoug Rabson 
446c2e3ddeSDoug Rabson 	/* device-specific flag overrides any wildcard */
456c2e3ddeSDoug Rabson 	sensitive = 0;
466c2e3ddeSDoug Rabson 	if (resource_int_value(name, unit, "sensitive", &sensitive) != 0)
476c2e3ddeSDoug Rabson 		resource_int_value(name, -1, "sensitive", &sensitive);
486c2e3ddeSDoug Rabson 
496c2e3ddeSDoug Rabson 	if (sensitive)
50bea6af4dSDoug Rabson 		order = ISA_ORDER_SENSITIVE;
516c2e3ddeSDoug Rabson 	else
52bea6af4dSDoug Rabson 		order = ISA_ORDER_SPECULATIVE;
53bea6af4dSDoug Rabson 
54bea6af4dSDoug Rabson 	child = BUS_ADD_CHILD(parent, order, name, unit);
556c2e3ddeSDoug Rabson 	if (child == 0)
566c2e3ddeSDoug Rabson 		return;
576c2e3ddeSDoug Rabson 
58a3be63b3SDoug Rabson 	start = 0;
59a3be63b3SDoug Rabson 	count = 0;
600197892dSYoshihiro Takahashi 	resource_int_value(name, unit, "port", &start);
610197892dSYoshihiro Takahashi 	resource_int_value(name, unit, "portsize", &count);
620197892dSYoshihiro Takahashi 	if (start > 0 || count > 0)
6325afb89bSDoug Rabson 		bus_set_resource(child, SYS_RES_IOPORT, 0, start, count);
646c2e3ddeSDoug Rabson 
65a3be63b3SDoug Rabson 	start = 0;
66a3be63b3SDoug Rabson 	count = 0;
670197892dSYoshihiro Takahashi 	resource_int_value(name, unit, "maddr", &start);
680197892dSYoshihiro Takahashi 	resource_int_value(name, unit, "msize", &count);
690197892dSYoshihiro Takahashi 	if (start > 0 || count > 0)
7025afb89bSDoug Rabson 		bus_set_resource(child, SYS_RES_MEMORY, 0, start, count);
716c2e3ddeSDoug Rabson 
72828cb040SKazutaka YOKOTA 	if (resource_int_value(name, unit, "irq", &start) == 0 && start > 0)
7325afb89bSDoug Rabson 		bus_set_resource(child, SYS_RES_IRQ, 0, start, 1);
746c2e3ddeSDoug Rabson 
750e7e521cSAndrew Gallatin 	if (resource_int_value(name, unit, "drq", &start) == 0 && start >= 0)
7625afb89bSDoug Rabson 		bus_set_resource(child, SYS_RES_DRQ, 0, start, 1);
776c2e3ddeSDoug Rabson 
786c2e3ddeSDoug Rabson 	if (resource_int_value(name, unit, "flags", &t) == 0)
79062acdb7SDoug Rabson 		device_set_flags(child, t);
806c2e3ddeSDoug Rabson 
816c2e3ddeSDoug Rabson 	if (resource_int_value(name, unit, "disabled", &t) == 0 && t != 0)
826c2e3ddeSDoug Rabson 		device_disable(child);
836c2e3ddeSDoug Rabson }
846c2e3ddeSDoug Rabson 
856c2e3ddeSDoug Rabson static void
866c2e3ddeSDoug Rabson isahint_identify(driver_t *driver, device_t parent)
876c2e3ddeSDoug Rabson {
886c2e3ddeSDoug Rabson 	int i;
896c2e3ddeSDoug Rabson 	static char buf[] = "isaXXX";
906c2e3ddeSDoug Rabson 
916c2e3ddeSDoug Rabson 	/*
926c2e3ddeSDoug Rabson 	 * Add all devices configured to be attached to parent.
936c2e3ddeSDoug Rabson 	 */
946c2e3ddeSDoug Rabson 	sprintf(buf, "isa%d", device_get_unit(parent));
95ada54f9eSPeter Wemm 	i = -1;
96efed28b0SPeter Wemm 	while ((i = resource_query_string(i, "at", buf)) != -1) {
976c2e3ddeSDoug Rabson 		if (strcmp(resource_query_name(i), "atkbd") == 0)
986c2e3ddeSDoug Rabson 			continue;	/* old GENERIC kludge */
996c2e3ddeSDoug Rabson 		isahint_add_device(parent,
1006c2e3ddeSDoug Rabson 				   resource_query_name(i),
1016c2e3ddeSDoug Rabson 				   resource_query_unit(i));
1026c2e3ddeSDoug Rabson 	}
1036c2e3ddeSDoug Rabson 
1046c2e3ddeSDoug Rabson 	/*
1056c2e3ddeSDoug Rabson 	 * and isa?
1066c2e3ddeSDoug Rabson 	 */
107ada54f9eSPeter Wemm 	i = -1;
108ada54f9eSPeter Wemm 	while ((i = resource_query_string(i, "at", "isa")) != -1) {
1096c2e3ddeSDoug Rabson 		if (strcmp(resource_query_name(i), "atkbd") == 0)
1106c2e3ddeSDoug Rabson 			continue;	/* old GENERIC kludge */
1116c2e3ddeSDoug Rabson 		isahint_add_device(parent,
1126c2e3ddeSDoug Rabson 				   resource_query_name(i),
1136c2e3ddeSDoug Rabson 				   resource_query_unit(i));
1146c2e3ddeSDoug Rabson 	}
1156c2e3ddeSDoug Rabson }
1166c2e3ddeSDoug Rabson 
1176c2e3ddeSDoug Rabson static device_method_t isahint_methods[] = {
1186c2e3ddeSDoug Rabson 	/* Device interface */
1196c2e3ddeSDoug Rabson 	DEVMETHOD(device_identify,	isahint_identify),
1206c2e3ddeSDoug Rabson 
1216c2e3ddeSDoug Rabson 	{ 0, 0 }
1226c2e3ddeSDoug Rabson };
1236c2e3ddeSDoug Rabson 
1246c2e3ddeSDoug Rabson static driver_t isahint_driver = {
1256c2e3ddeSDoug Rabson 	"hint",
1266c2e3ddeSDoug Rabson 	isahint_methods,
1276c2e3ddeSDoug Rabson 	1,			/* no softc */
1286c2e3ddeSDoug Rabson };
1296c2e3ddeSDoug Rabson 
1306c2e3ddeSDoug Rabson static devclass_t hint_devclass;
1316c2e3ddeSDoug Rabson 
1326c2e3ddeSDoug Rabson DRIVER_MODULE(isahint, isa, isahint_driver, hint_devclass, 0, 0);
133