diff --git a/patina_dxe_core/src/dxe_dispatch_service.rs b/patina_dxe_core/src/dxe_dispatch_service.rs new file mode 100644 index 000000000..d665e60da --- /dev/null +++ b/patina_dxe_core/src/dxe_dispatch_service.rs @@ -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); + +impl CoreDxeDispatch { + /// Create a new dispatch service with the given dispatch function. + pub(crate) fn new(dispatch_fn: fn() -> Result) -> Self { + Self(dispatch_fn) + } +} + +impl DxeDispatch for CoreDxeDispatch { + fn dispatch(&self) -> Result { + (self.0)() + } +} diff --git a/patina_dxe_core/src/lib.rs b/patina_dxe_core/src/lib.rs index d09a24bfb..3dec04a98 100644 --- a/patina_dxe_core/src/lib.rs +++ b/patina_dxe_core/src/lib.rs @@ -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; @@ -474,6 +475,8 @@ impl Core

{ 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))); diff --git a/sdk/patina/src/component/service.rs b/sdk/patina/src/component/service.rs index a72c0a2cc..c0725fc70 100644 --- a/sdk/patina/src/component/service.rs +++ b/sdk/patina/src/component/service.rs @@ -124,6 +124,7 @@ use crate::component::{ storage::{Storage, UnsafeStorageCell}, }; +pub mod dxe_dispatch; pub mod memory; pub mod perf_timer; diff --git a/sdk/patina/src/component/service/dxe_dispatch.rs b/sdk/patina/src/component/service/dxe_dispatch.rs new file mode 100644 index 000000000..8872a9799 --- /dev/null +++ b/sdk/patina/src/component/service/dxe_dispatch.rs @@ -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; +}