xref: /freebsd/share/man/man9/config_intrhook.9 (revision 6ba2210ee039f2f12878c217bcf058e9c8b26b29)
1.\"
2.\" Copyright (C) 2006 M. Warner Losh <imp@FreeBSD.org>
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice(s), this list of conditions and the following disclaimer as
9.\"    the first lines of this file unmodified other than the possible
10.\"    addition of one or more copyright notices.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice(s), this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
16.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18.\" DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
19.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25.\" DAMAGE.
26.\"
27.\" $FreeBSD$
28.\"
29.Dd March 8, 2021
30.Dt CONFIG_INTRHOOK 9
31.Os
32.Sh NAME
33.Nm config_intrhook
34.Nd schedule a function to be run after interrupts have been enabled,
35but before root is mounted
36.Sh SYNOPSIS
37.In sys/kernel.h
38.Vt typedef void (*ich_func_t)(void *arg);
39.Ft int
40.Fn config_intrhook_establish "struct intr_config_hook *hook"
41.Ft void
42.Fn config_intrhook_disestablish "struct intr_config_hook *hook"
43.Ft int
44.Fn config_intrhook_drain "struct intr_config_hook *hook"
45.Ft void
46.Fn config_intrhook_oneshot "ich_func_t func" "void *arg"
47.Sh DESCRIPTION
48The
49.Fn config_intrhook_establish
50function schedules a function to be run after interrupts have been
51enabled, but before root is mounted.
52If the system has already passed this point in its initialization,
53the function is called immediately.
54.Pp
55The
56.Fn config_intrhook_disestablish
57function removes the entry from the hook queue.
58.Pp
59The
60.Fn config_intrhook_drain
61function removes the entry from the hook queue in a safe way.
62If the hook is not currently active it removes
63.Fa hook
64from the hook queue and returns
65.Vt ICHS_QUEUED .
66If the hook is active, it waits for the hook to complete before returning
67.Vt ICHS_RUNNING .
68If the hook has previously completed, it returns
69.Vt ICHS_DONE .
70Because a
71.Vt config_intrhook
72is undefined prior to
73.Fn config_intrhook_establish ,
74this function may only be called after that function has returned.
75.Pp
76The
77.Fn config_intrhook_oneshot
78function schedules a function to be run as described for
79.Fn config_intrhook_establish ;
80the entry is automatically removed from the hook queue
81after that function runs.
82This is appropriate when additional device configuration must be done
83after interrupts are enabled, but there is no need to stall the
84boot process after that.
85This function allocates memory using M_WAITOK; do not call this while
86holding any non-sleepable locks.
87.Pp
88Before root is mounted, all the previously established hooks are
89run.
90The boot process is then stalled until all handlers remove their hook
91from the hook queue with
92.Fn config_intrhook_disestablish .
93The boot process then proceeds to attempt to mount the root file
94system.
95Any driver that can potentially provide devices they wish to be
96mounted as root must use either this hook, or probe all these devices
97in the initial probe.
98Since interrupts are disabled during the probe process, many drivers
99need a method to probe for devices with interrupts enabled.
100.Pp
101The requests are made with the
102.Vt intr_config_hook
103structure.
104This structure is defined as follows:
105.Bd -literal
106struct intr_config_hook {
107	TAILQ_ENTRY(intr_config_hook) ich_links;/* Private */
108	ich_func_t	ich_func;		/* function to call */
109	void		*ich_arg;		/* Argument to call */
110};
111.Ed
112.Pp
113Storage for the
114.Vt intr_config_hook
115structure must be provided by the driver.
116It must be stable from just before the hook is established until
117after the hook is disestablished.
118.Pp
119Specifically, hooks are run at
120.Fn SI_SUB_INT_CONFIG_HOOKS ,
121which is immediately after the scheduler is started,
122and just before the root file system device is discovered.
123.Sh RETURN VALUES
124A zero return value means the hook was successfully added to the queue
125(with either deferred or immediate execution).
126A non-zero return value means the hook could not be added to the queue
127because it was already on the queue.
128.Sh SEE ALSO
129.Xr DEVICE_ATTACH 9
130.Sh HISTORY
131These functions were introduced in
132.Fx 3.0
133with the CAM subsystem, but are available for any driver to use.
134.Sh AUTHORS
135.An -nosplit
136The functions were written by
137.An Justin Gibbs Aq Mt gibbs@FreeBSD.org .
138This manual page was written by
139.An M. Warner Losh Aq Mt imp@FreeBSD.org .
140