Revision e5ad936b hw/apic_common.c
b/hw/apic_common.c | ||
---|---|---|
20 | 20 |
#include "apic.h" |
21 | 21 |
#include "apic_internal.h" |
22 | 22 |
#include "trace.h" |
23 |
#include "kvm.h" |
|
23 | 24 |
|
24 | 25 |
static int apic_irq_delivered; |
26 |
bool apic_report_tpr_access; |
|
25 | 27 |
|
26 | 28 |
void cpu_set_apic_base(DeviceState *d, uint64_t val) |
27 | 29 |
{ |
... | ... | |
63 | 65 |
|
64 | 66 |
uint8_t cpu_get_apic_tpr(DeviceState *d) |
65 | 67 |
{ |
68 |
APICCommonState *s; |
|
69 |
APICCommonClass *info; |
|
70 |
|
|
71 |
if (!d) { |
|
72 |
return 0; |
|
73 |
} |
|
74 |
|
|
75 |
s = APIC_COMMON(d); |
|
76 |
info = APIC_COMMON_GET_CLASS(s); |
|
77 |
|
|
78 |
return info->get_tpr(s); |
|
79 |
} |
|
80 |
|
|
81 |
void apic_enable_tpr_access_reporting(DeviceState *d, bool enable) |
|
82 |
{ |
|
83 |
APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d); |
|
84 |
APICCommonClass *info = APIC_COMMON_GET_CLASS(s); |
|
85 |
|
|
86 |
apic_report_tpr_access = enable; |
|
87 |
if (info->enable_tpr_reporting) { |
|
88 |
info->enable_tpr_reporting(s, enable); |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
void apic_enable_vapic(DeviceState *d, target_phys_addr_t paddr) |
|
93 |
{ |
|
66 | 94 |
APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d); |
95 |
APICCommonClass *info = APIC_COMMON_GET_CLASS(s); |
|
67 | 96 |
|
68 |
return s ? s->tpr >> 4 : 0; |
|
97 |
s->vapic_paddr = paddr; |
|
98 |
info->vapic_base_update(s); |
|
69 | 99 |
} |
70 | 100 |
|
71 | 101 |
void apic_handle_tpr_access_report(DeviceState *d, target_ulong ip, |
72 | 102 |
TPRAccess access) |
73 | 103 |
{ |
104 |
APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d); |
|
105 |
|
|
106 |
vapic_report_tpr_access(s->vapic, s->cpu_env, ip, access); |
|
74 | 107 |
} |
75 | 108 |
|
76 | 109 |
void apic_report_irq_delivered(int delivered) |
... | ... | |
171 | 204 |
static void apic_reset_common(DeviceState *d) |
172 | 205 |
{ |
173 | 206 |
APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d); |
207 |
APICCommonClass *info = APIC_COMMON_GET_CLASS(s); |
|
174 | 208 |
bool bsp; |
175 | 209 |
|
176 | 210 |
bsp = cpu_is_bsp(s->cpu_env); |
177 | 211 |
s->apicbase = 0xfee00000 | |
178 | 212 |
(bsp ? MSR_IA32_APICBASE_BSP : 0) | MSR_IA32_APICBASE_ENABLE; |
179 | 213 |
|
214 |
s->vapic_paddr = 0; |
|
215 |
info->vapic_base_update(s); |
|
216 |
|
|
180 | 217 |
apic_init_reset(d); |
181 | 218 |
|
182 | 219 |
if (bsp) { |
... | ... | |
239 | 276 |
{ |
240 | 277 |
APICCommonState *s = APIC_COMMON(dev); |
241 | 278 |
APICCommonClass *info; |
279 |
static DeviceState *vapic; |
|
242 | 280 |
static int apic_no; |
243 | 281 |
|
244 | 282 |
if (apic_no >= MAX_APICS) { |
... | ... | |
249 | 287 |
info = APIC_COMMON_GET_CLASS(s); |
250 | 288 |
info->init(s); |
251 | 289 |
|
252 |
sysbus_init_mmio(&s->busdev, &s->io_memory); |
|
290 |
sysbus_init_mmio(dev, &s->io_memory); |
|
291 |
|
|
292 |
if (!vapic && s->vapic_control & VAPIC_ENABLE_MASK) { |
|
293 |
vapic = sysbus_create_simple("kvmvapic", -1, NULL); |
|
294 |
} |
|
295 |
s->vapic = vapic; |
|
296 |
if (apic_report_tpr_access && info->enable_tpr_reporting) { |
|
297 |
info->enable_tpr_reporting(s, true); |
|
298 |
} |
|
299 |
|
|
253 | 300 |
return 0; |
254 | 301 |
} |
255 | 302 |
|
303 |
static void apic_dispatch_pre_save(void *opaque) |
|
304 |
{ |
|
305 |
APICCommonState *s = APIC_COMMON(opaque); |
|
306 |
APICCommonClass *info = APIC_COMMON_GET_CLASS(s); |
|
307 |
|
|
308 |
if (info->pre_save) { |
|
309 |
info->pre_save(s); |
|
310 |
} |
|
311 |
} |
|
312 |
|
|
256 | 313 |
static int apic_dispatch_post_load(void *opaque, int version_id) |
257 | 314 |
{ |
258 | 315 |
APICCommonState *s = APIC_COMMON(opaque); |
... | ... | |
270 | 327 |
.minimum_version_id = 3, |
271 | 328 |
.minimum_version_id_old = 1, |
272 | 329 |
.load_state_old = apic_load_old, |
330 |
.pre_save = apic_dispatch_pre_save, |
|
273 | 331 |
.post_load = apic_dispatch_post_load, |
274 | 332 |
.fields = (VMStateField[]) { |
275 | 333 |
VMSTATE_UINT32(apicbase, APICCommonState), |
... | ... | |
299 | 357 |
static Property apic_properties_common[] = { |
300 | 358 |
DEFINE_PROP_UINT8("id", APICCommonState, id, -1), |
301 | 359 |
DEFINE_PROP_PTR("cpu_env", APICCommonState, cpu_env), |
360 |
DEFINE_PROP_BIT("vapic", APICCommonState, vapic_control, VAPIC_ENABLE_BIT, |
|
361 |
true), |
|
302 | 362 |
DEFINE_PROP_END_OF_LIST(), |
303 | 363 |
}; |
304 | 364 |
|
Also available in: Unified diff