Skip to content

Commit fc8bda5

Browse files
authored
Merge pull request #1345 from nicholasbishop/bishop-component-name-drop-bs
uefi: Drop BootServices arg from ComponentName::open
2 parents 0aed47a + cd4e814 commit fc8bda5

File tree

4 files changed

+35
-38
lines changed

4 files changed

+35
-38
lines changed

uefi-test-runner/src/proto/driver.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
use uefi::boot::{self, ScopedProtocol, SearchType};
12
use uefi::prelude::*;
23
use uefi::proto::driver::{ComponentName, ComponentName2, LanguageError, LanguageIter};
3-
use uefi::table::boot::{ScopedProtocol, SearchType};
44
use uefi::{CStr16, Result};
55

66
#[allow(deprecated)]
77
use uefi::proto::driver::ComponentName1;
88

99
/// Generic interface for testing `ComponentName1`, `ComponentName2`, and
1010
/// `ComponentName`.
11-
trait ComponentNameInterface<'a>: Sized {
12-
fn open(boot_services: &'a BootServices, handle: Handle) -> Result<Self>;
11+
trait ComponentNameInterface: Sized {
12+
fn open(handle: Handle) -> Result<Self>;
1313
fn supported_languages(&self) -> core::result::Result<LanguageIter, LanguageError>;
1414
fn driver_name(&self, language: &str) -> Result<&CStr16>;
1515
fn controller_name(
@@ -21,9 +21,9 @@ trait ComponentNameInterface<'a>: Sized {
2121
}
2222

2323
#[allow(deprecated)]
24-
impl<'a> ComponentNameInterface<'a> for ScopedProtocol<'a, ComponentName1> {
25-
fn open(boot_services: &'a BootServices, handle: Handle) -> Result<Self> {
26-
boot_services.open_protocol_exclusive::<ComponentName1>(handle)
24+
impl ComponentNameInterface for ScopedProtocol<ComponentName1> {
25+
fn open(handle: Handle) -> Result<Self> {
26+
boot::open_protocol_exclusive::<ComponentName1>(handle)
2727
}
2828

2929
fn supported_languages(&self) -> core::result::Result<LanguageIter, LanguageError> {
@@ -44,9 +44,9 @@ impl<'a> ComponentNameInterface<'a> for ScopedProtocol<'a, ComponentName1> {
4444
}
4545
}
4646

47-
impl<'a> ComponentNameInterface<'a> for ScopedProtocol<'a, ComponentName2> {
48-
fn open(boot_services: &'a BootServices, handle: Handle) -> Result<Self> {
49-
boot_services.open_protocol_exclusive::<ComponentName2>(handle)
47+
impl ComponentNameInterface for ScopedProtocol<ComponentName2> {
48+
fn open(handle: Handle) -> Result<Self> {
49+
boot::open_protocol_exclusive::<ComponentName2>(handle)
5050
}
5151

5252
fn supported_languages(&self) -> core::result::Result<LanguageIter, LanguageError> {
@@ -67,9 +67,9 @@ impl<'a> ComponentNameInterface<'a> for ScopedProtocol<'a, ComponentName2> {
6767
}
6868
}
6969

70-
impl<'a> ComponentNameInterface<'a> for ComponentName<'a> {
71-
fn open(boot_services: &'a BootServices, handle: Handle) -> Result<Self> {
72-
Self::open(boot_services, handle)
70+
impl ComponentNameInterface for ComponentName {
71+
fn open(handle: Handle) -> Result<Self> {
72+
Self::open(handle)
7373
}
7474

7575
fn supported_languages(&self) -> core::result::Result<LanguageIter, LanguageError> {
@@ -90,13 +90,8 @@ impl<'a> ComponentNameInterface<'a> for ComponentName<'a> {
9090
}
9191
}
9292

93-
fn test_component_name<'a, C: ComponentNameInterface<'a>>(
94-
boot_services: &'a BootServices,
95-
english: &str,
96-
) {
97-
let all_handles = boot_services
98-
.locate_handle_buffer(SearchType::AllHandles)
99-
.unwrap();
93+
fn test_component_name<C: ComponentNameInterface>(english: &str) {
94+
let all_handles = boot::locate_handle_buffer(SearchType::AllHandles).unwrap();
10095

10196
let fat_driver_name = cstr16!("FAT File System Driver");
10297
let fat_controller_name = cstr16!("FAT File System");
@@ -105,7 +100,7 @@ fn test_component_name<'a, C: ComponentNameInterface<'a>>(
105100
let component_name: C = all_handles
106101
.iter()
107102
.find_map(|handle| {
108-
let component_name = C::open(boot_services, *handle).ok()?;
103+
let component_name = C::open(*handle).ok()?;
109104

110105
assert!(component_name
111106
.supported_languages()
@@ -138,11 +133,11 @@ fn test_component_name<'a, C: ComponentNameInterface<'a>>(
138133
.expect("failed to find FAT controller");
139134
}
140135

141-
pub fn test(boot_services: &BootServices) {
136+
pub fn test() {
142137
info!("Running component name test");
143138

144139
#[allow(deprecated)]
145-
test_component_name::<ScopedProtocol<ComponentName1>>(boot_services, "eng");
146-
test_component_name::<ScopedProtocol<ComponentName2>>(boot_services, "en");
147-
test_component_name::<ComponentName>(boot_services, "en");
140+
test_component_name::<ScopedProtocol<ComponentName1>>("eng");
141+
test_component_name::<ScopedProtocol<ComponentName2>>("en");
142+
test_component_name::<ComponentName>("en");
148143
}

uefi-test-runner/src/proto/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn test(st: &mut SystemTable<Boot>) {
1616

1717
debug::test(bt);
1818
device_path::test(bt);
19-
driver::test(bt);
19+
driver::test();
2020
load::test(bt);
2121
loaded_image::test(bt);
2222
media::test(bt);

uefi/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ how to integrate the `uefi` crate into them.
1212
take a `BootServices` argument. The global system table is used instead.
1313
- **Breaking:** `GraphicsOutput::modes` no longer takes a `BootServices`
1414
argument. The global system table is used instead.
15+
- **Breaking:** `ComponentName::open` no longer takes a `BootServices`
16+
argument. The global system table is used instead.
1517
- `allocator::init` and `allocator::exit_boot_services` have been
1618
deprecated. These functions are now no-ops. The allocator now internally uses
1719
the global system table.

uefi/src/proto/driver/component_name.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// allow more fine-grained, see https://github.com/rust-lang/rust/issues/62398.
55
#![allow(deprecated)]
66

7+
use crate::boot::{self, ScopedProtocol};
78
use crate::proto::unsafe_protocol;
8-
use crate::table::boot::{BootServices, ScopedProtocol};
99
use crate::{CStr16, Error, Handle, Result, Status, StatusExt};
1010
use core::fmt::{self, Debug, Display, Formatter};
1111
use core::{ptr, slice};
@@ -153,24 +153,24 @@ impl ComponentName2 {
153153
/// Wrapper around [`ComponentName1`] and [`ComponentName2`]. This will use
154154
/// [`ComponentName2`] if available, otherwise it will back to
155155
/// [`ComponentName1`].
156-
pub enum ComponentName<'a> {
156+
pub enum ComponentName {
157157
/// Opened [`ComponentName1`] protocol.
158-
V1(ScopedProtocol<'a, ComponentName1>),
158+
V1(ScopedProtocol<ComponentName1>),
159159

160160
/// Opened [`ComponentName2`] protocol.
161-
V2(ScopedProtocol<'a, ComponentName2>),
161+
V2(ScopedProtocol<ComponentName2>),
162162
}
163163

164-
impl<'a> ComponentName<'a> {
164+
impl ComponentName {
165165
/// Open the [`ComponentName2`] protocol if available, otherwise fall back to
166166
/// [`ComponentName1`].
167-
pub fn open(boot_services: &'a BootServices, handle: Handle) -> Result<Self> {
168-
if let Ok(cn2) = boot_services.open_protocol_exclusive::<ComponentName2>(handle) {
167+
pub fn open(handle: Handle) -> Result<Self> {
168+
if let Ok(cn2) = boot::open_protocol_exclusive::<ComponentName2>(handle) {
169169
Ok(Self::V2(cn2))
170170
} else {
171-
Ok(Self::V1(
172-
boot_services.open_protocol_exclusive::<ComponentName1>(handle)?,
173-
))
171+
Ok(Self::V1(boot::open_protocol_exclusive::<ComponentName1>(
172+
handle,
173+
)?))
174174
}
175175
}
176176

@@ -219,11 +219,11 @@ impl<'a> ComponentName<'a> {
219219
}
220220
}
221221

222-
impl<'a> Debug for ComponentName<'a> {
222+
impl Debug for ComponentName {
223223
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
224224
match self {
225-
ComponentName::V1(_) => f.debug_tuple("V1").finish(),
226-
ComponentName::V2(_) => f.debug_tuple("V2").finish(),
225+
Self::V1(_) => f.debug_tuple("V1").finish(),
226+
Self::V2(_) => f.debug_tuple("V2").finish(),
227227
}
228228
}
229229
}

0 commit comments

Comments
 (0)