UACPI: Difference between revisions

1,401 bytes added ,  2 months ago
no edit summary
[unchecked revision][unchecked revision]
No edit summary
Line 126:
 
== Code examples ==
 
Shutting down the system:
<source lang="c">
int system_shutdown(void) {
/*
* Prepare the system for shutdown.
* This will run the \_PTS & \_SST methods, if they exist, as well as
* some work to fetch the \_S5 and \_S0 values to make system wake
* possible later on.
*/
uacpi_status ret = uacpi_prepare_for_sleep_state(UACPI_SLEEP_STATE_S5);
if (uacpi_unlikely_error(ret)) {
log_error("failed to prepare for sleep: %s", uacpi_status_to_string(ret));
return -EIO;
}
 
/*
* This is where we disable interrupts to prevent anything from
* racing with our shutdown sequence below.
*/
disable_interrupts();
 
/*
* Actually do the work of entering the sleep state by writing to the hardware
* registers with the values we fetched during preparation.
* This will also disable runtime events and enable only those that are
* needed for wake.
*/
ret = uacpi_enter_sleep_state(UACPI_SLEEP_STATE_S5);
if (uacpi_unlikely_error(ret)) {
log_error("failed to enter sleep: %s", uacpi_status_to_string(ret));
return -EIO;
}
 
/*
* Technically unreachable code, but leave it here to prevent the compiler
* from complaining.
*/
return 0;
}
</source>
 
You can look at the [https://github.com/managarm/managarm/tree/master/kernel/thor/system/acpi managarm kernel source] to see an example of how you might use uACPI to implement various kernel features.
Anonymous user