Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
.\"     $NetBSD: autoconf.9,v 1.30 2013/03/13 00:09:21 riastradh Exp $
.\"
.\" Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Gregory McGarry.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd February 17, 2012
.Dt AUTOCONF 9
.Os
.Sh NAME
.Nm autoconf ,
.Nm config_search_loc ,
.Nm config_search_ia ,
.Nm config_found_sm_loc ,
.Nm config_found_ia ,
.Nm config_found ,
.Nm config_match ,
.Nm config_attach_loc ,
.Nm config_attach ,
.Nm config_attach_pseudo ,
.Nm config_detach ,
.Nm config_detach_children ,
.Nm config_deactivate ,
.Nm config_defer ,
.Nm config_interrupts ,
.Nm config_mountroot ,
.Nm config_pending_incr ,
.Nm config_pending_decr ,
.Nm config_finalize_register
.Nd autoconfiguration framework
.Sh SYNOPSIS
.In sys/param.h
.In sys/device.h
.In sys/errno.h
.Ft cfdata_t
.Fn config_search_loc "cfsubmatch_t func" "device_t parent" "const char *ia" \
"const int *locs" "void *aux"
.Ft cfdata_t
.Fn config_search_ia "cfsubmatch_t func" "device_t parent" "const char *ia" \
"void *aux"
.Ft device_t
.Fn config_found_sm_loc "device_t parent" "const char *ia" "const int *locs" \
"void *aux" "cfprint_t print" "cfsubmatch_t submatch"
.Ft device_t
.Fn config_found_ia "device_t parent" "const char *ia" "void *aux" \
"cfprint_t print"
.Ft device_t
.Fn config_found "device_t parent" "void *aux" "cfprint_t print"
.Ft int
.Fn config_match "device_t parent" "cfdata_t cf" "void *aux"
.Ft device_t
.Fn config_attach_loc "device_t parent" "cfdata_t cf" "const int *locs" \
"void *aux" "cfprint_t print"
.Ft device_t
.Fn config_attach "device_t parent" "cfdata_t cf" "void *aux" \
"cfprint_t print"
.Ft device_t
.Fn config_attach_pseudo "cfdata_t cf"
.Ft int
.Fn config_detach "device_t dev" "int flags"
.Ft int
.Fn config_detach_children "device_t dev" "int flags"
.Ft int
.Fn config_deactivate "device_t dev"
.Ft int
.Fn config_defer "device_t dev" "void (*func)(device_t)"
.Ft void
.Fn config_interrupts "device_t dev" "void (*func)(device_t)"
.Ft void
.Fn config_mountroot "device_t dev" "void (*func)(device_t)"
.Ft void
.Fn config_pending_incr
.Ft void
.Fn config_pending_decr
.Ft int
.Fn config_finalize_register "device_t dev" "int (*func)(device_t)"
.Sh DESCRIPTION
Autoconfiguration is the process of matching hardware devices with an
appropriate device driver.
In its most basic form, autoconfiguration consists of the recursive process
of finding and attaching all devices on a bus, including other busses.
.Pp
The autoconfiguration framework supports
.Em direct configuration
where the bus driver can determine the devices present.
The autoconfiguration framework also supports
.Em indirect configuration
where the drivers must probe the bus looking for the presence of a device.
Direct configuration is preferred since it can find hardware
regardless of the presence of proper drivers.
.Pp
The autoconfiguration process occurs at system bootstrap and is driven
by a table generated from a
.Do
machine description
.Dc
file by
.Xr config 1 .
For a description of the
.Xr config 1
.Do
device definition
.Dc
language, see
.Xr config 9 .
.Pp
Each device must have a name consisting of an alphanumeric string that
ends with a unit number.
The unit number identifies an instance of the driver.
Device data structures are allocated dynamically during
autoconfiguration, giving a unique address for each instance.
.Sh FUNCTIONS
.Bl -tag -width compact
.It Fn config_search_loc "func" "parent" "ia" "locs" "aux"
Performs indirect configuration of physical devices.
.Fn config_search_loc
iterates over all potential children, calling the given
function
.Fa func
for each one.
If
.Fa func
is
.Dv NULL ,
.Fn config_search_loc
applies each child's match function instead.
The argument
.Fa parent
is the pointer to the parent's device structure.
The argument
.Fa ia
is the interface attribute on which the potential children should attach.
It can be
.Dv NULL ,
in which case all children attaching to any attribute are considered.
The
.Fa locs
argument lists the locator values for the device and are passed to function
.Fa func .
The given
.Fa aux
argument describes the device that has been found and is simply passed
on through
.Fa func
to the child.
.Fn config_search_loc
returns a pointer to the best-matched child or
.Dv NULL
otherwise.
.Pp
The role of
.Fa func
is to call
the match function for each device and call
.Fn config_attach_loc
for any positive matches.
If
.Fa func
is
.Dv NULL ,
then the parent should record the return value from
.Fn config_search_loc
and call
.Fn config_attach_loc
itself.
.Pp
Note that this function is designed so that it can be used to apply an
arbitrary function to all potential children.
In this case callers may choose to ignore the return value.
.It Fn config_search_ia "func" "parent" "ia" "aux"
This function is equivalent to calling
.Fn config_search_loc "func" "parent" "ia" "locs" "aux"
with
.Fa locs
set to
.Dv NULL .
.It Fn config_found_sm_loc "parent" "ia" "locs" "aux" "print" "submatch"
Performs direct configuration on a physical device.
.Fn config_found_sm_loc
is called by the parent and in turn calls the
.Fa submatch
function to call the match function as
determined by the configuration table.
If
.Fa submatch
is
.Dv NULL ,
the driver match functions are called directly.
The argument
.Fa parent
is the pointer to the parent's device structure.
The argument
.Fa ia
is the name of the interface attribute on which the child will attach,
per
.Xr config 5
syntax.
The argument
.Fa locs
lists the locator values for the device.
The given
.Fa aux
argument describes the device that has been found.
.Fn config_found_sm_loc
internally uses
.Fn config_search_loc ,
passing on
.Fa submatch , ia , locs
and
.Fa aux .
The
.Em softc
structure for the matched device will be allocated, and the
appropriate driver attach function will be called.
If the device is matched, the system prints the name of the child and
parent devices, and then calls the
.Fa print
function to produce additional information if desired.
If no driver takes a match, the same
.Fa print
function is called to complain.
The print function is called with the
.Fa aux
argument and, if the matches failed, the full name (including unit
number) of the parent device, otherwise
.Dv NULL .
The
.Fa print
function must return an integer value.
.Pp
Two special strings,
.Do
not configured
.Dc
and
.Do
unsupported
.Dc
will be appended automatically to non-driver reports if the return
value is UNCONF or UNSUPP respectively; otherwise the function should
return the value QUIET.
.Pp
.Fn config_found_sm_loc
returns a pointer to the attached device's
.Em softc
structure if the device is attached,
.Dv NULL
otherwise.
Most callers can ignore this value, since the system will already have
printed a diagnostic.
.It Fn config_found_ia "parent" "ia" "aux" "print"
This function is equivalent to calling
.Fn config_found_sm_loc "parent" "ia" "locs" "aux" "print" "submatch"
with
.Fa locs
and
.Fa submatch
set to
.Dv NULL .
It is provided for better source code readability with locator-less device
buses.
.It Fn config_found "parent" "aux" "print"
This function is equivalent to calling
.Fn config_found_sm_loc "parent" "ia" "locs" "aux" "print" "submatch"
with
.Fa ia , locs
and
.Fa submatch
set to
.Dv NULL
and is provided for compatibility with older drivers.
New code should either make the interface attribute explicit or prefer an
indirect method based on
.Fn config_search_loc .
.It Fn config_match "parent" "cf" "aux"
Match a device.
Invokes the drivers match function according to the
configuration table.
The
.Fn config_match
function returns a nonzero integer indicating the confidence of
supporting this device and a value of 0 if the driver doesn't support
the device.
.It Fn config_attach_loc "parent" "cf" "locs" "aux" "print"
Attach a found device.
Allocates the memory for the
.Em softc
structure and calls the drivers attach function according to the
configuration table.
If successful,
.Fn config_attach_loc
returns the
.Em softc .
If unsuccessful, it returns
.Dv NULL .
.It Fn config_attach "parent" "cf" "aux" "print"
This function is equivalent to calling
.Fn config_attach_loc "parent" "cf" "locs" "aux" "print"
with
.Fa locs
set to
.Dv NULL .
.It Fn config_attach_pseudo "cf"
Create an instance of a pseudo-device driver.
.Xr config 5
syntax allows the creation of pseudo-devices from which regular
.Ft device_t
instances can be created.
Such objects are similar to the devices that attach at the root of the device
tree.
.Pp
The caller is expected to allocate and fill the
.Ft cfdata_t
object and pass it to
.Fn config_attach_pseudo .
The content of that object is similar to what is returned by
.Fn config_search_loc
for regular devices.
.It Fn config_detach "dev" "flags"
Called by the parent to detach the child device.
The second argument
.Em flags
contains detachment flags.
Valid values are DETACH_FORCE (force detachment (e.g., because of hardware
removal)) and DETACH_QUIET (do not print a notice).
.Fn config_detach
returns zero if successful and an error code otherwise.
.Fn config_detach
is always called from a thread context, allowing condition variables
to be used while the device detaches itself.
.It Fn config_detach_children "dev" "flags"
Iterate through all attached devices, calling
.Fn config_detach
for each child of
.Fa dev ,
passing
.Fa flags .
If detaching any child results in an error, the iteration will halt
and any remaining devices will not be detached.
.Fn config_detach_children
returns zero if successful and an error code otherwise.
.It Fn config_deactivate "dev"
Called by the parent to deactivate the child device
.Fa dev .
.Fn config_deactivate
is called from interrupt context to immediately relinquish resources
and notify dependent kernel subsystems that the device is about to be
detached.
At some later point
.Fn config_detach
will be called to finalise the removal of the device.
.It Fn config_defer "dev" "func"
Called by the child to defer the remainder of its configuration until
all its parent's devices have been attached.
At this point, the function
.Fa func
is called with the argument
.Fa dev .
.It Fn config_interrupts "dev" "func"
Called by the child to defer the remainder of its configuration until
interrupts are enabled.
At this point, the function
.Fa func
is called with the argument
.Fa dev .
.It Fn config_mountroot "dev" "func"
Called by the child to defer the remainder of its configuration until
the root file system is mounted.
At this point, the function
.Fa func
is called with the argument
.Fa dev .
This is used for devices that need to load firmware image from
a mounted file system.
.It Fn config_pending_incr
Increment the
.Va config_pending
semaphore.
It is used to account for deferred configurations before
mounting the root file system.
.It Fn config_pending_decr
Decrement the
.Va config_pending
semaphore.
It is used to account for deferred configurations before
mounting the root file system.
.It Fn config_finalize_register "dev" "func"
Register a function to be called after all real devices have been found.
.Pp
Registered functions are all executed until all of them return 0.
The callbacks should return 0 to indicate they do not require to be called
another time, but they should be aware that they still might be in case one of
them returns 1.
.El
.Sh CODE REFERENCES
The autoconfiguration framework itself is implemented within the file
.Pa sys/kern/subr_autoconf.c .
Data structures and function prototypes for the framework are located in
.Pa sys/sys/device.h .
.Sh SEE ALSO
.Xr config 1 ,
.Xr config 5 ,
.Xr condvar 9 ,
.Xr config 9 ,
.Xr driver 9
.Sh HISTORY
Autoconfiguration first appeared in
.Bx 4.1 .
The autoconfiguration framework was completely revised in
.Bx 4.4 .
The detach and deactivate interfaces appeared in
.Nx 1.5 .