hyperv_ic_protocol/
shutdown.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Protocol for shutdown IC.
5
6use crate::Version;
7use bitfield_struct::bitfield;
8use guid::Guid;
9use zerocopy::FromBytes;
10use zerocopy::Immutable;
11use zerocopy::IntoBytes;
12use zerocopy::KnownLayout;
13
14/// The unique vmbus interface ID of the shutdown IC.
15pub const INTERFACE_ID: Guid = guid::guid!("0e0b6031-5213-4934-818b-38d90ced39db");
16/// The unique vmbus instance ID of the shutdown IC.
17pub const INSTANCE_ID: Guid = guid::guid!("b6650ff7-33bc-4840-8048-e0676786f393");
18
19/// Version 1.0.
20pub const SHUTDOWN_VERSION_1: Version = Version::new(1, 0);
21/// Version 3.0.
22pub const SHUTDOWN_VERSION_3: Version = Version::new(3, 0);
23/// Version 3.1.
24pub const SHUTDOWN_VERSION_3_1: Version = Version::new(3, 1);
25/// Version 3.2.
26pub const SHUTDOWN_VERSION_3_2: Version = Version::new(3, 2);
27
28/// The message for shutdown initiated from the host.
29#[repr(C)]
30#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
31pub struct ShutdownMessage {
32    /// The shutdown reason.
33    pub reason_code: u32,
34    /// The maximum amount of time allotted to the guest to perform the
35    /// shutdown.
36    pub timeout_secs: u32,
37    /// Flags for the shutdown request.
38    pub flags: ShutdownFlags,
39    /// Friendly text string for the shutdown request.
40    pub message: [u8; 2048],
41}
42
43/// Flags for shutdown.
44#[bitfield(u32)]
45#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
46pub struct ShutdownFlags {
47    /// Whether the shutdown operation is being forced.
48    pub force: bool,
49    /// Flag indicating the shutdown behavior is guest restart.
50    pub restart: bool,
51    /// Flag indicating the shutdown behavior is guest hibernate.
52    pub hibernate: bool,
53    /// Reserved -- must be zero.
54    #[bits(29)]
55    _reserved: u32,
56}
57
58/// Reason code for '[ShutdownMessage]', from Windows SDK.
59pub const SHTDN_REASON_FLAG_PLANNED: u32 = 0x80000000;