This changes the IPC realize and reset handlers in DeviceRealize and
DeviceReset handlers. parent handlers are now called from the
inheriting classes which is a cleaner object pattern.
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
include/hw/ppc/xics.h | 5 +++--
hw/intc/xics.c | 10 ----------
hw/intc/xics_kvm.c | 34 +++++++++++++++++++++++++++-------
hw/intc/xics_pnv.c | 15 +++++++++++++--
4 files changed, 43 insertions(+), 21 deletions(-)
diff --git a/include/hw/ppc/xics.h b/include/hw/ppc/xics.h
index adc5f437b118..6ac8a9392da6 100644
--- a/include/hw/ppc/xics.h
+++ b/include/hw/ppc/xics.h
@@ -65,10 +65,11 @@ typedef struct XICSFabric XICSFabric;
struct ICPStateClass {
DeviceClass parent_class;
- void (*realize)(ICPState *icp, Error **errp);
+ DeviceRealize parent_realize;
+ DeviceReset parent_reset;
+
void (*pre_save)(ICPState *icp);
int (*post_load)(ICPState *icp, int version_id);
- void (*reset)(ICPState *icp);
void (*synchronize_state)(ICPState *icp);
};
diff --git a/hw/intc/xics.c b/hw/intc/xics.c
index b351262d1db9..ef5c612dc711 100644
--- a/hw/intc/xics.c
+++ b/hw/intc/xics.c
@@ -294,7 +294,6 @@ static const VMStateDescription vmstate_icp_server = {
static void icp_reset(void *dev)
{
ICPState *icp = ICP(dev);
- ICPStateClass *icpc = ICP_GET_CLASS(icp);
icp->xirr = 0;
icp->pending_priority = 0xff;
@@ -302,16 +301,11 @@ static void icp_reset(void *dev)
/* Make all outputs are deasserted */
qemu_set_irq(icp->output, 0);
-
- if (icpc->reset) {
- icpc->reset(icp);
- }
}
static void icp_realize(DeviceState *dev, Error **errp)
{
ICPState *icp = ICP(dev);
- ICPStateClass *icpc = ICP_GET_CLASS(dev);
PowerPCCPU *cpu;
CPUPPCState *env;
Object *obj;
@@ -351,10 +345,6 @@ static void icp_realize(DeviceState *dev, Error **errp)
return;
}
- if (icpc->realize) {
- icpc->realize(icp, errp);
- }
-
qemu_register_reset(icp_reset, dev);
vmstate_register(NULL, icp->cs->cpu_index, &vmstate_icp_server, icp);
}
diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
index 57d0ebbfaa8a..50d7457abd34 100644
--- a/hw/intc/xics_kvm.c
+++ b/hw/intc/xics_kvm.c
@@ -114,22 +114,38 @@ static int icp_set_kvm_state(ICPState *icp, int version_id)
return 0;
}
-static void icp_kvm_reset(ICPState *icp)
+static void icp_kvm_reset(DeviceState *dev)
{
- icp_set_kvm_state(icp, 1);
+ ICPStateClass *icpc = ICP_GET_CLASS(dev);
+
+ icpc->parent_reset(dev);
+
+ icp_set_kvm_state(ICP(dev), 1);
}
-static void icp_kvm_realize(ICPState *icp, Error **errp)
+static void icp_kvm_realize(DeviceState *dev, Error **errp)
{
- CPUState *cs = icp->cs;
+ ICPState *icp = ICP(dev);
+ ICPStateClass *icpc = ICP_GET_CLASS(icp);
+ Error *local_err = NULL;
+ CPUState *cs;
KVMEnabledICP *enabled_icp;
- unsigned long vcpu_id = kvm_arch_vcpu_id(cs);
+ unsigned long vcpu_id;
int ret;
if (kernel_xics_fd == -1) {
abort();
}
+ icpc->parent_realize(dev, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ cs = icp->cs;
+ vcpu_id = kvm_arch_vcpu_id(cs);
+
/*
* If we are reusing a parked vCPU fd corresponding to the CPU
* which was hot-removed earlier we don't have to renable
@@ -154,12 +170,16 @@ static void icp_kvm_realize(ICPState *icp, Error **errp)
static void icp_kvm_class_init(ObjectClass *klass, void *data)
{
+ DeviceClass *dc = DEVICE_CLASS(klass);
ICPStateClass *icpc = ICP_CLASS(klass);
+ device_class_set_parent_realize(dc, icp_kvm_realize,
+ &icpc->parent_realize);
+ device_class_set_parent_reset(dc, icp_kvm_reset,
+ &icpc->parent_reset);
+
icpc->pre_save = icp_get_kvm_state;
icpc->post_load = icp_set_kvm_state;
- icpc->realize = icp_kvm_realize;
- icpc->reset = icp_kvm_reset;
icpc->synchronize_state = icp_synchronize_state;
}
diff --git a/hw/intc/xics_pnv.c b/hw/intc/xics_pnv.c
index c87de2189cf7..fa48505f365e 100644
--- a/hw/intc/xics_pnv.c
+++ b/hw/intc/xics_pnv.c
@@ -18,6 +18,7 @@
*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "sysemu/sysemu.h"
#include "qemu/log.h"
#include "hw/ppc/xics.h"
@@ -158,9 +159,18 @@ static const MemoryRegionOps pnv_icp_ops = {
},
};
-static void pnv_icp_realize(ICPState *icp, Error **errp)
+static void pnv_icp_realize(DeviceState *dev, Error **errp)
{
+ ICPState *icp = ICP(dev);
PnvICPState *pnv_icp = PNV_ICP(icp);
+ ICPStateClass *icpc = ICP_GET_CLASS(icp);
+ Error *local_err = NULL;
+
+ icpc->parent_realize(dev, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
memory_region_init_io(&pnv_icp->mmio, OBJECT(icp), &pnv_icp_ops,
icp, "icp-thread", 0x1000);
@@ -171,7 +181,8 @@ static void pnv_icp_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
ICPStateClass *icpc = ICP_CLASS(klass);
- icpc->realize = pnv_icp_realize;
+ device_class_set_parent_realize(dc, pnv_icp_realize,
+ &icpc->parent_realize);
dc->desc = "PowerNV ICP";
}
--
2.13.6
On Wed, Jun 20, 2018 at 12:24:13PM +0200, Cédric Le Goater wrote:
> This changes the IPC realize and reset handlers in DeviceRealize and
> DeviceReset handlers. parent handlers are now called from the
> inheriting classes which is a cleaner object pattern.
>
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
Applied to ppc-for-3.0, thanks.
> ---
> include/hw/ppc/xics.h | 5 +++--
> hw/intc/xics.c | 10 ----------
> hw/intc/xics_kvm.c | 34 +++++++++++++++++++++++++++-------
> hw/intc/xics_pnv.c | 15 +++++++++++++--
> 4 files changed, 43 insertions(+), 21 deletions(-)
>
> diff --git a/include/hw/ppc/xics.h b/include/hw/ppc/xics.h
> index adc5f437b118..6ac8a9392da6 100644
> --- a/include/hw/ppc/xics.h
> +++ b/include/hw/ppc/xics.h
> @@ -65,10 +65,11 @@ typedef struct XICSFabric XICSFabric;
> struct ICPStateClass {
> DeviceClass parent_class;
>
> - void (*realize)(ICPState *icp, Error **errp);
> + DeviceRealize parent_realize;
> + DeviceReset parent_reset;
> +
> void (*pre_save)(ICPState *icp);
> int (*post_load)(ICPState *icp, int version_id);
> - void (*reset)(ICPState *icp);
> void (*synchronize_state)(ICPState *icp);
> };
>
> diff --git a/hw/intc/xics.c b/hw/intc/xics.c
> index b351262d1db9..ef5c612dc711 100644
> --- a/hw/intc/xics.c
> +++ b/hw/intc/xics.c
> @@ -294,7 +294,6 @@ static const VMStateDescription vmstate_icp_server = {
> static void icp_reset(void *dev)
> {
> ICPState *icp = ICP(dev);
> - ICPStateClass *icpc = ICP_GET_CLASS(icp);
>
> icp->xirr = 0;
> icp->pending_priority = 0xff;
> @@ -302,16 +301,11 @@ static void icp_reset(void *dev)
>
> /* Make all outputs are deasserted */
> qemu_set_irq(icp->output, 0);
> -
> - if (icpc->reset) {
> - icpc->reset(icp);
> - }
> }
>
> static void icp_realize(DeviceState *dev, Error **errp)
> {
> ICPState *icp = ICP(dev);
> - ICPStateClass *icpc = ICP_GET_CLASS(dev);
> PowerPCCPU *cpu;
> CPUPPCState *env;
> Object *obj;
> @@ -351,10 +345,6 @@ static void icp_realize(DeviceState *dev, Error **errp)
> return;
> }
>
> - if (icpc->realize) {
> - icpc->realize(icp, errp);
> - }
> -
> qemu_register_reset(icp_reset, dev);
> vmstate_register(NULL, icp->cs->cpu_index, &vmstate_icp_server, icp);
> }
> diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
> index 57d0ebbfaa8a..50d7457abd34 100644
> --- a/hw/intc/xics_kvm.c
> +++ b/hw/intc/xics_kvm.c
> @@ -114,22 +114,38 @@ static int icp_set_kvm_state(ICPState *icp, int version_id)
> return 0;
> }
>
> -static void icp_kvm_reset(ICPState *icp)
> +static void icp_kvm_reset(DeviceState *dev)
> {
> - icp_set_kvm_state(icp, 1);
> + ICPStateClass *icpc = ICP_GET_CLASS(dev);
> +
> + icpc->parent_reset(dev);
> +
> + icp_set_kvm_state(ICP(dev), 1);
> }
>
> -static void icp_kvm_realize(ICPState *icp, Error **errp)
> +static void icp_kvm_realize(DeviceState *dev, Error **errp)
> {
> - CPUState *cs = icp->cs;
> + ICPState *icp = ICP(dev);
> + ICPStateClass *icpc = ICP_GET_CLASS(icp);
> + Error *local_err = NULL;
> + CPUState *cs;
> KVMEnabledICP *enabled_icp;
> - unsigned long vcpu_id = kvm_arch_vcpu_id(cs);
> + unsigned long vcpu_id;
> int ret;
>
> if (kernel_xics_fd == -1) {
> abort();
> }
>
> + icpc->parent_realize(dev, &local_err);
> + if (local_err) {
> + error_propagate(errp, local_err);
> + return;
> + }
> +
> + cs = icp->cs;
> + vcpu_id = kvm_arch_vcpu_id(cs);
> +
> /*
> * If we are reusing a parked vCPU fd corresponding to the CPU
> * which was hot-removed earlier we don't have to renable
> @@ -154,12 +170,16 @@ static void icp_kvm_realize(ICPState *icp, Error **errp)
>
> static void icp_kvm_class_init(ObjectClass *klass, void *data)
> {
> + DeviceClass *dc = DEVICE_CLASS(klass);
> ICPStateClass *icpc = ICP_CLASS(klass);
>
> + device_class_set_parent_realize(dc, icp_kvm_realize,
> + &icpc->parent_realize);
> + device_class_set_parent_reset(dc, icp_kvm_reset,
> + &icpc->parent_reset);
> +
> icpc->pre_save = icp_get_kvm_state;
> icpc->post_load = icp_set_kvm_state;
> - icpc->realize = icp_kvm_realize;
> - icpc->reset = icp_kvm_reset;
> icpc->synchronize_state = icp_synchronize_state;
> }
>
> diff --git a/hw/intc/xics_pnv.c b/hw/intc/xics_pnv.c
> index c87de2189cf7..fa48505f365e 100644
> --- a/hw/intc/xics_pnv.c
> +++ b/hw/intc/xics_pnv.c
> @@ -18,6 +18,7 @@
> */
>
> #include "qemu/osdep.h"
> +#include "qapi/error.h"
> #include "sysemu/sysemu.h"
> #include "qemu/log.h"
> #include "hw/ppc/xics.h"
> @@ -158,9 +159,18 @@ static const MemoryRegionOps pnv_icp_ops = {
> },
> };
>
> -static void pnv_icp_realize(ICPState *icp, Error **errp)
> +static void pnv_icp_realize(DeviceState *dev, Error **errp)
> {
> + ICPState *icp = ICP(dev);
> PnvICPState *pnv_icp = PNV_ICP(icp);
> + ICPStateClass *icpc = ICP_GET_CLASS(icp);
> + Error *local_err = NULL;
> +
> + icpc->parent_realize(dev, &local_err);
> + if (local_err) {
> + error_propagate(errp, local_err);
> + return;
> + }
>
> memory_region_init_io(&pnv_icp->mmio, OBJECT(icp), &pnv_icp_ops,
> icp, "icp-thread", 0x1000);
> @@ -171,7 +181,8 @@ static void pnv_icp_class_init(ObjectClass *klass, void *data)
> DeviceClass *dc = DEVICE_CLASS(klass);
> ICPStateClass *icpc = ICP_CLASS(klass);
>
> - icpc->realize = pnv_icp_realize;
> + device_class_set_parent_realize(dc, pnv_icp_realize,
> + &icpc->parent_realize);
> dc->desc = "PowerNV ICP";
> }
>
--
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
© 2016 - 2026 Red Hat, Inc.