mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-24 22:42:53 +00:00
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>
This commit is contained in:
parent
7ce0e6a395
commit
07e71212cc
@ -34,8 +34,11 @@
|
|||||||
|
|
||||||
#define COM1_BASE 0x3F8U
|
#define COM1_BASE 0x3F8U
|
||||||
#define COM1_IRQ 4U
|
#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_init(vu) spinlock_init(&((vu)->lock))
|
||||||
#define vuart_lock(vu) spinlock_obtain(&((vu)->lock))
|
#define vuart_lock(vu) spinlock_obtain(&((vu)->lock))
|
||||||
@ -45,22 +48,14 @@
|
|||||||
int8_t vuart_vmid = - 1;
|
int8_t vuart_vmid = - 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void fifo_reset(struct fifo *fifo)
|
static inline void fifo_reset(struct fifo *fifo)
|
||||||
{
|
{
|
||||||
fifo->rindex = 0U;
|
fifo->rindex = 0U;
|
||||||
fifo->windex = 0U;
|
fifo->windex = 0U;
|
||||||
fifo->num = 0U;
|
fifo->num = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fifo_init(struct fifo *fifo, uint32_t sz)
|
static inline void fifo_putchar(struct fifo *fifo, char ch)
|
||||||
{
|
|
||||||
fifo->buf = calloc(1U, sz);
|
|
||||||
ASSERT(fifo->buf != NULL, "");
|
|
||||||
fifo->size = sz;
|
|
||||||
fifo_reset(fifo);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fifo_putchar(struct fifo *fifo, char ch)
|
|
||||||
{
|
{
|
||||||
fifo->buf[fifo->windex] = ch;
|
fifo->buf[fifo->windex] = ch;
|
||||||
if (fifo->num < fifo->size) {
|
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;
|
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;
|
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:
|
* The IIR returns a prioritized interrupt reason:
|
||||||
* - receive data available
|
* - receive data available
|
||||||
@ -383,8 +393,7 @@ void vuart_init(struct vm *vm)
|
|||||||
vm->vuart.active = false;
|
vm->vuart.active = false;
|
||||||
vm->vuart.base = COM1_BASE;
|
vm->vuart.base = COM1_BASE;
|
||||||
vm->vuart.vm = vm;
|
vm->vuart.vm = vm;
|
||||||
fifo_init(&vm->vuart.rxfifo, RX_FIFO_SIZE);
|
vuart_fifo_init(vu);
|
||||||
fifo_init(&vm->vuart.txfifo, TX_FIFO_SIZE);
|
|
||||||
vuart_lock_init(vu);
|
vuart_lock_init(vu);
|
||||||
vuart_register_io_handler(vm);
|
vuart_register_io_handler(vm);
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ static inline struct vcpu *get_primary_vcpu(struct vm *vm)
|
|||||||
static inline struct acrn_vuart*
|
static inline struct acrn_vuart*
|
||||||
vm_vuart(struct vm *vm)
|
vm_vuart(struct vm *vm)
|
||||||
{
|
{
|
||||||
return (struct acrn_vuart *)&(vm->vuart);
|
return &(vm->vuart);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct acrn_vpic *
|
static inline struct acrn_vpic *
|
||||||
|
@ -30,6 +30,9 @@
|
|||||||
#ifndef _VUART_H_
|
#ifndef _VUART_H_
|
||||||
#define _VUART_H_
|
#define _VUART_H_
|
||||||
|
|
||||||
|
#define RX_BUF_SIZE 256U
|
||||||
|
#define TX_BUF_SIZE 8192U
|
||||||
|
|
||||||
struct fifo {
|
struct fifo {
|
||||||
char *buf;
|
char *buf;
|
||||||
uint32_t rindex; /* index to read from */
|
uint32_t rindex; /* index to read from */
|
||||||
@ -53,7 +56,10 @@ struct acrn_vuart {
|
|||||||
struct fifo rxfifo;
|
struct fifo rxfifo;
|
||||||
struct fifo txfifo;
|
struct fifo txfifo;
|
||||||
uint16_t base;
|
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 thre_int_pending; /* THRE interrupt pending */
|
||||||
bool active;
|
bool active;
|
||||||
struct vm *vm;
|
struct vm *vm;
|
||||||
|
Loading…
Reference in New Issue
Block a user