Skip to content
Open
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
38 changes: 38 additions & 0 deletions patina_dxe_core/src/dxe_dispatch_service.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! DXE Core Dispatch Service
//!
//! Provides the [`CoreDxeDispatch`] service implementation, which exposes
//! the PI dispatcher to components via dependency injection. This allows
//! components to trigger DXE driver dispatch passes (e.g., to interleave
//! controller connection with driver dispatch during boot).
//!
//! ## License
//!
//! Copyright (c) Microsoft Corporation.
//!
//! SPDX-License-Identifier: Apache-2.0
//!
use patina::{
component::service::{IntoService, dxe_dispatch::DxeDispatch},
error::Result,
};

/// DXE dispatch service backed by the PI dispatcher.
///
/// Holds a function pointer to the concrete dispatch implementation,
/// set at construction during Core initialization.
#[derive(IntoService)]
#[service(dyn DxeDispatch)]
pub(crate) struct CoreDxeDispatch(fn() -> Result<bool>);

impl CoreDxeDispatch {
/// Create a new dispatch service with the given dispatch function.
pub(crate) fn new(dispatch_fn: fn() -> Result<bool>) -> Self {
Self(dispatch_fn)
}
}

impl DxeDispatch for CoreDxeDispatch {
fn dispatch(&self) -> Result<bool> {
(self.0)()
}
}
3 changes: 3 additions & 0 deletions patina_dxe_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ mod cpu;
mod debugger_reload;
mod decompress;
mod driver_services;
mod dxe_dispatch_service;
mod dxe_services;
mod event_db;
mod events;
Expand Down Expand Up @@ -474,6 +475,8 @@ impl<P: PlatformInfo> Core<P> {
component_dispatcher.add_service(cpu);
component_dispatcher.add_service(interrupt_manager);
component_dispatcher.add_service(CoreMemoryManager);
component_dispatcher
.add_service(dxe_dispatch_service::CoreDxeDispatch::new(|| Self::instance().pi_dispatcher.dispatch()));
component_dispatcher
.add_service(cpu::PerfTimer::with_frequency(P::CpuInfo::perf_timer_frequency().unwrap_or(0)));

Expand Down
1 change: 1 addition & 0 deletions sdk/patina/src/component/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ use crate::component::{
storage::{Storage, UnsafeStorageCell},
};

pub mod dxe_dispatch;
pub mod memory;
pub mod perf_timer;

Expand Down
28 changes: 28 additions & 0 deletions sdk/patina/src/component/service/dxe_dispatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//! DXE Dispatch Service Definition.
//!
//! This module contains the [`DxeDispatch`] trait for services that expose
//! DXE driver dispatch capability. See [`DxeDispatch`] for the primary interface.
//!
//! ## License
//!
//! Copyright (c) Microsoft Corporation.
//!
//! SPDX-License-Identifier: Apache-2.0
//!
#[cfg(any(test, feature = "mockall"))]
use mockall::automock;

use crate::error::Result;

/// Service interface for DXE driver dispatch.
///
/// Provides access to the PI dispatcher for components that need to trigger
/// driver dispatch passes (e.g., to interleave controller connection with
/// driver dispatch during boot).
#[cfg_attr(any(test, feature = "mockall"), automock)]
pub trait DxeDispatch {
/// Performs a single DXE driver dispatch pass.
///
/// Returns `true` if any drivers were dispatched, `false` if no drivers remain.
fn dispatch(&self) -> Result<bool>;
}
Loading