2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This software was developed by the Computer Systems Engineering group
6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 * contributed to Berkeley.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)subr_autoconf.c 8.1 (Berkeley) 6/10/93
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
42 #include <sys/param.h>
43 #include <sys/kernel.h>
44 #include <sys/linker.h>
46 #include <sys/mutex.h>
47 #include <sys/systm.h>
50 * Autoconfiguration subroutines.
54 * "Interrupt driven config" functions.
56 static TAILQ_HEAD(, intr_config_hook) intr_config_hook_list =
57 TAILQ_HEAD_INITIALIZER(intr_config_hook_list);
58 static struct mtx intr_config_hook_lock;
59 MTX_SYSINIT(intr_config_hook, &intr_config_hook_lock, "intr config", MTX_DEF);
62 static void run_interrupt_driven_config_hooks(void *dummy);
65 * If we wait too long for an interrupt-driven config hook to return, print
68 #define WARNING_INTERVAL_SECS 60
70 run_interrupt_driven_config_hooks_warning(int warned)
72 struct intr_config_hook *hook_entry;
77 printf("run_interrupt_driven_hooks: still waiting after %d "
78 "seconds for", warned * WARNING_INTERVAL_SECS);
79 TAILQ_FOREACH(hook_entry, &intr_config_hook_list, ich_links) {
80 if (linker_search_symbol_name(
81 (caddr_t)hook_entry->ich_func, namebuf,
82 sizeof(namebuf), &offset) == 0)
83 printf(" %s", namebuf);
85 printf(" %p", hook_entry->ich_func);
90 ("run_interrupt_driven_config_hooks: waited too long"));
94 run_interrupt_driven_config_hooks(void *dummy)
96 struct intr_config_hook *hook_entry, *next_entry;
99 mtx_lock(&intr_config_hook_lock);
100 TAILQ_FOREACH_SAFE(hook_entry, &intr_config_hook_list, ich_links,
102 mtx_unlock(&intr_config_hook_lock);
103 (*hook_entry->ich_func)(hook_entry->ich_arg);
104 mtx_lock(&intr_config_hook_lock);
108 while (!TAILQ_EMPTY(&intr_config_hook_list)) {
109 if (msleep(&intr_config_hook_list, &intr_config_hook_lock,
110 PCONFIG, "conifhk", WARNING_INTERVAL_SECS * hz) ==
112 mtx_unlock(&intr_config_hook_lock);
114 run_interrupt_driven_config_hooks_warning(warned);
115 mtx_lock(&intr_config_hook_lock);
118 mtx_unlock(&intr_config_hook_lock);
120 SYSINIT(intr_config_hooks, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_FIRST,
121 run_interrupt_driven_config_hooks, NULL);
124 * Register a hook that will be called after "cold"
125 * autoconfiguration is complete and interrupts can
126 * be used to complete initialization.
129 config_intrhook_establish(struct intr_config_hook *hook)
131 struct intr_config_hook *hook_entry;
133 mtx_lock(&intr_config_hook_lock);
134 TAILQ_FOREACH(hook_entry, &intr_config_hook_list, ich_links)
135 if (hook_entry == hook)
137 if (hook_entry != NULL) {
138 mtx_unlock(&intr_config_hook_lock);
139 printf("config_intrhook_establish: establishing an "
140 "already established hook.\n");
143 TAILQ_INSERT_TAIL(&intr_config_hook_list, hook, ich_links);
144 mtx_unlock(&intr_config_hook_lock);
146 /* XXX Sufficient for modules loaded after initial config??? */
147 run_interrupt_driven_config_hooks(NULL);
152 config_intrhook_disestablish(struct intr_config_hook *hook)
154 struct intr_config_hook *hook_entry;
156 mtx_lock(&intr_config_hook_lock);
157 TAILQ_FOREACH(hook_entry, &intr_config_hook_list, ich_links)
158 if (hook_entry == hook)
160 if (hook_entry == NULL)
161 panic("config_intrhook_disestablish: disestablishing an "
162 "unestablished hook");
164 TAILQ_REMOVE(&intr_config_hook_list, hook, ich_links);
166 /* Wakeup anyone watching the list */
167 wakeup(&intr_config_hook_list);
168 mtx_unlock(&intr_config_hook_lock);
174 DB_SHOW_COMMAND(conifhk, db_show_conifhk)
176 struct intr_config_hook *hook_entry;
180 TAILQ_FOREACH(hook_entry, &intr_config_hook_list, ich_links) {
181 if (linker_ddb_search_symbol_name(
182 (caddr_t)hook_entry->ich_func, namebuf, sizeof(namebuf),
184 db_printf("hook: %p at %s+%#lx arg: %p\n",
185 hook_entry->ich_func, namebuf, offset,
186 hook_entry->ich_arg);
188 db_printf("hook: %p at ??+?? arg %p\n",
189 hook_entry->ich_func, hook_entry->ich_arg);