Skip to content

Commit 688b26a

Browse files
committed
uefi: protocols: cleanup test_protocol[_by_guid]()
The majority of our protocol-related public functions use a generic approach with `<P: ProtocolPointer + ?Sized>`. Unfortunately: - we are inconsistent with that - this hinders some use-cases where the GUID is only known at runtime Therefore, this is the first commit of a series of commits that improves the situation by providing base functions that use the generic-based API and `by_guid` counterparts for more runtime- flexibility.
1 parent 78162c0 commit 688b26a

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

uefi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Added `proto::pci::root_bridge::PciRootBridgeIo::enumerate()`.
88
- Added `proto::nvme::pass_thru::NvmePassThru::broadcast()`.
99
- Added `proto::media::block::BlockIO2`.
10+
- Added `boot::test_protocol_by_guid()`
1011

1112
## Changed
1213
- Changed ordering of `proto::pci::PciIoAddress` to (bus -> dev -> fun -> reg -> ext_reg).

uefi/src/boot.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,14 @@ pub fn open_protocol_exclusive<P: ProtocolPointer + ?Sized>(
11431143
///
11441144
/// * [`Status::INVALID_PARAMETER`]: one of the handles in `params` is invalid.
11451145
pub fn test_protocol<P: ProtocolPointer + ?Sized>(params: OpenProtocolParams) -> Result<bool> {
1146+
test_protocol_by_guid(&P::GUID, params)
1147+
}
1148+
1149+
/// Variant of [`test_protocol_by_guid`] that consumes the [`Guid`] as
1150+
/// parameter.
1151+
pub fn test_protocol_by_guid(guid: &Guid, params: OpenProtocolParams) -> Result<bool> {
1152+
// Not part of `OpenProtocolAttributes` as it is fairly irrelevant for
1153+
// library users.
11461154
const TEST_PROTOCOL: u32 = 0x04;
11471155

11481156
let bt = boot_services_raw_panicking();
@@ -1152,7 +1160,7 @@ pub fn test_protocol<P: ProtocolPointer + ?Sized>(params: OpenProtocolParams) ->
11521160
let status = unsafe {
11531161
(bt.open_protocol)(
11541162
params.handle.as_ptr(),
1155-
&P::GUID,
1163+
guid,
11561164
&mut interface,
11571165
params.agent.as_ptr(),
11581166
Handle::opt_to_ptr(params.controller),

0 commit comments

Comments
 (0)