ide_resources/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Client definitions for describing IDE controller configuration.
5//!
6//! TODO: refactor to support `Resource`-based instantiation of IDE controllers,
7//! at which point this crate name makes sense.
8
9#![forbid(unsafe_code)]
10
11use inspect::Inspect;
12use mesh::MeshPayload;
13use vm_resource::Resource;
14use vm_resource::kind::DiskHandleKind;
15use vm_resource::kind::ScsiDeviceHandleKind;
16
17/// The location of an IDE device on a controller.
18#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash, MeshPayload, Inspect)]
19#[inspect(display)]
20pub struct IdePath {
21    /// The channel number. Must be zero or one.
22    pub channel: u8,
23    /// The device number on the channel. Must be zero or one.
24    pub drive: u8,
25}
26
27impl std::fmt::Display for IdePath {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        write!(f, "{}/{}", self.channel, self.drive)
30    }
31}
32
33/// Guest media for an IDE device.
34#[derive(Debug, MeshPayload)]
35pub enum GuestMedia {
36    /// An ATAPI drive, backed by a SCSI device.
37    Dvd(Resource<ScsiDeviceHandleKind>),
38    /// An ATA disk, backed by a disk.
39    Disk {
40        /// The backing disk.
41        disk_type: Resource<DiskHandleKind>,
42        /// Whether the disk is read-only.
43        read_only: bool,
44        /// The disk parameters, used for the vmbus SCSI interface.
45        disk_parameters: Option<scsidisk_resources::DiskParameters>,
46    },
47}
48
49/// IDE device configuration.
50#[derive(Debug, MeshPayload)]
51pub struct IdeDeviceConfig {
52    /// The location of the device on the controller.
53    pub path: IdePath,
54    /// The backing media for the device.
55    pub guest_media: GuestMedia,
56}
57
58/// IDE controller configuration.
59#[derive(Debug, MeshPayload)]
60pub struct IdeControllerConfig {
61    /// Disks on the primary channel.
62    pub primary_channel_disks: Vec<IdeDeviceConfig>,
63    /// Disks on the secondary channel.
64    pub secondary_channel_disks: Vec<IdeDeviceConfig>,
65    /// The maximum queue depth for the vmbus SCSI interface.
66    pub io_queue_depth: Option<u32>,
67}