OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 4:50 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Handling power button press
PostPosted: Tue Feb 06, 2018 1:25 am 
Offline

Joined: Sun Jul 07, 2013 7:29 pm
Posts: 16
Hi,

I am working on my hobby OS and now I am trying to add a shutdown handler. I need to install a handler for power button. I tryed to google the answer and it looks like I need to use SCI interruption. I parsed ACPI FADI and found that IRQ number for SCI at my machine is 9. I installed an IRQ handler then use QEMU monitor command 'system_powerdown' but I do not see that my power button press handler is called.

What is the semantic of power button handler setup? Is there additional ACPI configuration ineeded for this use-case?


Top
 Profile  
 
 Post subject: Re: Handling power button press
PostPosted: Tue Feb 06, 2018 4:13 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

anatolik wrote:
I am working on my hobby OS and now I am trying to add a shutdown handler. I need to install a handler for power button. I tryed to google the answer and it looks like I need to use SCI interruption. I parsed ACPI FADI and found that IRQ number for SCI at my machine is 9. I installed an IRQ handler then use QEMU monitor command 'system_powerdown' but I do not see that my power button press handler is called.

What is the semantic of power button handler setup? Is there additional ACPI configuration ineeded for this use-case?


You can think of firmware as having 2 modes.

For the default/legacy mode, the user presses the power button (for 5+ seconds), the firmware gets a SMI/"System Management Interrupt", and the firmware shuts the computer down (the OS is not aware of any of this happening).

For "ACPI mode", the user presses the power button and the hardware (ACPI's embedded controller) sends an SCI/"System Control Interrupt" (instead of the SMI), the operating system's "SCI handler" starts and responds by interpreting ACPI's AML, the AML figures out what caused the SCI and generate a "button event", and the OS handles the button event however it likes (typically by using other AML functions to turn the computer off or to hibernate/suspend). Note that in "ACPI mode" you may also need to handle things like "over-temperature events" correctly (to prevent the computer from melting).

To switch from default/legacy mode to "ACPI mode" you need to follow a sequence that begins with installing an interrupt handler for the SCI and fiddling with an "enable flag" (described by fields in ACPI's FADT), and then call a few initialisation functions in the firmware's AML (with your AML interpreter) to do things like tell the AML which version of Windows your OS is, whether it intends to use PIC or IO APIC, etc. This typically means porting ACPICA to your OS to avoid the ~10 years of pain required to use AML properly/reliably (and emulate the quirks of whichever version of Windows your OS said it is). Note that if your OS tells AML the truth (instead of pretending its a version of Windows), then AML won't recognise your OS and will only provide bare minimum features (almost everything disabled).

For a hobby OS, my advice is to use the default/legacy mode. It just means that the user will need to hold the power button for 5+ seconds to ge the computer to turn itself off (and that the OS won't have a chance to do anything before power off).


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Handling power button press
PostPosted: Tue Feb 13, 2018 8:39 am 
Offline

Joined: Sun Jul 07, 2013 7:29 pm
Posts: 16
Hello Brendan.

Thank you for the information. It looks like using ACPICA is the only reasonable way to achieve my goal. Though integrating ACPICA into my code will take some time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 173 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group