ACPI: Tiny power button driver
Subsystems (2)
cover ACPI: Tiny power button driver
Virtual machines often use an ACPI power button event to tell the machine to shut down gracefully.
Provide an extremely lightweight "tiny power button" driver to handle this event by signaling init directly, rather than running a separate daemon (such as acpid or systemd-logind) that adds to startup time and VM image complexity.
I originally proposed a change to the ACPI power button driver to introduce an optional path to signal init, but Rafael expressed a preference to have this as a separate, mutually exclusive driver instead. The result did come out much simpler, conceptually, with the added benefit of being able to disable CONFIG_INPUT entirely for a kernel that exclusively targets cloud/VM systems.
The first patch in the series just moves HID definitions to acpi/button.h in preparation for sharing them with the tiny-power-button driver. The second patch provides the driver itself.
Josh Triplett (2):
acpi: button: move HIDs to acpi/button.h
acpi: Add new tiny-power-button driver to directly signal init
drivers/acpi/Kconfig | 24 +++++++++++++++++ drivers/acpi/Makefile | 1 + drivers/acpi/button.c | 3 --- drivers/acpi/tiny-power-button.c | 46 ++++++++++++++++++++++++++++++++ include/acpi/button.h | 4 +++ 5 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 drivers/acpi/tiny-power-button.c
Signature · 1 line
2.25.0
PATCH 1/2 ACPI: button: move HIDs to acpi/button.h
This makes it possible to use ACPI_BUTTON_HID_POWER in another driver.
--- drivers/acpi/button.c | 3 --- include/acpi/button.h | 4 ++++ 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/acpi/button.c +0 -3
@@ -30,17 +30,14 @@#define ACPI_BUTTON_NOTIFY_STATUS 0x80#define ACPI_BUTTON_SUBCLASS_POWER "power" -#define ACPI_BUTTON_HID_POWER "PNP0C0C"#define ACPI_BUTTON_DEVICE_NAME_POWER "Power Button"#define ACPI_BUTTON_TYPE_POWER 0x01#define ACPI_BUTTON_SUBCLASS_SLEEP "sleep" -#define ACPI_BUTTON_HID_SLEEP "PNP0C0E"#define ACPI_BUTTON_DEVICE_NAME_SLEEP "Sleep Button"#define ACPI_BUTTON_TYPE_SLEEP 0x03#define ACPI_BUTTON_SUBCLASS_LID "lid" -#define ACPI_BUTTON_HID_LID "PNP0C0D"#define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch"#define ACPI_BUTTON_TYPE_LID 0x05
include/acpi/button.h +4 -0
@@ -2,6 +2,10 @@#ifndef ACPI_BUTTON_H #define ACPI_BUTTON_H +#define ACPI_BUTTON_HID_POWER "PNP0C0C" +#define ACPI_BUTTON_HID_LID "PNP0C0D" +#define ACPI_BUTTON_HID_SLEEP "PNP0C0E" +#if IS_ENABLED (CONFIG_ACPI_BUTTON )extern int acpi_lid_open (void );#else
Signature · 1 line
2.25.0
PATCH 2/2 ACPI: Add new tiny-power-button driver to directly signal init
In reply to Josh TriplettVirtual machines often use an ACPI power button event to tell the machine to shut down gracefully.
Provide an extremely lightweight "tiny power button" driver to handle this event by signaling init directly, rather than running a separate daemon (such as acpid or systemd-logind) that adds to startup time and VM image complexity.
The kernel configuration defines the default signal to send init, and userspace can change this signal via a module parameter.
--- drivers/acpi/Kconfig | 24 +++++++++++++++++ drivers/acpi/Makefile | 1 + drivers/acpi/tiny-power-button.c | 46 ++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 drivers/acpi/tiny-power-button.c
drivers/acpi/Kconfig +24 -0
@@ -190,6 +190,30 @@ config ACPI_BUTTON To compile this driver as a module, choose M here: the module will be called button. +config ACPI_TINY_POWER_BUTTON + tristate "Tiny Power Button Driver" + depends on !ACPI_BUTTON + help + This driver provides a tiny alternative to the ACPI Button driver. + The tiny power button driver only handles the power button. Rather + than notifying userspace via the input layer or a netlink event, this + driver directly signals the init process to shut down. + + This driver is particularly suitable for cloud and VM environments, + which use a simulated power button to initiate a controlled poweroff, + but which may not want to run a separate userspace daemon to process + input events. + +config ACPI_TINY_POWER_BUTTON_SIGNAL + int "Tiny Power Button Signal" + depends on ACPI_TINY_POWER_BUTTON + default 38 + help + Default signal to send to init in response to the power button. + + Likely values here include 38 (SIGRTMIN+4) to power off, or 2 + (SIGINT) to simulate Ctrl+Alt+Del. + config ACPI_VIDEO tristate "Video" depends on X86 && BACKLIGHT_CLASS_DEVICE
drivers/acpi/Makefile +1 -0
@@ -71,6 +71,7 @@ obj-$(CONFIG_ACPI_IPMI) += acpi_ipmi.o obj-$(CONFIG_ACPI_AC) += ac.o obj-$(CONFIG_ACPI_BUTTON) += button.o +obj-$(CONFIG_ACPI_TINY_POWER_BUTTON) += tiny-power-button.o obj-$(CONFIG_ACPI_FAN) += fan.o obj-$(CONFIG_ACPI_VIDEO) += video.o obj-$(CONFIG_ACPI_TAD) += acpi_tad.o
drivers/acpi/tiny-power-button.c new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.25.0
Quoted 16 lines · Josh Triplett
Virtual machines often use an ACPI power button event to tell the machine to shut down gracefully.
Provide an extremely lightweight "tiny power button" driver to handle this event by signaling init directly, rather than running a separate daemon (such as acpid or systemd-logind) that adds to startup time and VM image complexity.
I originally proposed a change to the ACPI power button driver to introduce an optional path to signal init, but Rafael expressed a preference to have this as a separate, mutually exclusive driver instead. The result did come out much simpler, conceptually, with the added benefit of being able to disable
CONFIG_INPUTentirely for a kernel that exclusively targets cloud/VM systems.
Quoted 7 lines
The first patch in the series just moves HID definitions to
acpi/button.hin preparation for sharing them with the tiny-power-button driver. The second patch provides the driver itself.Josh Triplett (2):
acpi: button: move HIDs toacpi/button.h
acpi: Add new tiny-power-button driver to directly signal init
Applied as 5.7 material, thanks!