Commit Graph

122 Commits

Author SHA1 Message Date
dyoung 0d1ba3e899 During shutdown, detach devices in an orderly fashion.
Call the detach routine for every device in the device tree, starting
with the leaves and moving toward the root, expecting that each
(pseudo-)device driver will use the opportunity to gracefully commit
outstandings transactions to the underlying (pseudo-)device and to
relinquish control of the hardware to the system BIOS.

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

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

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

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

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

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

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

(2) #include <sys/device.h> in sys/pmf.h in order to get some
definitions that it needs.  Stop unnecessarily #including <sys/device.h>
in sys/arch/x86/include/pic.h to keep the amd64, xen, and i386 releases
building.
2009-04-02 00:09:32 +00:00
christos 9a5d3f2817 replace bitmask_snprintf(9) with snprintb(3) 2008-12-16 22:35:21 +00:00
bouyer 5c26c1f703 Do not depend on physmem for pci_dma64_available(). On some systems (e.g. Xen,
or any system with non-contigous physical memory), physmem may not represent
the hightest physical address available.
Discussed on tech-kern@ some weeks ago.
2008-11-16 17:31:03 +00:00
joerg b8df2b2d5f Complain about devices with misaligned PCI capability pointers instead
of panicing. Christoph Schug reported that such a device is made by
Nvidia.
2008-09-19 14:37:13 +00:00
cegger 3bde75a1bc use device_lookup_private to get softc 2008-06-12 22:44:47 +00:00
dyoung f05735da97 Restore PCI devices to a state that is closer to the state that
NetBSD finds them in: save and restore power management state
(D0..D3) and PCI Configuration Registers 0x0 through 0x40 during
device attachment and detachment, respectively.  Among other things,
this will fix sip(4) detachment and re-attachment.
2008-05-05 20:14:30 +00:00
dyoung 82efc281ac Export some PCI autoconf routines for use by elansc(4), for example. 2008-04-09 17:01:53 +00:00
cube 55ee8b25d0 Split device_t and softc for pci(4). 2008-03-23 16:40:12 +00:00
dyoung 8ce2158b0c pci_activate() expects for its void * argument to be a device_t,
so change the type of the argument to device_t.  Update each use
of pci_activate().

Use device_t and accessors.  Use aprint_*_dev().
2008-03-21 07:47:43 +00:00
drochner 0e748e633e Extend the pmf suspend/resume hooks by a shutdown method, so drivers
can register a shutdown handler explicitely.
Install a pci bus shutdown handler which disables bus master accesses
for all childs, so the drivers don't need to care.
This will hopefully be sufficient to replace the shutdownhooks
(together with the powerhooks). (It has been suggested to use some
general event notification framework for shutdown handlers, but there
might be cases where shutdown handlers must be run in an order following
the device hierarchy, which wouldn't be easy with event handlers
not tied to drivers.)
approved by David Young
2008-02-28 14:25:12 +00:00
dyoung 86fcf72f67 Simplify the switch-statement in pci_set_powerstate_int(), and fix
a couple of typos so that it will work as I think that it was
intended to: delay for 10000us or 200us on transitions to/from D3
or D2 state, respectively.  Discussed this with jmcneill@.
2008-02-23 00:27:53 +00:00
drochner efa71badb8 -fix the delay logics in "set powerstate" for the cases that D2 or D3
are switched to (was harmless because we don't do D2 yet and also
 don't (hmm - shouldn't) access devices in D3 (which would only make
 sense if we'd support D3hot)
-zero the io/mem/master enable bits before entering D3
 (The special handling of PCI_CLASS_DISPLAY devices is questionable
  here -- we can't care about the console if we are seriously follow
  the spec, and upstream bridges aren't considered anyway.)
-add exact references to the PCI PM spec
2008-02-21 22:02:22 +00:00
jmcneill ab245e294e PCI Power Management 1.2 says that system software should wait 10ms after
transitioning a device to or from D3hot, 200us to or from D2, and no wait
for D1 transitions. Update pci_set_powerstate_int to match the spec,
rather than naively waiting 1ms after every state transition.
2008-01-28 22:48:43 +00:00
dyoung 17b65ff15d Disable pci_disable_retry() and cardbus_disable_retry(), with a
long comment on pci_disable_retry() (cross-referenced at
cardbus_disable_retry()) that explains why.
2008-01-03 23:15:43 +00:00
dyoung cf784f4497 Improve pci, cbb, cardslot, cardbus, and pcmcia to support detachment
of this entire device tree:

pci0 at mainbus0
        elansc0 at pci0
                gpio0 at elansc0
        cbb0 at pci0
                cardslot0 at cbb0
                        cardbus0 at cardslot0
                        pcmcia0 at cardslot0
        cbb1 at pci0
                cardslot1 at cbb1
                        cardbus1 at cardslot1
                                rtw0 at cardbus1
                        pcmcia1 at cardslot1
        sip0 at pci0
                nsphyter0 at sip0
        sip1 at pci0
                nsphyter1 at sip1

Whew!
2007-12-16 21:28:30 +00:00
jmcneill 4c1d81b2b5 Merge jmcneill-pm branch. 2007-12-09 20:27:42 +00:00
ad b4214e6788 Empty vessels make the most noise 2007-12-01 16:46:18 +00:00
joerg 4f26bc754d Merge pci_disable_retry function from jmcneill-pm as it is found in
various drivers.
2007-11-12 19:54:36 +00:00
joerg 7f01b64cf1 Merge 1.103.22.4 from jmcneill-pm:
Decode capabilities for PCI-PCI bridges as well.
2007-10-16 18:25:53 +00:00
christos 168cd830d2 __unused removal on arguments; approved by core. 2006-11-16 01:32:37 +00:00
christos 4d595fd7b1 - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
2006-10-12 01:30:41 +00:00
jmcneill f40fbf1bb9 Print error on powerhook_establish failure, not success. PR# 34698. 2006-10-02 21:23:44 +00:00
jmcneill 8e37d48dc1 Create a PCI bus powerhook to handle setting PCI D# power state transitions
on suspend/standby/resume.
2006-09-25 23:09:42 +00:00
christos 63bbcb495a re-factor the pci powestate api. reviewed by gimpy 2006-06-17 23:34:26 +00:00
thorpej 78ffd948be Replace device_locators() with device_locator(), and use it. 2006-03-29 06:00:46 +00:00
christos 95e1ffb156 merge ktrace-lwp. 2005-12-11 12:16:03 +00:00
drochner 49126e9efe use XXXCF_NLOCS constants instead of magic numbers 2005-08-26 11:01:42 +00:00
drochner e6a178f21f kill a number of autoconf submatch functions which follow the
standard scheme:
if (<configured> != <wildcard> && <configured> != <real>)
	then fail
else
	ask device match function

This is handled by config_stdsubmatch() now.
2005-08-25 22:33:18 +00:00
drochner fa3cb84d62 replace the "locdesc_t" structure carrying the number of locators
explicitely by a plain integer array
the length in now known to all relevant parties, so this avoids
duplication of information, and we can allocate that thing in
drivers without hacks
2005-08-25 18:35:38 +00:00
thorpej d36c43c511 Use ANSI function decls and static. 2005-06-28 00:28:41 +00:00
perry f31bd063e9 nuke trailing whitespace 2005-02-27 00:26:58 +00:00
perry 18db93c7f6 de-__P 2005-02-04 02:10:35 +00:00
jmcneill 9c40186bce Add support functions for capturing and restoring PCI configuration
registers for power management code.
2005-01-26 21:49:00 +00:00
drochner a987cab220 remove macros which just hide cfdata internals
(and are used at one place only)
2004-09-13 12:22:52 +00:00
drochner 46289e1fef Phase out the use of a string as first "attach args" member to control
which bustype should be attached with a specific call to config_found()
(from a "mainbus" or a bus bridge).
Do it for isa/eisa/mca and pci/agp for now. These buses all attach to
an mi interface attribute "isabus", "eisabus" etc., and the autoconf
framework now allows to specify an interface attribute on config_found()
and config_search(), which limits the search of matching config data
to these which attach to that specific attribute.
So we basically have to call config_found_ia(..., "foobus", ...) where
such a bus is attached.
As a consequence, where a "mainbus" or alike also attaches other
devices (eg CPUs) which do not attach to a specific attribute yet,
we need at least pass an attribute name (different from "foobus") so
that the foo bus is not found at these places. This made some minor
changes necessary which are not obviously related to the mentioned buses.
2004-08-30 15:05:15 +00:00
drochner c67a72f6ff make PCI devices attachable/detachable (as far as the particular drivers
allow), and allow to rescan a bus selectively (ie only the device/
function I'm looking at)
2004-08-17 23:20:10 +00:00
drochner 04a2fc0f5a make the "generic" PCI bus enumeration code the standard case which
gets used if nothing else is defined in MD headers,
introduce a "PCI_MACHDEP_ENUMERATE_BUS" CPP definition which can
be used by MD headers (just 1 port atm) to plug in special code
2004-07-29 16:51:01 +00:00
kochi d8c488d1ef Fix typo (func8 -> func7) 2004-05-17 16:57:49 +00:00
christos 956dab9c37 GC pci_{g,s}et_powerstate into pci_powerstate(). Idea from mycroft and gimpy.
Nothing uses them yet.
2004-05-08 23:41:40 +00:00
itojun 6123043789 pass string length (= boundary info) to pci_devinfo so that we do not run over
the end of memory region
2004-04-23 21:13:05 +00:00
itojun dc4bf37abf support new quirk bits on debug output 2003-08-18 05:39:07 +00:00
itojun c2ab035d77 - check HDRTYPE early, and ignore if it is not supported (n > 2).
- defer access to interrupt configuration register, as its existence depends on
  HDRTYPE.
- add "skip particular funtion in multifunction device" functionality
  to quirk table.
- add GEODE/NS SC1100 quirk (now boots on soekris Net4801).
2003-08-15 07:17:21 +00:00
fvdl 7dd7f8baa2 Handle 64bit DMA addresses on PCI for platforms that can (currently only
enabled on amd64). Add a dmat64 field to various PCI attach structures,
and pass it down where needed. Implement a simple new function called
pci_dma64_available(pa) to test if 64bit DMA addresses may be used.
This returns 1 iff _PCI_HAVE_DMA64 is defined in <machine/pci_machdep.h>,
and there is more than 4G of memory.
2003-06-15 23:08:53 +00:00
thorpej 9039a9311b Fix inverted logic in pci_vpd_write(). From Jachym Holecek, PR kern/21440. 2003-05-03 18:02:37 +00:00
thorpej b43b1645a2 Use aprint*(). 2003-04-29 01:07:30 +00:00
thorpej ecb44c329e Add PCI VPD access routines. From psi.cz!freza, PR kern/20889. 2003-03-25 21:56:20 +00:00
christos fb66693ce7 It is not appropriate for pcivar.h to include "locators.h"
The two files that need it, should include it themselves.
2003-03-19 17:56:58 +00:00
thorpej 72a7af27b0 Use aprint_normal() in cfprint routines. 2003-01-01 00:10:15 +00:00
perry 43ed640ca5 fix lint warnings about things being stringified under cpp -traditional 2002-10-23 01:50:11 +00:00
thorpej b75a007d9f Add trailing ; to CFATTACH_DECL. 2002-10-02 16:51:16 +00:00