Skip to contentSkip to conversation

hw/char/escc: Lower irq when transmit buffer is filled

PATCH Superseded Stephen Checkoway 2 participants 3 messages Apr 17, 2019 – Apr 19, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/char/escc: Lower irq when transmit buffer is filled

The SCC/ESCC will briefly stop asserting an interrupt when the transmit FIFO is filled.

This code doesn't model the transmit FIFO/shift register so the pending transmit interrupt is never deasserted which means that an edge-triggered interrupt controller will never see the low-to-high transition it needs to raise another interrupt. The practical consequence of this is that guest firmware with an interrupt service routine for the ESCC that does not send all of the data it has immediately will stop sending data if the following sequence of events occurs:
1. Disable processor interrupts
2. Write a character to the ESCC
3. Add additional characters to a buffer which is drained by the ISR
4. Enable processor interrupts

In this case, the first character will be sent, the interrupt will fire and the ISR will output the second character. Since the pending transmit interrupt remains asserted, no additional interrupts will ever fire.

This fixes that situation by explicitly lowering the IRQ when a character is written to the buffer and no other interrupts are currently pending.

---
 hw/char/escc.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/char/escc.c +7 -0
index 628f5f81f7..c5b05a63f1 100644
@@ -509,6 +509,13 @@ static void escc_mem_write(void *opaque, hwaddr addr,
         break;
     case SERIAL_DATA:
         trace_escc_mem_writeb_data(CHN_C(s), val);
+        /*
+         * Lower the irq when data is written to the Tx buffer and no other
+         * interrupts are currently pending. The irq will be raised again once
+         * the Tx buffer becomes empty below.
+         */
+        s->txint = 0;
+        escc_update_irq(s);
         s->tx = val;
         if (s->wregs[W_TXCTRL2] & TXCTRL2_TXEN) { // tx enabled
             if (qemu_chr_fe_backend_connected(&s->chr)) {
Signature · 1 line
2.20.1 (Apple Git-117)
Reviewed-by on v2 1/1
#1 lore raw
Quoted 16 lines · Stephen Checkoway

The SCC/ESCC will briefly stop asserting an interrupt when the transmit FIFO is filled.

This code doesn't model the transmit FIFO/shift register so the pending transmit interrupt is never deasserted which means that an edge-triggered interrupt controller will never see the low-to-high transition it needs to raise another interrupt. The practical consequence of this is that guest firmware with an interrupt service routine for the ESCC that does not send all of the data it has immediately will stop sending data if the following sequence of events occurs:
1. Disable processor interrupts
2. Write a character to the ESCC
3. Add additional characters to a buffer which is drained by the ISR
4. Enable processor interrupts

Quoted 4 lines

In this case, the first character will be sent, the interrupt will fire and the ISR will output the second character. Since the pending transmit interrupt remains asserted, no additional interrupts will ever fire.

You might want to add a line expliciting the chipset model which forced you to do that patch (Z85C30).

Quoted 15 lines

This fixes that situation by explicitly lowering the IRQ when a character is written to the buffer and no other interrupts are currently pending.

---
 hw/char/escc.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/char/escc.c +0 -0
index 628f5f81f7..c5b05a63f1 100644

hw/char/escc.c static void escc_mem_write(void *opaque, hwaddr addr, · line 518

Quoted 10 lines
hw/char/escc.c +7 -0
@@ -509,6 +509,13 @@ static void escc_mem_write(void *opaque, hwaddr addr,
         break;
     case SERIAL_DATA:
         trace_escc_mem_writeb_data(CHN_C(s), val);
+        /*
+         * Lower the irq when data is written to the Tx buffer and no other
+         * interrupts are currently pending. The irq will be raised again once
+         * the Tx buffer becomes empty below.
+         */
+        s->txint = 0;
+        escc_update_irq(s);

Way better, thanks :)

Note: the Z85C30 has a 1-byte transmit FIFO and 3-byte receive FIFO. Our model default is the ESCC, and we use ESCC_SERIO_QUEUE_SIZE=256 byte for rx FIFO... If needed we can add properties and use a white list of chipset with their tx/rx FIFO size.

Quoted 4 lines
hw/char/escc.c +0 -0
         s->tx = val;
         if (s->wregs[W_TXCTRL2] & TXCTRL2_TXEN) { // tx enabled
             if (qemu_chr_fe_backend_connected(&s->chr)) {
#2 lore raw
Quoted 21 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Stephen Checkoway

The SCC/ESCC will briefly stop asserting an interrupt when the transmit FIFO is filled.

This code doesn't model the transmit FIFO/shift register so the pending transmit interrupt is never deasserted which means that an edge-triggered interrupt controller will never see the low-to-high transition it needs to raise another interrupt. The practical consequence of this is that guest firmware with an interrupt service routine for the ESCC that does not send all of the data it has immediately will stop sending data if the following sequence of events occurs:
1. Disable processor interrupts
2. Write a character to the ESCC
3. Add additional characters to a buffer which is drained by the ISR
4. Enable processor interrupts

Quoted 7 lines
Quoted 4 lines

In this case, the first character will be sent, the interrupt will fire and the ISR will output the second character. Since the pending transmit interrupt remains asserted, no additional interrupts will ever fire.

You might want to add a line expliciting the chipset model which forced you to do that patch (Z85C30).

Done.

Thanks for looking at this.

Signature · 1 line
Stephen Checkoway