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 },
45}
46
47/// IDE device configuration.
48#[derive(Debug, MeshPayload)]
49pub struct IdeDeviceConfig {
50 /// The location of the device on the controller.
51 pub path: IdePath,
52 /// The backing media for the device.
53 pub guest_media: GuestMedia,
54}
55
56/// IDE controller configuration.
57#[derive(Debug, MeshPayload)]
58pub struct IdeControllerConfig {
59 /// Disks on the primary channel.
60 pub primary_channel_disks: Vec<IdeDeviceConfig>,
61 /// Disks on the secondary channel.
62 pub secondary_channel_disks: Vec<IdeDeviceConfig>,
63 /// The maximum queue depth for the vmbus SCSI interface.
64 pub io_queue_depth: Option<u32>,
65}