-
-
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
Open
tmvkrpxl0
wants to merge
10
commits into
rust-osdev:main
Choose a base branch
from
tmvkrpxl0:pci_protocol
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.
+1,310
−42
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
29683ff
uefi: Implement PciRootBridgeIo::allocate_buffer
tmvkrpxl0 f5b6b95
uefi: Implement PciRootBridgeIo::map
tmvkrpxl0 4c76f96
uefi: Implement PciRootBridgeIo::copy
tmvkrpxl0 0dbfcfa
uefi: Use RefCell for allocate_buffer and map
tmvkrpxl0 ea65942
uefi: Switch to GhostCell
tmvkrpxl0 e31b213
uefi: Fix copy_mem test and implement access for io and memory space
tmvkrpxl0 173115f
uefi: Remove achieved TODO comments
tmvkrpxl0 eaee087
uefi: Remove GhostCell and implement PciRootBridgeIo::configuration
tmvkrpxl0 cec0f50
uefi: Implement polling for both IO and memory
tmvkrpxl0 a6b9f85
uefi: Implement get/set attributes
tmvkrpxl0 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
pub mod resource; | ||
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,108 @@ | ||
use bitflags::bitflags; | ||
use static_assertions::assert_eq_size; | ||
|
||
/// Descriptor for current PCI root bridge's configuration space. | ||
/// Specification: | ||
/// https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/06_Device_Configuration/Device_Configuration.html#qword-address-space-descriptor | ||
#[repr(C, packed)] | ||
#[derive(Debug)] | ||
pub struct QWordAddressSpaceDescriptor { | ||
pub tag: u8, | ||
pub descriptor_length: u16, | ||
pub resource_type: ResourceType, | ||
pub flags: GeneralFlags, | ||
pub type_flags: u8, | ||
pub address_granularity: u64, | ||
pub range_min: u64, | ||
pub range_max: u64, // inclusive | ||
pub translation_offset: u64, | ||
pub address_length: u64, | ||
} | ||
assert_eq_size!(QWordAddressSpaceDescriptor, [u8; 0x2E]); | ||
|
||
newtype_enum! { | ||
/// Indicates which type of resource this descriptor describes. | ||
pub enum ResourceType: u8 => { | ||
/// This resource describes range of memory. | ||
MEMORY = 0, | ||
|
||
/// This resource describes range of I/O ports. | ||
IO = 1, | ||
|
||
/// This resource describes range of Bus numbers. | ||
BUS = 2, | ||
} | ||
} | ||
|
||
bitflags! { | ||
#[repr(transparent)] | ||
#[derive(Debug, Copy, Clone)] | ||
pub struct GeneralFlags: u8 { | ||
/// Indicates maximum address is fixed. | ||
const MAX_ADDRESS_FIXED = 0b1000; | ||
|
||
/// Indicates minimum address is fixed. | ||
const MIN_ADDRESS_FIXED = 0b0100; | ||
|
||
/// Indicates if this bridge would subtract or positively decode address. | ||
/// 1 This bridge subtractively decodes this address (top level bridges only) | ||
/// 0 This bridge positively decodes this address | ||
const DECODE_TYPE = 0b0010; | ||
} | ||
} | ||
|
||
impl QWordAddressSpaceDescriptor { | ||
/// Verifies if given descriptor is valid according to specification. | ||
/// This also checks if all reserved bit fields which are supposed to be 0 are actually 0. | ||
pub fn verify(&self) { | ||
let tag = self.tag; | ||
if tag != 0x8A { | ||
panic!( | ||
"Tag value for QWordAddressSpaceDescriptor should be 0x8A, not {}", | ||
tag | ||
); | ||
} | ||
|
||
let length = self.descriptor_length; | ||
if self.descriptor_length != 0x2B { | ||
panic!( | ||
"Length value for QWordAddressSpaceDescriptor should be 0x2B, not {}", | ||
length | ||
); | ||
} | ||
|
||
if self.flags.bits() & 0b11110000 != 0 { | ||
panic!("Reserved bits for GeneralFlags are 1") | ||
} | ||
|
||
let type_flags = self.type_flags; | ||
match self.resource_type { | ||
ResourceType::MEMORY => { | ||
if type_flags & 0b11000000 != 0 { | ||
panic!("Reserved bits for Memory Type Flags are 1"); | ||
} | ||
} | ||
ResourceType::IO => { | ||
if type_flags & 0b11001100 != 0 { | ||
panic!("Reserved bits for IO Type Flags are 1"); | ||
} | ||
} | ||
ResourceType::BUS => { | ||
if type_flags != 0 { | ||
panic!("Bus type flags should be 0, not {}", type_flags); | ||
} | ||
} | ||
ResourceType(3..=191) => panic!("Invalid resource type: {}", self.resource_type.0), | ||
ResourceType(192..) => {} // Hardware defined range | ||
} | ||
|
||
let min = self.range_min; | ||
let max = self.range_max; | ||
if max < min { | ||
panic!( | ||
"Address range is invalid. Max(0x{:X}) is smaller than Min(0x{:X}).", | ||
max, min | ||
); | ||
} | ||
} | ||
} |
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
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.
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
etc