From 07e71212cc96c64e6e66cdb50d0d7c6b916a5e20 Mon Sep 17 00:00:00 2001 From: Mingqiang Chi Date: Wed, 12 Sep 2018 11:48:19 +0800 Subject: [PATCH] hv:Replace dynamic memory allocation for vuart Replace dynamic allocation for vuart rx/tx buffer with static array. v2-->v3: -- Reduce the size of vuart tx buffer from 64K to 8K -- For non-partition mode, will use global rx/tx buffer, for partition mode, will use per VM rx/tx buffer. -- Change several APIs to inline v1-->v2: -- Move vuart rx/tx buffer into acrn_vuart data structure Tracked-On: #861 Signed-off-by: Mingqiang Chi Reviewed-by: Li, Fei1 Reviewed-by: Anthony Xu Acked-by: Eddie Dong --- hypervisor/debug/vuart.c | 41 ++++++++++++++++---------- hypervisor/include/arch/x86/guest/vm.h | 2 +- hypervisor/include/debug/vuart.h | 8 ++++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/hypervisor/debug/vuart.c b/hypervisor/debug/vuart.c index 9aa134eee..9a1686402 100644 --- a/hypervisor/debug/vuart.c +++ b/hypervisor/debug/vuart.c @@ -34,8 +34,11 @@ #define COM1_BASE 0x3F8U #define COM1_IRQ 4U -#define RX_FIFO_SIZE 256U -#define TX_FIFO_SIZE 65536U + +#ifndef CONFIG_PARTITION_MODE +static char vuart_rx_buf[RX_BUF_SIZE]; +static char vuart_tx_buf[TX_BUF_SIZE]; +#endif #define vuart_lock_init(vu) spinlock_init(&((vu)->lock)) #define vuart_lock(vu) spinlock_obtain(&((vu)->lock)) @@ -45,22 +48,14 @@ int8_t vuart_vmid = - 1; #endif -static void fifo_reset(struct fifo *fifo) +static inline void fifo_reset(struct fifo *fifo) { fifo->rindex = 0U; fifo->windex = 0U; fifo->num = 0U; } -static void fifo_init(struct fifo *fifo, uint32_t sz) -{ - fifo->buf = calloc(1U, sz); - ASSERT(fifo->buf != NULL, ""); - fifo->size = sz; - fifo_reset(fifo); -} - -static void fifo_putchar(struct fifo *fifo, char ch) +static inline void fifo_putchar(struct fifo *fifo, char ch) { fifo->buf[fifo->windex] = ch; if (fifo->num < fifo->size) { @@ -72,7 +67,7 @@ static void fifo_putchar(struct fifo *fifo, char ch) } } -static char fifo_getchar(struct fifo *fifo) +static inline char fifo_getchar(struct fifo *fifo) { char c; @@ -86,11 +81,26 @@ static char fifo_getchar(struct fifo *fifo) } } -static uint32_t fifo_numchars(struct fifo *fifo) +static inline uint32_t fifo_numchars(struct fifo *fifo) { return fifo->num; } +static inline void vuart_fifo_init(struct acrn_vuart *vu) +{ +#ifdef CONFIG_PARTITION_MODE + vu->txfifo.buf = vu->vuart_tx_buf; + vu->rxfifo.buf = vu->vuart_rx_buf; +#else + vu->txfifo.buf = vuart_tx_buf; + vu->rxfifo.buf = vuart_rx_buf; +#endif + vu->txfifo.size = TX_BUF_SIZE; + vu->rxfifo.size = RX_BUF_SIZE; + fifo_reset(&(vu->txfifo)); + fifo_reset(&(vu->rxfifo)); +} + /* * The IIR returns a prioritized interrupt reason: * - receive data available @@ -383,8 +393,7 @@ void vuart_init(struct vm *vm) 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_fifo_init(vu); vuart_lock_init(vu); vuart_register_io_handler(vm); } diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index ceeb5ffc2..10211207e 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -253,7 +253,7 @@ static inline struct vcpu *get_primary_vcpu(struct vm *vm) static inline struct acrn_vuart* vm_vuart(struct vm *vm) { - return (struct acrn_vuart *)&(vm->vuart); + return &(vm->vuart); } static inline struct acrn_vpic * diff --git a/hypervisor/include/debug/vuart.h b/hypervisor/include/debug/vuart.h index d0bcc2185..31fba6518 100644 --- a/hypervisor/include/debug/vuart.h +++ b/hypervisor/include/debug/vuart.h @@ -30,6 +30,9 @@ #ifndef _VUART_H_ #define _VUART_H_ +#define RX_BUF_SIZE 256U +#define TX_BUF_SIZE 8192U + struct fifo { char *buf; uint32_t rindex; /* index to read from */ @@ -53,7 +56,10 @@ struct acrn_vuart { struct fifo rxfifo; struct fifo txfifo; uint16_t base; - +#ifdef CONFIG_PARTITION_MODE + char vuart_rx_buf[RX_BUF_SIZE]; + char vuart_tx_buf[TX_BUF_SIZE]; +#endif bool thre_int_pending; /* THRE interrupt pending */ bool active; struct vm *vm;