From ced74e6f2f4653049fc9a23959214bd9b3a3ab4a Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 22 May 2019 10:24:24 -0700 Subject: devices: cmos: report memory size in CMOS This matches the QEMU CMOS implementation and is used by BIOSes to determine the valid memory regions to add to the e820 map. BUG=b:133358982 TEST=Boot u-boot qemu build; observe memory size Change-Id: I27956bc05738b5dd5b84240d5137cb06846aaab9 Signed-off-by: Daniel Verkamp Reviewed-on: https://chromium-review.googlesource.com/1625330 Tested-by: kokoro Legacy-Commit-Queue: Commit Bot Reviewed-by: Dylan Reid --- x86_64/src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'x86_64') diff --git a/x86_64/src/lib.rs b/x86_64/src/lib.rs index 0a2185c..5e54e69 100644 --- a/x86_64/src/lib.rs +++ b/x86_64/src/lib.rs @@ -352,6 +352,7 @@ impl arch::LinuxArch for X8664arch { split_irqchip, exit_evt.try_clone().map_err(Error::CloneEventFd)?, Some(pci_bus.clone()), + components.memory_size, )?; let (stdio_serial_num, stdio_serial) = @@ -582,11 +583,13 @@ impl X8664arch { /// * - `vm` the vm object /// * - `split_irqchip`: whether to use a split IRQ chip (i.e. userspace PIT/PIC/IOAPIC) /// * - `exit_evt` - the event fd object which should receive exit events + /// * - `mem_size` - the size in bytes of physical ram for the guest fn setup_io_bus( vm: &mut Vm, split_irqchip: bool, exit_evt: EventFd, pci: Option>>, + mem_size: u64, ) -> Result<(devices::Bus)> { struct NoDevice; impl devices::BusDevice for NoDevice { @@ -597,8 +600,17 @@ impl X8664arch { let mut io_bus = devices::Bus::new(); + let mem_gap_start = FIRST_ADDR_PAST_32BITS - MEM_32BIT_GAP_SIZE; + let mem_below_4g = std::cmp::min(mem_gap_start, mem_size); + let mem_above_4g = mem_size.saturating_sub(FIRST_ADDR_PAST_32BITS); + io_bus - .insert(Arc::new(Mutex::new(devices::Cmos::new())), 0x70, 0x2, false) + .insert( + Arc::new(Mutex::new(devices::Cmos::new(mem_below_4g, mem_above_4g))), + 0x70, + 0x2, + false, + ) .unwrap(); io_bus .insert( -- cgit 1.4.1