2 * TPR optimization for 32-bit Windows guests (XP and Server 2003)
4 * Copyright (C) 2007-2008 Qumranet Technologies
5 * Copyright (C) 2012 Jan Kiszka, Siemens AG
7 * This work is licensed under the terms of the GNU GPL version 2, or
8 * (at your option) any later version. See the COPYING file in the
11 #include "qemu/osdep.h"
12 #include "qemu-common.h"
14 #include "exec/exec-all.h"
15 #include "sysemu/sysemu.h"
16 #include "sysemu/cpus.h"
17 #include "sysemu/hw_accel.h"
18 #include "sysemu/kvm.h"
19 #include "hw/i386/apic_internal.h"
20 #include "hw/sysbus.h"
23 #define VAPIC_IO_PORT 0x7e
25 #define VAPIC_CPU_SHIFT 7
27 #define ROM_BLOCK_SIZE 512
28 #define ROM_BLOCK_MASK (~(ROM_BLOCK_SIZE - 1))
30 typedef enum VAPICMode
{
36 typedef struct VAPICHandlers
{
40 uint32_t get_tpr_stack
;
41 } QEMU_PACKED VAPICHandlers
;
43 typedef struct GuestROMState
{
51 uint32_t real_tpr_addr
;
54 } QEMU_PACKED GuestROMState
;
56 typedef struct VAPICROMState
{
61 uint32_t rom_state_paddr
;
62 uint32_t rom_state_vaddr
;
64 uint32_t real_tpr_addr
;
65 GuestROMState rom_state
;
67 bool rom_mapped_writable
;
68 VMChangeStateEntry
*vmsentry
;
71 #define TYPE_VAPIC "kvmvapic"
72 #define VAPIC(obj) OBJECT_CHECK(VAPICROMState, (obj), TYPE_VAPIC)
74 #define TPR_INSTR_ABS_MODRM 0x1
75 #define TPR_INSTR_MATCH_MODRM_REG 0x2
77 typedef struct TPRInstruction
{
86 /* must be sorted by length, shortest first */
87 static const TPRInstruction tpr_instr
[] = {
88 { /* mov abs to eax */
90 .access
= TPR_ACCESS_READ
,
94 { /* mov eax to abs */
96 .access
= TPR_ACCESS_WRITE
,
100 { /* mov r32 to r/m32 */
102 .flags
= TPR_INSTR_ABS_MODRM
,
103 .access
= TPR_ACCESS_WRITE
,
107 { /* mov r/m32 to r32 */
109 .flags
= TPR_INSTR_ABS_MODRM
,
110 .access
= TPR_ACCESS_READ
,
117 .flags
= TPR_INSTR_ABS_MODRM
| TPR_INSTR_MATCH_MODRM_REG
,
118 .access
= TPR_ACCESS_READ
,
122 { /* mov imm32, r/m32 (c7/0) */
125 .flags
= TPR_INSTR_ABS_MODRM
| TPR_INSTR_MATCH_MODRM_REG
,
126 .access
= TPR_ACCESS_WRITE
,
132 static void read_guest_rom_state(VAPICROMState
*s
)
134 cpu_physical_memory_read(s
->rom_state_paddr
, &s
->rom_state
,
135 sizeof(GuestROMState
));
138 static void write_guest_rom_state(VAPICROMState
*s
)
140 cpu_physical_memory_write(s
->rom_state_paddr
, &s
->rom_state
,
141 sizeof(GuestROMState
));
144 static void update_guest_rom_state(VAPICROMState
*s
)
146 read_guest_rom_state(s
);
148 s
->rom_state
.real_tpr_addr
= cpu_to_le32(s
->real_tpr_addr
);
149 s
->rom_state
.vcpu_shift
= cpu_to_le32(VAPIC_CPU_SHIFT
);
151 write_guest_rom_state(s
);
154 static int find_real_tpr_addr(VAPICROMState
*s
, CPUX86State
*env
)
156 CPUState
*cs
= CPU(x86_env_get_cpu(env
));
160 if (s
->state
== VAPIC_ACTIVE
) {
164 * If there is no prior TPR access instruction we could analyze (which is
165 * the case after resume from hibernation), we need to scan the possible
166 * virtual address space for the APIC mapping.
168 for (addr
= 0xfffff000; addr
>= 0x80000000; addr
-= TARGET_PAGE_SIZE
) {
169 paddr
= cpu_get_phys_page_debug(cs
, addr
);
170 if (paddr
!= APIC_DEFAULT_ADDRESS
) {
173 s
->real_tpr_addr
= addr
+ 0x80;
174 update_guest_rom_state(s
);
180 static uint8_t modrm_reg(uint8_t modrm
)
182 return (modrm
>> 3) & 7;
185 static bool is_abs_modrm(uint8_t modrm
)
187 return (modrm
& 0xc7) == 0x05;
190 static bool opcode_matches(uint8_t *opcode
, const TPRInstruction
*instr
)
192 return opcode
[0] == instr
->opcode
&&
193 (!(instr
->flags
& TPR_INSTR_ABS_MODRM
) || is_abs_modrm(opcode
[1])) &&
194 (!(instr
->flags
& TPR_INSTR_MATCH_MODRM_REG
) ||
195 modrm_reg(opcode
[1]) == instr
->modrm_reg
);
198 static int evaluate_tpr_instruction(VAPICROMState
*s
, X86CPU
*cpu
,
199 target_ulong
*pip
, TPRAccess access
)
201 CPUState
*cs
= CPU(cpu
);
202 const TPRInstruction
*instr
;
203 target_ulong ip
= *pip
;
205 uint32_t real_tpr_addr
;
208 if ((ip
& 0xf0000000ULL
) != 0x80000000ULL
&&
209 (ip
& 0xf0000000ULL
) != 0xe0000000ULL
) {
214 * Early Windows 2003 SMP initialization contains a
218 * instruction that is patched by TPR optimization. The problem is that
219 * RSP, used by the patched instruction, is zero, so the guest gets a
220 * double fault and dies.
222 if (cpu
->env
.regs
[R_ESP
] == 0) {
226 if (kvm_enabled() && !kvm_irqchip_in_kernel()) {
228 * KVM without kernel-based TPR access reporting will pass an IP that
229 * points after the accessing instruction. So we need to look backward
230 * to find the reason.
232 for (i
= 0; i
< ARRAY_SIZE(tpr_instr
); i
++) {
233 instr
= &tpr_instr
[i
];
234 if (instr
->access
!= access
) {
237 if (cpu_memory_rw_debug(cs
, ip
- instr
->length
, opcode
,
238 sizeof(opcode
), 0) < 0) {
241 if (opcode_matches(opcode
, instr
)) {
248 if (cpu_memory_rw_debug(cs
, ip
, opcode
, sizeof(opcode
), 0) < 0) {
251 for (i
= 0; i
< ARRAY_SIZE(tpr_instr
); i
++) {
252 instr
= &tpr_instr
[i
];
253 if (opcode_matches(opcode
, instr
)) {
262 * Grab the virtual TPR address from the instruction
263 * and update the cached values.
265 if (cpu_memory_rw_debug(cs
, ip
+ instr
->addr_offset
,
266 (void *)&real_tpr_addr
,
267 sizeof(real_tpr_addr
), 0) < 0) {
270 real_tpr_addr
= le32_to_cpu(real_tpr_addr
);
271 if ((real_tpr_addr
& 0xfff) != 0x80) {
274 s
->real_tpr_addr
= real_tpr_addr
;
275 update_guest_rom_state(s
);
281 static int update_rom_mapping(VAPICROMState
*s
, CPUX86State
*env
, target_ulong ip
)
283 CPUState
*cs
= CPU(x86_env_get_cpu(env
));
285 uint32_t rom_state_vaddr
;
286 uint32_t pos
, patch
, offset
;
288 /* nothing to do if already activated */
289 if (s
->state
== VAPIC_ACTIVE
) {
293 /* bail out if ROM init code was not executed (missing ROM?) */
294 if (s
->state
== VAPIC_INACTIVE
) {
298 /* find out virtual address of the ROM */
299 rom_state_vaddr
= s
->rom_state_paddr
+ (ip
& 0xf0000000);
300 paddr
= cpu_get_phys_page_debug(cs
, rom_state_vaddr
);
304 paddr
+= rom_state_vaddr
& ~TARGET_PAGE_MASK
;
305 if (paddr
!= s
->rom_state_paddr
) {
308 read_guest_rom_state(s
);
309 if (memcmp(s
->rom_state
.signature
, "kvm aPiC", 8) != 0) {
312 s
->rom_state_vaddr
= rom_state_vaddr
;
314 /* fixup addresses in ROM if needed */
315 if (rom_state_vaddr
== le32_to_cpu(s
->rom_state
.vaddr
)) {
318 for (pos
= le32_to_cpu(s
->rom_state
.fixup_start
);
319 pos
< le32_to_cpu(s
->rom_state
.fixup_end
);
321 cpu_physical_memory_read(paddr
+ pos
- s
->rom_state
.vaddr
,
322 &offset
, sizeof(offset
));
323 offset
= le32_to_cpu(offset
);
324 cpu_physical_memory_read(paddr
+ offset
, &patch
, sizeof(patch
));
325 patch
= le32_to_cpu(patch
);
326 patch
+= rom_state_vaddr
- le32_to_cpu(s
->rom_state
.vaddr
);
327 patch
= cpu_to_le32(patch
);
328 cpu_physical_memory_write(paddr
+ offset
, &patch
, sizeof(patch
));
330 read_guest_rom_state(s
);
331 s
->vapic_paddr
= paddr
+ le32_to_cpu(s
->rom_state
.vapic_vaddr
) -
332 le32_to_cpu(s
->rom_state
.vaddr
);
338 * Tries to read the unique processor number from the Kernel Processor Control
339 * Region (KPCR) of 32-bit Windows XP and Server 2003. Returns -1 if the KPCR
340 * cannot be accessed or is considered invalid. This also ensures that we are
341 * not patching the wrong guest.
343 static int get_kpcr_number(X86CPU
*cpu
)
345 CPUX86State
*env
= &cpu
->env
;
353 if (cpu_memory_rw_debug(CPU(cpu
), env
->segs
[R_FS
].base
,
354 (void *)&kpcr
, sizeof(kpcr
), 0) < 0 ||
355 kpcr
.self
!= env
->segs
[R_FS
].base
) {
361 static int vapic_enable(VAPICROMState
*s
, X86CPU
*cpu
)
363 int cpu_number
= get_kpcr_number(cpu
);
365 static const uint8_t enabled
= 1;
367 if (cpu_number
< 0) {
370 vapic_paddr
= s
->vapic_paddr
+
371 (((hwaddr
)cpu_number
) << VAPIC_CPU_SHIFT
);
372 cpu_physical_memory_write(vapic_paddr
+ offsetof(VAPICState
, enabled
),
373 &enabled
, sizeof(enabled
));
374 apic_enable_vapic(cpu
->apic_state
, vapic_paddr
);
376 s
->state
= VAPIC_ACTIVE
;
381 static void patch_byte(X86CPU
*cpu
, target_ulong addr
, uint8_t byte
)
383 cpu_memory_rw_debug(CPU(cpu
), addr
, &byte
, 1, 1);
386 static void patch_call(VAPICROMState
*s
, X86CPU
*cpu
, target_ulong ip
,
391 offset
= cpu_to_le32(target
- ip
- 5);
392 patch_byte(cpu
, ip
, 0xe8); /* call near */
393 cpu_memory_rw_debug(CPU(cpu
), ip
+ 1, (void *)&offset
, sizeof(offset
), 1);
396 static void patch_instruction(VAPICROMState
*s
, X86CPU
*cpu
, target_ulong ip
)
398 CPUState
*cs
= CPU(cpu
);
399 CPUX86State
*env
= &cpu
->env
;
400 VAPICHandlers
*handlers
;
403 target_ulong current_pc
= 0;
404 target_ulong current_cs_base
= 0;
405 uint32_t current_flags
= 0;
408 handlers
= &s
->rom_state
.up
;
410 handlers
= &s
->rom_state
.mp
;
413 if (!kvm_enabled()) {
414 cpu_get_tb_cpu_state(env
, ¤t_pc
, ¤t_cs_base
,
416 /* Account this instruction, because we will exit the tb.
417 This is the first instruction in the block. Therefore
418 there is no need in restoring CPU state. */
420 --cs
->icount_decr
.u16
.low
;
426 cpu_memory_rw_debug(cs
, ip
, opcode
, sizeof(opcode
), 0);
429 case 0x89: /* mov r32 to r/m32 */
430 patch_byte(cpu
, ip
, 0x50 + modrm_reg(opcode
[1])); /* push reg */
431 patch_call(s
, cpu
, ip
+ 1, handlers
->set_tpr
);
433 case 0x8b: /* mov r/m32 to r32 */
434 patch_byte(cpu
, ip
, 0x90);
435 patch_call(s
, cpu
, ip
+ 1, handlers
->get_tpr
[modrm_reg(opcode
[1])]);
437 case 0xa1: /* mov abs to eax */
438 patch_call(s
, cpu
, ip
, handlers
->get_tpr
[0]);
440 case 0xa3: /* mov eax to abs */
441 patch_call(s
, cpu
, ip
, handlers
->set_tpr_eax
);
443 case 0xc7: /* mov imm32, r/m32 (c7/0) */
444 patch_byte(cpu
, ip
, 0x68); /* push imm32 */
445 cpu_memory_rw_debug(cs
, ip
+ 6, (void *)&imm32
, sizeof(imm32
), 0);
446 cpu_memory_rw_debug(cs
, ip
+ 1, (void *)&imm32
, sizeof(imm32
), 1);
447 patch_call(s
, cpu
, ip
+ 5, handlers
->set_tpr
);
449 case 0xff: /* push r/m32 */
450 patch_byte(cpu
, ip
, 0x50); /* push eax */
451 patch_call(s
, cpu
, ip
+ 1, handlers
->get_tpr_stack
);
459 if (!kvm_enabled()) {
460 /* Both tb_lock and iothread_mutex will be reset when
461 * longjmps back into the cpu_exec loop. */
463 tb_gen_code(cs
, current_pc
, current_cs_base
, current_flags
, 1);
464 cpu_loop_exit_noexc(cs
);
468 void vapic_report_tpr_access(DeviceState
*dev
, CPUState
*cs
, target_ulong ip
,
471 VAPICROMState
*s
= VAPIC(dev
);
472 X86CPU
*cpu
= X86_CPU(cs
);
473 CPUX86State
*env
= &cpu
->env
;
475 cpu_synchronize_state(cs
);
477 if (evaluate_tpr_instruction(s
, cpu
, &ip
, access
) < 0) {
478 if (s
->state
== VAPIC_ACTIVE
) {
479 vapic_enable(s
, cpu
);
483 if (update_rom_mapping(s
, env
, ip
) < 0) {
486 if (vapic_enable(s
, cpu
) < 0) {
489 patch_instruction(s
, cpu
, ip
);
492 typedef struct VAPICEnableTPRReporting
{
495 } VAPICEnableTPRReporting
;
497 static void vapic_do_enable_tpr_reporting(CPUState
*cpu
, run_on_cpu_data data
)
499 VAPICEnableTPRReporting
*info
= data
.host_ptr
;
500 apic_enable_tpr_access_reporting(info
->apic
, info
->enable
);
503 static void vapic_enable_tpr_reporting(bool enable
)
505 VAPICEnableTPRReporting info
= {
513 info
.apic
= cpu
->apic_state
;
514 run_on_cpu(cs
, vapic_do_enable_tpr_reporting
, RUN_ON_CPU_HOST_PTR(&info
));
518 static void vapic_reset(DeviceState
*dev
)
520 VAPICROMState
*s
= VAPIC(dev
);
522 s
->state
= VAPIC_INACTIVE
;
523 s
->rom_state_paddr
= 0;
524 vapic_enable_tpr_reporting(false);
528 * Set the IRQ polling hypercalls to the supported variant:
529 * - vmcall if using KVM in-kernel irqchip
530 * - 32-bit VAPIC port write otherwise
532 static int patch_hypercalls(VAPICROMState
*s
)
534 hwaddr rom_paddr
= s
->rom_state_paddr
& ROM_BLOCK_MASK
;
535 static const uint8_t vmcall_pattern
[] = { /* vmcall */
536 0xb8, 0x1, 0, 0, 0, 0xf, 0x1, 0xc1
538 static const uint8_t outl_pattern
[] = { /* nop; outl %eax,0x7e */
539 0xb8, 0x1, 0, 0, 0, 0x90, 0xe7, 0x7e
541 uint8_t alternates
[2];
542 const uint8_t *pattern
;
543 const uint8_t *patch
;
547 rom
= g_malloc(s
->rom_size
);
548 cpu_physical_memory_read(rom_paddr
, rom
, s
->rom_size
);
550 for (pos
= 0; pos
< s
->rom_size
- sizeof(vmcall_pattern
); pos
++) {
551 if (kvm_irqchip_in_kernel()) {
552 pattern
= outl_pattern
;
553 alternates
[0] = outl_pattern
[7];
554 alternates
[1] = outl_pattern
[7];
555 patch
= &vmcall_pattern
[5];
557 pattern
= vmcall_pattern
;
558 alternates
[0] = vmcall_pattern
[7];
559 alternates
[1] = 0xd9; /* AMD's VMMCALL */
560 patch
= &outl_pattern
[5];
562 if (memcmp(rom
+ pos
, pattern
, 7) == 0 &&
563 (rom
[pos
+ 7] == alternates
[0] || rom
[pos
+ 7] == alternates
[1])) {
564 cpu_physical_memory_write(rom_paddr
+ pos
+ 5, patch
, 3);
566 * Don't flush the tb here. Under ordinary conditions, the patched
567 * calls are miles away from the current IP. Under malicious
568 * conditions, the guest could trick us to crash.
578 * For TCG mode or the time KVM honors read-only memory regions, we need to
579 * enable write access to the option ROM so that variables can be updated by
582 static int vapic_map_rom_writable(VAPICROMState
*s
)
584 hwaddr rom_paddr
= s
->rom_state_paddr
& ROM_BLOCK_MASK
;
585 MemoryRegionSection section
;
590 as
= sysbus_address_space(&s
->busdev
);
592 if (s
->rom_mapped_writable
) {
593 memory_region_del_subregion(as
, &s
->rom
);
594 object_unparent(OBJECT(&s
->rom
));
597 /* grab RAM memory region (region @rom_paddr may still be pc.rom) */
598 section
= memory_region_find(as
, 0, 1);
600 /* read ROM size from RAM region */
601 if (rom_paddr
+ 2 >= memory_region_size(section
.mr
)) {
604 ram
= memory_region_get_ram_ptr(section
.mr
);
605 rom_size
= ram
[rom_paddr
+ 2] * ROM_BLOCK_SIZE
;
609 s
->rom_size
= rom_size
;
611 /* We need to round to avoid creating subpages
612 * from which we cannot run code. */
613 rom_size
+= rom_paddr
& ~TARGET_PAGE_MASK
;
614 rom_paddr
&= TARGET_PAGE_MASK
;
615 rom_size
= TARGET_PAGE_ALIGN(rom_size
);
617 memory_region_init_alias(&s
->rom
, OBJECT(s
), "kvmvapic-rom", section
.mr
,
618 rom_paddr
, rom_size
);
619 memory_region_add_subregion_overlap(as
, rom_paddr
, &s
->rom
, 1000);
620 s
->rom_mapped_writable
= true;
621 memory_region_unref(section
.mr
);
626 static int vapic_prepare(VAPICROMState
*s
)
628 if (vapic_map_rom_writable(s
) < 0) {
632 if (patch_hypercalls(s
) < 0) {
636 vapic_enable_tpr_reporting(true);
641 static void vapic_write(void *opaque
, hwaddr addr
, uint64_t data
,
644 VAPICROMState
*s
= opaque
;
653 cpu_synchronize_state(current_cpu
);
654 cpu
= X86_CPU(current_cpu
);
658 * The VAPIC supports two PIO-based hypercalls, both via port 0x7E.
659 * o 16-bit write access:
660 * Reports the option ROM initialization to the hypervisor. Written
661 * value is the offset of the state structure in the ROM.
662 * o 8-bit write access:
663 * Reactivates the VAPIC after a guest hibernation, i.e. after the
664 * option ROM content has been re-initialized by a guest power cycle.
665 * o 32-bit write access:
666 * Poll for pending IRQs, considering the current VAPIC state.
670 if (s
->state
== VAPIC_INACTIVE
) {
671 rom_paddr
= (env
->segs
[R_CS
].base
+ env
->eip
) & ROM_BLOCK_MASK
;
672 s
->rom_state_paddr
= rom_paddr
+ data
;
674 s
->state
= VAPIC_STANDBY
;
676 if (vapic_prepare(s
) < 0) {
677 s
->state
= VAPIC_INACTIVE
;
678 s
->rom_state_paddr
= 0;
685 * Disable triggering instruction in ROM by writing a NOP.
687 * We cannot do this in TCG mode as the reported IP is not
691 patch_byte(cpu
, env
->eip
- 2, 0x66);
692 patch_byte(cpu
, env
->eip
- 1, 0x90);
696 if (s
->state
== VAPIC_ACTIVE
) {
699 if (update_rom_mapping(s
, env
, env
->eip
) < 0) {
702 if (find_real_tpr_addr(s
, env
) < 0) {
705 vapic_enable(s
, cpu
);
709 if (!kvm_irqchip_in_kernel()) {
710 apic_poll_irq(cpu
->apic_state
);
716 static uint64_t vapic_read(void *opaque
, hwaddr addr
, unsigned size
)
721 static const MemoryRegionOps vapic_ops
= {
722 .write
= vapic_write
,
724 .endianness
= DEVICE_NATIVE_ENDIAN
,
727 static void vapic_realize(DeviceState
*dev
, Error
**errp
)
729 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
730 VAPICROMState
*s
= VAPIC(dev
);
732 memory_region_init_io(&s
->io
, OBJECT(s
), &vapic_ops
, s
, "kvmvapic", 2);
733 sysbus_add_io(sbd
, VAPIC_IO_PORT
, &s
->io
);
734 sysbus_init_ioports(sbd
, VAPIC_IO_PORT
, 2);
736 option_rom
[nb_option_roms
].name
= "kvmvapic.bin";
737 option_rom
[nb_option_roms
].bootindex
= -1;
741 static void do_vapic_enable(CPUState
*cs
, run_on_cpu_data data
)
743 VAPICROMState
*s
= data
.host_ptr
;
744 X86CPU
*cpu
= X86_CPU(cs
);
746 static const uint8_t enabled
= 1;
747 cpu_physical_memory_write(s
->vapic_paddr
+ offsetof(VAPICState
, enabled
),
748 &enabled
, sizeof(enabled
));
749 apic_enable_vapic(cpu
->apic_state
, s
->vapic_paddr
);
750 s
->state
= VAPIC_ACTIVE
;
753 static void kvmvapic_vm_state_change(void *opaque
, int running
,
756 VAPICROMState
*s
= opaque
;
763 if (s
->state
== VAPIC_ACTIVE
) {
765 run_on_cpu(first_cpu
, do_vapic_enable
, RUN_ON_CPU_HOST_PTR(s
));
767 zero
= g_malloc0(s
->rom_state
.vapic_size
);
768 cpu_physical_memory_write(s
->vapic_paddr
, zero
,
769 s
->rom_state
.vapic_size
);
774 qemu_del_vm_change_state_handler(s
->vmsentry
);
778 static int vapic_post_load(void *opaque
, int version_id
)
780 VAPICROMState
*s
= opaque
;
783 * The old implementation of qemu-kvm did not provide the state
784 * VAPIC_STANDBY. Reconstruct it.
786 if (s
->state
== VAPIC_INACTIVE
&& s
->rom_state_paddr
!= 0) {
787 s
->state
= VAPIC_STANDBY
;
790 if (s
->state
!= VAPIC_INACTIVE
) {
791 if (vapic_prepare(s
) < 0) {
798 qemu_add_vm_change_state_handler(kvmvapic_vm_state_change
, s
);
803 static const VMStateDescription vmstate_handlers
= {
804 .name
= "kvmvapic-handlers",
806 .minimum_version_id
= 1,
807 .fields
= (VMStateField
[]) {
808 VMSTATE_UINT32(set_tpr
, VAPICHandlers
),
809 VMSTATE_UINT32(set_tpr_eax
, VAPICHandlers
),
810 VMSTATE_UINT32_ARRAY(get_tpr
, VAPICHandlers
, 8),
811 VMSTATE_UINT32(get_tpr_stack
, VAPICHandlers
),
812 VMSTATE_END_OF_LIST()
816 static const VMStateDescription vmstate_guest_rom
= {
817 .name
= "kvmvapic-guest-rom",
819 .minimum_version_id
= 1,
820 .fields
= (VMStateField
[]) {
821 VMSTATE_UNUSED(8), /* signature */
822 VMSTATE_UINT32(vaddr
, GuestROMState
),
823 VMSTATE_UINT32(fixup_start
, GuestROMState
),
824 VMSTATE_UINT32(fixup_end
, GuestROMState
),
825 VMSTATE_UINT32(vapic_vaddr
, GuestROMState
),
826 VMSTATE_UINT32(vapic_size
, GuestROMState
),
827 VMSTATE_UINT32(vcpu_shift
, GuestROMState
),
828 VMSTATE_UINT32(real_tpr_addr
, GuestROMState
),
829 VMSTATE_STRUCT(up
, GuestROMState
, 0, vmstate_handlers
, VAPICHandlers
),
830 VMSTATE_STRUCT(mp
, GuestROMState
, 0, vmstate_handlers
, VAPICHandlers
),
831 VMSTATE_END_OF_LIST()
835 static const VMStateDescription vmstate_vapic
= {
836 .name
= "kvm-tpr-opt", /* compatible with qemu-kvm VAPIC */
838 .minimum_version_id
= 1,
839 .post_load
= vapic_post_load
,
840 .fields
= (VMStateField
[]) {
841 VMSTATE_STRUCT(rom_state
, VAPICROMState
, 0, vmstate_guest_rom
,
843 VMSTATE_UINT32(state
, VAPICROMState
),
844 VMSTATE_UINT32(real_tpr_addr
, VAPICROMState
),
845 VMSTATE_UINT32(rom_state_vaddr
, VAPICROMState
),
846 VMSTATE_UINT32(vapic_paddr
, VAPICROMState
),
847 VMSTATE_UINT32(rom_state_paddr
, VAPICROMState
),
848 VMSTATE_END_OF_LIST()
852 static void vapic_class_init(ObjectClass
*klass
, void *data
)
854 DeviceClass
*dc
= DEVICE_CLASS(klass
);
856 dc
->reset
= vapic_reset
;
857 dc
->vmsd
= &vmstate_vapic
;
858 dc
->realize
= vapic_realize
;
861 static const TypeInfo vapic_type
= {
863 .parent
= TYPE_SYS_BUS_DEVICE
,
864 .instance_size
= sizeof(VAPICROMState
),
865 .class_init
= vapic_class_init
,
868 static void vapic_register(void)
870 type_register_static(&vapic_type
);
873 type_init(vapic_register
);