Skip to content

Commit cc47dbe

Browse files
lifeixacrnsi
authored andcommitted
hv: uart: enable early boot uart
Enable uart as early as possible to make things easier for debugging. After this we could use printf to output information to the uart. As for pr_xxx APIs, they start to work when init_logmsg is called. Tracked-On: #2987 Signed-off-by: Li, Fei1 <fei1.li@intel.com>
1 parent 3945bc4 commit cc47dbe

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <cat.h>
2727
#include <vboot.h>
2828
#include <sgx.h>
29+
#include <uart16550.h>
2930

3031
#define CPU_UP_TIMEOUT 100U /* millisecond */
3132
#define CPU_DOWN_TIMEOUT 100U /* millisecond */
@@ -106,6 +107,14 @@ void init_pcpu_pre(bool is_bsp)
106107
/* Clear BSS */
107108
(void)memset(&ld_bss_start, 0U, (size_t)(&ld_bss_end - &ld_bss_start));
108109

110+
(void)parse_hv_cmdline();
111+
/*
112+
* WARNNING: here assume that vaddr2paddr is identical mapping.
113+
* Enable UART as early as possible.
114+
* Then we could use printf for debugging on early boot stage.
115+
*/
116+
uart16550_init(true);
117+
109118
/* Get CPU capabilities thru CPUID, including the physical address bit
110119
* limit which is required for initializing paging.
111120
*/

hypervisor/boot/guest/deprivilege_boot.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ static void init_depri_boot(void)
2626
struct multiboot_info *mbi = NULL;
2727

2828
if (!depri_initialized) {
29-
(void)parse_hv_cmdline();
30-
3129
mbi = (struct multiboot_info *) hpa2hva(((uint64_t)(uint32_t)boot_regs[1]));
3230
if ((mbi == NULL) || ((mbi->mi_flags & MULTIBOOT_INFO_HAS_DRIVES) == 0U)) {
3331
pr_err("no multiboot drivers for depri_boot found");

hypervisor/debug/console.c

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

2525
void console_init(void)
2626
{
27-
uart16550_init();
27+
uart16550_init(false);
2828
}
2929

3030
void console_putc(const char *ch)

hypervisor/debug/uart16550.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,24 @@ static void uart16550_set_baud_rate(uint32_t baud_rate)
131131
uart16550_write_reg(uart, temp_reg, UART16550_LCR);
132132
}
133133

134-
void uart16550_init(void)
134+
void uart16550_init(bool eraly_boot)
135135
{
136136
if (!uart.enabled) {
137137
return;
138138
}
139139

140+
if (!eraly_boot && !uart.serial_port_mapped) {
141+
hv_access_memory_region_update((uint64_t)uart.mmio_base_vaddr, PDE_SIZE);
142+
return;
143+
}
144+
140145
/* if configure serial PCI BDF, get its base MMIO address */
141146
if (!uart.serial_port_mapped) {
142147
serial_pci_bdf.value = get_pci_bdf_value(pci_bdf_info);
143148
uart.mmio_base_vaddr =
144149
hpa2hva(pci_pdev_read_cfg(serial_pci_bdf, pci_bar_offset(0), 4U) & PCIM_BAR_MEM_BASE);
145150
}
146151

147-
if (!uart.serial_port_mapped) {
148-
hv_access_memory_region_update((uint64_t)uart.mmio_base_vaddr, PDE_SIZE);
149-
}
150-
151152
spinlock_init(&uart.rx_lock);
152153
spinlock_init(&uart.tx_lock);
153154
/* Enable TX and RX FIFOs */

hypervisor/include/debug/uart16550.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
/* UART oscillator clock */
128128
#define UART_CLOCK_RATE 1843200U /* 1.8432 MHz */
129129

130-
void uart16550_init(void);
130+
void uart16550_init(bool early_boot);
131131
char uart16550_getc(void);
132132
size_t uart16550_puts(const char *buf, uint32_t len);
133133
void uart16550_set_property(bool enabled, bool port_mapped, uint64_t base_addr);

hypervisor/release/uart16550.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (C) 2019 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#include <types.h>
8+
9+
void uart16550_init(__unused bool early_boot) {}

0 commit comments

Comments
 (0)