|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v8 05/26] emul/ns16x50: implement DLL/DLM registers
From: Denis Mukhin <dmukhin@xxxxxxxx>
Add DLL/DLM registers emulation.
DLL/DLM registers report hardcoded 115200 baud rate to the guest OS.
Signed-off-by: Denis Mukhin <dmukhin@xxxxxxxx>
---
xen/common/emul/vuart/ns16x50.c | 82 +++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/xen/common/emul/vuart/ns16x50.c b/xen/common/emul/vuart/ns16x50.c
index 6e1cfecbaa55..80805ee6ecc6 100644
--- a/xen/common/emul/vuart/ns16x50.c
+++ b/xen/common/emul/vuart/ns16x50.c
@@ -119,8 +119,37 @@ static inline void ns16x50_unlock(struct vuart_ns16x50
*vdev,
static int ns16x50_io_write8(
struct vuart_ns16x50 *vdev, uint32_t reg, uint8_t *data)
{
+ uint8_t *regs = vdev->regs;
+ uint8_t val = *data;
int rc = 0;
+ switch ( reg )
+ {
+ case UART_THR: /* DLAB=0 --> UART_RBR, DLAB=1 --> UART_DLL */
+ /* DLAB=1 */
+ if ( regs[UART_LCR] & UART_LCR_DLAB )
+ {
+ regs[NS16X50_REGS_NUM + UART_DLL] = val;
+ break;
+ }
+
+ /* DLAB=0 */
+ break;
+
+ case UART_IER: /* DLAB=0 --> UART_IER, DLAB=1 --> UART_DLM */
+ /* DLAB=1 */
+ if ( regs[UART_LCR] & UART_LCR_DLAB )
+ {
+ regs[NS16X50_REGS_NUM + UART_DLM] = val;
+ }
+ /* DLAB=0 */
+ break;
+
+ default:
+ rc = -EINVAL;
+ break;
+ }
+
return rc;
}
@@ -131,8 +160,17 @@ static int ns16x50_io_write8(
static int ns16x50_io_write16(
struct vuart_ns16x50 *vdev, uint32_t reg, uint16_t *data)
{
+ uint8_t *regs = vdev->regs;
+ uint16_t val = *data;
int rc = -EINVAL;
+ if ( (regs[UART_LCR] & UART_LCR_DLAB) && reg == UART_DLL )
+ {
+ vdev->regs[NS16X50_REGS_NUM + UART_DLL] = val & UINT8_MAX;
+ vdev->regs[NS16X50_REGS_NUM + UART_DLM] = (val >> 8) & UINT8_MAX;
+ rc = 0;
+ }
+
return rc;
}
@@ -168,9 +206,39 @@ static int ns16x50_io_write(
static int ns16x50_io_read8(
struct vuart_ns16x50 *vdev, uint32_t reg, uint8_t *data)
{
+ uint8_t *regs = vdev->regs;
uint8_t val = UINT8_MAX;
int rc = 0;
+ switch ( reg )
+ {
+ case UART_RBR: /* DLAB=0 --> UART_RBR, DLAB=1 --> UART_DLL */
+ /* DLAB=1 */
+ if ( regs[UART_LCR] & UART_LCR_DLAB )
+ {
+ val = regs[NS16X50_REGS_NUM + UART_DLL];
+ break;
+ }
+
+ /* DLAB=0 */
+ break;
+
+ case UART_IER: /* DLAB=0 --> UART_IER, DLAB=1 --> UART_DLM */
+ /* DLAB=1 */
+ if ( regs[UART_LCR] & UART_LCR_DLAB )
+ {
+ val = regs[NS16X50_REGS_NUM + UART_DLM];
+ break;
+ }
+
+ /* DLAB=0 */
+ break;
+
+ default:
+ rc = -EINVAL;
+ break;
+ }
+
*data = val;
return rc;
@@ -182,9 +250,17 @@ static int ns16x50_io_read8(
static int ns16x50_io_read16(
struct vuart_ns16x50 *vdev, uint32_t reg, uint16_t *data)
{
+ uint8_t *regs = vdev->regs;
uint16_t val = UINT16_MAX;
int rc = -EINVAL;
+ if ( (regs[UART_LCR] & UART_LCR_DLAB) && reg == UART_DLL )
+ {
+ val = vdev->regs[NS16X50_REGS_NUM + UART_DLM] << 8 |
+ vdev->regs[NS16X50_REGS_NUM + UART_DLL];
+ rc = 0;
+ }
+
*data = val;
return rc;
@@ -310,7 +386,13 @@ static int cf_check ns16x50_io_handle(
static void ns16x50_reset(struct vuart_ns16x50 *vdev)
{
+ const uint16_t divisor = (UART_CLOCK_HZ / 115200) >> 4;
+
memset(vdev->regs, 0, sizeof(vdev->regs));
+
+ /* NB: report 115200 baud rate. */
+ vdev->regs[NS16X50_REGS_NUM + UART_DLL] = divisor & UINT8_MAX;
+ vdev->regs[NS16X50_REGS_NUM + UART_DLM] = (divisor >> 8) & UINT8_MAX;
}
static int ns16x50_init(void *arg)
--
2.56.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |