generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 20
Feat power button #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wipawel
merged 3 commits into
KernelTestFramework:mainline
from
sparchatus:feat_power_button
Nov 25, 2025
Merged
Feat power button #351
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #include <acpi_ktf.h> | ||
| #include <drivers/power_button.h> | ||
|
|
||
| static void default_handler(void *); | ||
|
|
||
| /** power button press handler */ | ||
| static pb_handler_t pb_handler = default_handler; | ||
| /** context passed to the power button press handler */ | ||
| static void *pb_context = NULL; | ||
|
|
||
| #ifdef KTF_ACPICA | ||
| static UINT32 button_handler(void *Context) { | ||
| if (ACPI_FAILURE(AcpiClearEvent(ACPI_EVENT_POWER_BUTTON))) | ||
| panic("PWRB: Failed to clear power button event"); | ||
|
|
||
| if (pb_handler) | ||
| pb_handler(pb_context); | ||
|
|
||
| return ACPI_INTERRUPT_HANDLED; | ||
| } | ||
| #endif | ||
|
|
||
| static void default_handler(void *notused) { | ||
| #ifdef KTF_ACPICA | ||
| acpi_power_off(); | ||
| #endif | ||
| } | ||
|
|
||
| void pb_set_handler(pb_handler_t handler, void *context) { | ||
| // check that we are on the bsp. Assumes that there is no task migration | ||
| ASSERT(is_cpu_bsp(get_this_cpu())); | ||
|
|
||
| unsigned long flags = interrupts_disable_save(); | ||
| pb_handler = handler; | ||
| pb_context = context; | ||
| interrupts_restore(flags); | ||
| } | ||
|
|
||
| bool init_power_button() { | ||
| #ifdef KTF_ACPICA | ||
| ACPI_TABLE_FADT *fadt = acpi_find_table(ACPI_SIG_FADT); | ||
|
|
||
| if (!(fadt->Flags & ACPI_FADT_POWER_BUTTON)) { | ||
| printk("PWRB: Configuring ACPI 'fixed' power button handling\n"); | ||
|
|
||
| if (ACPI_FAILURE(AcpiClearEvent(ACPI_EVENT_POWER_BUTTON))) { | ||
| warning("PWRB: Failed to clear power button event"); | ||
| return false; | ||
| } | ||
|
|
||
| if (ACPI_FAILURE(AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON, | ||
| button_handler, NULL))) { | ||
| warning("PWRB: Failed to install power button handler"); | ||
| return false; | ||
| } | ||
| } | ||
| else { | ||
| warning("PWRB: Non-fixed power button not implemented\n"); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| #else | ||
| warning("PWRB: Power button without ACPICA not implemented\n"); | ||
|
|
||
| return false; | ||
| #endif | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #ifndef KTF_POWER_BUTTON_H | ||
| #define KTF_POWER_BUTTON_H | ||
|
|
||
| typedef void (*pb_handler_t)(void *); | ||
|
|
||
| /** | ||
| * Set a handler for the power button. Useful to control experiments. | ||
| * | ||
| * Note: This function MUST be called from the bsp to ensure consistency! | ||
| */ | ||
| void pb_set_handler(pb_handler_t handler, void *context); | ||
|
|
||
| /** | ||
| * Initialize power button handling. Requires ACPICA library. | ||
| */ | ||
| extern bool init_power_button(); | ||
|
|
||
| #endif /* KTF_POWER_BUTTON_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.