1.\" -*- nroff -*- 2.\" 3.\" Copyright (c) 2000 Alexander Langer 4.\" 5.\" All rights reserved. 6.\" 7.\" This program is free software. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28.\" 29.\" $FreeBSD$ 30.\" 31.Dd April 19, 2022 32.Dt DRIVER_MODULE 9 33.Os 34.Sh NAME 35.Nm DRIVER_MODULE , 36.Nm DRIVER_MODULE_ORDERED , 37.Nm EARLY_DRIVER_MODULE , 38.Nm EARLY_DRIVER_MODULE_ORDERED 39.Nd kernel driver declaration macro 40.Sh SYNOPSIS 41.In sys/param.h 42.In sys/kernel.h 43.In sys/bus.h 44.In sys/module.h 45.Fn DRIVER_MODULE name busname "driver_t driver" "modeventhand_t evh" "void *arg" 46.Fn DRIVER_MODULE_ORDERED name busname "driver_t driver" "modeventhand_t evh" "void *arg" "int order" 47.Fn EARLY_DRIVER_MODULE name busname "driver_t driver" "modeventhand_t evh" "void *arg" "int pass" 48.Fn EARLY_DRIVER_MODULE_ORDERED name busname "driver_t driver" "modeventhand_t evh" "void *arg" "enum sysinit_elem_order order" "int pass" 49.Sh DESCRIPTION 50The 51.Fn DRIVER_MODULE 52macro declares a kernel driver. 53.Fn DRIVER_MODULE 54expands to the real driver declaration, where the phrase 55.Fa name 56is used as the naming prefix for the driver and its functions. 57Note that it is supplied as plain text, and not a 58.Li char 59or 60.Li char * . 61.Pp 62.Fa busname 63is the parent bus of the driver (PCI, ISA, PPBUS and others), e.g.\& 64.Ql pci , 65.Ql isa , 66or 67.Ql ppbus . 68.Pp 69The identifier used in 70.Fn DRIVER_MODULE 71can be different from the driver name. 72Also, the same driver identifier can exist on different buses, 73which is a pretty clean way of making front ends for different cards 74using the same driver on the same or different buses. 75For example, the following is allowed: 76.Pp 77.Fn DRIVER_MODULE foo isa foo_driver NULL NULL ; 78.Pp 79.Fn DRIVER_MODULE foo pci foo_driver NULL NULL ; 80.Pp 81.Fa driver 82is the driver of type 83.Li driver_t , 84which contains the information about the driver and is therefore one of the 85two most important parts of the call to 86.Fn DRIVER_MODULE . 87.Pp 88The 89.Fa evh 90argument is the event handler which is called when the driver (or module) 91is loaded or unloaded (see 92.Xr module 9 ) . 93.Pp 94The 95.Fa arg 96is unused at this time and should be a 97.Dv NULL 98pointer. 99.Pp 100The 101.Fn DRIVER_MODULE_ORDERED 102macro allows a driver to be registered in a specific order. 103This can be useful if a single kernel module contains multiple drivers 104that are inter-dependent. 105The 106.Fa order 107argument should be one of the 108.Xr SYSINIT 9 109initialization ordering constants 110.Pq Dv SI_ORDER_* . 111The default order for a driver module is 112.Dv SI_ORDER_MIDDLE . 113Typically a module will specify an order of 114.Dv SI_ORDER_ANY 115for a single driver to ensure it is registered last. 116.Pp 117The 118.Fn EARLY_DRIVER_MODULE 119macro allows a driver to be registered for a specific pass level. 120The boot time probe and attach process makes multiple passes over the 121device tree. 122Certain critical drivers that provide basic services needed by other 123devices are attached during earlier passes. 124Most drivers are attached in a final general pass. 125A driver that attaches during an early pass must register for a specific 126pass level 127.Pq BUS_PASS_* 128via the 129.Fa pass 130argument. 131Once a driver is registered it is available to attach to devices for 132all subsequent passes. 133.Pp 134The 135.Fn EARLY_DRIVER_MODULE_ORDERED 136macro allows a driver to be registered both in a specific order and 137for a specific pass level. 138.Sh SEE ALSO 139.Xr device 9 , 140.Xr driver 9 , 141.Xr module 9 , 142.Xr MODULE_PNP_INFO 9 , 143.Xr SYSINIT 9 144.Sh HISTORY 145Prior to 146.Fx 14.0 , 147these macros accepted an additional 148.Vt devclass_t 149argument after 150.Fa driver . 151.Sh AUTHORS 152This manual page was written by 153.An Alexander Langer Aq Mt alex@FreeBSD.org . 154