]>
Commit | Line | Data |
---|---|---|
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 |
27 | typedef struct CPUExistsArgs { |
28 | int64_t id; | |
29 | bool found; | |
30 | } CPUExistsArgs; | |
31 | ||
32 | static 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 | ||
42 | bool 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 */ |
54 | static NotifierList cpu_added_notifiers = | |
55 | NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers); | |
56 | ||
57 | void qemu_register_cpu_added_notifier(Notifier *notifier) | |
58 | { | |
59 | notifier_list_add(&cpu_added_notifiers, notifier); | |
60 | } | |
dd83b06a | 61 | |
d8ed887b AF |
62 | void cpu_reset_interrupt(CPUState *cpu, int mask) |
63 | { | |
64 | cpu->interrupt_request &= ~mask; | |
65 | } | |
66 | ||
dd83b06a AF |
67 | void cpu_reset(CPUState *cpu) |
68 | { | |
69 | CPUClass *klass = CPU_GET_CLASS(cpu); | |
70 | ||
71 | if (klass->reset != NULL) { | |
72 | (*klass->reset)(cpu); | |
73 | } | |
74 | } | |
75 | ||
76 | static void cpu_common_reset(CPUState *cpu) | |
77 | { | |
fcd7d003 | 78 | cpu->exit_request = 0; |
259186a7 | 79 | cpu->interrupt_request = 0; |
d77953b9 | 80 | cpu->current_tb = NULL; |
259186a7 | 81 | cpu->halted = 0; |
dd83b06a AF |
82 | } |
83 | ||
2b8c2754 AF |
84 | ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model) |
85 | { | |
86 | CPUClass *cc = CPU_CLASS(object_class_by_name(typename)); | |
87 | ||
88 | return cc->class_by_name(cpu_model); | |
89 | } | |
90 | ||
91 | static ObjectClass *cpu_common_class_by_name(const char *cpu_model) | |
92 | { | |
93 | return NULL; | |
94 | } | |
95 | ||
4f658099 AF |
96 | static void cpu_common_realizefn(DeviceState *dev, Error **errp) |
97 | { | |
13eed94e IM |
98 | CPUState *cpu = CPU(dev); |
99 | ||
100 | if (dev->hotplugged) { | |
101 | cpu_synchronize_post_init(cpu); | |
066e9b27 | 102 | notifier_list_notify(&cpu_added_notifiers, dev); |
6afb4721 | 103 | cpu_resume(cpu); |
13eed94e | 104 | } |
4f658099 AF |
105 | } |
106 | ||
997395d3 IM |
107 | static int64_t cpu_common_get_arch_id(CPUState *cpu) |
108 | { | |
109 | return cpu->cpu_index; | |
110 | } | |
111 | ||
dd83b06a AF |
112 | static void cpu_class_init(ObjectClass *klass, void *data) |
113 | { | |
961f8395 | 114 | DeviceClass *dc = DEVICE_CLASS(klass); |
dd83b06a AF |
115 | CPUClass *k = CPU_CLASS(klass); |
116 | ||
2b8c2754 | 117 | k->class_by_name = cpu_common_class_by_name; |
dd83b06a | 118 | k->reset = cpu_common_reset; |
997395d3 | 119 | k->get_arch_id = cpu_common_get_arch_id; |
4f658099 | 120 | dc->realize = cpu_common_realizefn; |
961f8395 | 121 | dc->no_user = 1; |
dd83b06a AF |
122 | } |
123 | ||
961f8395 | 124 | static const TypeInfo cpu_type_info = { |
dd83b06a | 125 | .name = TYPE_CPU, |
961f8395 | 126 | .parent = TYPE_DEVICE, |
dd83b06a AF |
127 | .instance_size = sizeof(CPUState), |
128 | .abstract = true, | |
129 | .class_size = sizeof(CPUClass), | |
130 | .class_init = cpu_class_init, | |
131 | }; | |
132 | ||
133 | static void cpu_register_types(void) | |
134 | { | |
135 | type_register_static(&cpu_type_info); | |
136 | } | |
137 | ||
138 | type_init(cpu_register_types) |