-
-
Notifications
You must be signed in to change notification settings - Fork 170
uefi-raw: Add binding for EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL #1658
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
seijikun
wants to merge
2
commits into
rust-osdev:main
Choose a base branch
from
seijikun:mr-pciroot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+193
−5
Open
Changes from all commits
Commits
Show all changes
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
pub mod root_bridge; |
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 |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
use crate::table::boot::{AllocateType, MemoryType}; | ||
use crate::{Handle, PhysicalAddress, Status}; | ||
use core::ffi::c_void; | ||
use uguid::{guid, Guid}; | ||
|
||
newtype_enum! { | ||
/// Corresponds to the `EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH` enum. | ||
pub enum PciRootBridgeIoProtocolWidth: u32 => { | ||
UINT8 = 0, | ||
UINT16 = 1, | ||
UINT32 = 2, | ||
UINT64 = 3, | ||
FIFO_UINT8 = 4, | ||
FIFO_UINT16 = 5, | ||
FIFO_UINT32 = 6, | ||
FIFO_UINT64 = 7, | ||
FILL_UINT8 = 8, | ||
FILL_UINT16 = 9, | ||
FILL_UINT32 = 10, | ||
FILL_UINT64 = 11, | ||
MAXIMUM = 12, | ||
} | ||
} | ||
|
||
newtype_enum! { | ||
/// Corresponds to the `EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION` enum. | ||
pub enum PciRootBridgeIoProtocolOperation: u32 => { | ||
BUS_MASTER_READ = 0, | ||
BUS_MASTER_WRITE = 1, | ||
BUS_MASTER_COMMON_BUFFER = 2, | ||
BUS_MASTER_READ64 = 3, | ||
BUS_MASTER_WRITE64 = 4, | ||
BUS_MASTER_COMMON_BUFFER64 = 5, | ||
MAXIMUM = 6, | ||
} | ||
} | ||
|
||
#[repr(C, packed)] | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub struct PciIoAddress { | ||
pub reg: u8, | ||
pub fun: u8, | ||
pub dev: u8, | ||
pub bus: u8, | ||
pub ext_reg: u32, | ||
} | ||
|
||
impl PciIoAddress { | ||
#[must_use] | ||
pub const fn new(bus: u8, dev: u8, fun: u8) -> Self { | ||
Self { | ||
bus, | ||
dev, | ||
fun, | ||
reg: 0, | ||
ext_reg: 0, | ||
} | ||
} | ||
|
||
#[must_use] | ||
pub const fn with_register(&self, reg: u8) -> Self { | ||
let mut addr = *self; | ||
addr.reg = reg; | ||
addr.ext_reg = 0; | ||
addr | ||
} | ||
|
||
#[must_use] | ||
pub const fn with_extended_register(&self, ext_reg: u32) -> Self { | ||
let mut addr = *self; | ||
addr.reg = 0; | ||
addr.ext_reg = ext_reg; | ||
addr | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
#[repr(C)] | ||
pub struct PciRootBridgeIoAccess<TAddr> { | ||
pub read: unsafe extern "efiapi" fn( | ||
this: *mut PciRootBridgeIoProtocol, | ||
width: PciRootBridgeIoProtocolWidth, | ||
address: TAddr, | ||
count: usize, | ||
buffer: *mut c_void, | ||
) -> Status, | ||
pub write: unsafe extern "efiapi" fn( | ||
this: *mut Self, | ||
width: PciRootBridgeIoProtocolWidth, | ||
address: TAddr, | ||
count: usize, | ||
buffer: *const c_void, | ||
) -> Status, | ||
} | ||
|
||
#[derive(Debug)] | ||
#[repr(C)] | ||
pub struct PciRootBridgeIoProtocol { | ||
pub parent_handle: Handle, | ||
pub poll_mem: unsafe extern "efiapi" fn( | ||
this: *mut Self, | ||
width: PciRootBridgeIoProtocolWidth, | ||
address: u64, | ||
mask: u64, | ||
value: u64, | ||
delay: u64, | ||
result: *mut u64, | ||
) -> Status, | ||
pub poll_io: unsafe extern "efiapi" fn( | ||
this: *mut Self, | ||
width: PciRootBridgeIoProtocolWidth, | ||
address: u64, | ||
mask: u64, | ||
value: u64, | ||
delay: u64, | ||
result: *mut u64, | ||
) -> Status, | ||
pub mem: PciRootBridgeIoAccess<u64>, | ||
pub io: PciRootBridgeIoAccess<u64>, | ||
pub pci: PciRootBridgeIoAccess<PciIoAddress>, | ||
pub copy_mem: unsafe extern "efiapi" fn( | ||
this: *mut Self, | ||
width: PciRootBridgeIoProtocolWidth, | ||
dest_addr: u64, | ||
src_addr: u64, | ||
count: usize, | ||
) -> Status, | ||
pub map: unsafe extern "efiapi" fn( | ||
this: *const Self, | ||
operation: PciRootBridgeIoProtocolOperation, | ||
host_addr: *const c_void, | ||
num_bytes: *mut usize, | ||
device_addr: *mut PhysicalAddress, | ||
mapping: *mut *mut c_void, | ||
) -> Status, | ||
pub unmap: unsafe extern "efiapi" fn(this: *const Self, mapping: *const c_void) -> Status, | ||
pub allocate_buffer: unsafe extern "efiapi" fn( | ||
this: *const Self, | ||
alloc_ty: AllocateType, | ||
memory_ty: MemoryType, | ||
pages: usize, | ||
host_addr: *mut *const c_void, | ||
attributes: u64, | ||
) -> Status, | ||
pub free_buffer: unsafe extern "efiapi" fn( | ||
this: *const Self, | ||
pages: usize, | ||
host_addr: *const c_void, | ||
) -> Status, | ||
pub flush: unsafe extern "efiapi" fn(this: *mut Self) -> Status, | ||
pub get_attributes: unsafe extern "efiapi" fn( | ||
this: *const Self, | ||
supports: *mut u64, | ||
attributes: *mut u64, | ||
) -> Status, | ||
pub set_attributes: unsafe extern "efiapi" fn( | ||
this: *mut Self, | ||
attributes: u64, | ||
resource_base: *mut u64, | ||
resource_length: *mut u64, | ||
) -> Status, | ||
pub configuration: | ||
unsafe extern "efiapi" fn(this: *const Self, resources: *mut *const c_void) -> Status, | ||
pub segment_number: u32, | ||
} | ||
|
||
impl PciRootBridgeIoProtocol { | ||
pub const GUID: Guid = guid!("2f707ebb-4a1a-11d4-9a38-0090273fc14d"); | ||
} |
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
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.
The uefi-raw crate doesn't normally use generics. I think in the spec the
address
is treated asu64
in all cases, even though for for pci specifically theu64
is broken down into subfields, so let's do that and leave higher-level abstractions to theuefi
crate.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.
Yes, the interface itself in the spec accepts a
u64
, because they use the same struct forpci
,memory
andio
.But the
pci
one is supposed to be filled by something like this:My thought process was: If they could have used templates/generics in their interface, they would have done it there.
At least I would like to have the PCI addressing somehow as part of the unsafe API, because otherwise you can't use it without reading the UEFI spec. Do you have an alternative suggestion? The only alternative I was able to come up with, was a
union
and that's IMHO ugly to use.