mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
arch: Serializable CPUID parameters
We introduce a type representing CPUID parameters that will be utilized by the CPU profiles. We place this new type in a module that will be further populated with types related to adjusting CPUID entries based on the CPU profile in a follow up commit. Signed-off-by: Oliver Anderson <oliver.anderson@cyberus-technology.de> On-behalf-of: SAP oliver.anderson@sap.com
This commit is contained in:
committed by
Rob Bradford
parent
7700f4b585
commit
9f38cec485
66
arch/src/x86_64/cpu_profile/cpuid_adjustments.rs
Normal file
66
arch/src/x86_64/cpu_profile/cpuid_adjustments.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright © 2026 Cyberus Technology GmbH
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
//! This module contains types associated with adjusting CPUID entries according
|
||||
//! to a selected CPU profile.
|
||||
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::x86_64::{CpuidReg, deserialize_u32_hex, serialize_u32_hex};
|
||||
|
||||
/// Parameters for inspecting CPUID definitions.
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct CpuidParameters {
|
||||
/// The leaf (EAX) parameter used with the CPUID instruction
|
||||
#[serde(
|
||||
serialize_with = "serialize_u32_hex",
|
||||
deserialize_with = "deserialize_u32_hex"
|
||||
)]
|
||||
pub leaf: u32,
|
||||
/// The sub-leaf (ECX) parameter used with the CPUID instruction
|
||||
#[serde(
|
||||
serialize_with = "serialize_range_hex",
|
||||
deserialize_with = "deserialize_range_hex"
|
||||
)]
|
||||
pub sub_leaf: RangeInclusive<u32>,
|
||||
/// The register we are interested in inspecting which gets filled by the CPUID instruction
|
||||
pub register: CpuidReg,
|
||||
}
|
||||
|
||||
// Only used for (de-)serialization
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct ProvisionalRangeInclusive {
|
||||
#[serde(
|
||||
serialize_with = "serialize_u32_hex",
|
||||
deserialize_with = "deserialize_u32_hex"
|
||||
)]
|
||||
start: u32,
|
||||
#[serde(
|
||||
serialize_with = "serialize_u32_hex",
|
||||
deserialize_with = "deserialize_u32_hex"
|
||||
)]
|
||||
end: u32,
|
||||
}
|
||||
|
||||
fn serialize_range_hex<S: serde::Serializer>(
|
||||
input: &RangeInclusive<u32>,
|
||||
serializer: S,
|
||||
) -> Result<S::Ok, S::Error> {
|
||||
let provisional = ProvisionalRangeInclusive {
|
||||
start: *input.start(),
|
||||
end: *input.end(),
|
||||
};
|
||||
provisional.serialize(serializer)
|
||||
}
|
||||
|
||||
fn deserialize_range_hex<'de, D: serde::Deserializer<'de>>(
|
||||
deserializer: D,
|
||||
) -> Result<RangeInclusive<u32>, D::Error> {
|
||||
let ProvisionalRangeInclusive { start, end } =
|
||||
ProvisionalRangeInclusive::deserialize(deserializer)?;
|
||||
Ok(start..=end)
|
||||
}
|
||||
6
arch/src/x86_64/cpu_profile/mod.rs
Normal file
6
arch/src/x86_64/cpu_profile/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
// Copyright © 2026 Cyberus Technology GmbH
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
pub mod cpuid_adjustments;
|
||||
@@ -7,6 +7,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE-BSD-3-Clause file.
|
||||
|
||||
pub mod cpu_profile;
|
||||
pub mod interrupts;
|
||||
pub mod layout;
|
||||
pub mod regs;
|
||||
|
||||
Reference in New Issue
Block a user