From b50519651c7323d51da649a923cd122216fa8051 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 27 Sep 2021 14:52:10 +0100 Subject: [PATCH] vmm: Simplify slot eject code in PCI ACPI device code Use a simpler method for extracting the affected slot on the eject command. Also update the terminology to reflect that this a slot rather than a bdf (which is what device id refers to elsewhere.) Signed-off-by: Rob Bradford --- vmm/src/device_manager.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index d3421a0f6..bc720aad4 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -4439,7 +4439,7 @@ impl BusDevice for DeviceManager { assert!(data.len() == B0EJ_FIELD_SIZE); // Always return an empty bitmap since the eject is always // taken care of right away during a write access. - data.copy_from_slice(&[0, 0, 0, 0]); + data.fill(0); } _ => error!( "Accessing unknown location at base 0x{:x}, offset 0x{:x}", @@ -4459,15 +4459,14 @@ impl BusDevice for DeviceManager { assert!(data.len() == B0EJ_FIELD_SIZE); let mut data_array: [u8; 4] = [0, 0, 0, 0]; data_array.copy_from_slice(data); - let device_bitmap = u32::from_le_bytes(data_array); + let mut slot_bitmap = u32::from_le_bytes(data_array); - for device_id in 0..32 { - let mask = 1u32 << device_id; - if (device_bitmap & mask) == mask { - if let Err(e) = self.eject_device(device_id as u8) { - error!("Failed ejecting device {}: {:?}", device_id, e); - } + while slot_bitmap > 0 { + let slot_id = slot_bitmap.trailing_zeros(); + if let Err(e) = self.eject_device(slot_id as u8) { + error!("Failed ejecting device {}: {:?}", slot_id, e); } + slot_bitmap &= !(1 << slot_id); } } _ => error!(