> I'm looking to trap the signal from the power button on many modern
ATX/NLX
> motherboards (I think they might call it 'soft power' or something), and
use it
> to do something useful.  For example -
>
> a) A server might do a uniform shutdown without plugging in a keyboard to
do a
> shutdown.
> b) A client might suspend and power down so that a reboot isn't required
to
> carry on working.
> c) Even better - a combination of the two - quick press to suspend, two
second
> press to shutdown.
>
> Has someone already done work on something like this, or does anyone have
> suggestions as to a good starting point?
>

The power button is an APM function of the BIOS and chipset.  When the user
presses the power button the chipset senses that trigger, enters SMM. In SMM
the processor jumps to a memory location in BIOS and start executing the
Interrupt handler for that function.  Some BIOS's use an interrupt rather
than SMM, but the results are the same. On most BIOS's the function sends an
APM_USER_SUSPEND or APM_SYSTEM_SUSPEND signal to the OS.

To make use of this signal you must first compile a kernel with APM enabled,
have a system with support for APM in the BIOS, and if you want your system
to power down, an ATX power supply and ATX power supply connection on the
motherboard.

I currently use this trigger to perform a real shutdown of the system vs a
power off.  Edit the linux/drivers/char/apm_bios.c (2.0.x kernels).  You
will see a case statement in the function check_events. In the case for
APM_USER_SUSPEND (or APM_SYSTEM_SUSPEND depending on your BIOS) set a
semaphore put in a proc file to be read from a user space program.
Currently the variable apm_bios_info.flags has three bits available for this
semaphore. Also make sure you send an APM_STATE_REJECT or your system will
enter suspend mode.  You can do this by compiling the kernel with
CONFIG_APM_IGNORE_USER_SYSPEND.

Now you need to write a user space program that can read the file /proc/apm
(obviously you will need to compile the kernel with the proc file system).
When your semaphore bit is set do your thing.

Hope this helps.

Jim DiFronzo

Reply via email to