Home | History | Annotate | Download | only in sys
History log of /src/sys/sys/device.h
RevisionDateAuthorComments
 1.192  12-Oct-2025  thorpej Introduce the notion of a "system default" device call provider. This
is useful on a platform like sparc, where a single booted kernel can
support OpenFirmware, pre-OFW OpenBOOT, or the "old ROM" universe that
does not have a platform device tree, but has platform-specific logic
for handling some kinds of device properties. The SYSDFLT get a crack
if the normal by-handle device call lookup fails.
 1.191  03-Oct-2025  thorpej Introduce a set of functions that wrap the device properties dictionary,
providing a more abstract and convenient interface for interacting (setting
and getting) with them, along with information about the properties themselves.
Inspiration for the interface is taken from the traditional OpenFirmware
interface.
 1.190  19-Mar-2025  jakllsch remove long-unused LKM-related structure
 1.189  27-Aug-2024  thorpej - Remove devhandle_impl_inherit() and re-implement as devhandle_impl_subclass()
and a helper devhandle_subclass().
- Add a devhandle_t argument to device_call_generic(); don't imply it from
the device; let the device_call() wrapper own that logic.

(Ride the bump to 10.99.12; I've been sitting on this change for ages
waiting for a version bump to go by.)
 1.188  15-Jan-2024  thorpej branches: 1.188.2;
Revert unintended commit (didn't hit CTRL-C fast enough I guess).
 1.187  15-Jan-2024  thorpej Provide an ev_count32 field for situations where a 32-bit counter is
sufficient (and, notably, might be desirable to avoid 64-bit math on
an older 32-bit platform). This is overlaid on the 64-bit counter
field, and simply references the correct half based on byte order.
 1.186  22-May-2023  riastradh autoconf(9): New functions for referenced attach/detach.

New functions:

- config_found_acquire(dev, aux, print, cfargs)
- config_attach_acquire(parent, cf, aux, print, cfargs)
- config_attach_pseudo_acquire(cf, aux)
- config_detach_release(dev, flags)
- device_acquire(dev)

The config_*_acquire functions are like the non-acquire versions, but
they return a referenced device_t, which is guaranteed to be safe to
use until released. The device's detach function may run while it is
referenced, but the device_t will not be freed and the parent's
.ca_childdetached routine will not be called.

=> config_attach_pseudo_acquire additionally lets you pass an aux
argument to the device's .ca_attach routine, unlike
config_attach_pseudo which always passes NULL.

=> Eventually, config_found, config_attach, and config_attach_pseudo
should be made to return void, because use of the device_t they
return is unsafe without the kernel lock and difficult to use
safely even with the kernel lock or in a UP system. For now,
they require the caller to hold the kernel lock, while
config_*_acquire do not.

config_detach_release is like device_release and then config_detach,
but avoids the race inherent with that sequence.

=> Eventually, config_detach should be eliminated, because getting at
the device_t it needs is unsafe without the kernel lock and
difficult to use safely even with the kernel lock or in a UP
system. For now, it requires the caller to hold the kernel lock,
while config_detach_release does not.

device_acquire acquires a reference to a device. It never fails and
can be used in thread context (but not interrupt context, hard or
soft). Caller is responsible for ensuring that the device_t cannot
be freed; in other words, the device_t must be made unavailable to
any device_acquire callers before the .ca_detach function returns.
Typically device_acquire will be used in a read section (mutex,
rwlock, pserialize, &c.) in a data structure lookup, with
corresponding logic in the .ca_detach function to remove the device
from the data structure and wait for all read sections to complete.

Proposed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/05/10/msg028889.html
 1.185  24-Aug-2022  riastradh pmf(9): *_child_register never fails. Make it return void.

No kernel bump because this isn't documented or used in any modules,
only in dev/pci/pci.c and dev/cardbus/cardbus.c which are as far as I
know always statically linked into the kernel.

The next change, however, will require a revbump -- to make
pmf_device_register return void so we can prune vast swaths of dead
error branches.
 1.184  24-Aug-2022  riastradh kern: Move various pmf declarations to device_impl.h.

These are used only inside subr_autoconf.c and subr_pmf.c. Let's
stop having changes to these trigger rebuilds of all device drivers.
 1.183  24-Aug-2022  riastradh kern: device_pmf_driver_register never fails, so make it return void.

No ABI bump despite change to device.h because this is used only
inside autoconf.
 1.182  28-Mar-2022  riastradh sys: Split struct device into a private device_impl.h.

Include this only inside autoconf itself, and a few files that abuse
autoconf in ways I can't confidently make easy fixes for.

XXX kernel ABI change requires bump -- no more use of struct device
internals allowed, previously done by some drivers
 1.181  28-Mar-2022  riastradh autoconf(9): New function config_detach_commit.

When a driver's .ca_detach function has committed to detaching -- it
definitely won't back out with EBUSY, for instance -- it can call
this to wake all pending calls to device_lookup_acquire and make them
fail immediately.

This is necessary to break a deadlock if the device_lookup_acquire
calls happen inside I/O operations which the driver's .ca_detach
function waits for the completion of -- without config_detach_commit,
I/O operations would be stuck in device_lookup_acquire waiting for
.ca_detach and .ca_detach would be stuck waiting for I/O operations
to return.

Most drivers won't need to call this: for autoconf drivers used the
traditional way by devsw for userland device nodes, the .ca_detach
routine uses vdevgone, and we will arrange to make vdevgone call
config_detach_commit automagically in such drivers anyway.

XXX kernel ABI change to struct device requires bump -- later change
will make struct device opaque to ABI, but we're not there yet
 1.180  28-Mar-2022  riastradh autoconf(9): New localcount-based device instance references.

device_lookup_acquire looks up an autoconf device instance, if found,
and acquires a reference the caller must release with device_release.
If attach or detach is still in progress, device_lookup_acquire waits
until it completes. While references are held, the device's softc
will not be freed or reused until the last reference is released.

The reference is meant to be held while opening a device in the short
term, and then to be passed off to a longer-term reference that can
be broken explicitly by detach -- usually a device special vnode,
which is broken by vdevgone in the driver's *_detach function.

Sleeping while holding a reference is allowed, e.g. waiting to open a
tty. A driver must arrange that its *_detach function will interrupt
any threads sleeping while holding references and cause them to back
out so that detach can complete promptly.

Subsequent changes to subr_devsw.c will make bdev_open and cdev_open
automatically take a reference to an autoconf instance for drivers
that opt into this, so there will be no logic changes needed in most
drivers other than to connect the autoconf cfdriver to the
bdevsw/cdevsw I/O operation tables. The effect will be that *_detach
may run while d_open is in progress, but no new d_open can begin
until *_detach has backed out from or committed to detaching.

XXX kernel ABI change to struct device requires bump -- later change
will make struct device opaque to ABI, but we're not there yet
 1.179  03-Mar-2022  riastradh driver(9): New device_set_private.

Used to initialize a device_t's private pointer at most once. Only
for drivers with zero cfattach size so autoconf doesn't preallocate;
KASSERT checks for this mistake.
 1.178  22-Jan-2022  thorpej Add a function to compare 2 devhandles.
 1.177  22-Jan-2022  thorpej Make the devhandle "integer" field an intptr_t to ensure that all
bits of the union are initialized when that field is used.
 1.176  21-Jan-2022  thorpej Replace devhandle_invalidate(), which invalidates a devhandle, with
devhandle_invalid(), which returns an invalid devhandle.
 1.175  15-Sep-2021  thorpej Adjust the device_call() calling convention so as to provide type checking
of the arguments passed to the call, using auto-generated argument
structures and binding macros.
 1.174  15-Aug-2021  thorpej Define a constant for the size of device_t::dv_xname, rather than just
using 16.
 1.173  07-Aug-2021  thorpej branches: 1.173.2;
Export devhandle_lookup_device_call().
 1.172  07-Aug-2021  thorpej Merge thorpej-cfargs2.
 1.171  12-Jun-2021  riastradh branches: 1.171.2;
autoconf(9): Prevent concurrent attach/detach and detach/detach.

- Use config_pending_incr/decr around attach. No need for separate
flag indicating device is still attaching. (dv_flags locking is also
incoherent.)

- Any config_pending now blocks config_detach.

- New dv_detaching exclusive lock for config_detach.
 1.170  10-May-2021  thorpej sparc{,64} promlib -> devhandle_t glue
 1.169  27-Apr-2021  thorpej branches: 1.169.2;
The Amiga and Atari ports abuse some autoconfiguration internals as part
of their early console bring-up, so we need to expose some of the new
internals to them and adapt the call sites.
 1.168  24-Apr-2021  thorpej branches: 1.168.2;
Merge thorpej-cfargs branch:

Simplify and make extensible the config_search() / config_found() /
config_attach() interfaces: rather than having different variants for
which arguments you want pass along, just have a single call that
takes a variadic list of tag-value arguments.

Adjust all call sites:
- Simplify wherever possible; don't pass along arguments that aren't
actually needed.
- Don't be explicit about what interface attribute is attaching if
the device only has one. (More simplification.)
- Add a config_probe() function to be used in indirect configuiration
situations, making is visibly easier to see when indirect config is
in play, and allowing for future change in semantics. (As of now,
this is just a wrapper around config_match(), but that is an
implementation detail.)

Remove unnecessary or redundant interface attributes where they're not
needed.

There are currently 5 "cfargs" defined:
- CFARG_SUBMATCH (submatch function for direct config)
- CFARG_SEARCH (search function for indirect config)
- CFARG_IATTR (interface attribte)
- CFARG_LOCATORS (locators array)
- CFARG_DEVHANDLE (devhandle_t - wraps OFW, ACPI, etc. handles)

...and a sentinel value CFARG_EOL.

Add some extra sanity checking to ensure that interface attributes
aren't ambiguous.

Use CFARG_DEVHANDLE in MI FDT, OFW, and ACPI code, and macppc and shark
ports to associate those device handles with device_t instance. This
will trickle trough to more places over time (need back-end for pre-OFW
Sun OBP; any others?).
 1.167  06-Feb-2021  christos branches: 1.167.2;
Expose devhandle_t to standalone programs (fixes sparc* build etc)
 1.166  05-Feb-2021  thorpej Introduce a generalized "device handle", designed to abstract the handles
used by platform description mechanisms like OpenFirmware, Device Tree,
and ACPI. In addition to encapsulating the handle's opaque value, the
handle also contains a pointer to an "implementation", which can be used
to invoke methods on a device / device handle.

Device handles are designed to be passed around by-value. It is expected
that any other memory objects they refer to will be durable. They are an
aggregate type that consumes 2 pointers worth of storage space.

When device_t's are created, they initially have an invalid device handle.
It is currently the responsibility of platform-specific code to assign
device handles to device_t's.

When necessary, platform-specific code can override a handle's implementation
in a way that resembles sub-classing, such that specific methods can by
intercepted, but others simply passed through. This also allows platforms
that do not otherwise have a platform description mechanism to provide
handle implementations in specific circumstances to describe the hardware
to platform-independent code.

A general device method calling infrastructure is provided. Method names
that begin with "device-" are reserved for / defined by the autoconfiguration
subsystem. Define the "device-enumerate-children" method. Other subsystems
are free to define their own device method calls and bindings.

Welcome to NetBSD 9.99.80.
 1.165  04-Feb-2021  thorpej Add device_attached_to_iattr(), which return true if the device
attached to the specified interface attribute.
 1.164  27-Jan-2021  thorpej Add device_compatible_match_id() and device_compatible_lookup_id(), which
are like device_compatible_match() and device_compatible_lookup(), but
take a single scalar value as an ID.

Add a "uintptr_t id" field to device_compatible_entry, in an anonymous
union with the existing "const char *compat" field.
 1.163  27-Jan-2021  thorpej Define a macro to terminate the common usage of device_compatible_entry
arrays, in order to placate the angry hordes objecting to use of a GCC
extension.
 1.162  24-Jan-2021  thorpej Refactor and simplify device_compatible_match(), and also provide
device_compatible_p{match,lookup}() which treats the strings in the
driver compatible data as pmatch(9) patterns.

Add device_compatible_{,p}{match,lookup}_strlist(), which are the same, but
take an OpenFirmware-style string list rather than an array of strings
for the device data.
 1.161  18-Jan-2021  thorpej Change the device_compatible_match() function to only perform the match.
Introduce a device_compatible_lookup() function to return an entry based
on the same matching criteria (a'la of_search_compatible()).

Update iic_compatible_match() to reflect the above change, and introduce
iic_compatible_lookup(). This pattern is less awkward to use.
 1.160  17-Jan-2021  thorpej Change the device_compatible_entry struct to have a union of
a scalar value (uintptr_t value) and a pointer value (const void *data),
rather than just "uintptr_t data". This eliminates the need for drivers
to cast this value, and doesn't lose const'ness of pointers assigned
to the field.

Update all of the users of this field to use the correct set of
designated initialisers for each specific case.
 1.159  24-Nov-2020  christos PR/55816: Martin Husemann: widen cfunit to 24 bits so that it fits the
largest minor number which is 20 bits. Welcome to 2x2x19.
 1.158  03-Oct-2020  riastradh branches: 1.158.2;
autoconf: Blame devices holding up boot with config_pending.

Blame message requires `boot -x' (AB_DEBUG).

Fix ata so it doesn't mismatch config_pending_incr/decr devices.
 1.157  01-Dec-2018  msaitoh Add new dv_flags value DVF_ATTACH_INPROGRESS. Currenty, this flags is used
only for checking the registration of pmf.

This flag should be set when an attach function(ca_attach) doesn't complete
the whole attach work when the function returned. config_interrupts() set it.
It's also required for device drivers who do a part of the attach work in their
own kthread to set it.
 1.156  18-Sep-2018  mrg - move export for devmon_insert_vec into sys/device.h.
- export root_is_mounted for future USB RB_ASKNAME hack.
- make some things in subr_autoconf.c static
- move device_printf() prototype out from the middle of two sets of
aprint_*() prototypes.
 1.155  26-Jun-2018  thorpej branches: 1.155.2;
In my quest to make device_compatible_entry (and associated goo)
super-general, it turns out I also made it a little to cumbersome
to use (if my tired fingers are any indication). So, this is a
course-correction -- one string per entry (like of_compat_data,
which it will soon replace), and remove the over-verbose macros.
 1.154  26-Jun-2018  thorpej Change device_compatible_match() and iic_compatible_match() to return
the weighted match value and take an optional compatible-entry pointer,
rather than the other way around.
 1.153  18-Jun-2018  thorpej Add device_compatible_match(), a generalized routine for weighted
matching of device_compatible_entry data to a device's "compatible"
strings.
 1.152  17-Jun-2018  thorpej Add slightly-more generalized version of the "of_compat_data" structure
called "device_compatible_entry". It performs a similar function, but
instead of one "compatible" string per entry, it takes an array of
"comaptible" strings per entry. Also included are macros for initializing
an array of these entries and accessing data embedded in them.
 1.151  04-Mar-2018  mlelstv branches: 1.151.2;
Expose device structures to _KMEMUSER
 1.150  09-Nov-2017  christos add a "booted_method" string to aid in debugging double boot matches.
 1.149  19-Jun-2016  bouyer branches: 1.149.2; 1.149.8; 1.149.10;
Add a new config_detach() flag, DETACH_POWEROFF, which is set when
detaching devices at shutdown time with RB_POWERDOWN.
When detaching wd(4), put the drive in standby before detach
for DETACH_POWEROFF.
Fix PR kern/51252
 1.148  07-Dec-2015  pgoyette Modularize drvctl(4)
 1.147  06-Mar-2015  mrg wait for config_mountroot threads to complete before we tell init it
can start up. this solves the problem where a console device needs
mountroot to complete attaching, and must create wsdisplay0 before
init tries to open /dev/console. fixes PR#49709.

XXX: pullup-7
 1.146  22-Nov-2014  mlelstv branches: 1.146.2;
Let MD code provide boot disk information as spec string that can be
parsed by MI code. The format is the same as provided by an embedded
'root on <rootspec>' string in the config file. An embedded string
(other than a wildcard) still takes precedence.
 1.145  05-Sep-2014  matt Don't nest structure definitions.
 1.144  12-Oct-2013  christos branches: 1.144.4;
Pass the device name in, so we can debug what deferred drivers did not work.
 1.143  27-Oct-2012  chs branches: 1.143.2;
split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
 1.142  07-Jul-2012  tsutsui branches: 1.142.2;
unsigned -> unsigned int
 1.141  10-Jun-2012  mlelstv Make detection of root on wedges (dk(4)) machine independent. Remove
MD code for x86, xen, sparc64.
 1.140  13-Nov-2011  christos branches: 1.140.6;
add getdiskinfo a companion utility to getdisksize.
 1.139  24-Apr-2011  rmind branches: 1.139.4;
- Replace few malloc(9) uses with kmem(9).
- Rename buf_malloc() to buf_alloc(), fix comments.
- Remove some unnecessary inclusions.
 1.138  31-Jan-2011  dyoung Let the linker instead of the C preprocessor configure the kernel: make
weak aliases device_register(9) and device_register_post_config(9)
for the stub routine voidop(). Get rid of __HAVE_DEVICE_REGISTER and
__HAVE_DEVICE_REGISTER_POST_CONFIG.
 1.137  25-Jun-2010  tsutsui branches: 1.137.2; 1.137.4;
Add config_mountroot(9), which defers device configuration
after mountroot(), like config_interrupt(9) that defers
configuration after interrupts are enabled.
This will be used for devices that require firmware loaded
from the root file system by firmload(9) to complete device
initialization (getting MAC address etc).

No objection on tech-kern@:
http://mail-index.NetBSD.org/tech-kern/2010/06/18/msg008370.html
and will also fix PR kern/43125.
 1.136  25-Mar-2010  pooka Add init/fini for components (modules etc.). These eat the standard
driver/attach/data typically present and once some locking is grown
in here, these routines can be made to fail or succeed a component
attachment/detachment atomically.
 1.135  24-Feb-2010  dyoung branches: 1.135.2;
A pointer typedef entails trading too much flexibility to declare const
and non-const types, and the kernel uses both const and non-const
PMF qualifiers and device suspensors, so change the pmf_qual_t and
device_suspensor_t typedefs from "pointers to const" to non-pointer,
non-const types.
 1.134  15-Feb-2010  dyoung Extract a subroutine, const char *cfdata_ifattr(cfdata_t cf), that
returns the name of the interface attribute that associates cf with
its parent. Use cfdata_ifattr() at several sites in the autoconf
code.
 1.133  30-Jan-2010  mlelstv branches: 1.133.2;
Add helper function that determines the size and block size of a disk device.
For now we query
- the disk label
- the wedge info and data from disk(9)
 1.132  10-Jan-2010  martin forgot to commit this - prototype for device_register_post_config()
 1.131  08-Jan-2010  dyoung Expand PMF_FN_* macros.
 1.130  08-Jan-2010  dyoung Move all copies of ifattr_match() to sys/kern/subr_autoconf.c.
 1.129  07-Jan-2010  dyoung Add a do-nothing child-detachment hook, null_childdetached(device_t,
device_t).
 1.128  15-Dec-2009  dyoung Per rmind@'s suggestion, avoid an acquire/release-mutex dance by
collecting garbage in two phases: in the first stage, with
alldevs_mtx held, gather all of the objects to be freed onto a
list. Drop alldevs_mtx, and in the second stage, free all the
collected objects.

Also per rmind@'s suggestion, remove KASSERT(!mutex_owned(&alldevs_mtx))
throughout, it is not useful.

Find a free unit number and allocate it for a new device_t atomically.
Before, two threads would sometimes find the same free unit number
and race to allocate it. The loser panicked. Now there is no
race.

In support of the changes above, extract some new subroutines that
are private to this module: config_unit_nextfree(), config_unit_alloc(),
config_devfree(), config_dump_garbage().

Delete all of the #ifdef __BROKEN_CONFIG_UNIT_USAGE code. Only
the sun3 port still depends on __BROKEN_CONFIG_UNIT_USAGE, it's
not hard for the port to do without, and port-sun3@ had fair warning
that it was going away (>1 week, or a few years' warning, depending
how far back you look!).
 1.127  07-Dec-2009  dyoung Poison future uses of DVACT_ACTIVATE by deleting it. I deleted the last
"use" of DVACT_ACTIVATE in a driver, yesterday.
 1.126  26-Nov-2009  pooka Add DV_VIRTUAL for non-backed virtual devices and allow to mount
root from a DV_VIRTUAL device.
 1.125  12-Nov-2009  dyoung Move a device-deactivation pattern that is replicated throughout
the system into config_deactivate(dev): deactivate dev and all of
its descendants. Block all interrupts while calling each device's
activation hook, ca_activate. Now it is possible to simplify or
to delete several device-activation hooks throughout the system.

Do not deactivate a driver while detaching it! If the driver was
already deactivated (because of accidental/emergency removal), let
the driver cope with the knowledge that DVF_ACTIVE has been cleared.
Otherwise, let the driver access the underlying hardware (so that
it can flush caches, restore original register settings, et cetera)
until it exits its device-detachment hook.

Let multiple readers and writers simultaneously access the system's
device_t list, alldevs, from either interrupt or thread context:
postpone changing alldevs linkages and freeing autoconf device
structures until a garbage-collection phase that runs after all
readers & writers have left the list.

Give device iterators (deviter(9)) a consistent view of alldevs no
matter whether device_t's are added and deleted during iteration:
keep a global alldevs generation number. When an iterator enters
alldevs, record the current generation number in the iterator and
increase the global number. When a device_t is created, label it
with the current global generation number. When a device_t is
deleted, add a second label, the current global generation number.
During iteration, compare a device_t's added- and deleted-generation
with the iterator's generation and skip a device_t that was deleted
before the iterator entered the list or added after the iterator
entered the list.

The alldevs generation number is never 0. The garbage collector
reaps device_t's whose delete-generation number is non-zero.

Make alldevs private to sys/kern/subr_autoconf.c. Use deviter(9)
to access it.
 1.124  21-Sep-2009  pooka Split config_init() into config_init() and config_init_mi() to help
platforms which want to call config_init() very early in the boot.
 1.123  16-Sep-2009  dyoung Nothing calls config_activate(9) any longer, so delete it.
 1.122  16-Sep-2009  dyoung In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.

Currently, the kernel defines three suspensors,

3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,

3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.

3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.

A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.

Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.

4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.

Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.

6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.
 1.121  03-Sep-2009  pooka Move configure() and configure2() from subr_autoconf.c to init_main.c,
since they are only peripherially related to the autoconf subsystem
and more related to boot initialization. Also, apply _KERNEL_OPT
to autoconf where necessary.
 1.120  26-Jun-2009  dyoung Switch to kmem(9).

(void *)pew is one way to get a struct work *, but let's
write&pew->pew_work, instead. It is more defensive and persuasive.

Make miscellaneous changes in support of tearing down arbitrary
stacks of filesystems and devices during shutdown:

1 Move struct shutdown_state, shutdown_first(), and shutdown_next(),
from kern_pmf.c to subr_autoconf.c. Rename detach_all() to
config_detach_all(), and move it from kern_pmf.c to subr_autoconf.c.
Export all of those routines.

2 In pmf_system_shutdown(), do not suspend user process scheduling, and
do not detach all devices: I am going to do that in cpu_reboot(),
instead. (Soon I will do it in an MI cpu_reboot() routine.) Do still
call PMF shutdown hooks.

3 In config_detach(), add a DIAGNOSTIC assertion: if we're exiting
config_detach() at the bottom, alldevs_nwrite had better not be 0,
because config_detach() is a writer of the device list.

4 In deviter_release(), check to see if we're iterating the device list
for reading, *first*, and if so, decrease the number of readers. Used
to be that if we happened to be reading during shutdown, we ran the
shutdown branch. Thus the number of writers reached 0, the number
of readers remained > 0, and no writer could iterate again. Under
certain circumstances that would cause a hang during shutdown.
 1.119  07-May-2009  cegger CFATTACH_DECL2 is no longer used. remove it.
ok dyoung@
 1.118  05-May-2009  cegger CFATTACH_DECL3 is no longer used.
ok dyoung@
 1.117  02-Apr-2009  dyoung During shutdown, detach devices in an orderly fashion.

Call the detach routine for every device in the device tree, starting
with the leaves and moving toward the root, expecting that each
(pseudo-)device driver will use the opportunity to gracefully commit
outstandings transactions to the underlying (pseudo-)device and to
relinquish control of the hardware to the system BIOS.

Detaching devices is not suitable for every shutdown: in an emergency,
or if the system state is inconsistent, we should resort to a fast,
simple shutdown that uses only the pmf(9) shutdown hooks and the
(deprecated) shutdownhooks. For now, if the flag RB_NOSYNC is set in
boothowto, opt for the fast, simple shutdown.

Add a device flag, DVF_DETACH_SHUTDOWN, that indicates by its presence
that it is safe to detach a device during shutdown. Introduce macros
CFATTACH_DECL3() and CFATTACH_DECL3_NEW() for creating autoconf
attachments with default device flags. Add DVF_DETACH_SHUTDOWN
to configuration attachments for atabus(4), atw(4) at cardbus(4),
cardbus(4), cardslot(4), com(4) at isa(4), elanpar(4), elanpex(4),
elansc(4), gpio(4), npx(4) at isa(4), nsphyter(4), pci(4), pcib(4),
pcmcia(4), ppb(4), sip(4), wd(4), and wdc(4) at isa(4).

Add a device-detachment "reason" flag, DETACH_SHUTDOWN, that tells the
autoconf code and a device driver that the reason for detachment is
system shutdown.

Add a sysctl, kern.detachall, that tells the system to try to detach
every device at shutdown, regardless of any device's DVF_DETACH_SHUTDOWN
flag. The default for kern.detachall is 0. SET IT TO 1, PLEASE, TO
HELP TEST AND DEBUG DEVICE DETACHMENT AT SHUTDOWN.

This is a work in progress. In future work, I aim to treat
pseudo-devices more thoroughly, and to gracefully tear down a stack of
(pseudo-)disk drivers and filesystems, including cgd(4), vnd(4), and
raid(4) instances at shutdown.

Also commit some changes that are not easily untangled from the rest:

(1) begin to simplify device_t locking: rename struct pmf_private to
device_lock, and incorporate device_lock into struct device.

(2) #include <sys/device.h> in sys/pmf.h in order to get some
definitions that it needs. Stop unnecessarily #including <sys/device.h>
in sys/arch/x86/include/pic.h to keep the amd64, xen, and i386 releases
building.
 1.116  12-Feb-2009  christos Unbreak ssp kernels. The issue here that when the ssp_init() call was deferred,
it caused the return from the enclosing function to break, as well as the
ssp return on i386. To fix both issues, split configure in two pieces
the one before calling ssp_init and the one after, and move the ssp_init()
call back in main. Put ssp_init() in its own file, and compile this new file
with -fno-stack-protector. Tested on amd64.
XXX: If we want to have ssp kernels working on 5.0, this change needs to
be pulled up.
 1.115  13-Nov-2008  dyoung branches: 1.115.4;
Only define 'struct device' if _KERNEL is #defined, so that I can
add a kmutex_t and a kcondvar_t to struct device, later, without
breaking userland. Userland does not use struct device.
 1.114  12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.113  06-Nov-2008  dyoung Use DVUNIT_ANY instead of the anonymous constant -1.
 1.112  11-Jun-2008  drochner branches: 1.112.2; 1.112.4; 1.112.6;
tighten type checking: use device_t instead of void* at some places
 1.111  27-May-2008  ad branches: 1.111.2;
Don't expose config_pending.
 1.110  25-May-2008  jmcneill Add DRVGETEVENT support for /dev/drvctl, based on devmon support by
Jachym Holecek for Google Summer of Code. DRVGETEVENT plist is currently
limited to event type, device name, and device parent name.
 1.109  12-Mar-2008  dyoung branches: 1.109.2; 1.109.4; 1.109.6;
Use device_t and its accessors throughout. Use aprint_*_dev().

Improve PMF-ability.

Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().

Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).

In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.

In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.

In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).

rtw(4) improvements:

Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.

Remove activate() methods:

Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.

Honor this property in cardbus_child_suspend().

Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

Warn if ath(4) tries to write crypto keys to suspended
hardware.

Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.

Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.

Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.
 1.108  11-Mar-2008  matt Add device_lookup_private() which is just device_private(device_lookup(&cd, i))
Most callers don't want the device_t, they want their softc and that's what
device_lookup_private returns.
 1.107  07-Mar-2008  dyoung PMF: synchronize device suspension and resumption.
 1.106  05-Mar-2008  dyoung Synchronize readers and writers of the device tree.

Add a device iterator object, deviter_t, and methods deviter_init(),
deviter_first(), and deviter_next() for visiting each device in
the device tree.

Take care not to re-shutdown a device in the event that the machine
panics during reboot and the operator types 'reboot' at the kernel
debugger prompt.

While I'm here, sprinkle PMF_FN_ARGS, PMF_FN_PROTO, et cetera.
 1.105  05-Mar-2008  dyoung Introduce PMF_FN_{ARGS,PROTO}1, and use PMF_FN_{ARGS,PROTO} more
widely, further helping me to introduce PMF API changes piecemeal.
 1.104  28-Feb-2008  drochner Extend the pmf suspend/resume hooks by a shutdown method, so drivers
can register a shutdown handler explicitely.
Install a pci bus shutdown handler which disables bus master accesses
for all childs, so the drivers don't need to care.
This will hopefully be sufficient to replace the shutdownhooks
(together with the powerhooks). (It has been suggested to use some
general event notification framework for shutdown handlers, but there
might be cases where shutdown handlers must be run in an order following
the device hierarchy, which wouldn't be easy with event handlers
not tied to drivers.)
approved by David Young
 1.103  12-Feb-2008  joerg branches: 1.103.2; 1.103.6;
Introduce device_find_by_xname and device_find_by_driver_unit to replace
alldevs iterations all over src.

Patch discussed with and improved on suggestioned from cube@.
 1.102  06-Feb-2008  drochner The tricks done in device_foreach_child() still don't make it safe to use
by config_detach_children(), because the latter can work recursively
and remove any number of devices, so rewrite config_detach_children()
to restart list traversal after each call of config_detach(), and since
only one user of device_foreach_child() is left (in kern_drvctl.c),
and it is simpler to open-code the loop than to deal with callbacks,
just remove it.
 1.101  16-Dec-2007  drochner don't include <sys/pmf.h> for userland programs, saves some recompilation
if internals are changed
 1.100  16-Dec-2007  dyoung Add config_deferred() for forcing the deferred configuration to
run, which we need to do from drvctl(4) sometimes.

Add device_foreach_child() for calling a function on each child of
a device_t.

Add config_detach_children() for detaching all of the children of
a device (uses device_foreach_child()).
 1.99  09-Dec-2007  jmcneill branches: 1.99.2; 1.99.4;
Merge jmcneill-pm branch.
 1.98  24-Sep-2007  joerg branches: 1.98.4; 1.98.6; 1.98.8;
Introduce CFATTACH_DECL_NEW and CFATTACH_DECL2_NEW for drivers that
don't expect struct device as first field of softc. device_private uses
a new field of struct device to give the softc address and that field is
either set the struct device for old-style devices or a separate
allocation by config_devalloc. Both macros are intended as temporary
bandaid until all drivers are converted and will be removed later.
 1.97  26-Aug-2007  matt branches: 1.97.2; 1.97.4;
Change CFATTACH_DECL, CFATTACH_DECL2, and CFDRIVER_DECL to use C99 structure
initializers.
 1.96  09-Jul-2007  tsutsui branches: 1.96.2; 1.96.6;
Hmm, pesudo seems pseudo of pseudo.
 1.95  24-Jun-2007  dyoung Extract common code from i386, xen, and sparc64, creating
config_handle_wedges() and read_disk_sectors(). On x86, handle_wedges()
is a thin wrapper for config_handle_wedges(). Share opendisk()
across architectures.

Add kernel code in support of specifying a root partition by wedge
name. E.g., root specifications "wedge:wd0a", "wedge:David's Root
Volume" are possible. (Patches for config(1) coming soon.)

In support of moving disks between architectures (esp. i386 <->
evbmips), I've written a routine convertdisklabel() that ensures
that the raw partition is at RAW_DISK by following these steps:

0 If we have read a disklabel that has a RAW_PART with
p_offset == 0 and p_size != 0, then use that raw partition.

1 If we have read a disklabel that has both partitions 'c'
and 'd', and RAW_PART has p_offset != 0 or p_size == 0,
but the other partition is suitable for a raw partition
(p_offset == 0, p_size != 0), then swap the two partitions
and use the new raw partition.

2 If the architecture's raw partition is 'd', and if there
is no partition 'd', but there is a partition 'c' that
is suitable for a raw partition, then copy partition 'c'
to partition 'd'.

3 Determine the drive's last sector, using either the
d_secperunit the drive reported, or by guessing (0x1fffffff).
If we cannot read the drive's last sector, then fail.

4 If we have read a disklabel that has no partition slot
RAW_PART, then create a partition RAW_PART. Make it span
the whole drive.

5 If there are fewer than MAXPARTITIONS partitions,
then "slide" the unsuitable raw partition RAW_PART, and
subsequent partitions, into partition slots RAW_PART+1
and subsequent slots. Create a raw partition at RAW_PART.
Make it span the whole drive.

The convertdisklabel() procedure can probably stand to be simplified,
but it ought to deal with all but an extraordinarily broken disklabel,
now.

i386: compiled and tested, sparc64: compiled, evbmips: compiled.
 1.94  05-Mar-2007  drochner branches: 1.94.2; 1.94.4;
Make the attach functions for real and pseudo devices share as much code
as possible. For that, split out a function which does the allocation
of a softc (without linking it into global structures) and a function
which inserts the device into the global alldevs lists and the per-driver
cd_devs.
There is a little semantic change involved: the pseudo-device code didn't
interpret FSTATE_STAR as such, for no good reason. This looks harmless;
I'll modify driver frontends as I find ways to test.
Get config_makeroom() out of the public namespace - that's clearly an
internal of autoconf which drivers can't be allowed to deal with.
 1.93  21-Feb-2007  thorpej Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.92  28-Aug-2006  christos branches: 1.92.8;
complete CFDRIVER initializer.
 1.91  27-Aug-2006  christos Fix incomplete initialization.
 1.90  05-May-2006  thorpej Remove the devprop API and switch everthing over to the new proplib. Add
a new device_properties() accessor for device_t that returns the device's
property dictionary.
 1.89  29-Mar-2006  thorpej Add a device_private() to return the driver's private data (softc).
For now, this just returns the passed device_t (as a void *) because
device softcs currently contain a "struct device" as the first member.
 1.88  29-Mar-2006  thorpej Replace device_locators() with device_locator(), and use it.
 1.87  23-Feb-2006  thorpej branches: 1.87.2; 1.87.4; 1.87.6;
Add device_is_a(), which returns true if the device is an instance
of the driver specified by name.
 1.86  19-Feb-2006  thorpej Add accessor functions for the device_t type. Make device_lookup() a
real function, rather than a macro.
 1.85  18-Feb-2006  thorpej - Don't expose dev_propdb directly -- provide devprop_*() wrappers instead.
- Rework the ARMADILLO / epe device properties interaction so that it actually
associates the MAC address property with the epe device instance.
 1.84  24-Dec-2005  perry branches: 1.84.2; 1.84.4; 1.84.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.83  20-Dec-2005  thorpej Move evcnt definitions into <sys/evcnt.h>. Include this from <sys/device.h>
for compatibility.
 1.82  20-Dec-2005  thorpej Provide typedefs:
- devclass_t
- devact_t
- cfdata_t
- device_t

...and use them.
 1.81  11-Dec-2005  christos merge ktrace-lwp.
 1.80  10-Sep-2005  itohy Make it compile for gcc 2.95.
 1.79  26-Aug-2005  drochner nuke locdesc_t from orbit
 1.78  25-Aug-2005  drochner now that we have information about default locator values
we can implement an universal submatch() function covering all
the standard cases:
if (<configured> != <wildcard> && <configured> != <real>)
then fail
else
ask device match function
 1.77  25-Aug-2005  drochner replace the "locdesc_t" structure carrying the number of locators
explicitely by a plain integer array
the length in now known to all relevant parties, so this avoids
duplication of information, and we can allocate that thing in
drivers without hacks
 1.76  25-Aug-2005  drochner Replace the "locnames", attached to cfdata, which was solely good for
userconf, by more complete information (including default values) about
interface attributes, attached to the drivers which provide them.
 1.75  28-Jun-2005  drochner branches: 1.75.2;
clean up duplication which was to support the old (not locator passing)
API for bus "submatch" functions
 1.74  19-Jun-2005  christos remove duplicate declaration.
 1.73  26-Feb-2005  perry nuke trailing whitespace
 1.72  23-Oct-2004  thorpej branches: 1.72.4; 1.72.6;
- Centralize the declaration of booted_device and booted_partition.
- Add a booted_wedge variable that indicates the wedge that was booted
from. If this is NULL, booted_partition is consulted.
- Adjust setroot() and its support routines for root-on-wedges. Could
use some tidy-up, but this works for now.
 1.71  15-Oct-2004  thorpej Change config_attach_pseudo() to take a cfdata * that contains the
necessary information to create the pseudo-device instance. Pseudo-device
device's will reference this cfdata, just as normal devices reference
their corresponding cfdata.

Welcome to 2.99.10.
 1.70  30-Aug-2004  drochner -change the config_found() macro to use config_sound_sm_loc()
internally (shouldn't make a difference for callers)
-add convenience macros for config_found() and config_search() to
ease the case where just an interface attribute is specified
 1.69  17-Aug-2004  drochner Add some extensions to the autoconf framework to better support
loadable drivers and user controlled attach/detach of devices.
An outline was given in
http://mail-index.NetBSD.org/tech-kern/2004/08/11/0000.html
To cite the relevant parts:
-Add a "child detached" and a "rescan" method (both optional)
to the device driver. (This is added to the "cfattach" for now
because this is under the driver writer's control. Logically
it belongs more to the "cfdriver", but this is automatically
generated now.)
The "child detached" is called by the autoconf framework
during config_detach(), after the child's ca_detach()
function was called but before the device data structure
is freed.
The "rescan" is called explicitely, either after a driver LKM
was loaded, or on user request (see the "control device" below).
-Add a field to the device instance where the "locators" (in
terms of the autoconf framework), which describe the actual
location of the device relatively to the parent bus, can be
stored. This can be used by the "child detached" function
for easier bookkeeping (no need to lookup by device instance
pointer). (An idea for the future is to use this for generation
of optimized kernel config files - like DEC's "doconfig".)
-Pass the locators tuple describing a device's location to
various autoconf functions to support the previous. And since
locators do only make sense in relation to an "interface
attribute", pass this as well.
-Add helper functions to add/remove supplemental "cfdata"
arrays. Needed for driver LKMs.

There is some code duplication which will hopefully resolved
when all "submatch"-style functions are changed to accept the
locator argument.
Some more cleanup can take place when config(8) issues more
information about locators, in particular the length and default
values. To be done later.
 1.68  30-Apr-2004  matt Add EVCNT_ATTACH_STATIC2 to allow adding of array members
 1.67  17-Nov-2003  keihan www.netbsd.org -> www.NetBSD.org
 1.66  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.65  04-Jul-2003  thorpej Add a dev_propdb to hold device properties. Properties are already being
used in an ad hoc way by a couple of eval board ports, so might as well
tidy it up a little and add some formality. (And, yes, I need to use it
in another eval board port.)
 1.64  24-Nov-2002  thorpej branches: 1.64.6;
Add an EVCNT_ATTACH_STATIC() macro which gathers static evcnts
into a link set, which are added to the list of event counters
at boot time.
 1.63  23-Oct-2002  christos s/{ }/{ 0 }/g
 1.62  20-Oct-2002  isaki x68k needs config_cfdriver_lookup() to initialize its console.
XXX ad-hoc way?
 1.61  09-Oct-2002  thorpej Implement config_attach_pseudo(), which creates an instance of
a pseudo-device which behaves like a normal device in the device
tree, including the capability to have children.
 1.60  04-Oct-2002  thorpej Overhaul the way cfattach structures are looked up. The cfdata entry
now carries the name of the attachment (e.g. "tlp_pci" or "audio"),
and cfattach structures are registered at boot time on a per-driver
basis. The cfdriver and cfattach pointers are cached in the device
structure when attached.
 1.59  02-Oct-2002  thorpej Assume caller will add trailing ; to CFDRIVER_DECL and CFATTACH_DECL.
 1.58  01-Oct-2002  thorpej Add a generic config finalization hook, to be called once all real
devices have been discovered. All finalizer routines are iteratively
invoked until all of them report that they have done no work.

Use this hook to fix a latent bug in RAIDframe autoconfiguration of
RAID sets exposed by the rework of SCSI device discovery.
 1.57  30-Sep-2002  thorpej Fix thinko in CFATTACH_DECL().
 1.56  30-Sep-2002  thorpej Add macros to declare cfdriver and cfattach structures. This will allow
us to shield things that declare these structures from changes to the
structure (to a certain extent, anyway).
 1.55  30-Sep-2002  thorpej Add a config_init() function to initialize the config data structures.
Normally this is called by configure(), but some ports (amiga, atari,
x68k) need to do this early because of how they find the console.
 1.54  27-Sep-2002  thorpej Declare all cfattach structures const.
 1.53  27-Sep-2002  thorpej Introduce a new routine, config_match(), which invokes the
cfattach->ca_match function in behalf of the caller. Use it
rather than invoking cfattach->ca_match directly.
 1.52  27-Sep-2002  thorpej Rather than referencing the cfdriver directly in the cfdata entries,
instead use a string naming the driver. The cfdriver is then looked
up in a list which is built at run-time.
 1.51  26-Sep-2002  thorpej Overhaul the way parent attachments are specified; instead of using
a vector of indices into the cfdata table to specify potential parents,
record the interface attributes that devices have and add a new "parent
spec" structure which lists the iattr, as well as optionally listing
specific parent device instances.

See:

http://mail-index.netbsd.org/tech-kern/2002/09/25/0014.html

...for a detailed description.

While here, const poison some things, as suggested by Matt Thomas.
 1.50  23-Sep-2002  thorpej Add support for multiple cfdata tables to the internals of the
autoconfiguration machinery, derived from PR #2112.

More work is left to do, including revamping how matches against
a candidate parent are done.
 1.49  15-Feb-2002  simonb branches: 1.49.6;
Add a "show event" ddb command to show the event counters.
 1.48  02-Dec-2001  augustss Prototype for config_makeroom(), the routine that expands the cd_devs array.
 1.47  26-Aug-2001  matt Add EVCNT_TRAP event counter type.
 1.46  01-Jul-2001  gmcgarry branches: 1.46.2;
In-kernel device configuration manager - allows modification
of device locators at run-time.

Written by Mats O Jansson <moj@stacken.kth.se>. Reworked by
Jun-ichiro itojun Hagino <itojun@netbsd.org>.
 1.45  01-Dec-2000  simonb branches: 1.45.2;
Remove trailing , from last enum element.
 1.44  22-Jul-2000  matt Make gcc-2.96 shutup about trigraph ignored.
 1.43  06-Jul-2000  thorpej Add a device_lookup() macro which encapsulates a small snippet of code
that tons and tons of files all over the tree duplicate, many in slightly
different ways.
 1.42  13-Jun-2000  cgd branches: 1.42.2;
Replace my personal attribution string ("This product includes software
developed by Christopher G. Demetriou for the NetBSD Project.") with
a generic NetBSD one ("This product includes software developed for the
NetBSD Project. See http://www.netbsd.org/ for information about NetBSD.")
so that this same set of terms can be used by others if they so desire.
(Eventually i'll be converting more/all of my code.)
 1.41  04-Jun-2000  cgd Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).
 1.40  02-Jun-2000  cgd another mod of opportunity: const poison. (cfprint_t should take
const char * as second arg, too, but that's Hard.) also, convert use
of "(char *)0" to NULL.
 1.39  02-Jun-2000  cgd __P and K&R declarations -> ANSI protos + declarations. tweak NetBSD IDs,
and __KERNEL_RCSID to subr_autoconf.c.
 1.38  01-Jun-2000  matt Add extern struct device *booted_device (make MI instead of MD since nearly
every port uses it).
 1.37  06-Mar-2000  mhitch branches: 1.37.2;
Also use __HAVE_DEVICE_REGISTER for the device_register() prototype, rather
than a list of architecture defines.
 1.36  24-Jan-2000  thorpej Add a `config_pending' semaphore to block mounting of the root file system
until all device driver discovery threads have had a chance to do their
work. This in turn blocks initproc's exec of init(8) until root is
mounted and process start times and CWD info has been fixed up.

Addresses kern/9247.
 1.35  23-Sep-1999  minoura branches: 1.35.2;
First step toward network boot.
By Takeshi Nakayama <tn@catvmics.ne.jp>.
 1.34  15-Sep-1999  thorpej Add a mechanism to defer configuration of children until interrupts
are enabled.
 1.33  15-Sep-1999  thorpej Rename the machine-dependent autoconfiguration entry point `cpu_configure()',
and rename config_init() to configure() and call cpu_configure() from there.
 1.32  20-Jun-1999  ragge Add vax to user of device_register.
 1.31  03-Dec-1998  pk branches: 1.31.6;
Enable `device_register()' for the sparc.
 1.30  17-Nov-1998  thorpej Implement config_detach(), mostly from Chris Demetriou, modified slightly
by Ken Hornstein and myself.

Add flags to struct device, and define one as "active". Devices are
initially active from config_attach(). Their active state may be changed
via config_activate() and config_deactivate().

These new functions assume that the device being manipulated will recursively
perform the action on its children.

Together, config_deactivate() and config_detach() may be used to implement
interrupt-driven device detachment. config_deactivate() will take care of
things that need to be performed at interrupt time, and config_detach()
(which must run in a valid thread context) finishes the job, which may
block.
 1.29  06-Oct-1998  thorpej Prototype configure() here, and make it a machine-dependent call that
MI code expects to exist.
 1.28  13-Sep-1998  christos Fix copyright typos...
 1.27  31-Aug-1998  cgd the cfdriver's cd_lossage_prevention field is no longer necessary, since
config automatically generates cfdriver structs (for better or worse).
 1.26  31-Aug-1998  cgd kill the last remnants of __BROKEN_INDIRECT_CONFIG. (only the pica port
used it, and it's non-working and apparently slated for replacement.)
 1.25  09-Jun-1998  thorpej Implement config_defer(), a generic mechanism to defer the configuration
of a device until all of its parent's children have been attached.
 1.24  12-Jan-1998  thorpej Revert last change.
 1.23  12-Jan-1998  thorpej Pull in ioconf.h if _KERNEL and ! _LKM.
 1.22  20-Sep-1997  drochner enable "device_register()" for the i386 too
 1.21  14-Mar-1997  jtk branches: 1.21.4;
add cf_locnames to struct cfdata
 1.20  17-Dec-1996  thorpej Prototype device_register() if __alpha__ || hp300
 1.19  05-Dec-1996  cgd First steps in removing config_scan() and the hacks that gave devices
on indirect-config busses a (permanent) softc that they could share
between 'match' and 'attach' routines:

Check for a new definition, __BROKEN_INDIRECT_CONFIG, and if it is _not_
defined:
define match functions to take a struct cfdata * as their second
argument, config_search() to take a struct cfdata * as its second
argument, and config_{root,}search() to return struct cfdata *.

remove 'cd_indirect' cfdriver element.

remove config_scan().

Ports will define __BROKEN_INDIRECT_CONFIG until their drivers prototypes
are updated to work with the new definitions, and until it is sure that
their indirect-config drivers do not assume that they have a softc
in their match routine.
 1.18  11-Nov-1996  mycroft Remove remaining vector cruft.
 1.17  27-Aug-1996  cgd change cfprint_t type definition to take a const char *, rather than
a char *, because that's what was really intended, and because
if the print function modifies the string, various things could become
unhappy (so the string should _not_ be modified).
 1.16  10-Jul-1996  cgd #ifdef __alpha__, prototype device_register
 1.15  09-Apr-1996  cgd fix extra spaces at ends of lines, etc. (all spacing nits.)
 1.14  04-Apr-1996  cgd Make config_found_sm() (and therefore config_found()) and config_rootfound()
return a struct device * of attached device, or NULL if device attach failed,
rather than 1/0 for success/failure, so that code that bus code which needs
to know what the child device is doesn't have to open-code a hacked variant
of config_found(). Make config_attach() return struct device *, rather than
void, to facilitate that.
 1.13  04-Apr-1996  cgd change 'struct device' and 'struct evcnt' lists (alldevs and allevents) to
be TAILQ's. TAILQ_HEAD's of those structs are now 'struct devicelist' and
'struct evcntlist', respectively.
 1.12  17-Mar-1996  thorpej New device attachment scheme:

- split softc size and match/attach out from cfdriver into
a new struct cfattach.

- new "attach" directive for files.*. May specify the name of
the cfattach structure, so that devices may be easily attached
to parents with different autoconfiguration semantics.
 1.11  05-Mar-1996  thorpej Protect function prototypes and declaration of global variables
with #ifdef _KERNEL
 1.10  27-Feb-1996  cgd Replace config_found() with config_found_sm(), which adds a cfmatch_t to the
argument list. This allows easy 'submatching', which will eliminate a fair
bit of slightly tricky duplicated code from various busses. config_found()
is now a #define in sys/device.h, which invokes config_found_sm().
 1.9  09-Feb-1996  christos Filesystem prototype changes
 1.8  04-Nov-1994  mycroft Add a new function config_scan(), which just calls a particular function
with each plausibly cfdata, ignoring the priority mechanism completely.
 1.7  04-Nov-1994  mycroft Export struct matchinfo and mapply().
 1.6  03-Nov-1994  mycroft Change second arg of match routines and config_attach() to void*; have
config_search() and config_rootsearch() return void*. Remove old cd_aux
(which was unused), and add cd_indirect where it used to be.
 1.5  03-Nov-1994  mycroft If CONFIG_INDIRECT, the second arg to the match routine is a softc, not a cfdata.
 1.4  29-Jun-1994  cgd New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'
 1.3  27-Jun-1994  cgd new standard, minimally intrusive ID format
 1.2  20-May-1994  glass update to 4.4-lite, except for some prototypes in disk.h that would've caused trouble
 1.1  13-Aug-1993  glass branches: 1.1.1; 1.1.2;
snapshot of intergration of torek's config
 1.1.2.1  29-Nov-1993  mycroft Add a prototype of dk_establish(), with a forward declaration of dkdevice.
 1.1.1.1  01-Mar-1998  fvdl Import 4.4BSD-Lite for reference
 1.21.4.1  22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.31.6.1  21-Jun-1999  thorpej Sync w/ -current.
 1.35.2.2  08-Dec-2000  bouyer Sync with HEAD.
 1.35.2.1  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
 1.37.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.42.2.1  25-Oct-2001  he Pull up revision 1.43 (requested by ad):
Add Mylex DACC960, CAC-EISA, and I2O block/SCSI drivers.
 1.45.2.7  11-Dec-2002  thorpej Sync with HEAD.
 1.45.2.6  11-Nov-2002  nathanw Catch up to -current
 1.45.2.5  18-Oct-2002  nathanw Catch up to -current.
 1.45.2.4  28-Feb-2002  nathanw Catch up to -current.
 1.45.2.3  08-Jan-2002  nathanw Catch up to -current.
 1.45.2.2  21-Sep-2001  nathanw Catch up to -current.
 1.45.2.1  24-Aug-2001  nathanw Catch up with -current.
 1.46.2.4  10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.46.2.3  16-Mar-2002  jdolecek Catch up with -current.
 1.46.2.2  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.46.2.1  13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.49.6.2  06-Apr-2002  eeh Add dev_dumprops() for debug and make dev_mdgetprop() conditional.
 1.49.6.1  22-Mar-2002  eeh Add devprops interfaces.
 1.64.6.9  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.64.6.8  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.64.6.7  02-Nov-2004  skrll Sync with HEAD.
 1.64.6.6  19-Oct-2004  skrll Sync with HEAD
 1.64.6.5  21-Sep-2004  skrll Fix the sync with head I botched.
 1.64.6.4  18-Sep-2004  skrll Sync with HEAD.
 1.64.6.3  03-Sep-2004  skrll Sync with HEAD
 1.64.6.2  25-Aug-2004  skrll Sync with HEAD.
 1.64.6.1  03-Aug-2004  skrll Sync with HEAD
 1.72.6.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.72.4.1  29-Apr-2005  kent sync with -current
 1.75.2.9  17-Mar-2008  yamt sync with head.
 1.75.2.8  27-Feb-2008  yamt sync with head.
 1.75.2.7  11-Feb-2008  yamt sync with head.
 1.75.2.6  21-Jan-2008  yamt sync with head
 1.75.2.5  27-Oct-2007  yamt sync with head.
 1.75.2.4  03-Sep-2007  yamt sync with head.
 1.75.2.3  26-Feb-2007  yamt sync with head.
 1.75.2.2  30-Dec-2006  yamt sync with head.
 1.75.2.1  21-Jun-2006  yamt sync with head.
 1.84.6.2  01-Jun-2006  kardel Sync with head.
 1.84.6.1  22-Apr-2006  simonb Sync with head.
 1.84.4.1  09-Sep-2006  rpaulo sync with head
 1.84.2.2  01-Mar-2006  yamt sync with head.
 1.84.2.1  18-Feb-2006  yamt sync with head.
 1.87.6.2  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.87.6.1  31-Mar-2006  tron Merge 2006-03-31 NetBSD-current into the "peter-altq" branch.
 1.87.4.2  11-May-2006  elad sync with head
 1.87.4.1  19-Apr-2006  elad sync with head.
 1.87.2.3  03-Sep-2006  yamt sync with head.
 1.87.2.2  24-May-2006  yamt sync with head.
 1.87.2.1  01-Apr-2006  yamt sync with head.
 1.92.8.2  12-Mar-2007  rmind Sync with HEAD.
 1.92.8.1  27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.94.4.1  11-Jul-2007  mjf Sync with head.
 1.94.2.2  09-Oct-2007  ad Sync with head.
 1.94.2.1  15-Jul-2007  ad Sync with head.
 1.96.6.7  08-Dec-2007  jmcneill Rename pnp(9) -> pmf(9), as requested by many.
 1.96.6.6  07-Nov-2007  joerg Introduce device_has_power to fix a race between resuming a device and
the device enabling interrupts as seen by jmcneill@ with uhci. Change
ehci, ohci, uhci and azalia to use this function to protect the
interrupt handler.
 1.96.6.5  06-Nov-2007  joerg Refactor PNP API:
- Make suspend/resume directly a device functionality. It consists of
three layers (class logic, device logic, bus logic), all of them being
optional. This replaces D0/D3 transitions.
- device_is_active returns true if the device was not disabled and was
not suspended (even partially), device_is_enabled returns true if the
device was enabled.
- Change pnp_global_transition into pnp_system_suspend and
pnp_system_resume. Before running any suspend/resume handlers, check
that all currently attached devices support power management and bail
out otherwise. The latter is not done for the shutdown/panic case.
- Make the former bus-specific generic network handlers a class handler.
- Make PNP message like volume up/down/toogle PNP events. Each device
can register what events they are interested in and whether the handler
should be global or not.
- Introduce device_active API for devices to mark themselve in use from
either the system or the device. Use this to implement the idle handling
for audio and input devices. This is intended to replace most ad-hoc
watchdogs as well.
- Fix somes situations in which audio resume would lose mixer settings.
- Make USB host controllers better deal with suspend in the light of
shared interrupts.
- Flush filesystem cache on suspend.
- Flush disk caches on suspend. Put ATA disks into standby on suspend as
well.
- Adopt drivers to use the new PNP API.
- Fix a critical bug in the generic cardbus layer that made D0->D3
break.
- Fix ral(4) to set if_stop.
- Convert cbb(4) to the new PNP API.
- Apply the PCI Express SCI fix on resume again.
 1.96.6.4  02-Oct-2007  joerg Sync with HEAD.
 1.96.6.3  01-Oct-2007  joerg Extend device API by device_power_private and device_power_set_private.
The latter is a temporary mean until the pnp_register API itself is
overhault. This functions allow a generic power handler to store its
state independent of the driver.

Use this and revamp the PCI power handling. Pretty much all PCI devices
had power handlers that did the same thing, generalize this in
pci_generic_power_register/deregister and the handler. This interface
offers callbacks for the drivers to save and restore state on
transistions. After a long discussion with jmcneill@ it was considered
to be powerful enough until evidence is shown that devices can handle
D1/D2 with less code and higher speed than without the full
save/restore. The generic code is carefully written to handle device
without PCI-PM support and ensure that the correct registers are written
to when D3 loses all state.

Reimplement the generic PCI network device handling on
top of PCI generic power handling.

Introduce pci_disable_retry as used and implemented locally at least by
ath(4) and iwi(4). Use it in this drivers to restore behaviour from
before the introduction of generic PCI network handling.

Convert all PCI drivers that were using pnp_register to the new
framework. The only exception is vga(4) as it is commonly used as
console device. Add a note therein that this should be fixed later.
 1.96.6.2  03-Sep-2007  jmcneill Sync with HEAD.
 1.96.6.1  03-Aug-2007  jmcneill Pull in power management changes from private branch.
 1.96.2.1  03-Sep-2007  skrll Sync with HEAD.
 1.97.4.1  06-Oct-2007  yamt sync with head.
 1.97.2.3  23-Mar-2008  matt sync with HEAD
 1.97.2.2  09-Jan-2008  matt sync with HEAD
 1.97.2.1  06-Nov-2007  matt sync with HEAD
 1.98.8.1  11-Dec-2007  yamt sync with head.
 1.98.6.1  26-Dec-2007  ad Sync with head.
 1.98.4.2  18-Feb-2008  mjf Add some devfs code that's been sitting in my local tree for a while.

devfsd(8) is now the first daemon to be started after init(8). It tracks
device insertion (will eventually track removal) and devfs mounts.

Currently, we can mount multiple device file systems and have device
special files pushed into the mounts automatically, though, the device
special files aren't created with the correct major/minor number pairs
yet.

More work to come soon.
 1.98.4.1  18-Feb-2008  mjf Sync with HEAD.
 1.99.4.1  16-Dec-2007  cube Split off device-specific stuff out of subr_autconf.c, and split off
autoconf-specific stuff out of device.h.

The only functional change is the removal of the unused evcnt.h include in
device.h which (*sigh*) has side-effects in x86's intr.h, and probably some
other in the rest of the tree but I'm only compiling i386's QEMU for the
time being.
 1.99.2.1  02-Jan-2008  bouyer Sync with HEAD
 1.103.6.6  17-Jan-2009  mjf Sync with HEAD.
 1.103.6.5  29-Jun-2008  mjf Sync with HEAD.
 1.103.6.4  02-Jun-2008  mjf Sync with HEAD.
 1.103.6.3  03-Apr-2008  mjf Sync with HEAD.
 1.103.6.2  20-Mar-2008  mjf - Introduce new API for allowing device drivers to register/unregister
names for device nodes along with a corresponding dev_t.

- Make device drivers that technically never get attached and need device
nodes (mem, zero, null) provide an initialisation function, which gets
an entry in a table of init functions that devsw_init() calls when the
device switch tables are initialised.

- Since we're moving to a new way of notifying devfsd(8) of new devices,
we no longer need to link together struct devices.
 1.103.6.1  21-Feb-2008  mjf Start where the mjf-devfs branch left off.
 1.103.2.1  24-Mar-2008  keiichi sync with head.
 1.109.6.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.109.4.6  11-Aug-2010  yamt sync with head.
 1.109.4.5  11-Mar-2010  yamt sync with head
 1.109.4.4  16-Sep-2009  yamt sync with head
 1.109.4.3  18-Jul-2009  yamt sync with head.
 1.109.4.2  16-May-2009  yamt sync with head
 1.109.4.1  04-May-2009  yamt sync with head.
 1.109.2.2  17-Jun-2008  yamt sync with head.
 1.109.2.1  04-Jun-2008  yamt sync with head
 1.111.2.1  18-Jun-2008  simonb Sync with head.
 1.112.6.2  07-Jan-2011  riz Pull up following revision(s) (requested by mrg in ticket #1520):
sys/sys/device.h: revision 1.133
sys/kern/subr_disk.c: patch
Add helper function that determines the size and block size of a disk device.
For now we query
- the disk label
- the wedge info and data from disk(9)
 1.112.6.1  15-Mar-2009  snj branches: 1.112.6.1.4;
Pull up following revision(s) (requested by christos in ticket #458):
sys/conf/Makefile.kern.inc: revision 1.121
sys/conf/files: revision 1.940
sys/kern/init_main.c: revision 1.381
sys/kern/kern_ssp.c: revision 1.1
sys/kern/subr_autoconf.c: revision 1.168
sys/sys/device.h: revision 1.116
sys/sys/systm.h: revision 1.233
Unbreak ssp kernels. The issue here that when the ssp_init() call was
deferred, it caused the return from the enclosing function to break, as
well as the ssp return on i386. To fix both issues, split configure in
two pieces the one before calling ssp_init and the one after, and move
the ssp_init() call back in main. Put ssp_init() in its own file, and
compile this new file with -fno-stack-protector. Tested on amd64.
XXX: If we want to have ssp kernels working on 5.0, this change needs to
be pulled up.
 1.112.6.1.4.1  14-Nov-2013  matt more things for xhci
 1.112.4.3  28-Apr-2009  skrll Sync with HEAD.
 1.112.4.2  03-Mar-2009  skrll Sync with HEAD.
 1.112.4.1  19-Jan-2009  skrll Sync with HEAD.
 1.112.2.1  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.115.4.2  23-Jul-2009  jym Sync with HEAD.
 1.115.4.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.133.2.2  17-Aug-2010  uebayasi Sync with HEAD.
 1.133.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.135.2.4  31-May-2011  rmind sync with head
 1.135.2.3  05-Mar-2011  rmind sync with head
 1.135.2.2  03-Jul-2010  rmind sync with head
 1.135.2.1  30-May-2010  rmind sync with head
 1.137.4.1  08-Feb-2011  bouyer Sync with HEAD
 1.137.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.139.4.3  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.139.4.2  30-Oct-2012  yamt sync with head
 1.139.4.1  17-Apr-2012  yamt sync with head
 1.140.6.1  05-Jul-2012  riz Pull up following revision(s) (requested by mlelstv in ticket #402):
sys/dev/vnd.c: revision 1.221
sys/kern/init_main.c: revision 1.443
sys/kern/init_main.c: revision 1.444
sys/dev/dkwedge/dk.c: revision 1.64
sys/arch/x86/x86/x86_autoconf.c: revision 1.63
sys/arch/sparc64/sparc64/autoconf.c: revision 1.187
sys/sys/device.h: revision 1.141
sys/dev/dkwedge/dkwedge_bsdlabel.c: revision 1.17
sys/kern/kern_subr.c: revision 1.213
sys/arch/zaurus/zaurus/autoconf.c: revision 1.11
sys/arch/xen/x86/autoconf.c: revision 1.14
sys/sys/disk.h: revision 1.57
Use the label's packname to create wedge names instead of the classic
device names. Fall back to classic device names when the label has an
empty name or the default name 'fictitious'.
autodiscover wedges
Make detection of root on wedges (dk(4)) machine independent. Remove
MD code for x86, xen, sparc64.
Make detection of root on wedges (dk(4)) machine independent. Remove
MD code for zaurus.
Do not try to find the wedge we booted from if opendisk(booted_device)
failed.
 1.142.2.4  03-Dec-2017  jdolecek update from HEAD
 1.142.2.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.142.2.2  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.142.2.1  12-Sep-2012  tls Initial snapshot of work to eliminate 64K MAXPHYS. Basically works for
physio (I/O to raw devices); needs more doing to get it going with the
filesystems, but it shouldn't damage data.

All work's been done on amd64 so far. Not hard to add support to other
ports. If others want to pitch in, one very helpful thing would be to
sort out when and how IDE disks can do 128K or larger transfers, and
adjust the various PCI IDE (or at least ahcisata) drivers and wd.c
accordingly -- it would make testing much easier. Another very helpful
thing would be to implement a smart minphys() for RAIDframe along the
lines detailed in the MAXPHYS-NOTES file.
 1.143.2.1  18-May-2014  rmind sync with head
 1.144.4.2  05-Jul-2016  snj Pull up following revision(s) (requested by bouyer in ticket #1186):
sys/dev/ata/wd.c: revision 1.421
sys/kern/subr_autoconf.c: revision 1.242 via patch
sys/sys/device.h: revision 1.149
Add a new config_detach() flag, DETACH_POWEROFF, which is set when
detaching devices at shutdown time with RB_POWERDOWN.
When detaching wd(4), put the drive in standby before detach
for DETACH_POWEROFF.
Fix PR kern/51252
 1.144.4.1  09-Mar-2015  snj Pull up following revision(s) (requested by mrg in ticket #576):
sys/kern/init_main.c: revision 1.462
sys/kern/subr_autoconf.c: revision 1.234
sys/sys/device.h: revision 1.147
wait for config_mountroot threads to complete before we tell init it
can start up. this solves the problem where a console device needs
mountroot to complete attaching, and must create wsdisplay0 before
init tries to open /dev/console. fixes PR#49709.
XXX: pullup-7
 1.146.2.3  09-Jul-2016  skrll Sync with HEAD
 1.146.2.2  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.146.2.1  06-Apr-2015  skrll Sync with HEAD
 1.149.10.1  23-Sep-2018  martin Pull up following revision(s) (requested by mrg in ticket #1025):

sys/kern/subr_autoconf.c: revision 1.263
sys/kern/kern_drvctl.c: revision 1.44
sys/sys/device.h: revision 1.156
sys/sys/systm.h: revision 1.278

- move export for devmon_insert_vec into sys/device.h.
- export root_is_mounted for future USB RB_ASKNAME hack.
- make some things in subr_autoconf.c static
- move device_printf() prototype out from the middle of two sets of
aprint_*() prototypes.
 1.149.8.2  28-Apr-2017  pgoyette Introduce config_detach_release() which does all the work from the
former config_detach(). Now, config_detach() simply acquires a
reference to the device, which config_detach_release() can release!

This is needed because some drivers call config_detach() with a
reference, while other drivers have not been updated to use the
localcount reference mechanism. So we provide a shim to make
everyone equal.
 1.149.8.1  27-Apr-2017  pgoyette Restore all work from the former pgoyette-localcount branch (which is
now abandoned doe to cvs merge botch).

The branch now builds, and installs via anita. There are still some
problems (cgd is non-functional and all atf tests time-out) but they
will get resolved soon.
 1.149.2.3  24-Jul-2016  pgoyette Add a device_acquire() for when we need to grab a reference and we
already have a pointer to the device.
 1.149.2.2  16-Jul-2016  pgoyette Add new xxx_acquire variants for device_lookup_private() and
device_find_by_driver_unit_acquire rather than blindly making the old
variants call localcount_acquire().

Also fix a couple of locking sequences.

Thanks to Taylor for the review!
 1.149.2.1  16-Jul-2016  pgoyette Initial set of changes for subr_autoconf usage of localcount mechanism.

Nothing actually uses this yet - all callers of device_lookup() need
conversion to device_lookup_acquire()/device_release(). This also
means that callers of device_lookup_private() need to be modified to
call device_release() when finished accessing the softc.

XXX Perhaps device_lookup_private() should be removed, and all callers
XXX modified to use device_lookup_acquire()/.../device_release()?
 1.151.2.4  26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.151.2.3  30-Sep-2018  pgoyette Ssync with HEAD
 1.151.2.2  28-Jul-2018  pgoyette Sync with HEAD
 1.151.2.1  25-Jun-2018  pgoyette Sync with HEAD
 1.155.2.1  10-Jun-2019  christos Sync with HEAD
 1.158.2.2  03-Apr-2021  thorpej Sync with HEAD.
 1.158.2.1  14-Dec-2020  thorpej Sync w/ HEAD.
 1.167.2.10  24-Apr-2021  thorpej Use a value for CFARG_EOL that is not likely to be encountered randomly in
nature. Suggested by dholland.
 1.167.2.9  04-Apr-2021  thorpej Add a config_probe() function. This is currently a synonym for config_match(),
but exists so as to make a distinction between probing (as is done in indirect
configuration) and matching (which is done in direct configuration).

The intention is for direct config "submatch" routines to use config_match()
and for indirect config "search" routines to use config_probe().
 1.167.2.8  04-Apr-2021  thorpej Add a CFARG_SEARCH tag, which specifies an indirect config search function
(which has the same signature as a direct config submatch function). This
is a synonym for CFARG_SUBMATCH internally, but this is an implementation
detail; the two things should be distinct to callers, because submatch
and search functions have different behaviors. Only one SEARCH or SUBMATCH
argument is allowed.

Also, change config_get_cfargs() to panic if an unknown tag is passed
(we don't know what kind of argument to consume after an unknown tag, so
this is fatal).
 1.167.2.7  03-Apr-2021  thorpej Add CFARG_DEVHANDLE, allowing direct configuration using e.g. ACPI or
OpenFirmware / FDT to associate the handle with the device_t.
 1.167.2.6  03-Apr-2021  thorpej config_attach_loc() -> config_attach() with CFARG_LOCATORS argument.
 1.167.2.5  03-Apr-2021  thorpej Give config_attach() the tagged variadic argument treatment and
mechanically convert all call sites.
 1.167.2.4  02-Apr-2021  thorpej config_found_ia() -> config_found() w/ CFARG_IATTR.
 1.167.2.3  22-Mar-2021  thorpej Temporarily continue to provide config_found_ia().
 1.167.2.2  21-Mar-2021  thorpej Give config_found() the same variadic arguments treatment as
config_search(). This commit only adds the CFARG_EOL sentinel
to the existing config_found() calls. Conversion of config_found_sm_loc()
and config_found_ia() call sites will be in subsequent commits.
 1.167.2.1  20-Mar-2021  thorpej The proliferation if config_search_*() and config_found_*() combinations
is a little absurd, so begin to tidy this up:

- Introduce a new cfarg_t enumerated type, that defines the types of
tag-value variadic arguments that can be passed to the various
config_*() functions (CFARG_SUBMATCH, CFARG_IATTR, and CFARG_LOCATORS,
for now, plus a CFARG_EOL sentinel).
- Collapse config_search_*() into config_search() that takes these
variadic arguments.
- Convert all call sites of config_search_*() to the new signature.
Noticed several incorrect usages along the way, which will be
audited in a future commit.
 1.168.2.3  17-Jun-2021  thorpej Sync w/ HEAD.
 1.168.2.2  15-May-2021  thorpej Expose devhandle_lookup_device_call(), which can be useful when
"sub-classing" a devhandle implementation.
 1.168.2.1  13-May-2021  thorpej Sync with HEAD.
 1.169.2.1  31-May-2021  cjep sync with head
 1.171.2.2  07-Aug-2021  thorpej Hide "struct cfargs" from user space.
 1.171.2.1  03-Aug-2021  thorpej Address concerns about limited compile-time type checking with the
tag-value mechanism of specifying arguments to config_search(),
config_found(), and config_attach() by replacing the tag-value scheme
with a "struct cfargs", a pointer to which is passed to the aforementioned
functions instead.

The structure has a version field to allow for future ABI versioning
flexibility. The external structure is canononicalized internally
before use.

To ease the initialization of this structure, use a variadic preprocessor
macro, CFARGS(), to construct an anonymous "struct cfargs" inline, the
address of which is passed to the target function. A CFARGS_NONE macro
provides a symbolic stand-in for when the caller doesn't want to pass
arguments (currently expands to NULL and is handled during canonicalization).
 1.173.2.1  11-Sep-2021  thorpej Add a devhandle_subclass() helper function to simplify the common case
and use it. Improve some comments.
 1.188.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed