Rename printf -> kprintf in sys/ and add some defines where necessary
[dragonfly.git] / sys / kern / subr_autoconf.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
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.
8 *
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.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
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. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the University of
25 * California, Berkeley and its contributors.
26 * 4. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 * @(#)subr_autoconf.c 8.1 (Berkeley) 6/10/93
43 *
44 * $FreeBSD: src/sys/kern/subr_autoconf.c,v 1.14 1999/10/05 21:19:41 n_hibma Exp $
6ea70f76 45 * $DragonFly: src/sys/kern/subr_autoconf.c,v 1.8 2006/12/23 00:35:04 swildner Exp $
984263bc
MD
46 */
47
48#include <sys/param.h>
49#include <sys/kernel.h>
50#include <sys/systm.h>
a1e26a0c
MD
51#include <sys/thread.h>
52#include <sys/thread2.h>
984263bc
MD
53
54/*
55 * Autoconfiguration subroutines.
56 */
57
58/*
59 * "Interrupt driven config" functions.
60 */
61static TAILQ_HEAD(, intr_config_hook) intr_config_hook_list =
62 TAILQ_HEAD_INITIALIZER(intr_config_hook_list);
63
64
65/* ARGSUSED */
402ed7e1 66static void run_interrupt_driven_config_hooks (void *dummy);
fbda7fa6 67
984263bc 68static void
fbda7fa6 69run_interrupt_driven_config_hooks(void *dummy)
984263bc
MD
70{
71 struct intr_config_hook *hook_entry, *next_entry;
a1e26a0c 72 int waiting;
984263bc
MD
73
74 for (hook_entry = TAILQ_FIRST(&intr_config_hook_list);
75 hook_entry != NULL;
76 hook_entry = next_entry) {
77 next_entry = TAILQ_NEXT(hook_entry, ich_links);
78 (*hook_entry->ich_func)(hook_entry->ich_arg);
79 }
80
a1e26a0c 81 waiting = 0;
984263bc 82 while (!TAILQ_EMPTY(&intr_config_hook_list)) {
8a4ec7a1 83 if (waiting >= 20) {
a1e26a0c 84 crit_enter();
6ea70f76 85 kprintf("**WARNING** waiting for the following device to finish configuring:\n");
a1e26a0c 86 TAILQ_FOREACH(hook_entry, &intr_config_hook_list, ich_links) {
6ea70f76 87 kprintf(" %s:\tfunc=%p arg=%p\n",
a1e26a0c
MD
88 (hook_entry->ich_desc ?
89 hook_entry->ich_desc : "?"),
90 hook_entry->ich_func,
91 hook_entry->ich_arg);
92 }
93 crit_exit();
94 if (waiting >= 60) {
6ea70f76 95 kprintf("Giving up, interrupt routing is probably hosed\n");
a1e26a0c
MD
96 break;
97 }
98 }
99 tsleep(&intr_config_hook_list, 0, "conifhk", hz * 10);
100 waiting += 10;
984263bc
MD
101 }
102}
103SYSINIT(intr_config_hooks, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_FIRST,
104 run_interrupt_driven_config_hooks, NULL)
105
106/*
107 * Register a hook that will be called after "cold"
108 * autoconfiguration is complete and interrupts can
109 * be used to complete initialization.
110 */
111int
fbda7fa6 112config_intrhook_establish(struct intr_config_hook *hook)
984263bc
MD
113{
114 struct intr_config_hook *hook_entry;
115
116 for (hook_entry = TAILQ_FIRST(&intr_config_hook_list);
117 hook_entry != NULL;
118 hook_entry = TAILQ_NEXT(hook_entry, ich_links))
119 if (hook_entry == hook)
120 break;
121 if (hook_entry != NULL) {
6ea70f76 122 kprintf("config_intrhook_establish: establishing an "
984263bc
MD
123 "already established hook.\n");
124 return (1);
125 }
126 TAILQ_INSERT_TAIL(&intr_config_hook_list, hook, ich_links);
127 if (cold == 0)
128 /* XXX Sufficient for modules loaded after initial config??? */
129 run_interrupt_driven_config_hooks(NULL);
130 return (0);
131}
132
133void
fbda7fa6 134config_intrhook_disestablish(struct intr_config_hook *hook)
984263bc
MD
135{
136 struct intr_config_hook *hook_entry;
137
138 for (hook_entry = TAILQ_FIRST(&intr_config_hook_list);
139 hook_entry != NULL;
140 hook_entry = TAILQ_NEXT(hook_entry, ich_links))
141 if (hook_entry == hook)
142 break;
143 if (hook_entry == NULL)
144 panic("config_intrhook_disestablish: disestablishing an "
fbda7fa6 145 "unestablished hook");
984263bc
MD
146
147 TAILQ_REMOVE(&intr_config_hook_list, hook, ich_links);
148 /* Wakeup anyone watching the list */
149 wakeup(&intr_config_hook_list);
150}