xref: /freebsd/share/man/man9/config_intrhook.9 (revision e5b786625f7f82a1fa91e41823332459ea5550f9)
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.Dd March 8, 2021
28.Dt CONFIG_INTRHOOK 9
29.Os
30.Sh NAME
31.Nm config_intrhook
32.Nd schedule a function to be run after interrupts have been enabled,
33but before root is mounted
34.Sh SYNOPSIS
35.In sys/kernel.h
36.Vt typedef void (*ich_func_t)(void *arg);
37.Ft int
38.Fn config_intrhook_establish "struct intr_config_hook *hook"
39.Ft void
40.Fn config_intrhook_disestablish "struct intr_config_hook *hook"
41.Ft int
42.Fn config_intrhook_drain "struct intr_config_hook *hook"
43.Ft void
44.Fn config_intrhook_oneshot "ich_func_t func" "void *arg"
45.Sh DESCRIPTION
46The
47.Fn config_intrhook_establish
48function schedules a function to be run after interrupts have been
49enabled, but before root is mounted.
50If the system has already passed this point in its initialization,
51the function is called immediately.
52.Pp
53The
54.Fn config_intrhook_disestablish
55function removes the entry from the hook queue.
56.Pp
57The
58.Fn config_intrhook_drain
59function removes the entry from the hook queue in a safe way.
60If the hook is not currently active it removes
61.Fa hook
62from the hook queue and returns
63.Vt ICHS_QUEUED .
64If the hook is active, it waits for the hook to complete before returning
65.Vt ICHS_RUNNING .
66If the hook has previously completed, it returns
67.Vt ICHS_DONE .
68Because a
69.Vt config_intrhook
70is undefined prior to
71.Fn config_intrhook_establish ,
72this function may only be called after that function has returned.
73.Pp
74The
75.Fn config_intrhook_oneshot
76function schedules a function to be run as described for
77.Fn config_intrhook_establish ;
78the entry is automatically removed from the hook queue
79after that function runs.
80This is appropriate when additional device configuration must be done
81after interrupts are enabled, but there is no need to stall the
82boot process after that.
83This function allocates memory using M_WAITOK; do not call this while
84holding any non-sleepable locks.
85.Pp
86Before root is mounted, all the previously established hooks are
87run.
88The boot process is then stalled until all handlers remove their hook
89from the hook queue with
90.Fn config_intrhook_disestablish .
91The boot process then proceeds to attempt to mount the root file
92system.
93Any driver that can potentially provide devices they wish to be
94mounted as root must use either this hook, or probe all these devices
95in the initial probe.
96Since interrupts are disabled during the probe process, many drivers
97need a method to probe for devices with interrupts enabled.
98.Pp
99The requests are made with the
100.Vt intr_config_hook
101structure.
102This structure is defined as follows:
103.Bd -literal
104struct intr_config_hook {
105	TAILQ_ENTRY(intr_config_hook) ich_links;/* Private */
106	ich_func_t	ich_func;		/* function to call */
107	void		*ich_arg;		/* Argument to call */
108};
109.Ed
110.Pp
111Storage for the
112.Vt intr_config_hook
113structure must be provided by the driver.
114It must be stable from just before the hook is established until
115after the hook is disestablished.
116.Pp
117Specifically, hooks are run at
118.Fn SI_SUB_INT_CONFIG_HOOKS ,
119which is immediately after the scheduler is started,
120and just before the root file system device is discovered.
121.Sh RETURN VALUES
122A zero return value means the hook was successfully added to the queue
123(with either deferred or immediate execution).
124A non-zero return value means the hook could not be added to the queue
125because it was already on the queue.
126.Sh SEE ALSO
127.Xr DEVICE_ATTACH 9
128.Sh HISTORY
129These functions were introduced in
130.Fx 3.0
131with the CAM subsystem, but are available for any driver to use.
132.Sh AUTHORS
133.An -nosplit
134The functions were written by
135.An Justin Gibbs Aq Mt gibbs@FreeBSD.org .
136This manual page was written by
137.An M. Warner Losh Aq Mt imp@FreeBSD.org .
138