Skip to content

Add functions to get and clear pending events for Pm1EventRegisterBlock - #325

Open
ChocolateLoverRaj wants to merge 1 commit into
rust-osdev:mainfrom
ChocolateLoverRaj:pm1_events
Open

Add functions to get and clear pending events for Pm1EventRegisterBlock#325
ChocolateLoverRaj wants to merge 1 commit into
rust-osdev:mainfrom
ChocolateLoverRaj:pm1_events

Conversation

@ChocolateLoverRaj

Copy link
Copy Markdown

Closes #323

@ChocolateLoverRaj
ChocolateLoverRaj marked this pull request as ready for review August 27, 2026 05:55
@ChocolateLoverRaj

Copy link
Copy Markdown
Author

I tested this on QEMU q35 and on a Lenovo Z560 laptop. In my OS I was able to receive interrupts when the power button is pressed. Read the events, which contained power button, cleared the events, and then when I pressed the power button again I got another interrupt. Both machines use I/O address space and event length of 4.

Comment thread src/address.rs
}

/// Ignores the GAS access size and does a 16-bit read.
pub fn read_u16(&self, byte_offset: u64) -> u16 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if a cleaner way of doing this would be to have a method to derive a GenericAddress with a different access width from another one? (i.e. 'split' the GAS into the different registers?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that. Then we could make functions for getting the status register and getting the control register. Would the derived GAS use lifetimes or Arc?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a random thought - splitting a MappedGas has the potential to create fun with PhysicalMapping::drop, because you'll need to ensure the PhysicalMapping gets dropped only once. So if you create two new MappedGas objects you could:

  • Create two new PhysicalMapping objects, one for each child. This would be wasteful but safe (I think)
  • Wrap the child MappedGas Handlers in ManuallyDrop or similar - but then the split MappedGas objects have a different type to the originals.

I suppose what I'm trying to say is to be careful 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yes, very true Martin 😬

I wonder if the safest way would be to have a 'cast' effectively fn cast(self) -> MappedGas and some sort of way to duplicate a mapping, but that does seem inefficient? Maybe this isn't so bad after all?

Comment thread src/registers.rs
Pm1EventFlags::from_bits_retain(bits)
}

pub fn clear_events(&self, events: Pm1EventFlags) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't read the spec on this in quite a while (but remember wiring this up locally ages ago) - is it a useful API to clear all events, or would it be better to clear a specific event that you've handled (I assume by writing with an individual bit set)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I have it now where you specify which events to clear is better. If you clear all events, you might miss an event.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I somehow misread this as clearing all the events. Yes, this is good.

@IsaacWoods

Copy link
Copy Markdown
Member

Lovely, thank you for working on this! I think I got this working on QEMU a while ago on my OS but likely with some changes that haven't yet made it upstream. Just a few questions from my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Pm1EventRegisterBlock status get and clear

3 participants