Skip to content

Commit 8017ebd

Browse files
Shawnshhlijinxia
authored andcommitted
HV:vtd:dma change the macro to the inline function
Function like macro changed to be inline function to limit the return type and parameter type. V1->V2:change the apis to letter case. Signed-off-by: Huihuang Shi <huihuang.shi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent d8c3765 commit 8017ebd

File tree

2 files changed

+156
-53
lines changed

2 files changed

+156
-53
lines changed

hypervisor/arch/x86/vtd.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,11 @@ static void dmar_invalid_context_cache(struct dmar_drhd_rt *dmar_uint,
565565
cmd |= DMA_CCMD_GLOBAL_INVL;
566566
break;
567567
case DMAR_CIRG_DOMAIN:
568-
cmd |= DMA_CCMD_DOMAIN_INVL | DMA_CCMD_DID(did);
568+
cmd |= DMA_CCMD_DOMAIN_INVL | dma_ccmd_did(did);
569569
break;
570570
case DMAR_CIRG_DEVICE:
571-
cmd |= DMA_CCMD_DEVICE_INVL | DMA_CCMD_DID(did) |
572-
DMA_CCMD_SID(sid) | DMA_CCMD_FM(fm);
571+
cmd |= DMA_CCMD_DEVICE_INVL | dma_ccmd_did(did) |
572+
dma_ccmd_sid(sid) | dma_ccmd_fm(fm);
573573
break;
574574
default:
575575
pr_err("unknown CIRG type");
@@ -585,7 +585,7 @@ static void dmar_invalid_context_cache(struct dmar_drhd_rt *dmar_uint,
585585
IOMMU_UNLOCK(dmar_uint);
586586

587587
dev_dbg(ACRN_DBG_IOMMU, "cc invalidation granularity %d",
588-
DMA_CCMD_GET_CAIG_32(status));
588+
dma_ccmd_get_caig_32(status));
589589
}
590590

591591
static void dmar_invalid_context_cache_global(struct dmar_drhd_rt *dmar_uint)
@@ -609,11 +609,11 @@ static void dmar_invalid_iotlb(struct dmar_drhd_rt *dmar_uint,
609609
cmd |= DMA_IOTLB_GLOBAL_INVL;
610610
break;
611611
case DMAR_IIRG_DOMAIN:
612-
cmd |= DMA_IOTLB_DOMAIN_INVL | DMA_IOTLB_DID(did);
612+
cmd |= DMA_IOTLB_DOMAIN_INVL | dma_iotlb_did(did);
613613
break;
614614
case DMAR_IIRG_PAGE:
615-
cmd |= DMA_IOTLB_PAGE_INVL | DMA_IOTLB_DID(did);
616-
addr = address | DMA_IOTLB_INVL_ADDR_AM(am);
615+
cmd |= DMA_IOTLB_PAGE_INVL | dma_iotlb_did(did);
616+
addr = address | dma_iotlb_invl_addr_am(am);
617617
if (hint) {
618618
addr |= DMA_IOTLB_INVL_ADDR_IH_UNMODIFIED;
619619
}
@@ -633,7 +633,7 @@ static void dmar_invalid_iotlb(struct dmar_drhd_rt *dmar_uint,
633633
(status & DMA_IOTLB_IVT_32) == 0U, status);
634634
IOMMU_UNLOCK(dmar_uint);
635635

636-
if (DMA_IOTLB_GET_IAIG_32(status) == 0U) {
636+
if (dma_iotlb_get_iaig_32(status) == 0U) {
637637
pr_err("fail to invalidate IOTLB!, 0x%x, 0x%x",
638638
status, iommu_read32(dmar_uint, DMAR_FSTS_REG));
639639
}
@@ -705,58 +705,58 @@ static void dmar_fault_msi_write(struct dmar_drhd_rt *dmar_uint,
705705
#if DBG_IOMMU
706706
static void fault_status_analysis(uint32_t status)
707707
{
708-
if (DMA_FSTS_PFO(status)) {
708+
if (dma_fsts_pfo(status)) {
709709
pr_info("Primary Fault Overflow");
710710
}
711711

712-
if (DMA_FSTS_PPF(status)) {
712+
if (dma_fsts_ppf(status)) {
713713
pr_info("Primary Pending Fault");
714714
}
715715

716-
if (DMA_FSTS_AFO(status)) {
716+
if (dma_fsts_afo(status)) {
717717
pr_info("Advanced Fault Overflow");
718718
}
719719

720-
if (DMA_FSTS_APF(status)) {
720+
if (dma_fsts_apf(status)) {
721721
pr_info("Advanced Pending Fault");
722722
}
723723

724-
if (DMA_FSTS_IQE(status)) {
724+
if (dma_fsts_iqe(status)) {
725725
pr_info("Invalidation Queue Error");
726726
}
727727

728-
if (DMA_FSTS_ICE(status)) {
728+
if (dma_fsts_ice(status)) {
729729
pr_info("Invalidation Completion Error");
730730
}
731731

732-
if (DMA_FSTS_ITE(status)) {
732+
if (dma_fsts_ite(status)) {
733733
pr_info("Invalidation Time-out Error");
734734
}
735735

736-
if (DMA_FSTS_PRO(status)) {
736+
if (dma_fsts_pro(status)) {
737737
pr_info("Page Request Overflow");
738738
}
739739
}
740740
#endif
741741

742742
static void fault_record_analysis(__unused uint64_t low, uint64_t high)
743743
{
744-
if (DMA_FRCD_UP_F(high) == 0U) {
744+
if (dma_frcd_up_f(high)) {
745745
return;
746746
}
747747

748748
/* currently skip PASID related parsing */
749749
pr_info("%s, Reason: 0x%x, SID: %x.%x.%x @0x%llx",
750-
(DMA_FRCD_UP_T(high) != 0U) ? "Read/Atomic" : "Write",
751-
DMA_FRCD_UP_FR(high),
752-
DMA_FRCD_UP_SID(high) >> 8,
753-
(DMA_FRCD_UP_SID(high) >> 3) & 0x1fUL,
754-
DMA_FRCD_UP_SID(high) & 0x7UL,
750+
dma_frcd_up_t(high) ? "Read/Atomic" : "Write",
751+
dma_frcd_up_fr(high),
752+
dma_frcd_up_sid(high) >> 8,
753+
(dma_frcd_up_sid(high) >> 3) & 0x1fUL,
754+
dma_frcd_up_sid(high) & 0x7UL,
755755
low);
756756
#if DBG_IOMMU
757757
if (iommu_ecap_dt(dmar_uint->ecap)i != 0U) {
758758
pr_info("Address Type: 0x%x",
759-
DMA_FRCD_UP_AT(high));
759+
dma_frcd_up_at(high));
760760
}
761761
#endif
762762
}
@@ -778,9 +778,9 @@ static int dmar_fault_handler(int irq, void *data)
778778
fault_status_analysis(fsr);
779779
#endif
780780

781-
while (DMA_FSTS_PPF(fsr) != 0U) {
781+
while (dma_fsts_ppf(fsr)) {
782782
loop++;
783-
index = DMA_FSTS_FRI(fsr);
783+
index = dma_fsts_fri(fsr);
784784
record_reg_offset = dmar_uint->cap_fault_reg_offset
785785
+ index * 16;
786786
if (index >= dmar_uint->cap_num_fault_regs) {

hypervisor/include/arch/x86/vtd.h

Lines changed: 131 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@
3535
#define DMAR_ICS_REG 0x9cU /* Invalidation complete status register */
3636
#define DMAR_IRTA_REG 0xb8U /* Interrupt remapping table addr register */
3737

38-
#define DMAR_VER_MAJOR(v) (((v) & 0xf0U) >> 4)
39-
#define DMAR_VER_MINOR(v) ((v) & 0x0fU)
38+
static inline uint8_t dmar_ver_major(uint64_t version)
39+
{
40+
return ((version & 0xf0UL) >> 4U);
41+
}
42+
43+
static inline uint8_t dmar_ver_minor(uint64_t version)
44+
{
45+
return (version & 0x0fUL);
46+
}
4047

4148
/*
4249
* Decoding Capability Register
@@ -282,14 +289,30 @@ static inline uint8_t iommu_ecap_pds(uint64_t ecap)
282289
#define DMA_CCMD_GLOBAL_INVL (((uint64_t)1UL) << 61)
283290
#define DMA_CCMD_DOMAIN_INVL (((uint64_t)2UL) << 61)
284291
#define DMA_CCMD_DEVICE_INVL (((uint64_t)3UL) << 61)
285-
#define DMA_CCMD_FM(m) (((uint64_t)((m) & 0x3UL)) << 32)
292+
static inline uint64_t dma_ccmd_fm(uint8_t fm)
293+
{
294+
return (((uint64_t)(fm & 0x3U)) << 32U);
295+
}
296+
286297
#define DMA_CCMD_MASK_NOBIT 0UL
287298
#define DMA_CCMD_MASK_1BIT 1UL
288299
#define DMA_CCMD_MASK_2BIT 2UL
289300
#define DMA_CCMD_MASK_3BIT 3UL
290-
#define DMA_CCMD_SID(s) (((uint64_t)((s) & 0xffffUL)) << 16)
291-
#define DMA_CCMD_DID(d) ((uint64_t)((d) & 0xffffUL))
292-
#define DMA_CCMD_GET_CAIG_32(v) (((uint32_t)(v) >> 27) & 0x3U)
301+
static inline uint64_t dma_ccmd_sid(uint16_t sid)
302+
{
303+
return (((uint64_t)(sid & 0xffffU)) << 16U);
304+
}
305+
306+
static inline uint16_t dma_ccmd_did(uint16_t did)
307+
{
308+
return (did & 0xffffU);
309+
}
310+
311+
static inline uint8_t dma_ccmd_get_caig_32(uint32_t gaig)
312+
{
313+
return ((gaig >> 27U) & 0x3U);
314+
}
315+
293316

294317
/* IOTLB_REG */
295318
#define DMA_IOTLB_IVT (((uint64_t)1UL) << 63)
@@ -299,38 +322,118 @@ static inline uint8_t iommu_ecap_pds(uint64_t ecap)
299322
#define DMA_IOTLB_PAGE_INVL (((uint64_t)3UL) << 60)
300323
#define DMA_IOTLB_DR (((uint64_t)1UL) << 49)
301324
#define DMA_IOTLB_DW (((uint64_t)1UL) << 48)
302-
#define DMA_IOTLB_DID(d) \
303-
(((uint64_t)((d) & 0xffffUL)) << 32)
304-
#define DMA_IOTLB_GET_IAIG_32(v) (((uint32_t)(v) >> 25) & 0x3U)
325+
static inline uint64_t dma_iotlb_did(uint16_t did)
326+
{
327+
return (((uint64_t)(did & 0xffffU)) << 32U);
328+
}
329+
330+
static inline uint8_t dma_iotlb_get_iaig_32(uint32_t iai)
331+
{
332+
return ((iai >> 25U) & 0x3U);
333+
}
305334

306335
/* INVALIDATE_ADDRESS_REG */
307-
#define DMA_IOTLB_INVL_ADDR_AM(m) ((uint64_t)((m) & 0x3fUL))
336+
static inline uint8_t dma_iotlb_invl_addr_am(uint8_t am)
337+
{
338+
return (am & 0x3fU);
339+
}
340+
308341
#define DMA_IOTLB_INVL_ADDR_IH_UNMODIFIED (((uint64_t)1UL) << 6)
309342

310343
/* FECTL_REG */
311344
#define DMA_FECTL_IM (((uint32_t)1U) << 31)
312345

313346
/* FSTS_REG */
314-
#define DMA_FSTS_PFO(s) (((s) >> 0) & 1U)
315-
#define DMA_FSTS_PPF(s) (((s) >> 1) & 1U)
316-
#define DMA_FSTS_AFO(s) (((s) >> 2) & 1U)
317-
#define DMA_FSTS_APF(s) (((s) >> 3) & 1U)
318-
#define DMA_FSTS_IQE(s) (((s) >> 4) & 1U)
319-
#define DMA_FSTS_ICE(s) (((s) >> 5) & 1U)
320-
#define DMA_FSTS_ITE(s) (((s) >> 6) & 1U)
321-
#define DMA_FSTS_PRO(s) (((s) >> 7) & 1U)
322-
#define DMA_FSTS_FRI(s) (((s) >> 8) & 0xFFU)
347+
static inline bool dma_fsts_pfo(uint32_t PFO)
348+
{
349+
return ((PFO >> 0U) & 1U) == 1U;
350+
}
351+
352+
static inline bool dma_fsts_ppf(uint32_t PPF)
353+
{
354+
return ((PPF >> 1U) & 1U) == 1U;
355+
}
356+
357+
static inline bool dma_fsts_afo(uint32_t AFO)
358+
{
359+
return ((AFO >> 2U) & 1U) == 1U;
360+
}
361+
362+
static inline bool dma_fsts_apf(uint32_t APF)
363+
{
364+
return ((APF >> 3U) & 1U) == 1U;
365+
}
366+
367+
static inline bool dma_fsts_iqe(uint32_t IQE)
368+
{
369+
return ((IQE >> 4U) & 1U) == 1U;
370+
}
371+
372+
static inline bool dma_fsts_ice(uint32_t ICE)
373+
{
374+
return ((ICE >> 5U) & 1U) == 1U;
375+
}
376+
377+
static inline bool dma_fsts_ite(uint32_t ITE)
378+
{
379+
return ((ITE >> 6U) & 1U) == 1U;
380+
}
381+
382+
static inline bool dma_fsts_pro(uint32_t PRO)
383+
{
384+
return ((PRO >> 7U) & 1U) == 1U;
385+
}
386+
387+
static inline uint8_t dma_fsts_fri(uint32_t FRI)
388+
{
389+
return ((FRI >> 8U) & 0xFFU);
390+
}
323391

324392
/* FRCD_REGs: upper 64 bits*/
325-
#define DMA_FRCD_UP_F(r) (((r) >> 63) & 1UL)
326-
#define DMA_FRCD_UP_T(r) (((r) >> 62) & 1UL)
327-
#define DMA_FRCD_UP_AT(r) (((r) >> 60) & 3UL)
328-
#define DMA_FRCD_UP_PASID(r) (((r) >> 40) & 0xfffffUL)
329-
#define DMA_FRCD_UP_FR(r) (((r) >> 32) & 0xffUL)
330-
#define DMA_FRCD_UP_PP(r) (((r) >> 31) & 1UL)
331-
#define DMA_FRCD_UP_EXE(r) (((r) >> 30) & 1UL)
332-
#define DMA_FRCD_UP_PRIV(r) (((r) >> 29) & 1UL)
333-
#define DMA_FRCD_UP_SID(r) (((r) >> 0) & 0xffffUL)
393+
static inline bool dma_frcd_up_f(uint64_t UP_F)
394+
{
395+
return ((UP_F >> 63U) & 1UL) == 1UL;
396+
}
397+
398+
static inline uint8_t dma_frcd_up_t(uint64_t UP_T)
399+
{
400+
return ((UP_T >> 62U) & 1UL);
401+
}
402+
403+
static inline uint8_t dma_frcd_up_at(uint64_t UP_AT)
404+
{
405+
return ((UP_AT >> 60U) & 3UL);
406+
}
407+
408+
static inline uint32_t dma_frcd_up_pasid(uint64_t UP_PASID)
409+
{
410+
return ((UP_PASID >> 40U) & 0xfffffUL);
411+
}
412+
413+
static inline uint8_t dma_frcd_up_fr(uint64_t UP_FR)
414+
{
415+
return ((UP_FR >> 32U) & 0xffUL);
416+
}
417+
418+
static inline bool dma_frcd_up_pp(uint64_t UP_PP)
419+
{
420+
return ((UP_PP >> 31U) & 1UL) == 1UL;
421+
}
422+
423+
static inline bool dma_frcd_up_exe(uint64_t UP_EXE)
424+
{
425+
return ((UP_EXE >> 30U) & 1UL) == 1UL;
426+
}
427+
428+
static inline bool dma_frcd_up_priv(uint64_t UP_PRIV)
429+
{
430+
return ((UP_PRIV >> 29U) & 1UL) == 1UL;
431+
}
432+
433+
static inline uint32_t dma_frcd_up_sid(uint64_t UP_SID)
434+
{
435+
return ((UP_SID >> 0U) & 0xffffUL);
436+
}
334437

335438
#define DMAR_CONTEXT_TRANSLATION_TYPE_TRANSLATED 0x00U
336439
#define DMAR_CONTEXT_TRANSLATION_TYPE_RESERVED 0x01U

0 commit comments

Comments
 (0)