1fa81ece8SWarner Losh.\" 2a339dcccSWarner Losh.\" Copyright (C) 2006 M. Warner Losh <imp@FreeBSD.org> 3fa81ece8SWarner Losh.\" 4fa81ece8SWarner Losh.\" Redistribution and use in source and binary forms, with or without 5fa81ece8SWarner Losh.\" modification, are permitted provided that the following conditions 6fa81ece8SWarner Losh.\" are met: 7fa81ece8SWarner Losh.\" 1. Redistributions of source code must retain the above copyright 8fa81ece8SWarner Losh.\" notice(s), this list of conditions and the following disclaimer as 9fa81ece8SWarner Losh.\" the first lines of this file unmodified other than the possible 10fa81ece8SWarner Losh.\" addition of one or more copyright notices. 11fa81ece8SWarner Losh.\" 2. Redistributions in binary form must reproduce the above copyright 12fa81ece8SWarner Losh.\" notice(s), this list of conditions and the following disclaimer in the 13fa81ece8SWarner Losh.\" documentation and/or other materials provided with the distribution. 14fa81ece8SWarner Losh.\" 15fa81ece8SWarner Losh.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 16fa81ece8SWarner Losh.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17fa81ece8SWarner Losh.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18fa81ece8SWarner Losh.\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 19fa81ece8SWarner Losh.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20fa81ece8SWarner Losh.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21fa81ece8SWarner Losh.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22fa81ece8SWarner Losh.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23fa81ece8SWarner Losh.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24fa81ece8SWarner Losh.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25fa81ece8SWarner Losh.\" DAMAGE. 26fa81ece8SWarner Losh.\" 27*e5236836SWarner Losh.Dd March 8, 2021 28fa81ece8SWarner Losh.Dt CONFIG_INTRHOOK 9 29fa81ece8SWarner Losh.Os 30fa81ece8SWarner Losh.Sh NAME 31fa81ece8SWarner Losh.Nm config_intrhook 32bd84dd2fSRuslan Ermilov.Nd schedule a function to be run after interrupts have been enabled, 33bd84dd2fSRuslan Ermilovbut before root is mounted 34fa81ece8SWarner Losh.Sh SYNOPSIS 35fa81ece8SWarner Losh.In sys/kernel.h 362db14f97SIan Lepore.Vt typedef void (*ich_func_t)(void *arg); 37bd84dd2fSRuslan Ermilov.Ft int 38fa81ece8SWarner Losh.Fn config_intrhook_establish "struct intr_config_hook *hook" 39bd84dd2fSRuslan Ermilov.Ft void 40fa81ece8SWarner Losh.Fn config_intrhook_disestablish "struct intr_config_hook *hook" 41*e5236836SWarner Losh.Ft int 42*e5236836SWarner Losh.Fn config_intrhook_drain "struct intr_config_hook *hook" 432db14f97SIan Lepore.Ft void 442db14f97SIan Lepore.Fn config_intrhook_oneshot "ich_func_t func" "void *arg" 45fa81ece8SWarner Losh.Sh DESCRIPTION 46fa81ece8SWarner LoshThe 47fa81ece8SWarner Losh.Fn config_intrhook_establish 48fa81ece8SWarner Loshfunction schedules a function to be run after interrupts have been 49fa81ece8SWarner Loshenabled, but before root is mounted. 50fa81ece8SWarner LoshIf the system has already passed this point in its initialization, 51fa81ece8SWarner Loshthe function is called immediately. 52fa81ece8SWarner Losh.Pp 53fa81ece8SWarner LoshThe 54fa81ece8SWarner Losh.Fn config_intrhook_disestablish 55fa81ece8SWarner Loshfunction removes the entry from the hook queue. 56fa81ece8SWarner Losh.Pp 572db14f97SIan LeporeThe 58*e5236836SWarner Losh.Fn config_intrhook_drain 59*e5236836SWarner Loshfunction removes the entry from the hook queue in a safe way. 60*e5236836SWarner LoshIf the hook is not currently active it removes 61*e5236836SWarner Losh.Fa hook 62*e5236836SWarner Loshfrom the hook queue and returns 63*e5236836SWarner Losh.Vt ICHS_QUEUED . 64*e5236836SWarner LoshIf the hook is active, it waits for the hook to complete before returning 65*e5236836SWarner Losh.Vt ICHS_RUNNING . 66*e5236836SWarner LoshIf the hook has previously completed, it returns 67*e5236836SWarner Losh.Vt ICHS_DONE . 68*e5236836SWarner LoshBecause a 69*e5236836SWarner Losh.Vt config_intrhook 70*e5236836SWarner Loshis undefined prior to 71*e5236836SWarner Losh.Fn config_intrhook_establish , 72*e5236836SWarner Loshthis function may only be called after that function has returned. 73*e5236836SWarner Losh.Pp 74*e5236836SWarner LoshThe 752db14f97SIan Lepore.Fn config_intrhook_oneshot 762db14f97SIan Leporefunction schedules a function to be run as described for 772db14f97SIan Lepore.Fn config_intrhook_establish ; 782db14f97SIan Leporethe entry is automatically removed from the hook queue 792db14f97SIan Leporeafter that function runs. 802db14f97SIan LeporeThis is appropriate when additional device configuration must be done 812db14f97SIan Leporeafter interrupts are enabled, but there is no need to stall the 822db14f97SIan Leporeboot process after that. 832db14f97SIan LeporeThis function allocates memory using M_WAITOK; do not call this while 842db14f97SIan Leporeholding any non-sleepable locks. 852db14f97SIan Lepore.Pp 86fa81ece8SWarner LoshBefore root is mounted, all the previously established hooks are 87fa81ece8SWarner Loshrun. 88fa81ece8SWarner LoshThe boot process is then stalled until all handlers remove their hook 89fa81ece8SWarner Loshfrom the hook queue with 90fa81ece8SWarner Losh.Fn config_intrhook_disestablish . 91fa81ece8SWarner LoshThe boot process then proceeds to attempt to mount the root file 92fa81ece8SWarner Loshsystem. 93fa81ece8SWarner LoshAny driver that can potentially provide devices they wish to be 94fa81ece8SWarner Loshmounted as root must use either this hook, or probe all these devices 95fa81ece8SWarner Loshin the initial probe. 96fa81ece8SWarner LoshSince interrupts are disabled during the probe process, many drivers 97fa81ece8SWarner Loshneed a method to probe for devices with interrupts enabled. 98fa81ece8SWarner Losh.Pp 99fa81ece8SWarner LoshThe requests are made with the 100bd84dd2fSRuslan Ermilov.Vt intr_config_hook 101fa81ece8SWarner Loshstructure. 102fa81ece8SWarner LoshThis structure is defined as follows: 103fa81ece8SWarner Losh.Bd -literal 104fa81ece8SWarner Loshstruct intr_config_hook { 105fa81ece8SWarner Losh TAILQ_ENTRY(intr_config_hook) ich_links;/* Private */ 1062db14f97SIan Lepore ich_func_t ich_func; /* function to call */ 107fa81ece8SWarner Losh void *ich_arg; /* Argument to call */ 108fa81ece8SWarner Losh}; 109fa81ece8SWarner Losh.Ed 110fa81ece8SWarner Losh.Pp 111fa81ece8SWarner LoshStorage for the 112fa81ece8SWarner Losh.Vt intr_config_hook 113fa81ece8SWarner Loshstructure must be provided by the driver. 114fa81ece8SWarner LoshIt must be stable from just before the hook is established until 115fa81ece8SWarner Loshafter the hook is disestablished. 116fa81ece8SWarner Losh.Pp 117fa81ece8SWarner LoshSpecifically, hooks are run at 118fa81ece8SWarner Losh.Fn SI_SUB_INT_CONFIG_HOOKS , 1199280e5faSMike Pritchardwhich is immediately after the scheduler is started, 120fa81ece8SWarner Loshand just before the root file system device is discovered. 121fa81ece8SWarner Losh.Sh RETURN VALUES 1220cc19870SWarner LoshA zero return value means the hook was successfully added to the queue 1230cc19870SWarner Losh(with either deferred or immediate execution). 1240cc19870SWarner LoshA non-zero return value means the hook could not be added to the queue 1250cc19870SWarner Loshbecause it was already on the queue. 126fa81ece8SWarner Losh.Sh SEE ALSO 127fa81ece8SWarner Losh.Xr DEVICE_ATTACH 9 128fa81ece8SWarner Losh.Sh HISTORY 129fa81ece8SWarner LoshThese functions were introduced in 130fa81ece8SWarner Losh.Fx 3.0 131fa81ece8SWarner Loshwith the CAM subsystem, but are available for any driver to use. 132fa81ece8SWarner Losh.Sh AUTHORS 133bd84dd2fSRuslan Ermilov.An -nosplit 134fa81ece8SWarner LoshThe functions were written by 1358a7314fcSBaptiste Daroussin.An Justin Gibbs Aq Mt gibbs@FreeBSD.org . 136fa81ece8SWarner LoshThis manual page was written by 1378a7314fcSBaptiste Daroussin.An M. Warner Losh Aq Mt imp@FreeBSD.org . 138