aboutsummaryrefslogtreecommitdiff
path: root/hw/milkymist-uart.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2011-10-09 13:11:50 +0200
committerAvi Kivity <avi@redhat.com>2011-10-09 13:11:50 +0200
commitdf2921d326d0903ff684759ac8508f87396b7018 (patch)
treeb9f9d2a2a116413591362278b2dc9d148c7ee943 /hw/milkymist-uart.c
parent306f66b42f961e38442d1721523dbb4906b33afb (diff)
parent02d6516c8ba00bdd6d96b622f000cb28c3449f43 (diff)
downloadqemu-df2921d326d0903ff684759ac8508f87396b7018.zip
qemu-df2921d326d0903ff684759ac8508f87396b7018.tar.gz
qemu-df2921d326d0903ff684759ac8508f87396b7018.tar.bz2
Merge remote-tracking branch 'upstream' into memory/batch
* upstream: (87 commits) target-alpha: Fix compilation errors for 32 bit hosts target-alpha: Add high-resolution access to wall clock and an alarm. target-alpha: Implement HALT IPR. target-alpha: Implement WAIT IPR. target-alpha: Add CLIPPER emulation. target-alpha: Add custom PALcode image for CLIPPER emulation. target-alpha: Honor icount for RPCC instruction. tcg/s390: Remove unused tcg_out_addi() tcg/ia64: Remove unused tcg_out_addi() ARM: fix segfault ppc64: Fix linker script pseries: Implement set-time-of-day RTAS function pseries: Refactor spapr irq allocation PPC: Clean up BookE timer code PPC: booke timers KVM: PPC: Use HIOR setting for -M pseries with PR KVM KVM: Update kernel headers KVM: Update kernel headers PPC: Fix heathrow PIC to use little endian MMIO PPC: Fix via-cuda memory registration ... Conflicts: hw/milkymist-uart.c hw/ppce500_mpc8544ds.c Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'hw/milkymist-uart.c')
-rw-r--r--hw/milkymist-uart.c73
1 files changed, 63 insertions, 10 deletions
diff --git a/hw/milkymist-uart.c b/hw/milkymist-uart.c
index 128cd8c..5404ca9 100644
--- a/hw/milkymist-uart.c
+++ b/hw/milkymist-uart.c
@@ -30,21 +30,54 @@
enum {
R_RXTX = 0,
R_DIV,
+ R_STAT,
+ R_CTRL,
+ R_DBG,
R_MAX
};
+enum {
+ STAT_THRE = (1<<0),
+ STAT_RX_EVT = (1<<1),
+ STAT_TX_EVT = (1<<2),
+};
+
+enum {
+ CTRL_RX_IRQ_EN = (1<<0),
+ CTRL_TX_IRQ_EN = (1<<1),
+ CTRL_THRU_EN = (1<<2),
+};
+
+enum {
+ DBG_BREAK_EN = (1<<0),
+};
+
struct MilkymistUartState {
SysBusDevice busdev;
MemoryRegion regs_region;
CharDriverState *chr;
-
- qemu_irq rx_irq;
- qemu_irq tx_irq;
+ qemu_irq irq;
uint32_t regs[R_MAX];
};
typedef struct MilkymistUartState MilkymistUartState;
+static void uart_update_irq(MilkymistUartState *s)
+{
+ int rx_event = s->regs[R_STAT] & STAT_RX_EVT;
+ int tx_event = s->regs[R_STAT] & STAT_TX_EVT;
+ int rx_irq_en = s->regs[R_CTRL] & CTRL_RX_IRQ_EN;
+ int tx_irq_en = s->regs[R_CTRL] & CTRL_TX_IRQ_EN;
+
+ if ((rx_irq_en && rx_event) || (tx_irq_en && tx_event)) {
+ trace_milkymist_uart_raise_irq();
+ qemu_irq_raise(s->irq);
+ } else {
+ trace_milkymist_uart_lower_irq();
+ qemu_irq_lower(s->irq);
+ }
+}
+
static uint64_t uart_read(void *opaque, target_phys_addr_t addr,
unsigned size)
{
@@ -54,7 +87,12 @@ static uint64_t uart_read(void *opaque, target_phys_addr_t addr,
addr >>= 2;
switch (addr) {
case R_RXTX:
+ r = s->regs[addr];
+ break;
case R_DIV:
+ case R_STAT:
+ case R_CTRL:
+ case R_DBG:
r = s->regs[addr];
break;
@@ -83,18 +121,26 @@ static void uart_write(void *opaque, target_phys_addr_t addr, uint64_t value,
if (s->chr) {
qemu_chr_fe_write(s->chr, &ch, 1);
}
- trace_milkymist_uart_pulse_irq_tx();
- qemu_irq_pulse(s->tx_irq);
+ s->regs[R_STAT] |= STAT_TX_EVT;
break;
case R_DIV:
+ case R_CTRL:
+ case R_DBG:
s->regs[addr] = value;
break;
+ case R_STAT:
+ /* write one to clear bits */
+ s->regs[addr] &= ~(value & (STAT_RX_EVT | STAT_TX_EVT));
+ break;
+
default:
error_report("milkymist_uart: write access to unknown register 0x"
TARGET_FMT_plx, addr << 2);
break;
}
+
+ uart_update_irq(s);
}
static const MemoryRegionOps uart_mmio_ops = {
@@ -111,14 +157,19 @@ static void uart_rx(void *opaque, const uint8_t *buf, int size)
{
MilkymistUartState *s = opaque;
+ assert(!(s->regs[R_STAT] & STAT_RX_EVT));
+
+ s->regs[R_STAT] |= STAT_RX_EVT;
s->regs[R_RXTX] = *buf;
- trace_milkymist_uart_pulse_irq_rx();
- qemu_irq_pulse(s->rx_irq);
+
+ uart_update_irq(s);
}
static int uart_can_rx(void *opaque)
{
- return 1;
+ MilkymistUartState *s = opaque;
+
+ return !(s->regs[R_STAT] & STAT_RX_EVT);
}
static void uart_event(void *opaque, int event)
@@ -133,14 +184,16 @@ static void milkymist_uart_reset(DeviceState *d)
for (i = 0; i < R_MAX; i++) {
s->regs[i] = 0;
}
+
+ /* THRE is always set */
+ s->regs[R_STAT] = STAT_THRE;
}
static int milkymist_uart_init(SysBusDevice *dev)
{
MilkymistUartState *s = FROM_SYSBUS(typeof(*s), dev);
- sysbus_init_irq(dev, &s->rx_irq);
- sysbus_init_irq(dev, &s->tx_irq);
+ sysbus_init_irq(dev, &s->irq);
memory_region_init_io(&s->regs_region, &uart_mmio_ops, s,
"milkymist-uart", R_MAX * 4);