xref: /illumos-kvm/kvm_lapic.h (revision 2a9ff8dc)
1 /*
2  * GPL HEADER START
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * GPL HEADER END
18  *
19  * Copyright 2011 various Linux Kernel contributors.
20  * Copyright 2011 Joyent, Inc. All Rights Reserved.
21  */
22 #ifndef __KVM_X86_LAPIC_H
23 #define	__KVM_X86_LAPIC_H
24 
25 #include <vm/page.h>
26 
27 #include "kvm_iodev.h"
28 #include "kvm_timer.h"
29 
30 #define	APIC_LVT_NUM			6
31 /* 14 is the version for Xeon and Pentium 8.4.8 */
32 #define	APIC_VERSION			(0x14UL | ((APIC_LVT_NUM - 1) << 16))
33 
34 typedef struct kvm_lapic {
35 	unsigned long base_address;
36 	struct kvm_io_device dev;
37 	struct kvm_timer lapic_timer;
38 	uint32_t divide_count;
39 	struct kvm_vcpu *vcpu;
40 	int irr_pending;
41 	void *regs;
42 	gpa_t vapic_addr;
43 	page_t *vapic_page;
44 } kvm_lapic_t;
45 
46 extern int kvm_create_lapic(struct kvm_vcpu *);
47 extern void kvm_lapic_reset(struct kvm_vcpu *);
48 extern void kvm_free_lapic(struct kvm_vcpu *);
49 
50 extern void kvm_apic_set_version(struct kvm_vcpu *);
51 extern int kvm_apic_present(struct kvm_vcpu *vcpu);
52 
53 extern void kvm_lapic_sync_from_vapic(struct kvm_vcpu *);
54 extern void kvm_lapic_sync_to_vapic(struct kvm_vcpu *);
55 
56 extern int kvm_apic_has_interrupt(struct kvm_vcpu *);
57 extern int kvm_apic_accept_pic_intr(struct kvm_vcpu *);
58 extern int kvm_get_apic_interrupt(struct kvm_vcpu *);
59 extern int kvm_apic_match_dest(struct kvm_vcpu *, struct kvm_lapic *,
60     int, int, int);
61 
62 extern int kvm_lapic_enabled(struct kvm_vcpu *);
63 extern uint64_t kvm_lapic_get_cr8(struct kvm_vcpu *);
64 extern int kvm_lapic_find_highest_irr(struct kvm_vcpu *);
65 extern int kvm_apic_set_irq(struct kvm_vcpu *, struct kvm_lapic_irq *);
66 extern int kvm_apic_compare_prio(struct kvm_vcpu *, struct kvm_vcpu *);
67 
68 extern void kvm_lapic_set_tpr(struct kvm_vcpu *, unsigned long);
69 extern void kvm_lapic_set_base(struct kvm_vcpu *, uint64_t);
70 extern int kvm_lapic_set_vapic_addr(struct kvm_vcpu *, struct kvm_vapic_addr *);
71 
72 extern int kvm_x2apic_msr_write(struct kvm_vcpu *, uint32_t, uint64_t);
73 extern int kvm_x2apic_msr_read(struct kvm_vcpu *, uint32_t, uint64_t *);
74 
75 extern int kvm_hv_vapic_msr_write(struct kvm_vcpu *, uint32_t, uint64_t);
76 extern int kvm_hv_vapic_msr_read(struct kvm_vcpu *, uint32_t, uint64_t *);
77 
78 extern uint64_t kvm_get_apic_base(struct kvm_vcpu *);
79 extern void kvm_set_apic_base(struct kvm_vcpu *, uint64_t);
80 
81 extern int kvm_irq_delivery_to_apic(struct kvm *,
82     struct kvm_lapic *, struct kvm_lapic_irq *);
83 extern void kvm_apic_post_state_restore(struct kvm_vcpu *);
84 
85 #endif
86