summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/i2o/iop.c5
-rw-r--r--sys/kern/init_main.c4
-rw-r--r--sys/kern/kern_subr.c75
-rw-r--r--sys/sys/systm.h41
4 files changed, 76 insertions, 49 deletions
diff --git a/sys/dev/i2o/iop.c b/sys/dev/i2o/iop.c
index 4e010c434e8..a84409b74a3 100644
--- a/sys/dev/i2o/iop.c
+++ b/sys/dev/i2o/iop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: iop.c,v 1.17 2001/06/29 05:40:32 niklas Exp $ */
+/* $OpenBSD: iop.c,v 1.18 2001/07/27 09:55:08 niklas Exp $ */
/* $NetBSD: iop.c,v 1.12 2001/03/21 14:27:05 ad Exp $ */
/*-
@@ -402,6 +402,7 @@ iop_init(struct iop_softc *sc, const char *intrstr)
lockinit(&sc->sc_conflock, PRIBIO, "iopconf", hz * 30, 0);
+ startuphook_establish((void (*)(void *))iop_config_interrupts, sc);
kthread_create_deferred(iop_create_reconf_thread, sc);
return;
@@ -560,8 +561,6 @@ iop_create_reconf_thread(void *cookie)
sc = cookie;
sc->sc_flags |= IOP_ONLINE;
- iop_config_interrupts(cookie);
-
rv = kthread_create(iop_reconf_thread, sc, &sc->sc_reconf_proc,
"%s", sc->sc_dv.dv_xname);
if (rv != 0) {
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 61f2ade8124..2f6d4da0e1e 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.72 2001/07/05 10:12:24 art Exp $ */
+/* $OpenBSD: init_main.c,v 1.73 2001/07/27 09:55:07 niklas Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -360,6 +360,8 @@ main(framep)
/* Start the scheduler */
scheduler_start();
+ dostartuphooks();
+
/* Configure root/swap devices */
if (md_diskconf)
(*md_diskconf)();
diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c
index 69e9117c6e4..70b9dcecfe0 100644
--- a/sys/kern/kern_subr.c
+++ b/sys/kern/kern_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_subr.c,v 1.19 2001/06/27 04:49:45 art Exp $ */
+/* $OpenBSD: kern_subr.c,v 1.20 2001/07/27 09:55:07 niklas Exp $ */
/* $NetBSD: kern_subr.c,v 1.15 1996/04/09 17:21:56 ragge Exp $ */
/*
@@ -183,72 +183,71 @@ hashinit(elements, type, flags, hashmask)
}
/*
- * "Shutdown hook" types, functions, and variables.
+ * "Shutdown/startup hook" types, functions, and variables.
*/
-struct shutdownhook_desc {
- LIST_ENTRY(shutdownhook_desc) sfd_list;
- void (*sfd_fn) __P((void *));
- void *sfd_arg;
-};
-
-LIST_HEAD(, shutdownhook_desc) shutdownhook_list;
-
-int shutdownhooks_done;
+struct hook_desc_head startuphook_list =
+ TAILQ_HEAD_INITIALIZER(startuphook_list);
+struct hook_desc_head shutdownhook_list =
+ TAILQ_HEAD_INITIALIZER(shutdownhook_list);
void *
-shutdownhook_establish(fn, arg)
+hook_establish(head, tail, fn, arg)
+ struct hook_desc_head *head;
+ int tail;
void (*fn) __P((void *));
void *arg;
{
- struct shutdownhook_desc *ndp;
+ struct hook_desc *hdp;
- ndp = (struct shutdownhook_desc *)
- malloc(sizeof (*ndp), M_DEVBUF, M_NOWAIT);
- if (ndp == NULL)
- return NULL;
+ hdp = (struct hook_desc *)malloc(sizeof (*hdp), M_DEVBUF, M_NOWAIT);
+ if (hdp == NULL)
+ return (NULL);
- ndp->sfd_fn = fn;
- ndp->sfd_arg = arg;
- LIST_INSERT_HEAD(&shutdownhook_list, ndp, sfd_list);
+ hdp->hd_fn = fn;
+ hdp->hd_arg = arg;
+ if (tail)
+ TAILQ_INSERT_TAIL(head, hdp, hd_list);
+ else
+ TAILQ_INSERT_HEAD(head, hdp, hd_list);
- return (ndp);
+ return (hdp);
}
void
-shutdownhook_disestablish(vhook)
+hook_disestablish(head, vhook)
+ struct hook_desc_head *head;
void *vhook;
{
#ifdef DIAGNOSTIC
- struct shutdownhook_desc *dp;
+ struct hook_desc *hdp;
- for (dp = shutdownhook_list.lh_first; dp != NULL;
- dp = dp->sfd_list.le_next)
- if (dp == vhook)
+ for (hdp = TAILQ_FIRST(head); hdp != NULL;
+ hdp = TAILQ_NEXT(hdp, hd_list))
+ if (hdp == vhook)
break;
- if (dp == NULL)
- panic("shutdownhook_disestablish: hook not established");
+ if (hdp == NULL)
+ panic("hook_disestablish: hook not established");
#endif
- LIST_REMOVE((struct shutdownhook_desc *)vhook, sfd_list);
+ TAILQ_REMOVE(head, (struct hook_desc *)vhook, hd_list);
}
/*
- * Run shutdown hooks. Should be invoked immediately before the
+ * Run hooks. Startup hooks are invoked right after scheduler_start but
+ * before root is mounted. Shutdown hooks are invoked immediately before the
* system is halted or rebooted, i.e. after file systems unmounted,
* after crash dump done, etc.
*/
void
-doshutdownhooks()
+dohooks(head)
+ struct hook_desc_head *head;
{
- struct shutdownhook_desc *dp;
-
- if (shutdownhooks_done)
- return;
+ struct hook_desc *hdp;
- for (dp = shutdownhook_list.lh_first; dp != NULL; dp =
- dp->sfd_list.le_next)
- (*dp->sfd_fn)(dp->sfd_arg);
+ for (hdp = TAILQ_FIRST(head); hdp != NULL;
+ hdp = TAILQ_NEXT(hdp, hd_list))
+ (*hdp->hd_fn)(hdp->hd_arg);
}
/*
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index 7cab4c0cd98..f2357b4d0dc 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: systm.h,v 1.40 2001/06/27 04:51:49 art Exp $ */
+/* $OpenBSD: systm.h,v 1.41 2001/07/27 09:55:07 niklas Exp $ */
/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */
/*-
@@ -44,6 +44,7 @@
#ifndef __SYSTM_H__
#define __SYSTM_H__
+#include <sys/queue.h>
#include <machine/stdarg.h>
/*
@@ -230,15 +231,41 @@ void stopprofclock __P((struct proc *));
void setstatclockrate __P((int));
/*
- * Shutdown hooks. Functions to be run with all interrupts disabled
- * immediately before the system is halted or rebooted.
+ * Startup/shutdown hooks. Startup hooks are functions running after
+ * the scheduler has started but before any threads have been created
+ * or root has been mounted The shutdown hooks are functions to be run
+ * with all interrupts disabled immediately before the system is
+ * halted or rebooted.
*/
-void *shutdownhook_establish __P((void (*)(void *), void *));
-void shutdownhook_disestablish __P((void *));
-void doshutdownhooks __P((void));
+
+struct hook_desc {
+ TAILQ_ENTRY(hook_desc) hd_list;
+ void (*hd_fn) __P((void *));
+ void *hd_arg;
+};
+TAILQ_HEAD(hook_desc_head, hook_desc);
+
+extern struct hook_desc_head shutdownhook_list, startuphook_list;
+
+void *hook_establish __P((struct hook_desc_head *, int, void (*)(void *),
+ void *));
+void hook_disestablish __P((struct hook_desc_head *, void *));
+void dohooks __P((struct hook_desc_head *));
+
+#define startuphook_establish(fn, arg) \
+ hook_establish(&startuphook_list, 1, (fn), (arg))
+#define startuphook_disestablish(vhook) \
+ hook_disestablish(&startuphook_list, (vhook))
+#define dostartuphooks() dohooks(&startuphook_list)
+
+#define shutdownhook_establish(fn, arg) \
+ hook_establish(&shutdownhook_list, 0, (fn), (arg))
+#define shutdownhook_disestablish(vhook) \
+ hook_disestablish(&shutdownhook_list, (vhook))
+#define doshutdownhooks() dohooks(&shutdownhook_list)
/*
- * Power managment hooks.
+ * Power management hooks.
*/
void *powerhook_establish __P((void (*)(int, void *), void *));
void powerhook_disestablish __P((void *));