Commit Graph

1161 Commits

Author SHA1 Message Date
Matthew D Fleming
6e6d95d1b9 Correctly output the entire array for hw.acpi.thermal._ACx.
Reported by:	Taku YAMAMOTO < taku AT tackymt DOT homeip DOT net >
Tested by:	Nick Ulen < uncle AT wolfman DOT devio DOT us >
2011-04-19 20:44:43 +00:00
Jung-uk Kim
6af444b118 Do not assume PM timer GAS type is I/O or memory. It may be an unsupported
type, i. e., a broken table.  Also, do not hardcode ACPI timer frequency in
device description.
2011-04-18 23:12:41 +00:00
Matthew D Fleming
8db47cc0d4 Fix a few acpi sysctls that want "IK" formatting to specify CTLTYPE_INT.
This got broken after r217586.

Pointy hat:	to me
Tested by:	David Wolfskill < davit AT catwhisker DOT org >
2011-04-18 19:02:41 +00:00
Jung-uk Kim
4a8fa6fe58 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.
2011-04-14 22:17:39 +00:00
Jung-uk Kim
5331d61da4 Add some tunable descriptions about x86 timers.
Requested by:	arundel
2011-04-14 00:07:08 +00:00
Jung-uk Kim
3453537fa5 Use atomic load & store for TSC frequency. It may be overkill for amd64 but
safer for i386 because it can be easily over 4 GHz now.  More worse, it can
be easily changed by user with 'machdep.tsc_freq' tunable (directly) or
cpufreq(4) (indirectly).  Note it is intentionally not used in performance
critical paths to avoid performance regression (but we should, in theory).
Alternatively, we may add "virtual TSC" with lower frequency if maximum
frequency overflows 32 bits (and ignore possible incoherency as we do now).
2011-04-07 23:28:28 +00:00
Jung-uk Kim
9abd8cd05b Lower the bar for ACPI-fast on real machines slightly. Empirical evidences
show that there are perfectly working PM timers with occasional "hiccups",
probably because of an SMI.  Now we ignore the maximum if it happens once in
the test loop and the width is small enough.  Also, relax normal width a bit
to count in a boundary case.
2011-04-05 18:40:19 +00:00
Jung-uk Kim
059e24646a Move a trivial acpi_TimerDelta() to acpivar.h to make it inlineable. 2011-04-04 18:39:04 +00:00
Jung-uk Kim
aa977fc70e Always check the current minimum value to make the test more predictable.
Use INT32_MAX instead of an arbitrary big number for the initial minimum.
2011-04-04 17:44:26 +00:00
Jung-uk Kim
8defd647f2 Fix bogus logic to calculate delta between two values from ACPI timers. 2011-04-04 17:30:33 +00:00
Jung-uk Kim
d141bf6e2f Lower the bar for ACPI-fast on virtual machines. The current logic depends
on the fact that real hardware has almost fixed cost to read the ACPI timer.
It is virtually always false for hardware emulation and it makes no sense to
read it multiple times, which is already quite expensive for full emulation.
2011-04-04 17:00:50 +00:00
Jung-uk Kim
93bd1f7e31 Add inline to acpi_timer_read() to reduce unnecessary jumps and calls. 2011-04-04 16:47:42 +00:00
Jung-uk Kim
9fae4b2a8c Add more definitions for vendor-specific CPU capability bits to the last
revision, which is renamed to "Intel Processor Vendor-Specific ACPI".
2011-02-25 18:29:57 +00:00
Jung-uk Kim
f6c05906ee Rework r218685. Copy just enough data for the resource type.
Reviewed by:	jhb, mdf
2011-02-14 20:05:37 +00:00
Matthew D Fleming
224e25e117 Prevent reading from the ACPI_RESOURCE past its actual end. For
paranoia limit to the size of the ACPI_RESOURCE as well.

Reviewd by:	jhb (in spirit)
MFC after:	1 week
2011-02-14 17:20:20 +00:00
Marcel Moolenaar
efdb11cd58 Use the preload_fetch_addr() and preload_fetch_size() convenience
functions to obtain the address and size of the overriding DSDT.

Sponsored by: Juniper Networks.
2011-02-13 19:24:04 +00:00
Matthew D Fleming
f4f04709ac Fix a few more SYSCTL_PROC() that were missing a CTLFLAG type specifier. 2011-01-19 00:57:58 +00:00
John Baldwin
4a26285ea1 Remove bogus check. pcib_get_bus() (like other BUS_ACCESSOR() methods)
doesn't "fail", it may merely return garbage if it is not a valid ivar
for a given device.  Our parent device must be a 'pcib' device, so we
can just assume it implements pcib IVARs, and all pcib devices have a
bus number.

Submitted by:	clang via rdivacky
2011-01-18 14:58:44 +00:00
Jung-uk Kim
b5854f5f59 Work around a witness(4) panic introduced in r217238.
Reported by:	jh
2011-01-11 19:26:39 +00:00
Jung-uk Kim
5947a0a3c8 Fix a witness(4) warning introduced in r217238. 2011-01-11 19:20:01 +00:00
Jung-uk Kim
ea5bef4942 Remove impossible error conditions. 2011-01-10 21:09:38 +00:00
Jung-uk Kim
bd532602ec Add forgotten free(9) in the previous commit for an error case. 2011-01-10 21:01:41 +00:00
Jung-uk Kim
82bf55575d Allow AcpiOsInstallInterruptHandler() and AcpiOsRemoveInterruptHandler() to
install or remove non-SCI interrupt handlers per ACPI Component Architecture
User Guide and Programmer Reference.  ACPICA may install such interrupt
handler when a GPE block device is found, for example.  Add a wrapper for
ACPI_OSD_HANDLER, convert its return values to ours, and make it a filter.
Prefer KASSERT(9) over panic(9) as we have never seen those in reality.
Clean up some style(9) nits and add my copyright.
2011-01-10 20:56:59 +00:00
Jung-uk Kim
b839a7f44b Prefer KASSERT(9) over panic(9) as it was never seen in reality. 2011-01-10 20:26:36 +00:00
Jung-uk Kim
000d939024 Clarify the previous commit. AcpiFinishGpe() will not clear GPE for us
because we set it to edge-trigger.
2011-01-04 17:06:03 +00:00
Jung-uk Kim
5568050d57 Clear GPE from a query handler if the task was deferred. 2011-01-04 00:10:29 +00:00
Jung-uk Kim
80b1151e82 Fix parameters for wakeup(9) and tsleep(9).
MFC after:	3 days
2011-01-03 23:37:42 +00:00
John Baldwin
0d81cf1227 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
2010-12-23 18:50:14 +00:00
John Baldwin
ea23319939 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.
2010-12-22 20:27:20 +00:00
Andriy Gapon
766d7e6539 small cleanup of acpi battery status setting and checking
This is based on the patch submitted by Yuri Skripachov.
Overview of the changes:
- clarify double-use of some ACPI_BATT_STAT_* definitions
- clean up undefined/extended status bits returned by _BST
- warn about charging+discharging bits being set at the same time

PR:		kern/124744
Submitted by:	Yuri Skripachov <y.skripachov@gmail.com>
Tested by:	Yuri Skripachov <y.skripachov@gmail.com>
MFC after:	2 weeks
2010-12-17 16:21:30 +00:00
John Baldwin
686b1e6bc0 Small style fixes:
- Avoid side-effect assignments in if statements when possible.
- Don't use ! to check for NULL pointers, explicitly check against NULL.
- Explicitly check error return values against 0.
- Don't use INTR_MPSAFE for interrupt handlers with only filters as it is
  meaningless.
- Remove unneeded function casts.
2010-12-16 17:05:28 +00:00
John Baldwin
5e66b8e231 Spelling fix. 2010-12-16 16:55:22 +00:00
Jung-uk Kim
5a77b11bd3 Merge ACPICA 20101209. 2010-12-15 23:48:45 +00:00
Jung-uk Kim
e1c9d39ebe Stop lying about supporting cpu_est_clockrate() when TSC is invariant. This
function always returned the nominal frequency instead of current frequency
because we use RDTSC instruction to calculate difference in CPU ticks, which
is supposedly constant for the case.  Now we support cpu_get_nominal_mhz()
for the case, instead.  Note it should be just enough for most usage cases
because cpu_est_clockrate() is often times abused to find maximum frequency
of the processor.
2010-12-14 20:07:51 +00:00
John Baldwin
4a588c1ba7 Use proper resource ID's for HPET IRQ resources. This mostly consists of
looking to see if there is an existing IRQ resource for a given IRQ
provided by the BIOS and using that RID if so.  Otherwise, allocate a new
RID for the new IRQ.

Reviewed by:	mav (a while ago)
2010-12-07 18:49:11 +00:00
John Baldwin
d2014f5180 Various small typos and grammar nits in comments. 2010-11-18 22:17:20 +00:00
Jung-uk Kim
68d5e11c9f Create C1 state when _CST is valid but _CST does not have one. Some BIOSes
do not report C1 state in _CST object, probably because it is a mandatory
state with or without existence of the optional _CST.

Reviewed by:	avg
2010-11-12 17:10:12 +00:00
Jung-uk Kim
93a8847473 Make APM emulation look more closer to its origin. Use device_get_softc(9)
instead of hardcoding acpi(4) unit number as we have device_t for it.
2010-11-10 18:50:12 +00:00
Jung-uk Kim
7c2bf852d7 Refactor acpi_machdep.c for amd64 and i386, move APM emulation into a new
file acpi_apm.c, and place it on sys/x86/acpica.
2010-11-10 01:29:56 +00:00
Jung-uk Kim
affa18265a Consistently use padding `_' in the comment. 2010-11-08 19:52:14 +00:00
Jung-uk Kim
e7bb9ab605 Add a forgotten change from the previous commit. 2010-11-05 20:24:26 +00:00
Jung-uk Kim
9fe3e6c023 Fix a use-after-free bug for extended IRQ resource[1]. When _PRS buffer is
copied as a template for _SRS, a string pointer for descriptor name is also
copied and it becomes stale as soon as it gets de-allocated[2].  Now _CRS is
used as a template for _SRS as ACPI specification suggests if it is usable.
The template from _PRS is still utilized but only when _CRS is not available
or broken.  To avoid use-after-free the problem in this case, however, only
mandatory fields are copied, optional data is removed, and structure length
is adjusted accordingly.

Reported by:	hps[1]
Analyzed by:	avg[2]
Tested by:	hps
2010-11-05 19:50:09 +00:00
Jung-uk Kim
495a414454 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.
2010-11-03 23:16:35 +00:00
Jung-uk Kim
ae19af49e0 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"
2010-10-26 18:59:50 +00:00
Jung-uk Kim
f3e0b10973 Introduce a new tunable 'hw.pci.do_power_suspend'. This tunable lets you
avoid PCI power state transition from D0 to D3 for suspending case.  Default
is 1 or enabled.
2010-10-20 16:47:09 +00:00
Jung-uk Kim
220666153d 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.
2010-10-19 20:38:21 +00:00
Jung-uk Kim
a7a3177f27 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)
2010-10-19 19:53:06 +00:00
Jung-uk Kim
edc0cb7dc8 Make any PCI devices enumerated in ACPI tree honor do_power_resume as well. 2010-10-19 18:43:11 +00:00
Jung-uk Kim
1debbf5d79 Clean up unused headers. 2010-10-13 17:06:25 +00:00
Jung-uk Kim
e41724b279 Remove acpi_bus_number() completely. It had to be removed in r212761.
Pointed out by:	jhb
2010-10-13 16:30:41 +00:00
Rui Paulo
1d90e6b224 Mark acpi_bus_number() as __unused. This allows clang to this file
without any warnings.
2010-10-13 11:38:24 +00:00
Jung-uk Kim
ac731af567 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).
2010-10-13 00:21:53 +00:00
Andriy Gapon
5ff14fa9b4 acpi_ec: changes in communication with hardware
Short description of the changes:
- attempt to retry some commands for which it is possible (read, query)
- always make a short sleep before checking EC status in polled mode
- periodically poll EC status in interrupt mode
- change logic for detecting broken interrupt delivery and falling back
  to polled mode
- check that EC is ready for input before starting a new command, wait
  if necessary

This commit is based on the original patch by David Naylor.

PR:		kern/150517
Submitted by:	David Naylor <naylor.b.david@gmail.com>
Reviewed by:	jkim
MFC after:	3 weeks
2010-10-12 17:53:01 +00:00
Alexander Motin
3a2c9a26b5 Do not use regular interrupts on NVidia HPETs. NVidia MCP5x chipsets have
number of unexplained interrupt problems. For some reason, using HPET
interrupts there breaks HDA sound. Legacy route mode interrupts reported
to work fine there.
2010-09-30 16:23:01 +00:00
Alexander Motin
48fe2e6719 Quick fix for unmotivated C2 state usage during boot, introduced at r212541.
That caused LAPIC timer failure and huge delays during boot on some systems.
2010-09-22 11:32:22 +00:00
Andriy Gapon
9c2d052943 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
2010-09-22 06:10:22 +00:00
Jung-uk Kim
42fecd1294 Merge ACPICA 20100915. 2010-09-16 20:08:00 +00:00
Andriy Gapon
09c22c66e1 acpi_cpu: do not apply P_LVLx_LAT rules to latencies returned by _CST
ACPI specification sates that if P_LVL2_LAT > 100, then a system doesn't
support C2; if P_LVL3_LAT > 1000, then C3 is not supported.
But there are no such rules for Cx state data returned by _CST.  If a
state is not supported it should not be included into the return
package.  In other words, any latency value returned by _CST is valid,
it's up to the OS and/or user to decide whether to use it.

Submitted by:	nork
Suggested by:	mav
MFC after:	1 week
2010-09-13 09:51:24 +00:00
Alexander Motin
a157e42516 Refactor timer management code with priority to one-shot operation mode.
The main goal of this is to generate timer interrupts only when there is
some work to do. When CPU is busy interrupts are generating at full rate
of hz + stathz to fullfill scheduler and timekeeping requirements. But
when CPU is idle, only minimum set of interrupts (down to 8 interrupts per
second per CPU now), needed to handle scheduled callouts is executed.
This allows significantly increase idle CPU sleep time, increasing effect
of static power-saving technologies. Also it should reduce host CPU load
on virtualized systems, when guest system is idle.

There is set of tunables, also available as writable sysctls, allowing to
control wanted event timer subsystem behavior:
  kern.eventtimer.timer - allows to choose event timer hardware to use.
On x86 there is up to 4 different kinds of timers. Depending on whether
chosen timer is per-CPU, behavior of other options slightly differs.
  kern.eventtimer.periodic - allows to choose periodic and one-shot
operation mode. In periodic mode, current timer hardware taken as the only
source of time for time events. This mode is quite alike to previous kernel
behavior. One-shot mode instead uses currently selected time counter
hardware to schedule all needed events one by one and program timer to
generate interrupt exactly in specified time. Default value depends of
chosen timer capabilities, but one-shot mode is preferred, until other is
forced by user or hardware.
  kern.eventtimer.singlemul - in periodic mode specifies how much times
higher timer frequency should be, to not strictly alias hardclock() and
statclock() events. Default values are 2 and 4, but could be reduced to 1
if extra interrupts are unwanted.
  kern.eventtimer.idletick - makes each CPU to receive every timer interrupt
independently of whether they busy or not. By default this options is
disabled. If chosen timer is per-CPU and runs in periodic mode, this option
has no effect - all interrupts are generating.

As soon as this patch modifies cpu_idle() on some platforms, I have also
refactored one on x86. Now it makes use of MONITOR/MWAIT instrunctions
(if supported) under high sleep/wakeup rate, as fast alternative to other
methods. It allows SMP scheduler to wake up sleeping CPUs much faster
without using IPI, significantly increasing performance on some highly
task-switching loads.

Tested by:	many (on i386, amd64, sparc64 and powerc)
H/W donated by:	Gheorghe Ardelean
Sponsored by:	iXsystems, Inc.
2010-09-13 07:25:35 +00:00
Alexander Motin
373d257ef0 Add tunable 'hint.hpet.X.per_cpu' to specify how much per-CPU timers driver
should provide if there is sufficient hardware. Default is 1.
2010-09-13 06:32:56 +00:00
Alexander Motin
6184f8d60e Instead of storing last event timestamp, store the next event timestamp.
It corrects handling of the first event offset in emulated periodic mode.
2010-09-12 11:11:53 +00:00
Andriy Gapon
3d844eddb7 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
2010-09-10 11:19:03 +00:00
Alexander Motin
b28fc1b5c8 During SMP startup there is time window, when SMP started, but interrupts
are still bound to BSP. It confuses timer management logic in per-CPU mode
and may cause timer not being reloaded. Check such cases on interrupt
arival and reload timer to give system some more time to manage proper
binding.
2010-09-08 16:59:22 +00:00
Alexander Motin
09538b1020 Several improvements to HPET driver:
- Add special check for case when time expires before being programmed.
This fixes interrupt loss and respectively timer death on attempt to
program very short interval. Increase minimal supported period to more
realistic value.
 - Add support for hint.hpet.X.allowed_irqs tunable, allowing manually
specify which interrupts driver allowed to use. Unluckily, many BIOSes
program wrong allowed interrupts mask, so driver tries to stay on safe
side by not using unshareable ISA IRQs. This option gives control over
this limitation, allowing more per-CPU timers to be provided, when FSB
interrupts are not supported. Value of this tunable is bitmask.
 - Do not use regular interrupts on virtual machines. QEMU and VirtualBox
do not support them properly, that may cause problems. Stay safe by default.
Same time both QEMU and VirtualBox work fine in legacy_route mode.
VirtualBox also works fine if manually specify allowed ISA IRQs with above.
2010-09-05 19:24:32 +00:00
Andriy Gapon
b1f9b9965b 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
2010-09-03 08:07:04 +00:00
John Baldwin
62508c531e 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
2010-08-17 15:44:52 +00:00
Jung-uk Kim
34622ff1ab When EC burst mode is activated and multiple bytes are accessed, do not
disable and enable repeatedly, just do it once per call.  It also reduces
code duplication.  Check all parameters early and fail immediately.
2010-08-06 23:35:33 +00:00
Jung-uk Kim
709fac0616 Merge ACPICA 20100806. 2010-08-06 23:11:19 +00:00
John Baldwin
7d23a9b3d5 - Retire acpi_pcib_resume(). It is has just been an alias for
bus_generic_resume() since the pci_link(4) driver was added.
- Change the ACPI PCI-PCI bridge driver to inherit most of its methods
  from the generic PCI-PCI bridge driver.  In particular, this will now
  restore PCI config registers for ACPI PCI-PCI bridges.

Tested by:	Oleg Sharoyko  osharoiko of gmail
2010-08-05 16:10:12 +00:00
Alexander Motin
599cf0f197 Fix several un-/signedness bugs of r210290 and r210293. Add one more check. 2010-07-20 15:48:29 +00:00
Alexander Motin
51636352b6 Extend timer driver API to report also minimal and maximal supported period
lengths. Make MI wrapper code to validate periods in request. Make kernel
clock management code to honor these hardware limitations while choosing hz,
stathz and profhz values.
2010-07-20 10:58:56 +00:00
Jung-uk Kim
69496408a5 Simplify AcpiOsReadPort() and AcpiOsWritePort() with iodev_read_*() and
iodev_write_*().  This removes unnecessary uses of temporary macros as well.
There is no functional change after this (verified with md5(1) on amd64).
2010-07-16 04:27:38 +00:00
Jung-uk Kim
aa353b1b6b Use pmap_mapdev()/pmap_unmapdev() to map device memory instead of using
AcpiOsMapMemory()/AcpiOsUnmapMemory() (-> pmap_mapbios()/pmap_unmapbios())
for AcpiOsReadMemory() and AcpiOsWriteMemory().  Although they do not sound
too obvious, these functions are exclusively used to access memory mapped
IO in ACPICA.
2010-07-16 03:59:50 +00:00
Jung-uk Kim
337744d9a6 If there is any pending sleep request, disallow entering S5 state.
Otherwise, bad things may happen. ;-)
2010-07-15 23:24:06 +00:00
Jung-uk Kim
6e7661023a - AcpiOsReadPciConfiguration() needs similar fixes as r209965 and r210129.
According to ACPICA User Guide and Programmer Reference, the read data must
be zero extended to fill the 64-bit return value even if the bit width of
the location is less than 64.
- Return error when 64-bit access is requested as we do not support 64-bit
PCI register access (yet).  XXX We may have to split it up into two 32-bit
accesses if it is really required.
2010-07-15 19:52:54 +00:00
Jung-uk Kim
89339b38d8 - AcpiOsReadMemory() needs similar fixes as r209965. [1]
According to ACPICA User Guide and Programmer Reference, the read data must
be zero extended to fill the 32-bit return value even if the bit width of
the port is less than 32.
- Remove 64-bit read/write from AcpiOsReadMemory() and AcpiOsWriteMemory().
These functions do not support 64-bit access (yet).  Clean up style nits
and unnecessary bit masking while I am here.

Reported by:	Liu, Jinsong (jinsong dot liu at intel dot com) via
		Lin Ming (ming dot m dot lin at intel dot com) [1]
2010-07-15 17:11:49 +00:00
Jung-uk Kim
36a483bbcd Make SMP code path conditional at run-time. 2010-07-13 16:35:41 +00:00
Alexander Motin
8a6870808d Rise knowledge about curthread->td_intr_frame by one step. Make timer
callback argument really opaque. Not repeat interrupt handler's problem
in case somebody will ever need to have both argument and frame.
2010-07-13 12:46:06 +00:00
Jung-uk Kim
31bc79db46 Fix white spaces. 2010-07-13 02:48:42 +00:00
Jung-uk Kim
502e578cde According to ACPICA User Guide and Programmer Reference, the read data must
be zero extended to fill the 32-bit return value even if the bit width of
the port is less than 32.
2010-07-13 02:45:44 +00:00
Jung-uk Kim
3664686221 Fix mis-merges in the previous commit. 2010-07-06 21:41:08 +00:00
Jung-uk Kim
a88e22b7ad Merge ACPICA 20100702. 2010-07-06 20:57:28 +00:00
Alexander Motin
49ed68bbf3 Add "legacy route" support to HPET driver. When enabled, this mode makes
HPET to steal IRQ0 from i8254 and IRQ8 from RTC timers. It can be suitable
for HPETs without FSB interrupts support, as it gives them two unshared
IRQs. It allows them to provide one per-CPU event timer on dual-CPU system,
that should be suitable for further tickless kernels.

To enable it, such lines may be added to /boot/loader.conf:
hint.atrtc.0.clock=0
hint.attimer.0.clock=0
hint.hpet.0.legacy_route=1
2010-06-22 19:42:27 +00:00
Alexander Motin
e723056a58 Do not set level-triggered interrupt mode if we are not going to use it.
This fixes QEMU crash due to unsupported level-triggered HPET interrupts.

Reported by:	kib@
2010-06-22 16:10:48 +00:00
Alexander Motin
7ea5021353 Fix ia64 build broken by r209371.
ia64, same as amd64 has ACPI and always has APIC.

Submitted by:	jhb@
2010-06-21 20:27:32 +00:00
Alexander Motin
875b8844be Implement new event timers infrastructure. It provides unified APIs for
writing event timer drivers, for choosing best possible drivers by machine
independent code and for operating them to supply kernel with hardclock(),
statclock() and profclock() events in unified fashion on various hardware.

Infrastructure provides support for both per-CPU (independent for every CPU
core) and global timers in periodic and one-shot modes. MI management code
at this moment uses only periodic mode, but one-shot mode use planned for
later, as part of tickless kernel project.

For this moment infrastructure used on i386 and amd64 architectures. Other
archs are welcome to follow, while their current operation should not be
affected.

This patch updates existing drivers (i8254, RTC and LAPIC) for the new
order, and adds event timers support into the HPET driver. These drivers
have different capabilities:
 LAPIC - per-CPU timer, supports periodic and one-shot operation, may
freeze in C3 state, calibrated on first use, so may be not exactly precise.
 HPET - depending on hardware can work as per-CPU or global, supports
periodic and one-shot operation, usually provides several event timers.
 i8254 - global, limited to periodic mode, because same hardware used also
as time counter.
 RTC - global, supports only periodic mode, set of frequencies in Hz
limited by powers of 2.

Depending on hardware capabilities, drivers preferred in following orders,
either LAPIC, HPETs, i8254, RTC or HPETs, LAPIC, i8254, RTC.
User may explicitly specify wanted timers via loader tunables or sysctls:
kern.eventtimer.timer1 and kern.eventtimer.timer2.
If requested driver is unavailable or unoperational, system will try to
replace it. If no more timers available or "NONE" specified for second,
system will operate using only one timer, multiplying it's frequency by few
times and uing respective dividers to honor hz, stathz and profhz values,
set during initial setup.
2010-06-20 21:33:29 +00:00
Alexander Motin
3a18e1b6d7 Oops! Add " / hz" missed in r209328. Assume interrupt rate hz/2, not 1/2. 2010-06-19 08:46:17 +00:00
Alexander Motin
7150e67191 While we indeed can't precisely measure time spent in C1, we can consider
measured interval as upper bound. It should be more precise then just
assuming hz/2. For idle CPU it should be quite precise, for busy - not
worse then before.
2010-06-19 08:36:12 +00:00
John Baldwin
42040ff081 When updating individual CPU's lowest Cx state to use, never set it to a
state lower than the lowest one supported by the current CPU.  This closes
some races with changes to the hw.acpi.cpu_cx_lowest sysctl while Cx
states for individual CPUs were changing (e.g. unplugging the AC adapter
of a laptop) that could result in panics.

Submitted by:	Giovanni Trematerra
Tested by:	David Demelier  demelier dot david of gmail
MFC after:	3 days
2010-06-15 19:14:39 +00:00
Jung-uk Kim
2e1bf57ca8 Simplify a function for getting brightness levels. 2010-06-11 19:58:41 +00:00
Jung-uk Kim
30363a9a9e Remove unused assignment.
Found by:	clang static analyzer
Found by:	Coverity Prevent[tm] (CID 4537, 4538, 4539)
2010-06-11 19:53:42 +00:00
Andriy Gapon
1bdfff2252 fix a few cases where a string is passed via format argument instead of
via %s

Most of the cases looked harmless, but this is done for the sake of
correctness.  In one case it even allowed to drop an intermediate buffer.

Found by:	clang
MFC after:	2 week
2010-06-11 19:27:21 +00:00
John Baldwin
3aa6d94e0c Update several places that iterate over CPUs to use CPU_FOREACH(). 2010-06-11 18:46:34 +00:00
John Baldwin
374d9c4d18 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
2010-06-08 21:27:05 +00:00
Jung-uk Kim
e115a49ff3 Remove unnecessary pointer type castings, shift operations and dead code. 2010-06-01 21:15:05 +00:00
Alexander Motin
b169c85e20 Oops, HPET ID optionally stored in _UID, not in _ADR. 2010-05-23 08:31:15 +00:00
Alexander Motin
3c4c08dce7 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.
2010-05-23 07:53:22 +00:00
Jung-uk Kim
3f5e024c14 Merge ACPICA 20100428. 2010-04-28 22:25:27 +00:00
Jung-uk Kim
8c8be05f00 Merge ACPICA 20100331 (and four additional upstream patches). 2010-04-02 23:04:31 +00:00
Jung-uk Kim
9c98a9acdd Fix white spaces. 2010-03-10 18:30:55 +00:00
Jung-uk Kim
2a18c71d03 - 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.
2010-03-09 19:02:02 +00:00
Jung-uk Kim
ca3cf4fa2c Merge ACPICA 20100304. 2010-03-05 21:39:16 +00:00
Jung-uk Kim
463537a097 Rename some macros to clarify their intentions and fix style nits. 2010-02-15 20:46:01 +00:00
Jung-uk Kim
aba311e1d4 Add support for cycle' and zero' events for LCD brightness control.
Submitted by:	Daniel Walter (d dot walter at 0x90 dot at) (intial version)
2010-02-15 19:30:28 +00:00
Jung-uk Kim
f29d6f75fa Make sanity check slightly more useful and tweak an error message. 2010-02-13 05:38:21 +00:00
Jung-uk Kim
35dd1ef75c Implement LCD brightness control notify handler.
Submitted by:	Daniel Walter(d dot walter at 0x90 dot at) (intial version)
2010-02-13 02:24:23 +00:00
Andriy Gapon
0430ba9e55 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
2010-02-11 18:24:00 +00:00
Andriy Gapon
aa83516001 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
2010-02-11 08:50:21 +00:00
Andriy Gapon
f4ab0cccce acpi_cpu: prefer _OSC over _PDC, just in case
_PDC was deprecated in favor of _OSC long time ago, but it
seems that they still peacefully coexist and in some case
only _PDC is present.
Still _OSC provides a reacher interface and is capable to
report back its status.
If the status is non-zero, then report it, we may find
it useful to understand what firmware expects from OS.
Also clean up some comments that became less useful over time.

Reviewed by:	njl, jhb, rpaulo
MFC after:	3 weeks
2010-02-06 12:48:06 +00:00
Andriy Gapon
877a6d9994 acpi_cpu: correct capabilities arguments for Processor _OSC evaluation
Populate capabilities buffer according to
Intel Processor Vendor-Specific ACPI Interface Specification.

MFC after:	2 weeks
2010-02-03 14:35:33 +00:00
Andriy Gapon
9a6a6ecb3a acpi_hpet: correctly get number of timers/comparators in a timer block
Also, account for a quirk of AMD/ATI HPET which reports number of timers
instead of id of the last timer as manadated by the specification.
Currently this has no effect on functionality but in the future we may
make actual use of the HPET timers, not only of its timecounter.

MFC after:	2 weeks
2010-01-27 10:17:28 +00:00
Jung-uk Kim
9a179dd8be Merge ACPICA 20100121. 2010-01-21 21:14:28 +00:00
Andriy Gapon
bfd1961beb acpi_ec: remove redundant acpi_disabled check in probe method
MFC after:	4 days
2010-01-18 11:33:58 +00:00
Andriy Gapon
943124d3f0 acpi_ec: clean up 'private' ivar when freeing memory to which it points
This is not only a prudent thing to do, but also makes sure that probe
method is not confused by non-NULL 'private', if the previous attach
attempt fails for any reason.

PR:		kern/142561
Tested by:	Alex Goncharov <alex-goncharov@comcast.net>
MFC after:	4 days
2010-01-18 10:30:11 +00:00
Jung-uk Kim
2272d05019 Merge ACPICA 20091112. 2009-11-16 21:47:12 +00:00
Andriy Gapon
f6eb382c79 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
2009-11-07 11:46:38 +00:00
John Baldwin
146672474f Do not hold the ACPI A/C adapter lock when changing the power profile.
MFC after:	2 weeks
2009-09-30 17:07:49 +00:00
John Baldwin
0032eb1acb Split the 'video' ACPI lock up into two locks to resolve a LOR with the
sysctl lock.  The 'video' lock now protects the 'bus' of video output
devices attached to a graphics adapter.  It is used when iterating over
the list of outputs, etc.  The 'video_output' lock is used to lock the
output-specific data similar to a driver lock for the individual video
outputs.

MFC after:	2 weeks
2009-09-30 17:05:26 +00:00
Jung-uk Kim
71f99e637a Copy apm(4) emulation from sys/i386/acpica/acpi_machdep.c and
install apm(8) and apm_bios.h on amd64.
2009-09-27 14:00:16 +00:00
John Baldwin
d95e7f5a7a 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.
2009-09-23 15:42:35 +00:00
John Baldwin
36a888a17f Uninline an instance of STAILQ_FOREACH_SAFE(). 2009-09-23 15:39:54 +00:00
Jung-uk Kim
92488a5703 Catch up with ACPICA 20090903. 2009-09-11 22:49:34 +00:00
John Baldwin
2fcd493c4b 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
2009-08-24 21:51:46 +00:00
John Baldwin
a56fe095f0 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
2009-08-20 19:17:53 +00:00
Attilio Rao
444b91868b 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)
2009-08-02 14:28:40 +00:00
Jung-uk Kim
e8c4d3e407 Match PCI Express root bridge _HID directly instead of
relying on _CID.

Reviewed by:	jhb
Approved by:	re (kib)
2009-07-13 21:36:31 +00:00
Jung-uk Kim
435f8ce5b8 Add a missing return in NULL mutex case.
Submitted by:	Pawel Worach (pawel dot worach at gmail dot com)
2009-06-22 17:46:55 +00:00
Jung-uk Kim
5d1540edf3 - Remove unnecessary read memory barriers from atomic operations[1].
- Define a macro to make my intention more clearer.

Submitted by:	jhb [1]
2009-06-11 16:48:59 +00:00
Jung-uk Kim
3ff9febde6 Catch up with r193750 (OsdSynch.c locking changes):
- Preallocate some memory for ACPI tasks early enough.  We cannot use
malloc(9) any more because spin mutex may be held here.  The reserved
memory can be tuned via debug.acpi.max_tasks tunable or ACPI_MAX_TASKS
in kernel configuration.  The default is 32 tasks.
- Implement a custom taskqueue_fast to wrap the new memory allocation.
This implementation is not the fastest in the world but we are being
conservative here.
2009-06-10 22:54:20 +00:00
John Baldwin
0668724b99 Rework the _BBN handling for Host-PCI bridges. Previously we only trusted
a _BBN value of 0 if it was for the first bridge encountered since some
older systems returned _BBN of 0 for all bridges.  However, some newer
systems enumerate bridges with non-zero _BBN before bus 0 which is
perfectly valid.  Handle both cases by trusting the first bridge that has
a _BBN of 0 and falling back to reading from non-standard config registers
only for subsequent bridges with a _BBN of 0.  We also only perform this
check for segment (domain) 0.  We assume that _BBN is always correct
for segments other than 0.

Tested by:	Josef Moellers  josef.moellers at fujitsu
MFC after:	1 week
2009-06-09 13:44:17 +00:00
Jung-uk Kim
c930b91c5f Remove redundant checks for ACPI_WAIT_FOREVER cases. 2009-06-08 20:50:38 +00:00
Jung-uk Kim
230bb4d90d Rewrite OsdSynch.c to reflect the latest ACPICA more closely:
- Implement ACPI semaphore (ACPI_SEMAPHORE) with condvar(9) and mutex(9).
- Implement ACPI mutex (ACPI_MUTEX) with mutex(9).
- Implement ACPI lock (ACPI_SPINLOCK) with spin mutex(9).
2009-06-08 20:07:16 +00:00
Jung-uk Kim
129d3046ef Import ACPICA 20090521. 2009-06-05 18:44:36 +00:00
Warner Losh
00b4e54ae7 We no longer need to use d_thread_t, migrate to struct thread *. 2009-05-20 17:29:21 +00:00
Alexander Motin
2500b6d96d Make dev.cpu.X.cx_usage sysctl also report current average of sleep time. 2009-05-03 06:25:37 +00:00
Alexander Motin
bb1d6ad5b3 Remove unused variable and fix spelling in comment. 2009-05-03 04:58:44 +00:00
Alexander Motin
b0baaaaecf Avoid comparing negative signed to positive unsignad values. It was
leading to a bug, when C-state does not decrease on sleep shorter then
declared transition latency. Fixing this deprecates workaround for broken
C-states on some hardware.

By the way, change state selecting logic a bit. Instead of last sleep
time use short-time average of it. Global interrupts rate in system is a
quite random value, to corellate subsequent sleeps so directly.
2009-05-02 22:30:33 +00:00
Jung-uk Kim
54b43614e7 Fix off-by-one bug. S5 state must be checked as well. 2009-04-30 18:00:53 +00:00
Jung-uk Kim
19682c4826 Fix style(9). 2009-04-30 17:45:43 +00:00
Jung-uk Kim
2d0c82e8cf Prefer device_printf() over printf() where ever possible. 2009-04-30 17:42:11 +00:00
Jung-uk Kim
a0e73a122d 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.
2009-04-30 17:35:44 +00:00
Andriy Gapon
33c70d417e 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
2009-04-28 11:56:54 +00:00
John Baldwin
ea66717737 Move the code to update cpu_cx_count out of acpi_cpu_generic_cx_probe() and
into acpi_cpu_startup() which is where all the other code to update this
global variable lives.  This fixes a bug where cpu_cx_count was not updated
correctly if acpi_cpu_generic_cx_probe() returned early.

PR:		kern/108581
Debugged by:	Bruce Cran
Reviewed by:	avg, njl, sepotvin
MFC after:	3 days
2009-03-26 21:10:35 +00:00
Jung-uk Kim
0755473ba2 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.
2009-03-23 22:12:33 +00:00
Jung-uk Kim
d42f0ad883 Check whether devd is running before calling resume notifier and
reshuffle code to reduce unnecessary locking coverage.
2009-03-23 22:06:09 +00:00
Jung-uk Kim
c66d2b38c8 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.
2009-03-17 00:48:11 +00:00
Andriy Gapon
f1e1ddc3d9 acpi_cpu: fixup for PIIX4E PCI config related to C2
This is triggered only if BIOS configures ACPI_BITREG_BUS_MASTER_RLD
aka BRLD_EN_BM to 1.
Rationale:
1. we do not support C3 on PIIX4E
2. bus master activity need not break out of C2 state
3. because of CPU_QUIRK_NO_BM_CTRL quirk we may reset bus master
   status which would result in immediate break out from C2

So if you have seen
cpu0: too many short sleeps, backing off to C1
with this chipset before you may want to try cx_lowest of C2 again.

Reviewed by: rpaulo (mentor), njl
Approved by: rpaulo (mentor)
2009-02-19 14:39:52 +00:00
Warner Losh
1496d4a967 pcib_read_config and pcib_write_config take u_int params. 2009-02-05 18:40:42 +00:00
Alexander Motin
0f9e2596e2 Convert battery capacity/rate from mA to mW only when summary is requested.
Unconditional conversion causes incorrect rate units reported by acpiconf.

MFC after:	2 weeks
2009-01-17 17:40:44 +00:00
Mike Silbersack
2b39b8273f Quick change to r186026. One of the conditionals was:
if (batt_sleep_ms)
	AcpiOsSleep(1);

where the rest are all:

if (batt_sleep_ms)
	AcpiOsSleep(batt_sleep_ms);

I can't recall why that one was different, so change it
to match the rest.

Pointed out by:	Christoph Mallon
MFC after:	2 weeks
2008-12-13 07:45:48 +00:00
Mike Silbersack
0a3604e155 Add the sysctl debug.acpi.batt.batt_sleep_ms.
On some laptops with smart batteries, enabling battery monitoring
software causes keystrokes from atkbd to be lost.  This has also been
reported on Linux, and is apparently due to the keyboard and I2C line
for the battery being routed through the same chip.  Whether that's
accurate or not, adding extra sleeps to the status checking code
causes the problem to go away.

I've been running this for nearly six months now on my laptop,
it works like a charm.

Reviewed by:	Nate Lawson (in a previous revision)
MFC after:	2 weeks
2008-12-13 06:04:34 +00:00
Ganbold Tsagaankhuu
d78d9a64cf Remove unused variable.
Found with:     Coverity Prevent(tm)
CID: 3678

Approved by: njl
2008-11-25 19:06:20 +00:00
Jung-uk Kim
ab9df4d74d Make sure legacy replacement route is turned off when enbling HPET.
Reviewed by:	jhb
2008-11-19 20:31:38 +00:00
John Baldwin
0d484d249f 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
2008-11-18 21:01:54 +00:00
Alexander Motin
9325b9b23b Remove " + 1".
Thread ID can't be zero anyway while increment may give owerflow.
2008-11-03 18:28:12 +00:00
Warner Losh
96cf0b6d56 Make the no driver stuff an ifdef. 2008-11-02 17:35:15 +00:00
Alexander Motin
57675eb3fa As soon as we have several threads per process now, it is not correct to
use process ID as ACPI thread ID. Concurrent requests with equal thread
IDs broke ACPI mutexes operation causing unpredictable errors including
AE_AML_MUTEX_NOT_ACQUIRED that I have seen.

Use kernel thread ID instead of process ID for ACPI thread.
2008-11-02 12:50:16 +00:00
Jung-uk Kim
d1dfacc2c8 Clean up DSDT and XSDT correctly instead of FADT when the tables are bad.
Submitted by:	jhb
Tested by:	olli
MFC after:	3 days
2008-09-19 15:25:13 +00:00
Warner Losh
099ea4b570 Handle errors from device_get_children. 2008-08-23 16:38:20 +00:00
John Baldwin
d320e05ca5 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
2008-08-22 02:14:23 +00:00
John Baldwin
8c0879b6f6 Fix a typo. 2008-08-04 19:45:15 +00:00
John Baldwin
b661868711 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.
2008-07-23 15:13:06 +00:00
Rui Paulo
edbb029388 Initialize tz_active to a new constant TZ_ACTIVE_UNKNOWN and make no
assumptions about the state of the cooling devices. Instead, switch them
off on init and, only after that, we are in TZ_ACTIVE_NONE.

Submited by:	Andriy Gapon <avg at icyb.net.ua>
Reviewed by:	njl
2008-04-25 16:45:13 +00:00
Rui Paulo
89ab2a7a53 Update the list of Cx states when ACPICA notifies us. Usually, this
notification is sent when the AC plug is plugged in/out.

This is required on some laptops, namely the MacBooks.

Silence on:	 freebsd-acpi
2008-04-12 12:06:00 +00:00
John Baldwin
d227204d2d 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
2008-04-07 18:35:11 +00:00
Takanori Watanabe
9d4ae9aa5b GPE lock may recurse on resume path. 2008-04-05 14:21:01 +00:00
John Baldwin
5217af301c 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@
2008-03-13 20:39:04 +00:00
John Baldwin
463e0f91cb 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
2008-03-10 22:18:07 +00:00
Rui Paulo
8a000acaa9 Some PIIX4 chipsets need to be told to generate Stop Breaks by setting
the appropriate bit in the DEVACTB register.
This change allows the C2 state on those systems to work as expected.

Reviewed by:	njl
Submitted by:	Andriy Gapon <avg at icyb.net.ua>
MFC after:	1 week
2008-03-09 11:19:03 +00:00
Hajimu UMEMOTO
d1c0178bfe Create a thread to handle passive cooling for 1st zone which has _PSV,
_TSP, _TC1 and _TC2.

Contirmed by:	"Alexandre \"Sunny\" Kovalenko" <alex.kovalenko_at_verizon.net>
Reviewed by:	njl
MFC after:	1 week
2008-02-16 07:15:34 +00:00
Rui Paulo
9e684e54fe Allow the user to override the current active cooling state if state
is currently TZ_ACTIVE_NONE.

Submitted by:   Andriy Gapon <avg at icyb.net.ua>
Reviewed by:    njl (mentor)
Approved by:    njl (mentor)
Requested by:   njl (mentor)
MFC after:      3 days
2008-02-16 02:09:05 +00:00
Rui Paulo
6e1de64dca Skip validation of the C3 state if we disabled C3 by software (i.e.,
via quirk).

Submitted by:	Andriy Gapon <avg at icyb.net.ua>
Reviewed by:	njl (mentor)
Approved by:	njl (mentor)
Requested by:	njl (mentor)
MFC after:	3 days
2008-02-16 02:00:25 +00:00
John Baldwin
7a31072193 Fix a typo when testing for the NO_C3 quirk.
MFC after:	3 days
2008-02-12 15:26:59 +00:00
Mitsuru IWASAKI
7572a9c749 Return errno value rather than boolean in this context.
MFC after:	1 week
2008-01-28 01:57:48 +00:00
Mitsuru IWASAKI
0c26519e5a 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
2008-01-27 16:11:04 +00:00
John Baldwin
f831d6e073 Add a header containing constants for the various HPET registers and their
fields and update the code to match.  The PR served more as an inspiration
than providing the actual diffs.

MFC after:	1 week
PR:		kern/112544
2008-01-16 18:47:07 +00:00
John Baldwin
572f347d9f Fix a few minor issues based on a bug report and reading over the HPET
spec:
- Use read/modify/write cycles to enable and disable the HPET instead of
  writing 0 to reserved bits.
- Shutdown the HPET during suspend as encouraged by the spec.
- Fail to attach to an HPET with a period of zero.

MFC after:	1 week
PR:		kern/119675 [3]
Reported by:	Leo Bicknell | bicknell ufp.org
2008-01-15 18:50:47 +00:00
Nate Lawson
4c12fb6750 Fix GPE livelock that occurs on HP/Compaq laptops, mostly in the thermal
zone code.  The GPE handler method (i.e. _L00) generates various Notify
events that need to be run to completion before the GPE is re-enabled.
In ACPI-CA, we queue an asynch callback at the same priority as a Notify
so that it will only run after all Notify handlers have completed.  The
callback re-enables the GPE afterwards.  We also changed the priority of
Notifies to be the same as GPEs, given the possibility that another GPE
could arrive before the Notifies have completed and we don't want it to
get queued ahead of the rest.

The ACPI-CA change was submitted by Alexey Starikovskiy (SUSE) and will
appear in a later release.  Special thanks to him for helping track this
bug down.

MFC after:	1 week
Tested by:	jhb, Yousif Hassan <yousif / alumni.jmu.edu>
2008-01-12 22:13:12 +00:00
John Baldwin
c903c5fbae Use devclass_get_count() instead of devclass_get_maxunit() to get the
correct number of acpi_thermalX devices.  Having this wrong caused the
acpi_thermal thread to realloc the array of devices on each loop iteration.

MFC after:	1 week
PR:		kern/118497
Submitted by:	Pasi Parviainen
2007-12-31 15:56:03 +00:00
Robert Watson
3de213cc00 Add a new 'why' argument to kdb_enter(), and a set of constants to use
for that argument.  This will allow DDB to detect the broad category of
reason why the debugger has been entered, which it can use for the
purposes of deciding which DDB script to run.

Assign approximate why values to all current consumers of the
kdb_enter() interface.
2007-12-25 17:52:02 +00:00
Hajimu UMEMOTO
0c3e489dce Add sysctl mibs for _TSP, _TC1 and _TC2 which is user overridable
but is blocked on user_override mib.
Not a few people want to use a passive cooling without their ACPI
BIOS support.

Reviewed by:	njl
2007-12-24 16:32:14 +00:00
Jung-uk Kim
1de9b7e4c9 Check battery presence first before trying to get battery information.
PR:		kern/117591
Tested by:	Jessica Mahoney (root at varusonline dot com)
2007-11-20 18:35:36 +00:00
Nate Lawson
69d3f89624 Whitespace only. 2007-11-08 21:20:34 +00:00
Nate Lawson
cc3c11f9c9 Fix a shutdown hang on some SMP systems. The previous logic was to IPI all
CPUs to make sure idle threads are evicted from the softc before returning
from acpi_cpu_shutdown().  However, this is unnecessary since stop_cpus()
handles this for itself and at this point it's possible that our IPI will be
blocked (interrupts disabled).

Thanks to:	Glen Leeder <glen.leeder / nokia.com>
MFC after:	3 days
2007-11-02 17:29:36 +00:00
John Baldwin
e71f249b66 Don't return an error from resume() if execution of _DIS fails for some
reason (not all BIOSen have _DIS methods for all link devices for example).
This matches the behavior of attach() with respect to _DIS as well.

Submitted by:	njl
2007-10-27 22:14:17 +00:00
John Baldwin
3052da8bb3 Don't destroy an ACPI device_t for a PCI device and reassign the ACPI
handle to the PCI device_t if the ACPI device_t is already attached to a
driver.  This happens on the Tablet TC1000 which for some reason includes
two PCI-ISA bridges and treats the second bridge as an ACPI system resource
device.

Reviewed by:	njl (a while ago)
MFC after:	3 days
2007-10-27 14:54:43 +00:00
John Baldwin
2445af1a8a Don't always re-route IRQs on resume. If this link hasn't been used, then
disable it with _DIS rather than assigning it an IRQ on resume.

MFC after:	1 week
2007-10-27 13:12:29 +00:00
Takanori Watanabe
68fb6c4858 More style nit.
Pointed out by: njl.
2007-10-25 20:02:38 +00:00
Takanori Watanabe
1de5ce99e3 Fix variable name to be clear what it means. 2007-10-25 17:03:07 +00:00
Takanori Watanabe
0bfeaded17 Turn EC into poll mode before device_resume invoked . 2007-10-25 16:49:07 +00:00
Julian Elischer
3745c395ec Rename the kthread_xxx (e.g. kthread_create()) calls
to kproc_xxx as they actually make whole processes.
Thos makes way for us to add REAL kthread_create() and friends
that actually make theads. it turns out that most of these
calls actually end up being moved back to the thread version
when it's added. but we need to make this cosmetic change first.

I'd LOVE to do this rename in 7.0  so that we can eventually MFC the
new kthread_xxx() calls.
2007-10-20 23:23:23 +00:00
Nate Lawson
4306354df1 When the EC times out (common with Compaqs), it may report a design
voltage of 0.  This can result in a divide by zero trap.  Add a guard
for this case.  The value of lfcap is checked in acpi_battery_bif_valid()
just before this, so it is safe.

Reportd by:	sam
Approved by:	re
MFC after:	3 days
2007-10-09 07:51:46 +00:00
Nate Lawson
f74e3c98dd 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
2007-10-09 07:48:07 +00:00
Marius Strobl
55aaf894e8 Make the PCI code aware of PCI domains (aka PCI segments) so we can
support machines having multiple independently numbered PCI domains
and don't support reenumeration without ambiguity amongst the
devices as seen by the OS and represented by PCI location strings.
This includes introducing a function pci_find_dbsf(9) which works
like pci_find_bsf(9) but additionally takes a domain number argument
and limiting pci_find_bsf(9) to only search devices in domain 0 (the
only domain in single-domain systems). Bge(4) and ofw_pcibus(4) are
changed to use pci_find_dbsf(9) instead of pci_find_bsf(9) in order
to no longer report false positives when searching for siblings and
dupe devices in the same domain respectively.
Along with this change the sole host-PCI bridge driver converted to
actually make use of PCI domain support is uninorth(4), the others
continue to use domain 0 only for now and need to be converted as
appropriate later on.
Note that this means that the format of the location strings as used
by pciconf(8) has been changed and that consumers of <sys/pciio.h>
potentially need to be recompiled.

Suggested by:	jhb
Reviewed by:	grehan, jhb, marcel
Approved by:	re (kensmith), jhb (PCI maintainer hat)
2007-09-30 11:05:18 +00:00
Nate Lawson
83dcc133d8 Rewrite the EC driver event model. The main goal is to avoid
polling/interrupt-driven fallback and instead use polling only during
boot and pure interrupt-driven mode after boot.  Polled mode could be
relegated completely to a legacy role if we could enable interrupts
during boot.  Polled mode can be forced after boot by setting
debug.acpi.ec.polled="1", i.e. if there are timeouts.

- Use polling only during boot, shutdown, or if requested by the user.
  Otherwise, use a generation count of GPEs, incremented atomically.  This
  prevents an old status value from being used if the EC is really slow
  and the same condition (i.e. multiple IBEs for a write transaction) is
  being checked.
- Check for and run the query handler directly if the SCI bit is set in
  the status register during boot.  Previously, the query handler wouldn't
  run until interrupts were finally enabled late in boot.
- During boot and after starting a command, check if the event appears
  to already have occurred before we even start waiting.  If so, it's
  possible the EC is very slow and we might accept an old status value.
  Print a warning in this case.  Once we've booted, interrupt-driven mode
  should work just fine but polled mode could be unreliable.  There's not
  much more we can do about this until interrupts are enabled during boot.
- In the above case, we also do one final check if the interrupt-driven
  mode gets a timeout.  If the status is complete, it will force the
  system back into polled mode since interrupt mode doesn't work.  For
  polled mode during boot, if the status appears to be already complete
  before beginning the check loop, it waits 10 us before actually checking
  the status, just in case the EC is really slow and hasn't gotten to work
  on the new request yet.
- Use upper-case hex for the _Qxx method
- Use device_printf for errors, don't hide them under verbose
- Increase default total timeout to 750 ms and decrease polling interval
  to 5 us.
- Don't pass the status value via the softc.  Just read it directly.
- Remove the mutex. We use the sx lock for transaction serialization
  with the query handler.
- Remove the Intel copyright notice as no code of theirs was ever
  present in this file (verified against rev 1.1)
- Allow KTR module-only builds for ease of testing

Thanks to jkim and Alexey Starikovskiy for helpful discussions and testing.

Approved by:	re
MFC after:	2 weeks
2007-09-24 16:59:06 +00:00
Nate Lawson
b6648efd3b 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
2007-09-13 01:37:17 +00:00
Nate Lawson
c961faca8c Evaluate _OSC on boot to indicate our OS capabilities to ACPI. This is
needed at least to convince the BIOS to give us access to CPU freq
control on MacBooks.

Submitted by:	Rui Paulo <rpaulo / fnop.net>
Approved by:	re
MFC after:	5 days
2007-08-30 21:18:42 +00:00
Nate Lawson
430eaa744e Dynamically choose the quality of the ACPI timer depending on whether
the fast or safe/slow method is in use.  Fast remains at 1000, slow is
now at 850 (always preferred to TSC).  Since the HPET has proven slower
than ACPI-fast on some systems, drop its quality to 900.  In the future,
it is hoped that HPET performance will improve as it is the main
timer Intel supports.  HPET may move back to 2000 in -current once RELENG_7
is branched to ensure that it gets tested.

Approved by:	re
2007-07-30 15:21:26 +00:00
Nate Lawson
9bbad5af65 The HPET appears to be broken on silby's Acer Pentium M system, never
advancing.  Read from the timer before attaching to be sure it advances
in 1 us.  Since the slowest rate allowed by the spec is 10 MHz, the
timer is guaranteed to change in this interval if it is working.

Tested by:	Rui Paulo
Approved by:	re
MFC after:	3 days
2007-07-22 20:45:27 +00:00
Nate Lawson
813d6dca45 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
2007-06-30 17:27:31 +00:00