File tree Expand file tree Collapse file tree
vm-core/src/virtualization
vm-firmware/src/acpi/type Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ use crate::virtualization::vcpu::command::VcpuCommandRequest;
2121use crate :: virtualization:: vcpu:: command:: VcpuCommandResponse ;
2222use crate :: virtualization:: vcpu:: error:: VcpuError ;
2323
24+ #[ cfg( target_arch = "x86_64" ) ]
25+ mod cpu_id;
2426mod vm_exit;
2527
2628pub struct KvmVcpuInternal < ' a > {
@@ -57,7 +59,17 @@ impl KvmVcpu {
5759 ) -> Result < Self , VcpuError > {
5860 let mut vcpu_fd = vm_fd. create_vcpu ( vcpu_id) ?;
5961 #[ cfg( target_arch = "x86_64" ) ]
60- vcpu_fd. set_cpuid2 ( supported_cpuid) ?;
62+ {
63+ use crate :: virtualization:: kvm:: vcpu:: cpu_id:: update_cpuid;
64+
65+ let cpuid = update_cpuid (
66+ supported_cpuid,
67+ vcpu_id
68+ . try_into ( )
69+ . map_err ( |_| VcpuError :: UpdateCpuid ( "vcpu_id too large" ) ) ?,
70+ ) ;
71+ vcpu_fd. set_cpuid2 ( & cpuid) ?;
72+ }
6173
6274 let ( command_tx, mut command_rx) = mpsc:: channel ( 8 ) ;
6375 let is_running = Arc :: new ( AtomicBool :: new ( false ) ) ;
Original file line number Diff line number Diff line change 1+ use kvm_bindings:: CpuId ;
2+
3+ pub fn update_cpuid ( cpuid : & CpuId , vcpu_id : u8 ) -> CpuId {
4+ let mut cpuid = cpuid. clone ( ) ;
5+
6+ for entry in cpuid. as_mut_slice ( ) {
7+ match entry. function {
8+ // Version and Features
9+ 0x01 => {
10+ entry. ebx &= 0xffffff ;
11+ // Update INITIAL_APIC_ID
12+ entry. ebx |= ( vcpu_id as u32 ) << 24 ;
13+ }
14+ _ => continue ,
15+ }
16+ }
17+
18+ cpuid
19+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ use crate::cpu::vm_exit::VmExitHandlerError;
44
55#[ derive( Error , Debug ) ]
66pub enum VcpuError {
7+ #[ error( "Failed to update cpuid, err: {0}" ) ]
8+ UpdateCpuid ( & ' static str ) ,
9+
710 #[ error( "Vcpu command channel disconnected" ) ]
811 VcpuCommandDisconnected ,
912
Original file line number Diff line number Diff line change @@ -9,8 +9,6 @@ pub struct Dummy;
99
1010impl Dummy {
1111 pub fn new ( pio_allocator : & mut RangeAllocator < u16 > ) -> Result < Self , DeviceError > {
12- let _ = pio_allocator. reserve ( 0x1004 , 1 ) ?;
13- let _ = pio_allocator. reserve ( 0x1006 , 1 ) ?;
1412 let _ = pio_allocator. reserve ( 0x87 , 1 ) ?;
1513
1614 Ok ( Dummy )
@@ -33,12 +31,11 @@ impl Device for Dummy {
3331
3432impl PioDevice for Dummy {
3533 fn ports ( & self ) -> Vec < Range < u16 > > {
34+ let range = 0x87 ..0x88 ;
35+
3636 vec ! [
37- // acpi pm1a
38- 0x1004 ..0x1005 ,
39- 0x1006 ..0x1007 ,
40- // TODO
41- 0x87 ..0x88 ,
37+ // TODO: What's this
38+ range,
4239 ]
4340 }
4441
Original file line number Diff line number Diff line change @@ -14,6 +14,16 @@ use crate::acpi::r#type::common_header::CommonHeader;
1414use crate :: acpi:: r#type:: generic_address_structure_format:: GenericAddressStructureFormat ;
1515use crate :: acpi:: utils:: checksum;
1616
17+ // A zero indicates the power button is handled as a fixed feature programming model;
18+ // a one indicates the power button is handled as a control method device.
19+ // If the system does not have a power button, this value would be “1” and no power button device would be present.
20+ const ACPI_FADT_POWER_BUTTON : u32 = 1 << 4 ; /* 04: [V1] Power button is handled as a control method device */
21+ // A zero indicates the sleep button is handled as a fixed feature programming model;
22+ // a one indicates the sleep button is handled as a control method device.
23+ // If the system does not have a sleep button, this value would be “1” and no sleep button device would be present.
24+ const ACPI_FADT_SLEEP_BUTTON : u32 = 1 << 5 ; /* 05: [V1] Sleep button is handled as a control method device */
25+ const FADT_F_HW_REDUCED_ACPI : u32 = 1 << 20 ; /* 20: [V5] ACPI hardware is not implemented (ACPI 5.0) */
26+
1727#[ derive( Default , Immutable , IntoBytes ) ]
1828#[ repr( C , packed) ]
1929pub struct Fadt {
@@ -89,20 +99,10 @@ impl Fadt {
8999 creator_id : CREATOR_ID ,
90100 creator_revision : CREATOR_REVISION ,
91101 } ,
92- flags : 0 ,
102+ flags : ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON | FADT_F_HW_REDUCED_ACPI ,
93103 fadt_minor_version : 5 , // ACPI 6.6 specification says it is 5.
94104 x_dsdt,
95105 hypervisor_vendor_id : HYPERVISOR_VENDOR_ID ,
96- // TODO
97- pm1a_cnt_blk : 0x1000 ,
98- // TODO
99- pm1_evt_len : 16 ,
100- // TODO
101- pm1a_evt_blk : 0x1004 ,
102- // TODO
103- pm1_cnt_len : 32 ,
104- // TODO
105- sci_int : 9 ,
106106 ..Default :: default ( )
107107 } ;
108108
You can’t perform that action at this time.
0 commit comments