Skip to contentSkip to conversation

ppc: Convert (mostly) from device_legacy_reset() to device_cold_reset()

PATCH Applied Peter Maydell 3 participants 9 messages May 3, 2021 – May 4, 2021

lore
Share & tools
lore
#0 lore raw

cover ppc: Convert (mostly) from device_legacy_reset() to device_cold_reset()

The old function device_legacy_reset() (which was originally device_reset() and got renamed when 3-phase-reset landed) is deprecated, because it has slightly odd semantics -- it resets the device itself, but (unlike when a device is reset as part of system reset) not any qbus it owns (and devices attached to the qbus). The replacement is device_cold_reset(), which resets the device and its bus (if any).

For a device with child bus, the two functions are identical; this patchset changes the PPC code which uses device_legacy_reset() on devices which have no qbus to use device_cold_reset() instead; this should have no functionally visible difference.

There is one other use of device_legacy_reset() in PPC code which I didn't change: in hw/ppc/spapr_pci.c:spapr_phb_children_reset(). I couldn't figure out what the children being reset here are and if they might own buses. I suspect that even if they do own buses the right thing would be to change to device_cold_reset(), but I stuck to only the changes I felt reasonably sure were definitely no-behaviour-change.

NB: tested with 'make check' and 'make check-acceptance' only.

thanks
-- PMM

Peter Maydell (3):
hw/intc/spapr_xive: Use device_cold_reset() instead of
device_legacy_reset()
hw/ppc/spapr_vio: Reset TCE table object with device_cold_reset() hw/ppc/pnv_psi: Use device_cold_reset() instead of
device_legacy_reset()

 hw/intc/spapr_xive.c | 2 +-
 hw/ppc/pnv_psi.c     | 4 ++--
 hw/ppc/spapr_vio.c   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 hw/intc/spapr_xive: Use device_cold_reset() instead of device_legacy_reset()

The h_int_reset() function resets the XIVE interrupt controller via device_legacy_reset(). We know that the interrupt controller does not have a qbus of its own, so the new device_cold_reset() function (which resets both the device and its child buses) is equivalent here to device_legacy_reset() and we can just switch to the new API.

---
 hw/intc/spapr_xive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/spapr_xive.c +1 -1
index 801bc193416..89cfa018f59 100644
@@ -1798,7 +1798,7 @@ static target_ulong h_int_reset(PowerPCCPU *cpu,
         return H_PARAMETER;
     }
 
-    device_legacy_reset(DEVICE(xive));
+    device_cold_reset(DEVICE(xive));
 
     if (spapr_xive_in_kernel(xive)) {
         Error *local_err = NULL;
Signature · 1 line
2.20.1
Applied
#2 lore raw

Re: [PATCH 1/3] hw/intc/spapr_xive: Use device_cold_reset() instead of device_legacy_reset()

Quoted 7 lines · Peter Maydell

The h_int_reset() function resets the XIVE interrupt controller via device_legacy_reset(). We know that the interrupt controller does not have a qbus of its own, so the new device_cold_reset() function (which resets both the device and its child buses) is equivalent here to device_legacy_reset() and we can just switch to the new API.

Applied to ppc-for-6.1.

Quoted 17 lines
---
 hw/intc/spapr_xive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/spapr_xive.c +1 -1
index 801bc193416..89cfa018f59 100644
@@ -1798,7 +1798,7 @@ static target_ulong h_int_reset(PowerPCCPU *cpu,
         return H_PARAMETER;
     }
 
-    device_legacy_reset(DEVICE(xive));
+    device_cold_reset(DEVICE(xive));
 
     if (spapr_xive_in_kernel(xive)) {
         Error *local_err = NULL;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw

PATCH 2/3 hw/ppc/spapr_vio: Reset TCE table object with device_cold_reset()

In reply to Peter Maydell

The spapr_vio_quiesce_one() function resets the TCE table object (TYPE_SPAPR_TCE_TABLE) via device_legacy_reset(). We know that objects of that type do not have a qbus of their own, so the new device_cold_reset() function (which resets both the device and its child buses) is equivalent here to device_legacy_reset() and we can just switch to the new API.

---
 hw/ppc/spapr_vio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_vio.c +1 -1
index ef06e0362c8..b59452bcd62 100644
@@ -310,7 +310,7 @@ int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *crq)
 static void spapr_vio_quiesce_one(SpaprVioDevice *dev)
 {
     if (dev->tcet) {
-        device_legacy_reset(DEVICE(dev->tcet));
+        device_cold_reset(DEVICE(dev->tcet));
     }
     free_crq(dev);
 }
Signature · 1 line
2.20.1
Applied
#4 lore raw

Re: [PATCH 2/3] hw/ppc/spapr_vio: Reset TCE table object with device_cold_reset()

Quoted 8 lines · Peter Maydell

The spapr_vio_quiesce_one() function resets the TCE table object (TYPE_SPAPR_TCE_TABLE) via device_legacy_reset(). We know that objects of that type do not have a qbus of their own, so the new device_cold_reset() function (which resets both the device and its child buses) is equivalent here to device_legacy_reset() and we can just switch to the new API.

Applied to ppc-for-6.1.

Actually, I strongly suspect we could just change rtas_quiesce() to cold reset the entire VIO bus, but we can look at that as a followup after checking bit more closely.

Quoted 17 lines
---
 hw/ppc/spapr_vio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_vio.c +1 -1
index ef06e0362c8..b59452bcd62 100644
@@ -310,7 +310,7 @@ int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *crq)
 static void spapr_vio_quiesce_one(SpaprVioDevice *dev)
 {
     if (dev->tcet) {
-        device_legacy_reset(DEVICE(dev->tcet));
+        device_cold_reset(DEVICE(dev->tcet));
     }
     free_crq(dev);
 }
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#5 lore raw

PATCH 3/3 hw/ppc/pnv_psi: Use device_cold_reset() instead of device_legacy_reset()

In reply to Peter Maydell

The pnv_psi.c code uses device_legacy_reset() for two purposes:
* to reset itself from its qemu_register_reset() handler
* to reset a XiveSource object it has

Neither it nor the XiveSource have any qbuses, so the new device_cold_reset() function (which resets both the device and its child buses) is equivalent here to device_legacy_reset() and we can just switch to the new API.

---
 hw/ppc/pnv_psi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ppc/pnv_psi.c +2 -2
index 3e868c8c8da..292b373f93f 100644
@@ -466,7 +466,7 @@ static void pnv_psi_reset(DeviceState *dev)
 
 static void pnv_psi_reset_handler(void *dev)
 {
-    device_legacy_reset(DEVICE(dev));
+    device_cold_reset(DEVICE(dev));
 }
 
 static void pnv_psi_realize(DeviceState *dev, Error **errp)
@@ -710,7 +710,7 @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
         break;
     case PSIHB9_INTERRUPT_CONTROL:
         if (val & PSIHB9_IRQ_RESET) {
-            device_legacy_reset(DEVICE(&psi9->source));
+            device_cold_reset(DEVICE(&psi9->source));
         }
         psi->regs[reg] = val;
         break;
Signature · 1 line
2.20.1
Applied
#6 lore raw

Re: [PATCH 3/3] hw/ppc/pnv_psi: Use device_cold_reset() instead of device_legacy_reset()

Quoted 10 lines · Peter Maydell

The pnv_psi.c code uses device_legacy_reset() for two purposes:
* to reset itself from its qemu_register_reset() handler
* to reset a XiveSource object it has

Neither it nor the XiveSource have any qbuses, so the new device_cold_reset() function (which resets both the device and its child buses) is equivalent here to device_legacy_reset() and we can just switch to the new API.

Applied to ppc-for-6.1.

Quoted 26 lines
---
 hw/ppc/pnv_psi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ppc/pnv_psi.c +2 -2
index 3e868c8c8da..292b373f93f 100644
@@ -466,7 +466,7 @@ static void pnv_psi_reset(DeviceState *dev)
 
 static void pnv_psi_reset_handler(void *dev)
 {
-    device_legacy_reset(DEVICE(dev));
+    device_cold_reset(DEVICE(dev));
 }
 
 static void pnv_psi_realize(DeviceState *dev, Error **errp)
@@ -710,7 +710,7 @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
         break;
     case PSIHB9_INTERRUPT_CONTROL:
         if (val & PSIHB9_IRQ_RESET) {
-            device_legacy_reset(DEVICE(&psi9->source));
+            device_cold_reset(DEVICE(&psi9->source));
         }
         psi->regs[reg] = val;
         break;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#7 lore raw
In reply to Peter Maydell

Hi Peter,

+Eduardo/Markus

Quoted 8 lines · Peter Maydell

The old function device_legacy_reset() (which was originally device_reset() and got renamed when 3-phase-reset landed) is deprecated, because it has slightly odd semantics -- it resets the device itself, but (unlike when a device is reset as part of system reset) not any qbus it owns (and devices attached to the qbus). The replacement is device_cold_reset(), which resets the device and its bus (if any).

Quoted 4 lines

For a device with child bus, the two functions are identical; this patchset changes the PPC code which uses device_legacy_reset() on devices which have no qbus to use device_cold_reset() instead; this should have no functionally visible difference.

So IIUC we should be able to add this check?

-- >8 --

hw/core/qdev.c +1 -0
index cefc5eaa0a9..4e03f964a42 100644
@@ -1121,6 +1122,7 @@ void device_legacy_reset(DeviceState *dev)
     DeviceClass *klass = DEVICE_GET_CLASS(dev);
 
     trace_qdev_reset(dev, object_get_typename(OBJECT(dev)));
+    assert(DEVICE_GET_CLASS(dev)->bus_type);
     if (klass->reset) {
         klass->reset(dev);
     }

---

Quoted 13 lines

There is one other use of device_legacy_reset() in PPC code which I didn't change: in hw/ppc/spapr_pci.c:spapr_phb_children_reset(). I couldn't figure out what the children being reset here are and if they might own buses. I suspect that even if they do own buses the right thing would be to change to device_cold_reset(), but I stuck to only the changes I felt reasonably sure were definitely no-behaviour-change.

NB: tested with 'make check' and 'make check-acceptance' only.

thanks
-- PMM

#8 lore raw
Quoted 27 lines · Philippe Mathieu-Daudé

Hi Peter,

+Eduardo/Markus

Quoted 8 lines · Peter Maydell

The old function device_legacy_reset() (which was originally device_reset() and got renamed when 3-phase-reset landed) is deprecated, because it has slightly odd semantics -- it resets the device itself, but (unlike when a device is reset as part of system reset) not any qbus it owns (and devices attached to the qbus). The replacement is device_cold_reset(), which resets the device and its bus (if any).

Quoted 4 lines

For a device with child bus, the two functions are identical; this patchset changes the PPC code which uses device_legacy_reset() on devices which have no qbus to use device_cold_reset() instead; this should have no functionally visible difference.

So IIUC we should be able to add this check?

-- >8 --

hw/core/qdev.c +0 -0
index cefc5eaa0a9..4e03f964a42 100644

hw/core/qdev.c void device_legacy_reset(DeviceState *dev)

Quoted 8 lines
hw/core/qdev.c +1 -1
@@ -1121,6 +1122,7 @@ void device_legacy_reset(DeviceState *dev)
     DeviceClass *klass = DEVICE_GET_CLASS(dev);
 
     trace_qdev_reset(dev, object_get_typename(OBJECT(dev)));
+    assert(DEVICE_GET_CLASS(dev)->bus_type);
     if (klass->reset) {
         klass->reset(dev);
     }
---

No, because the codepath starting at qdev_reset_all() which resets the whole qbus-and-devices tree calls device_legacy_reset() to reset a single device.

There are also probably places where we call device_legacy_reset() on devices which do have qbuses, where we need to figure out what to do (eg if they are also manually resetting the qbuses we could switch to using device_cold_reset(), or perhaps they aren't resetting the qbuses and this is technically a bug. Either way, those callsites are harder to convert.

thanks
-- PMM