Commit Graph

830 Commits

Author SHA1 Message Date
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
Nate Lawson
00a304487f 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
2007-06-21 22:50:37 +00:00
Nate Lawson
70fa7bc0ac Convert magic to a uintptr_t. This should get rid of some warnings on
gcc4.
2007-06-15 18:02:34 +00:00
David Malone
041b706b2f Despite several examples in the kernel, the third argument of
sysctl_handle_int is not sizeof the int type you want to export.
The type must always be an int or an unsigned int.

Remove the instances where a sizeof(variable) is passed to stop
people accidently cut and pasting these examples.

In a few places this was sysctl_handle_int was being used on 64 bit
types, which would truncate the value to be exported.  In these
cases use sysctl_handle_quad to export them and change the format
to Q so that sysctl(1) can still print them.
2007-06-04 18:25:08 +00:00
Nate Lawson
3331373ce7 Disable CPU idle states during suspend and reenable them during resume.
While in the suspend path, this means the idle thread will just return
immediately rather than trying to enter C1-n.  This helps in the case where
the chipset is powered down before the rest of the system and reads from
the cpu sleep registers begin returning immediately, causing the logic that
catches bad C2/C3 behavior to kick in.  Observed on my Panasonic Y4.

MFC after:	3 days
2007-06-03 00:40:56 +00:00
Nate Lawson
b13cf7741c Fix a bug introduced in the per-CPU Cx states commit. The wrong loop var
(j/i) was being used and it was being incremented, not decremented as before.
Factor out this code into a common function and call it from both the common
and per-CPU case.

MFC after:	1 day
2007-06-02 20:01:40 +00:00
Nate Lawson
35440dd3e9 AcpiAcquireGlobalLock() can sometimes sleep if the mutex is contested.
The global lock is a memory region shared with the BIOS and thus
has some strange behavior like the fact that the sleep is 1 ms max.
We use standard mutexes to synchronize with the SCI so acquiring
the global lock after locking the mutex resulted in a witness
warning.

To deal with this for now, acquire the global lock before all other
locks, similar to Giant.  This should fix the witness "sleeping
with mutex held" issue on boot that occurred after the last ACPI-CA
import.  In the future, we hope to move to the new mutex interface
in ACPI-CA instead of the pseudo-semaphore version we have now.

Reviewed by:    jkim
2007-06-02 19:21:40 +00:00
Takanori Watanabe
345a0942e9 Use ACPICA defined value for notification rather than locally defined one. 2007-05-31 08:49:51 +00:00
Nate Lawson
e727574190 Remove "acpi_bus_number: can't get _ADR" message. It usually appears as
we traverse \_SB and \ in the namespace, which won't have _ADR anyway.
Use a proper extern instead of our own private copy.

MFC after:	1 week
2007-05-31 00:52:32 +00:00
Nate Lawson
93bfd059fd 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
2007-05-25 05:26:21 +00:00
Nate Lawson
f1d16a11cb Fix a logic bug added in last commit where PNP0103 devices would no longer
be probed but table-based devs would be ok.  General style cleanup also.

MFC after:	5 days
2007-05-16 01:15:51 +00:00
Takanori Watanabe
fffe371da3 Add ACPI HPET table support.
Reviewed by:njl
2007-05-15 08:41:05 +00:00
Mark Santcroos
4b1ff978df Set the debug.acpi.acpi_ca_version sysctl even if ACPI support is not
available.
2007-05-08 14:31:49 +00:00
John Baldwin
e706f7f0c7 Revamp the MSI/MSI-X code a bit to achieve two main goals:
- Simplify the amount of work that has be done for each architecture by
  pushing more of the truly MI code down into the PCI bus driver.
- Don't bind MSI-X indicies to IRQs so that we can allow a driver to map
  multiple MSI-X messages into a single IRQ when handling a message
  shortage.

The changes include:
- Add a new pcib_if method: PCIB_MAP_MSI() which is called by the PCI bus
  to calculate the address and data values for a given MSI/MSI-X IRQ.
  The x86 nexus drivers map this into a call to a new 'msi_map()' function
  in msi.c that does the mapping.
- Retire the pcib_if method PCIB_REMAP_MSIX() and remove the 'index'
  parameter from PCIB_ALLOC_MSIX().  MD code no longer has any knowledge
  of the MSI-X index for a given MSI-X IRQ.
- The PCI bus driver now stores more MSI-X state in a child's ivars.
  Specifically, it now stores an array of IRQs (called "message vectors" in
  the code) that have associated address and data values, and a small
  virtual version of the MSI-X table that specifies the message vector
  that a given MSI-X table entry uses.  Sparse mappings are permitted in
  the virtual table.
- The PCI bus driver now configures the MSI and MSI-X address/data
  registers directly via custom bus_setup_intr() and bus_teardown_intr()
  methods.  pci_setup_intr() invokes PCIB_MAP_MSI() to determine the
  address and data values for a given message as needed.  The MD code
  no longer has to call back down into the PCI bus code to set these
  values from the nexus' bus_setup_intr() handler.
- The PCI bus code provides a callout (pci_remap_msi_irq()) that the MD
  code can call to force the PCI bus to re-invoke PCIB_MAP_MSI() to get
  new values of the address and data fields for a given IRQ.  The x86
  MSI code uses this when an MSI IRQ is moved to a different CPU, requiring
  a new value of the 'address' field.
- The x86 MSI psuedo-driver loses a lot of code, and in fact the separate
  MSI/MSI-X pseudo-PICs are collapsed down into a single MSI PIC driver
  since the only remaining diff between the two is a substring in a
  bootverbose printf.
- The PCI bus driver will now restore MSI-X state (including programming
  entries in the MSI-X table) on device resume.
- The interface for pci_remap_msix() has changed.  Instead of accepting
  indices for the allocated vectors, it accepts a mini-virtual table
  (with a new length parameter).  This table is an array of u_ints, where
  each value specifies which allocated message vector to use for the
  corresponding MSI-X message.  A vector of 0 forces a message to not
  have an associated IRQ.  The device may choose to only use some of the
  IRQs assigned, in which case the unused IRQs must be at the "end" and
  will be released back to the system.  This allows a driver to use the
  same remap table for different shortage values.  For example, if a driver
  wants 4 messages, it can use the same remap table (which only uses the
  first two messages) for the cases when it only gets 2 or 3 messages and
  in the latter case the PCI bus will release the 3rd IRQ back to the
  system.

MFC after:	1 month
2007-05-02 17:50:36 +00:00
John Baldwin
147c0ad0a1 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
2007-04-25 16:22:18 +00:00
John Baldwin
4e7f640dfb Optimize sx locks to use simple atomic operations for the common cases of
obtaining and releasing shared and exclusive locks.  The algorithms for
manipulating the lock cookie are very similar to that rwlocks.  This patch
also adds support for exclusive locks using the same algorithm as mutexes.

A new sx_init_flags() function has been added so that optional flags can be
specified to alter a given locks behavior.  The flags include SX_DUPOK,
SX_NOWITNESS, SX_NOPROFILE, and SX_QUITE which are all identical in nature
to the similar flags for mutexes.

Adaptive spinning on select locks may be enabled by enabling the
ADAPTIVE_SX kernel option.  Only locks initialized with the SX_ADAPTIVESPIN
flag via sx_init_flags() will adaptively spin.

The common cases for sx_slock(), sx_sunlock(), sx_xlock(), and sx_xunlock()
are now performed inline in non-debug kernels.  As a result, <sys/sx.h> now
requires <sys/lock.h> to be included prior to <sys/sx.h>.

The new kernel option SX_NOINLINE can be used to disable the aforementioned
inlining in non-debug kernels.

The size of struct sx has changed, so the kernel ABI is probably greatly
disturbed.

MFC after:	1 month
Submitted by:	attilio
Tested by:	kris, pjd
2007-03-31 23:23:42 +00:00
Nate Lawson
5394d87e21 Re-enable the HPET timer after a resume.
Submitted by:	Andrea Bittau <a.bittau@cs.ucl.ac.uk>
MFC after:	3 days
2007-03-28 22:28:48 +00:00
Jung-uk Kim
abedf9eb2f - Use '*h' instead of 'struct acpi_spinlock' for sizeof[1].
- Add a missing 'else' for 'if'[2].

Requested by:	njl[1]
Submitted by:	njl[2]
2007-03-26 23:04:02 +00:00
Jung-uk Kim
5acbef6ae5 Correct ACPI semaphore function parameters. 2007-03-26 21:56:35 +00:00
Jung-uk Kim
97c9968179 Free the handle, not the lock. Pointy hat to me. 2007-03-26 21:36:31 +00:00
Jung-uk Kim
98defcd3f2 Correct ACPI spinlock function parameters and use known ACPI spinlock names. 2007-03-26 21:23:23 +00:00
Nate Lawson
e49e68cc9d Use a unique name for each mutex now that acpi-ca is creating more than
one (hardware & global lock).  This should address witness complaints that
a duplicate mutex is being acquired.  Be sure to free the mutex to fix a
potential memory leak.

MFC after:	3 days
2007-03-26 19:38:28 +00:00
Jung-uk Kim
2be4e4713a Catch up with ACPI-CA 20070320 import. 2007-03-22 18:16:43 +00:00
John Baldwin
397c30a83d 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.
2007-03-21 15:39:11 +00:00
John Baldwin
ce533e82a2 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.
2007-03-20 20:21:44 +00:00
Nate Lawson
6e141df200 If we got an OBE/IBF event, we failed to re-enable the GPE. This would
cause the EC to stop handling future events because the GPE stayed masked.
Set a flag when queueing a GPE handler since it will ultimately re-enable
the GPE.  In all other cases, re-enable it ourselves.  I reworked the
patch from the submitter.

Submitted by:	Rong-en Fan <grafan@gmail.com>
2007-03-20 00:58:19 +00:00
Nate Lawson
675e5627d0 Disable burst mode by default. Testing has shown that while it works on
most systems, it causes the EC not to respond for some Acer and Compaq/HP
laptops.  This is the default value for Linux also.  For systems that need
it, burst mode can be enabled via the tunable/sysctl:
	debug.acpi.ec.burst="1"
2007-03-18 01:03:03 +00:00
Nate Lawson
929a5cf650 Only enter the debugger on a Fatal op if this is a debug build of the
acpi module.  Also clean up print of args a little.

This was accidentally committed as 1.9.2.3 in the stable branch.  Since it
is harmless, I will let the "insta-MFC" stand unless there is a problem.
2007-03-14 19:56:10 +00:00
Nate Lawson
4d44d81742 Check the _TMP value for sanity also. On some systems (HP NX laptops), the
EC occasionally times out and provides bogus values (3000C).  This change
prevents those systems from prematurely shutting down while we work on the
underlying problem.  Also, bump the sanity value to 0...200C from 0...150C.
2007-03-05 21:39:53 +00:00
Nate Lawson
ef2374f700 Rework EC I/O approach. Implement burst mode, including proper handling of
case where it asynchronously exits burst mode on its own.  Handle different
values of hz in sleep loop.  Provide more debugging options to tune EC
behavior.  These tunables/sysctls may be temporary and are not for user
access if the EC is working properly.  Burst mode is now on by default for
testing and the poll interval has been increased from 100 to 500 us and
total timeout from 100 to 500 ms.

Hopefully this should be the first step of addressing reports of timeout
errors during battery or thermal access, especially on HP/Compaq laptops.
It is reasonably stable and should not cause a loss of functionality or
performance on systems that were previously working.  Testing shows an
increase of responsiveness by ~75% on one system.

PR:		kern/98171
2007-02-27 00:14:20 +00:00
John Baldwin
a96255b62d Use 'pause' in several places rather than trying to tsleep() on NULL (which
triggers a KASSERT) or local variables.  In the case of kern_ndis, the
tsleep() actually used a common sleep address (curproc) making it
susceptible to a premature wakeup.
2007-02-23 16:25:08 +00:00
Paolo Pisati
ef544f6312 o break newbus api: add a new argument of type driver_filter_t to
bus_setup_intr()

o add an int return code to all fast handlers

o retire INTR_FAST/IH_FAST

For more info: http://docs.freebsd.org/cgi/getmsg.cgi?fetch=465712+0+current/freebsd-current

Reviewed by: many
Approved by: re@
2007-02-23 12:19:07 +00:00