]> git.proxmox.com Git - qemu.git/blame - qom/cpu.c
Merge remote-tracking branch 'kraxel/usb.82' into staging
[qemu.git] / qom / cpu.c
CommitLineData
dd83b06a
AF
1/*
2 * QEMU CPU model
3 *
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see
18 * <http://www.gnu.org/licenses/gpl-2.0.html>
19 */
20
14cccb61 21#include "qom/cpu.h"
dd83b06a 22#include "qemu-common.h"
13eed94e 23#include "sysemu/kvm.h"
066e9b27
IM
24#include "qemu/notify.h"
25#include "sysemu/sysemu.h"
26
69e5ff06
IM
27typedef struct CPUExistsArgs {
28 int64_t id;
29 bool found;
30} CPUExistsArgs;
31
32static void cpu_exist_cb(CPUState *cpu, void *data)
33{
34 CPUClass *klass = CPU_GET_CLASS(cpu);
35 CPUExistsArgs *arg = data;
36
37 if (klass->get_arch_id(cpu) == arg->id) {
38 arg->found = true;
39 }
40}
41
42bool cpu_exists(int64_t id)
43{
44 CPUExistsArgs data = {
45 .id = id,
46 .found = false,
47 };
48
49 qemu_for_each_cpu(cpu_exist_cb, &data);
50 return data.found;
51}
52
066e9b27
IM
53/* CPU hot-plug notifiers */
54static NotifierList cpu_added_notifiers =
55 NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
56
57void qemu_register_cpu_added_notifier(Notifier *notifier)
58{
59 notifier_list_add(&cpu_added_notifiers, notifier);
60}
dd83b06a 61
d8ed887b
AF
62void cpu_reset_interrupt(CPUState *cpu, int mask)
63{
64 cpu->interrupt_request &= ~mask;
65}
66
c72bf468
JF
67int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
68 void *opaque)
69{
70 CPUClass *cc = CPU_GET_CLASS(cpu);
71
72 return (*cc->write_elf32_qemunote)(f, cpu, opaque);
73}
74
75static int cpu_common_write_elf32_qemunote(WriteCoreDumpFunction f,
76 CPUState *cpu, void *opaque)
77{
78 return -1;
79}
80
81int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
82 int cpuid, void *opaque)
83{
84 CPUClass *cc = CPU_GET_CLASS(cpu);
85
86 return (*cc->write_elf32_note)(f, cpu, cpuid, opaque);
87}
88
89static int cpu_common_write_elf32_note(WriteCoreDumpFunction f,
90 CPUState *cpu, int cpuid,
91 void *opaque)
92{
93 return -1;
94}
95
96int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
97 void *opaque)
98{
99 CPUClass *cc = CPU_GET_CLASS(cpu);
100
101 return (*cc->write_elf64_qemunote)(f, cpu, opaque);
102}
103
104static int cpu_common_write_elf64_qemunote(WriteCoreDumpFunction f,
105 CPUState *cpu, void *opaque)
106{
107 return -1;
108}
109
110int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
111 int cpuid, void *opaque)
112{
113 CPUClass *cc = CPU_GET_CLASS(cpu);
114
115 return (*cc->write_elf64_note)(f, cpu, cpuid, opaque);
116}
117
118static int cpu_common_write_elf64_note(WriteCoreDumpFunction f,
119 CPUState *cpu, int cpuid,
120 void *opaque)
121{
122 return -1;
123}
124
125
dd83b06a
AF
126void cpu_reset(CPUState *cpu)
127{
128 CPUClass *klass = CPU_GET_CLASS(cpu);
129
130 if (klass->reset != NULL) {
131 (*klass->reset)(cpu);
132 }
133}
134
135static void cpu_common_reset(CPUState *cpu)
136{
fcd7d003 137 cpu->exit_request = 0;
259186a7 138 cpu->interrupt_request = 0;
d77953b9 139 cpu->current_tb = NULL;
259186a7 140 cpu->halted = 0;
dd83b06a
AF
141}
142
2b8c2754
AF
143ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model)
144{
145 CPUClass *cc = CPU_CLASS(object_class_by_name(typename));
146
147 return cc->class_by_name(cpu_model);
148}
149
150static ObjectClass *cpu_common_class_by_name(const char *cpu_model)
151{
152 return NULL;
153}
154
4f658099
AF
155static void cpu_common_realizefn(DeviceState *dev, Error **errp)
156{
13eed94e
IM
157 CPUState *cpu = CPU(dev);
158
159 if (dev->hotplugged) {
160 cpu_synchronize_post_init(cpu);
066e9b27 161 notifier_list_notify(&cpu_added_notifiers, dev);
6afb4721 162 cpu_resume(cpu);
13eed94e 163 }
4f658099
AF
164}
165
997395d3
IM
166static int64_t cpu_common_get_arch_id(CPUState *cpu)
167{
168 return cpu->cpu_index;
169}
170
dd83b06a
AF
171static void cpu_class_init(ObjectClass *klass, void *data)
172{
961f8395 173 DeviceClass *dc = DEVICE_CLASS(klass);
dd83b06a
AF
174 CPUClass *k = CPU_CLASS(klass);
175
2b8c2754 176 k->class_by_name = cpu_common_class_by_name;
dd83b06a 177 k->reset = cpu_common_reset;
997395d3 178 k->get_arch_id = cpu_common_get_arch_id;
c72bf468
JF
179 k->write_elf32_qemunote = cpu_common_write_elf32_qemunote;
180 k->write_elf32_note = cpu_common_write_elf32_note;
181 k->write_elf64_qemunote = cpu_common_write_elf64_qemunote;
182 k->write_elf64_note = cpu_common_write_elf64_note;
4f658099 183 dc->realize = cpu_common_realizefn;
961f8395 184 dc->no_user = 1;
dd83b06a
AF
185}
186
961f8395 187static const TypeInfo cpu_type_info = {
dd83b06a 188 .name = TYPE_CPU,
961f8395 189 .parent = TYPE_DEVICE,
dd83b06a
AF
190 .instance_size = sizeof(CPUState),
191 .abstract = true,
192 .class_size = sizeof(CPUClass),
193 .class_init = cpu_class_init,
194};
195
196static void cpu_register_types(void)
197{
198 type_register_static(&cpu_type_info);
199}
200
201type_init(cpu_register_types)