pflash_cfi02: Use QOM realize for pflash_cfi02
[qemu/ar7.git] / target-s390x / cpu.c
blob1ef2fc0e86faf9a460935c44a6eb392592dedaf4
1 /*
2 * QEMU S/390 CPU
4 * Copyright (c) 2009 Ulrich Hecht
5 * Copyright (c) 2011 Alexander Graf
6 * Copyright (c) 2012 SUSE LINUX Products GmbH
7 * Copyright (c) 2012 IBM Corp.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, see
21 * <http://www.gnu.org/licenses/lgpl-2.1.html>
22 * Contributions after 2012-12-11 are licensed under the terms of the
23 * GNU GPL, version 2 or (at your option) any later version.
26 #include "cpu.h"
27 #include "qemu-common.h"
28 #include "qemu/timer.h"
29 #include "hw/hw.h"
30 #ifndef CONFIG_USER_ONLY
31 #include "sysemu/arch_init.h"
32 #endif
34 #define CR0_RESET 0xE0UL
35 #define CR14_RESET 0xC2000000UL;
37 /* generate CPU information for cpu -? */
38 void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
40 #ifdef CONFIG_KVM
41 (*cpu_fprintf)(f, "s390 %16s\n", "host");
42 #endif
45 #ifndef CONFIG_USER_ONLY
46 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
48 CpuDefinitionInfoList *entry;
49 CpuDefinitionInfo *info;
51 info = g_malloc0(sizeof(*info));
52 info->name = g_strdup("host");
54 entry = g_malloc0(sizeof(*entry));
55 entry->value = info;
57 return entry;
59 #endif
61 /* CPUClass::reset() */
62 static void s390_cpu_reset(CPUState *s)
64 S390CPU *cpu = S390_CPU(s);
65 S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
66 CPUS390XState *env = &cpu->env;
68 s390_del_running_cpu(cpu);
70 scc->parent_reset(s);
72 memset(env, 0, offsetof(CPUS390XState, breakpoints));
74 /* architectured initial values for CR 0 and 14 */
75 env->cregs[0] = CR0_RESET;
76 env->cregs[14] = CR14_RESET;
77 /* set halted to 1 to make sure we can add the cpu in
78 * s390_ipl_cpu code, where CPUState::halted is set back to 0
79 * after incrementing the cpu counter */
80 #if !defined(CONFIG_USER_ONLY)
81 s->halted = 1;
82 #endif
83 tlb_flush(env, 1);
86 #if !defined(CONFIG_USER_ONLY)
87 static void s390_cpu_machine_reset_cb(void *opaque)
89 S390CPU *cpu = opaque;
91 cpu_reset(CPU(cpu));
93 #endif
95 static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
97 S390CPU *cpu = S390_CPU(dev);
98 S390CPUClass *scc = S390_CPU_GET_CLASS(dev);
100 cpu_reset(CPU(cpu));
102 scc->parent_realize(dev, errp);
105 static void s390_cpu_initfn(Object *obj)
107 CPUState *cs = CPU(obj);
108 S390CPU *cpu = S390_CPU(obj);
109 CPUS390XState *env = &cpu->env;
110 static bool inited;
111 static int cpu_num = 0;
112 #if !defined(CONFIG_USER_ONLY)
113 struct tm tm;
114 #endif
116 cs->env_ptr = env;
117 cpu_exec_init(env);
118 #if !defined(CONFIG_USER_ONLY)
119 qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
120 qemu_get_timedate(&tm, 0);
121 env->tod_offset = TOD_UNIX_EPOCH +
122 (time2tod(mktimegm(&tm)) * 1000000000ULL);
123 env->tod_basetime = 0;
124 env->tod_timer = qemu_new_timer_ns(vm_clock, s390x_tod_timer, cpu);
125 env->cpu_timer = qemu_new_timer_ns(vm_clock, s390x_cpu_timer, cpu);
126 /* set CPUState::halted state to 1 to avoid decrementing the running
127 * cpu counter in s390_cpu_reset to a negative number at
128 * initial ipl */
129 cs->halted = 1;
130 #endif
131 env->cpu_num = cpu_num++;
132 env->ext_index = -1;
134 if (tcg_enabled() && !inited) {
135 inited = true;
136 s390x_translate_init();
140 static void s390_cpu_finalize(Object *obj)
142 #if !defined(CONFIG_USER_ONLY)
143 S390CPU *cpu = S390_CPU(obj);
145 qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu);
146 #endif
149 static const VMStateDescription vmstate_s390_cpu = {
150 .name = "cpu",
151 .unmigratable = 1,
154 static void s390_cpu_class_init(ObjectClass *oc, void *data)
156 S390CPUClass *scc = S390_CPU_CLASS(oc);
157 CPUClass *cc = CPU_CLASS(scc);
158 DeviceClass *dc = DEVICE_CLASS(oc);
160 scc->parent_realize = dc->realize;
161 dc->realize = s390_cpu_realizefn;
163 scc->parent_reset = cc->reset;
164 cc->reset = s390_cpu_reset;
166 cc->do_interrupt = s390_cpu_do_interrupt;
167 cc->dump_state = s390_cpu_dump_state;
168 dc->vmsd = &vmstate_s390_cpu;
171 static const TypeInfo s390_cpu_type_info = {
172 .name = TYPE_S390_CPU,
173 .parent = TYPE_CPU,
174 .instance_size = sizeof(S390CPU),
175 .instance_init = s390_cpu_initfn,
176 .instance_finalize = s390_cpu_finalize,
177 .abstract = false,
178 .class_size = sizeof(S390CPUClass),
179 .class_init = s390_cpu_class_init,
182 static void s390_cpu_register_types(void)
184 type_register_static(&s390_cpu_type_info);
187 type_init(s390_cpu_register_types)