Skip to content

Commit 07e7121

Browse files
mingqiangchimwang106
authored andcommitted
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 <mingqiang.chi@intel.com> Reviewed-by: Li, Fei1 <fei1.li@intel.com> Reviewed-by: Anthony Xu <anthony.xu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 7ce0e6a commit 07e7121

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

hypervisor/debug/vuart.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@
3434

3535
#define COM1_BASE 0x3F8U
3636
#define COM1_IRQ 4U
37-
#define RX_FIFO_SIZE 256U
38-
#define TX_FIFO_SIZE 65536U
37+
38+
#ifndef CONFIG_PARTITION_MODE
39+
static char vuart_rx_buf[RX_BUF_SIZE];
40+
static char vuart_tx_buf[TX_BUF_SIZE];
41+
#endif
3942

4043
#define vuart_lock_init(vu) spinlock_init(&((vu)->lock))
4144
#define vuart_lock(vu) spinlock_obtain(&((vu)->lock))
@@ -45,22 +48,14 @@
4548
int8_t vuart_vmid = - 1;
4649
#endif
4750

48-
static void fifo_reset(struct fifo *fifo)
51+
static inline void fifo_reset(struct fifo *fifo)
4952
{
5053
fifo->rindex = 0U;
5154
fifo->windex = 0U;
5255
fifo->num = 0U;
5356
}
5457

55-
static void fifo_init(struct fifo *fifo, uint32_t sz)
56-
{
57-
fifo->buf = calloc(1U, sz);
58-
ASSERT(fifo->buf != NULL, "");
59-
fifo->size = sz;
60-
fifo_reset(fifo);
61-
}
62-
63-
static void fifo_putchar(struct fifo *fifo, char ch)
58+
static inline void fifo_putchar(struct fifo *fifo, char ch)
6459
{
6560
fifo->buf[fifo->windex] = ch;
6661
if (fifo->num < fifo->size) {
@@ -72,7 +67,7 @@ static void fifo_putchar(struct fifo *fifo, char ch)
7267
}
7368
}
7469

75-
static char fifo_getchar(struct fifo *fifo)
70+
static inline char fifo_getchar(struct fifo *fifo)
7671
{
7772
char c;
7873

@@ -86,11 +81,26 @@ static char fifo_getchar(struct fifo *fifo)
8681
}
8782
}
8883

89-
static uint32_t fifo_numchars(struct fifo *fifo)
84+
static inline uint32_t fifo_numchars(struct fifo *fifo)
9085
{
9186
return fifo->num;
9287
}
9388

89+
static inline void vuart_fifo_init(struct acrn_vuart *vu)
90+
{
91+
#ifdef CONFIG_PARTITION_MODE
92+
vu->txfifo.buf = vu->vuart_tx_buf;
93+
vu->rxfifo.buf = vu->vuart_rx_buf;
94+
#else
95+
vu->txfifo.buf = vuart_tx_buf;
96+
vu->rxfifo.buf = vuart_rx_buf;
97+
#endif
98+
vu->txfifo.size = TX_BUF_SIZE;
99+
vu->rxfifo.size = RX_BUF_SIZE;
100+
fifo_reset(&(vu->txfifo));
101+
fifo_reset(&(vu->rxfifo));
102+
}
103+
94104
/*
95105
* The IIR returns a prioritized interrupt reason:
96106
* - receive data available
@@ -383,8 +393,7 @@ void vuart_init(struct vm *vm)
383393
vm->vuart.active = false;
384394
vm->vuart.base = COM1_BASE;
385395
vm->vuart.vm = vm;
386-
fifo_init(&vm->vuart.rxfifo, RX_FIFO_SIZE);
387-
fifo_init(&vm->vuart.txfifo, TX_FIFO_SIZE);
396+
vuart_fifo_init(vu);
388397
vuart_lock_init(vu);
389398
vuart_register_io_handler(vm);
390399
}

hypervisor/include/arch/x86/guest/vm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static inline struct vcpu *get_primary_vcpu(struct vm *vm)
253253
static inline struct acrn_vuart*
254254
vm_vuart(struct vm *vm)
255255
{
256-
return (struct acrn_vuart *)&(vm->vuart);
256+
return &(vm->vuart);
257257
}
258258

259259
static inline struct acrn_vpic *

hypervisor/include/debug/vuart.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#ifndef _VUART_H_
3131
#define _VUART_H_
3232

33+
#define RX_BUF_SIZE 256U
34+
#define TX_BUF_SIZE 8192U
35+
3336
struct fifo {
3437
char *buf;
3538
uint32_t rindex; /* index to read from */
@@ -53,7 +56,10 @@ struct acrn_vuart {
5356
struct fifo rxfifo;
5457
struct fifo txfifo;
5558
uint16_t base;
56-
59+
#ifdef CONFIG_PARTITION_MODE
60+
char vuart_rx_buf[RX_BUF_SIZE];
61+
char vuart_tx_buf[TX_BUF_SIZE];
62+
#endif
5763
bool thre_int_pending; /* THRE interrupt pending */
5864
bool active;
5965
struct vm *vm;

0 commit comments

Comments
 (0)