1 // SPDX-License-Identifier: GPL-2.0
3 * intel-pasid.c - PASID idr, table and entry manipulation
5 * Copyright (C) 2018 Intel Corporation
7 * Author: Lu Baolu <baolu.lu@linux.intel.com>
10 #define pr_fmt(fmt) "DMAR: " fmt
12 #include <linux/bitops.h>
13 #include <linux/cpufeature.h>
14 #include <linux/dmar.h>
15 #include <linux/intel-iommu.h>
16 #include <linux/iommu.h>
17 #include <linux/memory.h>
18 #include <linux/pci.h>
19 #include <linux/pci-ats.h>
20 #include <linux/spinlock.h>
25 * Intel IOMMU system wide PASID name space:
27 u32 intel_pasid_max_id = PASID_MAX;
29 int vcmd_alloc_pasid(struct intel_iommu *iommu, u32 *pasid)
36 raw_spin_lock_irqsave(&iommu->register_lock, flags);
37 dmar_writeq(iommu->reg + DMAR_VCMD_REG, VCMD_CMD_ALLOC);
38 IOMMU_WAIT_OP(iommu, DMAR_VCRSP_REG, dmar_readq,
39 !(res & VCMD_VRSP_IP), res);
40 raw_spin_unlock_irqrestore(&iommu->register_lock, flags);
42 status_code = VCMD_VRSP_SC(res);
43 switch (status_code) {
44 case VCMD_VRSP_SC_SUCCESS:
45 *pasid = VCMD_VRSP_RESULT_PASID(res);
47 case VCMD_VRSP_SC_NO_PASID_AVAIL:
48 pr_info("IOMMU: %s: No PASID available\n", iommu->name);
53 pr_warn("IOMMU: %s: Unexpected error code %d\n",
54 iommu->name, status_code);
60 void vcmd_free_pasid(struct intel_iommu *iommu, u32 pasid)
66 raw_spin_lock_irqsave(&iommu->register_lock, flags);
67 dmar_writeq(iommu->reg + DMAR_VCMD_REG,
68 VCMD_CMD_OPERAND(pasid) | VCMD_CMD_FREE);
69 IOMMU_WAIT_OP(iommu, DMAR_VCRSP_REG, dmar_readq,
70 !(res & VCMD_VRSP_IP), res);
71 raw_spin_unlock_irqrestore(&iommu->register_lock, flags);
73 status_code = VCMD_VRSP_SC(res);
74 switch (status_code) {
75 case VCMD_VRSP_SC_SUCCESS:
77 case VCMD_VRSP_SC_INVALID_PASID:
78 pr_info("IOMMU: %s: Invalid PASID\n", iommu->name);
81 pr_warn("IOMMU: %s: Unexpected error code %d\n",
82 iommu->name, status_code);
87 * Per device pasid table management:
90 device_attach_pasid_table(struct device_domain_info *info,
91 struct pasid_table *pasid_table)
93 info->pasid_table = pasid_table;
94 list_add(&info->table, &pasid_table->dev);
98 device_detach_pasid_table(struct device_domain_info *info,
99 struct pasid_table *pasid_table)
101 info->pasid_table = NULL;
102 list_del(&info->table);
105 struct pasid_table_opaque {
106 struct pasid_table **pasid_table;
112 static int search_pasid_table(struct device_domain_info *info, void *opaque)
114 struct pasid_table_opaque *data = opaque;
116 if (info->iommu->segment == data->segment &&
117 info->bus == data->bus &&
118 info->devfn == data->devfn &&
120 *data->pasid_table = info->pasid_table;
127 static int get_alias_pasid_table(struct pci_dev *pdev, u16 alias, void *opaque)
129 struct pasid_table_opaque *data = opaque;
131 data->segment = pci_domain_nr(pdev->bus);
132 data->bus = PCI_BUS_NUM(alias);
133 data->devfn = alias & 0xff;
135 return for_each_device_domain(&search_pasid_table, data);
139 * Allocate a pasid table for @dev. It should be called in a
140 * single-thread context.
142 int intel_pasid_alloc_table(struct device *dev)
144 struct device_domain_info *info;
145 struct pasid_table *pasid_table;
146 struct pasid_table_opaque data;
153 info = get_domain_info(dev);
154 if (WARN_ON(!info || !dev_is_pci(dev) || info->pasid_table))
157 /* DMA alias device already has a pasid table, use it: */
158 data.pasid_table = &pasid_table;
159 ret = pci_for_each_dma_alias(to_pci_dev(dev),
160 &get_alias_pasid_table, &data);
164 pasid_table = kzalloc(sizeof(*pasid_table), GFP_KERNEL);
167 INIT_LIST_HEAD(&pasid_table->dev);
169 if (info->pasid_supported)
170 max_pasid = min_t(u32, pci_max_pasids(to_pci_dev(dev)),
173 size = max_pasid >> (PASID_PDE_SHIFT - 3);
174 order = size ? get_order(size) : 0;
175 pages = alloc_pages_node(info->iommu->node,
176 GFP_KERNEL | __GFP_ZERO, order);
182 pasid_table->table = page_address(pages);
183 pasid_table->order = order;
184 pasid_table->max_pasid = 1 << (order + PAGE_SHIFT + 3);
187 device_attach_pasid_table(info, pasid_table);
192 void intel_pasid_free_table(struct device *dev)
194 struct device_domain_info *info;
195 struct pasid_table *pasid_table;
196 struct pasid_dir_entry *dir;
197 struct pasid_entry *table;
200 info = get_domain_info(dev);
201 if (!info || !dev_is_pci(dev) || !info->pasid_table)
204 pasid_table = info->pasid_table;
205 device_detach_pasid_table(info, pasid_table);
207 if (!list_empty(&pasid_table->dev))
210 /* Free scalable mode PASID directory tables: */
211 dir = pasid_table->table;
212 max_pde = pasid_table->max_pasid >> PASID_PDE_SHIFT;
213 for (i = 0; i < max_pde; i++) {
214 table = get_pasid_table_from_pde(&dir[i]);
215 free_pgtable_page(table);
218 free_pages((unsigned long)pasid_table->table, pasid_table->order);
222 struct pasid_table *intel_pasid_get_table(struct device *dev)
224 struct device_domain_info *info;
226 info = get_domain_info(dev);
230 return info->pasid_table;
233 static int intel_pasid_get_dev_max_id(struct device *dev)
235 struct device_domain_info *info;
237 info = get_domain_info(dev);
238 if (!info || !info->pasid_table)
241 return info->pasid_table->max_pasid;
244 static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid)
246 struct device_domain_info *info;
247 struct pasid_table *pasid_table;
248 struct pasid_dir_entry *dir;
249 struct pasid_entry *entries;
250 int dir_index, index;
252 pasid_table = intel_pasid_get_table(dev);
253 if (WARN_ON(!pasid_table || pasid >= intel_pasid_get_dev_max_id(dev)))
256 dir = pasid_table->table;
257 info = get_domain_info(dev);
258 dir_index = pasid >> PASID_PDE_SHIFT;
259 index = pasid & PASID_PTE_MASK;
262 entries = get_pasid_table_from_pde(&dir[dir_index]);
264 entries = alloc_pgtable_page(info->iommu->node);
269 * The pasid directory table entry won't be freed after
270 * allocation. No worry about the race with free and
271 * clear. However, this entry might be populated by others
272 * while we are preparing it. Use theirs with a retry.
274 if (cmpxchg64(&dir[dir_index].val, 0ULL,
275 (u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) {
276 free_pgtable_page(entries);
281 return &entries[index];
285 * Interfaces for PASID table entry manipulation:
287 static inline void pasid_clear_entry(struct pasid_entry *pe)
289 WRITE_ONCE(pe->val[0], 0);
290 WRITE_ONCE(pe->val[1], 0);
291 WRITE_ONCE(pe->val[2], 0);
292 WRITE_ONCE(pe->val[3], 0);
293 WRITE_ONCE(pe->val[4], 0);
294 WRITE_ONCE(pe->val[5], 0);
295 WRITE_ONCE(pe->val[6], 0);
296 WRITE_ONCE(pe->val[7], 0);
299 static inline void pasid_clear_entry_with_fpd(struct pasid_entry *pe)
301 WRITE_ONCE(pe->val[0], PASID_PTE_FPD);
302 WRITE_ONCE(pe->val[1], 0);
303 WRITE_ONCE(pe->val[2], 0);
304 WRITE_ONCE(pe->val[3], 0);
305 WRITE_ONCE(pe->val[4], 0);
306 WRITE_ONCE(pe->val[5], 0);
307 WRITE_ONCE(pe->val[6], 0);
308 WRITE_ONCE(pe->val[7], 0);
312 intel_pasid_clear_entry(struct device *dev, u32 pasid, bool fault_ignore)
314 struct pasid_entry *pe;
316 pe = intel_pasid_get_entry(dev, pasid);
320 if (fault_ignore && pasid_pte_is_present(pe))
321 pasid_clear_entry_with_fpd(pe);
323 pasid_clear_entry(pe);
326 static inline void pasid_set_bits(u64 *ptr, u64 mask, u64 bits)
330 old = READ_ONCE(*ptr);
331 WRITE_ONCE(*ptr, (old & ~mask) | bits);
335 * Setup the DID(Domain Identifier) field (Bit 64~79) of scalable mode
339 pasid_set_domain_id(struct pasid_entry *pe, u64 value)
341 pasid_set_bits(&pe->val[1], GENMASK_ULL(15, 0), value);
345 * Get domain ID value of a scalable mode PASID entry.
348 pasid_get_domain_id(struct pasid_entry *pe)
350 return (u16)(READ_ONCE(pe->val[1]) & GENMASK_ULL(15, 0));
354 * Setup the SLPTPTR(Second Level Page Table Pointer) field (Bit 12~63)
355 * of a scalable mode PASID entry.
358 pasid_set_slptr(struct pasid_entry *pe, u64 value)
360 pasid_set_bits(&pe->val[0], VTD_PAGE_MASK, value);
364 * Setup the AW(Address Width) field (Bit 2~4) of a scalable mode PASID
368 pasid_set_address_width(struct pasid_entry *pe, u64 value)
370 pasid_set_bits(&pe->val[0], GENMASK_ULL(4, 2), value << 2);
374 * Setup the PGTT(PASID Granular Translation Type) field (Bit 6~8)
375 * of a scalable mode PASID entry.
378 pasid_set_translation_type(struct pasid_entry *pe, u64 value)
380 pasid_set_bits(&pe->val[0], GENMASK_ULL(8, 6), value << 6);
384 * Enable fault processing by clearing the FPD(Fault Processing
385 * Disable) field (Bit 1) of a scalable mode PASID entry.
387 static inline void pasid_set_fault_enable(struct pasid_entry *pe)
389 pasid_set_bits(&pe->val[0], 1 << 1, 0);
393 * Setup the SRE(Supervisor Request Enable) field (Bit 128) of a
394 * scalable mode PASID entry.
396 static inline void pasid_set_sre(struct pasid_entry *pe)
398 pasid_set_bits(&pe->val[2], 1 << 0, 1);
402 * Setup the WPE(Write Protect Enable) field (Bit 132) of a
403 * scalable mode PASID entry.
405 static inline void pasid_set_wpe(struct pasid_entry *pe)
407 pasid_set_bits(&pe->val[2], 1 << 4, 1 << 4);
411 * Setup the P(Present) field (Bit 0) of a scalable mode PASID
414 static inline void pasid_set_present(struct pasid_entry *pe)
416 pasid_set_bits(&pe->val[0], 1 << 0, 1);
420 * Setup Page Walk Snoop bit (Bit 87) of a scalable mode PASID
423 static inline void pasid_set_page_snoop(struct pasid_entry *pe, bool value)
425 pasid_set_bits(&pe->val[1], 1 << 23, value << 23);
429 * Setup the Page Snoop (PGSNP) field (Bit 88) of a scalable mode
433 pasid_set_pgsnp(struct pasid_entry *pe)
435 pasid_set_bits(&pe->val[1], 1ULL << 24, 1ULL << 24);
439 * Setup the First Level Page table Pointer field (Bit 140~191)
440 * of a scalable mode PASID entry.
443 pasid_set_flptr(struct pasid_entry *pe, u64 value)
445 pasid_set_bits(&pe->val[2], VTD_PAGE_MASK, value);
449 * Setup the First Level Paging Mode field (Bit 130~131) of a
450 * scalable mode PASID entry.
453 pasid_set_flpm(struct pasid_entry *pe, u64 value)
455 pasid_set_bits(&pe->val[2], GENMASK_ULL(3, 2), value << 2);
459 * Setup the Extended Access Flag Enable (EAFE) field (Bit 135)
460 * of a scalable mode PASID entry.
463 pasid_set_eafe(struct pasid_entry *pe)
465 pasid_set_bits(&pe->val[2], 1 << 7, 1 << 7);
469 pasid_cache_invalidation_with_pasid(struct intel_iommu *iommu,
474 desc.qw0 = QI_PC_DID(did) | QI_PC_GRAN(QI_PC_PASID_SEL) |
475 QI_PC_PASID(pasid) | QI_PC_TYPE;
480 qi_submit_sync(iommu, &desc, 1, 0);
484 devtlb_invalidation_with_pasid(struct intel_iommu *iommu,
485 struct device *dev, u32 pasid)
487 struct device_domain_info *info;
488 u16 sid, qdep, pfsid;
490 info = get_domain_info(dev);
491 if (!info || !info->ats_enabled)
494 sid = info->bus << 8 | info->devfn;
495 qdep = info->ats_qdep;
499 * When PASID 0 is used, it indicates RID2PASID(DMA request w/o PASID),
500 * devTLB flush w/o PASID should be used. For non-zero PASID under
501 * SVA usage, device could do DMA with multiple PASIDs. It is more
502 * efficient to flush devTLB specific to the PASID.
504 if (pasid == PASID_RID2PASID)
505 qi_flush_dev_iotlb(iommu, sid, pfsid, qdep, 0, 64 - VTD_PAGE_SHIFT);
507 qi_flush_dev_iotlb_pasid(iommu, sid, pfsid, pasid, qdep, 0, 64 - VTD_PAGE_SHIFT);
510 void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,
511 u32 pasid, bool fault_ignore)
513 struct pasid_entry *pte;
516 pte = intel_pasid_get_entry(dev, pasid);
520 if (!pasid_pte_is_present(pte))
523 did = pasid_get_domain_id(pte);
524 pgtt = pasid_pte_get_pgtt(pte);
526 intel_pasid_clear_entry(dev, pasid, fault_ignore);
528 if (!ecap_coherent(iommu->ecap))
529 clflush_cache_range(pte, sizeof(*pte));
531 pasid_cache_invalidation_with_pasid(iommu, did, pasid);
533 if (pgtt == PASID_ENTRY_PGTT_PT || pgtt == PASID_ENTRY_PGTT_FL_ONLY)
534 qi_flush_piotlb(iommu, did, pasid, 0, -1, 0);
536 iommu->flush.flush_iotlb(iommu, did, 0, 0, DMA_TLB_DSI_FLUSH);
538 /* Device IOTLB doesn't need to be flushed in caching mode. */
539 if (!cap_caching_mode(iommu->cap))
540 devtlb_invalidation_with_pasid(iommu, dev, pasid);
544 * This function flushes cache for a newly setup pasid table entry.
545 * Caller of it should not modify the in-use pasid table entries.
547 static void pasid_flush_caches(struct intel_iommu *iommu,
548 struct pasid_entry *pte,
551 if (!ecap_coherent(iommu->ecap))
552 clflush_cache_range(pte, sizeof(*pte));
554 if (cap_caching_mode(iommu->cap)) {
555 pasid_cache_invalidation_with_pasid(iommu, did, pasid);
556 qi_flush_piotlb(iommu, did, pasid, 0, -1, 0);
558 iommu_flush_write_buffer(iommu);
562 static inline int pasid_enable_wpe(struct pasid_entry *pte)
565 unsigned long cr0 = read_cr0();
567 /* CR0.WP is normally set but just to be sure */
568 if (unlikely(!(cr0 & X86_CR0_WP))) {
569 pr_err_ratelimited("No CPU write protect!\n");
579 * Set up the scalable mode pasid table entry for first only
582 int intel_pasid_setup_first_level(struct intel_iommu *iommu,
583 struct device *dev, pgd_t *pgd,
584 u32 pasid, u16 did, int flags)
586 struct pasid_entry *pte;
588 if (!ecap_flts(iommu->ecap)) {
589 pr_err("No first level translation support on %s\n",
594 pte = intel_pasid_get_entry(dev, pasid);
598 /* Caller must ensure PASID entry is not in use. */
599 if (pasid_pte_is_present(pte))
602 pasid_clear_entry(pte);
604 /* Setup the first level page table pointer: */
605 pasid_set_flptr(pte, (u64)__pa(pgd));
606 if (flags & PASID_FLAG_SUPERVISOR_MODE) {
607 if (!ecap_srs(iommu->ecap)) {
608 pr_err("No supervisor request support on %s\n",
613 if (pasid_enable_wpe(pte))
618 if (flags & PASID_FLAG_FL5LP) {
619 if (cap_5lp_support(iommu->cap)) {
620 pasid_set_flpm(pte, 1);
622 pr_err("No 5-level paging support for first-level\n");
623 pasid_clear_entry(pte);
628 if (flags & PASID_FLAG_PAGE_SNOOP)
629 pasid_set_pgsnp(pte);
631 pasid_set_domain_id(pte, did);
632 pasid_set_address_width(pte, iommu->agaw);
633 pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
635 /* Setup Present and PASID Granular Transfer Type: */
636 pasid_set_translation_type(pte, PASID_ENTRY_PGTT_FL_ONLY);
637 pasid_set_present(pte);
638 pasid_flush_caches(iommu, pte, pasid, did);
644 * Skip top levels of page tables for iommu which has less agaw
645 * than default. Unnecessary for PT mode.
647 static inline int iommu_skip_agaw(struct dmar_domain *domain,
648 struct intel_iommu *iommu,
649 struct dma_pte **pgd)
653 for (agaw = domain->agaw; agaw > iommu->agaw; agaw--) {
654 *pgd = phys_to_virt(dma_pte_addr(*pgd));
655 if (!dma_pte_present(*pgd))
663 * Set up the scalable mode pasid entry for second only translation type.
665 int intel_pasid_setup_second_level(struct intel_iommu *iommu,
666 struct dmar_domain *domain,
667 struct device *dev, u32 pasid)
669 struct pasid_entry *pte;
676 * If hardware advertises no support for second level
677 * translation, return directly.
679 if (!ecap_slts(iommu->ecap)) {
680 pr_err("No second level translation support on %s\n",
686 agaw = iommu_skip_agaw(domain, iommu, &pgd);
688 dev_err(dev, "Invalid domain page table\n");
692 pgd_val = virt_to_phys(pgd);
693 did = domain->iommu_did[iommu->seq_id];
695 pte = intel_pasid_get_entry(dev, pasid);
697 dev_err(dev, "Failed to get pasid entry of PASID %d\n", pasid);
701 /* Caller must ensure PASID entry is not in use. */
702 if (pasid_pte_is_present(pte))
705 pasid_clear_entry(pte);
706 pasid_set_domain_id(pte, did);
707 pasid_set_slptr(pte, pgd_val);
708 pasid_set_address_width(pte, agaw);
709 pasid_set_translation_type(pte, PASID_ENTRY_PGTT_SL_ONLY);
710 pasid_set_fault_enable(pte);
711 pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
713 if (domain->domain.type == IOMMU_DOMAIN_UNMANAGED)
714 pasid_set_pgsnp(pte);
717 * Since it is a second level only translation setup, we should
718 * set SRE bit as well (addresses are expected to be GPAs).
720 if (pasid != PASID_RID2PASID)
722 pasid_set_present(pte);
723 pasid_flush_caches(iommu, pte, pasid, did);
729 * Set up the scalable mode pasid entry for passthrough translation type.
731 int intel_pasid_setup_pass_through(struct intel_iommu *iommu,
732 struct dmar_domain *domain,
733 struct device *dev, u32 pasid)
735 u16 did = FLPT_DEFAULT_DID;
736 struct pasid_entry *pte;
738 pte = intel_pasid_get_entry(dev, pasid);
740 dev_err(dev, "Failed to get pasid entry of PASID %d\n", pasid);
744 /* Caller must ensure PASID entry is not in use. */
745 if (pasid_pte_is_present(pte))
748 pasid_clear_entry(pte);
749 pasid_set_domain_id(pte, did);
750 pasid_set_address_width(pte, iommu->agaw);
751 pasid_set_translation_type(pte, PASID_ENTRY_PGTT_PT);
752 pasid_set_fault_enable(pte);
753 pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
756 * We should set SRE bit as well since the addresses are expected
760 pasid_set_present(pte);
761 pasid_flush_caches(iommu, pte, pasid, did);
767 intel_pasid_setup_bind_data(struct intel_iommu *iommu, struct pasid_entry *pte,
768 struct iommu_gpasid_bind_data_vtd *pasid_data)
771 * Not all guest PASID table entry fields are passed down during bind,
772 * here we only set up the ones that are dependent on guest settings.
773 * Execution related bits such as NXE, SMEP are not supported.
774 * Other fields, such as snoop related, are set based on host needs
775 * regardless of guest settings.
777 if (pasid_data->flags & IOMMU_SVA_VTD_GPASID_SRE) {
778 if (!ecap_srs(iommu->ecap)) {
779 pr_err_ratelimited("No supervisor request support on %s\n",
784 /* Enable write protect WP if guest requested */
785 if (pasid_data->flags & IOMMU_SVA_VTD_GPASID_WPE)
789 if (pasid_data->flags & IOMMU_SVA_VTD_GPASID_EAFE) {
790 if (!ecap_eafs(iommu->ecap)) {
791 pr_err_ratelimited("No extended access flag support on %s\n",
799 * Memory type is only applicable to devices inside processor coherent
800 * domain. Will add MTS support once coherent devices are available.
802 if (pasid_data->flags & IOMMU_SVA_VTD_GPASID_MTS_MASK) {
803 pr_warn_ratelimited("No memory type support %s\n",
812 * intel_pasid_setup_nested() - Set up PASID entry for nested translation.
813 * This could be used for guest shared virtual address. In this case, the
814 * first level page tables are used for GVA-GPA translation in the guest,
815 * second level page tables are used for GPA-HPA translation.
817 * @iommu: IOMMU which the device belong to
818 * @dev: Device to be set up for translation
819 * @gpgd: FLPTPTR: First Level Page translation pointer in GPA
820 * @pasid: PASID to be programmed in the device PASID table
821 * @pasid_data: Additional PASID info from the guest bind request
822 * @domain: Domain info for setting up second level page tables
823 * @addr_width: Address width of the first level (guest)
825 int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev,
826 pgd_t *gpgd, u32 pasid,
827 struct iommu_gpasid_bind_data_vtd *pasid_data,
828 struct dmar_domain *domain, int addr_width)
830 struct pasid_entry *pte;
837 if (!ecap_nest(iommu->ecap)) {
838 pr_err_ratelimited("IOMMU: %s: No nested translation support\n",
843 if (!(domain->flags & DOMAIN_FLAG_NESTING_MODE)) {
844 pr_err_ratelimited("Domain is not in nesting mode, %x\n",
849 pte = intel_pasid_get_entry(dev, pasid);
854 * Caller must ensure PASID entry is not in use, i.e. not bind the
855 * same PASID to the same device twice.
857 if (pasid_pte_is_present(pte))
860 pasid_clear_entry(pte);
862 /* Sanity checking performed by caller to make sure address
863 * width matching in two dimensions:
867 switch (addr_width) {
869 case ADDR_WIDTH_5LEVEL:
870 if (!cpu_feature_enabled(X86_FEATURE_LA57) ||
871 !cap_5lp_support(iommu->cap)) {
872 dev_err_ratelimited(dev,
873 "5-level paging not supported\n");
877 pasid_set_flpm(pte, 1);
880 case ADDR_WIDTH_4LEVEL:
881 pasid_set_flpm(pte, 0);
884 dev_err_ratelimited(dev, "Invalid guest address width %d\n",
889 /* First level PGD is in GPA, must be supported by the second level */
890 if ((uintptr_t)gpgd > domain->max_addr) {
891 dev_err_ratelimited(dev,
892 "Guest PGD %lx not supported, max %llx\n",
893 (uintptr_t)gpgd, domain->max_addr);
896 pasid_set_flptr(pte, (uintptr_t)gpgd);
898 ret = intel_pasid_setup_bind_data(iommu, pte, pasid_data);
902 /* Setup the second level based on the given domain */
905 agaw = iommu_skip_agaw(domain, iommu, &pgd);
907 dev_err_ratelimited(dev, "Invalid domain page table\n");
910 pgd_val = virt_to_phys(pgd);
911 pasid_set_slptr(pte, pgd_val);
912 pasid_set_fault_enable(pte);
914 did = domain->iommu_did[iommu->seq_id];
915 pasid_set_domain_id(pte, did);
917 pasid_set_address_width(pte, agaw);
918 pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap));
920 pasid_set_translation_type(pte, PASID_ENTRY_PGTT_NESTED);
921 pasid_set_present(pte);
922 pasid_flush_caches(iommu, pte, pasid, did);