xref: /openbmc/linux/arch/x86/kvm/vmx/posted_intr.h (revision 173940b3)
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 bool pi_test_and_clear_sn(struct pi_desc *pi_desc)
44 {
45 	return test_and_clear_bit(POSTED_INTR_SN,
46 			(unsigned long *)&pi_desc->control);
47 }
48 
49 static inline bool pi_test_and_set_pir(int vector, struct pi_desc *pi_desc)
50 {
51 	return test_and_set_bit(vector, (unsigned long *)pi_desc->pir);
52 }
53 
54 static inline bool pi_is_pir_empty(struct pi_desc *pi_desc)
55 {
56 	return bitmap_empty((unsigned long *)pi_desc->pir, NR_VECTORS);
57 }
58 
59 static inline void pi_set_sn(struct pi_desc *pi_desc)
60 {
61 	set_bit(POSTED_INTR_SN,
62 		(unsigned long *)&pi_desc->control);
63 }
64 
65 static inline void pi_set_on(struct pi_desc *pi_desc)
66 {
67 	set_bit(POSTED_INTR_ON,
68 		(unsigned long *)&pi_desc->control);
69 }
70 
71 static inline void pi_clear_on(struct pi_desc *pi_desc)
72 {
73 	clear_bit(POSTED_INTR_ON,
74 		(unsigned long *)&pi_desc->control);
75 }
76 
77 static inline void pi_clear_sn(struct pi_desc *pi_desc)
78 {
79 	clear_bit(POSTED_INTR_SN,
80 		(unsigned long *)&pi_desc->control);
81 }
82 
83 static inline bool pi_test_on(struct pi_desc *pi_desc)
84 {
85 	return test_bit(POSTED_INTR_ON,
86 			(unsigned long *)&pi_desc->control);
87 }
88 
89 static inline bool pi_test_sn(struct pi_desc *pi_desc)
90 {
91 	return test_bit(POSTED_INTR_SN,
92 			(unsigned long *)&pi_desc->control);
93 }
94 
95 void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu);
96 void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu);
97 void pi_wakeup_handler(void);
98 void __init pi_init_cpu(int cpu);
99 bool pi_has_pending_interrupt(struct kvm_vcpu *vcpu);
100 int vmx_pi_update_irte(struct kvm *kvm, unsigned int host_irq,
101 		       uint32_t guest_irq, bool set);
102 void vmx_pi_start_assignment(struct kvm *kvm);
103 
104 #endif /* __KVM_X86_VMX_POSTED_INTR_H */
105