Skip to content

Commit 11cf9a4

Browse files
lifeixacrnsi
authored andcommitted
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>
1 parent 40475e2 commit 11cf9a4

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ void init_pcpu_pre(bool is_bsp)
109109

110110
(void)parse_hv_cmdline();
111111
/*
112-
* WARNNING: here assume that vaddr2paddr is identical mapping.
113112
* Enable UART as early as possible.
114113
* Then we could use printf for debugging on early boot stage.
115114
*/
@@ -132,6 +131,12 @@ void init_pcpu_pre(bool is_bsp)
132131
init_e820();
133132
init_paging();
134133

134+
/*
135+
* Need update uart_base_address here for vaddr2paddr mapping may changed
136+
* WARNNING: DO NOT CALL PRINTF BETWEEN ENABLE PAGING IN init_paging AND HERE!
137+
*/
138+
uart16550_init(false);
139+
135140
early_init_lapic();
136141

137142
init_vboot();

hypervisor/boot/cmdline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ int32_t parse_hv_cmdline(void)
2424
return -EINVAL;
2525
}
2626

27-
mbi = (struct multiboot_info *)(hpa2hva((uint64_t)boot_regs[1]));
27+
mbi = (struct multiboot_info *)(hpa2hva_early((uint64_t)boot_regs[1]));
2828
dev_dbg(ACRN_DBG_PARSE, "Multiboot detected, flag=0x%x", mbi->mi_flags);
2929

3030
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) == 0U) {
3131
dev_dbg(ACRN_DBG_PARSE, "no hv cmdline!");
3232
return -EINVAL;
3333
}
3434

35-
start = (char *)hpa2hva((uint64_t)mbi->mi_cmdline);
35+
start = (char *)hpa2hva_early((uint64_t)mbi->mi_cmdline);
3636
dev_dbg(ACRN_DBG_PARSE, "hv cmdline: %s", start);
3737

3838
do {

hypervisor/debug/console.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ uint16_t console_vmid = ACRN_INVALID_VMID;
2424

2525
void console_init(void)
2626
{
27-
uart16550_init(false);
2827
}
2928

3029
void console_putc(const char *ch)

hypervisor/debug/uart16550.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void uart16550_init(bool eraly_boot)
138138
}
139139

140140
if (!eraly_boot && !uart.serial_port_mapped) {
141+
uart.mmio_base_vaddr = hpa2hva(hva2hpa_early(uart.mmio_base_vaddr));
141142
hv_access_memory_region_update((uint64_t)uart.mmio_base_vaddr, PDE_SIZE);
142143
return;
143144
}
@@ -146,7 +147,7 @@ void uart16550_init(bool eraly_boot)
146147
if (!uart.serial_port_mapped) {
147148
serial_pci_bdf.value = get_pci_bdf_value(pci_bdf_info);
148149
uart.mmio_base_vaddr =
149-
hpa2hva(pci_pdev_read_cfg(serial_pci_bdf, pci_bar_offset(0), 4U) & PCIM_BAR_MEM_BASE);
150+
hpa2hva_early(pci_pdev_read_cfg(serial_pci_bdf, pci_bar_offset(0), 4U) & PCIM_BAR_MEM_BASE);
150151
}
151152

152153
spinlock_init(&uart.rx_lock);

hypervisor/include/arch/x86/pgtable.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,29 @@
145145
* @{
146146
*/
147147
/* hpa <--> hva, now it is 1:1 mapping */
148+
/**
149+
* @brief Translate host-physical address to host-virtual address
150+
*
151+
* @param[in] x The specified host-physical address
152+
*
153+
* @return The translated host-virtual address
154+
*/
155+
static inline void *hpa2hva_early(uint64_t x)
156+
{
157+
return (void *)x;
158+
}
159+
/**
160+
* @brief Translate host-virtual address to host-physical address
161+
*
162+
* @param[in] x The specified host-virtual address
163+
*
164+
* @return The translated host-physical address
165+
*/
166+
static inline uint64_t hva2hpa_early(void *x)
167+
{
168+
return (uint64_t)x;
169+
}
170+
148171
/**
149172
* @brief Translate host-physical address to host-virtual address
150173
*

0 commit comments

Comments
 (0)