Skip to contentSkip to conversation

Add rtc reset function.

PATCH Superseded Gleb Natapov 6 participants 14 messages Jun 8, 2009 – Jun 9, 2009

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Add rtc reset function.

On reset:
Periodic Interrupt Enable (PIE) bit is cleared to zero Alarm Interrupt Enable (AIE) bit is cleared to zero Update ended Interrupt Flag (UF) bit is cleared to zero Interrupt Request status Flag (IRQF) bit is cleared to zero Periodic Interrupt Flag (PF) bit is cleared to zero Alarm Interrupt Flag (AF) bit is cleared to zero Square Wave output Enable (SQWE) zero

---
 hw/mc146818rtc.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
hw/mc146818rtc.c +19 -0
index 888b85a..98a2273 100644
@@ -568,6 +568,22 @@ static int rtc_load_td(QEMUFile *f, void *opaque, int version_id)
 }
 #endif
 
+static void rtc_reset(void *opaque)
+{
+    RTCState *s = opaque;
+
+    /* clear PIE,AIE,SQWE on reset */
+    s->cmos_data[RTC_REG_B] &= ~((1<<6) | (1<<5) | (1<<3));
+
+    /* clear UF,IRQF,PF,AF on reset */
+    s->cmos_data[RTC_REG_C] &= ~((1<<4) | (1<<7) | (1<<6) | (1<<5));
+
+#ifdef TARGET_I386
+    if (rtc_td_hack)
+	    s->irq_coalesced = 0;
+#endif
+}
+
 RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
 {
     RTCState *s;
@@ -606,6 +622,8 @@ RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
     if (rtc_td_hack)
         register_savevm("mc146818rtc-td", base, 1, rtc_save_td, rtc_load_td, s);
 #endif
+    qemu_register_reset(rtc_reset, 0, s);
+
     return s;
 }
 
@@ -721,5 +739,6 @@ RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
     if (rtc_td_hack)
         register_savevm("mc146818rtc-td", base, 1, rtc_save_td, rtc_load_td, s);
 #endif
+    qemu_register_reset(rtc_reset, 0, s);
     return s;
 }
Signature · 1 line
1.6.2.1
#1 lore raw

PATCH 2/3 Add pci_bus_reset() function.

To reset internal irq handling data structures.

---
 hw/pci.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
hw/pci.c +16 -0
index 02b335f..89fefdf 100644
@@ -88,6 +88,21 @@ static int  pcibus_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
+static void pci_bus_reset(void *opaque)
+{
+    PCIBus *bus = (PCIBus *)opaque;
+    int i;
+
+    for (i = 0; i < bus->nirq; i++) {
+        bus->irq_count[i] = 0;
+    }
+    for (i = 0; i < PCI_DEVICES_MAX; i++) {
+        if (bus->devices[i])
+            memset(bus->devices[i]->irq_state, 0,
+                   sizeof(bus->devices[i]->irq_state));
+    }
+}
+
 PCIBus *pci_register_bus(DeviceState *parent, const char *name,
                          pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                          qemu_irq *pic, int devfn_min, int nirq)
@@ -106,6 +121,7 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,
     bus->next = first_bus;
     first_bus = bus;
     register_savevm("PCIBUS", nbus++, 1, pcibus_save, pcibus_load, bus);
+    qemu_register_reset(pci_bus_reset, 0, bus);
     return bus;
 }
 
Signature · 1 line
1.6.2.1
#11 lore raw

PATCH 3/3 Call piix3_reset() on system reset.

In reply to Gleb Natapov

Also zero pci_irq_levels on reset to avoid stuck irq after reset.

---
 hw/piix_pci.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/piix_pci.c +3 -0
index 914a65a..7b545ac 100644
@@ -267,6 +267,8 @@ static void piix3_reset(PCIDevice *d)
     pci_conf[0xab] = 0x00;
     pci_conf[0xac] = 0x00;
     pci_conf[0xae] = 0x00;
+
+    memset(pci_irq_levels, 0, sizeof(pci_irq_levels));
 }
 
 static void piix4_reset(PCIDevice *d)
@@ -339,6 +341,7 @@ int piix3_init(PCIBus *bus, int devfn)
         PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
 
     piix3_reset(d);
+    qemu_register_reset(piix3_reset, 0, d);
     return d->devfn;
 }
 
Signature · 1 line
1.6.2.1
#12 lore raw
In reply to Gleb Natapov
Quoted 21 lines · Gleb Natapov

On reset:
Periodic Interrupt Enable (PIE) bit is cleared to zero Alarm Interrupt Enable (AIE) bit is cleared to zero Update ended Interrupt Flag (UF) bit is cleared to zero Interrupt Request status Flag (IRQF) bit is cleared to zero Periodic Interrupt Flag (PF) bit is cleared to zero Alarm Interrupt Flag (AF) bit is cleared to zero Square Wave output Enable (SQWE) zero

---
 hw/mc146818rtc.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
hw/mc146818rtc.c +0 -0
index 888b85a..98a2273 100644
@@ -568,6 +568,22 @@ static int rtc_load_td(QEMUFile *f, void *opaque, int version_id)
 }
 #endif

hw/mc146818rtc.c static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) · line 579

Quoted 10 lines
hw/mc146818rtc.c +9 -0
 
+static void rtc_reset(void *opaque)
+{
+    RTCState *s = opaque;
+
+    /* clear PIE,AIE,SQWE on reset */
+    s->cmos_data[RTC_REG_B] &= ~((1<<6) | (1<<5) | (1<<3));
+
+    /* clear UF,IRQF,PF,AF on reset */
+    s->cmos_data[RTC_REG_C] &= ~((1<<4) | (1<<7) | (1<<6) | (1<<5));

Didn't check what the rest of this file does, but maybe it's a chance to give those bits names, ie. #define something.

Quoted 20 lines
hw/mc146818rtc.c +9 -0
+
+#ifdef TARGET_I386
+    if (rtc_td_hack)
+	    s->irq_coalesced = 0;
+#endif
+}
+
 RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
 {
     RTCState *s;
@@ -606,6 +622,8 @@ RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
     if (rtc_td_hack)
         register_savevm("mc146818rtc-td", base, 1, rtc_save_td, rtc_load_td, s);
 #endif
+    qemu_register_reset(rtc_reset, 0, s);
+
     return s;
 }
 

hw/mc146818rtc.c RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq, · line 744

Quoted 6 lines
hw/mc146818rtc.c +1 -0
@@ -721,5 +739,6 @@ RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
     if (rtc_td_hack)
         register_savevm("mc146818rtc-td", base, 1, rtc_save_td, rtc_load_td, s);
 #endif
+    qemu_register_reset(rtc_reset, 0, s);
     return s;
 }

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#13 lore raw
Quoted 23 lines · Jan Kiszka
Quoted 22 lines · Gleb Natapov

On reset:
Periodic Interrupt Enable (PIE) bit is cleared to zero Alarm Interrupt Enable (AIE) bit is cleared to zero Update ended Interrupt Flag (UF) bit is cleared to zero Interrupt Request status Flag (IRQF) bit is cleared to zero Periodic Interrupt Flag (PF) bit is cleared to zero Alarm Interrupt Flag (AF) bit is cleared to zero Square Wave output Enable (SQWE) zero

---
 hw/mc146818rtc.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
hw/mc146818rtc.c +0 -0
index 888b85a..98a2273 100644
@@ -568,6 +568,22 @@ static int rtc_load_td(QEMUFile *f, void *opaque, int version_id)
 }
 #endif
 
Quoted 13 lines

hw/mc146818rtc.c static int rtc_load_td(QEMUFile *f, void *opaque, int version_id) · line 579

Quoted 9 lines
hw/mc146818rtc.c +9 -0
+static void rtc_reset(void *opaque)
+{
+    RTCState *s = opaque;
+
+    /* clear PIE,AIE,SQWE on reset */
+    s->cmos_data[RTC_REG_B] &= ~((1<<6) | (1<<5) | (1<<3));
+
+    /* clear UF,IRQF,PF,AF on reset */
+    s->cmos_data[RTC_REG_C] &= ~((1<<4) | (1<<7) | (1<<6) | (1<<5));

Didn't check what the rest of this file does, but maybe it's a chance to give those bits names, ie. #define something.

Part of them already has names, I'll define rest.

Quoted 19 lines
Quoted 19 lines
hw/mc146818rtc.c +9 -0
+
+#ifdef TARGET_I386
+    if (rtc_td_hack)
+	    s->irq_coalesced = 0;
+#endif
+}
+
 RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
 {
     RTCState *s;
@@ -606,6 +622,8 @@ RTCState *rtc_init_sqw(int base, qemu_irq irq, qemu_irq sqw_irq, int base_year)
     if (rtc_td_hack)
         register_savevm("mc146818rtc-td", base, 1, rtc_save_td, rtc_load_td, s);
 #endif
+    qemu_register_reset(rtc_reset, 0, s);
+
     return s;
 }
 
Quoted 13 lines

hw/mc146818rtc.c RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq, · line 744

Quoted 7 lines
hw/mc146818rtc.c +1 -0
@@ -721,5 +739,6 @@ RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
     if (rtc_td_hack)
         register_savevm("mc146818rtc-td", base, 1, rtc_save_td, rtc_load_td, s);
 #endif
+    qemu_register_reset(rtc_reset, 0, s);
     return s;
 }

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux

--
Gleb.

#2 lore raw

Re: [Qemu-devel] [PATCH 2/3] Add pci_bus_reset() function.

In reply to Gleb Natapov
Quoted 22 lines · Gleb Natapov

To reset internal irq handling data structures.

---
 hw/pci.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
hw/pci.c +6 -0
index 02b335f..89fefdf 100644
@@ -88,6 +88,21 @@ static int  pcibus_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
+static void pci_bus_reset(void *opaque)
+{
+    PCIBus *bus = (PCIBus *)opaque;
+    int i;
+
+    for (i = 0; i < bus->nirq; i++) {

hw/pci.c static int pcibus_load(QEMUFile *f, void *opaque, int version_id) · line 106

Quoted 10 lines
hw/pci.c +9 -0
+        bus->irq_count[i] = 0;
+    }
+    for (i = 0; i < PCI_DEVICES_MAX; i++) {
+        if (bus->devices[i])
+            memset(bus->devices[i]->irq_state, 0,
+                   sizeof(bus->devices[i]->irq_state));
+    }
+}
+
 

Shouldn't each device's reset function bring its line low, thus zeroing the irq_state naturally?

If not, we have a bug somewhere. Note we have exactly the same issue with save/restore.

Signature · 1 line
error compiling committee.c: too many arguments to function
#3 lore raw

Re: [Qemu-devel] [PATCH 2/3] Add pci_bus_reset() function.

Quoted 36 lines · Avi Kivity
Quoted 21 lines · Gleb Natapov

To reset internal irq handling data structures.

---
 hw/pci.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
hw/pci.c +5 -0
index 02b335f..89fefdf 100644
@@ -88,6 +88,21 @@ static int  pcibus_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 +static void pci_bus_reset(void *opaque)
+{
+    PCIBus *bus = (PCIBus *)opaque;
+    int i;
+
+    for (i = 0; i < bus->nirq; i++) {

hw/pci.c static int pcibus_load(QEMUFile *f, void *opaque, int version_id) · line 105

Quoted 10 lines
hw/pci.c +9 -0
+        bus->irq_count[i] = 0;
+    }
+    for (i = 0; i < PCI_DEVICES_MAX; i++) {
+        if (bus->devices[i])
+            memset(bus->devices[i]->irq_state, 0,
+                   sizeof(bus->devices[i]->irq_state));
+    }
+}
+
 

Shouldn't each device's reset function bring its line low, thus zeroing the irq_state naturally?

Quoted 3 lines

If not, we have a bug somewhere. Note we have exactly the same issue with save/restore.

They should, but I haven't found one that does.

--
Gleb.

#4 lore raw

Re: [Qemu-devel] [PATCH 2/3] Add pci_bus_reset() function.

Quoted 38 lines · Gleb Natapov
Quoted 36 lines · Avi Kivity
Quoted 22 lines · Gleb Natapov

To reset internal irq handling data structures.

---
 hw/pci.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
hw/pci.c +6 -0
index 02b335f..89fefdf 100644
@@ -88,6 +88,21 @@ static int  pcibus_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 +static void pci_bus_reset(void *opaque)
+{
+    PCIBus *bus = (PCIBus *)opaque;
+    int i;
+
+    for (i = 0; i < bus->nirq; i++) {
+        bus->irq_count[i] = 0;

hw/pci.c static int pcibus_load(QEMUFile *f, void *opaque, int version_id) · line 106

Quoted 10 lines
hw/pci.c +8 -0
+    }
+    for (i = 0; i < PCI_DEVICES_MAX; i++) {
+        if (bus->devices[i])
+            memset(bus->devices[i]->irq_state, 0,
+                   sizeof(bus->devices[i]->irq_state));
+    }
+}
+
 
 

Shouldn't each device's reset function bring its line low, thus zeroing the irq_state naturally?

Quoted 5 lines
Quoted 3 lines

If not, we have a bug somewhere. Note we have exactly the same issue with save/restore.

They should, but I haven't found one that does.

This is matter of definitions and not right or wrong, Since PCI in current imp save and load its state then it only logical that PCI will also reset it state.

Yaniv

Quoted 3 lines

--
Gleb.

#5 lore raw

Re: [Qemu-devel] [PATCH 2/3] Add pci_bus_reset() function.

In reply to Gleb Natapov
Quoted 38 lines · Gleb Natapov
Quoted 36 lines · Avi Kivity
Quoted 22 lines · Gleb Natapov

To reset internal irq handling data structures.

---
 hw/pci.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
hw/pci.c +6 -0
index 02b335f..89fefdf 100644
@@ -88,6 +88,21 @@ static int  pcibus_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 +static void pci_bus_reset(void *opaque)
+{
+    PCIBus *bus = (PCIBus *)opaque;
+    int i;
+
+    for (i = 0; i < bus->nirq; i++) {
+        bus->irq_count[i] = 0;

hw/pci.c static int pcibus_load(QEMUFile *f, void *opaque, int version_id) · line 106

Quoted 10 lines
hw/pci.c +8 -0
+    }
+    for (i = 0; i < PCI_DEVICES_MAX; i++) {
+        if (bus->devices[i])
+            memset(bus->devices[i]->irq_state, 0,
+                   sizeof(bus->devices[i]->irq_state));
+    }
+}
+
 
 

Shouldn't each device's reset function bring its line low, thus zeroing the irq_state naturally?

Quoted 5 lines
Quoted 3 lines

If not, we have a bug somewhere. Note we have exactly the same issue with save/restore.

They should, but I haven't found one that does.

virtio does and so do many others. Sad thing is that all should do it since the line is shared. e1000 and rtl8139 do not register a reset handler.

Maybe we should make it a required callback for pci_qdev_register? or better have every (pci?) device register several callback together.

#6 lore raw

Re: [Qemu-devel] [PATCH 2/3] Add pci_bus_reset() function.

Quoted 43 lines · Dor Laor
Quoted 42 lines · Gleb Natapov
Quoted 40 lines · Avi Kivity
Quoted 21 lines · Gleb Natapov

To reset internal irq handling data structures.

---
 hw/pci.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
hw/pci.c +5 -0
index 02b335f..89fefdf 100644
@@ -88,6 +88,21 @@ static int  pcibus_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 +static void pci_bus_reset(void *opaque)
+{
+    PCIBus *bus = (PCIBus *)opaque;
+    int i;
+
+    for (i = 0; i < bus->nirq; i++) {

hw/pci.c static int pcibus_load(QEMUFile *f, void *opaque, int version_id) · line 105

Quoted 10 lines
hw/pci.c +9 -0
+        bus->irq_count[i] = 0;
+    }
+    for (i = 0; i < PCI_DEVICES_MAX; i++) {
+        if (bus->devices[i])
+            memset(bus->devices[i]->irq_state, 0,
+                   sizeof(bus->devices[i]->irq_state));
+    }
+}
+
 

Shouldn't each device's reset function bring its line low, thus zeroing the irq_state naturally?

If not, we have a bug somewhere. Note we have exactly the same issue
with save/restore.

Quoted 6 lines
Quoted 2 lines

They should, but I haven't found one that does.

virtio does and so do many others. Sad thing is that all should do it since the line is shared.
e1000 and rtl8139 do not register a reset handler.

So somebody (not me) should go and fix all others.

Quoted 2 lines

Maybe we should make it a required callback for pci_qdev_register? or better have every (pci?) device register several callback together.

May be.

--
Gleb.

#7 lore raw

Re: [Qemu-devel] [PATCH 2/3] Add pci_bus_reset() function.

Quoted 44 lines · Gleb Natapov
Quoted 43 lines · Dor Laor
Quoted 42 lines · Gleb Natapov
Quoted 40 lines · Avi Kivity
Quoted 21 lines · Gleb Natapov

To reset internal irq handling data structures.

---
 hw/pci.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
hw/pci.c +5 -0
index 02b335f..89fefdf 100644
@@ -88,6 +88,21 @@ static int  pcibus_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 +static void pci_bus_reset(void *opaque)
+{
+    PCIBus *bus = (PCIBus *)opaque;
+    int i;
+
+    for (i = 0; i < bus->nirq; i++) {

hw/pci.c static int pcibus_load(QEMUFile *f, void *opaque, int version_id) · line 105

Quoted 10 lines
hw/pci.c +9 -0
+        bus->irq_count[i] = 0;
+    }
+    for (i = 0; i < PCI_DEVICES_MAX; i++) {
+        if (bus->devices[i])
+            memset(bus->devices[i]->irq_state, 0,
+                   sizeof(bus->devices[i]->irq_state));
+    }
+}
+
 

Shouldn't each device's reset function bring its line low, thus zeroing the irq_state naturally?

If not, we have a bug somewhere. Note we have exactly the same issue
with save/restore.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

They should, but I haven't found one that does.

virtio does and so do many others. Sad thing is that all should do it since the line is shared.
e1000 and rtl8139 do not register a reset handler.

So somebody (not me) should go and fix all others.

Here's a 5 min patch to add reset to e1000 and rtl8139. Not too difficult?

Quoted 4 lines
Quoted 2 lines

Maybe we should make it a required callback for pci_qdev_register? or better have every (pci?) device register several callback together.

May be.

If we go to this, I'd also make savevm/loadvm mandatory.

From 32c86e95b258515099d04f9eff48efc57a469bf7 Mon Sep 17 00:00:00 2001
From: Blue Swirl <[email protected]>
Date: Tue, 9 Jun 2009 15:02:00 +0000
Subject: [PATCH] Register reset functions for e1000 and rtl8139

---
 hw/e1000.c   |   21 ++++++++++++++-------
 hw/rtl8139.c |    4 +++-
 2 files changed, 17 insertions(+), 8 deletions(-)
hw/e1000.c +14 -7
index 2665792..a04d7b1 100644
@@ -1058,6 +1058,18 @@ pci_e1000_uninit(PCIDevice *dev)
     return 0;
 }
 
+static void e1000_reset(void *opaque)
+{
+    E1000State *d = opaque;
+
+    memset(d->phy_reg, 0, sizeof d->phy_reg);
+    memmove(d->phy_reg, phy_reg_init, sizeof phy_reg_init);
+    memset(d->mac_reg, 0, sizeof d->mac_reg);
+    memmove(d->mac_reg, mac_reg_init, sizeof mac_reg_init);
+    d->rxbuf_min_shift = 1;
+    memset(&d->tx, 0, sizeof d->tx);
+}
+
 static void pci_e1000_init(PCIDevice *pci_dev)
 {
     E1000State *d = (E1000State *)pci_dev;
@@ -1098,13 +1110,6 @@ static void pci_e1000_init(PCIDevice *pci_dev)
     checksum = (uint16_t) EEPROM_SUM - checksum;
     d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
 
-    memset(d->phy_reg, 0, sizeof d->phy_reg);
-    memmove(d->phy_reg, phy_reg_init, sizeof phy_reg_init);
-    memset(d->mac_reg, 0, sizeof d->mac_reg);
-    memmove(d->mac_reg, mac_reg_init, sizeof mac_reg_init);
-    d->rxbuf_min_shift = 1;
-    memset(&d->tx, 0, sizeof d->tx);
-
     d->vc = qdev_get_vlan_client(&d->dev.qdev,
                                  e1000_receive, e1000_can_receive,
                                  e1000_cleanup, d);
@@ -1114,6 +1119,8 @@ static void pci_e1000_init(PCIDevice *pci_dev)
 
     register_savevm(info_str, -1, 2, nic_save, nic_load, d);
     d->dev.unregister = pci_e1000_uninit;
+    qemu_register_reset(e1000_reset, 0, d);
+    e1000_reset(d);
 }
 
 static void e1000_register_devices(void)
hw/rtl8139.c +3 -1
index d99f35c..ea2ca25 100644
@@ -1170,8 +1170,9 @@ static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize)
     s->RxBufAddr = 0;
 }
 
-static void rtl8139_reset(RTL8139State *s)
+static void rtl8139_reset(void *opaque)
 {
+    RTL8139State *s = opaque;
     int i;
 
     /* restore MAC address */
@@ -3473,6 +3474,7 @@ static void pci_rtl8139_init(PCIDevice *dev)
 
     s->pci_dev = (PCIDevice *)d;
     qdev_get_macaddr(&dev->qdev, s->macaddr);
+    qemu_register_reset(rtl8139_reset, 0, s);
     rtl8139_reset(s);
     s->vc = qdev_get_vlan_client(&dev->qdev,
                                  rtl8139_receive, rtl8139_can_receive,
Signature · 1 line
1.5.6.5
#8 lore raw

Re: [Qemu-devel] [PATCH 2/3] Add pci_bus_reset() function.

Quoted 47 lines · Blue Swirl
Quoted 46 lines · Gleb Natapov
Quoted 45 lines · Dor Laor
Quoted 44 lines · Gleb Natapov
Quoted 36 lines · Avi Kivity
Quoted 21 lines · Gleb Natapov

To reset internal irq handling data structures.

---
 hw/pci.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
hw/pci.c +5 -0
index 02b335f..89fefdf 100644
@@ -88,6 +88,21 @@ static int  pcibus_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 +static void pci_bus_reset(void *opaque)
+{
+    PCIBus *bus = (PCIBus *)opaque;
+    int i;
+
+    for (i = 0; i < bus->nirq; i++) {

hw/pci.c static int pcibus_load(QEMUFile *f, void *opaque, int version_id) · line 105

Quoted 10 lines
hw/pci.c +9 -0
+        bus->irq_count[i] = 0;
+    }
+    for (i = 0; i < PCI_DEVICES_MAX; i++) {
+        if (bus->devices[i])
+            memset(bus->devices[i]->irq_state, 0,
+                   sizeof(bus->devices[i]->irq_state));
+    }
+}
+
 

Shouldn't each device's reset function bring its line low, thus zeroing the irq_state naturally?

Quoted 4 lines

If not, we have a bug somewhere. Note we have exactly the same issue
with save/restore.

They should, but I haven't found one that does.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

virtio does and so do many others. Sad thing is that all should do it since the line is shared.
e1000 and rtl8139 do not register a reset handler.

So somebody (not me) should go and fix all others.

Here's a 5 min patch to add reset to e1000 and rtl8139. Not too difficult?

Very handy. I just discovered that e1000 continue to write to memory after OS reboot with some OSes. Will check if this fixes it.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Maybe we should make it a required callback for pci_qdev_register? or better have every (pci?) device register several callback together.

May be.

If we go to this, I'd also make savevm/loadvm mandatory.

We need this for device hot unplug. We have to be able to reset only one device at a time.

--
Gleb.

#9 lore raw

Re: [Qemu-devel] [PATCH 2/3] Add pci_bus_reset() function.

In reply to Blue Swirl
Quoted 2 lines · Blue Swirl

Here's a 5 min patch to add reset to e1000 and rtl8139. Not too difficult?

By the way I see that you don't lower irq line in e1000 reset handler (haven't looked at rtl8139 one).

--
Gleb.

#10 lore raw

Re: [Qemu-devel] [PATCH 2/3] Add pci_bus_reset() function.

Quoted 7 lines · Gleb Natapov
Quoted 2 lines · Blue Swirl

Here's a 5 min patch to add reset to e1000 and rtl8139. Not too difficult?

By the way I see that you don't lower irq line in e1000 reset handler
(haven't looked at rtl8139 one).

Also on loadvm the irq line should be toggled. Fixed in this patch.

From 3ab033016cbdfa5079c187946992da9d7c41492a Mon Sep 17 00:00:00 2001
From: Blue Swirl <[email protected]>
Date: Tue, 9 Jun 2009 16:03:41 +0000
Subject: [PATCH] Update irqs on reset and device load

---
 hw/e1000.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
hw/e1000.c +9 -1
index a04d7b1..03fad4c 100644
@@ -150,12 +150,18 @@ ioport_map(PCIDevice *pci_dev, int region_num, uint32_t addr,
 }
 
 static void
+update_irqs(E1000State *s)
+{
+    qemu_set_irq(s->dev.irq[0], (s->mac_reg[IMS] & s->mac_reg[ICR]) != 0);
+}
+
+static void
 set_interrupt_cause(E1000State *s, int index, uint32_t val)
 {
     if (val)
         val |= E1000_ICR_INT_ASSERTED;
     s->mac_reg[ICR] = val;
-    qemu_set_irq(s->dev.irq[0], (s->mac_reg[IMS] & s->mac_reg[ICR]) != 0);
+    update_irqs(s);
 }
 
 static void
@@ -970,6 +976,7 @@ nic_load(QEMUFile *f, void *opaque, int version_id)
         for (j = 0; j < mac_regarraystosave[i].size; j++)
             qemu_get_be32s(f,
                            s->mac_reg + mac_regarraystosave[i].array0 + j);
+    update_irqs(s);
     return 0;
 }
 
@@ -1068,6 +1075,7 @@ static void e1000_reset(void *opaque)
     memmove(d->mac_reg, mac_reg_init, sizeof mac_reg_init);
     d->rxbuf_min_shift = 1;
     memset(&d->tx, 0, sizeof d->tx);
+    update_irqs(d);
 }
 
 static void pci_e1000_init(PCIDevice *pci_dev)
Signature · 1 line
1.5.6.5