Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement base for PCI Root bridge io protocols #1724

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

Open
tmvkrpxl0 wants to merge 4 commits into rust-osdev:main
base: main
Choose a base branch
Loading
from tmvkrpxl0:pci_protocol_base

Conversation

Copy link

@tmvkrpxl0 tmvkrpxl0 commented Jul 17, 2025

This is continuation of #1705
As requested by @phil-opp I decided to split the pr into multiple.
This one only contains base for the upcoming other PRs.
Specifically, it contains wrapper for pages allocated and regions mapped by the protocol.
and it adds new pci device with big memory for testing memory protocols later.
Since no protocol is submitted yet users wont be able to use this for now.

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

@tmvkrpxl0 tmvkrpxl0 marked this pull request as ready for review July 18, 2025 01:43

impl Drop for PciMappedRegion<'_, '_> {
fn drop(&mut self) {
let status = unsafe { (self.proto.unmap)(self.proto, self.key) };
Copy link
Member

@nicholasbishop nicholasbishop Aug 2, 2025

Choose a reason for hiding this comment

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

Would it make sense to add a fn unmap(self) -> Result method, so that callers can choose to handle errors from unmapping? The Drop trait doesn't really allow that. I think the drop implementation should probably not panic on errors, and that we should remove the unreachable; UEFI implementations sometimes return additional errors beyond what the spec includes.

Ditto for the PciPage implementation.

phip1611 reacted with thumbs up emoji
Copy link
Author

@tmvkrpxl0 tmvkrpxl0 Aug 3, 2025

Choose a reason for hiding this comment

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

True, I initially put unreachable macro there to indicate that "errors that may happen according to spec are all handled and no other error can occur"
But yeah second thought we can never be sure

Copy link
Author

@tmvkrpxl0 tmvkrpxl0 Aug 3, 2025

Choose a reason for hiding this comment

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

Tho, what else should it do when an error occurs? Should I make it undroppable(assuming it's possible) so that users must use functions like unmap?

Copy link
Member

@nicholasbishop nicholasbishop Aug 8, 2025

Choose a reason for hiding this comment

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

There's no way to make something undroppable in Rust, unfortunately. There are two options:

  • A 'drop bomb', i.e. panic unconditionally in drop if unmap wasn't called. The documentation should strongly remind the user that unmap must be called.
  • Handle errors in drop by ignoring them (or log them and otherwise ignore). The documentation can encourage users to call unmap for better error handling, but it's not required. This is what File does, for example; it suggests calling sync_all before drop if you want to handle errors.

In cases where errors are unlikely (which I think is the case here), I prefer the 2nd option; log errors in drop but otherwise ignore them.

Copy link
Author

Well test fails on windows because it can't use new pci memory device

Copy link
Member

Well test fails on windows because it can't use new pci memory device

Might need to just skip this test on Windows. Take a look at https://github.com/rust-osdev/uefi-rs/blob/main/xtask/src/main.rs#L149 for examples of how we control test features.

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

@nicholasbishop nicholasbishop nicholasbishop left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /