Skip to content

uefi: Drop BootServices arg from ComponentName::open #1345

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions uefi-test-runner/src/proto/driver.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use uefi::boot::{self, ScopedProtocol, SearchType};
use uefi::prelude::*;
use uefi::proto::driver::{ComponentName, ComponentName2, LanguageError, LanguageIter};
use uefi::table::boot::{ScopedProtocol, SearchType};
use uefi::{CStr16, Result};

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

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

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

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

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

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

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

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

fn test_component_name<'a, C: ComponentNameInterface<'a>>(
boot_services: &'a BootServices,
english: &str,
) {
let all_handles = boot_services
.locate_handle_buffer(SearchType::AllHandles)
.unwrap();
fn test_component_name<C: ComponentNameInterface>(english: &str) {
let all_handles = boot::locate_handle_buffer(SearchType::AllHandles).unwrap();

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

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

pub fn test(boot_services: &BootServices) {
pub fn test() {
info!("Running component name test");

#[allow(deprecated)]
test_component_name::<ScopedProtocol<ComponentName1>>(boot_services, "eng");
test_component_name::<ScopedProtocol<ComponentName2>>(boot_services, "en");
test_component_name::<ComponentName>(boot_services, "en");
test_component_name::<ScopedProtocol<ComponentName1>>("eng");
test_component_name::<ScopedProtocol<ComponentName2>>("en");
test_component_name::<ComponentName>("en");
}
2 changes: 1 addition & 1 deletion uefi-test-runner/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn test(st: &mut SystemTable<Boot>) {

debug::test(bt);
device_path::test(bt);
driver::test(bt);
driver::test();
load::test(bt);
loaded_image::test(bt);
media::test(bt);
Expand Down
2 changes: 2 additions & 0 deletions uefi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ how to integrate the `uefi` crate into them.
take a `BootServices` argument. The global system table is used instead.
- **Breaking:** `GraphicsOutput::modes` no longer takes a `BootServices`
argument. The global system table is used instead.
- **Breaking:** `ComponentName::open` no longer takes a `BootServices`
argument. The global system table is used instead.
- `allocator::init` and `allocator::exit_boot_services` have been
deprecated. These functions are now no-ops. The allocator now internally uses
the global system table.
Expand Down
26 changes: 13 additions & 13 deletions uefi/src/proto/driver/component_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// allow more fine-grained, see https://github.com/rust-lang/rust/issues/62398.
#![allow(deprecated)]

use crate::boot::{self, ScopedProtocol};
use crate::proto::unsafe_protocol;
use crate::table::boot::{BootServices, ScopedProtocol};
use crate::{CStr16, Error, Handle, Result, Status, StatusExt};
use core::fmt::{self, Debug, Display, Formatter};
use core::{ptr, slice};
Expand Down Expand Up @@ -153,24 +153,24 @@ impl ComponentName2 {
/// Wrapper around [`ComponentName1`] and [`ComponentName2`]. This will use
/// [`ComponentName2`] if available, otherwise it will back to
/// [`ComponentName1`].
pub enum ComponentName<'a> {
pub enum ComponentName {
/// Opened [`ComponentName1`] protocol.
V1(ScopedProtocol<'a, ComponentName1>),
V1(ScopedProtocol<ComponentName1>),

/// Opened [`ComponentName2`] protocol.
V2(ScopedProtocol<'a, ComponentName2>),
V2(ScopedProtocol<ComponentName2>),
}

impl<'a> ComponentName<'a> {
impl ComponentName {
/// Open the [`ComponentName2`] protocol if available, otherwise fall back to
/// [`ComponentName1`].
pub fn open(boot_services: &'a BootServices, handle: Handle) -> Result<Self> {
if let Ok(cn2) = boot_services.open_protocol_exclusive::<ComponentName2>(handle) {
pub fn open(handle: Handle) -> Result<Self> {
if let Ok(cn2) = boot::open_protocol_exclusive::<ComponentName2>(handle) {
Ok(Self::V2(cn2))
} else {
Ok(Self::V1(
boot_services.open_protocol_exclusive::<ComponentName1>(handle)?,
))
Ok(Self::V1(boot::open_protocol_exclusive::<ComponentName1>(
handle,
)?))
}
}

Expand Down Expand Up @@ -219,11 +219,11 @@ impl<'a> ComponentName<'a> {
}
}

impl<'a> Debug for ComponentName<'a> {
impl Debug for ComponentName {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
ComponentName::V1(_) => f.debug_tuple("V1").finish(),
ComponentName::V2(_) => f.debug_tuple("V2").finish(),
Self::V1(_) => f.debug_tuple("V1").finish(),
Self::V2(_) => f.debug_tuple("V2").finish(),
}
}
}
Expand Down