History log of /freebsd-10.3-release/sys/dev/acpica/acpi.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 296373 04-Mar-2016 marius

- Copy stable/10@296371 to releng/10.3 in preparation for 10.3-RC1
builds.
- Update newvers.sh to reflect RC1.
- Update __FreeBSD_version to reflect 10.3.
- Update default pkg(8) configuration to use the quarterly branch.

Approved by: re (implicit)

# 295131 01-Feb-2016 jhb

MFC 278320,278336,278830,285621:
Add devctl(8): a utility for manipulating new-bus devices. Note that
this version does not include the 'suspend' and 'resume' commands
present in HEAD as those depend on larger changes to the suspend and
resume code in the kernel.

278320:
Add a new device control utility for new-bus devices called devctl. This
allows the user to request administrative changes to individual devices
such as attach or detaching drivers or disabling and re-enabling devices.
- Add a new /dev/devctl2 character device which uses ioctls for device
requests. The ioctls use a common 'struct devreq' which is somewhat
similar to 'struct ifreq'.
- The ioctls identify the device to operate on via a string. This
string can either by the device's name, or it can be a bus-specific
address. (For unattached devices, a bus address is the only way to
locate a device.) Bus drivers register an eventhandler to claim
unrecognized device names that the driver recognizes as a valid address.
Two buses currently support addresses: ACPI recognizes any device
in the ACPI namespace via its full path starting with "\" and
the PCI bus driver recognizes an address specification of
'pci[<domain>:]<bus>:<slot>:<func>' (identical to the PCI selector
strings supported by pciconf).
- To make it easier to cut and paste, change the PnP location string
in the PCI bus driver to output a full PCI selector string rather
than 'slot=<slot> function=<func>'.
- Add a devctl(3) interface in libdevctl which provides a wrapper around
the ioctls and is the preferred interface for other userland code.
- Add a devctl(8) program which is a simple wrapper around the requests
supported by devctl(3).
- Add a resource_unset_value() function that can be used to remove a
hint from the kernel environment. This is used to clear a
hint.<driver>.<unit>.disabled hint when re-enabling a boot-time
disabled device.

278336:
Unbreak the build (memchr is explicitly required by devctl(9) after r278320)

278830:
install the man page...

285621:
Fix formatting.

Approved by: re (marius)


# 289032 08-Oct-2015 cperciva

MFC r288446: Disable suspend during shutdown.


# 282750 11-May-2015 avg

MFC r277796: hook userland threads suspend + resume into acpi suspend code


# 281910 23-Apr-2015 jhb

MFC 281159:
Move the message complaining about failed system resource allocations
under bootverbose. Every example I've seen to date has been due to
an ACPI system resource device reserving a range that overlaps with
system memory (which ram0 attempts to reserve) or a local or I/O APIC
(which apic0 attempts to reserve). These are always harmless but look
scary to users.


# 281075 04-Apr-2015 dim

MFC r272444 (by jkim):

Merge ACPICA 20140926.

MFC r278970 (by jkim):

Merge ACPICA 20141107 and 20150204.

Approved by: jkim
Relnotes: yes


# 279904 12-Mar-2015 scottl

MFC r271889, 272799, 272800, 274976
This brings in bus_get_domain() and the related reporting via devinfo,
dmesg, and sysctl.

Obtained from: adrian, jhb
Sponsored by: Netflix, Inc.


# 273847 30-Oct-2014 hselasky

MFC r273733, r273740 and r273773:

The SYSCTL data pointers can come from userspace and must not be
directly accessed. Although this will work on some platforms, it can
throw an exception if the pointer is invalid and then panic the kernel.

Add a missing SYSCTL_IN() of "SCTP_BASE_STATS" structure.

Sponsored by: Mellanox Technologies


# 269038 24-Jul-2014 jhb

MFC 267883:
Expand r261243 even further and ignore any I/O port resources assigned to
PCI root bridges except for the one known-valid case on x86 where bridges
claim the I/O port registers used for PCI config space access.


# 265999 14-May-2014 ian

MFC r257334, r257336, r257337, r257338, r257341, r257342, r257343, r257370,
r257368, r257416

Hints-only devices should return BUS_PROBE_NOWILDCARD from their probe
methods.


# 263022 11-Mar-2014 jhb

MFC 261243:
Some BIOSes incorrectly use standard memory resource ranges to list
the memory ranges that they decode for downstream devices rather than
creating ResourceProducer range resource entries. The result is that
we allocate the full range to the PCI root bridge device causing
allocations in child devices to all fail.

As a workaround, ignore any standard memory resources on a PCI root
bridge device. It is normal for a PCI root bridge to allocate an I/O
resource for the I/O ports used for PCI config access, but I have not
seen any PCI root bridges that legitimately allocate a memory resource.


# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 249767 22-Apr-2013 jhb

- Some BIOSes use an Extended IRQ resource descriptor in _PRS for a link
that uses non-ISA IRQs but use a plain IRQ resource in _CRS. However,
a non-ISA IRQ can't fit into a plain IRQ resource. If we encounter a
link like this, build the resource buffer from _PRS instead of _CRS.
- Set the correct size of the end tag in a resource buffer.

Tested by: Benjamin Lee <ben@b1c1l1.com>
MFC after: 2 weeks


# 246252 02-Feb-2013 avg

revert accidentally committed unneeded changes from r246250

MFC after: 7 days
X-MFC with: r246250


# 246251 02-Feb-2013 avg

acpi: clear power button status bit after waking up...

so that it is not confused for a new power off request.

Learned from: Linux and ACPI specification
Tested by: gjb
MFC after: 12 days


# 246250 02-Feb-2013 avg

acpi: after wakeup from a state > S1 re-enable SCI_EN with a direct write

This hack is picked up from Linux, which claims that it follows
Windows behavior.

PR: amd64/174409
Tested by: Sergey V. Dyatko <sergey.dyatko@gmail.com>,
KAHO Toshikazu <kaho@elam.kais.kyoto-u.ac.jp>,
Slawa Olhovchenkov <slw@zxy.spb.ru>
MFC after: 13 days


# 246128 30-Jan-2013 sbz

Use DEVMETHOD_END macro defined in sys/bus.h instead of {0, 0} sentinel on device_method_t arrays

Reviewed by: cognet
Approved by: cognet


# 245582 18-Jan-2013 jkim

Merge ACPICA 20130117.


# 241973 23-Oct-2012 jkim

Merge ACPICA 20121018.


# 241885 22-Oct-2012 eadler

This isn't functionally identical. In some cases a hint to disable
unit 0 would in fact disable all units.

This reverts r241856

Approved by: cperciva (implicit)


# 241856 22-Oct-2012 eadler

Now that device disabling is generic, remove extraneous code from the
device drivers that used to provide this feature.

Reviewed by: des
Approved by: cperciva
MFC after: 1 week


# 239340 16-Aug-2012 jkim

Merge ACPICA 20120816.


# 236408 01-Jun-2012 jkim

Execute AcpiLeaveSleepStatePrep() for S1 and reduce code duplication.

MFC after: 3 days


# 236403 01-Jun-2012 iwasaki

Call AcpiLeaveSleepStatePrep() in interrupt disabled context
(described in ACPICA source code).

- Move intr_disable() and intr_restore() from acpi_wakeup.c to acpi.c
and call AcpiLeaveSleepStatePrep() in interrupt disabled context.
- Add acpi_wakeup_machdep() to execute wakeup MD procedures and call
it twice in interrupt disabled/enabled context (ia64 version is
just dummy).
- Rename wakeup_cpus variable in acpi_sleep_machdep() to suspcpus in
order to be shared by acpi_sleep_machdep() and acpi_wakeup_machdep().
- Move identity mapping related code to acpi_install_wakeup_handler()
(i386 version) for preparation of x86/acpica/acpi_wakeup.c
(MFC candidate).

Reviewed by: jkim@
MFC after: 2 days


# 236221 29-May-2012 iwasaki

Reorder resume procedures.

DEVICE_RESUME() should be done before AcpiLeaveSleepState() because
PCI config space evaluation can be occurred during control method
executions.

This should fix one of the hang up problems on resuming.

MFC after: 3 days


# 236220 29-May-2012 iwasaki

Fix the problem acpi_sleep_force() hang.

Suspending from callout cause the freeze in DEVICE_SUSPEND().
Suspend from acpi_task thread in stead.

MFC after: 3 days


# 235834 23-May-2012 jhb

Rework the previous change to honor MADT processor IDs when probing
processor objects. Instead of forcing the new-bus CPU objects to use
a unit number equal to pc_cpuid, adjust acpi_pcpu_get_id() to honor the
MADT IDs by default. As with the previous change, setting
debug.acpi.cpu_unordered to 1 in the loader will revert to the old
behavior.

Tested by: jimharris
MFC after: 1 month


# 235772 22-May-2012 iwasaki

Ignore the power button press event for resuming rather than starting
shutdown.

MFC after: 2 days


# 235692 20-May-2012 iwasaki

Don't start the sleep state transition procedure while sleep is
disabled or the system is in shutdown procedure.

This should fix the problem which kernel never response to the sleep
button press events after the message `suspend request ignored (not
ready yet)'.

MFC after: 3 days


# 235029 04-May-2012 jkim

Complete commit message for r235024:

Use MADT to match ACPI Processor objects to CPUs. MADT and DSDT/SSDTs may
list CPUs in different orders, especially for disabled logical cores. Now
we match ACPI IDs from the MADT with Processor objects, strictly order CPUs
accordingly, and ignore disabled cores. This prevents us from executing
methods for other CPUs, e. g., _PSS for disabled logical core, which may not
exist. Unfortunately, it is known that there are a few systems with buggy
BIOSes that do not have unique ACPI IDs for MADT and Processor objects. To
work around these problems, 'debug.acpi.cpu_unordered' tunable is added.
Set this to a non-zero value to restore the old behavior.
Many thanks to jhb for pointing me to the right direction and the manual
page change.

Reported by: Harris, James R (james dot r dot harris at intel dot com)
Tested by: Harris, James R (james dot r dot harris at intel dot com)
Reviewed by: jhb
MFC after: 1 month


# 235024 04-May-2012 jkim

Use MADT to match ACPI Processor objects to CPUs. MADT and DSDT/SSDTs may
list CPUs in different orders, especially for disabled logical cores. Now
we match ACPI IDs from the MADT with Processor objects, strictly order CPUs
accordingly, and ignore disabled cores. This prevents us from executing
methods for other CPUs, e. g., _PSS for disabled logical core, which may not
exist. Unfortunately, it is known that there are a few systems with buggy
BIOSes that do not have unique ACPI IDs for MADT and Processor objects. To
work around these problems


# 233579 27-Mar-2012 jkim

Restore interrupt state after executing AcpiEnterSleepState().


# 233313 22-Mar-2012 jkim

Add ACPI_LV_REPAIR debug level, available since ACPICA 20091214 (r200553).

MFC after: 3 days


# 233250 20-Mar-2012 jkim

Merge ACPICA 20120320.


# 231844 16-Feb-2012 jkim

Merge ACPICA 20120215.


# 231227 08-Feb-2012 jkim

Reset clock after atrtc(4) is properly resumed.


# 231161 07-Feb-2012 jkim

- Give all clocks and timers on acpi0 the equal probing order.
- Increase probing order for ECDT table to match HID-based probing.
- Decrease probing order for HPET table to match HID-based probing.
- Decrease probing order for CPUs and system resources.
- Fix ACPI_DEV_BASE_ORDER to reflect the reality.


# 227293 07-Nov-2011 ed

Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs.

This means that their use is restricted to a single C file.


# 226302 12-Oct-2011 jhb

If an allocation for a specific resource range fails because it is not in
a decoded range for an ACPI Host-PCI bridge, try to allocate it from the
ACPI system resource range. If that works, permit the resource allocation
regardless.

MFC after: 1 week


# 225533 13-Sep-2011 brueffer

Improve the sleep_delay sysctl description by specifying which unit
the number is in.

PR: 159975
Submitted by: gcooper
Approved by: re (kib)
MFC after: 1 week


# 223502 24-Jun-2011 jhb

Typo.


# 223207 17-Jun-2011 jhb

Don't create a device_t object or parse current resources (via _CRS) for
ACPI Device() objects that do not have any device IDs available via the
_HID or _CID methods. Without a device ID a device driver cannot attach
to the device anyway. Namespace objects that are devices but not of
type ACPI_TYPE_DEVICE are not affected.

A few BIOSes have also attached a _CRS method to a PCI device to
allocate resources that are not managed via a BAR. With the previous
code those resources are allocated from acpi0 directly which can interfere
with the new PCI-PCI bridge driver (since the PCI device in question may
be behind a bridge and its resources should be allocated from that
bridge's windows instead). The resources were also orphaned and
and would end up associated with some other random device whose device_t
reused the pointer of the original ACPI-enumerated device (after it was
free'd by the ACPI PCI bus driver) in devinfo output which was confusing.
If we want to handle _CRS on PCI devices we can adjust the ACPI PCI bus
driver to do that in the future and associate the resources with the
proper device object respecting PCI-PCI bridges, etc.

Note that with this change the ACPI PCI bus driver no longer has to
delete ACPI-enumerated device_t devices that mirror PCI devices since
they should in general not exist. There are rare cases when a BIOS
will give a PCI device a _HID (e.g. I've seen a PCI-ISA bridge given
a _HID for a system resource device). In that case we leave both the
ACPI and PCI-enumerated device_t objects around just as in the previous
code.


# 222929 10-Jun-2011 jhb

Implement BUS_ADJUST_RESOURCE() for the x86 drivers that sit between the
Host-PCI bridge drivers and nexus.


# 220647 14-Apr-2011 jkim

Add event handlers for (ACPI) suspend/resume events. Suspend event handlers
are invoked right before device drivers go into sleep state and resume event
handlers are invoked right after all device drivers are waken up.


# 220338 04-Apr-2011 jkim

Move a trivial acpi_TimerDelta() to acpivar.h to make it inlineable.


# 220334 04-Apr-2011 jkim

Fix bogus logic to calculate delta between two values from ACPI timers.


# 217279 11-Jan-2011 jkim

Work around a witness(4) panic introduced in r217238.

Reported by: jh


# 216680 23-Dec-2010 jhb

Don't try to reserve a resource that is already allocated. If the ECDT
table is present, then the acpi_ec(4) driver will allocate its resources
from nexus0 before the acpi0 device reserves resources for child devices.

Reviewed by: jkim


# 216674 22-Dec-2010 jhb

Use resource_list_reserve() to reserve I/O port and memory resources for
ACPI devices even if they are not allocated by a device driver since the
resources are in use and should not be allocated to another device.


# 216488 16-Dec-2010 jhb

Spelling fix.


# 216471 15-Dec-2010 jkim

Merge ACPICA 20101209.


# 214998 08-Nov-2010 jkim

Consistently use padding `_' in the comment.


# 214765 03-Nov-2010 jkim

Adjust a comment to clarify why \_SB_ and \_TZ_ are defined as device type
in ACPICA. Reshuffle the code a bit to make sure this kludge only applies
to these two specical cases and to make it cleaner.


# 214390 26-Oct-2010 jkim

Add two new loader tunables 'hw.acpi.install_interface' and
'hw.acpi.remove_interface'. hw.acpi.install_interface lets you install new
interfaces. Conversely, hw.acpi.remove_interface lets you remove OS
interfaces from the pre-defined list in ACPICA. For example,

hw.acpi.install_interface="FreeBSD"

lets _OSI("FreeBSD") method to return 0xffffffff (or success) and

hw.acpi.remove_interface="Windows 2009"

lets _OSI("Windows 2009") method to return zero (or failure). Both are
comma-separated lists and leading white spaces are ignored. For example,
the following examples are valid:

hw.acpi.install_interface="Linux, FreeBSD"
hw.acpi.remove_interface="Windows 2006, Windows 2006.1"


# 214076 19-Oct-2010 jkim

Remove undocumented and stale debug.acpi.do_powerstate tunable. It was
added with hw.pci.do_powerstate but the PCI version was splitted into two
separate tunables later and now this is completely stale. To make it worse,
PCI devices enumerated in ACPI tree ignore this tunable as it is handled by
a function in acpi_pci.c instead.


# 214072 19-Oct-2010 jkim

Remove PCI_SET_POWERSTATE method from acpi.c and eradicate all PCI-specific
knowledges from the file. All PCI devices enumerated in ACPI tree must use
correct one from acpi_pci.c any way. Reduce duplicate codes as we did for
pci.c in r213905. Do not return ESRCH from PCIB_POWER_FOR_SLEEP method.
When the method is not found, just return zero without modifying the given
default value as it is completely optional. As a side effect, the return
state must not be NULL. Note there is actually no functional change by
removing ESRCH because acpi_pcib_power_for_sleep() always returns zero.
Adjust debugging messages and add new ones under bootverbose to help
debugging device power state related issues.

Reviewed by: jhb, imp (earlier versions)


# 213755 13-Oct-2010 jkim

Use AcpiReset() from ACPICA instead of rolling our own, which is actually
incomplete. If FADT says the register is available, enable the capability
by default. Remove the previous default value from acpi(4).


# 212993 22-Sep-2010 avg

acpi_attach: do not explicitly install default handlers for default
address spaces

There has been no need to do that starting with ACPICA 20040427 as
AcpiEnableSubsystem() installs the handlers automatically.
Additionaly, explicitly calling AcpiInstallAddressSpaceHandler before
AcpiEnableSubsystem is not supported by ACPICA and leads to too early
execution of _REG methods in some DSDTs, which may result in problems.

Big thanks to Robert Moore of ACPICA/Intel for explaining the above.

Reported by: Daniel Bilik <daniel.bilik@neosystem.cz>
Tested by: Daniel Bilik <daniel.bilik@neosystem.cz>
Reviewed by: jkim
Suggested by: "Moore, Robert" <robert.moore@intel.com>
MFC after: 1 week


# 212413 10-Sep-2010 avg

bus_add_child: change type of order parameter to u_int

This reflects actual type used to store and compare child device orders.
Change is mostly done via a Coccinelle (soon to be devel/coccinelle)
semantic patch.
Verified by LINT+modules kernel builds.

Followup to: r212213
MFC after: 10 days


# 212172 03-Sep-2010 avg

acpi: update stale comments about order of cpu devices probing

These comments should have been updated in r203776 when the order was
changed.

Pointyhat to: avg
MFC after: 3 days


# 211430 17-Aug-2010 jhb

Add a new method to the PCI bridge interface, PCIB_POWER_FOR_SLEEP(). This
method is used by the PCI bus driver to query the power management system
to determine the proper device state to be used for a device during suspend
and resume. For the ACPI PCI bridge drivers this calls
acpi_device_pwr_for_sleep(). This removes ACPI-specific knowledge from
the PCI and PCI-PCI bridge drivers.

Reviewed by: jkim


# 210150 15-Jul-2010 jkim

If there is any pending sleep request, disallow entering S5 state.
Otherwise, bad things may happen. ;-)


# 210003 13-Jul-2010 jkim

Make SMP code path conditional at run-time.


# 209747 06-Jul-2010 jkim

Fix mis-merges in the previous commit.


# 209746 06-Jul-2010 jkim

Merge ACPICA 20100702.


# 208925 08-Jun-2010 jhb

The lock associated with the /dev/apm knote is already held, so use
KNOTE_LOCKED() instead of KNOTE_UNLOCKED().

Reported by: mav
MFC after: 3 days


# 208436 23-May-2010 mav

Make table-based HPET identification more clever. Before creating fake
device, make sure we have no real HPET device entry with same ID.
As side effect, it potentially allows several HPETs to be attached.
Use first of them for timecounting, rest (if ever present) could later
be used as event sources.


# 206117 02-Apr-2010 jkim

Merge ACPICA 20100331 (and four additional upstream patches).


# 204916 09-Mar-2010 jkim

- Allow users to enable dumping Debug objects without ACPI debugger.
Setting the new sysctl MIB "debug.acpi.enable_debug_objects" to a non-zero
value enables us to print Debug object when something is written to it.
- Allow users to disable interpreter slack mode. Setting the new tunable
"debug.acpi.interpreter_slack" to zero disables some workarounds for common
BIOS mistakes and enables strict ACPI implementations by the specification.


# 204773 05-Mar-2010 jkim

Merge ACPICA 20100304.


# 203785 11-Feb-2010 avg

acpi: drop the second bus_generic_attach pass

It is belived that that pass s not needed anymore.
Specifically it is not required now for the reasons that were given
in the removed comment.

Discussed with: jhb
MFC after: 4 weeks


# 203776 11-Feb-2010 avg

acpi cpu: probe+attach before all other enumerated children on acpi bus

Some current systems dynamically load SSDT(s) when _PDC/_OSC method
of Processor is evaluated. Other devices in ACPI namespace may access
objects defined in the dynamic SSDT. Drivers for such devices might
have to have a rather high priority, because of other dependencies.
Good example is acpi_ec driver for EC.
Thus we attach to Processors as early as possible to load the SSDTs
before any other drivers may try to evaluate control methods.
It also seems to be a natural order for a processor in a device
hierarchy.

On the other hand, some child devices on acpi cpu bus need to access
other system resources like PCI configuration space of chipset devices,
so they need to be probed and attached rather late.
For this reason we probe and attach the cpu bus at
SI_SUB_CONFIGURE:SI_ORDER_MIDDLE SYSINIT level.
In the future this could be done more elegantly via multipass.

Please note that acpi drivers that might access ACPI namespace from
device_identify will do that before _PDC/_OSC of Processors are evaluated.

Legacy cpu driver is not affected by this change.

PR: kern/142561 (in part)
Reviewed by: jhb
Silence from: acpi@
MFC after: 5 weeks


# 199337 16-Nov-2009 jkim

Merge ACPICA 20091112.


# 199016 07-Nov-2009 avg

acpi: remove 'magic' ivar

o acpi_hpet: auto-added 'wildcard' devices can be identified by
non-NULL handle attribute.
o acpi_ec: auto-add 'wildcard' devices can be identified by
unset (NULL) private attribute.
o acpi_cpu: use private instead of magic to store cpu id.

Reviewed by: jhb
Silence from: acpi@
MFC after: 2 weeks
X-MFC-Note: perhaps the ivar should stay for ABI stability


# 197536 27-Sep-2009 jkim

Copy apm(4) emulation from sys/i386/acpica/acpi_machdep.c and
install apm(8) and apm_bios.h on amd64.


# 197439 23-Sep-2009 jhb

Extract the code to find and map the MADT ACPI table during early kernel
startup and genericize it so it can be reused to map other tables as well:
- Add a routine to walk a list of ACPI subtables such as those used in the
APIC and SRAT tables in the MI acpi(4) driver.
- Move the routines for mapping and unmapping an ACPI table as well as
mapping the RSDT or XSDT and searching for a table with a given signature
out into acpica_machdep.c for both amd64 and i386.


# 197105 11-Sep-2009 jkim

Catch up with ACPICA 20090903.


# 196520 24-Aug-2009 jhb

Tweak the way that the ACPI and ISA bus drivers match hint devices to
BIOS-enumerated devices:
- Assume a device is a match if the memory and I/O ports match even if the
IRQ or DRQ is wrong or missing. Some BIOSes don't include an IRQ for
the atrtc device for example.
- Add a hack to better match floppy controller devices. Many BIOSes do not
include the starting port of the floppy controller listed in the hints
(0x3f0) in the resources for the device. So far, however, all the BIOS
variations encountered do include the 'port + 2' resource (0x3f2), so
adjust the matching for "fdc" devices to look for 'port + 2'.

Reviewed by: imp
MFC after: 3 days


# 196403 20-Aug-2009 jhb

Temporarily revert the new-bus locking for 8.0 release. It will be
reintroduced after HEAD is reopened for commits by re@.

Approved by: re (kib), attilio


# 196037 02-Aug-2009 attilio

Make the newbus subsystem Giant free by adding the new newbus sxlock.
The newbus lock is responsible for protecting newbus internIal structures,
device states and devclass flags. It is necessary to hold it when all
such datas are accessed. For the other operations, softc locking should
ensure enough protection to avoid races.

Newbus lock is automatically held when virtual operations on the device
and bus are invoked when loading the driver or when the suspend/resume
take place. For other 'spourious' operations trying to access/modify
the newbus topology, newbus lock needs to be automatically acquired and
dropped.

For the moment Giant is also acquired in some key point (modules subsystem)
in order to avoid problems before the 8.0 release as module handlers could
make assumptions about it. This Giant locking should go just after
the release happens.

Please keep in mind that the public interface can be expanded in order
to provide more support, if there are really necessities at some point
and also some bugs could arise as long as the patch needs a bit of
further testing.

Bump __FreeBSD_version in order to reflect the newbus lock introduction.

Reviewed by: ed, hps, jhb, imp, mav, scottl
No answer by: ariff, thompsa, yongari
Tested by: pho,
G. Trematerra <giovanni dot trematerra at gmail dot com>,
Brandon Gooch <jamesbrandongooch at gmail dot com>
Sponsored by: Yahoo! Incorporated
Approved by: re (ksmith)


# 193530 05-Jun-2009 jkim

Import ACPICA 20090521.


# 192450 20-May-2009 imp

We no longer need to use d_thread_t, migrate to struct thread *.


# 191699 30-Apr-2009 jkim

Fix off-by-one bug. S5 state must be checked as well.


# 191697 30-Apr-2009 jkim

Fix style(9).


# 191696 30-Apr-2009 jkim

Prefer device_printf() over printf() where ever possible.


# 191695 30-Apr-2009 jkim

General sleep state change clean up.

- Probe supported sleep states from acpi_attach() just once and do not
call AcpiGetSleepTypeData() again. It is redundant because
AcpiEnterSleepStatePrep() does it any way.
- Treat UNKNOWN sleep state as NONE, i.e., "do nothing", and remove obscure
NONE state (ACPI_S_STATES_MAX + 1) to avoid confusions.
- Do not set unsupported sleep states as default button/switch events.
If the default sleep state is not supported, just set it as UNKNOWN/NONE.
- Do not allow sleep state change if the system is not fully up and running.
This should prevent entering S5 state multiple times, which causes strange
behaviours later.
- Make sleep states case-insensitive when they are used with sysctl(8).
For example,

sysctl hw.acpi.lid_switch_state=s1
sysctl hw.acpi.sleep_button_state=none

are now legal and equivalent to the uppercase ones.


# 191627 28-Apr-2009 avg

acpi: do not run resume/backout code when entering S0/S5 states

This change adds (possibly redundant) early check for invalid
state input parameter (including S0). Handling of S5 request
is reduced to simply calling shutdown_nice(). As a result
control flow of acpi_EnterSleepState is somewhat simplified
and resume/backout half of the function is not executed
for S5 (soft poweroff) request and invalid state requests.

Note: it seems that shutdown_nice may act as nop when initproc
is already initialized (to grab pid of 1), but init process is in
"pre-natal" state.

Tested by: Fabian Keil <fk@fabiankeil.de>
Reviewed by: njl, jkim
Approved by: rpaulo


# 190340 23-Mar-2009 jkim

Add a function to reset system time after resuming, which will be used
by amd64 shortly. It can be turned off by setting "debug.acpi.reset_clock"
tunable to zero.


# 190339 23-Mar-2009 jkim

Check whether devd is running before calling resume notifier and
reshuffle code to reduce unnecessary locking coverage.


# 189903 17-Mar-2009 jkim

Initial suspend/resume support for amd64.

This code is heavily inspired by Takanori Watanabe's experimental SMP patch
for i386 and large portion was shamelessly cut and pasted from Peter Wemm's
AP boot code.


# 185059 18-Nov-2008 jhb

Allow device hints to wire the unit numbers of devices.
- An "at" hint now reserves a device name.
- A new BUS_HINT_DEVICE_UNIT method is added to the bus interface. When
determining the unit number of a device, this method is invoked to
let the bus driver specify the unit of a device given a specific
devclass. This is the only way a device can be given a name reserved
via an "at" hint.
- Implement BUS_HINT_DEVICE_UNIT() for the acpi(4) and isa(4) bus drivers.
Both of these busses implement this by comparing the resources for a
given hint device with the resources enumerated by ACPI/PnPBIOS and
wire a unit if the hint resources are a subset of the "real" resources.
- Use bus_hinted_children() for adding hinted devices on isa(4) busses
now instead of doing it by hand.
- Remove the unit kludging from sio(4) as it is no longer necessary.

Prodding from: peter, imp
OK'd by: marcel
MFC after: 1 month


# 184563 02-Nov-2008 imp

Make the no driver stuff an ifdef.


# 182071 23-Aug-2008 imp

Handle errors from device_get_children.


# 181987 22-Aug-2008 jhb

Extend the support for PCI-e memory mapped configuration space access:
- Rename pciereg_cfgopen() to pcie_cfgregopen() and expose it to the
rest of the kernel. It now also accepts parameters via function
arguments rather than global variables.
- Add a notion of minimum and maximum bus numbers and reject requests for
an out of range bus.
- Add more range checks on slot/func/reg/bytes parameters to the cfg reg
read/write routines. Don't panic on any invalid parameters, just fail
the request (writes do nothing, reads return -1). This matches the
behavior of the other cfg mechanisms.
- Port the memory mapped configuration space access to amd64. On amd64
we simply use the direct map (via pmap_mapdev()) for the memory mapped
window.
- During acpi_attach() just after loading the ACPI tables, check for a
MCFG table. If it exists, call pciereg_cfgopen() on each subtable
(memory mapped window). For now we only support windows for domain 0
that start with bus 0. This removes the need for more chipset-specific
quirks in the MD code.
- Remove the chipset-specific quirks for the Intel 5000P/V/Z chipsets
since these machines should all have MCFG tables via ACPI.
- Updated pci_cfgregopen() to DTRT if ACPI had invoked pcie_cfgregopen()
earlier.

MFC after: 2 weeks


# 181299 04-Aug-2008 jhb

Fix a typo.


# 180760 23-Jul-2008 jhb

Further refine the probe order of devices to more closely match the previous
behavior. Specifically, probe Host-PCI bridges in the order they are
encountered in the tree. For CPUs, just use an order of 100000 and assume
that no Host-PCI bridges will be more than 10000 levels deep in the
namespace. This fixes an issue on some boxes where the HPET timer stopped
attaching.


# 177985 07-Apr-2008 jhb

Revert back to probing Host-PCI bridges in the order we encounter them in
the tree rather than sorting them by their address on PCI bus 0.

Reported by: kan


# 177157 13-Mar-2008 jhb

Rework how the nexus(4) device works on x86 to better handle the idea of
different "platforms" on x86 machines. The existing code already handles
having two platforms: ACPI and legacy. However, the existing approach was
rather hardcoded and difficult to extend. These changes take the approach
that each x86 hardware platform should provide its own nexus(4) driver (it
can inherit most of its behavior from the default legacy nexus(4) driver)
which is responsible for probing for the platform and performing
appropriate platform-specific setup during attach (such as adding a
platform-specific bus device). This does mean changing the x86 platform
busses to no longer use an identify routine for probing, but to move that
logic into their matching nexus(4) driver instead.
- Make the default nexus(4) driver in nexus.c on i386 and amd64 handle the
legacy platform. It's probe routine now returns BUS_PROBE_GENERIC so it
can be overriden.
- Expose a nexus_init_resources() routine which initializes the various
resource managers so that subclassed nexus(4) drivers can invoke it from
their attach routine.
- The legacy nexus(4) driver explicitly adds a legacy0 device in its
attach routine.
- The ACPI driver no longer contains an new-bus identify method. Instead
it exposes a public function (acpi_identify()) which is a probe routine
that the MD nexus(4) drivers can use to probe for ACPI. All of the
probe logic in acpi_probe() is now moved into acpi_identify() and
acpi_probe() is just a stub.
- On i386 and amd64, an ACPI-specific nexus(4) driver checks for ACPI via
acpi_identify() and claims the nexus0 device if the probe succeeds. It
then explicitly adds an acpi0 device in its attach routine.
- The legacy(4) driver no longer knows anything about the acpi0 device.
- On ia64 if acpi_identify() fails you basically end up with no devices.
This matches the previous behavior where the old acpi_identify() would
fail to add an acpi0 device again leaving you with no devices.

Discussed with: imp
Silence on: arch@


# 177041 10-Mar-2008 jhb

Probe CPUs after the PCI hierarchy on i386, amd64, and ia64. This allows
the cpufreq drivers to reliably use properties of PCI devices for quirks,
etc.
- For the legacy drivers, add CPU devices via an identify routine in the
CPU driver itself rather than in the legacy driver's attach routine.
- Add CPU devices after Host-PCI bridges in the acpi bus driver.
- Change the ichss(4) driver to use pci_find_bsf() to locate the ICH and
check its device ID rather than having a bogus PCI attachment that only
checked for the ID in probe and always failed. As a side effect, you
can now kldload ichss after boot.
- Fix the ichss(4) driver to use the correct device_t for the ICH (and not
for ichss0) when doing PCI config space operations to enable SpeedStep.

MFC after: 2 weeks
Reviewed by: njl, Andriy Gapon avg of icyb.net.ua


# 175732 28-Jan-2008 iwasaki

Return errno value rather than boolean in this context.

MFC after: 1 week


# 175727 27-Jan-2008 iwasaki

Enter the sleep state immediately without waiting for timeout if
devd(8) is not running such as the system in single user mode.

MFC after: 1 week


# 172489 09-Oct-2007 njl

Fix the HPET table probe routine to run from device_identify() instead
of directly from acpi0. Before it would attach prior to the sysresource
devices, causing the later allocation of its memory range to fail and
print a warning like "acpi0: reservation of fed00000, 1000 (3) failed".
Use an explicit define for our probe order base value of 10.

Help from: jhb
Tested by: Abdullah Ibn Hamad Al-Marri <almarrie / gmail.com>
MFC after: 3 days
Approved by: re


# 172153 13-Sep-2007 njl

Reject requests to start or ack a suspend sequence on platforms that do not
support suspend/resume, currently all except i386.

Tested by: jkim
Approved by: re


# 171119 30-Jun-2007 njl

My previous commit introduced a spurious warning for the case where a
switch (i.e. lid) is set to have an action of NONE. This is not an
invalid state, so silently return. This fixes the warning:
"acpi: request to enter state S6 failed (err 22)"

Approved by: re


# 170976 21-Jun-2007 njl

Update the suspend/resume user API while maintaining backwards compat.

Improvements:
* /etc/rc.suspend,rc.resume are always run, no matter the source of the
suspend request (user or kernel, apm or acpi)
* suspend now requires positive user acknowledgement. If a user program
wants to cancel the suspend, they can. If one of the user programs
hangs or doesn't respond within 10 seconds, the system suspends anyway.
* /dev/apm is clonable, allowing multiple listeners for suspend events.
In the future, xorg-server can use this to be informed about suspend
even if there are other listeners (i.e. apmd).

Changes:
* Two new ACPI ioctls: REQSLPSTATE and ACKSLPSTATE. Request begins the
process of suspending by notifying all listeners. acpi is monitored by
devd(8) and /dev/apm listener(s) are also counted. Users register their
approval or disapproval via Ack. If anyone disapproves, suspend is vetoed.
* Old user programs or kernel modules that used SETSLPSTATE continue to
work. A message is printed once that this interface is deprecated.
* acpiconf gains the -k flag to ack the suspend request. This flag is
undocumented on purpose since it's only used by /etc/rc.suspend. It is
not intended to be a permanent change and will be removed once a better
power API is implemented.
* S5 (power off) is no longer supported via acpiconf -s 5 or apm -z/-Z.
This restores previous behavior of halt/shutdown -p being the interface.
* Miscellaneous improvements to error reporting

Approved by: re


# 170783 15-Jun-2007 njl

Convert magic to a uintptr_t. This should get rid of some warnings on
gcc4.


# 169973 25-May-2007 njl

Add a sysctl, 'debug.acpi.suspend_bounce', that causes the system to bounce
back in a simulated resume instead of entering the requested suspend state.
This helps in testing drivers separately from the acpi suspend code. To
test your drivers, set debug.acpi.suspend_bounce=1 and then run
acpiconf -s3 (or 4).

MFC after: 1 day


# 169574 15-May-2007 takawata

Add ACPI HPET table support.

Reviewed by:njl


# 169377 08-May-2007 marks

Set the debug.acpi.acpi_ca_version sysctl even if ACPI support is not
available.


# 169039 25-Apr-2007 jhb

Use a tighter check to see if a resource allocation request is for a
specific request and thus should first try to be allocated from the
sys_resource pool. This avoids using the sys_resource pool for wildcard
requests that have bounded ranges coming from cbb(4) and Host-PCI pcib(4)
drivers.

Tested by: Andrea Bittau <a.bittau of cs.ucl.ac.uk fame>
Sleuthing by: Andrea Bittau as well


# 167814 22-Mar-2007 jkim

Catch up with ACPI-CA 20070320 import.


# 167768 21-Mar-2007 jhb

Change acpi's handling of suballocating system resources to be a little
simpler. It now can just use rman_is_region_manager() during
acpi_release_resource() to see if the the resource is suballocated from
a system resource. Also, the driver no longer needs MD knowledge about
how to setup bus space tags and handles when doing a suballocation, but
can simply rely on bus_activate_resource() in the parent setting all that
up.


# 167742 20-Mar-2007 jhb

Tweak the probe/attach order of devices on the x86 nexus devices.
Various BIOS-related psuedo-devices are added at an order of 5. acpi0 is
added at an order of 10, and legacy0 is added at an order of 11.


# 166881 22-Feb-2007 njl

Improve readability of the version string.


# 165875 07-Jan-2007 njl

Re-work Cx handling to be per-cpu and asymmetrical, fixing support on
modern dual-core systems as well.

- Parse the _CST packages for each cpu and track all the states individually,
on a per-cpu basis.

- Revert to generic FADT/P_BLK based Cx control if the _CST package
is not present on all cpus. In that case, the new driver will
still support per-cpu Cx state handling. The driver will determine the
highest Cx level that can be supported by all the cpus and configure the
available Cx state based on that.

- Fixed the case where multiple cpus in the system share the same
registers for Cx state handling. To do that, added a new flag
parameter to the acpi_PkgGas and acpi_bus_alloc_gas functions that
enable the caller to add the RF_SHAREABLE flag. This flag could also be
useful to other callers (acpi_throttle?) in the tree but this change is
not yet made.

- For Core Duo cpus, both cores seems to be taken out of C3 state when
any one of the cores need to transition out. This broke the short sleep
detection logic. It is disabled now if there is more than one cpu in
the system for now as it fixed it in my case. This quirk may need to
be re-enabled later differently.

- Added support to control cx_lowest on a per-cpu basis. There is still
a generic cx_lowest to enable changing cx_lowest for all cpus with a single
sysctl and for ease of use. Sample output for the new sysctl:

dev.cpu.0.cx_supported: C1/1 C2/1 C3/57
dev.cpu.0.cx_lowest: C3
dev.cpu.0.cx_usage: 0.00% 43.16% 56.83%
dev.cpu.1.cx_supported: C1/1 C2/1 C3/57
dev.cpu.1.cx_lowest: C3
dev.cpu.1.cx_usage: 0.00% 45.65% 54.34%
hw.acpi.cpu.cx_lowest: C3

This work was done by Stephane E. Potvin with some simple reworking by
myself. Thank you.

Submitted by: Stephane E. Potvin <sepotvin / videotron.ca>
MFC after: 2 weeks


# 162531 21-Sep-2006 jhb

Fix a sign bug in acpi_release_resource(). acpi_sysres_find() returns !=
NULL if the specified resource is a sub-alloc of a system resource.


# 162225 11-Sep-2006 jhb

Give the ACPI I/O rman's unique description strings to make 'devinfo -u'
output less confusing.

MFC after: 3 days


# 160824 29-Jul-2006 njl

Add a new sysctl, hw.acpi.handle_reboot. If set, acpi will attempt to
perform the reboot action via the reset register instead of our legacy
method. Default is 0 (use legacy). This is needed because some systems
hang on reboot even though they claim to support the reset register.

MFC after: 2 days


# 159524 11-Jun-2006 njl

By default, don't disable ACPI during reboot. This appears to hang some
systems. Introduce a new sysctl "hw.acpi.disable_on_reboot" that allows
users to re-enable the old behavior in case it's needed for some systems.
We never disable in the power-off path.

Original approach submitted by Alexander Logvinov <abuse@akavia.ru> with
reworking by Jung-uk Kim and myself.


# 159476 10-Jun-2006 njl

Minor sysctl cleanup. The RW flag means read|write and so it is redundant
to add the RD flag. Also, the debug node does not need to be writable.


# 158651 16-May-2006 phk

Since DELAY() was moved, most <machine/clock.h> #includes have been
unnecessary.


# 158346 07-May-2006 njl

Don't attach special devices in the order they appear in the AML tree.
If the embedded controller exists before the sysresource devices, for
example, it will be attached first. Instead, let the normal device
order function work as we first desired. [1]

There still remained a problem where we couldn't allocate resources in
acpi0 that were passed up by the sysresource pseudo-devices. These
devices had to probe/attach first to give their resources to acpi, then
acpi would allocate them before probing/attaching other devices. To
work around this, we attach them from acpi_sysres_alloc(). A better
approach would be to implement multi-pass probe/attach in newbus but
that's a much bigger task.

Suggested by: jhb [1]
Hardware from: Centaur Technologies
MFC after: 1 week


# 157897 20-Apr-2006 imp

Set the rid for the resoruce obtained from rman_reserve_resource.


# 157774 15-Apr-2006 iwasaki

Import ACPI Dock Station support. Note that this is still very young.
Additional detach implementaions (or maybe improvement) for other
deivce drivers is required.

Reviewed by: njl, imp
MFC after: 1 week


# 157244 29-Mar-2006 njl

Add reset register support. This is the only method to reboot some new
systems (blade servers). On most systems, this is implemented as an IO
write to the SMI port and the BIOS generates the actual reset.

PR: kern/94939
Submitted by: dodell@ixsystems.com
Reviewed by: jhb
MFC after: 3 weeks


# 152171 07-Nov-2005 jhb

*sigh* Revert stuff that wasn't supposed to be committed. The
acpi_resource change was a minor nit offered as an early candidate for
the recent ACPICA import problem and the acpi.c change is one I need to
test still that makes the ordered probing of system devices actually work
as advertised (probe devices in order based on the type of device rather
than in the order we encounter them in the device tree).


# 152170 07-Nov-2005 jhb

Work around at least one busted BIOS. If we get a source index in a _PRT
entry that is not zero, assume that it is really a hard-wired IRQ (commonly
used for APIC routing) and not a source index. In practice, we've only
ever seen source indices of 0 for legitimate non-hard-wired _PRT entries.

Reviewed by: njl
Tested by: Alex Lyashkov shadow at psoft dot net
MFC after: 2 weeks


# 151948 01-Nov-2005 jkim

Catch up with ACPI-CA 20051021 import


# 151566 23-Oct-2005 njl

Add a hack to get around PCI link devices that report "present" but not
"functional" (i.e., if they are disabled). We should probe them anyway
since we may enable them later.

Tested by: thompsa
MFC after: 3 days


# 150003 11-Sep-2005 obrien

Canonize the include of acpi.h.


# 146949 03-Jun-2005 imp

In newbus land, ivars can only be accessed for direct child, or when
the driver has unholy private knowledge of its great-*cgrandchildren.
The ACPI allocation routine lacked such knowledge when it tried to do
a default allocation for all descendants, rather than just its
immeidate children, so would access grandchild's ivar in an unsafe
way. This could lead to a panic when devices were present which had
no addresses setup by the BIOS, but which were later allocated in a
lazy manner via pci_alloc_map. As such, only do the default
allocation adjustments for immediate children. The manner that
acpi_sysres_find accesses the resource list, used later in
acpi_alloc_resource, is safe and proper so no additional test is
needed there.

This fixes a panic when probing an disabled ata controller on some
newer intel blades.

Reported by: dwhite


# 146431 20-May-2005 njl

If devclass_get_devices() returns success but a count of 0, free the
pointer. If kernel malloc(0) returns a valid pointer, it needs to be
freed. If it returns NULL, it's ok to free this also.

Submitted by: pjd
Reviewed by: imp, dfr
Obtained from: Coverity Prevent


# 146021 09-May-2005 marks

Simplify the ACPI taskqueue implementation. Use a thread queue type instead
of swi. This allows us to use the taskqueue_thread_* functions instead of
rolling our own. It also avoids a double trip through the queue.

Submitted by: njl
Reviewed by: sam


# 145058 14-Apr-2005 jhb

Probe PCI link devices early so that we turn them all off via _DIS before
we start turning any of them back on again. This works around a bug in
some BIOSen that alias two different link devices for APIC vs ATPIC modes
onto the same physical hardware link.

Submitted by: njl
Tested by: Antoine Brodin antoine dot brodin at laposte dot net


# 144414 31-Mar-2005 njl

Always free the returned env pointer even it doesn't indicate we're in
verbose mode.

Found by: Coverity Prevent (via sam)


# 144197 27-Mar-2005 njl

Clean up resources properly if acpi_perf fails to attach. First, change
acpi_bus_alloc_gas() to delete the resource it set if alloc fails. Then,
change acpi_perf to delete the resource after releasing it if alloc fails.
This should make probe and attach both fully restartable if either fails.


# 144170 27-Mar-2005 njl

If a device_add_child fails (i.e. low memory situation), be sure to free
the unused ivars also.

Submitted by: pjd
Obtained from: Coverity Prevent analysis


# 143997 22-Mar-2005 njl

Add support for bus_delete_resource() and make acpi_bus_alloc_gas() do
this before setting a new resource.


# 143801 18-Mar-2005 phk

s/SLIST/STAILQ/
/imp/a\
pointy hat
.


# 143002 02-Mar-2005 obrien

Fix SCM ID's.


# 142516 25-Feb-2005 njl

Remove unused variable.

Noticed by: Coverity tool


# 142480 25-Feb-2005 njl

Instead of assuming units of bytes, it seems more likely that this is
a bitfield.


# 142278 23-Feb-2005 njl

If a register width is less than 8, assume the BIOS author thought it was
in units of bytes and adjust accordingly. This is found at least on the
Sony PCG-505BX.


# 142024 17-Feb-2005 njl

Check for the address space type first before validating it. In particular,
we want to return EOPNOTSUPP for FFixedHW no matter what the address.

Submitted by: Bruno Ducrot


# 141830 13-Feb-2005 njl

Allow users to manually override quirks with the tunable "debug.acpi.quirks".
Suggested by: Jung-uk Kim


# 141371 05-Feb-2005 njl

Convert the acpi_bus_alloc_gas() and acpi_PkgGas() APIs to output the memory
type. This is needed if the resource is to be released later. The RID is
still also present, though less necessary since rman_get_rid() can be used
to obtain it from the resource.


# 139900 08-Jan-2005 njl

In total violation of at least 4 sections in the ACPI spec, some systems
place device objects in \ (in this case, PCI links.) Work around this by
starting our probe from \. To avoid attaching system scope objects,
explicitly skip them. (I think it's an ACPI-CA bug that \_SB and \_TZ have
device and thermal object types.) Thanks to pjd@ for testing.

MFC after: 2 weeks


# 139339 27-Dec-2004 njl

Remove trailing whitespace.


# 138378 05-Dec-2004 njl

Grab Giant around calls to DEVICE_SUSPEND/RESUME in acpi_SetSleepState().
If we are resuming non-MPSAFE drivers, they need Giant held for them.
This may fix some obscure suspend/resume problems. It has fixed keyrate
setting problems that were triggered by cardbus (MPSAFE) changing the
ordering for syscons resume (non-MPSAFE). Also, add some asserts that
Giant is held in our suspend/resume and shutdown methods.

Found by: iedowse
MFC after: 2 days


# 138333 03-Dec-2004 njl

Enable the relaxed behavior for op regions and other workarounds for
non-standard BIOSen. We used to implement this in local patches but
now that ACPI-CA has merged/re-implemented most of our fixes, they were
no longer needed and we just needed to turn this knob on. Also, remove
an unnecessary cast.

Tested by: phk


# 138306 02-Dec-2004 njl

Turn ACPI and PCI devices off or to a lower power state in suspend and
back on again in resume. Override the default of D3 with the value the
BIOS specifies in _SxD, if present. Skip serial devices (PNP05xx) since
they seem to hang when set to D3 and may require special driver support.
Also, skip non-type 0 PCI devices (i.e., bridges) since our we don't yet
save/restore their config space and that seems to be necessary.

If this gives you trouble with suspend/resume, you can disable the new
ACPI and PCI power behavior separately with these tunables & sysctls:
debug.acpi.do_powerstate
hw.pci.do_powerstate

Approved by: imp (pci)
Tested by: acpi@ (numerous)


# 136476 13-Oct-2004 njl

Print before the footer, not after.


# 136475 13-Oct-2004 njl

If flags are present, print them like ISA does.

MFC after: 1 day


# 136455 12-Oct-2004 njl

Attach the device description for ISA devices on the ACPI bus.

MFC after: 1 day


# 135545 21-Sep-2004 njl

Don't disable acpi in shutdown if we're panicing (panicstr != NULL). This
may help with double panics.


# 134217 23-Aug-2004 njl

Rework sysresource management. Instead of having each sysresource object
hold its own values, pass them up to the parent (acpi0) and merge/uniq them
on the way. After the namespace evaluation, acpi will reserve these
resources and manage them via rman before bus_generic_probe() and
bus_generic_attach(). This is necessary because some systems specify
conflicting resources in separate sysresource objects. It's also cleaner
in that the interface between sysresource and acpi is now merely the parent's
resource list. This code handles the following cases:

1. Unique resource: add it to the parent via bus_set_resource().
2. New wholly contained in old: discard new.
3. New tail overlaps old head: grow old head downward.
AND/OR
4. New head overlaps old tail: grow old tail upward.

Tested by: Pawel Worach <sajd_at_telia.com>
Tested by: Radek Kozlowski <radek_at_raadradd.com>
MFC after: 5 days


# 133943 18-Aug-2004 njl

Call AcpiLeaveSleepState() before DEVICE_RESUME(). The former calls the
BFS and WAK methods, which are needed to initialize some devices before
the driver can resume them. This was the original order.

MFC after: 2 days


# 133933 18-Aug-2004 njl

Remove the ACPIIO_ENABLE and ACPIIO_DISABLE ioctls as well as all
callers. These ioctls attempted to enable and disable the ACPI
interpreter at runtime. In practice, it is not possible to boot with
ACPI and then disable it on many systems and trying to do so can cause
crashes, interrupt storms, etc. Binary compatibility with userland is
retained.

MFC after: 2 days


# 133612 13-Aug-2004 njl

MPSAFE locking

* Serialize calls to acpi_alloc_resource(), acpi_release_resource(),
acpi_Enable(), acpi_Disable(), and acpi_debug_sysctl().
* Acquire the ACPI mutex in acpi_register_ioctl(), acpi_deregister_ioctl(),
and acpiioctl().
* Acquire the mutex while disabling subsequent requests to enter a
sleep state in acpi_SetSleepState().
* Be sure to re-enable sleep requests and don't run resume methods when
the current request fails.
* Don't check if sleep requests are disabled in the ACPIIO_SETSLPSTATE
ioctl. acpi_SetSleepState() does this for us.
* Remove the acquisition of Giant from the struct cdevsw.
* Remove the ACPI_USE_THREADS option.


# 133584 12-Aug-2004 njl

Allow null handles to be passed into acpi_name().


# 133455 10-Aug-2004 njl

Don't call DEVICE_RESUME a second time if DEVICE_SUSPEND fails. The
bus_generic_suspend method does this for us. Disable interrupts before
entering S1. This may help some systems suspend to S1 successfully.


# 133188 06-Aug-2004 njl

Add flags for _STA (status) methods and convenience macros for checking
the presence of batteries and devices.


# 133081 03-Aug-2004 njl

Fix the ACPI_DEBUG case by removing a now unused variable.


# 133075 03-Aug-2004 obrien

Initialize variables to fix kernel build on AMD64.


# 133051 03-Aug-2004 njl

/tmp/m


# 132651 26-Jul-2004 njl

Don't force an immediate probe/attach for all devices when compiled with
ACPI_DEBUG. This upset the ordering that acpi_probe_order() was meant to
provide, causing devices to attach before the sysresource object. This
debugging feature has been unnecessary for a while so just remove it.

Testing by: marcel


# 132212 15-Jul-2004 njl

Update the interface for child drivers. Add acpi_scan_children, which
allows a bus to re-enumerate its child handles and optionally replace
them with new children, arranged to the bus's liking. (The current device
space is flat with all devices immediately under acpi0). Add comments
for each interface.


# 132115 13-Jul-2004 njl

Clean up our pnpinfo and location strings.


# 132114 13-Jul-2004 njl

Call device_identify routines after doing the namespace walk. This is
needed so that sysresource objects are created first to reserve all regions,
then other devices can allocate from them. Otherwise, acpi_timer (the only
ACPI device with an identify routine), would allocate its resources from
the nexus, causing the later sysresource reserve to fail.

Debugging by: Taku YAMAMOTO, Andrea Campi


# 131417 01-Jul-2004 imp

After re-exporting rman, et al, __RMAN_RESOURCE_VISIBLE is no longer
necessary for this file. It just needed the size and guts of struct
rman.


# 131344 30-Jun-2004 imp

Hide struct resource and struct rman. You must define
__RMAN_RESOURCE_VISIBLE to see inside these now.

Reviewed by: dfr, njl (not njr)


# 131341 30-Jun-2004 njl

Move flags into a private ivar so it can't collide with device flags.
Unify the code to disable GPEs with the enable code. Shutdown is handled
the same way. ACPI now does all wake/sleep prep for child devices so
now they no longer need to call external functions in the suspend/resume
path. Add the flags to non-ACPI busses (i.e., pci).


# 131336 30-Jun-2004 njl

Diff reduction for style.


# 131315 30-Jun-2004 njl

Add new quirk code that disables problem BIOS versions. Remove old quirk
code that was never really used. Print a message when disabling ACPI via
a quirk. Allow the user to override the blacklist decision by setting
hint.acpi.0.disabled="0". Add missing AcpiTerminate() calls; they are
needed to clean up if bailing out after AcpiInitializeSubsystem().


# 131281 29-Jun-2004 njl

Add implementation of the ACPI methods which hands them off to ACPI-CA.
acpi_id_probe() returns NULL for no match or the ID string that matched
if the driver should attach.


# 131258 29-Jun-2004 njl

Include isa/pnpvar.h and remove a duplicate copy of PNP_EISAID.


# 131221 28-Jun-2004 imp

rman_reserve_resource doesn't set the bushandle, so we have to do it here.

Badness noted by: njl
Perforce reply not read by: imp


# 131189 27-Jun-2004 imp

MFp4: Set the bus handle to the bus handle of the resource, not the
starting value. This is more pedantically correct (since the handle
isn't always identical to the start of the resource) and also doesn't
access the innards of struct resource direct (which I forbid in my
tree). We need to do this for all resource types, not just ioport.

Reviewed by: njl


# 131004 24-Jun-2004 njl

Run the power off code directly instead of using indirection through
smp_rendezvous() to ensure we run on the BSP. This reverts rev 1.128.
Add a comment indicating that MI code should be the one that runs all
shutdown functions on the BSP with the APs halted. This should work
around problems in power off while waiting for the MI code to be improved.


# 130981 23-Jun-2004 jhb

- Defer BUS_CONFIG_INTR() on ACPI IRQ resources until the resources are
actually used. For most ACPI devices this means deferring the call
until bus_alloc_resource().
- Add a function acpi_config_intr() to call BUS_CONFIG_INTR() for an
ACPI IRQ resource using the trigger mode and polarity information
stored in the ACPI resource object.
- Add a function acpi_lookup_irq_resource() to lookup the ACPI IRQ
resource that corresponds to a specified rid and new-bus resource.
- Have the ACPI PCI bridge driver call BUS_CONFIG_INTR() on interrupts
that it routes through link devices.
- Remove needactivate variable from acpi_alloc_resource() by changing the
function not modify the flags variable but just mask off RF_ACTIVE when
calling rman_reserve_resource().

Reviewed by: njl (1, an earlier version)


# 130585 16-Jun-2004 phk

Do the dreaded s/dev_t/struct cdev */
Bump __FreeBSD_version accordingly.


# 130451 14-Jun-2004 njl

Remove disable_on_poweroff and our pre-sync shutdown handler. Disabling
of GPEs is now done in acpi_shutdown() and so we no longer need the option
of disabling ACPI in the poweroff case.


# 130450 14-Jun-2004 njl

Clean up acpi_probe_order() a bit and clarify some comments.


# 130448 14-Jun-2004 njl

Don't probe/attach in the ACPI_DEBUG case.


# 130439 13-Jun-2004 njl

Add support to ACPI to manage its own resources. Previously, resource
allocation was passed up to nexus. Now, we probe sysresource objects and
manage the resources they describe in a local rman pool. This helps
devices which attach/detach varying resources (like the _CST object) and
module loads/unloads. The allocation/release routines now check to see if
the resource is described in a child sysresource object and if so,
allocate from the local rman. Sysresource objects add their resources to
the pool and reserve them upon boot. This means sysresources need to be
probed before other ACPI devices.

Changes include:
* Add ordering to the child device probe. The current order is: system
resource objects, embedded controllers, then everything else.
* Make acpi_MatchHid take a handle instead of a device_t arg.
* Replace acpi_{get,set}_resource with the generic equivalents.


# 130417 13-Jun-2004 njl

Associate a device_t with an ACPI_HANDLE. This make AcpiWalkNamespace more
useful. If ACPI-CA allowed null object handlers, we wouldn't need the
placeholder function.


# 130119 05-Jun-2004 njl

Don't forget to pass shutdown events down to children first now that we
handle them at the bus level too.


# 130114 05-Jun-2004 njl

Disable wake GPEs in the reboot path as well as poweroff path. This fixes
"stray irq 9" messages on my Thinkpad. It may also help with general
reboot consistency although the recent hang on reboot was solved by
acpi_cpu.c rev 1.39.


# 129879 30-May-2004 phk

Add missing <sys/module.h> includes


# 129831 29-May-2004 njl

Decrease sleep_delay default to 1 second now that the machines that
required the 5 second delay have been fixed.


# 129807 28-May-2004 njl

Now that we properly disable GPEs before entering a sleep state, including
S5 (soft off), we don't need to disable ACPI when powering off. This may
fix some systems that don't power off correctly.


# 129805 28-May-2004 njl

Update the new suspend/resume GPE methods to properly limit the GPE
based on the destination sleep state. Add a method to restore the old
state on resume. This is needed for the case of suspending to a very low
state disabling a GPE (i.e. S4), resuming, and then suspending to a higher
state (i.e. S3). This case should now keep the proper GPEs enabled.


# 129804 28-May-2004 njl

Pass a pointer to the sleep state instead of casting gymnastics to pass
the value itself in the pointer.


# 129803 28-May-2004 njl

Fix paste-o.


# 129802 28-May-2004 njl

Attach per-device sysctls to allow users to set whether or not a given
device can wake the system. For example:

dev.root0.nexus0.acpi0.acpi_lid0.wake: 1
dev.root0.nexus0.acpi0.acpi_button0.wake: 1
dev.root0.nexus0.acpi0.pcib0.wake: 0
dev.root0.nexus0.acpi0.sio0.wake: 0


# 129800 28-May-2004 marcel

Fix LP64 environments: cast a pointer type to intptr_t before casting
to int and vice versa.


# 129783 27-May-2004 njl

Restructure the wake GPE API. Now there are three functions:

acpi_wake_init:
Evaluate _PRW and set the GPE type
acpi_wake_set_enable:
Enable or disable a device's GPE.
acpi_wake_sleep_prep:
Perform any last-minute changes to the device to prepare it for
entering the given sleep state.

Also, walk the entire namespace when transitioning to a sleep state,
disabling any GPEs which aren't appropriate for the given state. Transition
acpi_lid and acpi_button to the new API.

This clears the way for non-ACPI-aware devices to wake the system (i.e.
modems) and fixes a problem where systems power up after shutdown when a
GPE is triggered.


# 129692 25-May-2004 njl

Changes to implement 20040514:

* Add calls to AcpiSetGpeType. We use wake/run as the type for lid and
button switches since wake-only causes Thinkpads to immediately wake on
the second suspend. Note that with wake/run, some systems return both
wake and device-specific notifies so we don't register for system notifies
for lid and button switches.
* Remove the hw.acpi.osi_method tunable since it is not needed.
* Always print unknown notifies for all types.
* Add more cleanup for the EC if it fails to attach.
* Use the GPE handle now that we parse it. This allows GPEs to be defined
in AML GPE blocks.
* Always use ACPI_NOT_ISR since it's ok to acquire a mutex in our thread
which processes queued requests.


# 128993 06-May-2004 njl

Select the highest valid (i.e., S3) sleep state for the default for the
sleep button. Change the default for the lid switch to NONE. This can
be overridden in /etc/sysctl.conf as desired.


# 128989 06-May-2004 njl

Fix setting debug strings via sysctl. Also, clean up the way we print
debug strings.


# 128656 26-Apr-2004 takawata

Fix build breakage.

Submitted by: Xin LI <delphij@frontfree.net>
PR: 65979


# 128655 26-Apr-2004 njl

Move the call to AcpiEnterSleepStatePrep() to before we select the BSP
(cpuid 0) as the processor. It mallocs some data and smp_rendezvous
calls functions with locks held.


# 128504 21-Apr-2004 njl

Remove extran parens.


# 128503 21-Apr-2004 njl

Move the timer difference convenience function from acpi_cpu.c to make it
globally available. acpi_TimerDelta() subtracts two readings from the
ACPI PM timer and returns the difference. It properly distinguishes between
24-bit and 32-bit timers and handles wraparound.


# 128319 16-Apr-2004 njl

Disable the new wake GPE behavior. With it enabled, my laptop won't stay
suspended after the second try. Intel is working on a fix to properly
differentiate the non-standard wake/runtime GPEs from wake-only GPEs.


# 128249 14-Apr-2004 njl

Remove a non-variable static and move other static variables to the same
location.


# 128222 14-Apr-2004 njl

Use TRUE for a boolean and a style nit.


# 128045 09-Apr-2004 njl

Add support for packages as the first element of _PRW. This may allow
some machines to enable wake events for more devices although I haven't
seen a system yet that uses this form. Also, introduce acpi_GetReference()
which retrieves an object reference from various types.


# 128036 08-Apr-2004 njl

Unify on version 1 to be similar to the rest of the tree. After 5-stable
branches, increment version on any API change visible to other modules.


# 127700 01-Apr-2004 njl

Move the ivar accessing routines back to inlines (reverting acpivar.h
rev 1.44 and acpi.c rev 1.96). Now gcc can handle larger inlines and we
really need external drivers to be able to read their acpi ivars.


# 127681 31-Mar-2004 njl

Staticize pnp methods, style fixes. Remove unused variable to unbreak
kernel build.


# 127679 31-Mar-2004 njl

Add an interface to pass an argument to the resource parsing functions.
This is just groundwork for changing sysresource behavior.

PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
MFC after:


# 127678 31-Mar-2004 takawata

Style fix.

Pointed out by: njl


# 127609 30-Mar-2004 njl

Disable serialize_methods and enable _OSI support by default. The former
is necessary because some IBMs use recursive methods (pointed out by
Robert Moore from Intel). The latter was a typo on my part. It was disabled
by default when it should have been enabled.


# 127488 27-Mar-2004 takawata

Add ACPI PnP string. This affects devinfo(8) output with -v option.


# 127193 19-Mar-2004 njl

Move the poweroff handler to a separate function. Make sure it is run
on the boot processor (cpuid == 0). Some chipsets do not power off the
system if the shutdown handler runs on an AP.


# 127184 18-Mar-2004 njl

Add tunables for disabling serialized method execution and disabling the
new _OSI method. These can be used if these new features end up causing
regression for users.


# 127135 17-Mar-2004 njl

Convert callers to the new bus_alloc_resource_any(9) API.

Submitted by: Mark Santcroos <marks@ripe.net>
Reviewed by: imp, dfr, bde


# 126767 09-Mar-2004 njl

Simplify some logic in converting a buffer to an integer.


# 126766 09-Mar-2004 njl

Use an unsigned int instead of an int for the Get/Set Integer interface.

Pointed out by: le


# 126573 04-Mar-2004 njl

Add a "quirks" value to disable quirks handling for a given boot.
Also, disable quirks if booting with a custom DSDT. Add a quirk
to disable loading ACPI so known bad systems can be completely
blacklisted.


# 126560 03-Mar-2004 njl

Change to acpi_{Get,Set}Integer to provide both methods. Convert all
callers to the new API.

Submitted by: Mark Santcroos <marks@ripe.net>


# 126517 03-Mar-2004 njl

Add support for quirks for acpi tables. Key off OEM vendor and revision.
Sort acpi debug values. Change "disable" to "disabled" to match rest of
the kernel. Remove debugging from acpi_toshiba since it was only used for
probe/attach.


# 126080 21-Feb-2004 phk

Device megapatch 4/6:

Introduce d_version field in struct cdevsw, this must always be
initialized to D_VERSION.

Flip sense of D_NOGIANT flag to D_NEEDGIANT, this involves removing
four D_NOGIANT flags and adding 145 D_NEEDGIANT flags.


# 126076 21-Feb-2004 phk

Device megapatch 1/6:

Free approx 86 major numbers with a mostly automatically generated patch.

A number of strategic drivers have been left behind by caution, and a few
because they still (ab)use their major number.


# 126015 19-Feb-2004 njl

Use ACPI_NEXT_RESOURCE instead of defining our own copy. The one provided
with ACPI-CA is identical now.


# 125986 19-Feb-2004 njl

Fix problem caused by previous commit where some users' buttons
stopped returning events. Don't disable the event when removing
the handler because it still needs to be enabled for the other
handler. Also, remove duplicate AcpiEnableEvent calls since the
install function now does this for us.


# 125679 11-Feb-2004 njl

Prefer buttons defined in the AML over the ones in the FADT. Some
systems define power/sleep buttons in both places but only deliver
notifies to the ones defined in the AML.

Also, reduce length of various function handler names.

PR:
Submitted by:
Reviewed by:
Approved by:
Obtained from:
MFC after:


# 125135 28-Jan-2004 roam

Add an ACPI_FUNCTION_TRACE() to the newly-added acpi_Startup() routine
to get the ACPI_DEBUG case (and LINT in particular) to build.

Reviewed by: jhb, njl
Approved by: jhb


# 125047 26-Jan-2004 jhb

Move the code to initialize ACPI-CA into a separate acpi_Startup() function
that other modules can call to initialize ACPI-CA before the new-bus probe
and change acpi_identify() to call it.

Reviewed by: njl


# 124314 09-Jan-2004 njl

Clean up the acpi announce message of trailing spaces.


# 123867 26-Dec-2003 jhb

Fix acpi_MatchHid() to check the compatibility ID's if the hardware ID
doesn't match.

Submitted by: marcel


# 123781 23-Dec-2003 njl

Fix locking broken by recent _CID changes. Always be sure to unlock
in the error case.


# 123619 18-Dec-2003 njl

Add support for multiple CIDs since _CID can contain a package of values.
Implement this in acpi_MatchHid() and acpi_isa_get_compatid(). This
should fix mouse support for some users.

Move all users of AcpiGetObjectInfo() to use dynamic storage instead of
a devinfo on the stack. This is necessary since ACPI-CA needs to
allocate different sized arrays for the CompatList.


# 123337 09-Dec-2003 njl

Use sbufs instead of snprintf for parsing debug strings.


# 122904 19-Nov-2003 njl

* Add a DEVMETHOD for acpi so that child detach methods get called. Add
an acpi_cpu method for shutdown that disables entry to acpi_cpu_idle
and then IPIs/waits for threads to exit. This fixes a panic late in
reboot in the SMP case.

* In the !SMP case, don't use the processor id filled out by the MADT
since there can only be one processor. This was causing a panic in
acpi_cpu_idle if the id was 1 since the data was being dereferenced from
cpu_softc[1] even though the actual data was in cpu_softc[0] (which is
correct).

* Rework the initialization functions so that cpu_idle_hook is written
late in the boot process.

* Make the P_BLK, P_BLK_LEN, and cpu_cx_count all softc-local variables.
This will help SMP boxes that have _CST or multiple P_BLKs. No such
boxes are known at this time.

* Always allocate the C1 state, even if the P_BLK is invalid. This means
we will always take over idling if enabled. Remove the value -1 as
valid for cx_lowest since this is redundant with machdep.cpu_idle_hlt.

* Reduce locking for the throttle initialization case to around the write
to the smi_cmd port. Add disabled code to write the CST_CNT. It will
be enabled once _CST re-evaluation is tested (post 5.2R).

Thank you: dfr, imp, jhb, marcel, peter
Tested by: rwatson, Harald Schmalzbauer <h@schmalzbauer.de>
Approved by: re (rwatson)


# 122764 15-Nov-2003 njl

Add acpi_bus_alloc_gas() for allocating a memory or IO resource from its
Generic Address Structure.


# 121493 25-Oct-2003 njl

Add devctl(4) notify support to ACPI. Various subsystems now notify
userland whenever events occur. See the example in devd.conf below
to see how to use it.


# 121239 19-Oct-2003 njl

Disable irqs before entering the power-off state. This is not known
to fix any problems but is similar to how Linux implements this
function.


# 120494 26-Sep-2003 njl

Make debug.acpi.level and debug.acpi.layer sysctls that can be set with
the strings found in acpi(4). Also make acpi_ca_version a string so it
is more readable.


# 120450 26-Sep-2003 njl

Sort debugging levels and update the man page to match reality. Also
update man page to reflect iasl(8) import.


# 120186 18-Sep-2003 njl

Add necessary newlines.


# 120185 18-Sep-2003 njl

Shorten the message announcing fixed power/sleep buttons.


# 120087 15-Sep-2003 njl

Only enable S4BIOS by default if the FACS says it is available. The
user can override this with a sysctl.

Be sure to return the acpi_SetSleepState return value to userland.


# 119903 09-Sep-2003 njl

Disallow attempts to suspend to S0. It was only enabled for testing.
Print a more informative message if a sleep state is not supported by BIOS.
Add comments.


# 119739 04-Sep-2003 njl

Don't free the buffer if it wasn't actually allocated.


# 119549 29-Aug-2003 njl

Use the ACPICA AcpiEnterSleepStateS4bios instead of rolling our own. This
change also disables interrupts around non-S4 suspends whereas before we
did not do this. Our version of AcpiEnterSleepStateS4bios was almost
identical to the ACPICA version.


# 119529 28-Aug-2003 njl

Style and whitespace changes. Also, make the ivar functions non-inline
since inlining failed due to the size of BUS_*


# 118924 15-Aug-2003 njl

Fix a couple changes that were incorrect in updating for 0619. Only unlock
the hardware mutex if it is held. Re-add calls to Enable/Clear fixed events.

This is not known to have caused problems. Bug symptoms might have included
instability after an aborted suspend attempt or power/sleep buttons not
being enabled.


# 118642 08-Aug-2003 njl

Default to 5 seconds before sleeping to give some machines time to stabilize.
This doesn't break anything on my laptop and some claim it helps them.


# 117796 20-Jul-2003 njl

Clarify the ACPI shutdown messages.


# 117795 20-Jul-2003 njl

Add ECDT (ACPI 2.0) support. This allows the EC to be enabled before the
namespace has been evaluated. Machines with ACPI 2.0 expect this behavior
and have AML which calls EC functions early in the boot process. If the
ECDT is not available, fall back to original probe behavior.

Other minor changes:
* Add GPE bit and GLK usage to the device announcement
* Always use the global lock in the ECDT case, but potentially downgrade to
not using it if _GLK is 0 once the namespace is available. This is
announced with "Changing GLK from 1 to 0"
* Remove the acpi_object_list definitions which were earlier deprecated

Ideas from: takawata


# 117530 13-Jul-2003 njl

Update code to work with 0619 dist

* Use ACPI_BUFFER as the type for AcpiGetObjectInfo
* Remove AcpiEnableEvent/AcpiClearEvent for ACPI_EVENT_FIXED (power/sleep
buttons) as they are no longer needed
* Change calls to use the new GPE functions
* Add AcpiOs*Lock functions


# 117167 02-Jul-2003 jhb

- Use the new resource_disabled() helper function to see if devices are
disabled.
- Change the apm driver to match the acpi driver's behavior by checking to
see if the device is disabled in the identify routine instead of in the
probe routine. This way if the device is disabled it is never created.

Note that a few places (ips(4), Alpha SMP) used "disable" instead of
"disabled" for their hint names, and these hints must be changed to
"disabled". If this is a big problem, resource_disabled() can always be
changed to honor both names.


# 114442 01-May-2003 jhb

Catch up to reworked debugging levels in latest Intel import.


# 113366 11-Apr-2003 iwasaki

Add new sysctl MIB (hw.acpi.supported_sleep_state) to indicate
the list of supported sleep state.
This should help people understand what following message means.

acpi0: AcpiGetSleepTypeData failed - AE_NOT_FOUND

MFC after: 3 days


# 111948 06-Mar-2003 takawata

Add integer value of _CID handling.
If _CID is string, it will need more complicated
handling to distinguish bus other than ISA.

Submitted by: Paul Wankadia <junyer@gmx.net>


# 111815 03-Mar-2003 phk

Gigacommit to improve device-driver source compatibility between
branches:

Initialize struct cdevsw using C99 sparse initializtion and remove
all initializations to default values.

This patch is automatically generated and has been tested by compiling
LINT with all the fields in struct cdevsw in reverse order on alpha,
sparc64 and i386.

Approved by: re(scottl)


# 111750 02-Mar-2003 phk

Use canonical form for cdevsw initialization.


# 110894 15-Feb-2003 takawata

Allow non-privilaged user to retrive battery or AC line information.

Reviewed by: rwatson


# 108345 28-Dec-2002 rwatson

Change ACPI make_dev() calls to use UID_ and GID_ constants rather
than hard-coded uids and gids.

Switch the device to a group of wheel instead of operator.

Narrow down the permissions on the device to require root privilege
to manipulate the system power state. It may be that we can broaden
access to the device after review of the access control in ACPI.

Submitted by: kris
Reviewed by: takawata


# 107753 11-Dec-2002 takawata

Add sysctl knob to stop disabling acpi on shutdown.

Approved by: re(jhb)


# 107199 24-Nov-2002 iwasaki

Add `if (!cold)' checkings for functions which is called via SYSINIT.
Loading acpi.ko with kldload is disallowed, however some
functions were executed unexpectedly.

Approved by: re


# 106261 31-Oct-2002 iwasaki

Interpret new loader tunable "hw.acpi.verbose" to turn
verbose mode on at boot time.


# 106255 31-Oct-2002 iwasaki

Invoke 3 ACPI task threads as default if option ACPI_MAX_THREADS is
not defined.
To make previous default behavior (ACPI_MAX_THREADS undefined), define
option ACPI_MAX_THREADS as 0.


# 105282 16-Oct-2002 jhb

Catch up to changes in acpivar.h to add support for using ACPI on
4-stable systems.

Sponsored by: The Weather Channel


# 104727 09-Oct-2002 jhb

Use d_thread_t for cdevsw functions instead of struct thread * so that it
is easier to share this code with 4-stable.


# 104677 08-Oct-2002 jhb

Don't panic for a bad ivar request, just return ENOENT.


# 103022 06-Sep-2002 jhb

Attach ACPI children a bit later in attach(), specifically after performing
any machine dependent initialization. This allows the MD code to set the
interrupt routing model so that PCI interrupts are routed correctly when
using an APIC or SAPIC for example.


# 103015 06-Sep-2002 jhb

Add a helper routine acpi_SetIntrModel() to call the _PIC method to set
the interrupt model in use so that ACPI can properly route interrupts for
machines using APIC's or SAPIC's.


# 102918 04-Sep-2002 jhb

Use resource_list_print_types() instead of duplicating the code.


# 102612 30-Aug-2002 iwasaki

s/hint.acpi.0.disable/hint.acpi.0.disabled/

Fix device hints entry for disabling acpi(4).
This also should fix the arbitration with apm(4) when both drivers
are enabled.

Note that your /boot/device.hints needs to be updated if you want to
stop auto-loading acpi.ko or disable acpi(4).


# 102553 29-Aug-2002 iwasaki

Resolve conflicts arising from the ACPI CA 20020815 import.


# 102535 28-Aug-2002 iwasaki

Change default value of hw.acpi.sleep_delay to 0.
This caused problems (reset or lock up) at wakeup.


# 102402 25-Aug-2002 iwasaki

Add new sysctl MIB (hw.acpi.sleep_delay) to specify the delay (in
seconds) before ACPI sleep. Some machines might need this to sleep
by Hot-key.


# 101763 12-Aug-2002 imp

don't include redunant \n in panic message


# 100969 30-Jul-2002 iwasaki

Resolve conflicts arising from the ACPI CA 20020725 import.


# 100497 22-Jul-2002 iwasaki

Add device(power/sleep button and lid) wake function from sleeping state.
This is required for some Thinkpad (and maybe VAIO) machines to wake
the system up from sleep.

Currently partially implemented, more complete implementation will come later.


# 99682 09-Jul-2002 iwasaki

Resolve conflicts arising from the ACPI CA 20020611 import.


# 96947 19-May-2002 iwasaki

Terminate ACPI subsystem on reboot.
Some machines stuck on reboot if ACPI sleep/wakeup was executed.


# 96926 19-May-2002 peter

Brutally deal with __func__ being 'const char *' on gcc-3.1.


# 96277 09-May-2002 jhb

Fix acpi_avoid() to call freeenv() on the original char * returned from
getenv().

Reported by: joe
Tested by: joe


# 95384 24-Apr-2002 mux

Don't call freeenv() on a modified pointer.

Submitted by: Alexander Kabaev <ak03@gte.com>
Reviewed by: phk
Pointy hat to: mux


# 95081 19-Apr-2002 mike

Fix compiling of acpica when debugging is enabled. In the previous
revision, two getenv()s were accidentally changed to use testenv().

Pointy hat to: mux


# 94936 17-Apr-2002 mux

Rework the kernel environment subsystem. We now convert the static
environment needed at boot time to a dynamic subsystem when VM is
up. The dynamic kernel environment is protected by an sx lock.

This adds some new functions to manipulate the kernel environment :
freeenv(), setenv(), unsetenv() and testenv(). freeenv() has to be
called after every getenv() when you have finished using the string.
testenv() only tests if an environment variable is present, and
doesn't require a freeenv() call. setenv() and unsetenv() are self
explanatory.

The kenv(2) syscall exports these new functionalities to userland,
mainly for kenv(1).

Reviewed by: peter


# 94168 08-Apr-2002 takawata

Print DRQ resource in boot message.


# 93818 04-Apr-2002 jhb

Change callers of mtx_init() to pass in an appropriate lock type name. In
most cases NULL is passed, but in some cases such as network driver locks
(which use the MTX_NETWORK_LOCK macro) and UMA zone locks, a name is used.

Tested on: i386, alpha, sparc64


# 91120 23-Feb-2002 msmith

Match namespace cleanup changes in ACPI CA 20020217 update.
Use ACPI_SUCCESS/ACPI_FAILURE consistently.
The AcpiGetInto* interfaces are obsoleted by ACPI_ALLOCATE_BUFFER.

Add AcpiBatteryIsPresent helper to determine whether a battery device
is inserted.

Add ACPI_ALL_DRIVERS to the list of debug layers, now that we own the
namespace for this.

Pr:


# 89054 08-Jan-2002 msmith

Staticise devclasses and some unnecessarily global variables.


# 88420 22-Dec-2001 iwasaki

Add OS layer ACPI mutex and threading support.
- Temporary fix a bug of Intel ACPI CA core code.
- Add OS layer ACPI mutex support. This can be disabled by
specifying option ACPI_NO_SEMAPHORES.
- Add ACPI threading support. Now that we have a dedicate taskqueue for
ACPI tasks and more ACPI task threads can be created by specifying option
ACPI_MAX_THREADS.
- Change acpi_EvaluateIntoBuffer() behavior slightly to reuse given
caller's buffer unless AE_BUFFER_OVERFLOW occurs. Also CM battery's
evaluations were changed to use acpi_EvaluateIntoBuffer().
- Add new utility function acpi_ConvertBufferToInteger().
- Add simple locking for CM battery and temperature updating.
- Fix a minor problem on EC locking.
- Make the thermal zone polling rate to be changeable.
- Change minor things on AcpiOsSignal(); in ACPI_SIGNAL_FATAL case,
entering Debugger is easier to investigate the problem rather than panic.


# 87566 09-Dec-2001 iwasaki

Disable sleep requests for 5 sec after wakeup. This is needed for
some Toshiba and Thinkpad laptops.
Wakeup event is generated by power button or sleep button on some
laptops but this also generates SCI interrupt, and shutdown the system
as result. So this is introduced so that acpi driver ignore given
requests for certain period.


# 87134 30-Nov-2001 iwasaki

Add a couple of minor changes.
- set sc->acpi_s4bios to 1 by default for hibernation until
OS-initiated S4 transition is implemented.
- change the behavior of acpi_sleep_state_sysctl() if new value is
the same as old one, do nothing instead of EINVAL.


# 87055 28-Nov-2001 iwasaki

Yet another synch with minor changes in the ACPI CA 20011120 snapshot.
We need to call AcpiEnterSleepStatePrep() before AcpiEnterSleepState().


# 86802 23-Nov-2001 iwasaki

Validate requested sleep state in acpi_SetSleepState() to avoid reentry
during wakeup procedure.


# 86401 15-Nov-2001 iwasaki

Fix re-enabling ACPI on wakeup from hibernation. The problem was that
acpi_Disable() cleared all GPE events.
Some old ACPI implementaions still need current re-enabling code.


# 86398 15-Nov-2001 iwasaki

Remove "S4B" from sleep_state_names and add "NONE" instead.
Now you can say;
# sysctl hw.acpi.lid_switch_state=NONE
instead of specifying unsupported _Sx object in the system.

Actually, S4B is going to disappear in ACPICA and we already have
hw.acpi.s4bios to distinguish BIOS hibernation or OS hibernation.


# 86133 06-Nov-2001 iwasaki

Add S4BIOS sleep (BIOS hibernation) and DSDT overriding support.
- Add S4BIOS sleep implementation. This will works well if MIB
hw.acpi.s4bios is set (and of course BIOS supports it and hibernation
is enabled correctly).
- Add DSDT overriding support which is submitted by takawata originally.
If loader tunable acpi_dsdt_load="YES" and DSDT file is set to
acpi_dsdt_name (default DSDT file name is /boot/acpi_dsdt.aml),
ACPI CA core loads DSDT from given file rather than BIOS memory block.
DSDT file can be generated by iasl in ports/devel/acpicatools/.
- Add new files so that we can add our proposed additional code to Intel
ACPI CA into these files temporary. They will be removed when
similar code is added into ACPI CA officially.


# 86083 05-Nov-2001 iwasaki

Remove unnecessary WAK_STS bit waiting code for S1 sleep.
It was duplicated with AcpiEnterSleepState() since acpica-unix-20010816.


# 85835 01-Nov-2001 iwasaki

Some fix for the recent apm module changes.
- Now that apm loadable module can inform its existence to other kernel
components (e.g. i386/isa/clock.c:startrtclock()'s TCS hack).
- Exchange priority of SI_SUB_CPU and SI_SUB_KLD for above purpose.
- Add simple arbitration mechanism for APM vs. ACPI. This prevents
the kernel enables both of them.
- Remove obsolete `#ifdef DEV_APM' related code.
- Add abstracted interface for Powermanagement operations. Public apm(4)
functions, such as apm_suspend(), should be replaced new interfaces.
Currently only power_pm_suspend (successor of apm_suspend) is implemented.

Reviewed by: peter, arch@ and audit@


# 85699 29-Oct-2001 iwasaki

Some small improvements of ACPI thermal driver.
- Give a guaranteed minimum cooling run time to avoid too frequent
cooling system On/Off switching. The minimum cooling run time can be
specified by hw.acpi.thermal.min_runtime in sec.
- Refine message printing (_AC-1 -> NONE).
- Add verbose mode enable/disable capability by hw.acpi.verbose in bool.

Reviewed by: acpi-jp@ folks


# 85556 26-Oct-2001 iwasaki

Add APM compatibility feature to ACPI.
This emulates APM device node interface APIs (mainly ioctl) and
provides APM services for the applications. The goal is to support
most of APM applications without any changes.
Implemented ioctls in this commit are:
- APMIO_SUSPEND (mapped ACPI S3 as default but changable by sysctl)
- APMIO_STANDBY (mapped ACPI S1 as default but changable by sysctl)
- APMIO_GETINFO and APMIO_GETINFO_OLD
- APMIO_GETPWSTATUS

With above, many APM applications which get batteries, ac-line
info. and transition the system into suspend/standby mode (such as
wmapm, xbatt) should work with ACPI enabled kernel (if ACPI works well :-)

Reviewed by: arch@, audit@ and some guys


# 84500 04-Oct-2001 msmith

Update usage of AcpiEnableEvent to reflect a new argument.

Fix acpi_DeviceIsPresent to check for valid _STA data and to check
the "present" and "functioning" bits.

Use acpi_DeviceIsPresent in acpi_pcib rather than rolling our own
(also broken) version.


# 84444 04-Oct-2001 dfr

Check the compatible ID as well as the hardware ID in acpi_MatchHid.


# 83581 17-Sep-2001 iwasaki

Call acpi_DeviceIsPresent() only for devices. This should make
non-ACPI_TYPE_DEVICE devices (such as acpi_tz and acpi_cpu) enabled
again.

Reviewed by: msmith


# 83491 15-Sep-2001 msmith

Disable devices that are not present; at a later stage we can then enable
them if the device arrives.

This should solve the problem where devices that have been disabled eg. in
the BIOS show up with nonsense resources and hang the bootstrap process.


# 83366 12-Sep-2001 julian

KSE Milestone 2
Note ALL MODULES MUST BE RECOMPILED
make the kernel aware that there are smaller units of scheduling than the
process. (but only allow one thread per process at this time).
This is functionally equivalent to teh previousl -current except
that there is a thread associated with each process.

Sorry john! (your next MFC will be a doosie!)

Reviewed by: peter@freebsd.org, dillon@freebsd.org

X-MFC after: ha ha ha ha


# 83183 07-Sep-2001 msmith

Should check debug.acpi.avoid, not .disable.


# 83180 07-Sep-2001 msmith

Allow the ACPI subsystem to be disabled with a hint.

Avoid fully initialising the ACPI namespace if we are attempting to avoid
parts of it. This is a workaround for some systems that still crash
the interpreter.

Implement the ISA_IVAR_LOGICALID for ISA compatibility. Implement stubs
for other PnP ID-related ivars.


# 83169 06-Sep-2001 jhb

Add a hack to acpi_EvaluateInteger() to handle the case of a method
returning a Buffer that contains an Integer rather an an Integer directly.

Submitted by: msmith
Approved by: msmith


# 82779 02-Sep-2001 iwasaki

Fix typo; CTLFLAG_RO -> CTLFLAG_RD.


# 82765 01-Sep-2001 msmith

Add a MODULE_VERSION declaration. This should prevent duplicate loading
of the module, and allows other modules to depend on and link against
the ACPI module.

Add a sysctl that allows us to retrieve the ACPI CA version number as
well.


# 82630 31-Aug-2001 takawata

Call OS-independent resume routine to execute _WAK .. etc.
This should also recover GPE bit,comment says, though not implemented yet.


# 82537 30-Aug-2001 msmith

Add support for attaching PnP-aware ISA drivers to ACPI.

Always parse ACPI device resource settings (current resources only)
and attach the resources to the device before probe/attaching.


# 82372 26-Aug-2001 msmith

Updates to match the ACPI CA 20010816 import:

- New debug macro (ACPI_DEBUG_PRINT), reducing debug-case code size.
- New debug level/subsystem codes.


# 81092 03-Aug-2001 msmith

Move the resource pointer when we reallocate the buffer.

Submitted by: "neckpain@nettaxi.com" <neckpain@nettaxi.com>


# 80604 30-Jul-2001 msmith

- Prevent the ACPI code from being loaded as a module other than at
boot time. Loading as a module once the system is up and running
doesn't make any sense.

- Fix acpi_FindIndexedResource (it would only check the first resource),
changes the calling interface.

- Add a new helper function (acpi_AppendBufferResource) to help building
buffers containing resources.


# 80160 22-Jul-2001 iwasaki

Don't do sleep state transition if specified sleep state is not
supported by the system.


# 80078 21-Jul-2001 msmith

Convert from acpi_strerror() to AcpiFormatException()

Fix dangling include of the dear departed acpi_ecreg.h


# 80066 21-Jul-2001 msmith

The API for loading tables changed (we no longer explicitly search for the
RSDP, it's now found via a callback).

AcpiOsSleepUsec() went away, use AcpiOsSleep() instead (we could use
AcpiOsStall() too)

AcpiFormatException() was changed to make more sense (it behaves like
our old acpi_strerror() did), so throw acpi_strerror() away (still
#defined in acpivar.h though, we need to sweep these seperately).


# 80028 20-Jul-2001 takawata

Add ACPI S2-S4BIOS Suspend/Resume code.
Some problems may remain.

Reviewed by:iwasaki


# 79387 07-Jul-2001 msmith

Add acpi_GetTableIntoBuffer, to aid in fetching tables.


# 79282 05-Jul-2001 msmith

Add a new helper function for finding resources in resource buffers.

Move the ACPI generic battery code into a new file.


# 78991 29-Jun-2001 msmith

Update to synch with the 20010615 ACPI CA import.

Add an ACPI subsystem mutex, and macros for handling it. Because it's
not possible to differentiate between ACPI CA acquiring mutexes for
internal use and for use by AML, and because AML in the field doesn't
handle mutexes correctly, we can't use the ACPI subsystem's internal
locking. In addition, we have other private data of our own to lock.

Add initial locking to the ACPI driver code and the thermal module.
These locks are currently inoperative.

Pull some errant style back into line.


# 78915 28-Jun-2001 msmith

Sync to my work in progress:

- Reorder the acpi_* functions in a sensible fashion
- Add acpi_ForeachPackageObject and acpi_GetHandleInScope
- Use the new debugging layer/level names
- Implement most of the guts of the acpi_thermal module; passive cooling
isn't there yet, but active cooling should work.
- Implement power resource handling (acpi_powerres.c)

This compiles and mostly works, but my test coverage is small, so feedback
is welcome.


# 78689 24-Jun-2001 iwasaki

- Swap order of "S4B" and "S5" in sleep_state_names. They already
changed in ACPICA actypes.h.
- Use ACPI_S_STATES_MAX instead of ACPI_STATE_S5.


# 78662 23-Jun-2001 iwasaki

Add sysctl interface (Read-only) for temprature, AC-line and Battery.
Patches for acpi_cmbat.c submitted by Munehiro Matsuda.


# 77432 29-May-2001 msmith

- Updates for new constant naming in the ACPI CA 20010518 update.
- Use __func__ instead of __FUNCTION.
- Support power-off to S3 or S5 (takawata)
- Enable ACPI debugging earlier (with a sysinit)
- Fix a deadlock in the EC code (takawata)
- Improve arithmetic and reduce the risk of spurious wakeup in
AcpiOsSleep.
- Add AcpiOsGetThreadId.
- Simplify mutex code (still disabled).


# 76166 01-May-2001 markm

Undo part of the tangle of having sys/lock.h and sys/mutex.h included in
other "system" header files.

Also help the deprecation of lockmgr.h by making it a sub-include of
sys/lock.h and removing sys/lockmgr.h form kernel .c files.

Sort sys/*.h includes where possible in affected files.

OK'ed by: bde (with reservations)


# 75100 02-Apr-2001 jhb

Remove bogus block device major now that bdev majors are gone.


# 74914 28-Mar-2001 jhb

Catch up to header include changes:
- <sys/mutex.h> now requires <sys/systm.h>
- <sys/mutex.h> and <sys/sx.h> now require <sys/lock.h>


# 73962 07-Mar-2001 iwasaki

Bring our local hack for wakeup back from
sys/contrib/dev/acpica/Subsystem/Hardware/Attic/hwxface.c to the proper
location after AcpiEnterSleepState().

- Wait for the WAK_STS bit
- Evaluate the _WAK method and check result code


# 71872 31-Jan-2001 msmith

ACPI_NUMBER becomes ACPI_INTEGER. acpi_EvaluateNumber becomes
acpi_EvaluateInteger.

Use acpi_EvaluateInteger instead of doing things the hard way where
possible.

AcpiSetSystemSleepState (unofficial) becomes AcpiEnterSleepState.

Use the AcpiGbl_FADT pointer rather than searching for the FADT.


# 71001 13-Jan-2001 jhb

Add 3 new dynamic sysctl's to control the sleep states switched to on a
power button, sleep button, or lid close event. The sysctl's use the
ACPI sleep state names S0, S1, S2, S3, S4, S4B, and S5.

Reviewed by: iwasaki


# 70897 10-Jan-2001 iwasaki

Enable fixed event at not only boot but also wakeup.

Reported and patch tested by: Peter Dufault <dufault@hda.hda.com>


# 70340 24-Dec-2000 iwasaki

Add ioctls to acpi_cmbat and acpi_acad. These use mike's acpi_register_ioctl().
Fix wrong AML method calling in acpi_cmbat.


# 70194 19-Dec-2000 iwasaki

Fix testing reboot howto flags in acpi_shutdown_final().
This sould make the system power-off correctly where the howto had
more bits set than RB_POWEROFF, e.g. RB_NOSYNC.

Submitted by: Peter Pentchev <roam@orbitel.bg>


# 69910 12-Dec-2000 iwasaki

Catch up with the recent conversion the per-eventhandler list mutex to
a lockmgr lock.


# 69744 08-Dec-2000 msmith

- Convert a lot of homebrew debugging output to use the ACPI CA debugging
infrastructure. It's not perfect, but it's a lot better than what
we've been using so far. The following rules apply to this:
o BSD component names should be capitalised
o Layer names should be taken from the non-CA set for now. We
may elect to add some new BSD-specific layers later.

- Make it possible to turn off selective debugging flags or layers
by listing them in debug.acpi.layer or debug.acpi.level prefixed
with !.

- Fully implement support for avoiding nodes in the ACPI namespace.
Nodes may be listed in the debug.acpi.avoid environment variable;
these nodes and all their children will be ignored (although still
scanned over) by ACPI functions which scan the namespace. Multiple
nodes can be specified, separated by whitespace.

- Implement support for selectively disabling ACPI subsystem components
via the debug.acpi.disable environment variable. The following
components can be disabled:
o bus creation/scanning of the ACPI 'bus'
o children attachment of children to the ACPI 'bus'
o button the acpi_button control-method button driver
o ec the acpi_ec embedded-controller driver
o isa acpi replacement of PnP BIOS for ISA device discovery
o lid the control-method lid switch driver
o pci pci root-bus discovery
o processor CPU power/speed management
o thermal system temperature detection and control
o timer ACPI timecounter
Multiple components may be disabled by specifying their name(s)
separated by whitespace.

- Add support for ioctl registration. ACPI subsystem components may
register ioctl handlers with the /dev/acpi generic ioctl handler,
allowing us to avoid the need for a multitude of /dev/acpi* control
devices, etc.


# 69585 05-Dec-2000 msmith

ACPI HID's aren't limited to 7 characters. Don't check the length of the
HID passed in as an argument at all; callers are typically going to be
sending us static strings anyway.

Submitted by: Munehiro Matsuda <haro@tk.kubota.co.jp>


# 69458 01-Dec-2000 msmith

Update to work with the new ACPI CA snapshot.

- Use ACPI_PHYSICAL_ADDRESS
- RSDT -> XSDT
- FACP -> FADT
- No APIC table support
- Don't install a global EC handler; this has bad side-effects
(it invokes _REG in *all* EC spaces in the namespace!)
- Check for PCI bus instances already existing before adding them


# 68406 06-Nov-2000 msmith

Remove unused PCI includes.


# 68067 31-Oct-2000 takawata

If acpica driver is loaded using kldload(8), warn and just ignore.


# 67761 28-Oct-2000 msmith

Initial FreeBSD OSPM (operating system power management) modules for
ACPICA. Most of these are still works in progress. Support exists for:

- Fixed feature and control method power, lid and sleep buttons.
- Detection of ISA PnP devices using ACPI namespace.
- Detection of PCI root busses using ACPI namespace.
- CPU throttling and sleep states (incomplete)
- Thermal monitoring and cooling control (incomplete)
- Interface to platform embedded controllers (mostly complete)
- ACPI timer (incomplete)
- Simple userland control of sleep states.
- Shutdown and poweroff.