hv: mmu: add hpa2hva_early API for earlt boot

When need hpa and hva translation before init_paging, we need hpa2hva_early and
hva2hpa_early since init_paging may modify hva2hpa to not be identical mapping.

Tracked-On: #2987
Signed-off-by: Li, Fei1 <fei1.li@intel.com>
This commit is contained in:
Li, Fei1 2019-07-24 18:03:44 +08:00 committed by ACRN System Integration
parent 40475e22b8
commit 11cf9a4a8a
5 changed files with 33 additions and 5 deletions

View File

@ -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();

View File

@ -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 {

View File

@ -24,7 +24,6 @@ uint16_t console_vmid = ACRN_INVALID_VMID;
void console_init(void)
{
uart16550_init(false);
}
void console_putc(const char *ch)

View File

@ -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);

View File

@ -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
*