hypervisor: arch: Move common regs from arch to hypervisor crate

There are other potential users of these registers definitions in the
hypervisor crate. And hypervisor crate cannot use definitions from arch
crate because it creates cyclic dependency.

Signed-off-by: Jinank Jain <jinankjain@microsoft.com>
This commit is contained in:
Jinank Jain
2025-04-23 09:14:12 +00:00
parent 1968805ba2
commit 58f71b0c44
4 changed files with 51 additions and 56 deletions

View File

@@ -25,8 +25,6 @@ use std::{cmp, io, result, thread};
use acpi_tables::sdt::Sdt;
use acpi_tables::{aml, Aml};
use anyhow::anyhow;
#[cfg(all(target_arch = "aarch64", feature = "guest_debug"))]
use arch::aarch64::regs;
#[cfg(target_arch = "x86_64")]
use arch::x86_64::get_x2apic_id;
use arch::{EntryPoint, NumaNodes};
@@ -37,6 +35,8 @@ use devices::interrupt_controller::InterruptController;
use gdbstub_arch::aarch64::reg::AArch64CoreRegs as CoreRegs;
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use gdbstub_arch::x86::reg::{X86SegmentRegs, X86_64CoreRegs as CoreRegs};
#[cfg(all(target_arch = "aarch64", feature = "guest_debug"))]
use hypervisor::arch::aarch64::regs::{ID_AA64MMFR0_EL1, TCR_EL1, TTBR1_EL1};
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use hypervisor::arch::x86::msr_index;
#[cfg(target_arch = "x86_64")]
@@ -1703,19 +1703,19 @@ impl CpuManager {
.lock()
.unwrap()
.vcpu
.get_sys_reg(regs::TCR_EL1)
.get_sys_reg(TCR_EL1)
.map_err(|e| Error::TranslateVirtualAddress(e.into()))?;
let ttbr1_el1: u64 = self.vcpus[usize::from(cpu_id)]
.lock()
.unwrap()
.vcpu
.get_sys_reg(regs::TTBR1_EL1)
.get_sys_reg(TTBR1_EL1)
.map_err(|e| Error::TranslateVirtualAddress(e.into()))?;
let id_aa64mmfr0_el1: u64 = self.vcpus[usize::from(cpu_id)]
.lock()
.unwrap()
.vcpu
.get_sys_reg(regs::ID_AA64MMFR0_EL1)
.get_sys_reg(ID_AA64MMFR0_EL1)
.map_err(|e| Error::TranslateVirtualAddress(e.into()))?;
// Bit 55 of the VA determines the range, high (0xFFFxxx...)
@@ -2937,8 +2937,8 @@ mod tests {
#[cfg(feature = "kvm")]
use std::mem;
use arch::aarch64::regs;
use arch::layout;
use hypervisor::arch::aarch64::regs::MPIDR_EL1;
#[cfg(feature = "kvm")]
use hypervisor::kvm::aarch64::is_system_register;
#[cfg(feature = "kvm")]
@@ -2973,10 +2973,10 @@ mod tests {
vm.get_preferred_target(&mut kvi).unwrap();
// Must fail when vcpu is not initialized yet.
vcpu.get_sys_reg(regs::MPIDR_EL1).unwrap_err();
vcpu.get_sys_reg(MPIDR_EL1).unwrap_err();
vcpu.vcpu_init(&kvi).unwrap();
assert_eq!(vcpu.get_sys_reg(regs::MPIDR_EL1).unwrap(), 0x80000000);
assert_eq!(vcpu.get_sys_reg(MPIDR_EL1).unwrap(), 0x80000000);
}
#[cfg(feature = "kvm")]