Skip to content

Rework GAS accesses to fixed register blocks - #373

Merged
IsaacWoods merged 3 commits into
rust-osdev:mainfrom
IsaacWoods:main
Nov 3, 2026
Merged

IsaacWoods merged 3 commits into
rust-osdev:mainfrom
IsaacWoods:main

Conversation

@IsaacWoods

Copy link
Copy Markdown
Member

This removes the read_u16 and write_u16 methods on GenericAddress, and fixes accesses to the PM1 register blocks by splitting them into their component STS and EN registers.

This does throw in a few unrelated changes that I have had locally on my main branch from poor gitting I'm afraid - I have not rebased these off as I don't think they reduce reviewability and I'd like them to go in at some point.

cc @martin-hughes - we've discussed complexities around handling these accesses. I'd be interested in your thoughts on this solution.

@martin-hughes martin-hughes left a comment

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.

Nice one @IsaacWoods, I think this looks very sensible. I can't see why we shouldn't split the register into two MappedGass and I think it improves the ergonomics a lot.

One minor question in the review comments, but no reason not to merge if you're still happy with this.

Comment thread src/sdt/fadt.rs
let block = GenericAddress::from_raw(raw)?;
let sts = GenericAddress {
address_space: AddressSpace::SystemIo,
bit_width: block.bit_width / 2,

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.

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)

Copy link
Copy Markdown
Member Author

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?

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.

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"

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!

Comment thread src/sdt/fadt.rs
address: block.address + (block.bit_width / 2 / 8) as u64,
};
Ok((sts, en))
} else {

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.

Nice bit of extra compatibility, like it 😄

@martin-hughes

Copy link
Copy Markdown
Contributor

Actually, I did have a thought. Is it possible for the GAS Access Size to specify that both registers (both parts of pm1a for example) need to be written in one access?

@IsaacWoods

IsaacWoods commented Nov 3, 2026 •

Copy link
Copy Markdown
Member Author

Actually, I did have a thought. Is it possible for the GAS Access Size to specify that both registers (both parts of pm1a for example) need to be written in one access?

Good thought - I think my reading infers that these are two registers within a register block and so would ordinarily be separate. I think they just put them in a single GAS to save a field in the FADT. I want to get my kernel booting on some real hardware in the near future to give this a test but until then assume this will be fine.

Edit: I've checked and uACPI also splits the accesses to these registers. This feels like the most resilient approach to me so will get this merged!

Thanks for your review Martin!

@IsaacWoods
IsaacWoods merged commit 386035c into rust-osdev:main Nov 3, 2026
6 checks passed
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.

2 participants