2007-09-16 23:08:06 +02:00
|
|
|
/*
|
2006-04-09 03:32:52 +02:00
|
|
|
* Arm PrimeCell PL011 UART
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 CodeSourcery.
|
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
2011-06-26 04:21:35 +02:00
|
|
|
* This code is licensed under the GPL.
|
2006-04-09 03:32:52 +02:00
|
|
|
*/
|
|
|
|
|
2019-02-21 19:17:46 +01:00
|
|
|
/*
|
|
|
|
* QEMU interface:
|
|
|
|
* + sysbus MMIO region 0: device registers
|
|
|
|
* + sysbus IRQ 0: UARTINTR (combined interrupt line)
|
|
|
|
* + sysbus IRQ 1: UARTRXINTR (receive FIFO interrupt line)
|
|
|
|
* + sysbus IRQ 2: UARTTXINTR (transmit FIFO interrupt line)
|
|
|
|
* + sysbus IRQ 3: UARTRTINTR (receive timeout interrupt line)
|
|
|
|
* + sysbus IRQ 4: UARTMSINTR (momem status interrupt line)
|
|
|
|
* + sysbus IRQ 5: UARTEINTR (error interrupt line)
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:05 +01:00
|
|
|
#include "qemu/osdep.h"
|
2019-02-21 19:17:46 +01:00
|
|
|
#include "hw/char/pl011.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.h"
|
2020-10-10 15:57:58 +02:00
|
|
|
#include "hw/qdev-clock.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2017-01-26 15:26:44 +01:00
|
|
|
#include "chardev/char-fe.h"
|
2015-12-15 13:16:16 +01:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2016-10-12 19:54:36 +02:00
|
|
|
#include "trace.h"
|
2006-04-09 03:32:52 +02:00
|
|
|
|
|
|
|
#define PL011_INT_TX 0x20
|
|
|
|
#define PL011_INT_RX 0x10
|
|
|
|
|
|
|
|
#define PL011_FLAG_TXFE 0x80
|
|
|
|
#define PL011_FLAG_RXFF 0x40
|
|
|
|
#define PL011_FLAG_TXFF 0x20
|
|
|
|
#define PL011_FLAG_RXFE 0x10
|
|
|
|
|
2019-02-21 19:17:46 +01:00
|
|
|
/* Interrupt status bits in UARTRIS, UARTMIS, UARTIMSC */
|
|
|
|
#define INT_OE (1 << 10)
|
|
|
|
#define INT_BE (1 << 9)
|
|
|
|
#define INT_PE (1 << 8)
|
|
|
|
#define INT_FE (1 << 7)
|
|
|
|
#define INT_RT (1 << 6)
|
|
|
|
#define INT_TX (1 << 5)
|
|
|
|
#define INT_RX (1 << 4)
|
|
|
|
#define INT_DSR (1 << 3)
|
|
|
|
#define INT_DCD (1 << 2)
|
|
|
|
#define INT_CTS (1 << 1)
|
|
|
|
#define INT_RI (1 << 0)
|
|
|
|
#define INT_E (INT_OE | INT_BE | INT_PE | INT_FE)
|
|
|
|
#define INT_MS (INT_RI | INT_DSR | INT_DCD | INT_CTS)
|
|
|
|
|
2009-05-14 23:35:07 +02:00
|
|
|
static const unsigned char pl011_id_arm[8] =
|
|
|
|
{ 0x11, 0x10, 0x14, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
|
|
|
|
static const unsigned char pl011_id_luminary[8] =
|
|
|
|
{ 0x11, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x05, 0xb1 };
|
2006-04-09 03:32:52 +02:00
|
|
|
|
2019-02-21 19:17:46 +01:00
|
|
|
/* Which bits in the interrupt status matter for each outbound IRQ line ? */
|
|
|
|
static const uint32_t irqmask[] = {
|
|
|
|
INT_E | INT_MS | INT_RT | INT_TX | INT_RX, /* combined IRQ */
|
|
|
|
INT_RX,
|
|
|
|
INT_TX,
|
|
|
|
INT_RT,
|
|
|
|
INT_MS,
|
|
|
|
INT_E,
|
|
|
|
};
|
|
|
|
|
2013-07-24 23:13:57 +02:00
|
|
|
static void pl011_update(PL011State *s)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
|
|
|
uint32_t flags;
|
2019-02-21 19:17:46 +01:00
|
|
|
int i;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2006-04-09 03:32:52 +02:00
|
|
|
flags = s->int_level & s->int_enabled;
|
2016-10-12 19:54:36 +02:00
|
|
|
trace_pl011_irq_state(flags != 0);
|
2019-02-21 19:17:46 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(s->irq); i++) {
|
|
|
|
qemu_set_irq(s->irq[i], (flags & irqmask[i]) != 0);
|
|
|
|
}
|
2006-04-09 03:32:52 +02:00
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t pl011_read(void *opaque, hwaddr offset,
|
2011-10-10 17:08:49 +02:00
|
|
|
unsigned size)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
2013-07-24 23:13:57 +02:00
|
|
|
PL011State *s = (PL011State *)opaque;
|
2006-04-09 03:32:52 +02:00
|
|
|
uint32_t c;
|
2016-10-12 19:54:36 +02:00
|
|
|
uint64_t r;
|
2006-04-09 03:32:52 +02:00
|
|
|
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* UARTDR */
|
|
|
|
s->flags &= ~PL011_FLAG_RXFF;
|
|
|
|
c = s->read_fifo[s->read_pos];
|
|
|
|
if (s->read_count > 0) {
|
|
|
|
s->read_count--;
|
|
|
|
if (++s->read_pos == 16)
|
|
|
|
s->read_pos = 0;
|
|
|
|
}
|
|
|
|
if (s->read_count == 0) {
|
|
|
|
s->flags |= PL011_FLAG_RXFE;
|
|
|
|
}
|
|
|
|
if (s->read_count == s->read_trigger - 1)
|
|
|
|
s->int_level &= ~ PL011_INT_RX;
|
2016-10-12 19:54:36 +02:00
|
|
|
trace_pl011_read_fifo(s->read_count);
|
2014-03-18 19:18:40 +01:00
|
|
|
s->rsr = c >> 8;
|
2006-04-09 03:32:52 +02:00
|
|
|
pl011_update(s);
|
2016-10-22 11:52:59 +02:00
|
|
|
qemu_chr_fe_accept_input(&s->chr);
|
2016-10-12 19:54:36 +02:00
|
|
|
r = c;
|
|
|
|
break;
|
2014-03-18 19:18:40 +01:00
|
|
|
case 1: /* UARTRSR */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->rsr;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 6: /* UARTFR */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->flags;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 8: /* UARTILPR */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->ilpr;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 9: /* UARTIBRD */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->ibrd;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 10: /* UARTFBRD */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->fbrd;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 11: /* UARTLCR_H */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->lcr;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 12: /* UARTCR */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->cr;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 13: /* UARTIFLS */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->ifl;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 14: /* UARTIMSC */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->int_enabled;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 15: /* UARTRIS */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->int_level;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 16: /* UARTMIS */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->int_level & s->int_enabled;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 18: /* UARTDMACR */
|
2016-10-12 19:54:36 +02:00
|
|
|
r = s->dmacr;
|
|
|
|
break;
|
|
|
|
case 0x3f8 ... 0x400:
|
|
|
|
r = s->id[(offset - 0xfe0) >> 2];
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
default:
|
2012-10-18 15:11:40 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
2019-02-21 19:17:46 +01:00
|
|
|
"pl011_read: Bad offset 0x%x\n", (int)offset);
|
2016-10-12 19:54:36 +02:00
|
|
|
r = 0;
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
}
|
2016-10-12 19:54:36 +02:00
|
|
|
|
|
|
|
trace_pl011_read(offset, r);
|
|
|
|
return r;
|
2006-04-09 03:32:52 +02:00
|
|
|
}
|
|
|
|
|
2013-07-24 23:13:57 +02:00
|
|
|
static void pl011_set_read_trigger(PL011State *s)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
/* The docs say the RX interrupt is triggered when the FIFO exceeds
|
|
|
|
the threshold. However linux only reads the FIFO in response to an
|
|
|
|
interrupt. Triggering the interrupt when the FIFO is non-empty seems
|
|
|
|
to make things work. */
|
|
|
|
if (s->lcr & 0x10)
|
|
|
|
s->read_trigger = (s->ifl >> 1) & 0x1c;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
s->read_trigger = 1;
|
|
|
|
}
|
|
|
|
|
2020-10-10 15:57:58 +02:00
|
|
|
static unsigned int pl011_get_baudrate(const PL011State *s)
|
|
|
|
{
|
|
|
|
uint64_t clk;
|
|
|
|
|
|
|
|
if (s->fbrd == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
clk = clock_get_hz(s->clk);
|
|
|
|
return (clk / ((s->ibrd << 6) + s->fbrd)) << 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pl011_trace_baudrate_change(const PL011State *s)
|
|
|
|
{
|
|
|
|
trace_pl011_baudrate_change(pl011_get_baudrate(s),
|
|
|
|
clock_get_hz(s->clk),
|
|
|
|
s->ibrd, s->fbrd);
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void pl011_write(void *opaque, hwaddr offset,
|
2011-10-10 17:08:49 +02:00
|
|
|
uint64_t value, unsigned size)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
2013-07-24 23:13:57 +02:00
|
|
|
PL011State *s = (PL011State *)opaque;
|
2006-04-09 03:32:52 +02:00
|
|
|
unsigned char ch;
|
|
|
|
|
2016-10-12 19:54:36 +02:00
|
|
|
trace_pl011_write(offset, value);
|
|
|
|
|
2006-04-09 03:32:52 +02:00
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* UARTDR */
|
|
|
|
/* ??? Check if transmitter is enabled. */
|
|
|
|
ch = value;
|
2016-10-22 11:52:59 +02:00
|
|
|
/* XXX this blocks entire thread. Rewrite to use
|
|
|
|
* qemu_chr_fe_write and background I/O callbacks */
|
|
|
|
qemu_chr_fe_write_all(&s->chr, &ch, 1);
|
2006-04-09 03:32:52 +02:00
|
|
|
s->int_level |= PL011_INT_TX;
|
|
|
|
pl011_update(s);
|
|
|
|
break;
|
2014-03-18 19:18:40 +01:00
|
|
|
case 1: /* UARTRSR/UARTECR */
|
|
|
|
s->rsr = 0;
|
2006-04-09 03:32:52 +02:00
|
|
|
break;
|
2007-11-11 01:04:49 +01:00
|
|
|
case 6: /* UARTFR */
|
|
|
|
/* Writes to Flag register are ignored. */
|
|
|
|
break;
|
2006-04-09 03:32:52 +02:00
|
|
|
case 8: /* UARTUARTILPR */
|
|
|
|
s->ilpr = value;
|
|
|
|
break;
|
|
|
|
case 9: /* UARTIBRD */
|
|
|
|
s->ibrd = value;
|
2020-10-10 15:57:58 +02:00
|
|
|
pl011_trace_baudrate_change(s);
|
2006-04-09 03:32:52 +02:00
|
|
|
break;
|
|
|
|
case 10: /* UARTFBRD */
|
|
|
|
s->fbrd = value;
|
2020-10-10 15:57:58 +02:00
|
|
|
pl011_trace_baudrate_change(s);
|
2006-04-09 03:32:52 +02:00
|
|
|
break;
|
|
|
|
case 11: /* UARTLCR_H */
|
2014-03-18 19:18:39 +01:00
|
|
|
/* Reset the FIFO state on FIFO enable or disable */
|
|
|
|
if ((s->lcr ^ value) & 0x10) {
|
|
|
|
s->read_count = 0;
|
|
|
|
s->read_pos = 0;
|
|
|
|
}
|
2006-04-09 03:32:52 +02:00
|
|
|
s->lcr = value;
|
|
|
|
pl011_set_read_trigger(s);
|
|
|
|
break;
|
|
|
|
case 12: /* UARTCR */
|
|
|
|
/* ??? Need to implement the enable and loopback bits. */
|
|
|
|
s->cr = value;
|
|
|
|
break;
|
|
|
|
case 13: /* UARTIFS */
|
|
|
|
s->ifl = value;
|
|
|
|
pl011_set_read_trigger(s);
|
|
|
|
break;
|
|
|
|
case 14: /* UARTIMSC */
|
|
|
|
s->int_enabled = value;
|
|
|
|
pl011_update(s);
|
|
|
|
break;
|
|
|
|
case 17: /* UARTICR */
|
|
|
|
s->int_level &= ~value;
|
|
|
|
pl011_update(s);
|
|
|
|
break;
|
|
|
|
case 18: /* UARTDMACR */
|
|
|
|
s->dmacr = value;
|
2012-10-18 15:11:40 +02:00
|
|
|
if (value & 3) {
|
|
|
|
qemu_log_mask(LOG_UNIMP, "pl011: DMA not implemented\n");
|
|
|
|
}
|
2006-04-09 03:32:52 +02:00
|
|
|
break;
|
|
|
|
default:
|
2012-10-18 15:11:40 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
2019-02-21 19:17:46 +01:00
|
|
|
"pl011_write: Bad offset 0x%x\n", (int)offset);
|
2006-04-09 03:32:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-12 00:48:58 +02:00
|
|
|
static int pl011_can_receive(void *opaque)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
2013-07-24 23:13:57 +02:00
|
|
|
PL011State *s = (PL011State *)opaque;
|
2016-10-12 19:54:36 +02:00
|
|
|
int r;
|
2006-04-09 03:32:52 +02:00
|
|
|
|
2016-10-12 19:54:36 +02:00
|
|
|
if (s->lcr & 0x10) {
|
|
|
|
r = s->read_count < 16;
|
|
|
|
} else {
|
|
|
|
r = s->read_count < 1;
|
|
|
|
}
|
|
|
|
trace_pl011_can_receive(s->lcr, s->read_count, r);
|
|
|
|
return r;
|
2006-04-09 03:32:52 +02:00
|
|
|
}
|
|
|
|
|
2008-04-08 21:51:43 +02:00
|
|
|
static void pl011_put_fifo(void *opaque, uint32_t value)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
2013-07-24 23:13:57 +02:00
|
|
|
PL011State *s = (PL011State *)opaque;
|
2006-04-09 03:32:52 +02:00
|
|
|
int slot;
|
|
|
|
|
|
|
|
slot = s->read_pos + s->read_count;
|
|
|
|
if (slot >= 16)
|
|
|
|
slot -= 16;
|
2008-04-08 21:51:43 +02:00
|
|
|
s->read_fifo[slot] = value;
|
2006-04-09 03:32:52 +02:00
|
|
|
s->read_count++;
|
|
|
|
s->flags &= ~PL011_FLAG_RXFE;
|
2016-10-12 19:54:36 +02:00
|
|
|
trace_pl011_put_fifo(value, s->read_count);
|
2014-03-18 19:18:41 +01:00
|
|
|
if (!(s->lcr & 0x10) || s->read_count == 16) {
|
2016-10-12 19:54:36 +02:00
|
|
|
trace_pl011_put_fifo_full();
|
2006-04-09 03:32:52 +02:00
|
|
|
s->flags |= PL011_FLAG_RXFF;
|
|
|
|
}
|
|
|
|
if (s->read_count == s->read_trigger) {
|
|
|
|
s->int_level |= PL011_INT_RX;
|
|
|
|
pl011_update(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-08 21:51:43 +02:00
|
|
|
static void pl011_receive(void *opaque, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
pl011_put_fifo(opaque, *buf);
|
|
|
|
}
|
|
|
|
|
chardev: Use QEMUChrEvent enum in IOEventHandler typedef
The Chardev events are listed in the QEMUChrEvent enum.
By using the enum in the IOEventHandler typedef we:
- make the IOEventHandler type more explicit (this handler
process out-of-band information, while the IOReadHandler
is in-band),
- help static code analyzers.
This patch was produced with the following spatch script:
@match@
expression backend, opaque, context, set_open;
identifier fd_can_read, fd_read, fd_event, be_change;
@@
qemu_chr_fe_set_handlers(backend, fd_can_read, fd_read, fd_event,
be_change, opaque, context, set_open);
@depends on match@
identifier opaque, event;
identifier match.fd_event;
@@
static
-void fd_event(void *opaque, int event)
+void fd_event(void *opaque, QEMUChrEvent event)
{
...
}
Then the typedef was modified manually in
include/chardev/char-fe.h.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Acked-by: Corey Minyard <cminyard@mvista.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20191218172009.8868-15-philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2019-12-18 18:20:09 +01:00
|
|
|
static void pl011_event(void *opaque, QEMUChrEvent event)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
2008-04-08 21:51:43 +02:00
|
|
|
if (event == CHR_EVENT_BREAK)
|
|
|
|
pl011_put_fifo(opaque, 0x400);
|
2006-04-09 03:32:52 +02:00
|
|
|
}
|
|
|
|
|
2020-10-10 15:57:58 +02:00
|
|
|
static void pl011_clock_update(void *opaque)
|
|
|
|
{
|
|
|
|
PL011State *s = PL011(opaque);
|
|
|
|
|
|
|
|
pl011_trace_baudrate_change(s);
|
|
|
|
}
|
|
|
|
|
2011-10-10 17:08:49 +02:00
|
|
|
static const MemoryRegionOps pl011_ops = {
|
|
|
|
.read = pl011_read,
|
|
|
|
.write = pl011_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2006-04-09 03:32:52 +02:00
|
|
|
};
|
|
|
|
|
2020-10-10 15:57:58 +02:00
|
|
|
static const VMStateDescription vmstate_pl011_clock = {
|
|
|
|
.name = "pl011/clock",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_CLOCK(clk, PL011State),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-12-02 01:50:33 +01:00
|
|
|
static const VMStateDescription vmstate_pl011 = {
|
|
|
|
.name = "pl011",
|
2014-03-18 19:18:40 +01:00
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
2014-05-13 17:09:35 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2013-07-24 23:13:57 +02:00
|
|
|
VMSTATE_UINT32(readbuff, PL011State),
|
|
|
|
VMSTATE_UINT32(flags, PL011State),
|
|
|
|
VMSTATE_UINT32(lcr, PL011State),
|
2014-03-18 19:18:40 +01:00
|
|
|
VMSTATE_UINT32(rsr, PL011State),
|
2013-07-24 23:13:57 +02:00
|
|
|
VMSTATE_UINT32(cr, PL011State),
|
|
|
|
VMSTATE_UINT32(dmacr, PL011State),
|
|
|
|
VMSTATE_UINT32(int_enabled, PL011State),
|
|
|
|
VMSTATE_UINT32(int_level, PL011State),
|
|
|
|
VMSTATE_UINT32_ARRAY(read_fifo, PL011State, 16),
|
|
|
|
VMSTATE_UINT32(ilpr, PL011State),
|
|
|
|
VMSTATE_UINT32(ibrd, PL011State),
|
|
|
|
VMSTATE_UINT32(fbrd, PL011State),
|
|
|
|
VMSTATE_UINT32(ifl, PL011State),
|
|
|
|
VMSTATE_INT32(read_pos, PL011State),
|
|
|
|
VMSTATE_INT32(read_count, PL011State),
|
|
|
|
VMSTATE_INT32(read_trigger, PL011State),
|
2010-12-02 01:50:33 +01:00
|
|
|
VMSTATE_END_OF_LIST()
|
2020-10-10 15:57:58 +02:00
|
|
|
},
|
|
|
|
.subsections = (const VMStateDescription * []) {
|
|
|
|
&vmstate_pl011_clock,
|
|
|
|
NULL
|
2010-12-02 01:50:33 +01:00
|
|
|
}
|
|
|
|
};
|
2008-07-02 18:48:32 +02:00
|
|
|
|
2016-06-06 17:59:31 +02:00
|
|
|
static Property pl011_properties[] = {
|
|
|
|
DEFINE_PROP_CHR("chardev", PL011State, chr),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2013-07-24 23:29:17 +02:00
|
|
|
static void pl011_init(Object *obj)
|
2006-04-09 03:32:52 +02:00
|
|
|
{
|
2013-07-24 23:29:17 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
|
|
|
PL011State *s = PL011(obj);
|
2019-02-21 19:17:46 +01:00
|
|
|
int i;
|
2006-04-09 03:32:52 +02:00
|
|
|
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &pl011_ops, s, "pl011", 0x1000);
|
2013-07-24 23:29:17 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2019-02-21 19:17:46 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(s->irq); i++) {
|
|
|
|
sysbus_init_irq(sbd, &s->irq[i]);
|
|
|
|
}
|
2009-05-14 23:35:07 +02:00
|
|
|
|
2020-10-10 15:57:58 +02:00
|
|
|
s->clk = qdev_init_clock_in(DEVICE(obj), "clk", pl011_clock_update, s);
|
|
|
|
|
2006-04-09 03:32:52 +02:00
|
|
|
s->read_trigger = 1;
|
|
|
|
s->ifl = 0x12;
|
|
|
|
s->cr = 0x300;
|
|
|
|
s->flags = 0x90;
|
2009-05-14 23:35:07 +02:00
|
|
|
|
2013-07-24 23:29:17 +02:00
|
|
|
s->id = pl011_id_arm;
|
2009-05-14 23:35:07 +02:00
|
|
|
}
|
|
|
|
|
2013-07-24 23:29:17 +02:00
|
|
|
static void pl011_realize(DeviceState *dev, Error **errp)
|
2009-05-14 23:35:07 +02:00
|
|
|
{
|
2013-07-24 23:29:17 +02:00
|
|
|
PL011State *s = PL011(dev);
|
|
|
|
|
2016-10-22 11:52:59 +02:00
|
|
|
qemu_chr_fe_set_handlers(&s->chr, pl011_can_receive, pl011_receive,
|
2017-07-06 14:08:49 +02:00
|
|
|
pl011_event, NULL, s, NULL, true);
|
2009-05-14 23:35:07 +02:00
|
|
|
}
|
|
|
|
|
2013-07-24 23:29:17 +02:00
|
|
|
static void pl011_class_init(ObjectClass *oc, void *data)
|
2012-01-24 20:12:29 +01:00
|
|
|
{
|
2013-07-24 23:29:17 +02:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2013-07-24 23:29:17 +02:00
|
|
|
dc->realize = pl011_realize;
|
|
|
|
dc->vmsd = &vmstate_pl011;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, pl011_properties);
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo pl011_arm_info = {
|
2013-07-24 23:29:17 +02:00
|
|
|
.name = TYPE_PL011,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2013-07-24 23:13:57 +02:00
|
|
|
.instance_size = sizeof(PL011State),
|
2013-07-24 23:29:17 +02:00
|
|
|
.instance_init = pl011_init,
|
|
|
|
.class_init = pl011_class_init,
|
2012-01-24 20:12:29 +01:00
|
|
|
};
|
|
|
|
|
2013-07-24 23:29:17 +02:00
|
|
|
static void pl011_luminary_init(Object *obj)
|
2012-01-24 20:12:29 +01:00
|
|
|
{
|
2013-07-24 23:29:17 +02:00
|
|
|
PL011State *s = PL011(obj);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2013-07-24 23:29:17 +02:00
|
|
|
s->id = pl011_id_luminary;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo pl011_luminary_info = {
|
2019-02-21 19:17:46 +01:00
|
|
|
.name = TYPE_PL011_LUMINARY,
|
2013-07-24 23:29:17 +02:00
|
|
|
.parent = TYPE_PL011,
|
|
|
|
.instance_init = pl011_luminary_init,
|
2012-01-24 20:12:29 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void pl011_register_types(void)
|
2009-05-14 23:35:07 +02:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&pl011_arm_info);
|
|
|
|
type_register_static(&pl011_luminary_info);
|
2009-05-14 23:35:07 +02:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(pl011_register_types)
|