Repository navigation
Rework GAS accesses to fixed register blocks #373
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
Merged
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
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 |
|---|---|---|
|
|
@@ -169,39 +169,88 @@ impl Fadt { | |
| } | ||
| } | ||
|
|
||
| pub fn pm1a_event_block(&self) -> Result<GenericAddress, AcpiError> { | ||
| /// Construct two `GenericAddress`s for the two registers within the PM1a event block - | ||
| /// `PM1a_STS` and `PM1a_EN`. Each register consists of half of the overall event register | ||
| /// block. | ||
| pub fn pm1a_event_block(&self) -> Result<(GenericAddress, GenericAddress), AcpiError> { | ||
| if let Some(raw) = unsafe { self.x_pm1a_event_block.access(self.header().revision) } | ||
| && raw.address != 0x0 | ||
| { | ||
| return GenericAddress::from_raw(raw); | ||
| let block = GenericAddress::from_raw(raw)?; | ||
| let sts = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: block.bit_width / 2, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: block.address, | ||
| }; | ||
| let en = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: block.bit_width / 2, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: block.address + (block.bit_width / 2 / 8) as u64, | ||
| }; | ||
| Ok((sts, en)) | ||
| } else { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice bit of extra compatibility, like it 😄 |
||
| // Calculate individual register width **in bytes** - half the block is STS, half EN | ||
| let reg_width = self.pm1_event_length / 2; | ||
| let sts = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: reg_width * 8, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: u64::from(self.pm1a_event_block), | ||
| }; | ||
| let en = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: reg_width * 8, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: u64::from(self.pm1a_event_block) + reg_width as u64, | ||
| }; | ||
| Ok((sts, en)) | ||
| } | ||
|
|
||
| Ok(GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: self.pm1_event_length * 8, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: self.pm1a_event_block.into(), | ||
| }) | ||
| } | ||
|
|
||
| pub fn pm1b_event_block(&self) -> Result<Option<GenericAddress>, AcpiError> { | ||
| pub fn pm1b_event_block(&self) -> Result<Option<(GenericAddress, GenericAddress)>, AcpiError> { | ||
| if let Some(raw) = unsafe { self.x_pm1b_event_block.access(self.header().revision) } | ||
| && raw.address != 0x0 | ||
| { | ||
| return Ok(Some(GenericAddress::from_raw(raw)?)); | ||
| } | ||
|
|
||
| if self.pm1b_event_block != 0 { | ||
| Ok(Some(GenericAddress { | ||
| let block = GenericAddress::from_raw(raw)?; | ||
| let sts = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: self.pm1_event_length * 8, | ||
| bit_width: block.bit_width / 2, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: self.pm1b_event_block.into(), | ||
| })) | ||
| address: block.address, | ||
| }; | ||
| let en = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: block.bit_width / 2, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: block.address + (block.bit_width / 2 / 8) as u64, | ||
| }; | ||
| Ok(Some((sts, en))) | ||
| } else { | ||
| Ok(None) | ||
| // Calculate individual register width **in bytes** - half the block is STS, half EN | ||
| let reg_width = self.pm1_event_length / 2; | ||
| let sts = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: reg_width * 8, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: u64::from(self.pm1b_event_block), | ||
| }; | ||
| let en = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: reg_width * 8, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: u64::from(self.pm1b_event_block) + reg_width as u64, | ||
| }; | ||
| Ok(Some((sts, en))) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -288,43 +337,85 @@ impl Fadt { | |
| } | ||
| } | ||
|
|
||
| pub fn gpe0_block(&self) -> Result<Option<GenericAddress>, AcpiError> { | ||
| pub fn gpe0_block(&self) -> Result<Option<(GenericAddress, GenericAddress)>, AcpiError> { | ||
| if let Some(raw) = unsafe { self.x_gpe0_block.access(self.header().revision) } | ||
| && raw.address != 0x0 | ||
| { | ||
| return Ok(Some(GenericAddress::from_raw(raw)?)); | ||
| } | ||
|
|
||
| if self.gpe0_block != 0 { | ||
| Ok(Some(GenericAddress { | ||
| let block = GenericAddress::from_raw(raw)?; | ||
| let sts = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: self.gpe0_block_length * 8, | ||
| bit_width: block.bit_width / 2, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: self.gpe0_block.into(), | ||
| })) | ||
| address: block.address, | ||
| }; | ||
| let en = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: block.bit_width / 2, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: block.address + (block.bit_width / 2 / 8) as u64, | ||
| }; | ||
| Ok(Some((sts, en))) | ||
| } else { | ||
| Ok(None) | ||
| // Calculate individual register width **in bytes** - half the block is STS, half EN | ||
| let reg_width = self.gpe0_block_length / 2; | ||
| let sts = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: reg_width * 8, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: u64::from(self.gpe0_block), | ||
| }; | ||
| let en = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: reg_width * 8, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: u64::from(self.gpe0_block) + reg_width as u64, | ||
| }; | ||
| Ok(Some((sts, en))) | ||
| } | ||
| } | ||
|
|
||
| pub fn gpe1_block(&self) -> Result<Option<GenericAddress>, AcpiError> { | ||
| pub fn gpe1_block(&self) -> Result<Option<(GenericAddress, GenericAddress)>, AcpiError> { | ||
| if let Some(raw) = unsafe { self.x_gpe1_block.access(self.header().revision) } | ||
| && raw.address != 0x0 | ||
| { | ||
| return Ok(Some(GenericAddress::from_raw(raw)?)); | ||
| } | ||
|
|
||
| if self.gpe1_block != 0 { | ||
| Ok(Some(GenericAddress { | ||
| let block = GenericAddress::from_raw(raw)?; | ||
| let sts = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: self.gpe1_block_length * 8, | ||
| bit_width: block.bit_width / 2, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: self.gpe1_block.into(), | ||
| })) | ||
| address: block.address, | ||
| }; | ||
| let en = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: block.bit_width / 2, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: block.address + (block.bit_width / 2 / 8) as u64, | ||
| }; | ||
| Ok(Some((sts, en))) | ||
| } else { | ||
| Ok(None) | ||
| // Calculate individual register width **in bytes** - half the block is STS, half EN | ||
| let reg_width = self.gpe1_block_length / 2; | ||
| let sts = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: reg_width * 8, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: u64::from(self.gpe1_block), | ||
| }; | ||
| let en = GenericAddress { | ||
| address_space: AddressSpace::SystemIo, | ||
| bit_width: reg_width * 8, | ||
| bit_offset: 0, | ||
| access_size: 0, | ||
| address: u64::from(self.gpe1_block) + reg_width as u64, | ||
| }; | ||
| Ok(Some((sts, en))) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a minimum width specified in the spec? (I can't see one...) What happens if the width ends up less than the size of
PM1a_STS? (Also the same question for the other registers)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think yes - it's mentioned in §4.8.1.1 of the 6.6 spec that "The PM1 event register block has a minimum size of 4 bytes", so each register will have a minimum size of the 16 currently-defined bits.
We could add some extra checks around this (?assume block is 4 bytes if size seems incorrect etc.) to deal with especially broken FADTs but could wait for a broken firmware to demonstrate that's an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot! Think I saw that and read it as "minimum size of 4 bits" 🤦
I think waiting for a broken firmware is fair - at some point you have to trust the firmware isn't completely broken!