@samitouri / QOSamiQemu / commits / 0d0f3f962e

intel_iommu: Export some functions

Export some functions for accel code usages. Inline functions and MACROs are moved to internal header files. Then accel code in following patches could access them. Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Reviewed-by: Clement Mathieu--Drif <clement.mathieu--drif@eviden.com> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Tested-by: Xudong Hao <xudong.hao@intel.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20260527054658.1021096-8-zhenzhong.duan@intel.com>

Zhenzhong Duan committed May 27, 2026 at 01:46 UTC 0d0f3f962eab4342b5d6314e28e7e87434ca9eff
2 files changed +40 -34
hw/i386/intel_iommu.c
+9 -34
@@ -42,12 +42,6 @@
42 #include "migration/vmstate.h"
43 #include "trace.h"
44
45 -/* context entry operations */
46 -#define VTD_CE_GET_PASID_DIR_TABLE(ce) \
47 - ((ce)->val[0] & VTD_PASID_DIR_BASE_ADDR_MASK)
48 -#define VTD_CE_GET_PRE(ce) \
49 - ((ce)->val[0] & VTD_SM_CONTEXT_ENTRY_PRE)
50 -
45 /*
46 * Paging mode for first-stage translation (VTD spec Figure 9-6)
47 * 00: 4-level paging, 01: 5-level paging
@@ -831,18 +825,12 @@ static inline bool vtd_pe_type_check(IntelIOMMUState *s, VTDPASIDEntry *pe)
825 }
826 }
827
834 -static inline bool vtd_pdire_present(VTDPASIDDirEntry *pdire)
835 -{
836 - return pdire->val & 1;
837 -}
838 -
828 /**
829 * Caller of this function should check present bit if wants
830 * to use pdir entry for further usage except for fpd bit check.
831 */
843 -static int vtd_get_pdire_from_pdir_table(dma_addr_t pasid_dir_base,
844 - uint32_t pasid,
845 - VTDPASIDDirEntry *pdire)
832 +int vtd_get_pdire_from_pdir_table(dma_addr_t pasid_dir_base, uint32_t pasid,
833 + VTDPASIDDirEntry *pdire)
834 {
835 uint32_t index;
836 dma_addr_t addr, entry_size;
@@ -860,15 +848,8 @@ static int vtd_get_pdire_from_pdir_table(dma_addr_t pasid_dir_base,
848 return 0;
849 }
850
863 -static inline bool vtd_pe_present(VTDPASIDEntry *pe)
864 -{
865 - return pe->val[0] & VTD_PASID_ENTRY_P;
866 -}
867 -
868 -static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s,
869 - uint32_t pasid,
870 - dma_addr_t addr,
871 - VTDPASIDEntry *pe)
851 +int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s, uint32_t pasid,
852 + dma_addr_t addr, VTDPASIDEntry *pe)
853 {
854 uint8_t pgtt;
855 uint32_t index;
@@ -1526,8 +1507,8 @@ static int vtd_ce_pasid_0_check(IntelIOMMUState *s, VTDContextEntry *ce)
1507 }
1508
1509 /* Map a device to its corresponding domain (context-entry) */
1529 -static int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num,
1530 - uint8_t devfn, VTDContextEntry *ce)
1510 +int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num,
1511 + uint8_t devfn, VTDContextEntry *ce)
1512 {
1513 VTDRootEntry re;
1514 int ret_fr;
@@ -1909,7 +1890,7 @@ static VTDAddressSpace *vtd_get_as_by_sid_and_pasid(IntelIOMMUState *s,
1890 vtd_find_as_by_sid_and_pasid, &key);
1891 }
1892
1912 -static VTDAddressSpace *vtd_get_as_by_sid(IntelIOMMUState *s, uint16_t sid)
1893 +VTDAddressSpace *vtd_get_as_by_sid(IntelIOMMUState *s, uint16_t sid)
1894 {
1895 return vtd_get_as_by_sid_and_pasid(s, sid, PCI_NO_PASID);
1896 }
@@ -3113,9 +3094,8 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState *s,
3094 return true;
3095 }
3096
3116 -static int vtd_dev_get_pe_from_pasid(IntelIOMMUState *s, PCIBus *bus,
3117 - uint8_t devfn, uint32_t pasid,
3118 - VTDPASIDEntry *pe)
3097 +int vtd_dev_get_pe_from_pasid(IntelIOMMUState *s, PCIBus *bus, uint8_t devfn,
3098 + uint32_t pasid, VTDPASIDEntry *pe)
3099 {
3100 VTDContextEntry ce;
3101 int ret;
@@ -3132,11 +3112,6 @@ static int vtd_dev_get_pe_from_pasid(IntelIOMMUState *s, PCIBus *bus,
3112 return vtd_ce_get_pasid_entry(s, &ce, pe, pasid);
3113 }
3114
3135 -static int vtd_pasid_entry_compare(VTDPASIDEntry *p1, VTDPASIDEntry *p2)
3136 -{
3137 - return memcmp(p1, p2, sizeof(*p1));
3138 -}
3139 -
3115 /* Update or invalidate pasid cache based on the pasid entry in guest memory. */
3116 static void vtd_pasid_cache_sync_locked(gpointer key, gpointer value,
3117 gpointer user_data)
hw/i386/intel_iommu_internal.h
+31
@@ -620,6 +620,12 @@ typedef struct VTDRootEntry VTDRootEntry;
620 #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL1 0xffffffffffe00000ULL
621 #define VTD_SM_CONTEXT_ENTRY_PRE 0x10ULL
622
623 +/* context entry operations */
624 +#define VTD_CE_GET_PASID_DIR_TABLE(ce) \
625 + ((ce)->val[0] & VTD_PASID_DIR_BASE_ADDR_MASK)
626 +#define VTD_CE_GET_PRE(ce) \
627 + ((ce)->val[0] & VTD_SM_CONTEXT_ENTRY_PRE)
628 +
629 typedef struct VTDPASIDCacheInfo {
630 uint8_t type;
631 uint16_t did;
@@ -746,4 +752,29 @@ static inline bool vtd_pe_pgtt_is_fst(VTDPASIDEntry *pe)
752 {
753 return (VTD_SM_PASID_ENTRY_PGTT(pe) == VTD_SM_PASID_ENTRY_FST);
754 }
755 +
756 +static inline bool vtd_pdire_present(VTDPASIDDirEntry *pdire)
757 +{
758 + return pdire->val & 1;
759 +}
760 +
761 +static inline bool vtd_pe_present(VTDPASIDEntry *pe)
762 +{
763 + return pe->val[0] & VTD_PASID_ENTRY_P;
764 +}
765 +
766 +static inline int vtd_pasid_entry_compare(VTDPASIDEntry *p1, VTDPASIDEntry *p2)
767 +{
768 + return memcmp(p1, p2, sizeof(*p1));
769 +}
770 +
771 +int vtd_get_pdire_from_pdir_table(dma_addr_t pasid_dir_base, uint32_t pasid,
772 + VTDPASIDDirEntry *pdire);
773 +int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s, uint32_t pasid,
774 + dma_addr_t addr, VTDPASIDEntry *pe);
775 +int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num,
776 + uint8_t devfn, VTDContextEntry *ce);
777 +VTDAddressSpace *vtd_get_as_by_sid(IntelIOMMUState *s, uint16_t sid);
778 +int vtd_dev_get_pe_from_pasid(IntelIOMMUState *s, PCIBus *bus, uint8_t devfn,
779 + uint32_t pasid, VTDPASIDEntry *pe);
780 #endif