serial_debugcon/
resolver.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Resource resolver for a serial debugcon chipset device.

use crate::SerialDebugcon;
use async_trait::async_trait;
use chipset_device_resources::ResolveChipsetDeviceHandleParams;
use chipset_device_resources::ResolvedChipsetDevice;
use serial_core::resources::ResolveSerialBackendParams;
use serial_debugcon_resources::SerialDebugconDeviceHandle;
use thiserror::Error;
use vm_resource::AsyncResolveResource;
use vm_resource::ResolveError;
use vm_resource::ResourceResolver;
use vm_resource::declare_static_async_resolver;
use vm_resource::kind::ChipsetDeviceHandleKind;

/// The resource resolver for [`SerialDebugcon`].
pub struct SerialDebugconResolver;

declare_static_async_resolver! {
    SerialDebugconResolver,
    (ChipsetDeviceHandleKind, SerialDebugconDeviceHandle),
}

/// An error resolving a [`SerialDebugconDeviceHandle`].
#[expect(missing_docs)]
#[derive(Debug, Error)]
pub enum ResolveDebugconError {
    #[error("failed to resolve io backend")]
    ResolveBackend(#[source] ResolveError),
}

#[async_trait]
impl AsyncResolveResource<ChipsetDeviceHandleKind, SerialDebugconDeviceHandle>
    for SerialDebugconResolver
{
    type Output = ResolvedChipsetDevice;
    type Error = ResolveDebugconError;

    async fn resolve(
        &self,
        resolver: &ResourceResolver,
        resource: SerialDebugconDeviceHandle,
        input: ResolveChipsetDeviceHandleParams<'_>,
    ) -> Result<Self::Output, Self::Error> {
        let io = resolver
            .resolve(
                resource.io,
                ResolveSerialBackendParams {
                    driver: Box::new(input.task_driver_source.simple()),
                    _async_trait_workaround: &(),
                },
            )
            .await
            .map_err(ResolveDebugconError::ResolveBackend)?;

        let device = SerialDebugcon::new(resource.port, io.0.into_io());
        Ok(device.into())
    }
}