ACPI

From Gentoo Wiki
Jump to: navigation, search
External resources

ACPI (Advanced Configuration and Power Management Interface) is a power management system. It is part of the BIOS.

Installation

Kernel

You need to activate the following kernel options:

Kernel configuration

Power management and ACPI options  --->
    [*] Power Management support
        [*] ACPI (Advanced Configuration and Power Interface) Support  --->
            [*] Optional drivers
Optional drivers
Option Module Recommend Description
Deprecated /proc/acpi files - No Creates deprecated files in the procfs filesystem, which are now replaced by files in the sysfs filesystem.
Deprecated power /proc/acpi directories - No Creates deprecated files in the procfs filesystem, which are now replaced by files in the sysfs filesystem.
EC read/write access through /sys/kernel/debug/ec ec-debugfs No Debug interface to the Embedded Controller.
Deprecated /proc/acpi/event support - No Creates deprecated files in the procfs filesystem, which are now replaced by the input layer or netlink events.
AC Adapter ac Laptops Creates files to tell, if your system is connected to AC.
Battery battery Laptops Creates files to tell, if your system is powered by a battery.
Button button - Handles events on the power, sleep, and lid buttons.
Video video - Supports basic operations for graphics adapters.
Fan fan - Supports ACPI fan devices, allowing user-mode applications to perform basic fan control (on, off, status).
Dock dock - Supports ACPI-controlled docking stations and removable drive bays, see the acpi dock article.
Processor processor - Installs ACPI as the idle handler for Linux and uses ACPI C2 and C3 processor states to save power.
Processor Aggregator processor-aggregator - ACPI 4.0 function to perform specific processor configuration and control.
Thermal Zone thermal Yes Supports ACPI thermal zones to protect your processor against overheating.
NUMA support - -
Debug Statements - No
PCI slot detection driver pci-slot No Helps to correlate PCI bus addresses with physical slots
Container and Module Devices container - Supports ACPI Container and Module devices to hotplug nodes, CPUs, and memory.
Smart Battery System sbs, sbshc - Supports another type of access to battery information, found on some laptops.
Hardware Error Device hed - Supports the Hardware Error Device, which is used to report some hardware errors.
Allow ACPI methods to be inserted/replaced at run time custom-method No
ACPI Platform Error Interface (APEI) - - APEI allows to report errors (for example from the chipset) to the operating system.

Software

Desktop environments react on the common events generated by ACPI. If you don't use a desktop environment or want to react on special events, install sys-power/acpid:

→ Information about USE flags
USE flag Default Recommended Description
selinux No No  !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
root # emerge --ask acpid

SELinux

If you want acpid to be able to shutdown the system, make sure you have installed sec-policy/selinux-shutdown and relabelled /sbin/shutdown

Configuration

The scripts in /etc/acpi define how to react on ACPI events. You can edit them or add more.

Boot service

You can now start acpid. If you are using openrc:

root # /etc/init.d/acpid start

To start acpid at boot time, add it your default runlevel:

root # rc-update add acpid default


In case of systemd:

root # systemctl enable acpid.service
root # systemctl start acpid.service

Advanced configuration

You may be satisfied with the default ACPI package set up. Although, you may need a little extra configuration to get acpid daemon treat some basic ACPI events like AC power plug in/out, multimedia keys etc.

You will have to edit /etc/acpi/default.sh along with /etc/acpi/events/default if necessary and why not a complicated set up that make use of /etc/acpi/actions and /etc/acpi/events. Just put your scripts and event files there.

A basic default.sh may be enough. The following is an example on what could be done.

File/etc/acpi/default.sh

#!/bin/sh
# $Id: /etc/acpi/default.sh, 2014/07/22 14:22:59 -tclover Exp $

log() { logger -p daemon "ACPI: $*"; }
uhd() { log "event unhandled: $*"; }

set $*
group=${1%/*}
action=${1#*/}
device=$2
id=$3
value=$4

[ -e /run/openrc/started/alsasound ] && alsa=true || alsa=false
[ -e /run/openrc/started/oss ]       && oss=true  || oss=false
amixer="amixer -q set Master"
ossmix="ossmix -- vmix0-outvol"

case $group in
	ac_adapter)
		case $value in
			*0) log "switching to power.bat power profile"
				hprofile power.bat;;
			*1) log "switching to power.adp power profile"
				hprofile power.adp;;
			*) uhd $*;;
		esac
		;;
	battery)
		case $value in
			*0) log "switching to power.adp power profile"
				hprofile power.adp;;
			*1) log "switching to power.adp power profile"
				hprofile power.adp;;
			*) uhd $*;;
		esac
		;;
	button)
		case $action in
			lid)
				case "$id" in
					close) hibernate-ram;;
					open) :;;
					*) uhd $*;;
				esac
				;;
			power) shutdown -H now;;
			sleep) hibernate-ram;;
			mute) 
				$alsa && $amixer toggle;;
			volumeup) 
				$alsa && $amixer 3dB+
				$oss && $ossmix +3;;
			volumedown) 
				$alsa && $amixer 3dB-
				$oss && $ossmix -3;;
			*) uhd $*;;
		esac
		;;
	cd)
		case $action in
			play) :;;
			stop) :;;
			prev) :;;
			next) :;;
			*) uhd $*;;
		esac
		;;
	jack)
		case $id in
			*plug) :;;
			*) uhd $*;;
		esac
		;;
	video)
		case $action in
			displayoff) :;;
			*) uhd $*;;
		esac
		;;
	*) uhd $*;;
esac

unset alsa oss amixer ossmix group action device id

# vim:fenc=utf-8:ft=sh:ci:pi:sts=4:sw=4:ts=4:
Note
Notice that the script is compatible with ALSA and OSS, so no extra actions to undergo when switching to using OSS from ALSA or the opposite. My laptop multimedia ACPI capable key events used to be taken care of by MPRIS in enlightenment and I enjoyed being able to control multimedia player with them. So I did not thought something about the related events when writing the script. If somebody is experiencing with the same annoyance, do not hesitate to edit the script and share it back!
Note
The previous script make use of a power management profile using hprofile. Refer to that article for more information.

Examples

ACPI events and actions examples for Lenovo ThinkPad T410