This directory contains a application using the ported ACPI-CA
library (https://www.acpica.org) and reports ACPI state changes in form of
Genode reports. Additionally the application is capable to perform ACPI poweroff
and reset.

Behavior
--------

General support for ACPI events compromises state changes from the following
sources:

- ACPI Lid                 - open/closed
- ACPI Smart battery (SB)  - charging/discharging and static information (capacity)
- ACPI fixed events        - e.g. power button
- ACPI AC adapters         - power cable plugged/un-plugged
- ACPI Embedded controller - some Fn-* keys and on some machines also Lid, AC, SB changes

Whenever a state change is detected, a Genode report is generated, if a 
config attribute "report" is set to "yes". The reports are named
'acpi_lid', 'acpi_battery', 'acpi_fixed', 'acpi_ac' and 'acpi_ec'. See below
for the xml syntax used so far. Please also look into the ACPI specification
for detailed description of some of the fields and their possible values.

If the config attributes 'reset' or 'poweroff' are set to yes, the application
additionally looks for a ROM in XML format named 'system' and monitors
changes of the 'state' attribute:

!<system state="something"/>

Additionally, if the config attributes 'acpi_ready' is set to yes, the
application generates a reports named 'acpi_ready' and set the state to

!<system state="acpi_ready"/>

after finishing the ACPI bring up. This is used by platform_drv to finally
announce the Platform session, so that drivers can start after acpica has
finished.

If the ROM changes to 'state="reset"' the application tries to reset the 
machine immediately.
If the ROM changes to 'state="poweroff"' the application tries to poweroff 
the machine immediately.

The attempt to reset or to poweroff may fail. One reason, we have seen so far,
is that the required resources are already owned by other components in the
system.

Furthermore the ACPICA library triggers depended on the ACPI table content
I/O operations on various PCI devices and partly re-configure it. Because of
this a policy rule at the platform driver is required, that permits access
to the required devices.

Acpica as acpi_drv replacement
------------------------------

The application acpica may also be run as replacement of the original acpi_drv
when the 'act_as_acpi_drv' attribute is set to yes:

!  <config ... acpi_ready="yes" act_as_acpi_drv="yes"/>

The acpica driver will parse in this mode the ACPI tables and will generate
the same content in the ACPI report, which is transformed by a report_rom
service into a ACPI ROM expected initially by the platform driver.

Excerpt of important parts of the acpica configuration
------------------------------------------------------

!<start name="acpica">
!  <!-- <binary name="debug-acpica"/> -->
!  ...
!  <config reset="no" poweroff="no" report="yes" acpi_ready="yes" act_as_acpi_drv="no"/>
!  <route>
!    <service name="ROM" label="system"> <child name="..."/> </service>
!    <service name="Report"> <child name="..."/> </service>
!    ...
!  </route>
!</start>
!
!<start name="platform_drv" >
!  ...
!  <config acpi="yes" system="yes">
!    <policy label_prefix="acpica"> <pci class="ALL"/> </policy>
!    ...
!  </config>
!</start>

Reports generated by the Genode acpica application
--------------------------------------------------

Report 'acpi_lid' - open/closed:

!<acpi_lid>
!  <lid value="1" count="1">open</lid>
!</acpi_lid>

!<acpi_lid>
!  <lid value="0" count="3">closed</lid>
!</acpi_lid>


Report 'acpi_ac' - power cable plugged-in /unplugged

!<acpi_ac>
!  <ac value="1" count="1">online</ac>
!</acpi_ac>

!<acpi_ac>
!  <ac value="0" count="2">offline</ac>
!</acpi_ac>


Report 'acpi_ec' - embedded controller events

!<acpi_ec>
!  <ec>
!    <data value="42" count="1">triggered</data>
!    <data value="43" count="1"/>
!  </ec>
!</acpi_ec>


Report 'acpi_battery' - smart battery status changes

!<acpi_battery>
!  <sb>
!    <name>BAT1</name>
!    <powerunit value="1">mA/mAh</powerunit>
!    <design_capacity value="4800"/>
!    <last_full_capacity value="5417"/>
!    <technology value="1">secondary</technology>
!    <voltage value="12608"/>
!    <warning_capacity value="325"/>
!    <low_capacity value="162"/>
!    <granularity1 value="0"/>
!    <granularity2 value="0"/>
!    <serial>BAT1</serial>
!    <model>RT672</model>
!    <type>LiON</type>
!    <oem>ASP</oem>
!    <status value="31"/>
!    <state value="1">discharging</state>
!    <present_rate value="0"/>
!    <remaining_capacity value="5663"/>
!    <present_voltage value="12524"/>
!  </sb>
!</acpi_battery>

!<acpi_battery>
!    ...
!    <state value="2">charging</state>
!    ...
!</acpi_battery>

!<acpi_battery>
!    ...
!    <status value="15">battery not present</status>
!    ...
!</acpi_battery>
