diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index baa914e8f..42c50642e 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -109,7 +109,6 @@ void init_pcpu_pre(bool is_bsp) (void)parse_hv_cmdline(); /* - * WARNNING: here assume that vaddr2paddr is identical mapping. * Enable UART as early as possible. * Then we could use printf for debugging on early boot stage. */ @@ -132,6 +131,12 @@ void init_pcpu_pre(bool is_bsp) init_e820(); init_paging(); + /* + * Need update uart_base_address here for vaddr2paddr mapping may changed + * WARNNING: DO NOT CALL PRINTF BETWEEN ENABLE PAGING IN init_paging AND HERE! + */ + uart16550_init(false); + early_init_lapic(); init_vboot(); diff --git a/hypervisor/boot/cmdline.c b/hypervisor/boot/cmdline.c index cb8500b07..4e6c59df1 100644 --- a/hypervisor/boot/cmdline.c +++ b/hypervisor/boot/cmdline.c @@ -24,7 +24,7 @@ int32_t parse_hv_cmdline(void) return -EINVAL; } - mbi = (struct multiboot_info *)(hpa2hva((uint64_t)boot_regs[1])); + mbi = (struct multiboot_info *)(hpa2hva_early((uint64_t)boot_regs[1])); dev_dbg(ACRN_DBG_PARSE, "Multiboot detected, flag=0x%x", mbi->mi_flags); if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) == 0U) { @@ -32,7 +32,7 @@ int32_t parse_hv_cmdline(void) return -EINVAL; } - start = (char *)hpa2hva((uint64_t)mbi->mi_cmdline); + start = (char *)hpa2hva_early((uint64_t)mbi->mi_cmdline); dev_dbg(ACRN_DBG_PARSE, "hv cmdline: %s", start); do { diff --git a/hypervisor/debug/console.c b/hypervisor/debug/console.c index 3390a9c62..f439e487d 100644 --- a/hypervisor/debug/console.c +++ b/hypervisor/debug/console.c @@ -24,7 +24,6 @@ uint16_t console_vmid = ACRN_INVALID_VMID; void console_init(void) { - uart16550_init(false); } void console_putc(const char *ch) diff --git a/hypervisor/debug/uart16550.c b/hypervisor/debug/uart16550.c index 98837a6b2..77c68aea7 100644 --- a/hypervisor/debug/uart16550.c +++ b/hypervisor/debug/uart16550.c @@ -138,6 +138,7 @@ void uart16550_init(bool eraly_boot) } if (!eraly_boot && !uart.serial_port_mapped) { + uart.mmio_base_vaddr = hpa2hva(hva2hpa_early(uart.mmio_base_vaddr)); hv_access_memory_region_update((uint64_t)uart.mmio_base_vaddr, PDE_SIZE); return; } @@ -146,7 +147,7 @@ void uart16550_init(bool eraly_boot) if (!uart.serial_port_mapped) { serial_pci_bdf.value = get_pci_bdf_value(pci_bdf_info); uart.mmio_base_vaddr = - hpa2hva(pci_pdev_read_cfg(serial_pci_bdf, pci_bar_offset(0), 4U) & PCIM_BAR_MEM_BASE); + hpa2hva_early(pci_pdev_read_cfg(serial_pci_bdf, pci_bar_offset(0), 4U) & PCIM_BAR_MEM_BASE); } spinlock_init(&uart.rx_lock); diff --git a/hypervisor/include/arch/x86/pgtable.h b/hypervisor/include/arch/x86/pgtable.h index 0c6493b23..b9a05eb3d 100644 --- a/hypervisor/include/arch/x86/pgtable.h +++ b/hypervisor/include/arch/x86/pgtable.h @@ -145,6 +145,29 @@ * @{ */ /* hpa <--> hva, now it is 1:1 mapping */ +/** + * @brief Translate host-physical address to host-virtual address + * + * @param[in] x The specified host-physical address + * + * @return The translated host-virtual address + */ +static inline void *hpa2hva_early(uint64_t x) +{ + return (void *)x; +} +/** + * @brief Translate host-virtual address to host-physical address + * + * @param[in] x The specified host-virtual address + * + * @return The translated host-physical address + */ +static inline uint64_t hva2hpa_early(void *x) +{ + return (uint64_t)x; +} + /** * @brief Translate host-physical address to host-virtual address *