subr_autoconf.c revision 51684
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: head/sys/kern/subr_autoconf.c 51684 1999-09-26 18:48:53Z n_hibma $
45 */
46
47#include <sys/param.h>
48#include <sys/kernel.h>
49#include <sys/systm.h>
50#include <sys/device.h>
51
52/*
53 * Autoconfiguration subroutines.
54 */
55
56/*
57 * "Interrupt driven config" functions.
58 */
59static TAILQ_HEAD(, intr_config_hook) intr_config_hook_list =
60	TAILQ_HEAD_INITIALIZER(intr_config_hook_list);
61
62
63/* ARGSUSED */
64static void run_interrupt_driven_config_hooks __P((void *dummy));
65static void
66run_interrupt_driven_config_hooks(dummy)
67	void *dummy;
68{
69	struct intr_config_hook *hook_entry, *next_entry;
70
71	for (hook_entry = TAILQ_FIRST(&intr_config_hook_list);
72	     hook_entry != NULL;
73	     hook_entry = next_entry) {
74		next_entry = TAILQ_NEXT(hook_entry, ich_links);
75		(*hook_entry->ich_func)(hook_entry->ich_arg);
76	}
77
78	while (!TAILQ_EMPTY(&intr_config_hook_list)) {
79		tsleep(&intr_config_hook_list, PCONFIG, "conifhk", 0);
80	}
81}
82SYSINIT(intr_config_hooks, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_FIRST,
83	run_interrupt_driven_config_hooks, NULL)
84
85/*
86 * Register a hook that will be called after "cold"
87 * autoconfiguration is complete and interrupts can
88 * be used to complete initialization.
89 */
90int
91config_intrhook_establish(hook)
92	struct intr_config_hook *hook;
93{
94	struct intr_config_hook *hook_entry;
95
96	for (hook_entry = TAILQ_FIRST(&intr_config_hook_list);
97	     hook_entry != NULL;
98	     hook_entry = TAILQ_NEXT(hook_entry, ich_links))
99		if (hook_entry == hook)
100			break;
101	if (hook_entry != NULL) {
102		printf("config_intrhook_establish: establishing an "
103		       "already established hook.\n");
104		return (1);
105	}
106	TAILQ_INSERT_TAIL(&intr_config_hook_list, hook, ich_links);
107	if (cold == 0)
108		/* XXX Sufficient for modules loaded after initial config??? */
109		run_interrupt_driven_config_hooks(NULL);
110	return (0);
111}
112
113void
114config_intrhook_disestablish(hook)
115	struct intr_config_hook *hook;
116{
117	struct intr_config_hook *hook_entry;
118
119	for (hook_entry = TAILQ_FIRST(&intr_config_hook_list);
120	     hook_entry != NULL;
121	     hook_entry = TAILQ_NEXT(hook_entry, ich_links))
122		if (hook_entry == hook)
123			break;
124	if (hook_entry == NULL)
125		panic("config_intrhook_disestablish: disestablishing an "
126		      "unestablished hook");
127
128	TAILQ_REMOVE(&intr_config_hook_list, hook, ich_links);
129	/* Wakeup anyone watching the list */
130	wakeup(&intr_config_hook_list);
131}
132