2021-05-04 18:30:07 +00:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
|
|
|
#include "hv.h"
|
|
|
|
#include "uart_regs.h"
|
|
|
|
|
2021-05-14 20:47:43 +00:00
|
|
|
static iodev_id_t vuart_iodev;
|
|
|
|
|
2021-05-04 18:30:07 +00:00
|
|
|
bool handle_vuart(u64 addr, u64 *val, bool write, int width)
|
|
|
|
{
|
|
|
|
UNUSED(width);
|
|
|
|
addr &= 0xfff;
|
|
|
|
|
|
|
|
if (write) {
|
|
|
|
switch (addr) {
|
|
|
|
case UTXH: {
|
|
|
|
uint8_t b = *val;
|
2021-05-14 20:47:43 +00:00
|
|
|
if (iodev_can_write(vuart_iodev))
|
|
|
|
iodev_write(vuart_iodev, &b, 1);
|
2021-05-04 18:30:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (addr) {
|
|
|
|
case UTRSTAT:
|
2021-05-29 16:39:26 +00:00
|
|
|
*val = 0x06;
|
2021-05-04 18:30:07 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*val = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// printf("HV: vuart(0x%lx, 0x%lx, %d, %d)\n", addr, *val, write, width);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-14 20:47:43 +00:00
|
|
|
void hv_map_vuart(u64 base, iodev_id_t iodev)
|
2021-05-04 18:30:07 +00:00
|
|
|
{
|
|
|
|
hv_map_hook(base, handle_vuart, 0x1000);
|
2021-05-14 20:47:43 +00:00
|
|
|
vuart_iodev = iodev;
|
2021-05-04 18:30:07 +00:00
|
|
|
}
|