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 * All advertising materials mentioning features or use of this software
10 * must display the following acknowledgement:
11 * This product includes software developed by the University of
12 * California, Lawrence Berkeley Laboratories.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)subr_autoconf.c 8.1 (Berkeley) 6/10/93
40 * $FreeBSD: src/sys/kern/subr_autoconf.c,v 1.14 1999/10/05 21:19:41 n_hibma Exp $
41 * $DragonFly: src/sys/kern/subr_autoconf.c,v 1.9 2007/07/28 23:24:33 dillon Exp $
44 #include <sys/param.h>
45 #include <sys/kernel.h>
46 #include <sys/systm.h>
47 #include <sys/thread.h>
48 #include <sys/thread2.h>
51 * Autoconfiguration subroutines.
55 * "Interrupt driven config" functions.
57 static TAILQ_HEAD(, intr_config_hook) intr_config_hook_list =
58 TAILQ_HEAD_INITIALIZER(intr_config_hook_list);
62 static void run_interrupt_driven_config_hooks (void *dummy);
63 static int ran_config_hooks;
66 run_interrupt_driven_config_hooks(void *dummy)
68 struct intr_config_hook *hook_entry;
70 #ifndef _KERNEL_VIRTUAL
71 int save_ticks = ticks;
76 while (!TAILQ_EMPTY(&intr_config_hook_list)) {
77 TAILQ_FOREACH(hook_entry, &intr_config_hook_list, ich_links) {
78 if (hook_entry->ich_ran == 0) {
79 hook_entry->ich_ran = 1;
80 (*hook_entry->ich_func)(hook_entry->ich_arg);
86 if (TAILQ_EMPTY(&intr_config_hook_list))
89 if (waiting >= 20 && (waiting % 10) == 0) {
91 kprintf("**WARNING** waiting for the following device "
92 "to finish configuring:\n");
93 TAILQ_FOREACH(hook_entry, &intr_config_hook_list,
95 kprintf(" %s:\tfunc=%p arg=%p\n",
96 (hook_entry->ich_desc ?
97 hook_entry->ich_desc : "?"),
103 kprintf("Giving up, interrupt routing is "
108 tsleep(&intr_config_hook_list, 0, "conifhk", hz);
113 * Terrible hack to give U4B (usb) a chance to configure, else
114 * the root mount might not see a valid usb device. This can happen
115 * because the AHCI devices might have already finished probing
116 * before the usb ports are even registered.
118 #ifndef _KERNEL_VIRTUAL
119 while (ticks - save_ticks < 5*hz)
120 tsleep(&intr_config_hook_list, 0, "delay", hz / 10);
124 SYSINIT(intr_config_hooks, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_FIRST,
125 run_interrupt_driven_config_hooks, NULL)
128 * Register a hook that will be called after "cold"
129 * autoconfiguration is complete and interrupts can
130 * be used to complete initialization.
133 config_intrhook_establish(struct intr_config_hook *hook)
135 struct intr_config_hook *hook_entry;
137 for (hook_entry = TAILQ_FIRST(&intr_config_hook_list);
139 hook_entry = TAILQ_NEXT(hook_entry, ich_links)) {
140 if (hook_entry == hook)
142 if (hook_entry->ich_order > hook->ich_order)
145 if (hook_entry == hook) {
146 kprintf("config_intrhook_establish: establishing an "
147 "already established hook.\n");
152 TAILQ_INSERT_BEFORE(hook_entry, hook, ich_links);
154 TAILQ_INSERT_TAIL(&intr_config_hook_list, hook, ich_links);
157 * Late hook, run immediately.
159 if (ran_config_hooks)
160 run_interrupt_driven_config_hooks(NULL);
165 config_intrhook_disestablish(struct intr_config_hook *hook)
167 struct intr_config_hook *hook_entry;
169 for (hook_entry = TAILQ_FIRST(&intr_config_hook_list);
171 hook_entry = TAILQ_NEXT(hook_entry, ich_links))
172 if (hook_entry == hook)
174 if (hook_entry == NULL)
175 panic("config_intrhook_disestablish: disestablishing an "
176 "unestablished hook");
178 TAILQ_REMOVE(&intr_config_hook_list, hook, ich_links);
179 /* Wakeup anyone watching the list */
180 wakeup(&intr_config_hook_list);