Important: You are required to change your passwords used for Gentoo services and set an email address for your Wiki account if you haven't done so. See the full announcement and Wiki email policy change for more information.

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, 2012/08/01 13:22:59 -tclover Exp $

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

unhandled() { logger "ACPI event unhandled: $*"; }

case "$group" in
	ac_adapter)
		case "$value" in
			*0) if [ "rc-status -r" != "battery" ]; then
					logger "Switching to battery runlevel"
					rc battery; hprofile power.bat
				fi
				;;
			*1) if [ "rc-status -r" != "default" ]; then
					logger "Switching to default runlevel"
					rc default; hprofile power.adp
				fi
				;;
			*)	unhandled $*;;
		esac
		;;
	battery)
		case "$value" in
			*0) if [ "rc-status -r" != "default" ]; then
					logger "Switching to default runlevel"
					hprofile power.adp; rc default
				fi
				;;
			*1) if [ "rc-status -r" != "default" ]; then
						logger "Switching to default runlevel"
						hprofile power.adp; rc default
				fi
				;;
			*)	unhandled $*;;
		esac
		;;
	button)
		case "$action" in
			lid)
				case "$id" in
					close) pm-suspend --quirk-none;;
					*) unhandled $*;;
				esac
				;;
			power) telinit 0;;
			prog1) :;;
			mute) 
				/etc/init.d/alsasound status &>/dev/null && amixer -q set Master toggle;;
			volumeup) 
				/etc/init.d/alsasound status &>/dev/null && amixer -q set Master 3dB+
				/etc/init.d/oss status &>/dev/null && ossmix -- vmix0-outvol +3;;
			volumedown) 
				/etc/init.d/alsasound status &>/dev/null && amixer -q set Master 3dB-
				/etc/init.d/oss status &>/dev/null && ossmix -- vmix0-outvol -3;;
			*)	unhandled $*;;
		esac
		;;
	cd)
		case "$action" in
			play) :;;
			stop) :;;
			prev) :;;
			next) :;;
		esac
		;;
	jack)
		case "$id" in
			unplug|plug) :;;
			*) unhandled;;
		esac
		;;
	*)	unhandled $*;;
esac

# vim:fenc=utf-8:ft=sh:ci:pi:sts=0: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. An extra notice should be taken for switching runlevels when AC power is unplugged or plugged in. Just make a battery runlevel with a simple `cp -a /etc/runlevels/{default,battery}' or else remove or comment out the related lines. 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.