vmm_core/
platform_resolvers.rs1use crate::partition_unit::Halt;
5use chipset_resources::ioapic::IoApicRoutingHandleKind;
6use power_resources::PowerRequest;
7use power_resources::PowerRequestClient;
8use power_resources::PowerRequestHandleKind;
9use std::convert::Infallible;
10use std::sync::Arc;
11use vm_resource::PlatformResource;
12use vm_resource::ResolveResource;
13use vmm_core_defs::HaltReason;
14
15pub struct HaltResolver(pub Arc<Halt>);
17
18impl ResolveResource<PowerRequestHandleKind, PlatformResource> for HaltResolver {
19 type Output = PowerRequestClient;
20 type Error = Infallible;
21
22 fn resolve(
23 &self,
24 _resource: PlatformResource,
25 _input: (),
26 ) -> Result<Self::Output, Self::Error> {
27 let halt = self.0.clone();
28 Ok((move |request: PowerRequest| match request {
29 PowerRequest::PowerOff => halt.halt(HaltReason::PowerOff),
30 PowerRequest::Reset => halt.halt(HaltReason::Reset),
31 PowerRequest::Hibernate => halt.halt(HaltReason::Hibernate),
32 PowerRequest::TripleFault { vp } => halt.halt(HaltReason::TripleFault {
33 vp,
34 registers: None,
35 }),
36 })
37 .into())
38 }
39}
40
41pub struct IoApicRoutingResolver<T: ?Sized>(pub Arc<T>);
45
46impl<T: ?Sized + virt::irqcon::IoApicRouting + 'static>
47 ResolveResource<IoApicRoutingHandleKind, PlatformResource> for IoApicRoutingResolver<T>
48{
49 type Output = chipset_resources::ioapic::ResolvedIoApicRouting;
50 type Error = Infallible;
51
52 fn resolve(
53 &self,
54 _resource: PlatformResource,
55 _input: (),
56 ) -> Result<Self::Output, Self::Error> {
57 Ok(chipset_resources::ioapic::ResolvedIoApicRouting(Box::new(
58 crate::emuplat::ioapic::IoApicRouting(self.0.clone()),
59 )))
60 }
61}