11// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4+ #[ cfg( target_arch = "x86_64" ) ]
45use acpi_tables:: { Aml , aml} ;
56use vm_memory:: GuestMemoryError ;
67
78use crate :: Vm ;
8- #[ cfg( target_arch = "x86_64" ) ]
99use crate :: devices:: acpi:: vmclock:: VmClock ;
1010use crate :: devices:: acpi:: vmgenid:: VmGenId ;
1111use crate :: vstate:: resources:: ResourceAllocator ;
@@ -23,7 +23,6 @@ pub struct ACPIDeviceManager {
2323 /// VMGenID device
2424 pub vmgenid : VmGenId ,
2525 /// VMclock device
26- #[ cfg( target_arch = "x86_64" ) ]
2726 pub vmclock : VmClock ,
2827}
2928
@@ -32,7 +31,6 @@ impl ACPIDeviceManager {
3231 pub fn new ( resource_allocator : & mut ResourceAllocator ) -> Self {
3332 ACPIDeviceManager {
3433 vmgenid : VmGenId :: new ( resource_allocator) ,
35- #[ cfg( target_arch = "x86_64" ) ]
3634 vmclock : VmClock :: new ( resource_allocator) ,
3735 }
3836 }
@@ -43,19 +41,19 @@ impl ACPIDeviceManager {
4341 Ok ( ( ) )
4442 }
4543
46- #[ cfg( target_arch = "x86_64" ) ]
4744 pub fn attach_vmclock ( & self , vm : & Vm ) -> Result < ( ) , ACPIDeviceError > {
45+ vm. register_irq ( & self . vmclock . interrupt_evt , self . vmclock . gsi ) ?;
4846 self . vmclock . activate ( vm. guest_memory ( ) ) ?;
4947 Ok ( ( ) )
5048 }
5149}
5250
51+ #[ cfg( target_arch = "x86_64" ) ]
5352impl Aml for ACPIDeviceManager {
5453 fn append_aml_bytes ( & self , v : & mut Vec < u8 > ) -> Result < ( ) , aml:: AmlError > {
5554 // AML for [`VmGenId`] device.
5655 self . vmgenid . append_aml_bytes ( v) ?;
5756 // AML for [`VmClock`] device.
58- #[ cfg( target_arch = "x86_64" ) ]
5957 self . vmclock . append_aml_bytes ( v) ?;
6058
6159 // Create the AML for the GED interrupt handler
@@ -65,30 +63,37 @@ impl Aml for ACPIDeviceManager {
6563 & aml:: Name :: new( "_HID" . try_into( ) ?, & "ACPI0013" ) ?,
6664 & aml:: Name :: new(
6765 "_CRS" . try_into( ) ?,
68- & aml:: ResourceTemplate :: new( vec![ & aml:: Interrupt :: new(
69- true ,
70- true ,
71- false ,
72- false ,
73- self . vmgenid. gsi,
74- ) ] ) ,
66+ & aml:: ResourceTemplate :: new( vec![
67+ & aml:: Interrupt :: new( true , true , false , false , self . vmgenid. gsi) ,
68+ & aml:: Interrupt :: new( true , true , false , false , self . vmclock. gsi) ,
69+ ] ) ,
7570 ) ?,
71+ // We know that the maximum IRQ number fits in a u8. We have up to
72+ // 32 IRQs in x86 and up to 128 in ARM (look into `vmm::crate::arch::layout::GSI_LEGACY_END`).
73+ // Both `vmgenid.gsi` and `vmclock.gsi` can safely be cast to `u8`
74+ // without truncation, so we let clippy know.
7675 & aml:: Method :: new(
7776 "_EVT" . try_into( ) ?,
7877 1 ,
7978 true ,
80- vec![ & aml:: If :: new(
81- // We know that the maximum IRQ number fits in a u8. We have up to
82- // 32 IRQs in x86 and up to 128 in
83- // ARM (look into
84- // `vmm::crate::arch::layout::GSI_LEGACY_END`)
85- #[ allow( clippy:: cast_possible_truncation) ]
86- & aml:: Equal :: new( & aml:: Arg ( 0 ) , & ( self . vmgenid. gsi as u8 ) ) ,
87- vec![ & aml:: Notify :: new(
88- & aml:: Path :: new( "\\ _SB_.VGEN" ) ?,
89- & 0x80usize ,
90- ) ] ,
91- ) ] ,
79+ vec![
80+ & aml:: If :: new(
81+ #[ allow( clippy:: cast_possible_truncation) ]
82+ & aml:: Equal :: new( & aml:: Arg ( 0 ) , & ( self . vmgenid. gsi as u8 ) ) ,
83+ vec![ & aml:: Notify :: new(
84+ & aml:: Path :: new( "\\ _SB_.VGEN" ) ?,
85+ & 0x80usize ,
86+ ) ] ,
87+ ) ,
88+ & aml:: If :: new(
89+ #[ allow( clippy:: cast_possible_truncation) ]
90+ & aml:: Equal :: new( & aml:: Arg ( 0 ) , & ( self . vmclock. gsi as u8 ) ) ,
91+ vec![ & aml:: Notify :: new(
92+ & aml:: Path :: new( "\\ _SB_.VCLK" ) ?,
93+ & 0x80usize ,
94+ ) ] ,
95+ ) ,
96+ ] ,
9297 ) ,
9398 ] ,
9499 )
0 commit comments