3030#ifndef VLAPIC_H
3131#define VLAPIC_H
3232
33+
34+ /**
35+ * @file vlapic.h
36+ *
37+ * @brief public APIs for virtual LAPIC
38+ */
39+
40+
3341/*
3442 * 16 priority levels with at most one vector injected per level.
3543 */
@@ -103,26 +111,72 @@ struct acrn_vlapic {
103111void vlapic_set_cr8 (struct acrn_vlapic * vlapic , uint64_t val );
104112uint64_t vlapic_get_cr8 (const struct acrn_vlapic * vlapic );
105113
106- /*
107- * Returns 0 if there is no eligible vector that can be delivered to the
108- * guest at this time and non-zero otherwise.
114+ /**
115+ * @brief virtual LAPIC
116+ *
117+ * @addtogroup acrn_vlapic ACRN vLAPIC
118+ * @{
119+ */
120+
121+
122+ /**
123+ * @brief Get pending virtual interrupts for vLAPIC.
124+ *
125+ * @param[in] vlapic Pointer to target vLAPIC data structure
126+ * @param[inout] vecptr Pointer to vector buffer and will be filled
127+ * with eligible vector if any.
109128 *
110- * If an eligible vector number is found and 'vecptr' is not NULL then it will
111- * be stored in the location pointed to by 'vecptr' .
129+ * @return 0 - There is no eligible pending vector.
130+ * @return 1 - There is pending vector .
112131 *
113- * Note that the vector does not automatically transition to the ISR as a
114- * result of calling this function.
132+ * @remark The vector does not automatically transition to the ISR as a
133+ * result of calling this function.
115134 */
116135int vlapic_pending_intr (const struct acrn_vlapic * vlapic , uint32_t * vecptr );
117136
118- /*
137+ /**
138+ * @brief Accept virtual interrupt.
139+ *
119140 * Transition 'vector' from IRR to ISR. This function is called with the
120141 * vector returned by 'vlapic_pending_intr()' when the guest is able to
121142 * accept this interrupt (i.e. RFLAGS.IF = 1 and no conditions exist that
122143 * block interrupt delivery).
144+ *
145+ * @param[in] vlapic Pointer to target vLAPIC data structure
146+ * @param[in] vector Target virtual interrupt vector
147+ *
148+ * @return void
149+ *
150+ * @pre vlapic != NULL
123151 */
124152void vlapic_intr_accepted (struct acrn_vlapic * vlapic , uint32_t vector );
153+
154+ /**
155+ * @brief Send notification vector to target pCPU.
156+ *
157+ * If APICv Posted-Interrupt is enabled and target pCPU is in non-root mode,
158+ * pCPU will sync pending virtual interrupts from PIR to vIRR automatically,
159+ * without VM exit.
160+ * If pCPU in root-mode, virtual interrupt will be injected in next VM entry.
161+ *
162+ * @param[in] dest_pcpu_id Target CPU ID.
163+ *
164+ * @return void
165+ */
125166void vlapic_post_intr (uint16_t dest_pcpu_id );
167+
168+ /**
169+ * @brief Get physical address to PIR description.
170+ *
171+ * If APICv Posted-interrupt is supported, this address will be configured
172+ * to VMCS "Posted-interrupt descriptor address" field.
173+ *
174+ * @param[in] vcpu Target vCPU
175+ *
176+ * @return physicall address to PIR
177+ *
178+ * @pre vcpu != NULL
179+ */
126180uint64_t apicv_get_pir_desc_paddr (struct vcpu * vcpu );
127181
128182int vlapic_rdmsr (struct vcpu * vcpu , uint32_t msr , uint64_t * rval );
@@ -136,24 +190,63 @@ int vlapic_set_intr(struct vcpu *vcpu, uint32_t vector, bool level);
136190
137191#define LAPIC_TRIG_LEVEL true
138192#define LAPIC_TRIG_EDGE false
193+ /**
194+ * @brief Pend level-trigger mode virtual interrupt to vCPU.
195+ *
196+ * @param[in] vcpu Pointer to target vCPU data structure
197+ * @param[in] vector Vector to be injected.
198+ *
199+ * @return 0 on success.
200+ * @return -EINVAL on error that vector is invalid or vcpu is NULL.
201+ */
139202static inline int
140203vlapic_intr_level (struct vcpu * vcpu , uint32_t vector )
141204{
142205 return vlapic_set_intr (vcpu , vector , LAPIC_TRIG_LEVEL );
143206}
144207
208+ /**
209+ * @brief Pend edge-trigger mode virtual interrupt to vCPU.
210+ *
211+ * @param[in] vcpu Pointer to target vCPU data structure
212+ * @param[in] vector Vector to be injected.
213+ *
214+ * @return 0 on success.
215+ * @return -EINVAL on error that vector is invalid or vcpu is NULL.
216+ */
145217static inline int
146218vlapic_intr_edge (struct vcpu * vcpu , uint32_t vector )
147219{
148220 return vlapic_set_intr (vcpu , vector , LAPIC_TRIG_EDGE );
149221}
150222
151- /*
152- * Triggers the LAPIC local interrupt (LVT) 'vector' on 'cpu'. 'cpu' can
153- * be set to -1 to trigger the interrupt on all CPUs.
223+ /**
224+ * @brief Triggers LAPIC local interrupt(LVT).
225+ *
226+ * @param[in] vm Pointer to VM data structure
227+ * @param[in] vcpu_id_arg ID of vCPU, BROADCAST_CPU_ID means triggering
228+ * interrupt to all vCPUs.
229+ * @param[in] vector Vector to be fired.
230+ *
231+ * @return 0 on success.
232+ * @return -EINVAL on error that vcpu_id_arg or vector is invalid.
233+ *
234+ * @pre vm != NULL
154235 */
155236int vlapic_set_local_intr (struct vm * vm , uint16_t vcpu_id_arg , uint32_t vector );
156237
238+ /**
239+ * @brief Inject MSI to target VM.
240+ *
241+ * @param[in] vm Pointer to VM data structure
242+ * @param[in] addr MSI address.
243+ * @param[in] msg MSI data.
244+ *
245+ * @return 0 on success.
246+ * @return non-zero on error that addr is invalid.
247+ *
248+ * @pre vm != NULL
249+ */
157250int vlapic_intr_msi (struct vm * vm , uint64_t addr , uint64_t msg );
158251
159252void vlapic_deliver_intr (struct vm * vm , bool level , uint32_t dest ,
@@ -189,4 +282,9 @@ int apic_write_vmexit_handler(struct vcpu *vcpu);
189282int veoi_vmexit_handler (struct vcpu * vcpu );
190283int tpr_below_threshold_vmexit_handler (__unused struct vcpu * vcpu );
191284void calcvdest (struct vm * vm , uint64_t * dmask , uint32_t dest , bool phys );
285+
286+ /**
287+ * @}
288+ */
289+ /* End of acrn_vlapic */
192290#endif /* VLAPIC_H */
0 commit comments