-
-
Notifications
You must be signed in to change notification settings - Fork 173
Implement rest of Pci Root Bridge Io protocol #1705
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
base: main
Are you sure you want to change the base?
Conversation
Currently |
I switched to GhostCell and finally got rid of that weird design where the self parameter can only be |
This allows PciRootBridgeIo to be used as `protocol.copy_mem` instead of `PciRootBridgeIo::copy_mem(protocol, ...)`
Well that was very messy but I finally cleaned out the git history. I think I'm ready for review. |
@@ -21,6 +21,7 @@ rust-version = "1.85.1" | |||
[dependencies] | |||
bitflags.workspace = true | |||
uguid.workspace = true | |||
static_assertions.workspace = true |
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'm not a fan of adding a new dependency at this point. For consistency with the code base, please add a unit test instead. Something like
#[test]
fn test_abi() {
assert_eq(size_of<...>, 0x123);
}
etc
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.
You can also do a static assert manually, e.g. something like:
const _ASSERT_S_SIZE: () = {
if core::mem::size_of::<S>() != 0x123 {
panic!("bad size");
}
};
Example in the playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=4dff15892d952d56edd3b79911f29581
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 point! But for consistency with the code base, I have a tendency towards a unit test.
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.
One potential reason to prefer a static assert is that it ensures the 'test' is run under the correct target. Unit tests are run on the host target, e.g. x86_64-unknown-linux-gnu
. Generally this won't matter, but e.g. if the struct contained a usize
field, the size of the struct might be different on i686-unknown-uefi
. Not sure that's really relevant here though, so +1 to your point about consistency and just doing it as a unit test.
I decided to implement missing features of Pci IO root bridge. It's not complete yet and I'm opening this PR beforehand to get a review.
Protocols to implement
Design Questions
All design questions are resolved as of now
I had to use RefCell for allocate, free, map, unmap and copy because I wanted allocated buffer and mapped region to clean themselves after they're dropped by calling free/unmap, and track their lifetimes so that they do not outlive protocol which allocated them (as it's required to free themselves), and for map function, do not outlive region they map.I couldn't just use normal reference because copy method requires mutable pointer. I wasn't sure if I can turn this into const pointer because some other functions inPciRootBridgeIoProtocol
struct takes in const pointer, so the original author for it must considered implications of this and I figured I should follow it.However it's quite ugly now and users must use these functions likePciRootBridgeIo::map
instead ofprotocol.map
Ideally it should work like this:
Fixed by switching to GhostCell
Does using GhostCell feel good?Currently the test methods are written as such:Now all methods ofPciRootBridgeIo
only needs shared reference to itself but all of them also take in either shared or mutable reference toGhostToken
And theGhostToken
is wrapped inRefCell
as some types likePciMappedRegion
orPciBuffer
needs mutable reference toGhostToken
but I don't want these to block others from using it either.Fixed by switching everything to shared reference. mutable reference is no longer needed.
Checklist