29
#include "qemu/osdep.h"
31
#include "migration/vmstate.h"
32
#include "chardev/char-fe.h"
34
#include "qemu/module.h"
36
#include "hw/char/digic-uart.h"
37
#include "hw/qdev-properties.h"
38
#include "hw/qdev-properties-system.h"
45
static uint64_t digic_uart_read(void *opaque, hwaddr addr,
48
DigicUartState *s = opaque;
55
s->reg_st &= ~(ST_RX_RDY);
64
qemu_log_mask(LOG_UNIMP,
65
"digic-uart: read access to unknown register 0x"
66
HWADDR_FMT_plx "\n", addr << 2);
72
static void digic_uart_write(void *opaque, hwaddr addr, uint64_t value,
75
DigicUartState *s = opaque;
76
unsigned char ch = value;
84
qemu_chr_fe_write_all(&s->chr, &ch, 1);
102
qemu_log_mask(LOG_UNIMP,
103
"digic-uart: write access to unknown register 0x"
104
HWADDR_FMT_plx "\n", addr << 2);
108
static const MemoryRegionOps uart_mmio_ops = {
109
.read = digic_uart_read,
110
.write = digic_uart_write,
112
.min_access_size = 4,
113
.max_access_size = 4,
115
.endianness = DEVICE_NATIVE_ENDIAN,
118
static int uart_can_rx(void *opaque)
120
DigicUartState *s = opaque;
122
return !(s->reg_st & ST_RX_RDY);
125
static void uart_rx(void *opaque, const uint8_t *buf, int size)
127
DigicUartState *s = opaque;
129
assert(uart_can_rx(opaque));
131
s->reg_st |= ST_RX_RDY;
135
static void uart_event(void *opaque, QEMUChrEvent event)
139
static void digic_uart_reset(DeviceState *d)
141
DigicUartState *s = DIGIC_UART(d);
144
s->reg_st = ST_TX_RDY;
147
static void digic_uart_realize(DeviceState *dev, Error **errp)
149
DigicUartState *s = DIGIC_UART(dev);
151
qemu_chr_fe_set_handlers(&s->chr, uart_can_rx, uart_rx,
152
uart_event, NULL, s, NULL, true);
155
static void digic_uart_init(Object *obj)
157
DigicUartState *s = DIGIC_UART(obj);
159
memory_region_init_io(&s->regs_region, OBJECT(s), &uart_mmio_ops, s,
160
TYPE_DIGIC_UART, 0x18);
161
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->regs_region);
164
static const VMStateDescription vmstate_digic_uart = {
165
.name = "digic-uart",
167
.minimum_version_id = 1,
168
.fields = (const VMStateField[]) {
169
VMSTATE_UINT32(reg_rx, DigicUartState),
170
VMSTATE_UINT32(reg_st, DigicUartState),
171
VMSTATE_END_OF_LIST()
175
static Property digic_uart_properties[] = {
176
DEFINE_PROP_CHR("chardev", DigicUartState, chr),
177
DEFINE_PROP_END_OF_LIST(),
180
static void digic_uart_class_init(ObjectClass *klass, void *data)
182
DeviceClass *dc = DEVICE_CLASS(klass);
184
dc->realize = digic_uart_realize;
185
dc->reset = digic_uart_reset;
186
dc->vmsd = &vmstate_digic_uart;
187
device_class_set_props(dc, digic_uart_properties);
190
static const TypeInfo digic_uart_info = {
191
.name = TYPE_DIGIC_UART,
192
.parent = TYPE_SYS_BUS_DEVICE,
193
.instance_size = sizeof(DigicUartState),
194
.instance_init = digic_uart_init,
195
.class_init = digic_uart_class_init,
198
static void digic_uart_register_types(void)
200
type_register_static(&digic_uart_info);
203
type_init(digic_uart_register_types)