xref: /illumos-kvm-cmd/qemu-kvm.h (revision 36b02c7d)
1 /*
2  * qemu/kvm integration
3  *
4  * Copyright (C) 2006-2008 Qumranet Technologies
5  * Portions Copyright 2011 Joyent, Inc.
6  *
7  * Licensed under the terms of the GNU GPL version 2 or higher.
8  */
9 #ifndef THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
10 #define THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
11 
12 #include "cpu.h"
13 
14 #include <signal.h>
15 #include <stdlib.h>
16 
17 #ifdef CONFIG_KVM
18 
19 #if defined(__s390__)
20 #include <asm/ptrace.h>
21 #endif
22 
23 #include <stdint.h>
24 
25 #ifndef __user
26 #define __user       /* temporary, until installed via make headers_install */
27 #endif
28 
29 #ifdef __sun__
30 #include <sys/kvm.h>
31 #else
32 #include <linux/kvm.h>
33 #endif
34 
35 #include <signal.h>
36 
37 /* FIXME: share this number with kvm */
38 /* FIXME: or dynamically alloc/realloc regions */
39 #ifdef __s390__
40 #define KVM_MAX_NUM_MEM_REGIONS 1u
41 #define MAX_VCPUS 64
42 #define LIBKVM_S390_ORIGIN (0UL)
43 #elif defined(__ia64__)
44 #define KVM_MAX_NUM_MEM_REGIONS 32u
45 #define MAX_VCPUS 256
46 #else
47 #define KVM_MAX_NUM_MEM_REGIONS 32u
48 #define MAX_VCPUS 16
49 #endif
50 
51 /* kvm abi verison variable */
52 extern int kvm_abi;
53 
54 /**
55  * \brief The KVM context
56  *
57  * The verbose KVM context
58  */
59 
60 struct kvm_context {
61     void *opaque;
62     /// is dirty pages logging enabled for all regions or not
63     int dirty_pages_log_all;
64     /// do not create in-kernel irqchip if set
65     int no_irqchip_creation;
66     /// in-kernel irqchip status
67     int irqchip_in_kernel;
68     /// ioctl to use to inject interrupts
69     int irqchip_inject_ioctl;
70     /// do not create in-kernel pit if set
71     int no_pit_creation;
72 #ifdef KVM_CAP_IRQ_ROUTING
73     struct kvm_irq_routing *irq_routes;
74     int nr_allocated_irq_routes;
75 #endif
76     void *used_gsi_bitmap;
77     int max_gsi;
78 };
79 
80 typedef struct kvm_context *kvm_context_t;
81 
82 #include "kvm.h"
83 int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
84                             void **vm_mem);
85 int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory,
86                                void **vm_mem);
87 
88 int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
89                     void **vm_mem);
90 
91 int kvm_arch_run(CPUState *env);
92 
93 
94 void kvm_show_code(CPUState *env);
95 
96 int handle_halt(CPUState *env);
97 
98 int handle_shutdown(kvm_context_t kvm, CPUState *env);
99 void post_kvm_run(kvm_context_t kvm, CPUState *env);
100 int pre_kvm_run(kvm_context_t kvm, CPUState *env);
101 int handle_io_window(kvm_context_t kvm);
102 int try_push_interrupts(kvm_context_t kvm);
103 
104 #if defined(__x86_64__) || defined(__i386__)
105 struct kvm_x86_mce;
106 #endif
107 
108 /*!
109  * \brief Disable the in-kernel IRQCHIP creation
110  *
111  * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
112  * this should be called prior to kvm_create().
113  *
114  * \param kvm Pointer to the kvm_context
115  */
116 void kvm_disable_irqchip_creation(kvm_context_t kvm);
117 
118 /*!
119  * \brief Disable the in-kernel PIT creation
120  *
121  * In-kernel pit is enabled by default. If userspace pit is to be used,
122  * this should be called prior to kvm_create().
123  *
124  *  \param kvm Pointer to the kvm_context
125  */
126 void kvm_disable_pit_creation(kvm_context_t kvm);
127 
128 /*!
129  * \brief Create new virtual machine
130  *
131  * This creates a new virtual machine, maps physical RAM to it, and creates a
132  * virtual CPU for it.\n
133  * \n
134  * Memory gets mapped for addresses 0->0xA0000, 0xC0000->phys_mem_bytes
135  *
136  * \param kvm Pointer to the current kvm_context
137  * \param phys_mem_bytes The amount of physical ram you want the VM to have
138  * \param phys_mem This pointer will be set to point to the memory that
139  * kvm_create allocates for physical RAM
140  * \return 0 on success
141  */
142 int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
143                void **phys_mem);
144 int kvm_create_vm(kvm_context_t kvm);
145 void kvm_create_irqchip(kvm_context_t kvm);
146 
147 /*!
148  * \brief Start the VCPU
149  *
150  * This starts the VCPU and virtualization is started.\n
151  * \n
152  * This function will not return until any of these conditions are met:
153  * - An IO/MMIO handler does not return "0"
154  * - An exception that neither the guest OS, nor KVM can handle occurs
155  *
156  * \note This function will call the callbacks registered in kvm_init()
157  * to emulate those functions
158  * \note If you at any point want to interrupt the VCPU, kvm_run() will
159  * listen to the EINTR signal. This allows you to simulate external interrupts
160  * and asyncronous IO.
161  *
162  * \param kvm Pointer to the current kvm_context
163  * \param vcpu Which virtual CPU should be started
164  * \return 0 on success, but you really shouldn't expect this function to
165  * return except for when an error has occured, or when you have sent it
166  * an EINTR signal.
167  */
168 int kvm_run(CPUState *env);
169 
170 /*!
171  * \brief Check if a vcpu is ready for interrupt injection
172  *
173  * This checks if vcpu interrupts are not masked by mov ss or sti.
174  *
175  * \param kvm Pointer to the current kvm_context
176  * \param vcpu Which virtual CPU should get dumped
177  * \return boolean indicating interrupt injection readiness
178  */
179 int kvm_is_ready_for_interrupt_injection(CPUState *env);
180 
181 /*!
182  * \brief Read VCPU registers
183  *
184  * This gets the GP registers from the VCPU and outputs them
185  * into a kvm_regs structure
186  *
187  * \note This function returns a \b copy of the VCPUs registers.\n
188  * If you wish to modify the VCPUs GP registers, you should call kvm_set_regs()
189  *
190  * \param kvm Pointer to the current kvm_context
191  * \param vcpu Which virtual CPU should get dumped
192  * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
193  * registers values
194  * \return 0 on success
195  */
196 int kvm_get_regs(CPUState *env, struct kvm_regs *regs);
197 
198 /*!
199  * \brief Write VCPU registers
200  *
201  * This sets the GP registers on the VCPU from a kvm_regs structure
202  *
203  * \note When this function returns, the regs pointer and the data it points to
204  * can be discarded
205  * \param kvm Pointer to the current kvm_context
206  * \param vcpu Which virtual CPU should get dumped
207  * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
208  * registers values
209  * \return 0 on success
210  */
211 int kvm_set_regs(CPUState *env, struct kvm_regs *regs);
212 
213 #ifdef KVM_CAP_MP_STATE
214 /*!
215  *  * \brief Read VCPU MP state
216  *
217  */
218 int kvm_get_mpstate(CPUState *env, struct kvm_mp_state *mp_state);
219 
220 /*!
221  *  * \brief Write VCPU MP state
222  *
223  */
224 int kvm_set_mpstate(CPUState *env, struct kvm_mp_state *mp_state);
225 #endif
226 
227 #if defined(__i386__) || defined(__x86_64__)
228 /*!
229  * \brief Simulate an external vectored interrupt
230  *
231  * This allows you to simulate an external vectored interrupt.
232  *
233  * \param kvm Pointer to the current kvm_context
234  * \param vcpu Which virtual CPU should get dumped
235  * \param irq Vector number
236  * \return 0 on success
237  */
238 int kvm_inject_irq(CPUState *env, unsigned irq);
239 
240 
241 /*!
242  * \brief Setting the number of shadow pages to be allocated to the vm
243  *
244  * \param kvm pointer to kvm_context
245  * \param nrshadow_pages number of pages to be allocated
246  */
247 int kvm_set_shadow_pages(kvm_context_t kvm, unsigned int nrshadow_pages);
248 
249 /*!
250  * \brief Getting the number of shadow pages that are allocated to the vm
251  *
252  * \param kvm pointer to kvm_context
253  * \param nrshadow_pages number of pages to be allocated
254  */
255 int kvm_get_shadow_pages(kvm_context_t kvm, unsigned int *nrshadow_pages);
256 
257 #endif
258 
259 /*!
260  * \brief Dump VCPU registers
261  *
262  * This dumps some of the information that KVM has about a virtual CPU, namely:
263  * - GP Registers
264  *
265  * A much more verbose version of this is available as kvm_dump_vcpu()
266  *
267  * \param kvm Pointer to the current kvm_context
268  * \param vcpu Which virtual CPU should get dumped
269  * \return 0 on success
270  */
271 void kvm_show_regs(CPUState *env);
272 
273 
274 void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start,
275                           unsigned long len, int log, int writable);
276 void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start,
277                           unsigned long len);
278 
279 int kvm_is_containing_region(kvm_context_t kvm, unsigned long phys_start,
280                              unsigned long size);
281 int kvm_register_phys_mem(kvm_context_t kvm, unsigned long phys_start,
282                           void *userspace_addr, unsigned long len, int log);
283 int kvm_get_dirty_pages_range(kvm_context_t kvm, unsigned long phys_addr,
284                               unsigned long end_addr, void *opaque,
285                               int (*cb)(unsigned long start,
286                                         unsigned long len, void *bitmap,
287                                         void *opaque));
288 int kvm_register_coalesced_mmio(kvm_context_t kvm, uint64_t addr,
289                                 uint32_t size);
290 int kvm_unregister_coalesced_mmio(kvm_context_t kvm, uint64_t addr,
291                                   uint32_t size);
292 
293 /*!
294  * \brief Get a bitmap of guest ram pages which are allocated to the guest.
295  *
296  * \param kvm Pointer to the current kvm_context
297  * \param phys_addr Memory slot phys addr
298  * \param bitmap Long aligned address of a big enough bitmap (one bit per page)
299  */
300 int kvm_get_mem_map(kvm_context_t kvm, unsigned long phys_addr, void *bitmap);
301 int kvm_get_mem_map_range(kvm_context_t kvm, unsigned long phys_addr,
302                           unsigned long len, void *buf, void *opaque,
303                           int (*cb)(unsigned long start,
304                                     unsigned long len, void *bitmap,
305                                     void *opaque));
306 int kvm_set_irq_level(kvm_context_t kvm, int irq, int level, int *status);
307 
308 int kvm_dirty_pages_log_enable_slot(kvm_context_t kvm, uint64_t phys_start,
309                                     uint64_t len);
310 int kvm_dirty_pages_log_disable_slot(kvm_context_t kvm, uint64_t phys_start,
311                                      uint64_t len);
312 /*!
313  * \brief Enable dirty-pages-logging for all memory regions
314  *
315  * \param kvm Pointer to the current kvm_context
316  */
317 int kvm_dirty_pages_log_enable_all(kvm_context_t kvm);
318 
319 /*!
320  * \brief Disable dirty-page-logging for some memory regions
321  *
322  * Disable dirty-pages-logging for those memory regions that were
323  * created with dirty-page-logging disabled.
324  *
325  * \param kvm Pointer to the current kvm_context
326  */
327 int kvm_dirty_pages_log_reset(kvm_context_t kvm);
328 
329 #ifdef KVM_CAP_IRQCHIP
330 /*!
331  * \brief Dump in kernel IRQCHIP contents
332  *
333  * Dump one of the in kernel irq chip devices, including PIC (master/slave)
334  * and IOAPIC into a kvm_irqchip structure
335  *
336  * \param kvm Pointer to the current kvm_context
337  * \param chip The irq chip device to be dumped
338  */
339 int kvm_get_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
340 
341 /*!
342  * \brief Set in kernel IRQCHIP contents
343  *
344  * Write one of the in kernel irq chip devices, including PIC (master/slave)
345  * and IOAPIC
346  *
347  *
348  * \param kvm Pointer to the current kvm_context
349  * \param chip THe irq chip device to be written
350  */
351 int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
352 
353 #if defined(__i386__) || defined(__x86_64__)
354 /*!
355  * \brief Get in kernel local APIC for vcpu
356  *
357  * Save the local apic state including the timer of a virtual CPU
358  *
359  * \param kvm Pointer to the current kvm_context
360  * \param vcpu Which virtual CPU should be accessed
361  * \param s Local apic state of the specific virtual CPU
362  */
363 int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s);
364 
365 /*!
366  * \brief Set in kernel local APIC for vcpu
367  *
368  * Restore the local apic state including the timer of a virtual CPU
369  *
370  * \param kvm Pointer to the current kvm_context
371  * \param vcpu Which virtual CPU should be accessed
372  * \param s Local apic state of the specific virtual CPU
373  */
374 int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s);
375 
376 #endif
377 
378 /*!
379  * \brief Simulate an NMI
380  *
381  * This allows you to simulate a non-maskable interrupt.
382  *
383  * \param kvm Pointer to the current kvm_context
384  * \param vcpu Which virtual CPU should get dumped
385  * \return 0 on success
386  */
387 int kvm_inject_nmi(CPUState *env);
388 
389 #endif
390 
391 /*!
392  * \brief Initialize coalesced MMIO
393  *
394  * Check for coalesced MMIO capability and store in context
395  *
396  * \param kvm Pointer to the current kvm_context
397  */
398 int kvm_init_coalesced_mmio(kvm_context_t kvm);
399 
400 #ifdef KVM_CAP_PIT
401 
402 #if defined(__i386__) || defined(__x86_64__)
403 /*!
404  * \brief Get in kernel PIT of the virtual domain
405  *
406  * Save the PIT state.
407  *
408  * \param kvm Pointer to the current kvm_context
409  * \param s PIT state of the virtual domain
410  */
411 int kvm_get_pit(kvm_context_t kvm, struct kvm_pit_state *s);
412 
413 /*!
414  * \brief Set in kernel PIT of the virtual domain
415  *
416  * Restore the PIT state.
417  * Timer would be retriggerred after restored.
418  *
419  * \param kvm Pointer to the current kvm_context
420  * \param s PIT state of the virtual domain
421  */
422 int kvm_set_pit(kvm_context_t kvm, struct kvm_pit_state *s);
423 
424 int kvm_reinject_control(kvm_context_t kvm, int pit_reinject);
425 
426 #ifdef KVM_CAP_PIT_STATE2
427 /*!
428  * \brief Check for kvm support of kvm_pit_state2
429  *
430  * \param kvm Pointer to the current kvm_context
431  * \return 0 on success
432  */
433 int kvm_has_pit_state2(kvm_context_t kvm);
434 
435 /*!
436  * \brief Set in kernel PIT state2 of the virtual domain
437  *
438  *
439  * \param kvm Pointer to the current kvm_context
440  * \param ps2 PIT state2 of the virtual domain
441  * \return 0 on success
442  */
443 int kvm_set_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2);
444 
445 /*!
446  * \brief Get in kernel PIT state2 of the virtual domain
447  *
448  *
449  * \param kvm Pointer to the current kvm_context
450  * \param ps2 PIT state2 of the virtual domain
451  * \return 0 on success
452  */
453 int kvm_get_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2);
454 
455 #endif
456 #endif
457 #endif
458 
459 #ifdef KVM_CAP_VAPIC
460 
461 int kvm_enable_vapic(CPUState *env, uint64_t vapic);
462 
463 #endif
464 
465 #if defined(__s390__)
466 int kvm_s390_initial_reset(kvm_context_t kvm, int slot);
467 int kvm_s390_interrupt(kvm_context_t kvm, int slot,
468                        struct kvm_s390_interrupt *kvmint);
469 int kvm_s390_set_initial_psw(kvm_context_t kvm, int slot, psw_t psw);
470 int kvm_s390_store_status(kvm_context_t kvm, int slot, unsigned long addr);
471 #endif
472 
473 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
474 /*!
475  * \brief Notifies host kernel about a PCI device to be assigned to a guest
476  *
477  * Used for PCI device assignment, this function notifies the host
478  * kernel about the assigning of the physical PCI device to a guest.
479  *
480  * \param kvm Pointer to the current kvm_context
481  * \param assigned_dev Parameters, like bus, devfn number, etc
482  */
483 int kvm_assign_pci_device(kvm_context_t kvm,
484                           struct kvm_assigned_pci_dev *assigned_dev);
485 
486 /*!
487  * \brief Assign IRQ for an assigned device
488  *
489  * Used for PCI device assignment, this function assigns IRQ numbers for
490  * an physical device and guest IRQ handling.
491  *
492  * \param kvm Pointer to the current kvm_context
493  * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
494  */
495 int kvm_assign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq);
496 
497 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
498 /*!
499  * \brief Deassign IRQ for an assigned device
500  *
501  * Used for PCI device assignment, this function deassigns IRQ numbers
502  * for an assigned device.
503  *
504  * \param kvm Pointer to the current kvm_context
505  * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
506  */
507 int kvm_deassign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq);
508 #endif
509 #endif
510 
511 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
512 /*!
513  * \brief Notifies host kernel about a PCI device to be deassigned from a guest
514  *
515  * Used for hot remove PCI device, this function notifies the host
516  * kernel about the deassigning of the physical PCI device from a guest.
517  *
518  * \param kvm Pointer to the current kvm_context
519  * \param assigned_dev Parameters, like bus, devfn number, etc
520  */
521 int kvm_deassign_pci_device(kvm_context_t kvm,
522                             struct kvm_assigned_pci_dev *assigned_dev);
523 #endif
524 
525 /*!
526  * \brief Determines the number of gsis that can be routed
527  *
528  * Returns the number of distinct gsis that can be routed by kvm.  This is
529  * also the number of distinct routes (if a gsi has two routes, than another
530  * gsi cannot be used...)
531  *
532  * \param kvm Pointer to the current kvm_context
533  */
534 int kvm_get_gsi_count(kvm_context_t kvm);
535 
536 /*!
537  * \brief Clears the temporary irq routing table
538  *
539  * Clears the temporary irq routing table.  Nothing is committed to the
540  * running VM.
541  *
542  */
543 int kvm_clear_gsi_routes(void);
544 
545 /*!
546  * \brief Adds an irq route to the temporary irq routing table
547  *
548  * Adds an irq route to the temporary irq routing table.  Nothing is
549  * committed to the running VM.
550  */
551 int kvm_add_irq_route(int gsi, int irqchip, int pin);
552 
553 /*!
554  * \brief Removes an irq route from the temporary irq routing table
555  *
556  * Adds an irq route to the temporary irq routing table.  Nothing is
557  * committed to the running VM.
558  */
559 int kvm_del_irq_route(int gsi, int irqchip, int pin);
560 
561 struct kvm_irq_routing_entry;
562 /*!
563  * \brief Adds a routing entry to the temporary irq routing table
564  *
565  * Adds a filled routing entry to the temporary irq routing table. Nothing is
566  * committed to the running VM.
567  */
568 int kvm_add_routing_entry(struct kvm_irq_routing_entry *entry);
569 
570 /*!
571  * \brief Removes a routing from the temporary irq routing table
572  *
573  * Remove a routing to the temporary irq routing table.  Nothing is
574  * committed to the running VM.
575  */
576 int kvm_del_routing_entry(struct kvm_irq_routing_entry *entry);
577 
578 /*!
579  * \brief Updates a routing in the temporary irq routing table
580  *
581  * Update a routing in the temporary irq routing table
582  * with a new value. entry type and GSI can not be changed.
583  * Nothing is committed to the running VM.
584  */
585 int kvm_update_routing_entry(struct kvm_irq_routing_entry *entry,
586                              struct kvm_irq_routing_entry *newentry);
587 
588 
589 /*!
590  * \brief Create a file descriptor for injecting interrupts
591  *
592  * Creates an eventfd based file-descriptor that maps to a specific GSI
593  * in the guest.  eventfd compliant signaling (write() from userspace, or
594  * eventfd_signal() from kernelspace) will cause the GSI to inject
595  * itself into the guest at the next available window.
596  *
597  * \param kvm Pointer to the current kvm_context
598  * \param gsi GSI to assign to this fd
599  * \param flags reserved, must be zero
600  */
601 int kvm_irqfd(kvm_context_t kvm, int gsi, int flags);
602 
603 #ifdef KVM_CAP_DEVICE_MSIX
604 int kvm_assign_set_msix_nr(kvm_context_t kvm,
605                            struct kvm_assigned_msix_nr *msix_nr);
606 int kvm_assign_set_msix_entry(kvm_context_t kvm,
607                               struct kvm_assigned_msix_entry *entry);
608 #endif
609 
610 #else                           /* !CONFIG_KVM */
611 
612 typedef struct kvm_context *kvm_context_t;
613 typedef struct kvm_vcpu_context *kvm_vcpu_context_t;
614 
615 struct kvm_pit_state {
616 };
617 
618 #endif                          /* !CONFIG_KVM */
619 
620 
621 /*!
622  * \brief Create new KVM context
623  *
624  * This creates a new kvm_context. A KVM context is a small area of data that
625  * holds information about the KVM instance that gets created by this call.\n
626  * This should always be your first call to KVM.
627  *
628  * \param opaque Not used
629  * \return NULL on failure
630  */
631 int kvm_init(void);
632 
633 int kvm_main_loop(void);
634 int kvm_init_ap(void);
635 int kvm_vcpu_inited(CPUState *env);
636 void kvm_save_lapic(CPUState *env);
637 void kvm_load_lapic(CPUState *env);
638 
639 void kvm_hpet_enable_kpit(void);
640 void kvm_hpet_disable_kpit(void);
641 
642 int kvm_physical_memory_set_dirty_tracking(int enable);
643 
644 void on_vcpu(CPUState *env, void (*func)(void *data), void *data);
645 void qemu_kvm_call_with_env(void (*func)(void *), void *data, CPUState *env);
646 void qemu_kvm_cpuid_on_env(CPUState *env);
647 void kvm_inject_interrupt(CPUState *env, int mask);
648 void kvm_update_after_sipi(CPUState *env);
649 void kvm_update_interrupt_request(CPUState *env);
650 #ifndef CONFIG_USER_ONLY
651 void *kvm_cpu_create_phys_mem(target_phys_addr_t start_addr, unsigned long size,
652                               int log, int writable);
653 
654 void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr,
655                               unsigned long size);
656 void kvm_qemu_log_memory(target_phys_addr_t start, target_phys_addr_t size,
657                          int log);
658 #endif
659 int kvm_qemu_create_memory_alias(uint64_t phys_start, uint64_t len,
660                                  uint64_t target_phys);
661 int kvm_qemu_destroy_memory_alias(uint64_t phys_start);
662 
663 int kvm_arch_qemu_create_context(void);
664 
665 void kvm_arch_save_regs(CPUState *env);
666 void kvm_arch_load_regs(CPUState *env, int level);
667 int kvm_arch_has_work(CPUState *env);
668 void kvm_arch_process_irqchip_events(CPUState *env);
669 int kvm_arch_try_push_interrupts(void *opaque);
670 void kvm_arch_push_nmi(void *opaque);
671 void kvm_arch_cpu_reset(CPUState *env);
672 int kvm_set_boot_cpu_id(uint32_t id);
673 
674 void qemu_kvm_aio_wait_start(void);
675 void qemu_kvm_aio_wait(void);
676 void qemu_kvm_aio_wait_end(void);
677 
678 void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write);
679 
680 int kvm_arch_init_irq_routing(void);
681 
682 int kvm_mmio_read(void *opaque, uint64_t addr, uint8_t * data, int len);
683 int kvm_mmio_write(void *opaque, uint64_t addr, uint8_t * data, int len);
684 
685 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
686 struct ioperm_data;
687 
688 void kvm_ioperm(CPUState *env, void *data);
689 void kvm_add_ioperm_data(struct ioperm_data *data);
690 void kvm_remove_ioperm_data(unsigned long start_port, unsigned long num);
691 void kvm_arch_do_ioperm(void *_data);
692 #endif
693 
694 #define ALIGN(x, y)  (((x)+(y)-1) & ~((y)-1))
695 #define BITMAP_SIZE(m) (ALIGN(((m)>>TARGET_PAGE_BITS), HOST_LONG_BITS) / 8)
696 
697 #ifdef CONFIG_KVM
698 #include "qemu-queue.h"
699 
700 extern int kvm_irqchip;
701 extern int kvm_pit;
702 extern int kvm_pit_reinject;
703 extern int kvm_nested;
704 extern kvm_context_t kvm_context;
705 
706 struct ioperm_data {
707     unsigned long start_port;
708     unsigned long num;
709     int turn_on;
710     QLIST_ENTRY(ioperm_data) entries;
711 };
712 
713 void qemu_kvm_cpu_stop(CPUState *env);
714 int kvm_arch_halt(CPUState *env);
715 int handle_tpr_access(void *opaque, CPUState *env, uint64_t rip,
716                       int is_write);
717 
718 #define qemu_kvm_has_gsi_routing() kvm_has_gsi_routing()
719 #ifdef TARGET_I386
720 #define qemu_kvm_has_pit_state2() kvm_has_pit_state2(kvm_context)
721 #endif
722 #else
723 #define kvm_nested 0
724 #define qemu_kvm_has_gsi_routing() (0)
725 #ifdef TARGET_I386
726 #define qemu_kvm_has_pit_state2() (0)
727 #endif
728 #define qemu_kvm_cpu_stop(env) do {} while(0)
729 #endif
730 
731 #ifdef CONFIG_KVM
732 
733 typedef struct KVMSlot {
734     target_phys_addr_t start_addr;
735     ram_addr_t memory_size;
736     ram_addr_t phys_offset;
737     int slot;
738     int flags;
739 } KVMSlot;
740 
741 typedef struct kvm_dirty_log KVMDirtyLog;
742 
743 struct KVMState {
744     KVMSlot slots[32];
745     int fd;
746     int vmfd;
747     int coalesced_mmio;
748 #ifdef KVM_CAP_COALESCED_MMIO
749     struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
750 #endif
751     int broken_set_mem_region;
752     int migration_log;
753     int vcpu_events;
754     int robust_singlestep;
755     int debugregs;
756 #ifdef KVM_CAP_SET_GUEST_DEBUG
757     QTAILQ_HEAD(, kvm_sw_breakpoint) kvm_sw_breakpoints;
758 #endif
759     int irqchip_in_kernel;
760     int pit_in_kernel;
761     int xsave, xcrs;
762     int many_ioeventfds;
763 
764     struct kvm_context kvm_context;
765 };
766 
767 extern struct KVMState *kvm_state;
768 
769 int kvm_tpr_enable_vapic(CPUState *env);
770 
771 unsigned long kvm_get_thread_id(void);
772 int kvm_cpu_is_stopped(CPUState *env);
773 
774 #endif
775 
776 #endif
777