diff --git a/hypervisor/arch/x86/assign.c b/hypervisor/arch/x86/assign.c index 6c0a836d5..c011bcb44 100644 --- a/hypervisor/arch/x86/assign.c +++ b/hypervisor/arch/x86/assign.c @@ -46,8 +46,7 @@ is_entry_active(struct ptdev_remapping_info *entry) static bool ptdev_hv_owned_intx(struct vm *vm, union source_id *virt_sid) { /* vm0 pin 4 (uart) is owned by hypervisor under debug version */ - if (is_vm0(vm) && (vm->vuart != NULL) && - (virt_sid->intx_id.pin == 4U)) { + if (is_vm0(vm) && (virt_sid->intx_id.pin == 4U)) { return true; } else { return false; diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index d4b02a230..a1d6da8b1 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -199,14 +199,14 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm) } /* Create virtual uart */ - vm->vuart = vuart_init(vm); + vuart_init(vm); } vpic_init(vm); #ifdef CONFIG_PARTITION_MODE /* Create virtual uart */ if (vm_desc->vm_vuart) { - vm->vuart = vuart_init(vm); + vuart_init(vm); } vrtc_init(vm); vpci_init(vm); diff --git a/hypervisor/debug/console.c b/hypervisor/debug/console.c index 88a208840..a067ec0c2 100644 --- a/hypervisor/debug/console.c +++ b/hypervisor/debug/console.c @@ -34,7 +34,7 @@ char console_getc(void) static void console_timer_callback(__unused void *data) { - struct vuart *vu; + struct acrn_vuart *vu; /* Kick HV-Shell and Uart-Console tasks */ vu = vuart_console_active(); diff --git a/hypervisor/debug/shell.c b/hypervisor/debug/shell.c index a079c6778..8a8a9fac5 100644 --- a/hypervisor/debug/shell.c +++ b/hypervisor/debug/shell.c @@ -722,7 +722,7 @@ static int shell_to_sos_console(__unused int argc, __unused char **argv) uint16_t guest_no = 0U; struct vm *vm; - struct vuart *vuart; + struct acrn_vuart *vu; #ifdef CONFIG_PARTITION_MODE if (argc == 2U) { @@ -736,25 +736,17 @@ static int shell_to_sos_console(__unused int argc, __unused char **argv) if (vm == NULL) { return -EINVAL; } - vuart = vm->vuart; - if (vuart == NULL) { - snprintf(temp_str, TEMP_STR_SIZE, - "\r\nError: serial console driver is not " - "enabled for VM %d\r\n", - guest_no); - shell_puts(temp_str); - } else { - /* UART is now owned by the SOS. - * Indicate by toggling the flag. - */ - vuart->active = true; - /* Output that switching to SOS shell */ - snprintf(temp_str, TEMP_STR_SIZE, - "\r\n----- Entering Guest %d Shell -----\r\n", - guest_no); + vu = vm_vuart(vm); + /* UART is now owned by the SOS. + * Indicate by toggling the flag. + */ + vu->active = true; + /* Output that switching to SOS shell */ + snprintf(temp_str, TEMP_STR_SIZE, + "\r\n----- Entering Guest %d Shell -----\r\n", + guest_no); - shell_puts(temp_str); - } + shell_puts(temp_str); return 0; } diff --git a/hypervisor/debug/vuart.c b/hypervisor/debug/vuart.c index 37b272e8e..9bc791b9d 100644 --- a/hypervisor/debug/vuart.c +++ b/hypervisor/debug/vuart.c @@ -41,8 +41,6 @@ #define vuart_lock(vu) spinlock_obtain(&((vu)->lock)) #define vuart_unlock(vu) spinlock_release(&((vu)->lock)) -#define vm_vuart(vm) (vm->vuart) - #ifdef CONFIG_PARTITION_MODE int8_t vuart_vmid = - 1; #endif @@ -100,7 +98,7 @@ static uint32_t fifo_numchars(struct fifo *fifo) * * Return an interrupt reason if one is available. */ -static uint8_t vuart_intr_reason(struct vuart *vu) +static uint8_t vuart_intr_reason(struct acrn_vuart *vu) { if (((vu->lsr & LSR_OE) != 0U) && ((vu->ier & IER_ELSI) != 0U)) { return IIR_RLS; @@ -118,7 +116,7 @@ static uint8_t vuart_intr_reason(struct vuart *vu) * Toggle the COM port's intr pin depending on whether or not we have an * interrupt condition to report to the processor. */ -static void vuart_toggle_intr(struct vuart *vu) +static void vuart_toggle_intr(struct acrn_vuart *vu) { uint8_t intr_reason; @@ -139,7 +137,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr, struct vm *vm, uint16_t offset_arg, __unused size_t width, uint32_t value) { uint16_t offset = offset_arg; - struct vuart *vu = vm_vuart(vm); + struct acrn_vuart *vu = vm_vuart(vm); uint8_t value_u8 = (uint8_t)value; offset -= vu->base; @@ -226,7 +224,7 @@ static uint32_t vuart_read(__unused struct vm_io_handler *hdlr, struct vm *vm, { uint16_t offset = offset_arg; uint8_t iir, reg, intr_reason; - struct vuart *vu = vm_vuart(vm); + struct acrn_vuart *vu = vm_vuart(vm); offset -= vu->base; vuart_lock(vu); @@ -314,7 +312,7 @@ static void vuart_register_io_handler(struct vm *vm) /** * @pre vu != NULL */ -void vuart_console_tx_chars(struct vuart *vu) +void vuart_console_tx_chars(struct acrn_vuart *vu) { vuart_lock(vu); while (fifo_numchars(&vu->txfifo) > 0U) { @@ -327,7 +325,7 @@ void vuart_console_tx_chars(struct vuart *vu) * @pre vu != NULL * @pre vu->active == true */ -void vuart_console_rx_chars(struct vuart *vu) +void vuart_console_rx_chars(struct acrn_vuart *vu) { char ch = -1; @@ -348,7 +346,7 @@ void vuart_console_rx_chars(struct vuart *vu) vuart_unlock(vu); } -struct vuart *vuart_console_active(void) +struct acrn_vuart *vuart_console_active(void) { #ifdef CONFIG_PARTITION_MODE struct vm *vm; @@ -362,36 +360,31 @@ struct vuart *vuart_console_active(void) struct vm *vm = get_vm_from_vmid(0U); #endif - if ((vm != NULL) && (vm->vuart != NULL)) { - struct vuart *vu = vm->vuart; + if (vm != NULL) { + struct acrn_vuart *vu = vm_vuart(vm); if (vu->active) { - return vm->vuart; + return vu; } } return NULL; } -void *vuart_init(struct vm *vm) +void vuart_init(struct vm *vm) { - struct vuart *vu; uint32_t divisor; - - vu = calloc(1U, sizeof(struct vuart)); - ASSERT(vu != NULL, ""); + struct acrn_vuart *vu = vm_vuart(vm); /* Set baud rate*/ divisor = (UART_CLOCK_RATE / BAUD_9600) >> 4U; - vu->dll = (uint8_t)divisor; - vu->dlh = (uint8_t)(divisor >> 8U); + vm->vuart.dll = (uint8_t)divisor; + vm->vuart.dlh = (uint8_t)(divisor >> 8U); - vu->active = false; - vu->base = COM1_BASE; - vu->vm = vm; - fifo_init(&vu->rxfifo, RX_FIFO_SIZE); - fifo_init(&vu->txfifo, TX_FIFO_SIZE); + vm->vuart.active = false; + vm->vuart.base = COM1_BASE; + vm->vuart.vm = vm; + fifo_init(&vm->vuart.rxfifo, RX_FIFO_SIZE); + fifo_init(&vm->vuart.txfifo, TX_FIFO_SIZE); vuart_lock_init(vu); vuart_register_io_handler(vm); - - return vu; } diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index 7cfbdb9ab..47857a40e 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -133,7 +133,7 @@ struct vm { struct vm_pm_info pm; /* Reference to this VM's arch information */ struct vm_arch arch_vm; /* Reference to this VM's arch information */ enum vm_state state; /* VM state */ - void *vuart; /* Virtual UART */ + struct acrn_vuart vuart; /* Virtual UART */ enum vpic_wire_mode wire_mode; struct iommu_domain *iommu; /* iommu domain of this VM */ struct list_head list; /* list of VM */ @@ -243,6 +243,12 @@ static inline struct vcpu *get_primary_vcpu(struct vm *vm) return NULL; } +static inline struct acrn_vuart* +vm_vuart(struct vm *vm) +{ + return (struct acrn_vuart *)&(vm->vuart); +} + static inline struct acrn_vpic * vm_pic(struct vm *vm) { diff --git a/hypervisor/include/arch/x86/hv_arch.h b/hypervisor/include/arch/x86/hv_arch.h index 9ed99011d..933a1fdd9 100644 --- a/hypervisor/include/arch/x86/hv_arch.h +++ b/hypervisor/include/arch/x86/hv_arch.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/hypervisor/include/debug/vuart.h b/hypervisor/include/debug/vuart.h index 332be4633..d0bcc2185 100644 --- a/hypervisor/include/debug/vuart.h +++ b/hypervisor/include/debug/vuart.h @@ -38,7 +38,7 @@ struct fifo { uint32_t size; /* size of the fifo */ }; -struct vuart { +struct acrn_vuart { uint8_t data; /* Data register (R/W) */ uint8_t ier; /* Interrupt enable register (R/W) */ uint8_t lcr; /* Line control register (R/W) */ @@ -63,21 +63,20 @@ struct vuart { extern int8_t vuart_vmid; #endif #ifdef HV_DEBUG -void *vuart_init(struct vm *vm); -struct vuart *vuart_console_active(void); -void vuart_console_tx_chars(struct vuart *vu); -void vuart_console_rx_chars(struct vuart *vu); +void vuart_init(struct vm *vm); +struct acrn_vuart *vuart_console_active(void); +void vuart_console_tx_chars(struct acrn_vuart *vu); +void vuart_console_rx_chars(struct acrn_vuart *vu); #else -static inline void *vuart_init(__unused struct vm *vm) +static inline void vuart_init(__unused struct vm *vm) +{ +} +static inline struct acrn_vuart *vuart_console_active(void) { return NULL; } -static inline struct vuart *vuart_console_active(void) -{ - return NULL; -} -static inline void vuart_console_tx_chars(__unused struct vuart *vu) {} -static inline void vuart_console_rx_chars(__unused struct vuart *vu) {} +static inline void vuart_console_tx_chars(__unused struct acrn_vuart *vu) {} +static inline void vuart_console_rx_chars(__unused struct acrn_vuart *vu) {} #endif /*HV_DEBUG*/ #endif diff --git a/hypervisor/include/hv_debug.h b/hypervisor/include/hv_debug.h index e35057999..010eb63c0 100644 --- a/hypervisor/include/hv_debug.h +++ b/hypervisor/include/hv_debug.h @@ -8,7 +8,6 @@ #define HV_DEBUG_H #include -#include #include #include #include