xref: /linux/arch/x86/kvm/vmx/posted_intr.h (revision a1c3be890440a1769ed6f822376a3e3ab0d42994)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __KVM_X86_VMX_POSTED_INTR_H
3 #define __KVM_X86_VMX_POSTED_INTR_H
4 
5 #define POSTED_INTR_ON  0
6 #define POSTED_INTR_SN  1
7 
8 /* Posted-Interrupt Descriptor */
9 struct pi_desc {
10 	u32 pir[8];     /* Posted interrupt requested */
11 	union {
12 		struct {
13 				/* bit 256 - Outstanding Notification */
14 			u16	on	: 1,
15 				/* bit 257 - Suppress Notification */
16 				sn	: 1,
17 				/* bit 271:258 - Reserved */
18 				rsvd_1	: 14;
19 				/* bit 279:272 - Notification Vector */
20 			u8	nv;
21 				/* bit 287:280 - Reserved */
22 			u8	rsvd_2;
23 				/* bit 319:288 - Notification Destination */
24 			u32	ndst;
25 		};
26 		u64 control;
27 	};
28 	u32 rsvd[6];
29 } __aligned(64);
30 
31 static inline bool pi_test_and_set_on(struct pi_desc *pi_desc)
32 {
33 	return test_and_set_bit(POSTED_INTR_ON,
34 			(unsigned long *)&pi_desc->control);
35 }
36 
37 static inline bool pi_test_and_clear_on(struct pi_desc *pi_desc)
38 {
39 	return test_and_clear_bit(POSTED_INTR_ON,
40 			(unsigned long *)&pi_desc->control);
41 }
42 
43 static inline int pi_test_and_set_pir(int vector, struct pi_desc *pi_desc)
44 {
45 	return test_and_set_bit(vector, (unsigned long *)pi_desc->pir);
46 }
47 
48 static inline bool pi_is_pir_empty(struct pi_desc *pi_desc)
49 {
50 	return bitmap_empty((unsigned long *)pi_desc->pir, NR_VECTORS);
51 }
52 
53 static inline void pi_set_sn(struct pi_desc *pi_desc)
54 {
55 	set_bit(POSTED_INTR_SN,
56 		(unsigned long *)&pi_desc->control);
57 }
58 
59 static inline void pi_set_on(struct pi_desc *pi_desc)
60 {
61 	set_bit(POSTED_INTR_ON,
62 		(unsigned long *)&pi_desc->control);
63 }
64 
65 static inline void pi_clear_on(struct pi_desc *pi_desc)
66 {
67 	clear_bit(POSTED_INTR_ON,
68 		(unsigned long *)&pi_desc->control);
69 }
70 
71 static inline void pi_clear_sn(struct pi_desc *pi_desc)
72 {
73 	clear_bit(POSTED_INTR_SN,
74 		(unsigned long *)&pi_desc->control);
75 }
76 
77 static inline int pi_test_on(struct pi_desc *pi_desc)
78 {
79 	return test_bit(POSTED_INTR_ON,
80 			(unsigned long *)&pi_desc->control);
81 }
82 
83 static inline int pi_test_sn(struct pi_desc *pi_desc)
84 {
85 	return test_bit(POSTED_INTR_SN,
86 			(unsigned long *)&pi_desc->control);
87 }
88 
89 void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu);
90 void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu);
91 int pi_pre_block(struct kvm_vcpu *vcpu);
92 void pi_post_block(struct kvm_vcpu *vcpu);
93 void pi_wakeup_handler(void);
94 void __init pi_init_cpu(int cpu);
95 bool pi_has_pending_interrupt(struct kvm_vcpu *vcpu);
96 int pi_update_irte(struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq,
97 		   bool set);
98 
99 #endif /* __KVM_X86_VMX_POSTED_INTR_H */
100