xref: /freebsd/share/man/man9/config_intrhook.9 (revision eb69d1f144a6fcc765d1b9d44a5ae8082353e70b)
1.\"
2.\" Copyright (C) 2006 M. Warner Losh <imp@FreeBSD.org>. All rights reserved.
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 August 10, 2017
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 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_oneshot
59function schedules a function to be run as described for
60.Fn config_intrhook_establish ;
61the entry is automatically removed from the hook queue
62after that function runs.
63This is appropriate when additional device configuration must be done
64after interrupts are enabled, but there is no need to stall the
65boot process after that.
66This function allocates memory using M_WAITOK; do not call this while
67holding any non-sleepable locks.
68.Pp
69Before root is mounted, all the previously established hooks are
70run.
71The boot process is then stalled until all handlers remove their hook
72from the hook queue with
73.Fn config_intrhook_disestablish .
74The boot process then proceeds to attempt to mount the root file
75system.
76Any driver that can potentially provide devices they wish to be
77mounted as root must use either this hook, or probe all these devices
78in the initial probe.
79Since interrupts are disabled during the probe process, many drivers
80need a method to probe for devices with interrupts enabled.
81.Pp
82The requests are made with the
83.Vt intr_config_hook
84structure.
85This structure is defined as follows:
86.Bd -literal
87struct intr_config_hook {
88	TAILQ_ENTRY(intr_config_hook) ich_links;/* Private */
89	ich_func_t	ich_func;		/* function to call */
90	void		*ich_arg;		/* Argument to call */
91};
92.Ed
93.Pp
94Storage for the
95.Vt intr_config_hook
96structure must be provided by the driver.
97It must be stable from just before the hook is established until
98after the hook is disestablished.
99.Pp
100Specifically, hooks are run at
101.Fn SI_SUB_INT_CONFIG_HOOKS ,
102which is immediately after the scheduler is started,
103and just before the root file system device is discovered.
104.Sh RETURN VALUES
105A zero return value means the hook was successfully added to the queue
106(with either deferred or immediate execution).
107A non-zero return value means the hook could not be added to the queue
108because it was already on the queue.
109.Sh SEE ALSO
110.Xr DEVICE_ATTACH 9
111.Sh HISTORY
112These functions were introduced in
113.Fx 3.0
114with the CAM subsystem, but are available for any driver to use.
115.Sh AUTHORS
116.An -nosplit
117The functions were written by
118.An Justin Gibbs Aq Mt gibbs@FreeBSD.org .
119This manual page was written by
120.An M. Warner Losh Aq Mt imp@FreeBSD.org .
121