History log of /openbsd-current/sys/kern/subr_autoconf.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.97 07-Nov-2022 robert

introduce a new kern.autoconf_serial sysctl that can be used by userland
to monitor state changes of the kernel device tree

input from dnd ok dlg@, deraadt@


Revision tags: OPENBSD_7_2_BASE
# 1.96 07-Apr-2022 tb

Fix kernel builds with pseudo-device rd

Make the cf_attach member of struct cfdata const and sprinkle a few
const into subr_autoconf.c to make this work. Fixes the compilation
of sys/dev/rd.c with newly const rd_ca.

ok miod (who had a similar diff)


Revision tags: OPENBSD_7_1_BASE
# 1.95 26-Oct-2021 deraadt

Improve unhibernate performance (30% on some machines, another upcoming diff
shows gains up to 50%) by skipping attach of irrelevant devices, which are
tagged CD_SKIPHIBERNATE in the per-driver cfdriver. In particular, usb devices
are not attached, so they don't need to detach during the suspend-unpack-resume.
New bootblocks are required (which tell the kernel it's job is unhibernate
before configure runs)
tested by various


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.94 30-Dec-2019 jsg

convert infinite msleep(9) to msleep_nsec(9)

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.93 05-Dec-2018 mpi

free(9) sizes for softcs.

ok tedu@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.92 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.91 20-Dec-2015 mpi

Simple free(9) sizes, from Matthieu <naabed AT poolp DOT org>.


# 1.90 11-Dec-2015 mpi

Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).

ok mikeb@, deraadt@


# 1.89 11-Sep-2015 dlg

back out refcnt for dv_ref, there's too many hand crafted devices all
over the tree.

much encouragement from l2k15


# 1.88 11-Sep-2015 dlg

use refcnts for the device reference counts as an example of how
refcnt(9) can be used.


Revision tags: OPENBSD_5_8_BASE
# 1.87 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.86 09-Feb-2015 dlg

you need atomic.h to do atomic things.

pointed out by deraadt@


# 1.85 09-Feb-2015 dlg

use atomic ops to increment and decrement the device ref count in
device_ref and device_unref.

ok guenther@ deraadt@


# 1.84 22-Jan-2015 dlg

bring back r1.80:

pass the size of the softc to free.

this time we only dereference the cfattach structure if we actually
need it once the refcount has dropped to 0.

tested by krw@ who found the original panic r1.80 was backed out for.
putting this in again so i can find out when else will break.


# 1.83 19-Jan-2015 deraadt

back it out properly


# 1.82 19-Jan-2015 deraadt

never tested with a make release


# 1.81 19-Jan-2015 dlg

pass the size of the softc to free.

ok deraadt@


# 1.80 18-Sep-2014 kettenis

Introduce config_suspend_all(9) a function that invokes config_suspend(9)
on all relevant device hierarchies in the appropriate order. For now this
means mpath(4) and mainbus(4), doing mpath(4) before mainbus(4) when
suspending or powering down and doing mpath(4) after mainbus(4) when
resuming such that mpath(4) can realy on the underlying hardware being
in a functional state.

Fixes problems with unflushed disk caches on machines where mpath(4) takes
control of some of your disks.

ok dlg@


# 1.79 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.78 13-Jul-2014 tedu

use mallocarray where arguments are multipled. ok deraadt


# 1.77 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.76 12-Jul-2014 mpi

Change config_deactivate(9) to always unset the DVF_ACTIVE flag so
that drivers can check for this flag to know they have to stop doing
any hardware access and release their reference.

While here makes the ca_activate() function optional and propagates
DVACT_DEACTIVATE to the children of a device that do not implement this
interface like it is done during suspend/resume.

ok uebayasi@, deraadt@


# 1.75 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


# 1.74 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.73 12-Dec-2013 guenther

printf(variable) --> printf("%s", variable)

ok deraadt@


# 1.72 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.71 29-Nov-2013 deraadt

msgs can be const


# 1.70 27-Nov-2013 dlg

get rid of the goop for maintaining multiple cftables since theres
no current code there to add or remove them. such code was put in
17 years ago, disabled 14 years ago, and removed 11 years ago, so
i suspect we dont really need it or the goop to support it.

very ok miod@


# 1.69 26-Nov-2013 dlg

compare pointers to NULL


Revision tags: OPENBSD_5_4_BASE
# 1.68 30-May-2013 deraadt

Enforce ca_activate tree-walks over the entire heirarchy for all events,
cleaning up some shutdown-hook related code on the way.
(A few drivers related to sparc are still skipped at kettenis' request)
ok kettenis mlarkin, tested by many others too


Revision tags: OPENBSD_5_3_BASE
# 1.67 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.66 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.65 20-Jun-2011 deraadt

serialize attach and detach of device sub-trees -- only one device
sub-tree may attach or detach at a time. attach and detach will sleep
against each other.
this is fixing (working around?) some bizzare corner cases that have
been seen (but not fully diagnosed) where the device trees, disk registration
subsystem, and other things could get messed up. one could argue though
that this serialization is a very good thing; it is easier than adding piles
of locks in various other places.
ok matthew jsing


# 1.64 01-Jun-2011 matthew

Add a few KASSERTs to config_attach() for sanity to make sure we don't
try to reuse device unit numbers and to check that the device pointer
array is allocated and large enough.

Also, improve the panic message generated by config_detach() when we
detect that we're detaching a device that still has children.

Discussed with deraadt@ while trying to brainstorm ways that
interleaving config_attach and config_detach could blow up.


Revision tags: OPENBSD_4_9_BASE
# 1.63 08-Sep-2010 deraadt

remove a useless comment


# 1.62 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


Revision tags: OPENBSD_4_8_BASE
# 1.61 30-Jun-2010 deraadt

Silence the activation debug reporting. We are starting to get worried
that there are interactions when we print in the various (saved, post-saved,
pre-restored, and restored) vga states, especially with how intel drm is
getting involved. If your machine has issues, you may want to activate
these messages again to help debug things better.
ok mlarkin


Revision tags: OPENBSD_4_7_BASE
# 1.60 28-Feb-2010 miod

Remove leftover debug printf in config_activate_children(); ok deraadt


# 1.59 23-Nov-2009 deraadt

Make config_activate_children() more useable as a suspend-and-resume
device tree walker, and add config_suspend() as well.
ok mlarkin pirofti, discussion with kettenis


# 1.58 22-Nov-2009 pirofti

Add basic suspend/resume autoconf functionality.

Okay deraadt@, kettenis@, mlarkin@.


# 1.57 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.56 20-Aug-2008 miod

Allow devices attaching at root (such as softraid) to be disabled in UKC.
ok marco@ deraadt@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.55 23-Nov-2007 kettenis

Since the devices that we detach may have children we cannot rely on the
"previous" device still being there, so if we detach a device, we really
have to start from scratch again (like the comment on this code actually
says we should). Simplifies the code as a bonus.

ok dlg@, deraadt@


# 1.54 29-Oct-2007 dlg

get rid of the unused cond_predicate_t typedef.

ok miod@ deraadt@ krw@


# 1.53 07-Sep-2007 art

Use M_ZERO in a few more places to shave bytes from the kernel.

eyeballed and ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.52 30-May-2007 deraadt

the (root) stuff is ugly, so print "at root", so it looks more like
regular things. everyone here buys it, and i'm 90% sure miod will be
ok with it


# 1.51 15-May-2007 deraadt

kill __HAVE_DEVICE_REGISTER by requiring all architectures to have a
device_register() function -- even if it does nothing. reduces the
cpp-based blather different between architectures
idea ok'd by miod; tested on all architectures (except a few miod will
need to cleanup because he has them)


# 1.50 09-May-2007 deraadt

evcnt_attach() is no longer used; ok miod


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.49 28-May-2006 mk

Remove device id from hotplug events.

ok henning


# 1.48 28-May-2006 deraadt

more fallout from the sensors: Every single ramdisk got broken.


# 1.47 28-May-2006 mk

Include device id in hotplug events. This will be used by ntpd to check
sensors on attach/detach. hotplugd changes following in a minute.

ok henning.


# 1.46 17-May-2006 krw

cf_unit should have a value between 0 and cd_ndevs. So set cf_unit to 0 when
cd_ndevs is set to 0.

"No kidding!" deraadt@ "Seems to make sense to me." beck@ "Seems right." miod@


# 1.45 17-May-2006 krw

Detach children devices in reverse order. This gives better display, and
allows cf_unit to be decremented correctly.

'put it in' deraadt@ "i think it's good' tedu@


# 1.44 14-May-2006 krw

When assigning a unit number, treat running off the end of the
cd_devs[] array the same as finding a NULL entry.

Fixes inconsistant assignment of unit numbers to media slots on the
Neodio 8-in-1 USB card reader donated by Manuel Pata. Previously the
unit numbers would vary depending on whether it had attached an even
or odd number of times.

'reads ok' marco@ ok miod@


Revision tags: OPENBSD_3_9_BASE
# 1.43 21-Jan-2006 miod

Remove now unused zeroref member in cfattach structures.


# 1.42 13-Jan-2006 miod

In config_detach_children(), after detaching a device, restart the device
list walk from its parent device, as the device which was following it may
have been one of its children, and thus gone as well. Found the hard way
using the strict queue macros.

Feedback and help toby@, ok deraadt@


# 1.41 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.40 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


# 1.39 23-Nov-2004 miod

Create the init process earlier, before the root filesystem is mounted,
and have it stall on a semaphore. This allows all kthread creations which
could have been requested during autoconf to be processed before root
is mounted as well.

This causes umass devices attached to any usb with flags 1 (such as on macppc)
to configure properly instead of panicing the kernel at mountroot time.

From NetBSD; tested by various.


Revision tags: OPENBSD_3_6_BASE
# 1.38 03-Aug-2004 pefo

Fix a minor bug where indirect config crashes the kernel
when match verbose is turend on.


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.37 30-May-2004 grange

Devices hot plugging support.
The hotplug pseudo-device passes device attachment and detachment events
to userland. When a device attaches or detaches, the corresponding event
is queued. The events can then be obtained from the queue through the
read(2) call on the /dev/hotplug device file. Each event consists of
event type (attach/detach), device class (DV_*) and device name (sd1 e.g.).

We have hotplug pseudo-device on alpha, amd64, i386, macppc and sparc64.
Since it was tested only on i386 other archs has it commented out
in GENERIC until tested.

The idea liked peter@ tedu@ drahn@ millert@ marco@ henning@.
Ok deraadt@.


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.36 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.35 03-May-2003 deraadt

string fixes; tedu ok


# 1.34 19-Apr-2003 krw

Tweak previous sprintf -> snprintf fix to eliminate unnecessary
intermediate variable.

Suggested by deraadt@.

ok henning@ millert@ tdeval@


# 1.33 30-Mar-2003 krw

Use snprintf() to simplify device name construction, removing now
superfluous variables and the function 'number()'.

ok deraadt@ and millert@


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_B
# 1.32 06-Oct-2002 art

Remove some '#if 0' cruft.


Revision tags: OPENBSD_3_2_BASE
# 1.31 24-Apr-2002 espie

Introduce a new file, machine/internal_types.h, to hold that specific arch
type characteristics.

internal_types.h will contain only settings invisible from standard C, e.g.,
in the __* or _[A-Z]* namespace, and be reused by files like limits.h.

This allows us to shorten machine/limits.h greatly, as all the common defines
are now in sys/limits.h, plus a small stub in internal_types.h.

Tested on all arches as far as I know.
Approved after discussion with art, millert, deraadt, and others.


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.29 01-Sep-2001 jason

branches: 1.29.4;
Add __HAVE_DEVICE_REGISTER to hp300/alpha (sparc64 already had it) and
clean up the arch specific #ifdef's in subr_autoconf.c; from NetBSD.
(tested by me on alpha/sparc64 and miod on hp300)


# 1.28 31-Aug-2001 jason

implement autoconf mechanism using device_register(); from NetBSD.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.27 09-Apr-2000 deraadt

range error; < cd_ndevs, not <=


# 1.26 09-Apr-2000 csapuntz

Added config_detach_children, config_activate_children.

Added ref counting to devices: device_ref, device_unref and a new method
for devices : ca_zeroref, called when the ref count hits zero.

Note that ca_zeroref may be called from interrupt context.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.25 08-Aug-1999 niklas

branches: 1.25.4;
From NetBSD; new device detaching infrastructure.


# 1.24 05-Aug-1999 niklas

From NetBSD; config_defer to defer configuration of a device until after all
other siblings.


# 1.23 23-Jul-1999 niklas

Remove obsolete detach logic in preparation of a newer one


Revision tags: OPENBSD_2_5_BASE
# 1.22 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.21 11-May-1998 niklas

Formerly reuse of unit numbers of detached devices was impossible, with
this change starred devices will search from the first allowed unit for
such devices and up for free units when attaching. This means you have
to rerun config(8) before yopu compile current kernels. FYI, this is
a necessity when doing PCMCIA flashcard reading, otherwise you soon run
out of unit numbers.

I have also added a way to detach all children of a certain device, used
in a new PCMCIA framework to come, so you detach all functions on a
single PCMCIA card when pulling it out.

A few bugs wrt starred devices fixed in the autoconfig_verbose code too.
Last and least, fixed some panic messages.


Revision tags: OPENBSD_2_3_BASE
# 1.20 20-Feb-1998 niklas

Please GCC 2.8's harsher view of good style


# 1.19 21-Jan-1998 niklas

Prevent a NULL-deref in the autoconf_verbose case


# 1.18 20-Jan-1998 niklas

typo


# 1.17 20-Jan-1998 niklas

Provide a way to debug probes. set autoconf_verbose via DDB, or
option AUTOCONF_VERBOSE=1
in your kernel config.


# 1.16 23-Nov-1997 mickey

indent


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.15 03-Feb-1997 downsj

hp300 needs device_register(), too.


# 1.14 21-Nov-1996 mickey

export struct cfdata cfdata[];


# 1.13 18-Oct-1996 niklas

As alpha uses device_register, it needs its proto too


Revision tags: OPENBSD_2_0_BASE
# 1.12 24-Sep-1996 deraadt

no mknod in chroot


# 1.11 15-Aug-1996 niklas

Remove unnecessary prototype


# 1.10 02-Jul-1996 deraadt

pretty


# 1.9 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.8 23-Jun-1996 maja

Added support for user modifiable kernel at boot (-c) /maja


# 1.7 18-Jun-1996 deraadt

sick netbsd alpha hack (why not do what other ports do?)


# 1.6 07-May-1996 niklas

Make sure config_init gets called before consinit, as at least one port
actually uses config_* functions for console attachment. Document
config_init should not call malloc as the move was over the mem-init
function calls too.


# 1.5 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.96 07-Apr-2022 tb

Fix kernel builds with pseudo-device rd

Make the cf_attach member of struct cfdata const and sprinkle a few
const into subr_autoconf.c to make this work. Fixes the compilation
of sys/dev/rd.c with newly const rd_ca.

ok miod (who had a similar diff)


Revision tags: OPENBSD_7_1_BASE
# 1.95 26-Oct-2021 deraadt

Improve unhibernate performance (30% on some machines, another upcoming diff
shows gains up to 50%) by skipping attach of irrelevant devices, which are
tagged CD_SKIPHIBERNATE in the per-driver cfdriver. In particular, usb devices
are not attached, so they don't need to detach during the suspend-unpack-resume.
New bootblocks are required (which tell the kernel it's job is unhibernate
before configure runs)
tested by various


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.94 30-Dec-2019 jsg

convert infinite msleep(9) to msleep_nsec(9)

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.93 05-Dec-2018 mpi

free(9) sizes for softcs.

ok tedu@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.92 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.91 20-Dec-2015 mpi

Simple free(9) sizes, from Matthieu <naabed AT poolp DOT org>.


# 1.90 11-Dec-2015 mpi

Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).

ok mikeb@, deraadt@


# 1.89 11-Sep-2015 dlg

back out refcnt for dv_ref, there's too many hand crafted devices all
over the tree.

much encouragement from l2k15


# 1.88 11-Sep-2015 dlg

use refcnts for the device reference counts as an example of how
refcnt(9) can be used.


Revision tags: OPENBSD_5_8_BASE
# 1.87 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.86 09-Feb-2015 dlg

you need atomic.h to do atomic things.

pointed out by deraadt@


# 1.85 09-Feb-2015 dlg

use atomic ops to increment and decrement the device ref count in
device_ref and device_unref.

ok guenther@ deraadt@


# 1.84 22-Jan-2015 dlg

bring back r1.80:

pass the size of the softc to free.

this time we only dereference the cfattach structure if we actually
need it once the refcount has dropped to 0.

tested by krw@ who found the original panic r1.80 was backed out for.
putting this in again so i can find out when else will break.


# 1.83 19-Jan-2015 deraadt

back it out properly


# 1.82 19-Jan-2015 deraadt

never tested with a make release


# 1.81 19-Jan-2015 dlg

pass the size of the softc to free.

ok deraadt@


# 1.80 18-Sep-2014 kettenis

Introduce config_suspend_all(9) a function that invokes config_suspend(9)
on all relevant device hierarchies in the appropriate order. For now this
means mpath(4) and mainbus(4), doing mpath(4) before mainbus(4) when
suspending or powering down and doing mpath(4) after mainbus(4) when
resuming such that mpath(4) can realy on the underlying hardware being
in a functional state.

Fixes problems with unflushed disk caches on machines where mpath(4) takes
control of some of your disks.

ok dlg@


# 1.79 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.78 13-Jul-2014 tedu

use mallocarray where arguments are multipled. ok deraadt


# 1.77 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.76 12-Jul-2014 mpi

Change config_deactivate(9) to always unset the DVF_ACTIVE flag so
that drivers can check for this flag to know they have to stop doing
any hardware access and release their reference.

While here makes the ca_activate() function optional and propagates
DVACT_DEACTIVATE to the children of a device that do not implement this
interface like it is done during suspend/resume.

ok uebayasi@, deraadt@


# 1.75 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


# 1.74 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.73 12-Dec-2013 guenther

printf(variable) --> printf("%s", variable)

ok deraadt@


# 1.72 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.71 29-Nov-2013 deraadt

msgs can be const


# 1.70 27-Nov-2013 dlg

get rid of the goop for maintaining multiple cftables since theres
no current code there to add or remove them. such code was put in
17 years ago, disabled 14 years ago, and removed 11 years ago, so
i suspect we dont really need it or the goop to support it.

very ok miod@


# 1.69 26-Nov-2013 dlg

compare pointers to NULL


Revision tags: OPENBSD_5_4_BASE
# 1.68 30-May-2013 deraadt

Enforce ca_activate tree-walks over the entire heirarchy for all events,
cleaning up some shutdown-hook related code on the way.
(A few drivers related to sparc are still skipped at kettenis' request)
ok kettenis mlarkin, tested by many others too


Revision tags: OPENBSD_5_3_BASE
# 1.67 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.66 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.65 20-Jun-2011 deraadt

serialize attach and detach of device sub-trees -- only one device
sub-tree may attach or detach at a time. attach and detach will sleep
against each other.
this is fixing (working around?) some bizzare corner cases that have
been seen (but not fully diagnosed) where the device trees, disk registration
subsystem, and other things could get messed up. one could argue though
that this serialization is a very good thing; it is easier than adding piles
of locks in various other places.
ok matthew jsing


# 1.64 01-Jun-2011 matthew

Add a few KASSERTs to config_attach() for sanity to make sure we don't
try to reuse device unit numbers and to check that the device pointer
array is allocated and large enough.

Also, improve the panic message generated by config_detach() when we
detect that we're detaching a device that still has children.

Discussed with deraadt@ while trying to brainstorm ways that
interleaving config_attach and config_detach could blow up.


Revision tags: OPENBSD_4_9_BASE
# 1.63 08-Sep-2010 deraadt

remove a useless comment


# 1.62 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


Revision tags: OPENBSD_4_8_BASE
# 1.61 30-Jun-2010 deraadt

Silence the activation debug reporting. We are starting to get worried
that there are interactions when we print in the various (saved, post-saved,
pre-restored, and restored) vga states, especially with how intel drm is
getting involved. If your machine has issues, you may want to activate
these messages again to help debug things better.
ok mlarkin


Revision tags: OPENBSD_4_7_BASE
# 1.60 28-Feb-2010 miod

Remove leftover debug printf in config_activate_children(); ok deraadt


# 1.59 23-Nov-2009 deraadt

Make config_activate_children() more useable as a suspend-and-resume
device tree walker, and add config_suspend() as well.
ok mlarkin pirofti, discussion with kettenis


# 1.58 22-Nov-2009 pirofti

Add basic suspend/resume autoconf functionality.

Okay deraadt@, kettenis@, mlarkin@.


# 1.57 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.56 20-Aug-2008 miod

Allow devices attaching at root (such as softraid) to be disabled in UKC.
ok marco@ deraadt@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.55 23-Nov-2007 kettenis

Since the devices that we detach may have children we cannot rely on the
"previous" device still being there, so if we detach a device, we really
have to start from scratch again (like the comment on this code actually
says we should). Simplifies the code as a bonus.

ok dlg@, deraadt@


# 1.54 29-Oct-2007 dlg

get rid of the unused cond_predicate_t typedef.

ok miod@ deraadt@ krw@


# 1.53 07-Sep-2007 art

Use M_ZERO in a few more places to shave bytes from the kernel.

eyeballed and ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.52 30-May-2007 deraadt

the (root) stuff is ugly, so print "at root", so it looks more like
regular things. everyone here buys it, and i'm 90% sure miod will be
ok with it


# 1.51 15-May-2007 deraadt

kill __HAVE_DEVICE_REGISTER by requiring all architectures to have a
device_register() function -- even if it does nothing. reduces the
cpp-based blather different between architectures
idea ok'd by miod; tested on all architectures (except a few miod will
need to cleanup because he has them)


# 1.50 09-May-2007 deraadt

evcnt_attach() is no longer used; ok miod


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.49 28-May-2006 mk

Remove device id from hotplug events.

ok henning


# 1.48 28-May-2006 deraadt

more fallout from the sensors: Every single ramdisk got broken.


# 1.47 28-May-2006 mk

Include device id in hotplug events. This will be used by ntpd to check
sensors on attach/detach. hotplugd changes following in a minute.

ok henning.


# 1.46 17-May-2006 krw

cf_unit should have a value between 0 and cd_ndevs. So set cf_unit to 0 when
cd_ndevs is set to 0.

"No kidding!" deraadt@ "Seems to make sense to me." beck@ "Seems right." miod@


# 1.45 17-May-2006 krw

Detach children devices in reverse order. This gives better display, and
allows cf_unit to be decremented correctly.

'put it in' deraadt@ "i think it's good' tedu@


# 1.44 14-May-2006 krw

When assigning a unit number, treat running off the end of the
cd_devs[] array the same as finding a NULL entry.

Fixes inconsistant assignment of unit numbers to media slots on the
Neodio 8-in-1 USB card reader donated by Manuel Pata. Previously the
unit numbers would vary depending on whether it had attached an even
or odd number of times.

'reads ok' marco@ ok miod@


Revision tags: OPENBSD_3_9_BASE
# 1.43 21-Jan-2006 miod

Remove now unused zeroref member in cfattach structures.


# 1.42 13-Jan-2006 miod

In config_detach_children(), after detaching a device, restart the device
list walk from its parent device, as the device which was following it may
have been one of its children, and thus gone as well. Found the hard way
using the strict queue macros.

Feedback and help toby@, ok deraadt@


# 1.41 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.40 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


# 1.39 23-Nov-2004 miod

Create the init process earlier, before the root filesystem is mounted,
and have it stall on a semaphore. This allows all kthread creations which
could have been requested during autoconf to be processed before root
is mounted as well.

This causes umass devices attached to any usb with flags 1 (such as on macppc)
to configure properly instead of panicing the kernel at mountroot time.

From NetBSD; tested by various.


Revision tags: OPENBSD_3_6_BASE
# 1.38 03-Aug-2004 pefo

Fix a minor bug where indirect config crashes the kernel
when match verbose is turend on.


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.37 30-May-2004 grange

Devices hot plugging support.
The hotplug pseudo-device passes device attachment and detachment events
to userland. When a device attaches or detaches, the corresponding event
is queued. The events can then be obtained from the queue through the
read(2) call on the /dev/hotplug device file. Each event consists of
event type (attach/detach), device class (DV_*) and device name (sd1 e.g.).

We have hotplug pseudo-device on alpha, amd64, i386, macppc and sparc64.
Since it was tested only on i386 other archs has it commented out
in GENERIC until tested.

The idea liked peter@ tedu@ drahn@ millert@ marco@ henning@.
Ok deraadt@.


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.36 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.35 03-May-2003 deraadt

string fixes; tedu ok


# 1.34 19-Apr-2003 krw

Tweak previous sprintf -> snprintf fix to eliminate unnecessary
intermediate variable.

Suggested by deraadt@.

ok henning@ millert@ tdeval@


# 1.33 30-Mar-2003 krw

Use snprintf() to simplify device name construction, removing now
superfluous variables and the function 'number()'.

ok deraadt@ and millert@


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_B
# 1.32 06-Oct-2002 art

Remove some '#if 0' cruft.


Revision tags: OPENBSD_3_2_BASE
# 1.31 24-Apr-2002 espie

Introduce a new file, machine/internal_types.h, to hold that specific arch
type characteristics.

internal_types.h will contain only settings invisible from standard C, e.g.,
in the __* or _[A-Z]* namespace, and be reused by files like limits.h.

This allows us to shorten machine/limits.h greatly, as all the common defines
are now in sys/limits.h, plus a small stub in internal_types.h.

Tested on all arches as far as I know.
Approved after discussion with art, millert, deraadt, and others.


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.29 01-Sep-2001 jason

branches: 1.29.4;
Add __HAVE_DEVICE_REGISTER to hp300/alpha (sparc64 already had it) and
clean up the arch specific #ifdef's in subr_autoconf.c; from NetBSD.
(tested by me on alpha/sparc64 and miod on hp300)


# 1.28 31-Aug-2001 jason

implement autoconf mechanism using device_register(); from NetBSD.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.27 09-Apr-2000 deraadt

range error; < cd_ndevs, not <=


# 1.26 09-Apr-2000 csapuntz

Added config_detach_children, config_activate_children.

Added ref counting to devices: device_ref, device_unref and a new method
for devices : ca_zeroref, called when the ref count hits zero.

Note that ca_zeroref may be called from interrupt context.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.25 08-Aug-1999 niklas

branches: 1.25.4;
From NetBSD; new device detaching infrastructure.


# 1.24 05-Aug-1999 niklas

From NetBSD; config_defer to defer configuration of a device until after all
other siblings.


# 1.23 23-Jul-1999 niklas

Remove obsolete detach logic in preparation of a newer one


Revision tags: OPENBSD_2_5_BASE
# 1.22 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.21 11-May-1998 niklas

Formerly reuse of unit numbers of detached devices was impossible, with
this change starred devices will search from the first allowed unit for
such devices and up for free units when attaching. This means you have
to rerun config(8) before yopu compile current kernels. FYI, this is
a necessity when doing PCMCIA flashcard reading, otherwise you soon run
out of unit numbers.

I have also added a way to detach all children of a certain device, used
in a new PCMCIA framework to come, so you detach all functions on a
single PCMCIA card when pulling it out.

A few bugs wrt starred devices fixed in the autoconfig_verbose code too.
Last and least, fixed some panic messages.


Revision tags: OPENBSD_2_3_BASE
# 1.20 20-Feb-1998 niklas

Please GCC 2.8's harsher view of good style


# 1.19 21-Jan-1998 niklas

Prevent a NULL-deref in the autoconf_verbose case


# 1.18 20-Jan-1998 niklas

typo


# 1.17 20-Jan-1998 niklas

Provide a way to debug probes. set autoconf_verbose via DDB, or
option AUTOCONF_VERBOSE=1
in your kernel config.


# 1.16 23-Nov-1997 mickey

indent


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.15 03-Feb-1997 downsj

hp300 needs device_register(), too.


# 1.14 21-Nov-1996 mickey

export struct cfdata cfdata[];


# 1.13 18-Oct-1996 niklas

As alpha uses device_register, it needs its proto too


Revision tags: OPENBSD_2_0_BASE
# 1.12 24-Sep-1996 deraadt

no mknod in chroot


# 1.11 15-Aug-1996 niklas

Remove unnecessary prototype


# 1.10 02-Jul-1996 deraadt

pretty


# 1.9 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.8 23-Jun-1996 maja

Added support for user modifiable kernel at boot (-c) /maja


# 1.7 18-Jun-1996 deraadt

sick netbsd alpha hack (why not do what other ports do?)


# 1.6 07-May-1996 niklas

Make sure config_init gets called before consinit, as at least one port
actually uses config_* functions for console attachment. Document
config_init should not call malloc as the move was over the mem-init
function calls too.


# 1.5 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.95 26-Oct-2021 deraadt

Improve unhibernate performance (30% on some machines, another upcoming diff
shows gains up to 50%) by skipping attach of irrelevant devices, which are
tagged CD_SKIPHIBERNATE in the per-driver cfdriver. In particular, usb devices
are not attached, so they don't need to detach during the suspend-unpack-resume.
New bootblocks are required (which tell the kernel it's job is unhibernate
before configure runs)
tested by various


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.94 30-Dec-2019 jsg

convert infinite msleep(9) to msleep_nsec(9)

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.93 05-Dec-2018 mpi

free(9) sizes for softcs.

ok tedu@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.92 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.91 20-Dec-2015 mpi

Simple free(9) sizes, from Matthieu <naabed AT poolp DOT org>.


# 1.90 11-Dec-2015 mpi

Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).

ok mikeb@, deraadt@


# 1.89 11-Sep-2015 dlg

back out refcnt for dv_ref, there's too many hand crafted devices all
over the tree.

much encouragement from l2k15


# 1.88 11-Sep-2015 dlg

use refcnts for the device reference counts as an example of how
refcnt(9) can be used.


Revision tags: OPENBSD_5_8_BASE
# 1.87 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.86 09-Feb-2015 dlg

you need atomic.h to do atomic things.

pointed out by deraadt@


# 1.85 09-Feb-2015 dlg

use atomic ops to increment and decrement the device ref count in
device_ref and device_unref.

ok guenther@ deraadt@


# 1.84 22-Jan-2015 dlg

bring back r1.80:

pass the size of the softc to free.

this time we only dereference the cfattach structure if we actually
need it once the refcount has dropped to 0.

tested by krw@ who found the original panic r1.80 was backed out for.
putting this in again so i can find out when else will break.


# 1.83 19-Jan-2015 deraadt

back it out properly


# 1.82 19-Jan-2015 deraadt

never tested with a make release


# 1.81 19-Jan-2015 dlg

pass the size of the softc to free.

ok deraadt@


# 1.80 18-Sep-2014 kettenis

Introduce config_suspend_all(9) a function that invokes config_suspend(9)
on all relevant device hierarchies in the appropriate order. For now this
means mpath(4) and mainbus(4), doing mpath(4) before mainbus(4) when
suspending or powering down and doing mpath(4) after mainbus(4) when
resuming such that mpath(4) can realy on the underlying hardware being
in a functional state.

Fixes problems with unflushed disk caches on machines where mpath(4) takes
control of some of your disks.

ok dlg@


# 1.79 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.78 13-Jul-2014 tedu

use mallocarray where arguments are multipled. ok deraadt


# 1.77 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.76 12-Jul-2014 mpi

Change config_deactivate(9) to always unset the DVF_ACTIVE flag so
that drivers can check for this flag to know they have to stop doing
any hardware access and release their reference.

While here makes the ca_activate() function optional and propagates
DVACT_DEACTIVATE to the children of a device that do not implement this
interface like it is done during suspend/resume.

ok uebayasi@, deraadt@


# 1.75 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


# 1.74 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.73 12-Dec-2013 guenther

printf(variable) --> printf("%s", variable)

ok deraadt@


# 1.72 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.71 29-Nov-2013 deraadt

msgs can be const


# 1.70 27-Nov-2013 dlg

get rid of the goop for maintaining multiple cftables since theres
no current code there to add or remove them. such code was put in
17 years ago, disabled 14 years ago, and removed 11 years ago, so
i suspect we dont really need it or the goop to support it.

very ok miod@


# 1.69 26-Nov-2013 dlg

compare pointers to NULL


Revision tags: OPENBSD_5_4_BASE
# 1.68 30-May-2013 deraadt

Enforce ca_activate tree-walks over the entire heirarchy for all events,
cleaning up some shutdown-hook related code on the way.
(A few drivers related to sparc are still skipped at kettenis' request)
ok kettenis mlarkin, tested by many others too


Revision tags: OPENBSD_5_3_BASE
# 1.67 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.66 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.65 20-Jun-2011 deraadt

serialize attach and detach of device sub-trees -- only one device
sub-tree may attach or detach at a time. attach and detach will sleep
against each other.
this is fixing (working around?) some bizzare corner cases that have
been seen (but not fully diagnosed) where the device trees, disk registration
subsystem, and other things could get messed up. one could argue though
that this serialization is a very good thing; it is easier than adding piles
of locks in various other places.
ok matthew jsing


# 1.64 01-Jun-2011 matthew

Add a few KASSERTs to config_attach() for sanity to make sure we don't
try to reuse device unit numbers and to check that the device pointer
array is allocated and large enough.

Also, improve the panic message generated by config_detach() when we
detect that we're detaching a device that still has children.

Discussed with deraadt@ while trying to brainstorm ways that
interleaving config_attach and config_detach could blow up.


Revision tags: OPENBSD_4_9_BASE
# 1.63 08-Sep-2010 deraadt

remove a useless comment


# 1.62 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


Revision tags: OPENBSD_4_8_BASE
# 1.61 30-Jun-2010 deraadt

Silence the activation debug reporting. We are starting to get worried
that there are interactions when we print in the various (saved, post-saved,
pre-restored, and restored) vga states, especially with how intel drm is
getting involved. If your machine has issues, you may want to activate
these messages again to help debug things better.
ok mlarkin


Revision tags: OPENBSD_4_7_BASE
# 1.60 28-Feb-2010 miod

Remove leftover debug printf in config_activate_children(); ok deraadt


# 1.59 23-Nov-2009 deraadt

Make config_activate_children() more useable as a suspend-and-resume
device tree walker, and add config_suspend() as well.
ok mlarkin pirofti, discussion with kettenis


# 1.58 22-Nov-2009 pirofti

Add basic suspend/resume autoconf functionality.

Okay deraadt@, kettenis@, mlarkin@.


# 1.57 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.56 20-Aug-2008 miod

Allow devices attaching at root (such as softraid) to be disabled in UKC.
ok marco@ deraadt@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.55 23-Nov-2007 kettenis

Since the devices that we detach may have children we cannot rely on the
"previous" device still being there, so if we detach a device, we really
have to start from scratch again (like the comment on this code actually
says we should). Simplifies the code as a bonus.

ok dlg@, deraadt@


# 1.54 29-Oct-2007 dlg

get rid of the unused cond_predicate_t typedef.

ok miod@ deraadt@ krw@


# 1.53 07-Sep-2007 art

Use M_ZERO in a few more places to shave bytes from the kernel.

eyeballed and ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.52 30-May-2007 deraadt

the (root) stuff is ugly, so print "at root", so it looks more like
regular things. everyone here buys it, and i'm 90% sure miod will be
ok with it


# 1.51 15-May-2007 deraadt

kill __HAVE_DEVICE_REGISTER by requiring all architectures to have a
device_register() function -- even if it does nothing. reduces the
cpp-based blather different between architectures
idea ok'd by miod; tested on all architectures (except a few miod will
need to cleanup because he has them)


# 1.50 09-May-2007 deraadt

evcnt_attach() is no longer used; ok miod


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.49 28-May-2006 mk

Remove device id from hotplug events.

ok henning


# 1.48 28-May-2006 deraadt

more fallout from the sensors: Every single ramdisk got broken.


# 1.47 28-May-2006 mk

Include device id in hotplug events. This will be used by ntpd to check
sensors on attach/detach. hotplugd changes following in a minute.

ok henning.


# 1.46 17-May-2006 krw

cf_unit should have a value between 0 and cd_ndevs. So set cf_unit to 0 when
cd_ndevs is set to 0.

"No kidding!" deraadt@ "Seems to make sense to me." beck@ "Seems right." miod@


# 1.45 17-May-2006 krw

Detach children devices in reverse order. This gives better display, and
allows cf_unit to be decremented correctly.

'put it in' deraadt@ "i think it's good' tedu@


# 1.44 14-May-2006 krw

When assigning a unit number, treat running off the end of the
cd_devs[] array the same as finding a NULL entry.

Fixes inconsistant assignment of unit numbers to media slots on the
Neodio 8-in-1 USB card reader donated by Manuel Pata. Previously the
unit numbers would vary depending on whether it had attached an even
or odd number of times.

'reads ok' marco@ ok miod@


Revision tags: OPENBSD_3_9_BASE
# 1.43 21-Jan-2006 miod

Remove now unused zeroref member in cfattach structures.


# 1.42 13-Jan-2006 miod

In config_detach_children(), after detaching a device, restart the device
list walk from its parent device, as the device which was following it may
have been one of its children, and thus gone as well. Found the hard way
using the strict queue macros.

Feedback and help toby@, ok deraadt@


# 1.41 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.40 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


# 1.39 23-Nov-2004 miod

Create the init process earlier, before the root filesystem is mounted,
and have it stall on a semaphore. This allows all kthread creations which
could have been requested during autoconf to be processed before root
is mounted as well.

This causes umass devices attached to any usb with flags 1 (such as on macppc)
to configure properly instead of panicing the kernel at mountroot time.

From NetBSD; tested by various.


Revision tags: OPENBSD_3_6_BASE
# 1.38 03-Aug-2004 pefo

Fix a minor bug where indirect config crashes the kernel
when match verbose is turend on.


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.37 30-May-2004 grange

Devices hot plugging support.
The hotplug pseudo-device passes device attachment and detachment events
to userland. When a device attaches or detaches, the corresponding event
is queued. The events can then be obtained from the queue through the
read(2) call on the /dev/hotplug device file. Each event consists of
event type (attach/detach), device class (DV_*) and device name (sd1 e.g.).

We have hotplug pseudo-device on alpha, amd64, i386, macppc and sparc64.
Since it was tested only on i386 other archs has it commented out
in GENERIC until tested.

The idea liked peter@ tedu@ drahn@ millert@ marco@ henning@.
Ok deraadt@.


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.36 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.35 03-May-2003 deraadt

string fixes; tedu ok


# 1.34 19-Apr-2003 krw

Tweak previous sprintf -> snprintf fix to eliminate unnecessary
intermediate variable.

Suggested by deraadt@.

ok henning@ millert@ tdeval@


# 1.33 30-Mar-2003 krw

Use snprintf() to simplify device name construction, removing now
superfluous variables and the function 'number()'.

ok deraadt@ and millert@


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_B
# 1.32 06-Oct-2002 art

Remove some '#if 0' cruft.


Revision tags: OPENBSD_3_2_BASE
# 1.31 24-Apr-2002 espie

Introduce a new file, machine/internal_types.h, to hold that specific arch
type characteristics.

internal_types.h will contain only settings invisible from standard C, e.g.,
in the __* or _[A-Z]* namespace, and be reused by files like limits.h.

This allows us to shorten machine/limits.h greatly, as all the common defines
are now in sys/limits.h, plus a small stub in internal_types.h.

Tested on all arches as far as I know.
Approved after discussion with art, millert, deraadt, and others.


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.29 01-Sep-2001 jason

branches: 1.29.4;
Add __HAVE_DEVICE_REGISTER to hp300/alpha (sparc64 already had it) and
clean up the arch specific #ifdef's in subr_autoconf.c; from NetBSD.
(tested by me on alpha/sparc64 and miod on hp300)


# 1.28 31-Aug-2001 jason

implement autoconf mechanism using device_register(); from NetBSD.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.27 09-Apr-2000 deraadt

range error; < cd_ndevs, not <=


# 1.26 09-Apr-2000 csapuntz

Added config_detach_children, config_activate_children.

Added ref counting to devices: device_ref, device_unref and a new method
for devices : ca_zeroref, called when the ref count hits zero.

Note that ca_zeroref may be called from interrupt context.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.25 08-Aug-1999 niklas

branches: 1.25.4;
From NetBSD; new device detaching infrastructure.


# 1.24 05-Aug-1999 niklas

From NetBSD; config_defer to defer configuration of a device until after all
other siblings.


# 1.23 23-Jul-1999 niklas

Remove obsolete detach logic in preparation of a newer one


Revision tags: OPENBSD_2_5_BASE
# 1.22 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.21 11-May-1998 niklas

Formerly reuse of unit numbers of detached devices was impossible, with
this change starred devices will search from the first allowed unit for
such devices and up for free units when attaching. This means you have
to rerun config(8) before yopu compile current kernels. FYI, this is
a necessity when doing PCMCIA flashcard reading, otherwise you soon run
out of unit numbers.

I have also added a way to detach all children of a certain device, used
in a new PCMCIA framework to come, so you detach all functions on a
single PCMCIA card when pulling it out.

A few bugs wrt starred devices fixed in the autoconfig_verbose code too.
Last and least, fixed some panic messages.


Revision tags: OPENBSD_2_3_BASE
# 1.20 20-Feb-1998 niklas

Please GCC 2.8's harsher view of good style


# 1.19 21-Jan-1998 niklas

Prevent a NULL-deref in the autoconf_verbose case


# 1.18 20-Jan-1998 niklas

typo


# 1.17 20-Jan-1998 niklas

Provide a way to debug probes. set autoconf_verbose via DDB, or
option AUTOCONF_VERBOSE=1
in your kernel config.


# 1.16 23-Nov-1997 mickey

indent


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.15 03-Feb-1997 downsj

hp300 needs device_register(), too.


# 1.14 21-Nov-1996 mickey

export struct cfdata cfdata[];


# 1.13 18-Oct-1996 niklas

As alpha uses device_register, it needs its proto too


Revision tags: OPENBSD_2_0_BASE
# 1.12 24-Sep-1996 deraadt

no mknod in chroot


# 1.11 15-Aug-1996 niklas

Remove unnecessary prototype


# 1.10 02-Jul-1996 deraadt

pretty


# 1.9 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.8 23-Jun-1996 maja

Added support for user modifiable kernel at boot (-c) /maja


# 1.7 18-Jun-1996 deraadt

sick netbsd alpha hack (why not do what other ports do?)


# 1.6 07-May-1996 niklas

Make sure config_init gets called before consinit, as at least one port
actually uses config_* functions for console attachment. Document
config_init should not call malloc as the move was over the mem-init
function calls too.


# 1.5 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.94 30-Dec-2019 jsg

convert infinite msleep(9) to msleep_nsec(9)

ok mpi@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.93 05-Dec-2018 mpi

free(9) sizes for softcs.

ok tedu@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.92 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.91 20-Dec-2015 mpi

Simple free(9) sizes, from Matthieu <naabed AT poolp DOT org>.


# 1.90 11-Dec-2015 mpi

Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).

ok mikeb@, deraadt@


# 1.89 11-Sep-2015 dlg

back out refcnt for dv_ref, there's too many hand crafted devices all
over the tree.

much encouragement from l2k15


# 1.88 11-Sep-2015 dlg

use refcnts for the device reference counts as an example of how
refcnt(9) can be used.


Revision tags: OPENBSD_5_8_BASE
# 1.87 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.86 09-Feb-2015 dlg

you need atomic.h to do atomic things.

pointed out by deraadt@


# 1.85 09-Feb-2015 dlg

use atomic ops to increment and decrement the device ref count in
device_ref and device_unref.

ok guenther@ deraadt@


# 1.84 22-Jan-2015 dlg

bring back r1.80:

pass the size of the softc to free.

this time we only dereference the cfattach structure if we actually
need it once the refcount has dropped to 0.

tested by krw@ who found the original panic r1.80 was backed out for.
putting this in again so i can find out when else will break.


# 1.83 19-Jan-2015 deraadt

back it out properly


# 1.82 19-Jan-2015 deraadt

never tested with a make release


# 1.81 19-Jan-2015 dlg

pass the size of the softc to free.

ok deraadt@


# 1.80 18-Sep-2014 kettenis

Introduce config_suspend_all(9) a function that invokes config_suspend(9)
on all relevant device hierarchies in the appropriate order. For now this
means mpath(4) and mainbus(4), doing mpath(4) before mainbus(4) when
suspending or powering down and doing mpath(4) after mainbus(4) when
resuming such that mpath(4) can realy on the underlying hardware being
in a functional state.

Fixes problems with unflushed disk caches on machines where mpath(4) takes
control of some of your disks.

ok dlg@


# 1.79 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.78 13-Jul-2014 tedu

use mallocarray where arguments are multipled. ok deraadt


# 1.77 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.76 12-Jul-2014 mpi

Change config_deactivate(9) to always unset the DVF_ACTIVE flag so
that drivers can check for this flag to know they have to stop doing
any hardware access and release their reference.

While here makes the ca_activate() function optional and propagates
DVACT_DEACTIVATE to the children of a device that do not implement this
interface like it is done during suspend/resume.

ok uebayasi@, deraadt@


# 1.75 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


# 1.74 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.73 12-Dec-2013 guenther

printf(variable) --> printf("%s", variable)

ok deraadt@


# 1.72 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.71 29-Nov-2013 deraadt

msgs can be const


# 1.70 27-Nov-2013 dlg

get rid of the goop for maintaining multiple cftables since theres
no current code there to add or remove them. such code was put in
17 years ago, disabled 14 years ago, and removed 11 years ago, so
i suspect we dont really need it or the goop to support it.

very ok miod@


# 1.69 26-Nov-2013 dlg

compare pointers to NULL


Revision tags: OPENBSD_5_4_BASE
# 1.68 30-May-2013 deraadt

Enforce ca_activate tree-walks over the entire heirarchy for all events,
cleaning up some shutdown-hook related code on the way.
(A few drivers related to sparc are still skipped at kettenis' request)
ok kettenis mlarkin, tested by many others too


Revision tags: OPENBSD_5_3_BASE
# 1.67 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.66 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.65 20-Jun-2011 deraadt

serialize attach and detach of device sub-trees -- only one device
sub-tree may attach or detach at a time. attach and detach will sleep
against each other.
this is fixing (working around?) some bizzare corner cases that have
been seen (but not fully diagnosed) where the device trees, disk registration
subsystem, and other things could get messed up. one could argue though
that this serialization is a very good thing; it is easier than adding piles
of locks in various other places.
ok matthew jsing


# 1.64 01-Jun-2011 matthew

Add a few KASSERTs to config_attach() for sanity to make sure we don't
try to reuse device unit numbers and to check that the device pointer
array is allocated and large enough.

Also, improve the panic message generated by config_detach() when we
detect that we're detaching a device that still has children.

Discussed with deraadt@ while trying to brainstorm ways that
interleaving config_attach and config_detach could blow up.


Revision tags: OPENBSD_4_9_BASE
# 1.63 08-Sep-2010 deraadt

remove a useless comment


# 1.62 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


Revision tags: OPENBSD_4_8_BASE
# 1.61 30-Jun-2010 deraadt

Silence the activation debug reporting. We are starting to get worried
that there are interactions when we print in the various (saved, post-saved,
pre-restored, and restored) vga states, especially with how intel drm is
getting involved. If your machine has issues, you may want to activate
these messages again to help debug things better.
ok mlarkin


Revision tags: OPENBSD_4_7_BASE
# 1.60 28-Feb-2010 miod

Remove leftover debug printf in config_activate_children(); ok deraadt


# 1.59 23-Nov-2009 deraadt

Make config_activate_children() more useable as a suspend-and-resume
device tree walker, and add config_suspend() as well.
ok mlarkin pirofti, discussion with kettenis


# 1.58 22-Nov-2009 pirofti

Add basic suspend/resume autoconf functionality.

Okay deraadt@, kettenis@, mlarkin@.


# 1.57 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.56 20-Aug-2008 miod

Allow devices attaching at root (such as softraid) to be disabled in UKC.
ok marco@ deraadt@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.55 23-Nov-2007 kettenis

Since the devices that we detach may have children we cannot rely on the
"previous" device still being there, so if we detach a device, we really
have to start from scratch again (like the comment on this code actually
says we should). Simplifies the code as a bonus.

ok dlg@, deraadt@


# 1.54 29-Oct-2007 dlg

get rid of the unused cond_predicate_t typedef.

ok miod@ deraadt@ krw@


# 1.53 07-Sep-2007 art

Use M_ZERO in a few more places to shave bytes from the kernel.

eyeballed and ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.52 30-May-2007 deraadt

the (root) stuff is ugly, so print "at root", so it looks more like
regular things. everyone here buys it, and i'm 90% sure miod will be
ok with it


# 1.51 15-May-2007 deraadt

kill __HAVE_DEVICE_REGISTER by requiring all architectures to have a
device_register() function -- even if it does nothing. reduces the
cpp-based blather different between architectures
idea ok'd by miod; tested on all architectures (except a few miod will
need to cleanup because he has them)


# 1.50 09-May-2007 deraadt

evcnt_attach() is no longer used; ok miod


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.49 28-May-2006 mk

Remove device id from hotplug events.

ok henning


# 1.48 28-May-2006 deraadt

more fallout from the sensors: Every single ramdisk got broken.


# 1.47 28-May-2006 mk

Include device id in hotplug events. This will be used by ntpd to check
sensors on attach/detach. hotplugd changes following in a minute.

ok henning.


# 1.46 17-May-2006 krw

cf_unit should have a value between 0 and cd_ndevs. So set cf_unit to 0 when
cd_ndevs is set to 0.

"No kidding!" deraadt@ "Seems to make sense to me." beck@ "Seems right." miod@


# 1.45 17-May-2006 krw

Detach children devices in reverse order. This gives better display, and
allows cf_unit to be decremented correctly.

'put it in' deraadt@ "i think it's good' tedu@


# 1.44 14-May-2006 krw

When assigning a unit number, treat running off the end of the
cd_devs[] array the same as finding a NULL entry.

Fixes inconsistant assignment of unit numbers to media slots on the
Neodio 8-in-1 USB card reader donated by Manuel Pata. Previously the
unit numbers would vary depending on whether it had attached an even
or odd number of times.

'reads ok' marco@ ok miod@


Revision tags: OPENBSD_3_9_BASE
# 1.43 21-Jan-2006 miod

Remove now unused zeroref member in cfattach structures.


# 1.42 13-Jan-2006 miod

In config_detach_children(), after detaching a device, restart the device
list walk from its parent device, as the device which was following it may
have been one of its children, and thus gone as well. Found the hard way
using the strict queue macros.

Feedback and help toby@, ok deraadt@


# 1.41 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.40 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


# 1.39 23-Nov-2004 miod

Create the init process earlier, before the root filesystem is mounted,
and have it stall on a semaphore. This allows all kthread creations which
could have been requested during autoconf to be processed before root
is mounted as well.

This causes umass devices attached to any usb with flags 1 (such as on macppc)
to configure properly instead of panicing the kernel at mountroot time.

From NetBSD; tested by various.


Revision tags: OPENBSD_3_6_BASE
# 1.38 03-Aug-2004 pefo

Fix a minor bug where indirect config crashes the kernel
when match verbose is turend on.


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.37 30-May-2004 grange

Devices hot plugging support.
The hotplug pseudo-device passes device attachment and detachment events
to userland. When a device attaches or detaches, the corresponding event
is queued. The events can then be obtained from the queue through the
read(2) call on the /dev/hotplug device file. Each event consists of
event type (attach/detach), device class (DV_*) and device name (sd1 e.g.).

We have hotplug pseudo-device on alpha, amd64, i386, macppc and sparc64.
Since it was tested only on i386 other archs has it commented out
in GENERIC until tested.

The idea liked peter@ tedu@ drahn@ millert@ marco@ henning@.
Ok deraadt@.


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.36 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.35 03-May-2003 deraadt

string fixes; tedu ok


# 1.34 19-Apr-2003 krw

Tweak previous sprintf -> snprintf fix to eliminate unnecessary
intermediate variable.

Suggested by deraadt@.

ok henning@ millert@ tdeval@


# 1.33 30-Mar-2003 krw

Use snprintf() to simplify device name construction, removing now
superfluous variables and the function 'number()'.

ok deraadt@ and millert@


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_B
# 1.32 06-Oct-2002 art

Remove some '#if 0' cruft.


Revision tags: OPENBSD_3_2_BASE
# 1.31 24-Apr-2002 espie

Introduce a new file, machine/internal_types.h, to hold that specific arch
type characteristics.

internal_types.h will contain only settings invisible from standard C, e.g.,
in the __* or _[A-Z]* namespace, and be reused by files like limits.h.

This allows us to shorten machine/limits.h greatly, as all the common defines
are now in sys/limits.h, plus a small stub in internal_types.h.

Tested on all arches as far as I know.
Approved after discussion with art, millert, deraadt, and others.


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.29 01-Sep-2001 jason

branches: 1.29.4;
Add __HAVE_DEVICE_REGISTER to hp300/alpha (sparc64 already had it) and
clean up the arch specific #ifdef's in subr_autoconf.c; from NetBSD.
(tested by me on alpha/sparc64 and miod on hp300)


# 1.28 31-Aug-2001 jason

implement autoconf mechanism using device_register(); from NetBSD.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.27 09-Apr-2000 deraadt

range error; < cd_ndevs, not <=


# 1.26 09-Apr-2000 csapuntz

Added config_detach_children, config_activate_children.

Added ref counting to devices: device_ref, device_unref and a new method
for devices : ca_zeroref, called when the ref count hits zero.

Note that ca_zeroref may be called from interrupt context.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.25 08-Aug-1999 niklas

branches: 1.25.4;
From NetBSD; new device detaching infrastructure.


# 1.24 05-Aug-1999 niklas

From NetBSD; config_defer to defer configuration of a device until after all
other siblings.


# 1.23 23-Jul-1999 niklas

Remove obsolete detach logic in preparation of a newer one


Revision tags: OPENBSD_2_5_BASE
# 1.22 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.21 11-May-1998 niklas

Formerly reuse of unit numbers of detached devices was impossible, with
this change starred devices will search from the first allowed unit for
such devices and up for free units when attaching. This means you have
to rerun config(8) before yopu compile current kernels. FYI, this is
a necessity when doing PCMCIA flashcard reading, otherwise you soon run
out of unit numbers.

I have also added a way to detach all children of a certain device, used
in a new PCMCIA framework to come, so you detach all functions on a
single PCMCIA card when pulling it out.

A few bugs wrt starred devices fixed in the autoconfig_verbose code too.
Last and least, fixed some panic messages.


Revision tags: OPENBSD_2_3_BASE
# 1.20 20-Feb-1998 niklas

Please GCC 2.8's harsher view of good style


# 1.19 21-Jan-1998 niklas

Prevent a NULL-deref in the autoconf_verbose case


# 1.18 20-Jan-1998 niklas

typo


# 1.17 20-Jan-1998 niklas

Provide a way to debug probes. set autoconf_verbose via DDB, or
option AUTOCONF_VERBOSE=1
in your kernel config.


# 1.16 23-Nov-1997 mickey

indent


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.15 03-Feb-1997 downsj

hp300 needs device_register(), too.


# 1.14 21-Nov-1996 mickey

export struct cfdata cfdata[];


# 1.13 18-Oct-1996 niklas

As alpha uses device_register, it needs its proto too


Revision tags: OPENBSD_2_0_BASE
# 1.12 24-Sep-1996 deraadt

no mknod in chroot


# 1.11 15-Aug-1996 niklas

Remove unnecessary prototype


# 1.10 02-Jul-1996 deraadt

pretty


# 1.9 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.8 23-Jun-1996 maja

Added support for user modifiable kernel at boot (-c) /maja


# 1.7 18-Jun-1996 deraadt

sick netbsd alpha hack (why not do what other ports do?)


# 1.6 07-May-1996 niklas

Make sure config_init gets called before consinit, as at least one port
actually uses config_* functions for console attachment. Document
config_init should not call malloc as the move was over the mem-init
function calls too.


# 1.5 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.93 05-Dec-2018 mpi

free(9) sizes for softcs.

ok tedu@


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.92 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.91 20-Dec-2015 mpi

Simple free(9) sizes, from Matthieu <naabed AT poolp DOT org>.


# 1.90 11-Dec-2015 mpi

Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).

ok mikeb@, deraadt@


# 1.89 11-Sep-2015 dlg

back out refcnt for dv_ref, there's too many hand crafted devices all
over the tree.

much encouragement from l2k15


# 1.88 11-Sep-2015 dlg

use refcnts for the device reference counts as an example of how
refcnt(9) can be used.


Revision tags: OPENBSD_5_8_BASE
# 1.87 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.86 09-Feb-2015 dlg

you need atomic.h to do atomic things.

pointed out by deraadt@


# 1.85 09-Feb-2015 dlg

use atomic ops to increment and decrement the device ref count in
device_ref and device_unref.

ok guenther@ deraadt@


# 1.84 22-Jan-2015 dlg

bring back r1.80:

pass the size of the softc to free.

this time we only dereference the cfattach structure if we actually
need it once the refcount has dropped to 0.

tested by krw@ who found the original panic r1.80 was backed out for.
putting this in again so i can find out when else will break.


# 1.83 19-Jan-2015 deraadt

back it out properly


# 1.82 19-Jan-2015 deraadt

never tested with a make release


# 1.81 19-Jan-2015 dlg

pass the size of the softc to free.

ok deraadt@


# 1.80 18-Sep-2014 kettenis

Introduce config_suspend_all(9) a function that invokes config_suspend(9)
on all relevant device hierarchies in the appropriate order. For now this
means mpath(4) and mainbus(4), doing mpath(4) before mainbus(4) when
suspending or powering down and doing mpath(4) after mainbus(4) when
resuming such that mpath(4) can realy on the underlying hardware being
in a functional state.

Fixes problems with unflushed disk caches on machines where mpath(4) takes
control of some of your disks.

ok dlg@


# 1.79 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.78 13-Jul-2014 tedu

use mallocarray where arguments are multipled. ok deraadt


# 1.77 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.76 12-Jul-2014 mpi

Change config_deactivate(9) to always unset the DVF_ACTIVE flag so
that drivers can check for this flag to know they have to stop doing
any hardware access and release their reference.

While here makes the ca_activate() function optional and propagates
DVACT_DEACTIVATE to the children of a device that do not implement this
interface like it is done during suspend/resume.

ok uebayasi@, deraadt@


# 1.75 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


# 1.74 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.73 12-Dec-2013 guenther

printf(variable) --> printf("%s", variable)

ok deraadt@


# 1.72 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.71 29-Nov-2013 deraadt

msgs can be const


# 1.70 27-Nov-2013 dlg

get rid of the goop for maintaining multiple cftables since theres
no current code there to add or remove them. such code was put in
17 years ago, disabled 14 years ago, and removed 11 years ago, so
i suspect we dont really need it or the goop to support it.

very ok miod@


# 1.69 26-Nov-2013 dlg

compare pointers to NULL


Revision tags: OPENBSD_5_4_BASE
# 1.68 30-May-2013 deraadt

Enforce ca_activate tree-walks over the entire heirarchy for all events,
cleaning up some shutdown-hook related code on the way.
(A few drivers related to sparc are still skipped at kettenis' request)
ok kettenis mlarkin, tested by many others too


Revision tags: OPENBSD_5_3_BASE
# 1.67 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.66 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.65 20-Jun-2011 deraadt

serialize attach and detach of device sub-trees -- only one device
sub-tree may attach or detach at a time. attach and detach will sleep
against each other.
this is fixing (working around?) some bizzare corner cases that have
been seen (but not fully diagnosed) where the device trees, disk registration
subsystem, and other things could get messed up. one could argue though
that this serialization is a very good thing; it is easier than adding piles
of locks in various other places.
ok matthew jsing


# 1.64 01-Jun-2011 matthew

Add a few KASSERTs to config_attach() for sanity to make sure we don't
try to reuse device unit numbers and to check that the device pointer
array is allocated and large enough.

Also, improve the panic message generated by config_detach() when we
detect that we're detaching a device that still has children.

Discussed with deraadt@ while trying to brainstorm ways that
interleaving config_attach and config_detach could blow up.


Revision tags: OPENBSD_4_9_BASE
# 1.63 08-Sep-2010 deraadt

remove a useless comment


# 1.62 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


Revision tags: OPENBSD_4_8_BASE
# 1.61 30-Jun-2010 deraadt

Silence the activation debug reporting. We are starting to get worried
that there are interactions when we print in the various (saved, post-saved,
pre-restored, and restored) vga states, especially with how intel drm is
getting involved. If your machine has issues, you may want to activate
these messages again to help debug things better.
ok mlarkin


Revision tags: OPENBSD_4_7_BASE
# 1.60 28-Feb-2010 miod

Remove leftover debug printf in config_activate_children(); ok deraadt


# 1.59 23-Nov-2009 deraadt

Make config_activate_children() more useable as a suspend-and-resume
device tree walker, and add config_suspend() as well.
ok mlarkin pirofti, discussion with kettenis


# 1.58 22-Nov-2009 pirofti

Add basic suspend/resume autoconf functionality.

Okay deraadt@, kettenis@, mlarkin@.


# 1.57 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.56 20-Aug-2008 miod

Allow devices attaching at root (such as softraid) to be disabled in UKC.
ok marco@ deraadt@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.55 23-Nov-2007 kettenis

Since the devices that we detach may have children we cannot rely on the
"previous" device still being there, so if we detach a device, we really
have to start from scratch again (like the comment on this code actually
says we should). Simplifies the code as a bonus.

ok dlg@, deraadt@


# 1.54 29-Oct-2007 dlg

get rid of the unused cond_predicate_t typedef.

ok miod@ deraadt@ krw@


# 1.53 07-Sep-2007 art

Use M_ZERO in a few more places to shave bytes from the kernel.

eyeballed and ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.52 30-May-2007 deraadt

the (root) stuff is ugly, so print "at root", so it looks more like
regular things. everyone here buys it, and i'm 90% sure miod will be
ok with it


# 1.51 15-May-2007 deraadt

kill __HAVE_DEVICE_REGISTER by requiring all architectures to have a
device_register() function -- even if it does nothing. reduces the
cpp-based blather different between architectures
idea ok'd by miod; tested on all architectures (except a few miod will
need to cleanup because he has them)


# 1.50 09-May-2007 deraadt

evcnt_attach() is no longer used; ok miod


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.49 28-May-2006 mk

Remove device id from hotplug events.

ok henning


# 1.48 28-May-2006 deraadt

more fallout from the sensors: Every single ramdisk got broken.


# 1.47 28-May-2006 mk

Include device id in hotplug events. This will be used by ntpd to check
sensors on attach/detach. hotplugd changes following in a minute.

ok henning.


# 1.46 17-May-2006 krw

cf_unit should have a value between 0 and cd_ndevs. So set cf_unit to 0 when
cd_ndevs is set to 0.

"No kidding!" deraadt@ "Seems to make sense to me." beck@ "Seems right." miod@


# 1.45 17-May-2006 krw

Detach children devices in reverse order. This gives better display, and
allows cf_unit to be decremented correctly.

'put it in' deraadt@ "i think it's good' tedu@


# 1.44 14-May-2006 krw

When assigning a unit number, treat running off the end of the
cd_devs[] array the same as finding a NULL entry.

Fixes inconsistant assignment of unit numbers to media slots on the
Neodio 8-in-1 USB card reader donated by Manuel Pata. Previously the
unit numbers would vary depending on whether it had attached an even
or odd number of times.

'reads ok' marco@ ok miod@


Revision tags: OPENBSD_3_9_BASE
# 1.43 21-Jan-2006 miod

Remove now unused zeroref member in cfattach structures.


# 1.42 13-Jan-2006 miod

In config_detach_children(), after detaching a device, restart the device
list walk from its parent device, as the device which was following it may
have been one of its children, and thus gone as well. Found the hard way
using the strict queue macros.

Feedback and help toby@, ok deraadt@


# 1.41 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.40 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


# 1.39 23-Nov-2004 miod

Create the init process earlier, before the root filesystem is mounted,
and have it stall on a semaphore. This allows all kthread creations which
could have been requested during autoconf to be processed before root
is mounted as well.

This causes umass devices attached to any usb with flags 1 (such as on macppc)
to configure properly instead of panicing the kernel at mountroot time.

From NetBSD; tested by various.


Revision tags: OPENBSD_3_6_BASE
# 1.38 03-Aug-2004 pefo

Fix a minor bug where indirect config crashes the kernel
when match verbose is turend on.


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.37 30-May-2004 grange

Devices hot plugging support.
The hotplug pseudo-device passes device attachment and detachment events
to userland. When a device attaches or detaches, the corresponding event
is queued. The events can then be obtained from the queue through the
read(2) call on the /dev/hotplug device file. Each event consists of
event type (attach/detach), device class (DV_*) and device name (sd1 e.g.).

We have hotplug pseudo-device on alpha, amd64, i386, macppc and sparc64.
Since it was tested only on i386 other archs has it commented out
in GENERIC until tested.

The idea liked peter@ tedu@ drahn@ millert@ marco@ henning@.
Ok deraadt@.


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.36 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.35 03-May-2003 deraadt

string fixes; tedu ok


# 1.34 19-Apr-2003 krw

Tweak previous sprintf -> snprintf fix to eliminate unnecessary
intermediate variable.

Suggested by deraadt@.

ok henning@ millert@ tdeval@


# 1.33 30-Mar-2003 krw

Use snprintf() to simplify device name construction, removing now
superfluous variables and the function 'number()'.

ok deraadt@ and millert@


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_B
# 1.32 06-Oct-2002 art

Remove some '#if 0' cruft.


Revision tags: OPENBSD_3_2_BASE
# 1.31 24-Apr-2002 espie

Introduce a new file, machine/internal_types.h, to hold that specific arch
type characteristics.

internal_types.h will contain only settings invisible from standard C, e.g.,
in the __* or _[A-Z]* namespace, and be reused by files like limits.h.

This allows us to shorten machine/limits.h greatly, as all the common defines
are now in sys/limits.h, plus a small stub in internal_types.h.

Tested on all arches as far as I know.
Approved after discussion with art, millert, deraadt, and others.


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.29 01-Sep-2001 jason

branches: 1.29.4;
Add __HAVE_DEVICE_REGISTER to hp300/alpha (sparc64 already had it) and
clean up the arch specific #ifdef's in subr_autoconf.c; from NetBSD.
(tested by me on alpha/sparc64 and miod on hp300)


# 1.28 31-Aug-2001 jason

implement autoconf mechanism using device_register(); from NetBSD.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.27 09-Apr-2000 deraadt

range error; < cd_ndevs, not <=


# 1.26 09-Apr-2000 csapuntz

Added config_detach_children, config_activate_children.

Added ref counting to devices: device_ref, device_unref and a new method
for devices : ca_zeroref, called when the ref count hits zero.

Note that ca_zeroref may be called from interrupt context.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.25 08-Aug-1999 niklas

branches: 1.25.4;
From NetBSD; new device detaching infrastructure.


# 1.24 05-Aug-1999 niklas

From NetBSD; config_defer to defer configuration of a device until after all
other siblings.


# 1.23 23-Jul-1999 niklas

Remove obsolete detach logic in preparation of a newer one


Revision tags: OPENBSD_2_5_BASE
# 1.22 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.21 11-May-1998 niklas

Formerly reuse of unit numbers of detached devices was impossible, with
this change starred devices will search from the first allowed unit for
such devices and up for free units when attaching. This means you have
to rerun config(8) before yopu compile current kernels. FYI, this is
a necessity when doing PCMCIA flashcard reading, otherwise you soon run
out of unit numbers.

I have also added a way to detach all children of a certain device, used
in a new PCMCIA framework to come, so you detach all functions on a
single PCMCIA card when pulling it out.

A few bugs wrt starred devices fixed in the autoconfig_verbose code too.
Last and least, fixed some panic messages.


Revision tags: OPENBSD_2_3_BASE
# 1.20 20-Feb-1998 niklas

Please GCC 2.8's harsher view of good style


# 1.19 21-Jan-1998 niklas

Prevent a NULL-deref in the autoconf_verbose case


# 1.18 20-Jan-1998 niklas

typo


# 1.17 20-Jan-1998 niklas

Provide a way to debug probes. set autoconf_verbose via DDB, or
option AUTOCONF_VERBOSE=1
in your kernel config.


# 1.16 23-Nov-1997 mickey

indent


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.15 03-Feb-1997 downsj

hp300 needs device_register(), too.


# 1.14 21-Nov-1996 mickey

export struct cfdata cfdata[];


# 1.13 18-Oct-1996 niklas

As alpha uses device_register, it needs its proto too


Revision tags: OPENBSD_2_0_BASE
# 1.12 24-Sep-1996 deraadt

no mknod in chroot


# 1.11 15-Aug-1996 niklas

Remove unnecessary prototype


# 1.10 02-Jul-1996 deraadt

pretty


# 1.9 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.8 23-Jun-1996 maja

Added support for user modifiable kernel at boot (-c) /maja


# 1.7 18-Jun-1996 deraadt

sick netbsd alpha hack (why not do what other ports do?)


# 1.6 07-May-1996 niklas

Make sure config_init gets called before consinit, as at least one port
actually uses config_* functions for console attachment. Document
config_init should not call malloc as the move was over the mem-init
function calls too.


# 1.5 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.92 14-Mar-2016 krw

Change a bunch of (<blah> *)0 to NULL.

ok beck@ deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.91 20-Dec-2015 mpi

Simple free(9) sizes, from Matthieu <naabed AT poolp DOT org>.


# 1.90 11-Dec-2015 mpi

Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).

ok mikeb@, deraadt@


# 1.89 11-Sep-2015 dlg

back out refcnt for dv_ref, there's too many hand crafted devices all
over the tree.

much encouragement from l2k15


# 1.88 11-Sep-2015 dlg

use refcnts for the device reference counts as an example of how
refcnt(9) can be used.


Revision tags: OPENBSD_5_8_BASE
# 1.87 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.86 09-Feb-2015 dlg

you need atomic.h to do atomic things.

pointed out by deraadt@


# 1.85 09-Feb-2015 dlg

use atomic ops to increment and decrement the device ref count in
device_ref and device_unref.

ok guenther@ deraadt@


# 1.84 22-Jan-2015 dlg

bring back r1.80:

pass the size of the softc to free.

this time we only dereference the cfattach structure if we actually
need it once the refcount has dropped to 0.

tested by krw@ who found the original panic r1.80 was backed out for.
putting this in again so i can find out when else will break.


# 1.83 19-Jan-2015 deraadt

back it out properly


# 1.82 19-Jan-2015 deraadt

never tested with a make release


# 1.81 19-Jan-2015 dlg

pass the size of the softc to free.

ok deraadt@


# 1.80 18-Sep-2014 kettenis

Introduce config_suspend_all(9) a function that invokes config_suspend(9)
on all relevant device hierarchies in the appropriate order. For now this
means mpath(4) and mainbus(4), doing mpath(4) before mainbus(4) when
suspending or powering down and doing mpath(4) after mainbus(4) when
resuming such that mpath(4) can realy on the underlying hardware being
in a functional state.

Fixes problems with unflushed disk caches on machines where mpath(4) takes
control of some of your disks.

ok dlg@


# 1.79 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.78 13-Jul-2014 tedu

use mallocarray where arguments are multipled. ok deraadt


# 1.77 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.76 12-Jul-2014 mpi

Change config_deactivate(9) to always unset the DVF_ACTIVE flag so
that drivers can check for this flag to know they have to stop doing
any hardware access and release their reference.

While here makes the ca_activate() function optional and propagates
DVACT_DEACTIVATE to the children of a device that do not implement this
interface like it is done during suspend/resume.

ok uebayasi@, deraadt@


# 1.75 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


# 1.74 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


Revision tags: OPENBSD_5_5_BASE
# 1.73 12-Dec-2013 guenther

printf(variable) --> printf("%s", variable)

ok deraadt@


# 1.72 06-Dec-2013 deraadt

Add a DVACT_WAKEUP op to the *_activate() API. This is called after the
kernel resumes normal (non-cold, able to run processes, etc) operation.
Previously we were relying on specific DVACT_RESUME op's in drivers
creating callback/threads themselves, but that has become too common,
indicating the need for a built-in mechanism.
ok dlg kettenis, tested by a sufficient amount of people


# 1.71 29-Nov-2013 deraadt

msgs can be const


# 1.70 27-Nov-2013 dlg

get rid of the goop for maintaining multiple cftables since theres
no current code there to add or remove them. such code was put in
17 years ago, disabled 14 years ago, and removed 11 years ago, so
i suspect we dont really need it or the goop to support it.

very ok miod@


# 1.69 26-Nov-2013 dlg

compare pointers to NULL


Revision tags: OPENBSD_5_4_BASE
# 1.68 30-May-2013 deraadt

Enforce ca_activate tree-walks over the entire heirarchy for all events,
cleaning up some shutdown-hook related code on the way.
(A few drivers related to sparc are still skipped at kettenis' request)
ok kettenis mlarkin, tested by many others too


Revision tags: OPENBSD_5_3_BASE
# 1.67 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.66 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.65 20-Jun-2011 deraadt

serialize attach and detach of device sub-trees -- only one device
sub-tree may attach or detach at a time. attach and detach will sleep
against each other.
this is fixing (working around?) some bizzare corner cases that have
been seen (but not fully diagnosed) where the device trees, disk registration
subsystem, and other things could get messed up. one could argue though
that this serialization is a very good thing; it is easier than adding piles
of locks in various other places.
ok matthew jsing


# 1.64 01-Jun-2011 matthew

Add a few KASSERTs to config_attach() for sanity to make sure we don't
try to reuse device unit numbers and to check that the device pointer
array is allocated and large enough.

Also, improve the panic message generated by config_detach() when we
detect that we're detaching a device that still has children.

Discussed with deraadt@ while trying to brainstorm ways that
interleaving config_attach and config_detach could blow up.


Revision tags: OPENBSD_4_9_BASE
# 1.63 08-Sep-2010 deraadt

remove a useless comment


# 1.62 31-Aug-2010 deraadt

Add DVACT_QUIECE support. This is called before splhigh() and before
DVACT_SUSPEND, therefore DVACT_QUIECE can do standard sleeping operations
to get ready.
Discussed quite a while back with kettenis and jakemsr, oga suddenly needed
it as well and wrote half of it, so it was time to finish it.
proofread by miod.


Revision tags: OPENBSD_4_8_BASE
# 1.61 30-Jun-2010 deraadt

Silence the activation debug reporting. We are starting to get worried
that there are interactions when we print in the various (saved, post-saved,
pre-restored, and restored) vga states, especially with how intel drm is
getting involved. If your machine has issues, you may want to activate
these messages again to help debug things better.
ok mlarkin


Revision tags: OPENBSD_4_7_BASE
# 1.60 28-Feb-2010 miod

Remove leftover debug printf in config_activate_children(); ok deraadt


# 1.59 23-Nov-2009 deraadt

Make config_activate_children() more useable as a suspend-and-resume
device tree walker, and add config_suspend() as well.
ok mlarkin pirofti, discussion with kettenis


# 1.58 22-Nov-2009 pirofti

Add basic suspend/resume autoconf functionality.

Okay deraadt@, kettenis@, mlarkin@.


# 1.57 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.56 20-Aug-2008 miod

Allow devices attaching at root (such as softraid) to be disabled in UKC.
ok marco@ deraadt@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.55 23-Nov-2007 kettenis

Since the devices that we detach may have children we cannot rely on the
"previous" device still being there, so if we detach a device, we really
have to start from scratch again (like the comment on this code actually
says we should). Simplifies the code as a bonus.

ok dlg@, deraadt@


# 1.54 29-Oct-2007 dlg

get rid of the unused cond_predicate_t typedef.

ok miod@ deraadt@ krw@


# 1.53 07-Sep-2007 art

Use M_ZERO in a few more places to shave bytes from the kernel.

eyeballed and ok dlg@


Revision tags: OPENBSD_4_2_BASE
# 1.52 30-May-2007 deraadt

the (root) stuff is ugly, so print "at root", so it looks more like
regular things. everyone here buys it, and i'm 90% sure miod will be
ok with it


# 1.51 15-May-2007 deraadt

kill __HAVE_DEVICE_REGISTER by requiring all architectures to have a
device_register() function -- even if it does nothing. reduces the
cpp-based blather different between architectures
idea ok'd by miod; tested on all architectures (except a few miod will
need to cleanup because he has them)


# 1.50 09-May-2007 deraadt

evcnt_attach() is no longer used; ok miod


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.49 28-May-2006 mk

Remove device id from hotplug events.

ok henning


# 1.48 28-May-2006 deraadt

more fallout from the sensors: Every single ramdisk got broken.


# 1.47 28-May-2006 mk

Include device id in hotplug events. This will be used by ntpd to check
sensors on attach/detach. hotplugd changes following in a minute.

ok henning.


# 1.46 17-May-2006 krw

cf_unit should have a value between 0 and cd_ndevs. So set cf_unit to 0 when
cd_ndevs is set to 0.

"No kidding!" deraadt@ "Seems to make sense to me." beck@ "Seems right." miod@


# 1.45 17-May-2006 krw

Detach children devices in reverse order. This gives better display, and
allows cf_unit to be decremented correctly.

'put it in' deraadt@ "i think it's good' tedu@


# 1.44 14-May-2006 krw

When assigning a unit number, treat running off the end of the
cd_devs[] array the same as finding a NULL entry.

Fixes inconsistant assignment of unit numbers to media slots on the
Neodio 8-in-1 USB card reader donated by Manuel Pata. Previously the
unit numbers would vary depending on whether it had attached an even
or odd number of times.

'reads ok' marco@ ok miod@


Revision tags: OPENBSD_3_9_BASE
# 1.43 21-Jan-2006 miod

Remove now unused zeroref member in cfattach structures.


# 1.42 13-Jan-2006 miod

In config_detach_children(), after detaching a device, restart the device
list walk from its parent device, as the device which was following it may
have been one of its children, and thus gone as well. Found the hard way
using the strict queue macros.

Feedback and help toby@, ok deraadt@


# 1.41 09-Dec-2005 jsg

ansi and deregister. No binary change.


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.40 26-Dec-2004 miod

Use list and queue macros where applicable to make the code easier to read;
no change in compiler assembly output.


# 1.39 23-Nov-2004 miod

Create the init process earlier, before the root filesystem is mounted,
and have it stall on a semaphore. This allows all kthread creations which
could have been requested during autoconf to be processed before root
is mounted as well.

This causes umass devices attached to any usb with flags 1 (such as on macppc)
to configure properly instead of panicing the kernel at mountroot time.

From NetBSD; tested by various.


Revision tags: OPENBSD_3_6_BASE
# 1.38 03-Aug-2004 pefo

Fix a minor bug where indirect config crashes the kernel
when match verbose is turend on.


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.37 30-May-2004 grange

Devices hot plugging support.
The hotplug pseudo-device passes device attachment and detachment events
to userland. When a device attaches or detaches, the corresponding event
is queued. The events can then be obtained from the queue through the
read(2) call on the /dev/hotplug device file. Each event consists of
event type (attach/detach), device class (DV_*) and device name (sd1 e.g.).

We have hotplug pseudo-device on alpha, amd64, i386, macppc and sparc64.
Since it was tested only on i386 other archs has it commented out
in GENERIC until tested.

The idea liked peter@ tedu@ drahn@ millert@ marco@ henning@.
Ok deraadt@.


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE
# 1.36 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: UBC_SYNC_A
# 1.35 03-May-2003 deraadt

string fixes; tedu ok


# 1.34 19-Apr-2003 krw

Tweak previous sprintf -> snprintf fix to eliminate unnecessary
intermediate variable.

Suggested by deraadt@.

ok henning@ millert@ tdeval@


# 1.33 30-Mar-2003 krw

Use snprintf() to simplify device name construction, removing now
superfluous variables and the function 'number()'.

ok deraadt@ and millert@


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_B
# 1.32 06-Oct-2002 art

Remove some '#if 0' cruft.


Revision tags: OPENBSD_3_2_BASE
# 1.31 24-Apr-2002 espie

Introduce a new file, machine/internal_types.h, to hold that specific arch
type characteristics.

internal_types.h will contain only settings invisible from standard C, e.g.,
in the __* or _[A-Z]* namespace, and be reused by files like limits.h.

This allows us to shorten machine/limits.h greatly, as all the common defines
are now in sys/limits.h, plus a small stub in internal_types.h.

Tested on all arches as far as I know.
Approved after discussion with art, millert, deraadt, and others.


Revision tags: OPENBSD_3_1_BASE
# 1.30 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.29 01-Sep-2001 jason

branches: 1.29.4;
Add __HAVE_DEVICE_REGISTER to hp300/alpha (sparc64 already had it) and
clean up the arch specific #ifdef's in subr_autoconf.c; from NetBSD.
(tested by me on alpha/sparc64 and miod on hp300)


# 1.28 31-Aug-2001 jason

implement autoconf mechanism using device_register(); from NetBSD.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.27 09-Apr-2000 deraadt

range error; < cd_ndevs, not <=


# 1.26 09-Apr-2000 csapuntz

Added config_detach_children, config_activate_children.

Added ref counting to devices: device_ref, device_unref and a new method
for devices : ca_zeroref, called when the ref count hits zero.

Note that ca_zeroref may be called from interrupt context.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.25 08-Aug-1999 niklas

branches: 1.25.4;
From NetBSD; new device detaching infrastructure.


# 1.24 05-Aug-1999 niklas

From NetBSD; config_defer to defer configuration of a device until after all
other siblings.


# 1.23 23-Jul-1999 niklas

Remove obsolete detach logic in preparation of a newer one


Revision tags: OPENBSD_2_5_BASE
# 1.22 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.21 11-May-1998 niklas

Formerly reuse of unit numbers of detached devices was impossible, with
this change starred devices will search from the first allowed unit for
such devices and up for free units when attaching. This means you have
to rerun config(8) before yopu compile current kernels. FYI, this is
a necessity when doing PCMCIA flashcard reading, otherwise you soon run
out of unit numbers.

I have also added a way to detach all children of a certain device, used
in a new PCMCIA framework to come, so you detach all functions on a
single PCMCIA card when pulling it out.

A few bugs wrt starred devices fixed in the autoconfig_verbose code too.
Last and least, fixed some panic messages.


Revision tags: OPENBSD_2_3_BASE
# 1.20 20-Feb-1998 niklas

Please GCC 2.8's harsher view of good style


# 1.19 21-Jan-1998 niklas

Prevent a NULL-deref in the autoconf_verbose case


# 1.18 20-Jan-1998 niklas

typo


# 1.17 20-Jan-1998 niklas

Provide a way to debug probes. set autoconf_verbose via DDB, or
option AUTOCONF_VERBOSE=1
in your kernel config.


# 1.16 23-Nov-1997 mickey

indent


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE
# 1.15 03-Feb-1997 downsj

hp300 needs device_register(), too.


# 1.14 21-Nov-1996 mickey

export struct cfdata cfdata[];


# 1.13 18-Oct-1996 niklas

As alpha uses device_register, it needs its proto too


Revision tags: OPENBSD_2_0_BASE
# 1.12 24-Sep-1996 deraadt

no mknod in chroot


# 1.11 15-Aug-1996 niklas

Remove unnecessary prototype


# 1.10 02-Jul-1996 deraadt

pretty


# 1.9 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.8 23-Jun-1996 maja

Added support for user modifiable kernel at boot (-c) /maja


# 1.7 18-Jun-1996 deraadt

sick netbsd alpha hack (why not do what other ports do?)


# 1.6 07-May-1996 niklas

Make sure config_init gets called before consinit, as at least one port
actually uses config_* functions for console attachment. Document
config_init should not call malloc as the move was over the mem-init
function calls too.


# 1.5 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 03-Mar-1996 niklas

From NetBSD: 960217 merge


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision