2 * Copyright (c) 1997,1998 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/kern/subr_bus.c,v 1.54.2.9 2002/10/10 15:13:32 jhb Exp $
27 * $DragonFly: src/sys/kern/subr_bus.c,v 1.13 2004/03/01 16:57:44 joerg Exp $
32 #include <sys/param.h>
33 #include <sys/queue.h>
34 #include <sys/malloc.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
38 #include <sys/sysctl.h>
41 #include <sys/bus_private.h>
42 #include <sys/systm.h>
43 #include <machine/bus.h>
45 #include <machine/stdarg.h> /* for device_printf() */
47 MALLOC_DEFINE(M_BUS, "bus", "Bus data structures");
50 #define PDEBUG(a) (printf(__FUNCTION__ ":%d: ", __LINE__), printf a, printf("\n"))
51 #define DEVICENAME(d) ((d)? device_get_name(d): "no device")
52 #define DRIVERNAME(d) ((d)? d->name : "no driver")
53 #define DEVCLANAME(d) ((d)? d->name : "no devclass")
55 /* Produce the indenting, indent*2 spaces plus a '.' ahead of that to
56 * prevent syslog from deleting initial spaces
58 #define indentprintf(p) do { int iJ; printf("."); for (iJ=0; iJ<indent; iJ++) printf(" "); printf p ; } while(0)
60 static void print_device_short(device_t dev, int indent);
61 static void print_device(device_t dev, int indent);
62 void print_device_tree_short(device_t dev, int indent);
63 void print_device_tree(device_t dev, int indent);
64 static void print_driver_short(driver_t *driver, int indent);
65 static void print_driver(driver_t *driver, int indent);
66 static void print_driver_list(driver_list_t drivers, int indent);
67 static void print_devclass_short(devclass_t dc, int indent);
68 static void print_devclass(devclass_t dc, int indent);
69 void print_devclass_list_short(void);
70 void print_devclass_list(void);
73 /* Make the compiler ignore the function calls */
74 #define PDEBUG(a) /* nop */
75 #define DEVICENAME(d) /* nop */
76 #define DRIVERNAME(d) /* nop */
77 #define DEVCLANAME(d) /* nop */
79 #define print_device_short(d,i) /* nop */
80 #define print_device(d,i) /* nop */
81 #define print_device_tree_short(d,i) /* nop */
82 #define print_device_tree(d,i) /* nop */
83 #define print_driver_short(d,i) /* nop */
84 #define print_driver(d,i) /* nop */
85 #define print_driver_list(d,i) /* nop */
86 #define print_devclass_short(d,i) /* nop */
87 #define print_devclass(d,i) /* nop */
88 #define print_devclass_list_short() /* nop */
89 #define print_devclass_list() /* nop */
93 static void device_register_oids(device_t dev);
94 static void device_unregister_oids(device_t dev);
97 kobj_method_t null_methods[] = {
101 DEFINE_CLASS(null, null_methods, 0);
104 * Devclass implementation
107 static devclass_list_t devclasses = TAILQ_HEAD_INITIALIZER(devclasses);
110 devclass_find_internal(const char *classname, int create)
114 PDEBUG(("looking for %s", classname));
115 if (classname == NULL)
118 TAILQ_FOREACH(dc, &devclasses, link)
119 if (!strcmp(dc->name, classname))
122 PDEBUG(("%s not found%s", classname, (create? ", creating": "")));
124 dc = malloc(sizeof(struct devclass) + strlen(classname) + 1,
125 M_BUS, M_NOWAIT | M_ZERO);
128 dc->name = (char*) (dc + 1);
129 strcpy(dc->name, classname);
132 TAILQ_INIT(&dc->drivers);
133 TAILQ_INSERT_TAIL(&devclasses, dc, link);
140 devclass_create(const char *classname)
142 return(devclass_find_internal(classname, TRUE));
146 devclass_find(const char *classname)
148 return(devclass_find_internal(classname, FALSE));
152 devclass_add_driver(devclass_t dc, driver_t *driver)
157 PDEBUG(("%s", DRIVERNAME(driver)));
159 dl = malloc(sizeof *dl, M_BUS, M_NOWAIT | M_ZERO);
164 * Compile the driver's methods. Also increase the reference count
165 * so that the class doesn't get freed when the last instance
166 * goes. This means we can safely use static methods and avoids a
167 * double-free in devclass_delete_driver.
169 kobj_class_compile((kobj_class_t) driver);
172 * Make sure the devclass which the driver is implementing exists.
174 devclass_find_internal(driver->name, TRUE);
177 TAILQ_INSERT_TAIL(&dc->drivers, dl, link);
181 * Call BUS_DRIVER_ADDED for any existing busses in this class.
183 for (i = 0; i < dc->maxunit; i++)
185 BUS_DRIVER_ADDED(dc->devices[i], driver);
191 devclass_delete_driver(devclass_t busclass, driver_t *driver)
193 devclass_t dc = devclass_find(driver->name);
199 PDEBUG(("%s from devclass %s", driver->name, DEVCLANAME(busclass)));
205 * Find the link structure in the bus' list of drivers.
207 TAILQ_FOREACH(dl, &busclass->drivers, link)
208 if (dl->driver == driver)
212 PDEBUG(("%s not found in %s list", driver->name, busclass->name));
217 * Disassociate from any devices. We iterate through all the
218 * devices in the devclass of the driver and detach any which are
219 * using the driver and which have a parent in the devclass which
220 * we are deleting from.
222 * Note that since a driver can be in multiple devclasses, we
223 * should not detach devices which are not children of devices in
224 * the affected devclass.
226 for (i = 0; i < dc->maxunit; i++)
227 if (dc->devices[i]) {
228 dev = dc->devices[i];
229 if (dev->driver == driver && dev->parent &&
230 dev->parent->devclass == busclass) {
231 if ((error = device_detach(dev)) != 0)
233 device_set_driver(dev, NULL);
237 TAILQ_REMOVE(&busclass->drivers, dl, link);
241 if (driver->refs == 0)
242 kobj_class_free((kobj_class_t) driver);
248 devclass_find_driver_internal(devclass_t dc, const char *classname)
252 PDEBUG(("%s in devclass %s", classname, DEVCLANAME(dc)));
254 TAILQ_FOREACH(dl, &dc->drivers, link)
255 if (!strcmp(dl->driver->name, classname))
258 PDEBUG(("not found"));
263 devclass_find_driver(devclass_t dc, const char *classname)
267 dl = devclass_find_driver_internal(dc, classname);
275 devclass_get_name(devclass_t dc)
281 devclass_get_device(devclass_t dc, int unit)
283 if (dc == NULL || unit < 0 || unit >= dc->maxunit)
285 return(dc->devices[unit]);
289 devclass_get_softc(devclass_t dc, int unit)
293 dev = devclass_get_device(dc, unit);
297 return(device_get_softc(dev));
301 devclass_get_devices(devclass_t dc, device_t **devlistp, int *devcountp)
308 for (i = 0; i < dc->maxunit; i++)
312 list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT | M_ZERO);
317 for (i = 0; i < dc->maxunit; i++)
318 if (dc->devices[i]) {
319 list[count] = dc->devices[i];
330 devclass_get_maxunit(devclass_t dc)
336 devclass_alloc_unit(devclass_t dc, int *unitp)
340 PDEBUG(("unit %d in devclass %s", unit, DEVCLANAME(dc)));
342 /* If we have been given a wired unit number, check for existing device */
344 if (unit >= 0 && unit < dc->maxunit &&
345 dc->devices[unit] != NULL) {
347 printf("%s-: %s%d exists, using next available unit number\n",
348 dc->name, dc->name, unit);
349 /* find the next available slot */
350 while (++unit < dc->maxunit && dc->devices[unit] != NULL)
354 /* Unwired device, find the next available slot for it */
356 while (unit < dc->maxunit && dc->devices[unit] != NULL)
361 * We've selected a unit beyond the length of the table, so let's
362 * extend the table to make room for all units up to and including
365 if (unit >= dc->maxunit) {
369 newsize = roundup((unit + 1), MINALLOCSIZE / sizeof(device_t));
370 newlist = malloc(sizeof(device_t) * newsize, M_BUS, M_NOWAIT | M_ZERO);
373 bcopy(dc->devices, newlist, sizeof(device_t) * dc->maxunit);
375 free(dc->devices, M_BUS);
376 dc->devices = newlist;
377 dc->maxunit = newsize;
379 PDEBUG(("now: unit %d in devclass %s", unit, DEVCLANAME(dc)));
386 devclass_add_device(devclass_t dc, device_t dev)
390 PDEBUG(("%s in devclass %s", DEVICENAME(dev), DEVCLANAME(dc)));
392 buflen = strlen(dc->name) + 5;
393 dev->nameunit = malloc(buflen, M_BUS, M_NOWAIT | M_ZERO);
397 if ((error = devclass_alloc_unit(dc, &dev->unit)) != 0) {
398 free(dev->nameunit, M_BUS);
399 dev->nameunit = NULL;
402 dc->devices[dev->unit] = dev;
404 snprintf(dev->nameunit, buflen, "%s%d", dc->name, dev->unit);
406 #ifdef DEVICE_SYSCTLS
407 device_register_oids(dev);
414 devclass_delete_device(devclass_t dc, device_t dev)
419 PDEBUG(("%s in devclass %s", DEVICENAME(dev), DEVCLANAME(dc)));
421 if (dev->devclass != dc || dc->devices[dev->unit] != dev)
422 panic("devclass_delete_device: inconsistent device class");
423 dc->devices[dev->unit] = NULL;
424 if (dev->flags & DF_WILDCARD)
426 dev->devclass = NULL;
427 free(dev->nameunit, M_BUS);
428 dev->nameunit = NULL;
430 #ifdef DEVICE_SYSCTLS
431 device_unregister_oids(dev);
438 make_device(device_t parent, const char *name, int unit)
443 PDEBUG(("%s at %s as unit %d", name, DEVICENAME(parent), unit));
446 dc = devclass_find_internal(name, TRUE);
448 printf("make_device: can't find device class %s\n", name);
454 dev = malloc(sizeof(struct device), M_BUS, M_NOWAIT | M_ZERO);
458 dev->parent = parent;
459 TAILQ_INIT(&dev->children);
460 kobj_init((kobj_t) dev, &null_class);
462 dev->devclass = NULL;
464 dev->nameunit = NULL;
468 dev->flags = DF_ENABLED;
471 dev->flags |= DF_WILDCARD;
473 dev->flags |= DF_FIXEDCLASS;
474 if (devclass_add_device(dc, dev) != 0) {
475 kobj_delete((kobj_t)dev, M_BUS);
482 dev->state = DS_NOTPRESENT;
488 device_print_child(device_t dev, device_t child)
492 if (device_is_alive(child))
493 retval += BUS_PRINT_CHILD(dev, child);
495 retval += device_printf(child, " not found\n");
501 device_add_child(device_t dev, const char *name, int unit)
503 return device_add_child_ordered(dev, 0, name, unit);
507 device_add_child_ordered(device_t dev, int order, const char *name, int unit)
512 PDEBUG(("%s at %s with order %d as unit %d", name, DEVICENAME(dev),
515 child = make_device(dev, name, unit);
518 child->order = order;
520 TAILQ_FOREACH(place, &dev->children, link)
521 if (place->order > order)
526 * The device 'place' is the first device whose order is
527 * greater than the new child.
529 TAILQ_INSERT_BEFORE(place, child, link);
532 * The new child's order is greater or equal to the order of
533 * any existing device. Add the child to the tail of the list.
535 TAILQ_INSERT_TAIL(&dev->children, child, link);
542 device_delete_child(device_t dev, device_t child)
547 PDEBUG(("%s from %s", DEVICENAME(child), DEVICENAME(dev)));
549 /* remove children first */
550 while ( (grandchild = TAILQ_FIRST(&child->children)) ) {
551 error = device_delete_child(child, grandchild);
556 if ((error = device_detach(child)) != 0)
559 devclass_delete_device(child->devclass, child);
560 TAILQ_REMOVE(&dev->children, child, link);
561 device_set_desc(child, NULL);
562 kobj_delete((kobj_t)child, M_BUS);
568 * Find only devices attached to this bus.
571 device_find_child(device_t dev, const char *classname, int unit)
576 dc = devclass_find(classname);
580 child = devclass_get_device(dc, unit);
581 if (child && child->parent == dev)
587 first_matching_driver(devclass_t dc, device_t dev)
590 return(devclass_find_driver_internal(dc, dev->devclass->name));
592 return(TAILQ_FIRST(&dc->drivers));
596 next_matching_driver(devclass_t dc, device_t dev, driverlink_t last)
600 for (dl = TAILQ_NEXT(last, link); dl; dl = TAILQ_NEXT(dl, link))
601 if (!strcmp(dev->devclass->name, dl->driver->name))
605 return(TAILQ_NEXT(last, link));
609 device_probe_child(device_t dev, device_t child)
612 driverlink_t best = 0;
615 int hasclass = (child->devclass != 0);
619 panic("device_probe_child: parent device has no devclass");
621 if (child->state == DS_ALIVE)
624 for (dl = first_matching_driver(dc, child); dl;
625 dl = next_matching_driver(dc, child, dl)) {
626 PDEBUG(("Trying %s", DRIVERNAME(dl->driver)));
627 device_set_driver(child, dl->driver);
629 device_set_devclass(child, dl->driver->name);
630 result = DEVICE_PROBE(child);
632 device_set_devclass(child, 0);
635 * If the driver returns SUCCESS, there can be no higher match
645 * The driver returned an error so it certainly doesn't match.
648 device_set_driver(child, 0);
653 * A priority lower than SUCCESS, remember the best matching
654 * driver. Initialise the value of pri for the first match.
656 if (best == 0 || result > pri) {
664 * If we found a driver, change state and initialise the devclass.
667 if (!child->devclass)
668 device_set_devclass(child, best->driver->name);
669 device_set_driver(child, best->driver);
672 * A bit bogus. Call the probe method again to make
673 * sure that we have the right description.
677 child->state = DS_ALIVE;
685 device_get_parent(device_t dev)
691 device_get_children(device_t dev, device_t **devlistp, int *devcountp)
698 TAILQ_FOREACH(child, &dev->children, link)
701 list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT | M_ZERO);
706 TAILQ_FOREACH(child, &dev->children, link) {
718 device_get_driver(device_t dev)
724 device_get_devclass(device_t dev)
726 return(dev->devclass);
730 device_get_name(device_t dev)
733 return devclass_get_name(dev->devclass);
738 device_get_nameunit(device_t dev)
740 return(dev->nameunit);
744 device_get_unit(device_t dev)
750 device_get_desc(device_t dev)
756 device_get_flags(device_t dev)
758 return(dev->devflags);
762 device_print_prettyname(device_t dev)
764 const char *name = device_get_name(dev);
767 return printf("unknown: ");
769 return printf("%s%d: ", name, device_get_unit(dev));
773 device_printf(device_t dev, const char * fmt, ...)
778 retval = device_print_prettyname(dev);
780 retval += vprintf(fmt, ap);
786 device_set_desc_internal(device_t dev, const char* desc, int copy)
788 if (dev->desc && (dev->flags & DF_DESCMALLOCED)) {
789 free(dev->desc, M_BUS);
790 dev->flags &= ~DF_DESCMALLOCED;
795 dev->desc = malloc(strlen(desc) + 1, M_BUS, M_NOWAIT);
797 strcpy(dev->desc, desc);
798 dev->flags |= DF_DESCMALLOCED;
801 /* Avoid a -Wcast-qual warning */
802 dev->desc = (char *)(uintptr_t) desc;
804 #ifdef DEVICE_SYSCTLS
806 struct sysctl_oid *oid = &dev->oid[1];
807 oid->oid_arg1 = dev->desc ? dev->desc : "";
808 oid->oid_arg2 = dev->desc ? strlen(dev->desc) : 0;
814 device_set_desc(device_t dev, const char* desc)
816 device_set_desc_internal(dev, desc, FALSE);
820 device_set_desc_copy(device_t dev, const char* desc)
822 device_set_desc_internal(dev, desc, TRUE);
826 device_set_flags(device_t dev, uint32_t flags)
828 dev->devflags = flags;
832 device_get_softc(device_t dev)
838 device_set_softc(device_t dev, void *softc)
840 if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC))
841 free(dev->softc, M_BUS);
844 dev->flags |= DF_EXTERNALSOFTC;
846 dev->flags &= ~DF_EXTERNALSOFTC;
850 device_get_ivars(device_t dev)
856 device_set_ivars(device_t dev, void * ivars)
865 device_get_state(device_t dev)
871 device_enable(device_t dev)
873 dev->flags |= DF_ENABLED;
877 device_disable(device_t dev)
879 dev->flags &= ~DF_ENABLED;
886 device_busy(device_t dev)
888 if (dev->state < DS_ATTACHED)
889 panic("device_busy: called for unattached device");
890 if (dev->busy == 0 && dev->parent)
891 device_busy(dev->parent);
893 dev->state = DS_BUSY;
900 device_unbusy(device_t dev)
902 if (dev->state != DS_BUSY)
903 panic("device_unbusy: called for non-busy device");
905 if (dev->busy == 0) {
907 device_unbusy(dev->parent);
908 dev->state = DS_ATTACHED;
913 device_quiet(device_t dev)
915 dev->flags |= DF_QUIET;
919 device_verbose(device_t dev)
921 dev->flags &= ~DF_QUIET;
925 device_is_quiet(device_t dev)
927 return((dev->flags & DF_QUIET) != 0);
931 device_is_enabled(device_t dev)
933 return((dev->flags & DF_ENABLED) != 0);
937 device_is_alive(device_t dev)
939 return(dev->state >= DS_ALIVE);
943 device_is_attached(device_t dev)
945 return(dev->state >= DS_ATTACHED);
949 device_set_devclass(device_t dev, const char *classname)
955 devclass_delete_device(dev->devclass, dev);
960 printf("device_set_devclass: device class already set\n");
964 dc = devclass_find_internal(classname, TRUE);
968 return(devclass_add_device(dc, dev));
972 device_set_driver(device_t dev, driver_t *driver)
974 if (dev->state >= DS_ATTACHED)
977 if (dev->driver == driver)
980 if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) {
981 free(dev->softc, M_BUS);
984 kobj_delete((kobj_t) dev, 0);
985 dev->driver = driver;
987 kobj_init((kobj_t) dev, (kobj_class_t) driver);
988 if (!(dev->flags & DF_EXTERNALSOFTC)) {
989 dev->softc = malloc(driver->size, M_BUS,
992 kobj_delete((kobj_t)dev, 0);
993 kobj_init((kobj_t) dev, &null_class);
999 kobj_init((kobj_t) dev, &null_class);
1004 device_probe_and_attach(device_t dev)
1006 device_t bus = dev->parent;
1008 int hasclass = (dev->devclass != 0);
1010 if (dev->state >= DS_ALIVE)
1013 if ((dev->flags & DF_ENABLED) == 0) {
1015 device_print_prettyname(dev);
1016 printf("not probed (disabled)\n");
1021 error = device_probe_child(bus, dev);
1023 if (!(dev->flags & DF_DONENOMATCH)) {
1024 BUS_PROBE_NOMATCH(bus, dev);
1025 dev->flags |= DF_DONENOMATCH;
1030 if (!device_is_quiet(dev))
1031 device_print_child(bus, dev);
1032 error = DEVICE_ATTACH(dev);
1034 dev->state = DS_ATTACHED;
1036 printf("device_probe_and_attach: %s%d attach returned %d\n",
1037 dev->driver->name, dev->unit, error);
1038 /* Unset the class that was set in device_probe_child */
1040 device_set_devclass(dev, 0);
1041 device_set_driver(dev, NULL);
1042 dev->state = DS_NOTPRESENT;
1049 device_detach(device_t dev)
1053 PDEBUG(("%s", DEVICENAME(dev)));
1054 if (dev->state == DS_BUSY)
1056 if (dev->state != DS_ATTACHED)
1059 if ((error = DEVICE_DETACH(dev)) != 0)
1061 device_printf(dev, "detached\n");
1063 BUS_CHILD_DETACHED(dev->parent, dev);
1065 if (!(dev->flags & DF_FIXEDCLASS))
1066 devclass_delete_device(dev->devclass, dev);
1068 dev->state = DS_NOTPRESENT;
1069 device_set_driver(dev, NULL);
1075 device_shutdown(device_t dev)
1077 if (dev->state < DS_ATTACHED)
1079 return DEVICE_SHUTDOWN(dev);
1083 device_set_unit(device_t dev, int unit)
1088 dc = device_get_devclass(dev);
1089 if (unit < dc->maxunit && dc->devices[unit])
1091 err = devclass_delete_device(dc, dev);
1095 err = devclass_add_device(dc, dev);
1099 #ifdef DEVICE_SYSCTLS
1102 * Sysctl nodes for devices.
1105 SYSCTL_NODE(_hw, OID_AUTO, devices, CTLFLAG_RW, 0, "A list of all devices");
1108 sysctl_handle_children(SYSCTL_HANDLER_ARGS)
1110 device_t dev = arg1;
1112 int first = 1, error = 0;
1114 TAILQ_FOREACH(child, &dev->children, link)
1115 if (child->nameunit) {
1117 error = SYSCTL_OUT(req, ",", 1);
1122 error = SYSCTL_OUT(req, child->nameunit,
1123 strlen(child->nameunit));
1128 error = SYSCTL_OUT(req, "", 1);
1134 sysctl_handle_state(SYSCTL_HANDLER_ARGS)
1136 device_t dev = arg1;
1138 switch (dev->state) {
1140 return SYSCTL_OUT(req, "notpresent", sizeof("notpresent"));
1142 return SYSCTL_OUT(req, "alive", sizeof("alive"));
1144 return SYSCTL_OUT(req, "attached", sizeof("attached"));
1146 return SYSCTL_OUT(req, "busy", sizeof("busy"));
1153 device_register_oids(device_t dev)
1155 struct sysctl_oid* oid;
1158 bzero(oid, sizeof(*oid));
1159 oid->oid_parent = &sysctl__hw_devices_children;
1160 oid->oid_number = OID_AUTO;
1161 oid->oid_kind = CTLTYPE_NODE | CTLFLAG_RW;
1162 oid->oid_arg1 = &dev->oidlist[0];
1164 oid->oid_name = dev->nameunit;
1165 oid->oid_handler = 0;
1167 SLIST_INIT(&dev->oidlist[0]);
1168 sysctl_register_oid(oid);
1171 bzero(oid, sizeof(*oid));
1172 oid->oid_parent = &dev->oidlist[0];
1173 oid->oid_number = OID_AUTO;
1174 oid->oid_kind = CTLTYPE_STRING | CTLFLAG_RD;
1175 oid->oid_arg1 = dev->desc ? dev->desc : "";
1176 oid->oid_arg2 = dev->desc ? strlen(dev->desc) : 0;
1177 oid->oid_name = "desc";
1178 oid->oid_handler = sysctl_handle_string;
1180 sysctl_register_oid(oid);
1183 bzero(oid, sizeof(*oid));
1184 oid->oid_parent = &dev->oidlist[0];
1185 oid->oid_number = OID_AUTO;
1186 oid->oid_kind = CTLTYPE_INT | CTLFLAG_RD;
1187 oid->oid_arg1 = dev;
1189 oid->oid_name = "children";
1190 oid->oid_handler = sysctl_handle_children;
1192 sysctl_register_oid(oid);
1195 bzero(oid, sizeof(*oid));
1196 oid->oid_parent = &dev->oidlist[0];
1197 oid->oid_number = OID_AUTO;
1198 oid->oid_kind = CTLTYPE_INT | CTLFLAG_RD;
1199 oid->oid_arg1 = dev;
1201 oid->oid_name = "state";
1202 oid->oid_handler = sysctl_handle_state;
1204 sysctl_register_oid(oid);
1208 device_unregister_oids(device_t dev)
1210 sysctl_unregister_oid(&dev->oid[0]);
1211 sysctl_unregister_oid(&dev->oid[1]);
1212 sysctl_unregister_oid(&dev->oid[2]);
1217 /*======================================*/
1219 * Access functions for device resources.
1222 /* Supplied by config(8) in ioconf.c */
1223 extern struct config_device config_devtab[];
1224 extern int devtab_count;
1226 /* Runtime version */
1227 struct config_device *devtab = config_devtab;
1230 resource_new_name(const char *name, int unit)
1232 struct config_device *new;
1234 new = malloc((devtab_count + 1) * sizeof(*new), M_TEMP,
1238 if (devtab && devtab_count > 0)
1239 bcopy(devtab, new, devtab_count * sizeof(*new));
1240 new[devtab_count].name = malloc(strlen(name) + 1, M_TEMP, M_NOWAIT);
1241 if (new[devtab_count].name == NULL) {
1245 strcpy(new[devtab_count].name, name);
1246 new[devtab_count].unit = unit;
1247 new[devtab_count].resource_count = 0;
1248 new[devtab_count].resources = NULL;
1250 return devtab_count++;
1254 resource_new_resname(int j, const char *resname, resource_type type)
1256 struct config_resource *new;
1259 i = devtab[j].resource_count;
1260 new = malloc((i + 1) * sizeof(*new), M_TEMP, M_NOWAIT | M_ZERO);
1263 if (devtab[j].resources && i > 0)
1264 bcopy(devtab[j].resources, new, i * sizeof(*new));
1265 new[i].name = malloc(strlen(resname) + 1, M_TEMP, M_NOWAIT);
1266 if (new[i].name == NULL) {
1270 strcpy(new[i].name, resname);
1272 if (devtab[j].resources)
1273 free(devtab[j].resources, M_TEMP);
1274 devtab[j].resources = new;
1275 devtab[j].resource_count = i + 1;
1280 resource_match_string(int i, const char *resname, const char *value)
1283 struct config_resource *res;
1285 for (j = 0, res = devtab[i].resources;
1286 j < devtab[i].resource_count; j++, res++)
1287 if (!strcmp(res->name, resname)
1288 && res->type == RES_STRING
1289 && !strcmp(res->u.stringval, value))
1295 resource_find(const char *name, int unit, const char *resname,
1296 struct config_resource **result)
1299 struct config_resource *res;
1302 * First check specific instances, then generic.
1304 for (i = 0; i < devtab_count; i++) {
1305 if (devtab[i].unit < 0)
1307 if (!strcmp(devtab[i].name, name) && devtab[i].unit == unit) {
1308 res = devtab[i].resources;
1309 for (j = 0; j < devtab[i].resource_count; j++, res++)
1310 if (!strcmp(res->name, resname)) {
1316 for (i = 0; i < devtab_count; i++) {
1317 if (devtab[i].unit >= 0)
1319 /* XXX should this `&& devtab[i].unit == unit' be here? */
1320 /* XXX if so, then the generic match does nothing */
1321 if (!strcmp(devtab[i].name, name) && devtab[i].unit == unit) {
1322 res = devtab[i].resources;
1323 for (j = 0; j < devtab[i].resource_count; j++, res++)
1324 if (!strcmp(res->name, resname)) {
1334 resource_int_value(const char *name, int unit, const char *resname, int *result)
1337 struct config_resource *res;
1339 if ((error = resource_find(name, unit, resname, &res)) != 0)
1341 if (res->type != RES_INT)
1343 *result = res->u.intval;
1348 resource_long_value(const char *name, int unit, const char *resname,
1352 struct config_resource *res;
1354 if ((error = resource_find(name, unit, resname, &res)) != 0)
1356 if (res->type != RES_LONG)
1358 *result = res->u.longval;
1363 resource_string_value(const char *name, int unit, const char *resname,
1367 struct config_resource *res;
1369 if ((error = resource_find(name, unit, resname, &res)) != 0)
1371 if (res->type != RES_STRING)
1373 *result = res->u.stringval;
1378 resource_query_string(int i, const char *resname, const char *value)
1384 for (; i < devtab_count; i++)
1385 if (resource_match_string(i, resname, value) >= 0)
1391 resource_locate(int i, const char *resname)
1397 for (; i < devtab_count; i++)
1398 if (!strcmp(devtab[i].name, resname))
1404 resource_count(void)
1406 return(devtab_count);
1410 resource_query_name(int i)
1412 return(devtab[i].name);
1416 resource_query_unit(int i)
1418 return(devtab[i].unit);
1422 resource_create(const char *name, int unit, const char *resname,
1423 resource_type type, struct config_resource **result)
1426 struct config_resource *res = NULL;
1428 for (i = 0; i < devtab_count; i++)
1429 if (!strcmp(devtab[i].name, name) && devtab[i].unit == unit) {
1430 res = devtab[i].resources;
1434 i = resource_new_name(name, unit);
1437 res = devtab[i].resources;
1439 for (j = 0; j < devtab[i].resource_count; j++, res++)
1440 if (!strcmp(res->name, resname)) {
1444 j = resource_new_resname(i, resname, type);
1447 res = &devtab[i].resources[j];
1453 resource_set_int(const char *name, int unit, const char *resname, int value)
1456 struct config_resource *res;
1458 error = resource_create(name, unit, resname, RES_INT, &res);
1461 if (res->type != RES_INT)
1463 res->u.intval = value;
1468 resource_set_long(const char *name, int unit, const char *resname, long value)
1471 struct config_resource *res;
1473 error = resource_create(name, unit, resname, RES_LONG, &res);
1476 if (res->type != RES_LONG)
1478 res->u.longval = value;
1483 resource_set_string(const char *name, int unit, const char *resname,
1487 struct config_resource *res;
1489 error = resource_create(name, unit, resname, RES_STRING, &res);
1492 if (res->type != RES_STRING)
1494 if (res->u.stringval)
1495 free(res->u.stringval, M_TEMP);
1496 res->u.stringval = malloc(strlen(value) + 1, M_TEMP, M_NOWAIT);
1497 if (res->u.stringval == NULL)
1499 strcpy(res->u.stringval, value);
1504 resource_cfgload(void *dummy __unused)
1506 struct config_resource *res, *cfgres;
1509 char *name, *resname;
1513 int config_devtab_count;
1515 config_devtab_count = devtab_count;
1519 for (i = 0; i < config_devtab_count; i++) {
1520 name = config_devtab[i].name;
1521 unit = config_devtab[i].unit;
1523 for (j = 0; j < config_devtab[i].resource_count; j++) {
1524 cfgres = config_devtab[i].resources;
1525 resname = cfgres[j].name;
1526 type = cfgres[j].type;
1527 error = resource_create(name, unit, resname, type,
1530 printf("create resource %s%d: error %d\n",
1534 if (res->type != type) {
1535 printf("type mismatch %s%d: %d != %d\n",
1536 name, unit, res->type, type);
1541 res->u.intval = cfgres[j].u.intval;
1544 res->u.longval = cfgres[j].u.longval;
1547 if (res->u.stringval)
1548 free(res->u.stringval, M_TEMP);
1549 stringval = cfgres[j].u.stringval;
1550 res->u.stringval = malloc(strlen(stringval) + 1,
1552 if (res->u.stringval == NULL)
1554 strcpy(res->u.stringval, stringval);
1557 panic("unknown resource type %d\n", type);
1562 SYSINIT(cfgload, SI_SUB_KMEM, SI_ORDER_ANY + 50, resource_cfgload, 0)
1565 /*======================================*/
1567 * Some useful method implementations to make life easier for bus drivers.
1571 resource_list_init(struct resource_list *rl)
1577 resource_list_free(struct resource_list *rl)
1579 struct resource_list_entry *rle;
1581 while ((rle = SLIST_FIRST(rl)) != NULL) {
1583 panic("resource_list_free: resource entry is busy");
1584 SLIST_REMOVE_HEAD(rl, link);
1590 resource_list_add(struct resource_list *rl,
1592 u_long start, u_long end, u_long count)
1594 struct resource_list_entry *rle;
1596 rle = resource_list_find(rl, type, rid);
1598 rle = malloc(sizeof(struct resource_list_entry), M_BUS, M_NOWAIT);
1600 panic("resource_list_add: can't record entry");
1601 SLIST_INSERT_HEAD(rl, rle, link);
1608 panic("resource_list_add: resource entry is busy");
1615 struct resource_list_entry*
1616 resource_list_find(struct resource_list *rl,
1619 struct resource_list_entry *rle;
1621 SLIST_FOREACH(rle, rl, link)
1622 if (rle->type == type && rle->rid == rid)
1628 resource_list_delete(struct resource_list *rl,
1631 struct resource_list_entry *rle = resource_list_find(rl, type, rid);
1634 SLIST_REMOVE(rl, rle, resource_list_entry, link);
1640 resource_list_alloc(struct resource_list *rl,
1641 device_t bus, device_t child,
1643 u_long start, u_long end,
1644 u_long count, u_int flags)
1646 struct resource_list_entry *rle = 0;
1647 int passthrough = (device_get_parent(child) != bus);
1648 int isdefault = (start == 0UL && end == ~0UL);
1651 return(BUS_ALLOC_RESOURCE(device_get_parent(bus), child,
1653 start, end, count, flags));
1656 rle = resource_list_find(rl, type, *rid);
1659 return(0); /* no resource of that type/rid */
1661 panic("resource_list_alloc: resource entry is busy");
1665 count = max(count, rle->count);
1666 end = max(rle->end, start + count - 1);
1669 rle->res = BUS_ALLOC_RESOURCE(device_get_parent(bus), child,
1670 type, rid, start, end, count, flags);
1673 * Record the new range.
1676 rle->start = rman_get_start(rle->res);
1677 rle->end = rman_get_end(rle->res);
1685 resource_list_release(struct resource_list *rl,
1686 device_t bus, device_t child,
1687 int type, int rid, struct resource *res)
1689 struct resource_list_entry *rle = 0;
1690 int passthrough = (device_get_parent(child) != bus);
1694 return(BUS_RELEASE_RESOURCE(device_get_parent(bus), child,
1698 rle = resource_list_find(rl, type, rid);
1701 panic("resource_list_release: can't find resource");
1703 panic("resource_list_release: resource entry is not busy");
1705 error = BUS_RELEASE_RESOURCE(device_get_parent(bus), child,
1715 resource_list_print_type(struct resource_list *rl, const char *name, int type,
1718 struct resource_list_entry *rle;
1719 int printed, retval;
1723 /* Yes, this is kinda cheating */
1724 SLIST_FOREACH(rle, rl, link) {
1725 if (rle->type == type) {
1727 retval += printf(" %s ", name);
1729 retval += printf(",");
1731 retval += printf(format, rle->start);
1732 if (rle->count > 1) {
1733 retval += printf("-");
1734 retval += printf(format, rle->start +
1743 * Call DEVICE_IDENTIFY for each driver.
1746 bus_generic_probe(device_t dev)
1748 devclass_t dc = dev->devclass;
1751 TAILQ_FOREACH(dl, &dc->drivers, link)
1752 DEVICE_IDENTIFY(dl->driver, dev);
1758 bus_generic_attach(device_t dev)
1762 TAILQ_FOREACH(child, &dev->children, link)
1763 device_probe_and_attach(child);
1769 bus_generic_detach(device_t dev)
1774 if (dev->state != DS_ATTACHED)
1777 TAILQ_FOREACH(child, &dev->children, link)
1778 if ((error = device_detach(child)) != 0)
1785 bus_generic_shutdown(device_t dev)
1789 TAILQ_FOREACH(child, &dev->children, link)
1790 device_shutdown(child);
1796 bus_generic_suspend(device_t dev)
1799 device_t child, child2;
1801 TAILQ_FOREACH(child, &dev->children, link) {
1802 error = DEVICE_SUSPEND(child);
1804 for (child2 = TAILQ_FIRST(&dev->children);
1805 child2 && child2 != child;
1806 child2 = TAILQ_NEXT(child2, link))
1807 DEVICE_RESUME(child2);
1815 bus_generic_resume(device_t dev)
1819 TAILQ_FOREACH(child, &dev->children, link)
1820 DEVICE_RESUME(child);
1821 /* if resume fails, there's nothing we can usefully do... */
1827 bus_print_child_header(device_t dev, device_t child)
1831 if (device_get_desc(child))
1832 retval += device_printf(child, "<%s>", device_get_desc(child));
1834 retval += printf("%s", device_get_nameunit(child));
1840 bus_print_child_footer(device_t dev, device_t child)
1842 return(printf(" on %s\n", device_get_nameunit(dev)));
1846 bus_generic_print_child(device_t dev, device_t child)
1850 retval += bus_print_child_header(dev, child);
1851 retval += bus_print_child_footer(dev, child);
1857 bus_generic_read_ivar(device_t dev, device_t child, int index,
1864 bus_generic_write_ivar(device_t dev, device_t child, int index,
1870 struct resource_list *
1871 bus_generic_get_resource_list(device_t dev, device_t child)
1877 bus_generic_driver_added(device_t dev, driver_t *driver)
1881 DEVICE_IDENTIFY(driver, dev);
1882 TAILQ_FOREACH(child, &dev->children, link)
1883 if (child->state == DS_NOTPRESENT)
1884 device_probe_and_attach(child);
1888 bus_generic_setup_intr(device_t dev, device_t child, struct resource *irq,
1889 int flags, driver_intr_t *intr, void *arg,
1892 /* Propagate up the bus hierarchy until someone handles it. */
1894 return(BUS_SETUP_INTR(dev->parent, child, irq, flags,
1895 intr, arg, cookiep));
1901 bus_generic_teardown_intr(device_t dev, device_t child, struct resource *irq,
1904 /* Propagate up the bus hierarchy until someone handles it. */
1906 return(BUS_TEARDOWN_INTR(dev->parent, child, irq, cookie));
1912 bus_generic_alloc_resource(device_t dev, device_t child, int type, int *rid,
1913 u_long start, u_long end, u_long count, u_int flags)
1915 /* Propagate up the bus hierarchy until someone handles it. */
1917 return(BUS_ALLOC_RESOURCE(dev->parent, child, type, rid,
1918 start, end, count, flags));
1924 bus_generic_release_resource(device_t dev, device_t child, int type, int rid,
1927 /* Propagate up the bus hierarchy until someone handles it. */
1929 return(BUS_RELEASE_RESOURCE(dev->parent, child, type, rid, r));
1935 bus_generic_activate_resource(device_t dev, device_t child, int type, int rid,
1938 /* Propagate up the bus hierarchy until someone handles it. */
1940 return(BUS_ACTIVATE_RESOURCE(dev->parent, child, type, rid, r));
1946 bus_generic_deactivate_resource(device_t dev, device_t child, int type,
1947 int rid, struct resource *r)
1949 /* Propagate up the bus hierarchy until someone handles it. */
1951 return(BUS_DEACTIVATE_RESOURCE(dev->parent, child, type, rid,
1958 bus_generic_config_intr(device_t dev, int irq, enum intr_trigger trig,
1959 enum intr_polarity pol)
1961 /* Propagate up the bus hierarchy until someone handles it. */
1963 return(BUS_CONFIG_INTR(dev->parent, irq, trig, pol));
1969 bus_generic_rl_get_resource(device_t dev, device_t child, int type, int rid,
1970 u_long *startp, u_long *countp)
1972 struct resource_list *rl = NULL;
1973 struct resource_list_entry *rle = NULL;
1975 rl = BUS_GET_RESOURCE_LIST(dev, child);
1979 rle = resource_list_find(rl, type, rid);
1984 *startp = rle->start;
1986 *countp = rle->count;
1992 bus_generic_rl_set_resource(device_t dev, device_t child, int type, int rid,
1993 u_long start, u_long count)
1995 struct resource_list *rl = NULL;
1997 rl = BUS_GET_RESOURCE_LIST(dev, child);
2001 resource_list_add(rl, type, rid, start, (start + count - 1), count);
2007 bus_generic_rl_delete_resource(device_t dev, device_t child, int type, int rid)
2009 struct resource_list *rl = NULL;
2011 rl = BUS_GET_RESOURCE_LIST(dev, child);
2015 resource_list_delete(rl, type, rid);
2019 bus_generic_rl_release_resource(device_t dev, device_t child, int type,
2020 int rid, struct resource *r)
2022 struct resource_list *rl = NULL;
2024 rl = BUS_GET_RESOURCE_LIST(dev, child);
2028 return(resource_list_release(rl, dev, child, type, rid, r));
2032 bus_generic_rl_alloc_resource(device_t dev, device_t child, int type,
2033 int *rid, u_long start, u_long end, u_long count, u_int flags)
2035 struct resource_list *rl = NULL;
2037 rl = BUS_GET_RESOURCE_LIST(dev, child);
2041 return(resource_list_alloc(rl, dev, child, type, rid,
2042 start, end, count, flags));
2046 bus_generic_child_present(device_t bus, device_t child)
2048 return(BUS_CHILD_PRESENT(device_get_parent(bus), bus));
2053 * Some convenience functions to make it easier for drivers to use the
2054 * resource-management functions. All these really do is hide the
2055 * indirection through the parent's method table, making for slightly
2056 * less-wordy code. In the future, it might make sense for this code
2057 * to maintain some sort of a list of resources allocated by each device.
2060 bus_alloc_resource(device_t dev, int type, int *rid, u_long start, u_long end,
2061 u_long count, u_int flags)
2063 if (dev->parent == 0)
2065 return(BUS_ALLOC_RESOURCE(dev->parent, dev, type, rid, start, end,
2070 bus_activate_resource(device_t dev, int type, int rid, struct resource *r)
2072 if (dev->parent == 0)
2074 return(BUS_ACTIVATE_RESOURCE(dev->parent, dev, type, rid, r));
2078 bus_deactivate_resource(device_t dev, int type, int rid, struct resource *r)
2080 if (dev->parent == 0)
2082 return(BUS_DEACTIVATE_RESOURCE(dev->parent, dev, type, rid, r));
2086 bus_release_resource(device_t dev, int type, int rid, struct resource *r)
2088 if (dev->parent == 0)
2090 return(BUS_RELEASE_RESOURCE(dev->parent, dev, type, rid, r));
2094 bus_setup_intr(device_t dev, struct resource *r, int flags,
2095 driver_intr_t handler, void *arg, void **cookiep)
2097 if (dev->parent == 0)
2099 return(BUS_SETUP_INTR(dev->parent, dev, r, flags, handler, arg,
2104 bus_teardown_intr(device_t dev, struct resource *r, void *cookie)
2106 if (dev->parent == 0)
2108 return(BUS_TEARDOWN_INTR(dev->parent, dev, r, cookie));
2112 bus_set_resource(device_t dev, int type, int rid,
2113 u_long start, u_long count)
2115 return(BUS_SET_RESOURCE(device_get_parent(dev), dev, type, rid,
2120 bus_get_resource(device_t dev, int type, int rid,
2121 u_long *startp, u_long *countp)
2123 return(BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid,
2128 bus_get_resource_start(device_t dev, int type, int rid)
2130 u_long start, count;
2133 error = BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid,
2141 bus_get_resource_count(device_t dev, int type, int rid)
2143 u_long start, count;
2146 error = BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid,
2154 bus_delete_resource(device_t dev, int type, int rid)
2156 BUS_DELETE_RESOURCE(device_get_parent(dev), dev, type, rid);
2160 root_print_child(device_t dev, device_t child)
2166 root_setup_intr(device_t dev, device_t child, driver_intr_t *intr, void *arg,
2170 * If an interrupt mapping gets to here something bad has happened.
2172 panic("root_setup_intr");
2176 * If we get here, assume that the device is permanant and really is
2177 * present in the system. Removable bus drivers are expected to intercept
2178 * this call long before it gets here. We return -1 so that drivers that
2179 * really care can check vs -1 or some ERRNO returned higher in the food
2183 root_child_present(device_t dev, device_t child)
2189 * XXX NOTE! other defaults may be set in bus_if.m
2191 static kobj_method_t root_methods[] = {
2192 /* Device interface */
2193 KOBJMETHOD(device_shutdown, bus_generic_shutdown),
2194 KOBJMETHOD(device_suspend, bus_generic_suspend),
2195 KOBJMETHOD(device_resume, bus_generic_resume),
2198 KOBJMETHOD(bus_print_child, root_print_child),
2199 KOBJMETHOD(bus_read_ivar, bus_generic_read_ivar),
2200 KOBJMETHOD(bus_write_ivar, bus_generic_write_ivar),
2201 KOBJMETHOD(bus_setup_intr, root_setup_intr),
2202 KOBJMETHOD(bus_child_present, root_child_present),
2207 static driver_t root_driver = {
2214 devclass_t root_devclass;
2217 root_bus_module_handler(module_t mod, int what, void* arg)
2221 kobj_class_compile((kobj_class_t) &root_driver);
2222 root_bus = make_device(NULL, "root", 0);
2223 root_bus->desc = "System root bus";
2224 kobj_init((kobj_t) root_bus, (kobj_class_t) &root_driver);
2225 root_bus->driver = &root_driver;
2226 root_bus->state = DS_ATTACHED;
2227 root_devclass = devclass_find_internal("root", FALSE);
2231 device_shutdown(root_bus);
2238 static moduledata_t root_bus_mod = {
2240 root_bus_module_handler,
2243 DECLARE_MODULE(rootbus, root_bus_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
2246 root_bus_configure(void)
2252 TAILQ_FOREACH(dev, &root_bus->children, link)
2253 device_probe_and_attach(dev);
2257 driver_module_handler(module_t mod, int what, void *arg)
2260 struct driver_module_data *dmd;
2261 devclass_t bus_devclass;
2263 dmd = (struct driver_module_data *)arg;
2264 bus_devclass = devclass_find_internal(dmd->dmd_busname, TRUE);
2269 if (dmd->dmd_chainevh)
2270 error = dmd->dmd_chainevh(mod,what,dmd->dmd_chainarg);
2272 for (i = 0; !error && i < dmd->dmd_ndrivers; i++) {
2273 PDEBUG(("Loading module: driver %s on bus %s",
2274 DRIVERNAME(dmd->dmd_drivers[i]),
2276 error = devclass_add_driver(bus_devclass,
2277 dmd->dmd_drivers[i]);
2283 * The drivers loaded in this way are assumed to all
2284 * implement the same devclass.
2286 *dmd->dmd_devclass =
2287 devclass_find_internal(dmd->dmd_drivers[0]->name,
2292 for (i = 0; !error && i < dmd->dmd_ndrivers; i++) {
2293 PDEBUG(("Unloading module: driver %s from bus %s",
2294 DRIVERNAME(dmd->dmd_drivers[i]),
2296 error = devclass_delete_driver(bus_devclass,
2297 dmd->dmd_drivers[i]);
2300 if (!error && dmd->dmd_chainevh)
2301 error = dmd->dmd_chainevh(mod,what,dmd->dmd_chainarg);
2311 * The _short versions avoid iteration by not calling anything that prints
2312 * more than oneliners. I love oneliners.
2316 print_device_short(device_t dev, int indent)
2321 indentprintf(("device %d: <%s> %sparent,%schildren,%s%s%s%s,%sivars,%ssoftc,busy=%d\n",
2322 dev->unit, dev->desc,
2323 (dev->parent? "":"no "),
2324 (TAILQ_EMPTY(&dev->children)? "no ":""),
2325 (dev->flags&DF_ENABLED? "enabled,":"disabled,"),
2326 (dev->flags&DF_FIXEDCLASS? "fixed,":""),
2327 (dev->flags&DF_WILDCARD? "wildcard,":""),
2328 (dev->flags&DF_DESCMALLOCED? "descmalloced,":""),
2329 (dev->ivars? "":"no "),
2330 (dev->softc? "":"no "),
2335 print_device(device_t dev, int indent)
2340 print_device_short(dev, indent);
2342 indentprintf(("Parent:\n"));
2343 print_device_short(dev->parent, indent+1);
2344 indentprintf(("Driver:\n"));
2345 print_driver_short(dev->driver, indent+1);
2346 indentprintf(("Devclass:\n"));
2347 print_devclass_short(dev->devclass, indent+1);
2351 * Print the device and all its children (indented).
2354 print_device_tree_short(device_t dev, int indent)
2361 print_device_short(dev, indent);
2363 TAILQ_FOREACH(child, &dev->children, link)
2364 print_device_tree_short(child, indent+1);
2368 * Print the device and all its children (indented).
2371 print_device_tree(device_t dev, int indent)
2378 print_device(dev, indent);
2380 TAILQ_FOREACH(child, &dev->children, link)
2381 print_device_tree(child, indent+1);
2385 print_driver_short(driver_t *driver, int indent)
2390 indentprintf(("driver %s: softc size = %d\n",
2391 driver->name, driver->size));
2395 print_driver(driver_t *driver, int indent)
2400 print_driver_short(driver, indent);
2405 print_driver_list(driver_list_t drivers, int indent)
2407 driverlink_t driver;
2409 TAILQ_FOREACH(driver, &drivers, link)
2410 print_driver(driver->driver, indent);
2414 print_devclass_short(devclass_t dc, int indent)
2419 indentprintf(("devclass %s: max units = %d\n", dc->name, dc->maxunit));
2423 print_devclass(devclass_t dc, int indent)
2430 print_devclass_short(dc, indent);
2431 indentprintf(("Drivers:\n"));
2432 print_driver_list(dc->drivers, indent+1);
2434 indentprintf(("Devices:\n"));
2435 for (i = 0; i < dc->maxunit; i++)
2437 print_device(dc->devices[i], indent+1);
2441 print_devclass_list_short(void)
2445 printf("Short listing of devclasses, drivers & devices:\n");
2446 TAILQ_FOREACH(dc, &devclasses, link) {
2447 print_devclass_short(dc, 0);
2452 print_devclass_list(void)
2456 printf("Full listing of devclasses, drivers & devices:\n");
2457 TAILQ_FOREACH(dc, &devclasses, link) {
2458 print_devclass(dc, 0);
2465 * Check to see if a device is disabled via a disabled hint.
2468 resource_disabled(const char *name, int unit)
2472 error = resource_int_value(name, unit, "disabled", &value);