diff mbox series

[v5,08/13] hw/core: deprecate old reset functions and introduce new ones

Message ID 20191018150630.31099-9-damien.hedde@greensocs.com
State New
Headers show
Series Multi-phase reset mechanism | expand

Commit Message

Damien Hedde Oct. 18, 2019, 3:06 p.m. UTC
Deprecate device_legacy_reset(), qdev_reset_all() and
qbus_reset_all() to be replaced by new functions
device_cold_reset() and bus_cold_reset() which uses resettable API.

Also introduce resettable_cold_reset_fn() which may be used as a
replacement for qdev_reset_all_fn and qbus_reset_all_fn().

Following patches will be needed to look at legacy reset call sites
and switch to resettable api. The legacy functions will be removed
when unused.

Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
---

I've removed the general helpers
+ device_reset(DeviceState *dev, ResetType type)
+ bus_reset(BusState *dev, ResetType type)
because with several reset types, all devices and buses will not
implement all of them. I think it is preferable to define a
type-specific helper every time it is needed for base classes
implementing the reset type (eg a device_pci_reset(PciDev*) for the
pci reset type if add that).

So device_reset()/bus_reset() symbol names are not taken anymore. I
don't have a strong opinion of what names should have the
device_cold_reset() and bus_cold_reset() function added in this
patch. It could be device/bus_hard_reset() (the current
qbus_reset_all() comment mention we do a "hard" reset) or simply
device/bus_reset() or anything else.
What do you think ? Any better idea ? It should be consistent with
the reset type name but we can change it also if cold is not what we
want.

Note that if we don't settle for device/bus_reset(). We can drop
the first patch that renames device_reset() to device_legacy_reset()
---
 hw/core/bus.c           |  5 +++++
 hw/core/qdev.c          |  5 +++++
 hw/core/resettable.c    |  5 +++++
 include/hw/qdev-core.h  | 27 +++++++++++++++++++++++++++
 include/hw/resettable.h |  9 +++++++++
 5 files changed, 51 insertions(+)

Comments

Philippe Mathieu-Daudé Oct. 31, 2019, 11:35 p.m. UTC | #1
On 10/18/19 5:06 PM, Damien Hedde wrote:
> Deprecate device_legacy_reset(), qdev_reset_all() and
> qbus_reset_all() to be replaced by new functions
> device_cold_reset() and bus_cold_reset() which uses resettable API.
> 
> Also introduce resettable_cold_reset_fn() which may be used as a
> replacement for qdev_reset_all_fn and qbus_reset_all_fn().
> 
> Following patches will be needed to look at legacy reset call sites
> and switch to resettable api. The legacy functions will be removed
> when unused.
> 
> Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
> ---
> 
> I've removed the general helpers
> + device_reset(DeviceState *dev, ResetType type)
> + bus_reset(BusState *dev, ResetType type)
> because with several reset types, all devices and buses will not
> implement all of them. I think it is preferable to define a
> type-specific helper every time it is needed for base classes
> implementing the reset type (eg a device_pci_reset(PciDev*) for the
> pci reset type if add that).

Agreed.

> So device_reset()/bus_reset() symbol names are not taken anymore. I
> don't have a strong opinion of what names should have the
> device_cold_reset() and bus_cold_reset() function added in this
> patch. It could be device/bus_hard_reset() (the current
> qbus_reset_all() comment mention we do a "hard" reset) or simply
> device/bus_reset() or anything else.
> What do you think ? Any better idea ? It should be consistent with
> the reset type name but we can change it also if cold is not what we
> want.

Cold/hot are self-illustrative so seems fine. Hard/soft are used in 
electronic but less in software I'd say.

> Note that if we don't settle for device/bus_reset(). We can drop
> the first patch that renames device_reset() to device_legacy_reset()
> ---
>   hw/core/bus.c           |  5 +++++
>   hw/core/qdev.c          |  5 +++++
>   hw/core/resettable.c    |  5 +++++
>   include/hw/qdev-core.h  | 27 +++++++++++++++++++++++++++
>   include/hw/resettable.h |  9 +++++++++
>   5 files changed, 51 insertions(+)
> 
> diff --git a/hw/core/bus.c b/hw/core/bus.c
> index 7c05e80db8..5f9e261bb2 100644
> --- a/hw/core/bus.c
> +++ b/hw/core/bus.c
> @@ -68,6 +68,11 @@ int qbus_walk_children(BusState *bus,
>       return 0;
>   }
>   
> +void bus_cold_reset(BusState *bus)
> +{
> +    resettable_reset(OBJECT(bus), RESET_TYPE_COLD);
> +}
> +
>   bool bus_is_in_reset(BusState *bus)
>   {
>       return resettable_is_in_reset(OBJECT(bus));
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index c5d107ea4e..3e6600ce76 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -335,6 +335,11 @@ void qbus_reset_all_fn(void *opaque)
>       qbus_reset_all(bus);
>   }
>   
> +void device_cold_reset(DeviceState *dev)
> +{
> +    resettable_reset(OBJECT(dev), RESET_TYPE_COLD);
> +}
> +
>   bool device_is_in_reset(DeviceState *dev)
>   {
>       return resettable_is_in_reset(OBJECT(dev));
> diff --git a/hw/core/resettable.c b/hw/core/resettable.c
> index 60d4285fcc..3d3200bdbc 100644
> --- a/hw/core/resettable.c
> +++ b/hw/core/resettable.c
> @@ -252,6 +252,11 @@ void resettable_change_parent(Object *obj, Object *newp, Object *oldp)
>       }
>   }
>   
> +void resettable_cold_reset_fn(void *opaque)
> +{
> +    resettable_reset((Object *) opaque, RESET_TYPE_COLD);

Why not take a Object* argument?

> +}
> +
>   void resettable_class_set_parent_phases(ResettableClass *rc,
>                                           ResettableEnterPhase enter,
>                                           ResettableHoldPhase hold,
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index 2e3346600e..1e88cb2f6a 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -386,6 +386,13 @@ int qdev_walk_children(DeviceState *dev,
>                          qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
>                          void *opaque);
>   
> +/**
> + * @qdev_reset_all:
> + * Reset @dev. See @qbus_reset_all() for more details.
> + *
> + * Note: This function is deprecated and will be removed when it becomes unused.
> + * Please use device_cold_reset() now.
> + */
>   void qdev_reset_all(DeviceState *dev);
>   void qdev_reset_all_fn(void *opaque);
>   
> @@ -398,10 +405,28 @@ void qdev_reset_all_fn(void *opaque);
>    * hard reset means that qbus_reset_all will reset all state of the device.
>    * For PCI devices, for example, this will include the base address registers
>    * or configuration space.
> + *
> + * Note: This function is deprecated and will be removed when it becomes unused.
> + * Please use bus_cold_reset() now.
>    */
>   void qbus_reset_all(BusState *bus);
>   void qbus_reset_all_fn(void *opaque);
>   
> +/**
> + * device_cold_reset:
> + * Reset device @dev and perform a recursive processing using the resettable
> + * interface. It triggers a RESET_TYPE_COLD.
> + */
> +void device_cold_reset(DeviceState *dev);
> +
> +/**
> + * bus_cold_reset:
> + *
> + * Reset bus @bus and perform a recursive processing using the resettable
> + * interface. It triggers a RESET_TYPE_COLD.
> + */
> +void bus_cold_reset(BusState *bus);
> +
>   /**
>    * device_is_in_reset:
>    * Return true if the device @dev is currently being reset.
> @@ -432,6 +457,8 @@ void qdev_machine_init(void);
>    * device_legacy_reset:
>    *
>    * Reset a single device (by calling the reset method).
> + * Note: This function is deprecated and will be removed when it becomes unused.
> + * Please use device_cold_reset() now.
>    */
>   void device_legacy_reset(DeviceState *dev);
>   
> diff --git a/include/hw/resettable.h b/include/hw/resettable.h
> index f6d379669f..6a9e17344e 100644
> --- a/include/hw/resettable.h
> +++ b/include/hw/resettable.h
> @@ -198,6 +198,15 @@ bool resettable_is_in_reset(Object *obj);
>    */
>   void resettable_change_parent(Object *obj, Object *newp, Object *oldp);
>   
> +/**
> + * resettable_cold_reset_fn:
> + * Helper to call resettable_reset((Object *) opaque, RESET_TYPE_COLD).
> + *
> + * This function is typically useful to register a reset handler with
> + * qemu_register_reset.
> + */
> +void resettable_cold_reset_fn(void *opaque);
> +
>   /**
>    * resettable_class_set_parent_phases:
>    *
>
Damien Hedde Nov. 4, 2019, 12:01 p.m. UTC | #2
On 11/1/19 12:35 AM, Philippe Mathieu-Daudé wrote:
> On 10/18/19 5:06 PM, Damien Hedde wrote:
>> Deprecate device_legacy_reset(), qdev_reset_all() and
>> qbus_reset_all() to be replaced by new functions
>> device_cold_reset() and bus_cold_reset() which uses resettable API.
>>
>> Also introduce resettable_cold_reset_fn() which may be used as a
>> replacement for qdev_reset_all_fn and qbus_reset_all_fn().
>>
>> Following patches will be needed to look at legacy reset call sites
>> and switch to resettable api. The legacy functions will be removed
>> when unused.
>>
>> Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
>> ---
>> [...]>>   +void resettable_cold_reset_fn(void *opaque)
>> +{
>> +    resettable_reset((Object *) opaque, RESET_TYPE_COLD);
> 
> Why not take a Object* argument?

This function is used to register a reset callback with
qemu_register_reset() (path 10 and 11), so we need void* to match the
prototype.
Philippe Mathieu-Daudé Nov. 4, 2019, 3:42 p.m. UTC | #3
On 11/4/19 1:01 PM, Damien Hedde wrote:
> On 11/1/19 12:35 AM, Philippe Mathieu-Daudé wrote:
>> On 10/18/19 5:06 PM, Damien Hedde wrote:
>>> Deprecate device_legacy_reset(), qdev_reset_all() and
>>> qbus_reset_all() to be replaced by new functions
>>> device_cold_reset() and bus_cold_reset() which uses resettable API.
>>>
>>> Also introduce resettable_cold_reset_fn() which may be used as a
>>> replacement for qdev_reset_all_fn and qbus_reset_all_fn().
>>>
>>> Following patches will be needed to look at legacy reset call sites
>>> and switch to resettable api. The legacy functions will be removed
>>> when unused.
>>>
>>> Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
>>> ---
>>> [...]>>   +void resettable_cold_reset_fn(void *opaque)
>>> +{
>>> +    resettable_reset((Object *) opaque, RESET_TYPE_COLD);
>>
>> Why not take a Object* argument?
> 
> This function is used to register a reset callback with
> qemu_register_reset() (path 10 and 11), so we need void* to match the
> prototype.

Alright.
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Peter Maydell Nov. 29, 2019, 6:42 p.m. UTC | #4
On Fri, 18 Oct 2019 at 16:07, Damien Hedde <damien.hedde@greensocs.com> wrote:
>
> Deprecate device_legacy_reset(), qdev_reset_all() and
> qbus_reset_all() to be replaced by new functions
> device_cold_reset() and bus_cold_reset() which uses resettable API.
>
> Also introduce resettable_cold_reset_fn() which may be used as a
> replacement for qdev_reset_all_fn and qbus_reset_all_fn().
>
> Following patches will be needed to look at legacy reset call sites
> and switch to resettable api. The legacy functions will be removed
> when unused.
>
> Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
> ---
>
> I've removed the general helpers
> + device_reset(DeviceState *dev, ResetType type)
> + bus_reset(BusState *dev, ResetType type)
> because with several reset types, all devices and buses will not
> implement all of them. I think it is preferable to define a
> type-specific helper every time it is needed for base classes
> implementing the reset type (eg a device_pci_reset(PciDev*) for the
> pci reset type if add that).
>
> So device_reset()/bus_reset() symbol names are not taken anymore. I
> don't have a strong opinion of what names should have the
> device_cold_reset() and bus_cold_reset() function added in this
> patch. It could be device/bus_hard_reset() (the current
> qbus_reset_all() comment mention we do a "hard" reset) or simply
> device/bus_reset() or anything else.
> What do you think ? Any better idea ? It should be consistent with
> the reset type name but we can change it also if cold is not what we
> want.
>
> Note that if we don't settle for device/bus_reset(). We can drop
> the first patch that renames device_reset() to device_legacy_reset()

I think we're good the way you have things in this patchset.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
diff mbox series

Patch

diff --git a/hw/core/bus.c b/hw/core/bus.c
index 7c05e80db8..5f9e261bb2 100644
--- a/hw/core/bus.c
+++ b/hw/core/bus.c
@@ -68,6 +68,11 @@  int qbus_walk_children(BusState *bus,
     return 0;
 }
 
+void bus_cold_reset(BusState *bus)
+{
+    resettable_reset(OBJECT(bus), RESET_TYPE_COLD);
+}
+
 bool bus_is_in_reset(BusState *bus)
 {
     return resettable_is_in_reset(OBJECT(bus));
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index c5d107ea4e..3e6600ce76 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -335,6 +335,11 @@  void qbus_reset_all_fn(void *opaque)
     qbus_reset_all(bus);
 }
 
+void device_cold_reset(DeviceState *dev)
+{
+    resettable_reset(OBJECT(dev), RESET_TYPE_COLD);
+}
+
 bool device_is_in_reset(DeviceState *dev)
 {
     return resettable_is_in_reset(OBJECT(dev));
diff --git a/hw/core/resettable.c b/hw/core/resettable.c
index 60d4285fcc..3d3200bdbc 100644
--- a/hw/core/resettable.c
+++ b/hw/core/resettable.c
@@ -252,6 +252,11 @@  void resettable_change_parent(Object *obj, Object *newp, Object *oldp)
     }
 }
 
+void resettable_cold_reset_fn(void *opaque)
+{
+    resettable_reset((Object *) opaque, RESET_TYPE_COLD);
+}
+
 void resettable_class_set_parent_phases(ResettableClass *rc,
                                         ResettableEnterPhase enter,
                                         ResettableHoldPhase hold,
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 2e3346600e..1e88cb2f6a 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -386,6 +386,13 @@  int qdev_walk_children(DeviceState *dev,
                        qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
                        void *opaque);
 
+/**
+ * @qdev_reset_all:
+ * Reset @dev. See @qbus_reset_all() for more details.
+ *
+ * Note: This function is deprecated and will be removed when it becomes unused.
+ * Please use device_cold_reset() now.
+ */
 void qdev_reset_all(DeviceState *dev);
 void qdev_reset_all_fn(void *opaque);
 
@@ -398,10 +405,28 @@  void qdev_reset_all_fn(void *opaque);
  * hard reset means that qbus_reset_all will reset all state of the device.
  * For PCI devices, for example, this will include the base address registers
  * or configuration space.
+ *
+ * Note: This function is deprecated and will be removed when it becomes unused.
+ * Please use bus_cold_reset() now.
  */
 void qbus_reset_all(BusState *bus);
 void qbus_reset_all_fn(void *opaque);
 
+/**
+ * device_cold_reset:
+ * Reset device @dev and perform a recursive processing using the resettable
+ * interface. It triggers a RESET_TYPE_COLD.
+ */
+void device_cold_reset(DeviceState *dev);
+
+/**
+ * bus_cold_reset:
+ *
+ * Reset bus @bus and perform a recursive processing using the resettable
+ * interface. It triggers a RESET_TYPE_COLD.
+ */
+void bus_cold_reset(BusState *bus);
+
 /**
  * device_is_in_reset:
  * Return true if the device @dev is currently being reset.
@@ -432,6 +457,8 @@  void qdev_machine_init(void);
  * device_legacy_reset:
  *
  * Reset a single device (by calling the reset method).
+ * Note: This function is deprecated and will be removed when it becomes unused.
+ * Please use device_cold_reset() now.
  */
 void device_legacy_reset(DeviceState *dev);
 
diff --git a/include/hw/resettable.h b/include/hw/resettable.h
index f6d379669f..6a9e17344e 100644
--- a/include/hw/resettable.h
+++ b/include/hw/resettable.h
@@ -198,6 +198,15 @@  bool resettable_is_in_reset(Object *obj);
  */
 void resettable_change_parent(Object *obj, Object *newp, Object *oldp);
 
+/**
+ * resettable_cold_reset_fn:
+ * Helper to call resettable_reset((Object *) opaque, RESET_TYPE_COLD).
+ *
+ * This function is typically useful to register a reset handler with
+ * qemu_register_reset.
+ */
+void resettable_cold_reset_fn(void *opaque);
+
 /**
  * resettable_class_set_parent_phases:
  *