mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
cpu: Use DeviceClass reset instead of a special CPUClass reset
The CPUClass has a 'reset' method. This is a legacy from when TYPE_CPU used not to inherit from TYPE_DEVICE. We don't need it any more, as we can simply use the TYPE_DEVICE reset. The 'cpu_reset()' function is kept as the API which most places use to reset a CPU; it is now a wrapper which calls device_cold_reset() and then the tracepoint function. This change should not cause CPU objects to be reset more often than they are at the moment, because: * nobody is directly calling device_cold_reset() or qdev_reset_all() on CPU objects * no CPU object is on a qbus, so they will not be reset either by somebody calling qbus_reset_all()/bus_cold_reset(), or by the main "reset sysbus and everything in the qbus tree" reset that most devices are reset by Note that this does not change the need for each machine or whatever to use qemu_register_reset() to arrange to call cpu_reset() -- that is necessary because CPU objects are not on any qbus, so they don't get reset when the qbus tree rooted at the sysbus bus is reset, and this isn't being changed here. All the changes to the files under target/ were made using the included Coccinelle script, except: (1) the deletion of the now-inaccurate and not terribly useful "CPUClass::reset" comments was done with a perl one-liner afterwards: perl -n -i -e '/ CPUClass::reset/ or print' target/*/*.c (2) this bit of the s390 change was done by hand, because the Coccinelle script is not sophisticated enough to handle the parent_reset call being inside another function: | @@ -96,8 +96,9 @@ static void s390_cpu_reset(CPUState *s, cpu_reset_type type) | S390CPU *cpu = S390_CPU(s); | S390CPUClass *scc = S390_CPU_GET_CLASS(cpu); | CPUS390XState *env = &cpu->env; |+ DeviceState *dev = DEVICE(s); | |- scc->parent_reset(s); |+ scc->parent_reset(dev); | cpu->env.sigp_order = 0; | s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu); Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Message-Id: <20200303100511.5498-1-peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
committed by
Eduardo Habkost
parent
4ba59be1d6
commit
781c67ca55
+4
-15
@@ -239,27 +239,16 @@ void cpu_dump_statistics(CPUState *cpu, int flags)
|
||||
}
|
||||
}
|
||||
|
||||
void cpu_class_set_parent_reset(CPUClass *cc,
|
||||
void (*child_reset)(CPUState *cpu),
|
||||
void (**parent_reset)(CPUState *cpu))
|
||||
{
|
||||
*parent_reset = cc->reset;
|
||||
cc->reset = child_reset;
|
||||
}
|
||||
|
||||
void cpu_reset(CPUState *cpu)
|
||||
{
|
||||
CPUClass *klass = CPU_GET_CLASS(cpu);
|
||||
|
||||
if (klass->reset != NULL) {
|
||||
(*klass->reset)(cpu);
|
||||
}
|
||||
device_cold_reset(DEVICE(cpu));
|
||||
|
||||
trace_guest_cpu_reset(cpu);
|
||||
}
|
||||
|
||||
static void cpu_common_reset(CPUState *cpu)
|
||||
static void cpu_common_reset(DeviceState *dev)
|
||||
{
|
||||
CPUState *cpu = CPU(dev);
|
||||
CPUClass *cc = CPU_GET_CLASS(cpu);
|
||||
|
||||
if (qemu_loglevel_mask(CPU_LOG_RESET)) {
|
||||
@@ -419,7 +408,6 @@ static void cpu_class_init(ObjectClass *klass, void *data)
|
||||
CPUClass *k = CPU_CLASS(klass);
|
||||
|
||||
k->parse_features = cpu_common_parse_features;
|
||||
k->reset = cpu_common_reset;
|
||||
k->get_arch_id = cpu_common_get_arch_id;
|
||||
k->has_work = cpu_common_has_work;
|
||||
k->get_paging_enabled = cpu_common_get_paging_enabled;
|
||||
@@ -440,6 +428,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
|
||||
set_bit(DEVICE_CATEGORY_CPU, dc->categories);
|
||||
dc->realize = cpu_common_realizefn;
|
||||
dc->unrealize = cpu_common_unrealizefn;
|
||||
dc->reset = cpu_common_reset;
|
||||
device_class_set_props(dc, cpu_common_props);
|
||||
/*
|
||||
* Reason: CPUs still need special care by board code: wiring up
|
||||
|
||||
@@ -79,7 +79,6 @@ struct TranslationBlock;
|
||||
* @class_by_name: Callback to map -cpu command line model name to an
|
||||
* instantiatable CPU type.
|
||||
* @parse_features: Callback to parse command line arguments.
|
||||
* @reset: Callback to reset the #CPUState to its initial state.
|
||||
* @reset_dump_flags: #CPUDumpFlags to use for reset logging.
|
||||
* @has_work: Callback for checking if there is work to do.
|
||||
* @do_interrupt: Callback for interrupt handling.
|
||||
@@ -165,7 +164,6 @@ typedef struct CPUClass {
|
||||
ObjectClass *(*class_by_name)(const char *cpu_model);
|
||||
void (*parse_features)(const char *typename, char *str, Error **errp);
|
||||
|
||||
void (*reset)(CPUState *cpu);
|
||||
int reset_dump_flags;
|
||||
bool (*has_work)(CPUState *cpu);
|
||||
void (*do_interrupt)(CPUState *cpu);
|
||||
@@ -1135,10 +1133,6 @@ void cpu_exec_unrealizefn(CPUState *cpu);
|
||||
*/
|
||||
bool target_words_bigendian(void);
|
||||
|
||||
void cpu_class_set_parent_reset(CPUClass *cc,
|
||||
void (*child_reset)(CPUState *cpu),
|
||||
void (**parent_reset)(CPUState *cpu));
|
||||
|
||||
#ifdef NEED_CPU_H
|
||||
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Convert targets using the old CPUState reset to DeviceState reset
|
||||
//
|
||||
// Copyright Linaro Ltd 2020
|
||||
// This work is licensed under the terms of the GNU GPLv2 or later.
|
||||
//
|
||||
// spatch --macro-file scripts/cocci-macro-file.h \
|
||||
// --sp-file scripts/coccinelle/cpu-reset.cocci \
|
||||
// --keep-comments --smpl-spacing --in-place --include-headers --dir target
|
||||
//
|
||||
// For simplicity we assume some things about the code we're modifying
|
||||
// that happen to be true for all our targets:
|
||||
// * all cpu_class_set_parent_reset() callsites have a 'DeviceClass *dc' local
|
||||
// * the parent reset field in the target CPU class is 'parent_reset'
|
||||
// * no reset function already has a 'dev' local
|
||||
|
||||
@@
|
||||
identifier cpu, x;
|
||||
typedef CPUState;
|
||||
@@
|
||||
struct x {
|
||||
...
|
||||
- void (*parent_reset)(CPUState *cpu);
|
||||
+ DeviceReset parent_reset;
|
||||
...
|
||||
};
|
||||
@ rule1 @
|
||||
identifier resetfn;
|
||||
expression resetfield;
|
||||
identifier cc;
|
||||
@@
|
||||
- cpu_class_set_parent_reset(cc, resetfn, resetfield)
|
||||
+ device_class_set_parent_reset(dc, resetfn, resetfield)
|
||||
@@
|
||||
identifier rule1.resetfn;
|
||||
identifier cpu, cc;
|
||||
typedef CPUState, DeviceState;
|
||||
@@
|
||||
-resetfn(CPUState *cpu)
|
||||
-{
|
||||
+resetfn(DeviceState *dev)
|
||||
+{
|
||||
+ CPUState *cpu = CPU(dev);
|
||||
<...
|
||||
- cc->parent_reset(cpu);
|
||||
+ cc->parent_reset(dev);
|
||||
...>
|
||||
}
|
||||
@@ -44,7 +44,7 @@ typedef struct AlphaCPUClass {
|
||||
/*< public >*/
|
||||
|
||||
DeviceRealize parent_realize;
|
||||
void (*parent_reset)(CPUState *cpu);
|
||||
DeviceReset parent_reset;
|
||||
} AlphaCPUClass;
|
||||
|
||||
typedef struct AlphaCPU AlphaCPU;
|
||||
|
||||
@@ -51,7 +51,7 @@ typedef struct ARMCPUClass {
|
||||
|
||||
const ARMCPUInfo *info;
|
||||
DeviceRealize parent_realize;
|
||||
void (*parent_reset)(CPUState *cpu);
|
||||
DeviceReset parent_reset;
|
||||
} ARMCPUClass;
|
||||
|
||||
typedef struct ARMCPU ARMCPU;
|
||||
|
||||
+4
-4
@@ -155,14 +155,14 @@ static void cp_reg_check_reset(gpointer key, gpointer value, gpointer opaque)
|
||||
assert(oldvalue == newvalue);
|
||||
}
|
||||
|
||||
/* CPUClass::reset() */
|
||||
static void arm_cpu_reset(CPUState *s)
|
||||
static void arm_cpu_reset(DeviceState *dev)
|
||||
{
|
||||
CPUState *s = CPU(dev);
|
||||
ARMCPU *cpu = ARM_CPU(s);
|
||||
ARMCPUClass *acc = ARM_CPU_GET_CLASS(cpu);
|
||||
CPUARMState *env = &cpu->env;
|
||||
|
||||
acc->parent_reset(s);
|
||||
acc->parent_reset(dev);
|
||||
|
||||
memset(env, 0, offsetof(CPUARMState, end_reset_fields));
|
||||
|
||||
@@ -2785,7 +2785,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
|
||||
&acc->parent_realize);
|
||||
|
||||
device_class_set_props(dc, arm_cpu_properties);
|
||||
cpu_class_set_parent_reset(cc, arm_cpu_reset, &acc->parent_reset);
|
||||
device_class_set_parent_reset(dc, arm_cpu_reset, &acc->parent_reset);
|
||||
|
||||
cc->class_by_name = arm_cpu_class_by_name;
|
||||
cc->has_work = arm_cpu_has_work;
|
||||
|
||||
@@ -45,7 +45,7 @@ typedef struct CRISCPUClass {
|
||||
/*< public >*/
|
||||
|
||||
DeviceRealize parent_realize;
|
||||
void (*parent_reset)(CPUState *cpu);
|
||||
DeviceReset parent_reset;
|
||||
|
||||
uint32_t vr;
|
||||
} CRISCPUClass;
|
||||
|
||||
+4
-4
@@ -40,15 +40,15 @@ static bool cris_cpu_has_work(CPUState *cs)
|
||||
return cs->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI);
|
||||
}
|
||||
|
||||
/* CPUClass::reset() */
|
||||
static void cris_cpu_reset(CPUState *s)
|
||||
static void cris_cpu_reset(DeviceState *dev)
|
||||
{
|
||||
CPUState *s = CPU(dev);
|
||||
CRISCPU *cpu = CRIS_CPU(s);
|
||||
CRISCPUClass *ccc = CRIS_CPU_GET_CLASS(cpu);
|
||||
CPUCRISState *env = &cpu->env;
|
||||
uint32_t vr;
|
||||
|
||||
ccc->parent_reset(s);
|
||||
ccc->parent_reset(dev);
|
||||
|
||||
vr = env->pregs[PR_VR];
|
||||
memset(env, 0, offsetof(CPUCRISState, end_reset_fields));
|
||||
@@ -264,7 +264,7 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data)
|
||||
device_class_set_parent_realize(dc, cris_cpu_realizefn,
|
||||
&ccc->parent_realize);
|
||||
|
||||
cpu_class_set_parent_reset(cc, cris_cpu_reset, &ccc->parent_reset);
|
||||
device_class_set_parent_reset(dc, cris_cpu_reset, &ccc->parent_reset);
|
||||
|
||||
cc->class_by_name = cris_cpu_class_by_name;
|
||||
cc->has_work = cris_cpu_has_work;
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef struct HPPACPUClass {
|
||||
/*< public >*/
|
||||
|
||||
DeviceRealize parent_realize;
|
||||
void (*parent_reset)(CPUState *cpu);
|
||||
DeviceReset parent_reset;
|
||||
} HPPACPUClass;
|
||||
|
||||
typedef struct HPPACPU HPPACPU;
|
||||
|
||||
@@ -71,7 +71,7 @@ typedef struct X86CPUClass {
|
||||
|
||||
DeviceRealize parent_realize;
|
||||
DeviceUnrealize parent_unrealize;
|
||||
void (*parent_reset)(CPUState *cpu);
|
||||
DeviceReset parent_reset;
|
||||
} X86CPUClass;
|
||||
|
||||
typedef struct X86CPU X86CPU;
|
||||
|
||||
+4
-4
@@ -5983,9 +5983,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
|
||||
}
|
||||
}
|
||||
|
||||
/* CPUClass::reset() */
|
||||
static void x86_cpu_reset(CPUState *s)
|
||||
static void x86_cpu_reset(DeviceState *dev)
|
||||
{
|
||||
CPUState *s = CPU(dev);
|
||||
X86CPU *cpu = X86_CPU(s);
|
||||
X86CPUClass *xcc = X86_CPU_GET_CLASS(cpu);
|
||||
CPUX86State *env = &cpu->env;
|
||||
@@ -5993,7 +5993,7 @@ static void x86_cpu_reset(CPUState *s)
|
||||
uint64_t xcr0;
|
||||
int i;
|
||||
|
||||
xcc->parent_reset(s);
|
||||
xcc->parent_reset(dev);
|
||||
|
||||
memset(env, 0, offsetof(CPUX86State, end_reset_fields));
|
||||
|
||||
@@ -7297,7 +7297,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
|
||||
&xcc->parent_unrealize);
|
||||
device_class_set_props(dc, x86_cpu_properties);
|
||||
|
||||
cpu_class_set_parent_reset(cc, x86_cpu_reset, &xcc->parent_reset);
|
||||
device_class_set_parent_reset(dc, x86_cpu_reset, &xcc->parent_reset);
|
||||
cc->reset_dump_flags = CPU_DUMP_FPU | CPU_DUMP_CCOP;
|
||||
|
||||
cc->class_by_name = x86_cpu_class_by_name;
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef struct LM32CPUClass {
|
||||
/*< public >*/
|
||||
|
||||
DeviceRealize parent_realize;
|
||||
void (*parent_reset)(CPUState *cpu);
|
||||
DeviceReset parent_reset;
|
||||
} LM32CPUClass;
|
||||
|
||||
typedef struct LM32CPU LM32CPU;
|
||||
|
||||
+4
-4
@@ -99,14 +99,14 @@ static bool lm32_cpu_has_work(CPUState *cs)
|
||||
return cs->interrupt_request & CPU_INTERRUPT_HARD;
|
||||
}
|
||||
|
||||
/* CPUClass::reset() */
|
||||
static void lm32_cpu_reset(CPUState *s)
|
||||
static void lm32_cpu_reset(DeviceState *dev)
|
||||
{
|
||||
CPUState *s = CPU(dev);
|
||||
LM32CPU *cpu = LM32_CPU(s);
|
||||
LM32CPUClass *lcc = LM32_CPU_GET_CLASS(cpu);
|
||||
CPULM32State *env = &cpu->env;
|
||||
|
||||
lcc->parent_reset(s);
|
||||
lcc->parent_reset(dev);
|
||||
|
||||
/* reset cpu state */
|
||||
memset(env, 0, offsetof(CPULM32State, end_reset_fields));
|
||||
@@ -218,7 +218,7 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data)
|
||||
|
||||
device_class_set_parent_realize(dc, lm32_cpu_realizefn,
|
||||
&lcc->parent_realize);
|
||||
cpu_class_set_parent_reset(cc, lm32_cpu_reset, &lcc->parent_reset);
|
||||
device_class_set_parent_reset(dc, lm32_cpu_reset, &lcc->parent_reset);
|
||||
|
||||
cc->class_by_name = lm32_cpu_class_by_name;
|
||||
cc->has_work = lm32_cpu_has_work;
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef struct M68kCPUClass {
|
||||
/*< public >*/
|
||||
|
||||
DeviceRealize parent_realize;
|
||||
void (*parent_reset)(CPUState *cpu);
|
||||
DeviceReset parent_reset;
|
||||
} M68kCPUClass;
|
||||
|
||||
typedef struct M68kCPU M68kCPU;
|
||||
|
||||
+4
-4
@@ -41,16 +41,16 @@ static void m68k_set_feature(CPUM68KState *env, int feature)
|
||||
env->features |= (1u << feature);
|
||||
}
|
||||
|
||||
/* CPUClass::reset() */
|
||||
static void m68k_cpu_reset(CPUState *s)
|
||||
static void m68k_cpu_reset(DeviceState *dev)
|
||||
{
|
||||
CPUState *s = CPU(dev);
|
||||
M68kCPU *cpu = M68K_CPU(s);
|
||||
M68kCPUClass *mcc = M68K_CPU_GET_CLASS(cpu);
|
||||
CPUM68KState *env = &cpu->env;
|
||||
floatx80 nan = floatx80_default_nan(NULL);
|
||||
int i;
|
||||
|
||||
mcc->parent_reset(s);
|
||||
mcc->parent_reset(dev);
|
||||
|
||||
memset(env, 0, offsetof(CPUM68KState, end_reset_fields));
|
||||
#ifdef CONFIG_SOFTMMU
|
||||
@@ -273,7 +273,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
|
||||
|
||||
device_class_set_parent_realize(dc, m68k_cpu_realizefn,
|
||||
&mcc->parent_realize);
|
||||
cpu_class_set_parent_reset(cc, m68k_cpu_reset, &mcc->parent_reset);
|
||||
device_class_set_parent_reset(dc, m68k_cpu_reset, &mcc->parent_reset);
|
||||
|
||||
cc->class_by_name = m68k_cpu_class_by_name;
|
||||
cc->has_work = m68k_cpu_has_work;
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef struct MicroBlazeCPUClass {
|
||||
/*< public >*/
|
||||
|
||||
DeviceRealize parent_realize;
|
||||
void (*parent_reset)(CPUState *cpu);
|
||||
DeviceReset parent_reset;
|
||||
} MicroBlazeCPUClass;
|
||||
|
||||
typedef struct MicroBlazeCPU MicroBlazeCPU;
|
||||
|
||||
@@ -102,14 +102,14 @@ static void microblaze_cpu_set_irq(void *opaque, int irq, int level)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* CPUClass::reset() */
|
||||
static void mb_cpu_reset(CPUState *s)
|
||||
static void mb_cpu_reset(DeviceState *dev)
|
||||
{
|
||||
CPUState *s = CPU(dev);
|
||||
MicroBlazeCPU *cpu = MICROBLAZE_CPU(s);
|
||||
MicroBlazeCPUClass *mcc = MICROBLAZE_CPU_GET_CLASS(cpu);
|
||||
CPUMBState *env = &cpu->env;
|
||||
|
||||
mcc->parent_reset(s);
|
||||
mcc->parent_reset(dev);
|
||||
|
||||
memset(env, 0, offsetof(CPUMBState, end_reset_fields));
|
||||
env->res_addr = RES_ADDR_NONE;
|
||||
@@ -292,7 +292,7 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
|
||||
|
||||
device_class_set_parent_realize(dc, mb_cpu_realizefn,
|
||||
&mcc->parent_realize);
|
||||
cpu_class_set_parent_reset(cc, mb_cpu_reset, &mcc->parent_reset);
|
||||
device_class_set_parent_reset(dc, mb_cpu_reset, &mcc->parent_reset);
|
||||
|
||||
cc->class_by_name = mb_cpu_class_by_name;
|
||||
cc->has_work = mb_cpu_has_work;
|
||||
|
||||
@@ -48,7 +48,7 @@ typedef struct MIPSCPUClass {
|
||||
/*< public >*/
|
||||
|
||||
DeviceRealize parent_realize;
|
||||
void (*parent_reset)(CPUState *cpu);
|
||||
DeviceReset parent_reset;
|
||||
const struct mips_def_t *cpu_def;
|
||||
} MIPSCPUClass;
|
||||
|
||||
|
||||
+4
-4
@@ -96,14 +96,14 @@ static bool mips_cpu_has_work(CPUState *cs)
|
||||
return has_work;
|
||||
}
|
||||
|
||||
/* CPUClass::reset() */
|
||||
static void mips_cpu_reset(CPUState *s)
|
||||
static void mips_cpu_reset(DeviceState *dev)
|
||||
{
|
||||
CPUState *s = CPU(dev);
|
||||
MIPSCPU *cpu = MIPS_CPU(s);
|
||||
MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(cpu);
|
||||
CPUMIPSState *env = &cpu->env;
|
||||
|
||||
mcc->parent_reset(s);
|
||||
mcc->parent_reset(dev);
|
||||
|
||||
memset(env, 0, offsetof(CPUMIPSState, end_reset_fields));
|
||||
|
||||
@@ -189,7 +189,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data)
|
||||
|
||||
device_class_set_parent_realize(dc, mips_cpu_realizefn,
|
||||
&mcc->parent_realize);
|
||||
cpu_class_set_parent_reset(cc, mips_cpu_reset, &mcc->parent_reset);
|
||||
device_class_set_parent_reset(dc, mips_cpu_reset, &mcc->parent_reset);
|
||||
|
||||
cc->class_by_name = mips_cpu_class_by_name;
|
||||
cc->has_work = mips_cpu_has_work;
|
||||
|
||||
+4
-3
@@ -35,13 +35,14 @@ static bool moxie_cpu_has_work(CPUState *cs)
|
||||
return cs->interrupt_request & CPU_INTERRUPT_HARD;
|
||||
}
|
||||
|
||||
static void moxie_cpu_reset(CPUState *s)
|
||||
static void moxie_cpu_reset(DeviceState *dev)
|
||||
{
|
||||
CPUState *s = CPU(dev);
|
||||
MoxieCPU *cpu = MOXIE_CPU(s);
|
||||
MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu);
|
||||
CPUMoxieState *env = &cpu->env;
|
||||
|
||||
mcc->parent_reset(s);
|
||||
mcc->parent_reset(dev);
|
||||
|
||||
memset(env, 0, offsetof(CPUMoxieState, end_reset_fields));
|
||||
env->pc = 0x1000;
|
||||
@@ -101,7 +102,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data)
|
||||
|
||||
device_class_set_parent_realize(dc, moxie_cpu_realizefn,
|
||||
&mcc->parent_realize);
|
||||
cpu_class_set_parent_reset(cc, moxie_cpu_reset, &mcc->parent_reset);
|
||||
device_class_set_parent_reset(dc, moxie_cpu_reset, &mcc->parent_reset);
|
||||
|
||||
cc->class_by_name = moxie_cpu_class_by_name;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user