Skip to contentSkip to conversation

sparc32 esp fix spurious interrupts in chip reset

PATCH In review Artyom Tarasenko 2 participants 9 messages May 30, 2010 – Jun 10, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc32 esp fix spurious interrupts in chip reset

lower interrupt during chip reset. Otherwise the ESP_RSTAT register may get out of sync with the IRQ line status. This effect became visible after commit 65899fe3

---
 hw/esp.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/esp.c +1 -0
index 0a8cf6e..0532c67 100644
@@ -423,6 +423,7 @@ static void esp_reset(DeviceState *d)
 {
     ESPState *s = container_of(d, ESPState, busdev.qdev);
 
+    esp_lower_irq(s);
     memset(s->rregs, 0, ESP_REGS);
     memset(s->wregs, 0, ESP_REGS);
     s->rregs[ESP_TCHI] = TCHI_FAS100A; // Indicate fas100a
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 3 lines · Artyom Tarasenko

lower interrupt during chip reset. Otherwise the ESP_RSTAT register may get out of sync with the IRQ line status. This effect became visible after commit 65899fe3

Hard reset handlers should not touch qemu_irqs, because on cold start, the receiving end may be unprepared to handle the signal. See 0d0a7e69e853639b123798877e019c3c7ee6634a, bc26e55a6615dc594be425d293db40d5cdcdb84b and 42f1ced228c9b616cfa2b69846025271618e4ef5.

For ESP there are two other sources of reset: signal from DMA and chip reset command. On those cases, lowering IRQ makes sense.

So the correct fix is to refactor the reset handling a bit. Does this patch also fix your test case?

From 44d40083652d5135ecb567fea4cff4f109ee4cd0 Mon Sep 17 00:00:00 2001
From: Blue Swirl <[email protected]>
Date: Tue, 1 Jun 2010 17:37:13 +0000
Subject: [PATCH] esp: lower IRQ on soft reset

42f1ced228c9b616cfa2b69846025271618e4ef5 removed irq lowering during reset. However, for chip reset command and DMA reset signal, its actually the correct thing to do.

Lower IRQ on soft reset only.

---
 hw/esp.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
hw/esp.c +14 -5
index 0a8cf6e..7740879 100644
@@ -419,7 +419,7 @@ static void handle_ti(ESPState *s)
     }
 }
 
-static void esp_reset(DeviceState *d)
+static void esp_hard_reset(DeviceState *d)
 {
     ESPState *s = container_of(d, ESPState, busdev.qdev);
 
@@ -435,10 +435,19 @@ static void esp_reset(DeviceState *d)
     s->rregs[ESP_CFG1] = 7;
 }
 
+static void esp_soft_reset(DeviceState *d)
+{
+    ESPState *s = container_of(d, ESPState, busdev.qdev);
+
+    qemu_irq_lower(s->irq);
+    esp_hard_reset(d);
+}
+
 static void parent_esp_reset(void *opaque, int irq, int level)
 {
-    if (level)
-        esp_reset(opaque);
+    if (level) {
+        esp_soft_reset(opaque);
+    }
 }
 
 static uint32_t esp_mem_readb(void *opaque, target_phys_addr_t addr)
@@ -528,7 +537,7 @@ static void esp_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
             break;
         case CMD_RESET:
             DPRINTF("Chip reset (%2.2x)\n", val);
-            esp_reset(&s->busdev.qdev);
+            esp_soft_reset(&s->busdev.qdev);
             break;
         case CMD_BUSRESET:
             DPRINTF("Bus reset (%2.2x)\n", val);
@@ -679,7 +688,7 @@ static SysBusDeviceInfo esp_info = {
     .qdev.name  = "esp",
     .qdev.size  = sizeof(ESPState),
     .qdev.vmsd  = &vmstate_esp,
-    .qdev.reset = esp_reset,
+    .qdev.reset = esp_hard_reset,
     .qdev.props = (Property[]) {
         {.name = NULL}
     }
Signature · 1 line
1.5.6.5
#2 lore raw

2010/6/1 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 3 lines · Artyom Tarasenko

lower interrupt during chip reset. Otherwise the ESP_RSTAT register may get out of sync with the IRQ line status. This effect became visible after commit 65899fe3

Hard reset handlers should not touch qemu_irqs, because on cold start, the receiving end may be unprepared to handle the signal.

Wouldn't the real hardware lower irq on the hardware reset? And if it would not, would it still clear the corresponding bit in the ESP_RSTAT register?

Quoted 10 lines

See
0d0a7e69e853639b123798877e019c3c7ee6634a,
bc26e55a6615dc594be425d293db40d5cdcdb84b and
42f1ced228c9b616cfa2b69846025271618e4ef5.

For ESP there are two other sources of reset: signal from DMA and chip reset command. On those cases, lowering IRQ makes sense.

So the correct fix is to refactor the reset handling a bit. Does this patch also fix your test case?

It does, but

+static void esp_soft_reset(DeviceState *d)
+{
+ ESPState *s = container_of(d, ESPState, busdev.qdev);
+
+ qemu_irq_lower(s->irq);

Shouldn't it be esp_lower_irq(s)? What's going to happen to the DMA_INTR bit if dma was the source of the irq?

+ esp_hard_reset(d);
+}
+

Signature · 4 lines
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/
#3 lore raw
Quoted 11 lines · Artyom Tarasenko

2010/6/1 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 3 lines · Artyom Tarasenko

lower interrupt during chip reset. Otherwise the ESP_RSTAT register may get out of sync with the IRQ line status. This effect became visible after commit 65899fe3

Hard reset handlers should not touch qemu_irqs, because on cold start, the receiving end may be unprepared to handle the signal.

Wouldn't the real hardware lower irq on the hardware reset?

Yes, but since qemu_irqs have no state, and on a cold start or system reset all other devices are guaranteed to be reset, the callback would be useless.

Quoted 2 lines

And if it would not, would it still clear the corresponding bit in the ESP_RSTAT register?

All registers are set to zero in the lines below.

Quoted 20 lines
Quoted 11 lines

See
0d0a7e69e853639b123798877e019c3c7ee6634a,
bc26e55a6615dc594be425d293db40d5cdcdb84b and
42f1ced228c9b616cfa2b69846025271618e4ef5.

For ESP there are two other sources of reset: signal from DMA and chip reset command. On those cases, lowering IRQ makes sense.

So the correct fix is to refactor the reset handling a bit. Does this patch also fix your test case?

It does, but

hw/esp.c +5 -0
+static void esp_soft_reset(DeviceState *d)
+{
+    ESPState *s = container_of(d, ESPState, busdev.qdev);
+
+    qemu_irq_lower(s->irq);
Quoted 2 lines

Shouldn't it be esp_lower_irq(s)? What's going to happen to the DMA_INTR bit if dma was the source of the irq?

Again, the registers are zeroed in esp_hard_reset().

Thanks for testing.

#4 lore raw

2010/6/1 Blue Swirl <[email protected]>:

Quoted 43 lines
Quoted 11 lines · Artyom Tarasenko

2010/6/1 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 3 lines · Artyom Tarasenko

lower interrupt during chip reset. Otherwise the ESP_RSTAT register may get out of sync with the IRQ line status. This effect became visible after commit 65899fe3

Hard reset handlers should not touch qemu_irqs, because on cold start, the receiving end may be unprepared to handle the signal.

Wouldn't the real hardware lower irq on the hardware reset?

Yes, but since qemu_irqs have no state, and on a cold start or system reset all other devices are guaranteed to be reset, the callback would be useless.

Quoted 2 lines

And if it would not, would it still clear the corresponding bit in the ESP_RSTAT register?

All registers are set to zero in the lines below.

Quoted 20 lines
Quoted 11 lines

See
0d0a7e69e853639b123798877e019c3c7ee6634a,
bc26e55a6615dc594be425d293db40d5cdcdb84b and
42f1ced228c9b616cfa2b69846025271618e4ef5.

For ESP there are two other sources of reset: signal from DMA and chip reset command. On those cases, lowering IRQ makes sense.

So the correct fix is to refactor the reset handling a bit. Does this patch also fix your test case?

It does, but

hw/esp.c +5 -0
+static void esp_soft_reset(DeviceState *d)
+{
+    ESPState *s = container_of(d, ESPState, busdev.qdev);
+
+    qemu_irq_lower(s->irq);
Quoted 4 lines
Quoted 2 lines

Shouldn't it be esp_lower_irq(s)? What's going to happen to the DMA_INTR bit if dma was the source of the irq?

Again, the registers are zeroed in esp_hard_reset().

How does it zero the _DMA_ registers? And sparc32_dma does share the IRQ line with ESP, doesn't it?

Quoted 3 lines

Thanks for testing.

Signature · 4 lines
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/
#5 lore raw
Quoted 44 lines · Artyom Tarasenko

2010/6/1 Blue Swirl <[email protected]>:

Quoted 43 lines
Quoted 11 lines · Artyom Tarasenko

2010/6/1 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 3 lines · Artyom Tarasenko

lower interrupt during chip reset. Otherwise the ESP_RSTAT register may get out of sync with the IRQ line status. This effect became visible after commit 65899fe3

Hard reset handlers should not touch qemu_irqs, because on cold start, the receiving end may be unprepared to handle the signal.

Wouldn't the real hardware lower irq on the hardware reset?

Yes, but since qemu_irqs have no state, and on a cold start or system reset all other devices are guaranteed to be reset, the callback would be useless.

Quoted 2 lines

And if it would not, would it still clear the corresponding bit in the ESP_RSTAT register?

All registers are set to zero in the lines below.

Quoted 20 lines
Quoted 11 lines

See
0d0a7e69e853639b123798877e019c3c7ee6634a,
bc26e55a6615dc594be425d293db40d5cdcdb84b and
42f1ced228c9b616cfa2b69846025271618e4ef5.

For ESP there are two other sources of reset: signal from DMA and chip reset command. On those cases, lowering IRQ makes sense.

So the correct fix is to refactor the reset handling a bit. Does this patch also fix your test case?

It does, but

hw/esp.c +5 -0
+static void esp_soft_reset(DeviceState *d)
+{
+    ESPState *s = container_of(d, ESPState, busdev.qdev);
+
+    qemu_irq_lower(s->irq);
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Shouldn't it be esp_lower_irq(s)? What's going to happen to the DMA_INTR bit if dma was the source of the irq?

Again, the registers are zeroed in esp_hard_reset().

How does it zero the _DMA_ registers? And sparc32_dma does share the IRQ line with ESP, doesn't it?

I'd suppose DMA registers are separate and they would not be cleared by for example ESP chip reset command. The IRQ goes from ESP to DMA, DMA has another line going to interrupt controller.

#6 lore raw

2010/6/4 Blue Swirl <[email protected]>:

Quoted 51 lines
Quoted 49 lines · Artyom Tarasenko

2010/6/1 Blue Swirl <[email protected]>:

Quoted 47 lines
Quoted 11 lines · Artyom Tarasenko

2010/6/1 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 3 lines · Artyom Tarasenko

lower interrupt during chip reset. Otherwise the ESP_RSTAT register may get out of sync with the IRQ line status. This effect became visible after commit 65899fe3

Hard reset handlers should not touch qemu_irqs, because on cold start, the receiving end may be unprepared to handle the signal.

Wouldn't the real hardware lower irq on the hardware reset?

Yes, but since qemu_irqs have no state, and on a cold start or system reset all other devices are guaranteed to be reset, the callback would be useless.

Quoted 2 lines

And if it would not, would it still clear the corresponding bit in the ESP_RSTAT register?

All registers are set to zero in the lines below.

Quoted 20 lines
Quoted 11 lines

See
0d0a7e69e853639b123798877e019c3c7ee6634a,
bc26e55a6615dc594be425d293db40d5cdcdb84b and
42f1ced228c9b616cfa2b69846025271618e4ef5.

For ESP there are two other sources of reset: signal from DMA and chip reset command. On those cases, lowering IRQ makes sense.

So the correct fix is to refactor the reset handling a bit. Does this patch also fix your test case?

It does, but

hw/esp.c +5 -0
+static void esp_soft_reset(DeviceState *d)
+{
+    ESPState *s = container_of(d, ESPState, busdev.qdev);
+
+    qemu_irq_lower(s->irq);
Quoted 2 lines

Shouldn't it be esp_lower_irq(s)? What's going to happen to the DMA_INTR bit if dma was the source of the irq?

Again, the registers are zeroed in esp_hard_reset().

Quoted 6 lines
Quoted 2 lines

How does it zero the _DMA_ registers? And sparc32_dma does share the IRQ line with ESP, doesn't it?

I'd suppose DMA registers are separate and they would not be cleared by for example ESP chip reset command. The IRQ goes from ESP to DMA, DMA has another line going to interrupt controller.

But do we have separate DMA lines in qemu? If we do, I'm absolutely fine with qemu_irq_lower(s->irq) . If we don't, imagine the following scenario: DMA rises an IRQ, then esp chip reset happens, and then... DMA can't rise the IRQ anymore.

Signature · 4 lines
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/
#7 lore raw
Quoted 55 lines · Artyom Tarasenko

2010/6/4 Blue Swirl <[email protected]>:

Quoted 54 lines
Quoted 51 lines · Artyom Tarasenko

2010/6/1 Blue Swirl <[email protected]>:

Quoted 43 lines
Quoted 11 lines · Artyom Tarasenko

2010/6/1 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 3 lines · Artyom Tarasenko

lower interrupt during chip reset. Otherwise the ESP_RSTAT register may get out of sync with the IRQ line status. This effect became visible after commit 65899fe3

Hard reset handlers should not touch qemu_irqs, because on cold start, the receiving end may be unprepared to handle the signal.

Wouldn't the real hardware lower irq on the hardware reset?

Yes, but since qemu_irqs have no state, and on a cold start or system reset all other devices are guaranteed to be reset, the callback would be useless.

Quoted 2 lines

And if it would not, would it still clear the corresponding bit in the ESP_RSTAT register?

All registers are set to zero in the lines below.

Quoted 20 lines
Quoted 11 lines

See
0d0a7e69e853639b123798877e019c3c7ee6634a,
bc26e55a6615dc594be425d293db40d5cdcdb84b and
42f1ced228c9b616cfa2b69846025271618e4ef5.

For ESP there are two other sources of reset: signal from DMA and chip reset command. On those cases, lowering IRQ makes sense.

So the correct fix is to refactor the reset handling a bit. Does this patch also fix your test case?

It does, but

hw/esp.c +5 -0
+static void esp_soft_reset(DeviceState *d)
+{
+    ESPState *s = container_of(d, ESPState, busdev.qdev);
+
+    qemu_irq_lower(s->irq);
Quoted 4 lines
Quoted 2 lines

Shouldn't it be esp_lower_irq(s)? What's going to happen to the DMA_INTR bit if dma was the source of the irq?

Again, the registers are zeroed in esp_hard_reset().

How does it zero the _DMA_ registers? And sparc32_dma does share the IRQ line with ESP, doesn't it?

Quoted 8 lines
Quoted 3 lines

I'd suppose DMA registers are separate and they would not be cleared by for example ESP chip reset command. The IRQ goes from ESP to DMA, DMA has another line going to interrupt controller.

But do we have separate DMA lines in qemu? If we do, I'm absolutely fine with qemu_irq_lower(s->irq) . If we don't, imagine the following scenario: DMA rises an IRQ, then esp chip reset happens, and then... DMA can't rise the IRQ anymore.

What ESP does with its IRQ line does not stop DMA from using its line.

#8 lore raw

2010/6/9 Blue Swirl <[email protected]>:

Quoted 61 lines
Quoted 59 lines · Artyom Tarasenko

2010/6/4 Blue Swirl <[email protected]>:

Quoted 57 lines
Quoted 44 lines · Artyom Tarasenko

2010/6/1 Blue Swirl <[email protected]>:

Quoted 43 lines
Quoted 11 lines · Artyom Tarasenko

2010/6/1 Blue Swirl <[email protected]>:

Quoted 8 lines
Quoted 3 lines · Artyom Tarasenko

lower interrupt during chip reset. Otherwise the ESP_RSTAT register may get out of sync with the IRQ line status. This effect became visible after commit 65899fe3

Hard reset handlers should not touch qemu_irqs, because on cold start, the receiving end may be unprepared to handle the signal.

Wouldn't the real hardware lower irq on the hardware reset?

Yes, but since qemu_irqs have no state, and on a cold start or system reset all other devices are guaranteed to be reset, the callback would be useless.

Quoted 2 lines

And if it would not, would it still clear the corresponding bit in the ESP_RSTAT register?

All registers are set to zero in the lines below.

Quoted 20 lines
Quoted 11 lines

See
0d0a7e69e853639b123798877e019c3c7ee6634a,
bc26e55a6615dc594be425d293db40d5cdcdb84b and
42f1ced228c9b616cfa2b69846025271618e4ef5.

For ESP there are two other sources of reset: signal from DMA and chip reset command. On those cases, lowering IRQ makes sense.

So the correct fix is to refactor the reset handling a bit. Does this patch also fix your test case?

It does, but

(quoted diff) +5 -0
+static void esp_soft_reset(DeviceState *d)
+{
+    ESPState *s = container_of(d, ESPState, busdev.qdev);
+
+    qemu_irq_lower(s->irq);
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Shouldn't it be esp_lower_irq(s)? What's going to happen to the DMA_INTR bit if dma was the source of the irq?

Again, the registers are zeroed in esp_hard_reset().

How does it zero the _DMA_ registers? And sparc32_dma does share the IRQ line with ESP, doesn't it?

I'd suppose DMA registers are separate and they would not be cleared by for example ESP chip reset command. The IRQ goes from ESP to DMA, DMA has another line going to interrupt controller.

Quoted 6 lines
Quoted 4 lines

But do we have separate DMA lines in qemu? If we do, I'm absolutely fine with qemu_irq_lower(s->irq) . If we don't, imagine the following scenario: DMA rises an IRQ, then esp chip reset happens, and then... DMA can't rise the IRQ anymore.

What ESP does with its IRQ line does not stop DMA from using its line.

Then I'm fine with your patch.

Signature · 4 lines
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/