162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright © 2006-2015, Intel Corporation. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Authors: Ashok Raj <ashok.raj@intel.com> 662306a36Sopenharmony_ci * Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> 762306a36Sopenharmony_ci * David Woodhouse <David.Woodhouse@intel.com> 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#ifndef _INTEL_IOMMU_H_ 1162306a36Sopenharmony_ci#define _INTEL_IOMMU_H_ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include <linux/types.h> 1462306a36Sopenharmony_ci#include <linux/iova.h> 1562306a36Sopenharmony_ci#include <linux/io.h> 1662306a36Sopenharmony_ci#include <linux/idr.h> 1762306a36Sopenharmony_ci#include <linux/mmu_notifier.h> 1862306a36Sopenharmony_ci#include <linux/list.h> 1962306a36Sopenharmony_ci#include <linux/iommu.h> 2062306a36Sopenharmony_ci#include <linux/io-64-nonatomic-lo-hi.h> 2162306a36Sopenharmony_ci#include <linux/dmar.h> 2262306a36Sopenharmony_ci#include <linux/bitfield.h> 2362306a36Sopenharmony_ci#include <linux/xarray.h> 2462306a36Sopenharmony_ci#include <linux/perf_event.h> 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#include <asm/cacheflush.h> 2762306a36Sopenharmony_ci#include <asm/iommu.h> 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* 3062306a36Sopenharmony_ci * VT-d hardware uses 4KiB page size regardless of host page size. 3162306a36Sopenharmony_ci */ 3262306a36Sopenharmony_ci#define VTD_PAGE_SHIFT (12) 3362306a36Sopenharmony_ci#define VTD_PAGE_SIZE (1UL << VTD_PAGE_SHIFT) 3462306a36Sopenharmony_ci#define VTD_PAGE_MASK (((u64)-1) << VTD_PAGE_SHIFT) 3562306a36Sopenharmony_ci#define VTD_PAGE_ALIGN(addr) (((addr) + VTD_PAGE_SIZE - 1) & VTD_PAGE_MASK) 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define VTD_STRIDE_SHIFT (9) 3862306a36Sopenharmony_ci#define VTD_STRIDE_MASK (((u64)-1) << VTD_STRIDE_SHIFT) 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#define DMA_PTE_READ BIT_ULL(0) 4162306a36Sopenharmony_ci#define DMA_PTE_WRITE BIT_ULL(1) 4262306a36Sopenharmony_ci#define DMA_PTE_LARGE_PAGE BIT_ULL(7) 4362306a36Sopenharmony_ci#define DMA_PTE_SNP BIT_ULL(11) 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#define DMA_FL_PTE_PRESENT BIT_ULL(0) 4662306a36Sopenharmony_ci#define DMA_FL_PTE_US BIT_ULL(2) 4762306a36Sopenharmony_ci#define DMA_FL_PTE_ACCESS BIT_ULL(5) 4862306a36Sopenharmony_ci#define DMA_FL_PTE_DIRTY BIT_ULL(6) 4962306a36Sopenharmony_ci#define DMA_FL_PTE_XD BIT_ULL(63) 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci#define ADDR_WIDTH_5LEVEL (57) 5262306a36Sopenharmony_ci#define ADDR_WIDTH_4LEVEL (48) 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci#define CONTEXT_TT_MULTI_LEVEL 0 5562306a36Sopenharmony_ci#define CONTEXT_TT_DEV_IOTLB 1 5662306a36Sopenharmony_ci#define CONTEXT_TT_PASS_THROUGH 2 5762306a36Sopenharmony_ci#define CONTEXT_PASIDE BIT_ULL(3) 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* 6062306a36Sopenharmony_ci * Intel IOMMU register specification per version 1.0 public spec. 6162306a36Sopenharmony_ci */ 6262306a36Sopenharmony_ci#define DMAR_VER_REG 0x0 /* Arch version supported by this IOMMU */ 6362306a36Sopenharmony_ci#define DMAR_CAP_REG 0x8 /* Hardware supported capabilities */ 6462306a36Sopenharmony_ci#define DMAR_ECAP_REG 0x10 /* Extended capabilities supported */ 6562306a36Sopenharmony_ci#define DMAR_GCMD_REG 0x18 /* Global command register */ 6662306a36Sopenharmony_ci#define DMAR_GSTS_REG 0x1c /* Global status register */ 6762306a36Sopenharmony_ci#define DMAR_RTADDR_REG 0x20 /* Root entry table */ 6862306a36Sopenharmony_ci#define DMAR_CCMD_REG 0x28 /* Context command reg */ 6962306a36Sopenharmony_ci#define DMAR_FSTS_REG 0x34 /* Fault Status register */ 7062306a36Sopenharmony_ci#define DMAR_FECTL_REG 0x38 /* Fault control register */ 7162306a36Sopenharmony_ci#define DMAR_FEDATA_REG 0x3c /* Fault event interrupt data register */ 7262306a36Sopenharmony_ci#define DMAR_FEADDR_REG 0x40 /* Fault event interrupt addr register */ 7362306a36Sopenharmony_ci#define DMAR_FEUADDR_REG 0x44 /* Upper address register */ 7462306a36Sopenharmony_ci#define DMAR_AFLOG_REG 0x58 /* Advanced Fault control */ 7562306a36Sopenharmony_ci#define DMAR_PMEN_REG 0x64 /* Enable Protected Memory Region */ 7662306a36Sopenharmony_ci#define DMAR_PLMBASE_REG 0x68 /* PMRR Low addr */ 7762306a36Sopenharmony_ci#define DMAR_PLMLIMIT_REG 0x6c /* PMRR low limit */ 7862306a36Sopenharmony_ci#define DMAR_PHMBASE_REG 0x70 /* pmrr high base addr */ 7962306a36Sopenharmony_ci#define DMAR_PHMLIMIT_REG 0x78 /* pmrr high limit */ 8062306a36Sopenharmony_ci#define DMAR_IQH_REG 0x80 /* Invalidation queue head register */ 8162306a36Sopenharmony_ci#define DMAR_IQT_REG 0x88 /* Invalidation queue tail register */ 8262306a36Sopenharmony_ci#define DMAR_IQ_SHIFT 4 /* Invalidation queue head/tail shift */ 8362306a36Sopenharmony_ci#define DMAR_IQA_REG 0x90 /* Invalidation queue addr register */ 8462306a36Sopenharmony_ci#define DMAR_ICS_REG 0x9c /* Invalidation complete status register */ 8562306a36Sopenharmony_ci#define DMAR_IQER_REG 0xb0 /* Invalidation queue error record register */ 8662306a36Sopenharmony_ci#define DMAR_IRTA_REG 0xb8 /* Interrupt remapping table addr register */ 8762306a36Sopenharmony_ci#define DMAR_PQH_REG 0xc0 /* Page request queue head register */ 8862306a36Sopenharmony_ci#define DMAR_PQT_REG 0xc8 /* Page request queue tail register */ 8962306a36Sopenharmony_ci#define DMAR_PQA_REG 0xd0 /* Page request queue address register */ 9062306a36Sopenharmony_ci#define DMAR_PRS_REG 0xdc /* Page request status register */ 9162306a36Sopenharmony_ci#define DMAR_PECTL_REG 0xe0 /* Page request event control register */ 9262306a36Sopenharmony_ci#define DMAR_PEDATA_REG 0xe4 /* Page request event interrupt data register */ 9362306a36Sopenharmony_ci#define DMAR_PEADDR_REG 0xe8 /* Page request event interrupt addr register */ 9462306a36Sopenharmony_ci#define DMAR_PEUADDR_REG 0xec /* Page request event Upper address register */ 9562306a36Sopenharmony_ci#define DMAR_MTRRCAP_REG 0x100 /* MTRR capability register */ 9662306a36Sopenharmony_ci#define DMAR_MTRRDEF_REG 0x108 /* MTRR default type register */ 9762306a36Sopenharmony_ci#define DMAR_MTRR_FIX64K_00000_REG 0x120 /* MTRR Fixed range registers */ 9862306a36Sopenharmony_ci#define DMAR_MTRR_FIX16K_80000_REG 0x128 9962306a36Sopenharmony_ci#define DMAR_MTRR_FIX16K_A0000_REG 0x130 10062306a36Sopenharmony_ci#define DMAR_MTRR_FIX4K_C0000_REG 0x138 10162306a36Sopenharmony_ci#define DMAR_MTRR_FIX4K_C8000_REG 0x140 10262306a36Sopenharmony_ci#define DMAR_MTRR_FIX4K_D0000_REG 0x148 10362306a36Sopenharmony_ci#define DMAR_MTRR_FIX4K_D8000_REG 0x150 10462306a36Sopenharmony_ci#define DMAR_MTRR_FIX4K_E0000_REG 0x158 10562306a36Sopenharmony_ci#define DMAR_MTRR_FIX4K_E8000_REG 0x160 10662306a36Sopenharmony_ci#define DMAR_MTRR_FIX4K_F0000_REG 0x168 10762306a36Sopenharmony_ci#define DMAR_MTRR_FIX4K_F8000_REG 0x170 10862306a36Sopenharmony_ci#define DMAR_MTRR_PHYSBASE0_REG 0x180 /* MTRR Variable range registers */ 10962306a36Sopenharmony_ci#define DMAR_MTRR_PHYSMASK0_REG 0x188 11062306a36Sopenharmony_ci#define DMAR_MTRR_PHYSBASE1_REG 0x190 11162306a36Sopenharmony_ci#define DMAR_MTRR_PHYSMASK1_REG 0x198 11262306a36Sopenharmony_ci#define DMAR_MTRR_PHYSBASE2_REG 0x1a0 11362306a36Sopenharmony_ci#define DMAR_MTRR_PHYSMASK2_REG 0x1a8 11462306a36Sopenharmony_ci#define DMAR_MTRR_PHYSBASE3_REG 0x1b0 11562306a36Sopenharmony_ci#define DMAR_MTRR_PHYSMASK3_REG 0x1b8 11662306a36Sopenharmony_ci#define DMAR_MTRR_PHYSBASE4_REG 0x1c0 11762306a36Sopenharmony_ci#define DMAR_MTRR_PHYSMASK4_REG 0x1c8 11862306a36Sopenharmony_ci#define DMAR_MTRR_PHYSBASE5_REG 0x1d0 11962306a36Sopenharmony_ci#define DMAR_MTRR_PHYSMASK5_REG 0x1d8 12062306a36Sopenharmony_ci#define DMAR_MTRR_PHYSBASE6_REG 0x1e0 12162306a36Sopenharmony_ci#define DMAR_MTRR_PHYSMASK6_REG 0x1e8 12262306a36Sopenharmony_ci#define DMAR_MTRR_PHYSBASE7_REG 0x1f0 12362306a36Sopenharmony_ci#define DMAR_MTRR_PHYSMASK7_REG 0x1f8 12462306a36Sopenharmony_ci#define DMAR_MTRR_PHYSBASE8_REG 0x200 12562306a36Sopenharmony_ci#define DMAR_MTRR_PHYSMASK8_REG 0x208 12662306a36Sopenharmony_ci#define DMAR_MTRR_PHYSBASE9_REG 0x210 12762306a36Sopenharmony_ci#define DMAR_MTRR_PHYSMASK9_REG 0x218 12862306a36Sopenharmony_ci#define DMAR_PERFCAP_REG 0x300 12962306a36Sopenharmony_ci#define DMAR_PERFCFGOFF_REG 0x310 13062306a36Sopenharmony_ci#define DMAR_PERFOVFOFF_REG 0x318 13162306a36Sopenharmony_ci#define DMAR_PERFCNTROFF_REG 0x31c 13262306a36Sopenharmony_ci#define DMAR_PERFINTRSTS_REG 0x324 13362306a36Sopenharmony_ci#define DMAR_PERFINTRCTL_REG 0x328 13462306a36Sopenharmony_ci#define DMAR_PERFEVNTCAP_REG 0x380 13562306a36Sopenharmony_ci#define DMAR_ECMD_REG 0x400 13662306a36Sopenharmony_ci#define DMAR_ECEO_REG 0x408 13762306a36Sopenharmony_ci#define DMAR_ECRSP_REG 0x410 13862306a36Sopenharmony_ci#define DMAR_ECCAP_REG 0x430 13962306a36Sopenharmony_ci#define DMAR_VCCAP_REG 0xe30 /* Virtual command capability register */ 14062306a36Sopenharmony_ci#define DMAR_VCMD_REG 0xe00 /* Virtual command register */ 14162306a36Sopenharmony_ci#define DMAR_VCRSP_REG 0xe10 /* Virtual command response register */ 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci#define DMAR_IQER_REG_IQEI(reg) FIELD_GET(GENMASK_ULL(3, 0), reg) 14462306a36Sopenharmony_ci#define DMAR_IQER_REG_ITESID(reg) FIELD_GET(GENMASK_ULL(47, 32), reg) 14562306a36Sopenharmony_ci#define DMAR_IQER_REG_ICESID(reg) FIELD_GET(GENMASK_ULL(63, 48), reg) 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci#define OFFSET_STRIDE (9) 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci#define dmar_readq(a) readq(a) 15062306a36Sopenharmony_ci#define dmar_writeq(a,v) writeq(v,a) 15162306a36Sopenharmony_ci#define dmar_readl(a) readl(a) 15262306a36Sopenharmony_ci#define dmar_writel(a, v) writel(v, a) 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci#define DMAR_VER_MAJOR(v) (((v) & 0xf0) >> 4) 15562306a36Sopenharmony_ci#define DMAR_VER_MINOR(v) ((v) & 0x0f) 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci/* 15862306a36Sopenharmony_ci * Decoding Capability Register 15962306a36Sopenharmony_ci */ 16062306a36Sopenharmony_ci#define cap_esrtps(c) (((c) >> 63) & 1) 16162306a36Sopenharmony_ci#define cap_esirtps(c) (((c) >> 62) & 1) 16262306a36Sopenharmony_ci#define cap_ecmds(c) (((c) >> 61) & 1) 16362306a36Sopenharmony_ci#define cap_fl5lp_support(c) (((c) >> 60) & 1) 16462306a36Sopenharmony_ci#define cap_pi_support(c) (((c) >> 59) & 1) 16562306a36Sopenharmony_ci#define cap_fl1gp_support(c) (((c) >> 56) & 1) 16662306a36Sopenharmony_ci#define cap_read_drain(c) (((c) >> 55) & 1) 16762306a36Sopenharmony_ci#define cap_write_drain(c) (((c) >> 54) & 1) 16862306a36Sopenharmony_ci#define cap_max_amask_val(c) (((c) >> 48) & 0x3f) 16962306a36Sopenharmony_ci#define cap_num_fault_regs(c) ((((c) >> 40) & 0xff) + 1) 17062306a36Sopenharmony_ci#define cap_pgsel_inv(c) (((c) >> 39) & 1) 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ci#define cap_super_page_val(c) (((c) >> 34) & 0xf) 17362306a36Sopenharmony_ci#define cap_super_offset(c) (((find_first_bit(&cap_super_page_val(c), 4)) \ 17462306a36Sopenharmony_ci * OFFSET_STRIDE) + 21) 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci#define cap_fault_reg_offset(c) ((((c) >> 24) & 0x3ff) * 16) 17762306a36Sopenharmony_ci#define cap_max_fault_reg_offset(c) \ 17862306a36Sopenharmony_ci (cap_fault_reg_offset(c) + cap_num_fault_regs(c) * 16) 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci#define cap_zlr(c) (((c) >> 22) & 1) 18162306a36Sopenharmony_ci#define cap_isoch(c) (((c) >> 23) & 1) 18262306a36Sopenharmony_ci#define cap_mgaw(c) ((((c) >> 16) & 0x3f) + 1) 18362306a36Sopenharmony_ci#define cap_sagaw(c) (((c) >> 8) & 0x1f) 18462306a36Sopenharmony_ci#define cap_caching_mode(c) (((c) >> 7) & 1) 18562306a36Sopenharmony_ci#define cap_phmr(c) (((c) >> 6) & 1) 18662306a36Sopenharmony_ci#define cap_plmr(c) (((c) >> 5) & 1) 18762306a36Sopenharmony_ci#define cap_rwbf(c) (((c) >> 4) & 1) 18862306a36Sopenharmony_ci#define cap_afl(c) (((c) >> 3) & 1) 18962306a36Sopenharmony_ci#define cap_ndoms(c) (((unsigned long)1) << (4 + 2 * ((c) & 0x7))) 19062306a36Sopenharmony_ci/* 19162306a36Sopenharmony_ci * Extended Capability Register 19262306a36Sopenharmony_ci */ 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci#define ecap_pms(e) (((e) >> 51) & 0x1) 19562306a36Sopenharmony_ci#define ecap_rps(e) (((e) >> 49) & 0x1) 19662306a36Sopenharmony_ci#define ecap_smpwc(e) (((e) >> 48) & 0x1) 19762306a36Sopenharmony_ci#define ecap_flts(e) (((e) >> 47) & 0x1) 19862306a36Sopenharmony_ci#define ecap_slts(e) (((e) >> 46) & 0x1) 19962306a36Sopenharmony_ci#define ecap_slads(e) (((e) >> 45) & 0x1) 20062306a36Sopenharmony_ci#define ecap_smts(e) (((e) >> 43) & 0x1) 20162306a36Sopenharmony_ci#define ecap_dit(e) (((e) >> 41) & 0x1) 20262306a36Sopenharmony_ci#define ecap_pds(e) (((e) >> 42) & 0x1) 20362306a36Sopenharmony_ci#define ecap_pasid(e) (((e) >> 40) & 0x1) 20462306a36Sopenharmony_ci#define ecap_pss(e) (((e) >> 35) & 0x1f) 20562306a36Sopenharmony_ci#define ecap_eafs(e) (((e) >> 34) & 0x1) 20662306a36Sopenharmony_ci#define ecap_nwfs(e) (((e) >> 33) & 0x1) 20762306a36Sopenharmony_ci#define ecap_srs(e) (((e) >> 31) & 0x1) 20862306a36Sopenharmony_ci#define ecap_ers(e) (((e) >> 30) & 0x1) 20962306a36Sopenharmony_ci#define ecap_prs(e) (((e) >> 29) & 0x1) 21062306a36Sopenharmony_ci#define ecap_broken_pasid(e) (((e) >> 28) & 0x1) 21162306a36Sopenharmony_ci#define ecap_dis(e) (((e) >> 27) & 0x1) 21262306a36Sopenharmony_ci#define ecap_nest(e) (((e) >> 26) & 0x1) 21362306a36Sopenharmony_ci#define ecap_mts(e) (((e) >> 25) & 0x1) 21462306a36Sopenharmony_ci#define ecap_iotlb_offset(e) ((((e) >> 8) & 0x3ff) * 16) 21562306a36Sopenharmony_ci#define ecap_max_iotlb_offset(e) (ecap_iotlb_offset(e) + 16) 21662306a36Sopenharmony_ci#define ecap_coherent(e) ((e) & 0x1) 21762306a36Sopenharmony_ci#define ecap_qis(e) ((e) & 0x2) 21862306a36Sopenharmony_ci#define ecap_pass_through(e) (((e) >> 6) & 0x1) 21962306a36Sopenharmony_ci#define ecap_eim_support(e) (((e) >> 4) & 0x1) 22062306a36Sopenharmony_ci#define ecap_ir_support(e) (((e) >> 3) & 0x1) 22162306a36Sopenharmony_ci#define ecap_dev_iotlb_support(e) (((e) >> 2) & 0x1) 22262306a36Sopenharmony_ci#define ecap_max_handle_mask(e) (((e) >> 20) & 0xf) 22362306a36Sopenharmony_ci#define ecap_sc_support(e) (((e) >> 7) & 0x1) /* Snooping Control */ 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci/* 22662306a36Sopenharmony_ci * Decoding Perf Capability Register 22762306a36Sopenharmony_ci */ 22862306a36Sopenharmony_ci#define pcap_num_cntr(p) ((p) & 0xffff) 22962306a36Sopenharmony_ci#define pcap_cntr_width(p) (((p) >> 16) & 0x7f) 23062306a36Sopenharmony_ci#define pcap_num_event_group(p) (((p) >> 24) & 0x1f) 23162306a36Sopenharmony_ci#define pcap_filters_mask(p) (((p) >> 32) & 0x1f) 23262306a36Sopenharmony_ci#define pcap_interrupt(p) (((p) >> 50) & 0x1) 23362306a36Sopenharmony_ci/* The counter stride is calculated as 2 ^ (x+10) bytes */ 23462306a36Sopenharmony_ci#define pcap_cntr_stride(p) (1ULL << ((((p) >> 52) & 0x7) + 10)) 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci/* 23762306a36Sopenharmony_ci * Decoding Perf Event Capability Register 23862306a36Sopenharmony_ci */ 23962306a36Sopenharmony_ci#define pecap_es(p) ((p) & 0xfffffff) 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci/* Virtual command interface capability */ 24262306a36Sopenharmony_ci#define vccap_pasid(v) (((v) & DMA_VCS_PAS)) /* PASID allocation */ 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci/* IOTLB_REG */ 24562306a36Sopenharmony_ci#define DMA_TLB_FLUSH_GRANU_OFFSET 60 24662306a36Sopenharmony_ci#define DMA_TLB_GLOBAL_FLUSH (((u64)1) << 60) 24762306a36Sopenharmony_ci#define DMA_TLB_DSI_FLUSH (((u64)2) << 60) 24862306a36Sopenharmony_ci#define DMA_TLB_PSI_FLUSH (((u64)3) << 60) 24962306a36Sopenharmony_ci#define DMA_TLB_IIRG(type) ((type >> 60) & 3) 25062306a36Sopenharmony_ci#define DMA_TLB_IAIG(val) (((val) >> 57) & 3) 25162306a36Sopenharmony_ci#define DMA_TLB_READ_DRAIN (((u64)1) << 49) 25262306a36Sopenharmony_ci#define DMA_TLB_WRITE_DRAIN (((u64)1) << 48) 25362306a36Sopenharmony_ci#define DMA_TLB_DID(id) (((u64)((id) & 0xffff)) << 32) 25462306a36Sopenharmony_ci#define DMA_TLB_IVT (((u64)1) << 63) 25562306a36Sopenharmony_ci#define DMA_TLB_IH_NONLEAF (((u64)1) << 6) 25662306a36Sopenharmony_ci#define DMA_TLB_MAX_SIZE (0x3f) 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci/* INVALID_DESC */ 25962306a36Sopenharmony_ci#define DMA_CCMD_INVL_GRANU_OFFSET 61 26062306a36Sopenharmony_ci#define DMA_ID_TLB_GLOBAL_FLUSH (((u64)1) << 4) 26162306a36Sopenharmony_ci#define DMA_ID_TLB_DSI_FLUSH (((u64)2) << 4) 26262306a36Sopenharmony_ci#define DMA_ID_TLB_PSI_FLUSH (((u64)3) << 4) 26362306a36Sopenharmony_ci#define DMA_ID_TLB_READ_DRAIN (((u64)1) << 7) 26462306a36Sopenharmony_ci#define DMA_ID_TLB_WRITE_DRAIN (((u64)1) << 6) 26562306a36Sopenharmony_ci#define DMA_ID_TLB_DID(id) (((u64)((id & 0xffff) << 16))) 26662306a36Sopenharmony_ci#define DMA_ID_TLB_IH_NONLEAF (((u64)1) << 6) 26762306a36Sopenharmony_ci#define DMA_ID_TLB_ADDR(addr) (addr) 26862306a36Sopenharmony_ci#define DMA_ID_TLB_ADDR_MASK(mask) (mask) 26962306a36Sopenharmony_ci 27062306a36Sopenharmony_ci/* PMEN_REG */ 27162306a36Sopenharmony_ci#define DMA_PMEN_EPM (((u32)1)<<31) 27262306a36Sopenharmony_ci#define DMA_PMEN_PRS (((u32)1)<<0) 27362306a36Sopenharmony_ci 27462306a36Sopenharmony_ci/* GCMD_REG */ 27562306a36Sopenharmony_ci#define DMA_GCMD_TE (((u32)1) << 31) 27662306a36Sopenharmony_ci#define DMA_GCMD_SRTP (((u32)1) << 30) 27762306a36Sopenharmony_ci#define DMA_GCMD_SFL (((u32)1) << 29) 27862306a36Sopenharmony_ci#define DMA_GCMD_EAFL (((u32)1) << 28) 27962306a36Sopenharmony_ci#define DMA_GCMD_WBF (((u32)1) << 27) 28062306a36Sopenharmony_ci#define DMA_GCMD_QIE (((u32)1) << 26) 28162306a36Sopenharmony_ci#define DMA_GCMD_SIRTP (((u32)1) << 24) 28262306a36Sopenharmony_ci#define DMA_GCMD_IRE (((u32) 1) << 25) 28362306a36Sopenharmony_ci#define DMA_GCMD_CFI (((u32) 1) << 23) 28462306a36Sopenharmony_ci 28562306a36Sopenharmony_ci/* GSTS_REG */ 28662306a36Sopenharmony_ci#define DMA_GSTS_TES (((u32)1) << 31) 28762306a36Sopenharmony_ci#define DMA_GSTS_RTPS (((u32)1) << 30) 28862306a36Sopenharmony_ci#define DMA_GSTS_FLS (((u32)1) << 29) 28962306a36Sopenharmony_ci#define DMA_GSTS_AFLS (((u32)1) << 28) 29062306a36Sopenharmony_ci#define DMA_GSTS_WBFS (((u32)1) << 27) 29162306a36Sopenharmony_ci#define DMA_GSTS_QIES (((u32)1) << 26) 29262306a36Sopenharmony_ci#define DMA_GSTS_IRTPS (((u32)1) << 24) 29362306a36Sopenharmony_ci#define DMA_GSTS_IRES (((u32)1) << 25) 29462306a36Sopenharmony_ci#define DMA_GSTS_CFIS (((u32)1) << 23) 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci/* DMA_RTADDR_REG */ 29762306a36Sopenharmony_ci#define DMA_RTADDR_SMT (((u64)1) << 10) 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ci/* CCMD_REG */ 30062306a36Sopenharmony_ci#define DMA_CCMD_ICC (((u64)1) << 63) 30162306a36Sopenharmony_ci#define DMA_CCMD_GLOBAL_INVL (((u64)1) << 61) 30262306a36Sopenharmony_ci#define DMA_CCMD_DOMAIN_INVL (((u64)2) << 61) 30362306a36Sopenharmony_ci#define DMA_CCMD_DEVICE_INVL (((u64)3) << 61) 30462306a36Sopenharmony_ci#define DMA_CCMD_FM(m) (((u64)((m) & 0x3)) << 32) 30562306a36Sopenharmony_ci#define DMA_CCMD_MASK_NOBIT 0 30662306a36Sopenharmony_ci#define DMA_CCMD_MASK_1BIT 1 30762306a36Sopenharmony_ci#define DMA_CCMD_MASK_2BIT 2 30862306a36Sopenharmony_ci#define DMA_CCMD_MASK_3BIT 3 30962306a36Sopenharmony_ci#define DMA_CCMD_SID(s) (((u64)((s) & 0xffff)) << 16) 31062306a36Sopenharmony_ci#define DMA_CCMD_DID(d) ((u64)((d) & 0xffff)) 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ci/* ECMD_REG */ 31362306a36Sopenharmony_ci#define DMA_MAX_NUM_ECMD 256 31462306a36Sopenharmony_ci#define DMA_MAX_NUM_ECMDCAP (DMA_MAX_NUM_ECMD / 64) 31562306a36Sopenharmony_ci#define DMA_ECMD_REG_STEP 8 31662306a36Sopenharmony_ci#define DMA_ECMD_ENABLE 0xf0 31762306a36Sopenharmony_ci#define DMA_ECMD_DISABLE 0xf1 31862306a36Sopenharmony_ci#define DMA_ECMD_FREEZE 0xf4 31962306a36Sopenharmony_ci#define DMA_ECMD_UNFREEZE 0xf5 32062306a36Sopenharmony_ci#define DMA_ECMD_OA_SHIFT 16 32162306a36Sopenharmony_ci#define DMA_ECMD_ECRSP_IP 0x1 32262306a36Sopenharmony_ci#define DMA_ECMD_ECCAP3 3 32362306a36Sopenharmony_ci#define DMA_ECMD_ECCAP3_ECNTS BIT_ULL(48) 32462306a36Sopenharmony_ci#define DMA_ECMD_ECCAP3_DCNTS BIT_ULL(49) 32562306a36Sopenharmony_ci#define DMA_ECMD_ECCAP3_FCNTS BIT_ULL(52) 32662306a36Sopenharmony_ci#define DMA_ECMD_ECCAP3_UFCNTS BIT_ULL(53) 32762306a36Sopenharmony_ci#define DMA_ECMD_ECCAP3_ESSENTIAL (DMA_ECMD_ECCAP3_ECNTS | \ 32862306a36Sopenharmony_ci DMA_ECMD_ECCAP3_DCNTS | \ 32962306a36Sopenharmony_ci DMA_ECMD_ECCAP3_FCNTS | \ 33062306a36Sopenharmony_ci DMA_ECMD_ECCAP3_UFCNTS) 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ci/* FECTL_REG */ 33362306a36Sopenharmony_ci#define DMA_FECTL_IM (((u32)1) << 31) 33462306a36Sopenharmony_ci 33562306a36Sopenharmony_ci/* FSTS_REG */ 33662306a36Sopenharmony_ci#define DMA_FSTS_PFO (1 << 0) /* Primary Fault Overflow */ 33762306a36Sopenharmony_ci#define DMA_FSTS_PPF (1 << 1) /* Primary Pending Fault */ 33862306a36Sopenharmony_ci#define DMA_FSTS_IQE (1 << 4) /* Invalidation Queue Error */ 33962306a36Sopenharmony_ci#define DMA_FSTS_ICE (1 << 5) /* Invalidation Completion Error */ 34062306a36Sopenharmony_ci#define DMA_FSTS_ITE (1 << 6) /* Invalidation Time-out Error */ 34162306a36Sopenharmony_ci#define DMA_FSTS_PRO (1 << 7) /* Page Request Overflow */ 34262306a36Sopenharmony_ci#define dma_fsts_fault_record_index(s) (((s) >> 8) & 0xff) 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_ci/* FRCD_REG, 32 bits access */ 34562306a36Sopenharmony_ci#define DMA_FRCD_F (((u32)1) << 31) 34662306a36Sopenharmony_ci#define dma_frcd_type(d) ((d >> 30) & 1) 34762306a36Sopenharmony_ci#define dma_frcd_fault_reason(c) (c & 0xff) 34862306a36Sopenharmony_ci#define dma_frcd_source_id(c) (c & 0xffff) 34962306a36Sopenharmony_ci#define dma_frcd_pasid_value(c) (((c) >> 8) & 0xfffff) 35062306a36Sopenharmony_ci#define dma_frcd_pasid_present(c) (((c) >> 31) & 1) 35162306a36Sopenharmony_ci/* low 64 bit */ 35262306a36Sopenharmony_ci#define dma_frcd_page_addr(d) (d & (((u64)-1) << PAGE_SHIFT)) 35362306a36Sopenharmony_ci 35462306a36Sopenharmony_ci/* PRS_REG */ 35562306a36Sopenharmony_ci#define DMA_PRS_PPR ((u32)1) 35662306a36Sopenharmony_ci#define DMA_PRS_PRO ((u32)2) 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci#define DMA_VCS_PAS ((u64)1) 35962306a36Sopenharmony_ci 36062306a36Sopenharmony_ci/* PERFINTRSTS_REG */ 36162306a36Sopenharmony_ci#define DMA_PERFINTRSTS_PIS ((u32)1) 36262306a36Sopenharmony_ci 36362306a36Sopenharmony_ci#define IOMMU_WAIT_OP(iommu, offset, op, cond, sts) \ 36462306a36Sopenharmony_cido { \ 36562306a36Sopenharmony_ci cycles_t start_time = get_cycles(); \ 36662306a36Sopenharmony_ci while (1) { \ 36762306a36Sopenharmony_ci sts = op(iommu->reg + offset); \ 36862306a36Sopenharmony_ci if (cond) \ 36962306a36Sopenharmony_ci break; \ 37062306a36Sopenharmony_ci if (DMAR_OPERATION_TIMEOUT < (get_cycles() - start_time))\ 37162306a36Sopenharmony_ci panic("DMAR hardware is malfunctioning\n"); \ 37262306a36Sopenharmony_ci cpu_relax(); \ 37362306a36Sopenharmony_ci } \ 37462306a36Sopenharmony_ci} while (0) 37562306a36Sopenharmony_ci 37662306a36Sopenharmony_ci#define QI_LENGTH 256 /* queue length */ 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_cienum { 37962306a36Sopenharmony_ci QI_FREE, 38062306a36Sopenharmony_ci QI_IN_USE, 38162306a36Sopenharmony_ci QI_DONE, 38262306a36Sopenharmony_ci QI_ABORT 38362306a36Sopenharmony_ci}; 38462306a36Sopenharmony_ci 38562306a36Sopenharmony_ci#define QI_CC_TYPE 0x1 38662306a36Sopenharmony_ci#define QI_IOTLB_TYPE 0x2 38762306a36Sopenharmony_ci#define QI_DIOTLB_TYPE 0x3 38862306a36Sopenharmony_ci#define QI_IEC_TYPE 0x4 38962306a36Sopenharmony_ci#define QI_IWD_TYPE 0x5 39062306a36Sopenharmony_ci#define QI_EIOTLB_TYPE 0x6 39162306a36Sopenharmony_ci#define QI_PC_TYPE 0x7 39262306a36Sopenharmony_ci#define QI_DEIOTLB_TYPE 0x8 39362306a36Sopenharmony_ci#define QI_PGRP_RESP_TYPE 0x9 39462306a36Sopenharmony_ci#define QI_PSTRM_RESP_TYPE 0xa 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_ci#define QI_IEC_SELECTIVE (((u64)1) << 4) 39762306a36Sopenharmony_ci#define QI_IEC_IIDEX(idx) (((u64)(idx & 0xffff) << 32)) 39862306a36Sopenharmony_ci#define QI_IEC_IM(m) (((u64)(m & 0x1f) << 27)) 39962306a36Sopenharmony_ci 40062306a36Sopenharmony_ci#define QI_IWD_STATUS_DATA(d) (((u64)d) << 32) 40162306a36Sopenharmony_ci#define QI_IWD_STATUS_WRITE (((u64)1) << 5) 40262306a36Sopenharmony_ci#define QI_IWD_FENCE (((u64)1) << 6) 40362306a36Sopenharmony_ci#define QI_IWD_PRQ_DRAIN (((u64)1) << 7) 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_ci#define QI_IOTLB_DID(did) (((u64)did) << 16) 40662306a36Sopenharmony_ci#define QI_IOTLB_DR(dr) (((u64)dr) << 7) 40762306a36Sopenharmony_ci#define QI_IOTLB_DW(dw) (((u64)dw) << 6) 40862306a36Sopenharmony_ci#define QI_IOTLB_GRAN(gran) (((u64)gran) >> (DMA_TLB_FLUSH_GRANU_OFFSET-4)) 40962306a36Sopenharmony_ci#define QI_IOTLB_ADDR(addr) (((u64)addr) & VTD_PAGE_MASK) 41062306a36Sopenharmony_ci#define QI_IOTLB_IH(ih) (((u64)ih) << 6) 41162306a36Sopenharmony_ci#define QI_IOTLB_AM(am) (((u8)am) & 0x3f) 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci#define QI_CC_FM(fm) (((u64)fm) << 48) 41462306a36Sopenharmony_ci#define QI_CC_SID(sid) (((u64)sid) << 32) 41562306a36Sopenharmony_ci#define QI_CC_DID(did) (((u64)did) << 16) 41662306a36Sopenharmony_ci#define QI_CC_GRAN(gran) (((u64)gran) >> (DMA_CCMD_INVL_GRANU_OFFSET-4)) 41762306a36Sopenharmony_ci 41862306a36Sopenharmony_ci#define QI_DEV_IOTLB_SID(sid) ((u64)((sid) & 0xffff) << 32) 41962306a36Sopenharmony_ci#define QI_DEV_IOTLB_QDEP(qdep) (((qdep) & 0x1f) << 16) 42062306a36Sopenharmony_ci#define QI_DEV_IOTLB_ADDR(addr) ((u64)(addr) & VTD_PAGE_MASK) 42162306a36Sopenharmony_ci#define QI_DEV_IOTLB_PFSID(pfsid) (((u64)(pfsid & 0xf) << 12) | \ 42262306a36Sopenharmony_ci ((u64)((pfsid >> 4) & 0xfff) << 52)) 42362306a36Sopenharmony_ci#define QI_DEV_IOTLB_SIZE 1 42462306a36Sopenharmony_ci#define QI_DEV_IOTLB_MAX_INVS 32 42562306a36Sopenharmony_ci 42662306a36Sopenharmony_ci#define QI_PC_PASID(pasid) (((u64)pasid) << 32) 42762306a36Sopenharmony_ci#define QI_PC_DID(did) (((u64)did) << 16) 42862306a36Sopenharmony_ci#define QI_PC_GRAN(gran) (((u64)gran) << 4) 42962306a36Sopenharmony_ci 43062306a36Sopenharmony_ci/* PASID cache invalidation granu */ 43162306a36Sopenharmony_ci#define QI_PC_ALL_PASIDS 0 43262306a36Sopenharmony_ci#define QI_PC_PASID_SEL 1 43362306a36Sopenharmony_ci#define QI_PC_GLOBAL 3 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci#define QI_EIOTLB_ADDR(addr) ((u64)(addr) & VTD_PAGE_MASK) 43662306a36Sopenharmony_ci#define QI_EIOTLB_IH(ih) (((u64)ih) << 6) 43762306a36Sopenharmony_ci#define QI_EIOTLB_AM(am) (((u64)am) & 0x3f) 43862306a36Sopenharmony_ci#define QI_EIOTLB_PASID(pasid) (((u64)pasid) << 32) 43962306a36Sopenharmony_ci#define QI_EIOTLB_DID(did) (((u64)did) << 16) 44062306a36Sopenharmony_ci#define QI_EIOTLB_GRAN(gran) (((u64)gran) << 4) 44162306a36Sopenharmony_ci 44262306a36Sopenharmony_ci/* QI Dev-IOTLB inv granu */ 44362306a36Sopenharmony_ci#define QI_DEV_IOTLB_GRAN_ALL 1 44462306a36Sopenharmony_ci#define QI_DEV_IOTLB_GRAN_PASID_SEL 0 44562306a36Sopenharmony_ci 44662306a36Sopenharmony_ci#define QI_DEV_EIOTLB_ADDR(a) ((u64)(a) & VTD_PAGE_MASK) 44762306a36Sopenharmony_ci#define QI_DEV_EIOTLB_SIZE (((u64)1) << 11) 44862306a36Sopenharmony_ci#define QI_DEV_EIOTLB_PASID(p) ((u64)((p) & 0xfffff) << 32) 44962306a36Sopenharmony_ci#define QI_DEV_EIOTLB_SID(sid) ((u64)((sid) & 0xffff) << 16) 45062306a36Sopenharmony_ci#define QI_DEV_EIOTLB_QDEP(qd) ((u64)((qd) & 0x1f) << 4) 45162306a36Sopenharmony_ci#define QI_DEV_EIOTLB_PFSID(pfsid) (((u64)(pfsid & 0xf) << 12) | \ 45262306a36Sopenharmony_ci ((u64)((pfsid >> 4) & 0xfff) << 52)) 45362306a36Sopenharmony_ci#define QI_DEV_EIOTLB_MAX_INVS 32 45462306a36Sopenharmony_ci 45562306a36Sopenharmony_ci/* Page group response descriptor QW0 */ 45662306a36Sopenharmony_ci#define QI_PGRP_PASID_P(p) (((u64)(p)) << 4) 45762306a36Sopenharmony_ci#define QI_PGRP_PDP(p) (((u64)(p)) << 5) 45862306a36Sopenharmony_ci#define QI_PGRP_RESP_CODE(res) (((u64)(res)) << 12) 45962306a36Sopenharmony_ci#define QI_PGRP_DID(rid) (((u64)(rid)) << 16) 46062306a36Sopenharmony_ci#define QI_PGRP_PASID(pasid) (((u64)(pasid)) << 32) 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ci/* Page group response descriptor QW1 */ 46362306a36Sopenharmony_ci#define QI_PGRP_LPIG(x) (((u64)(x)) << 2) 46462306a36Sopenharmony_ci#define QI_PGRP_IDX(idx) (((u64)(idx)) << 3) 46562306a36Sopenharmony_ci 46662306a36Sopenharmony_ci 46762306a36Sopenharmony_ci#define QI_RESP_SUCCESS 0x0 46862306a36Sopenharmony_ci#define QI_RESP_INVALID 0x1 46962306a36Sopenharmony_ci#define QI_RESP_FAILURE 0xf 47062306a36Sopenharmony_ci 47162306a36Sopenharmony_ci#define QI_GRAN_NONG_PASID 2 47262306a36Sopenharmony_ci#define QI_GRAN_PSI_PASID 3 47362306a36Sopenharmony_ci 47462306a36Sopenharmony_ci#define qi_shift(iommu) (DMAR_IQ_SHIFT + !!ecap_smts((iommu)->ecap)) 47562306a36Sopenharmony_ci 47662306a36Sopenharmony_cistruct qi_desc { 47762306a36Sopenharmony_ci u64 qw0; 47862306a36Sopenharmony_ci u64 qw1; 47962306a36Sopenharmony_ci u64 qw2; 48062306a36Sopenharmony_ci u64 qw3; 48162306a36Sopenharmony_ci}; 48262306a36Sopenharmony_ci 48362306a36Sopenharmony_cistruct q_inval { 48462306a36Sopenharmony_ci raw_spinlock_t q_lock; 48562306a36Sopenharmony_ci void *desc; /* invalidation queue */ 48662306a36Sopenharmony_ci int *desc_status; /* desc status */ 48762306a36Sopenharmony_ci int free_head; /* first free entry */ 48862306a36Sopenharmony_ci int free_tail; /* last free entry */ 48962306a36Sopenharmony_ci int free_cnt; 49062306a36Sopenharmony_ci}; 49162306a36Sopenharmony_ci 49262306a36Sopenharmony_ci/* Page Request Queue depth */ 49362306a36Sopenharmony_ci#define PRQ_ORDER 4 49462306a36Sopenharmony_ci#define PRQ_RING_MASK ((0x1000 << PRQ_ORDER) - 0x20) 49562306a36Sopenharmony_ci#define PRQ_DEPTH ((0x1000 << PRQ_ORDER) >> 5) 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_cistruct dmar_pci_notify_info; 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ci#ifdef CONFIG_IRQ_REMAP 50062306a36Sopenharmony_ci/* 1MB - maximum possible interrupt remapping table size */ 50162306a36Sopenharmony_ci#define INTR_REMAP_PAGE_ORDER 8 50262306a36Sopenharmony_ci#define INTR_REMAP_TABLE_REG_SIZE 0xf 50362306a36Sopenharmony_ci#define INTR_REMAP_TABLE_REG_SIZE_MASK 0xf 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ci#define INTR_REMAP_TABLE_ENTRIES 65536 50662306a36Sopenharmony_ci 50762306a36Sopenharmony_cistruct irq_domain; 50862306a36Sopenharmony_ci 50962306a36Sopenharmony_cistruct ir_table { 51062306a36Sopenharmony_ci struct irte *base; 51162306a36Sopenharmony_ci unsigned long *bitmap; 51262306a36Sopenharmony_ci}; 51362306a36Sopenharmony_ci 51462306a36Sopenharmony_civoid intel_irq_remap_add_device(struct dmar_pci_notify_info *info); 51562306a36Sopenharmony_ci#else 51662306a36Sopenharmony_cistatic inline void 51762306a36Sopenharmony_ciintel_irq_remap_add_device(struct dmar_pci_notify_info *info) { } 51862306a36Sopenharmony_ci#endif 51962306a36Sopenharmony_ci 52062306a36Sopenharmony_cistruct iommu_flush { 52162306a36Sopenharmony_ci void (*flush_context)(struct intel_iommu *iommu, u16 did, u16 sid, 52262306a36Sopenharmony_ci u8 fm, u64 type); 52362306a36Sopenharmony_ci void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr, 52462306a36Sopenharmony_ci unsigned int size_order, u64 type); 52562306a36Sopenharmony_ci}; 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_cienum { 52862306a36Sopenharmony_ci SR_DMAR_FECTL_REG, 52962306a36Sopenharmony_ci SR_DMAR_FEDATA_REG, 53062306a36Sopenharmony_ci SR_DMAR_FEADDR_REG, 53162306a36Sopenharmony_ci SR_DMAR_FEUADDR_REG, 53262306a36Sopenharmony_ci MAX_SR_DMAR_REGS 53362306a36Sopenharmony_ci}; 53462306a36Sopenharmony_ci 53562306a36Sopenharmony_ci#define VTD_FLAG_TRANS_PRE_ENABLED (1 << 0) 53662306a36Sopenharmony_ci#define VTD_FLAG_IRQ_REMAP_PRE_ENABLED (1 << 1) 53762306a36Sopenharmony_ci#define VTD_FLAG_SVM_CAPABLE (1 << 2) 53862306a36Sopenharmony_ci 53962306a36Sopenharmony_ci#define sm_supported(iommu) (intel_iommu_sm && ecap_smts((iommu)->ecap)) 54062306a36Sopenharmony_ci#define pasid_supported(iommu) (sm_supported(iommu) && \ 54162306a36Sopenharmony_ci ecap_pasid((iommu)->ecap)) 54262306a36Sopenharmony_ci 54362306a36Sopenharmony_cistruct pasid_entry; 54462306a36Sopenharmony_cistruct pasid_state_entry; 54562306a36Sopenharmony_cistruct page_req_dsc; 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci/* 54862306a36Sopenharmony_ci * 0: Present 54962306a36Sopenharmony_ci * 1-11: Reserved 55062306a36Sopenharmony_ci * 12-63: Context Ptr (12 - (haw-1)) 55162306a36Sopenharmony_ci * 64-127: Reserved 55262306a36Sopenharmony_ci */ 55362306a36Sopenharmony_cistruct root_entry { 55462306a36Sopenharmony_ci u64 lo; 55562306a36Sopenharmony_ci u64 hi; 55662306a36Sopenharmony_ci}; 55762306a36Sopenharmony_ci 55862306a36Sopenharmony_ci/* 55962306a36Sopenharmony_ci * low 64 bits: 56062306a36Sopenharmony_ci * 0: present 56162306a36Sopenharmony_ci * 1: fault processing disable 56262306a36Sopenharmony_ci * 2-3: translation type 56362306a36Sopenharmony_ci * 12-63: address space root 56462306a36Sopenharmony_ci * high 64 bits: 56562306a36Sopenharmony_ci * 0-2: address width 56662306a36Sopenharmony_ci * 3-6: aval 56762306a36Sopenharmony_ci * 8-23: domain id 56862306a36Sopenharmony_ci */ 56962306a36Sopenharmony_cistruct context_entry { 57062306a36Sopenharmony_ci u64 lo; 57162306a36Sopenharmony_ci u64 hi; 57262306a36Sopenharmony_ci}; 57362306a36Sopenharmony_ci 57462306a36Sopenharmony_cistruct iommu_domain_info { 57562306a36Sopenharmony_ci struct intel_iommu *iommu; 57662306a36Sopenharmony_ci unsigned int refcnt; /* Refcount of devices per iommu */ 57762306a36Sopenharmony_ci u16 did; /* Domain ids per IOMMU. Use u16 since 57862306a36Sopenharmony_ci * domain ids are 16 bit wide according 57962306a36Sopenharmony_ci * to VT-d spec, section 9.3 */ 58062306a36Sopenharmony_ci}; 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_cistruct dmar_domain { 58362306a36Sopenharmony_ci int nid; /* node id */ 58462306a36Sopenharmony_ci struct xarray iommu_array; /* Attached IOMMU array */ 58562306a36Sopenharmony_ci 58662306a36Sopenharmony_ci u8 has_iotlb_device: 1; 58762306a36Sopenharmony_ci u8 iommu_coherency: 1; /* indicate coherency of iommu access */ 58862306a36Sopenharmony_ci u8 force_snooping : 1; /* Create IOPTEs with snoop control */ 58962306a36Sopenharmony_ci u8 set_pte_snp:1; 59062306a36Sopenharmony_ci u8 use_first_level:1; /* DMA translation for the domain goes 59162306a36Sopenharmony_ci * through the first level page table, 59262306a36Sopenharmony_ci * otherwise, goes through the second 59362306a36Sopenharmony_ci * level. 59462306a36Sopenharmony_ci */ 59562306a36Sopenharmony_ci u8 has_mappings:1; /* Has mappings configured through 59662306a36Sopenharmony_ci * iommu_map() interface. 59762306a36Sopenharmony_ci */ 59862306a36Sopenharmony_ci 59962306a36Sopenharmony_ci spinlock_t lock; /* Protect device tracking lists */ 60062306a36Sopenharmony_ci struct list_head devices; /* all devices' list */ 60162306a36Sopenharmony_ci struct list_head dev_pasids; /* all attached pasids */ 60262306a36Sopenharmony_ci 60362306a36Sopenharmony_ci struct dma_pte *pgd; /* virtual address */ 60462306a36Sopenharmony_ci int gaw; /* max guest address width */ 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_ci /* adjusted guest address width, 0 is level 2 30-bit */ 60762306a36Sopenharmony_ci int agaw; 60862306a36Sopenharmony_ci int iommu_superpage;/* Level of superpages supported: 60962306a36Sopenharmony_ci 0 == 4KiB (no superpages), 1 == 2MiB, 61062306a36Sopenharmony_ci 2 == 1GiB, 3 == 512GiB, 4 == 1TiB */ 61162306a36Sopenharmony_ci u64 max_addr; /* maximum mapped address */ 61262306a36Sopenharmony_ci 61362306a36Sopenharmony_ci struct iommu_domain domain; /* generic domain data structure for 61462306a36Sopenharmony_ci iommu core */ 61562306a36Sopenharmony_ci}; 61662306a36Sopenharmony_ci 61762306a36Sopenharmony_ci/* 61862306a36Sopenharmony_ci * In theory, the VT-d 4.0 spec can support up to 2 ^ 16 counters. 61962306a36Sopenharmony_ci * But in practice, there are only 14 counters for the existing 62062306a36Sopenharmony_ci * platform. Setting the max number of counters to 64 should be good 62162306a36Sopenharmony_ci * enough for a long time. Also, supporting more than 64 counters 62262306a36Sopenharmony_ci * requires more extras, e.g., extra freeze and overflow registers, 62362306a36Sopenharmony_ci * which is not necessary for now. 62462306a36Sopenharmony_ci */ 62562306a36Sopenharmony_ci#define IOMMU_PMU_IDX_MAX 64 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_cistruct iommu_pmu { 62862306a36Sopenharmony_ci struct intel_iommu *iommu; 62962306a36Sopenharmony_ci u32 num_cntr; /* Number of counters */ 63062306a36Sopenharmony_ci u32 num_eg; /* Number of event group */ 63162306a36Sopenharmony_ci u32 cntr_width; /* Counter width */ 63262306a36Sopenharmony_ci u32 cntr_stride; /* Counter Stride */ 63362306a36Sopenharmony_ci u32 filter; /* Bitmask of filter support */ 63462306a36Sopenharmony_ci void __iomem *base; /* the PerfMon base address */ 63562306a36Sopenharmony_ci void __iomem *cfg_reg; /* counter configuration base address */ 63662306a36Sopenharmony_ci void __iomem *cntr_reg; /* counter 0 address*/ 63762306a36Sopenharmony_ci void __iomem *overflow; /* overflow status register */ 63862306a36Sopenharmony_ci 63962306a36Sopenharmony_ci u64 *evcap; /* Indicates all supported events */ 64062306a36Sopenharmony_ci u32 **cntr_evcap; /* Supported events of each counter. */ 64162306a36Sopenharmony_ci 64262306a36Sopenharmony_ci struct pmu pmu; 64362306a36Sopenharmony_ci DECLARE_BITMAP(used_mask, IOMMU_PMU_IDX_MAX); 64462306a36Sopenharmony_ci struct perf_event *event_list[IOMMU_PMU_IDX_MAX]; 64562306a36Sopenharmony_ci unsigned char irq_name[16]; 64662306a36Sopenharmony_ci struct hlist_node cpuhp_node; 64762306a36Sopenharmony_ci int cpu; 64862306a36Sopenharmony_ci}; 64962306a36Sopenharmony_ci 65062306a36Sopenharmony_ci#define IOMMU_IRQ_ID_OFFSET_PRQ (DMAR_UNITS_SUPPORTED) 65162306a36Sopenharmony_ci#define IOMMU_IRQ_ID_OFFSET_PERF (2 * DMAR_UNITS_SUPPORTED) 65262306a36Sopenharmony_ci 65362306a36Sopenharmony_cistruct intel_iommu { 65462306a36Sopenharmony_ci void __iomem *reg; /* Pointer to hardware regs, virtual addr */ 65562306a36Sopenharmony_ci u64 reg_phys; /* physical address of hw register set */ 65662306a36Sopenharmony_ci u64 reg_size; /* size of hw register set */ 65762306a36Sopenharmony_ci u64 cap; 65862306a36Sopenharmony_ci u64 ecap; 65962306a36Sopenharmony_ci u64 vccap; 66062306a36Sopenharmony_ci u64 ecmdcap[DMA_MAX_NUM_ECMDCAP]; 66162306a36Sopenharmony_ci u32 gcmd; /* Holds TE, EAFL. Don't need SRTP, SFL, WBF */ 66262306a36Sopenharmony_ci raw_spinlock_t register_lock; /* protect register handling */ 66362306a36Sopenharmony_ci int seq_id; /* sequence id of the iommu */ 66462306a36Sopenharmony_ci int agaw; /* agaw of this iommu */ 66562306a36Sopenharmony_ci int msagaw; /* max sagaw of this iommu */ 66662306a36Sopenharmony_ci unsigned int irq, pr_irq, perf_irq; 66762306a36Sopenharmony_ci u16 segment; /* PCI segment# */ 66862306a36Sopenharmony_ci unsigned char name[13]; /* Device Name */ 66962306a36Sopenharmony_ci 67062306a36Sopenharmony_ci#ifdef CONFIG_INTEL_IOMMU 67162306a36Sopenharmony_ci unsigned long *domain_ids; /* bitmap of domains */ 67262306a36Sopenharmony_ci unsigned long *copied_tables; /* bitmap of copied tables */ 67362306a36Sopenharmony_ci spinlock_t lock; /* protect context, domain ids */ 67462306a36Sopenharmony_ci struct root_entry *root_entry; /* virtual address */ 67562306a36Sopenharmony_ci 67662306a36Sopenharmony_ci struct iommu_flush flush; 67762306a36Sopenharmony_ci#endif 67862306a36Sopenharmony_ci#ifdef CONFIG_INTEL_IOMMU_SVM 67962306a36Sopenharmony_ci struct page_req_dsc *prq; 68062306a36Sopenharmony_ci unsigned char prq_name[16]; /* Name for PRQ interrupt */ 68162306a36Sopenharmony_ci unsigned long prq_seq_number; 68262306a36Sopenharmony_ci struct completion prq_complete; 68362306a36Sopenharmony_ci#endif 68462306a36Sopenharmony_ci struct iopf_queue *iopf_queue; 68562306a36Sopenharmony_ci unsigned char iopfq_name[16]; 68662306a36Sopenharmony_ci struct q_inval *qi; /* Queued invalidation info */ 68762306a36Sopenharmony_ci u32 iommu_state[MAX_SR_DMAR_REGS]; /* Store iommu states between suspend and resume.*/ 68862306a36Sopenharmony_ci 68962306a36Sopenharmony_ci#ifdef CONFIG_IRQ_REMAP 69062306a36Sopenharmony_ci struct ir_table *ir_table; /* Interrupt remapping info */ 69162306a36Sopenharmony_ci struct irq_domain *ir_domain; 69262306a36Sopenharmony_ci#endif 69362306a36Sopenharmony_ci struct iommu_device iommu; /* IOMMU core code handle */ 69462306a36Sopenharmony_ci int node; 69562306a36Sopenharmony_ci u32 flags; /* Software defined flags */ 69662306a36Sopenharmony_ci 69762306a36Sopenharmony_ci struct dmar_drhd_unit *drhd; 69862306a36Sopenharmony_ci void *perf_statistic; 69962306a36Sopenharmony_ci 70062306a36Sopenharmony_ci struct iommu_pmu *pmu; 70162306a36Sopenharmony_ci}; 70262306a36Sopenharmony_ci 70362306a36Sopenharmony_ci/* PCI domain-device relationship */ 70462306a36Sopenharmony_cistruct device_domain_info { 70562306a36Sopenharmony_ci struct list_head link; /* link to domain siblings */ 70662306a36Sopenharmony_ci u32 segment; /* PCI segment number */ 70762306a36Sopenharmony_ci u8 bus; /* PCI bus number */ 70862306a36Sopenharmony_ci u8 devfn; /* PCI devfn number */ 70962306a36Sopenharmony_ci u16 pfsid; /* SRIOV physical function source ID */ 71062306a36Sopenharmony_ci u8 pasid_supported:3; 71162306a36Sopenharmony_ci u8 pasid_enabled:1; 71262306a36Sopenharmony_ci u8 pri_supported:1; 71362306a36Sopenharmony_ci u8 pri_enabled:1; 71462306a36Sopenharmony_ci u8 ats_supported:1; 71562306a36Sopenharmony_ci u8 ats_enabled:1; 71662306a36Sopenharmony_ci u8 dtlb_extra_inval:1; /* Quirk for devices need extra flush */ 71762306a36Sopenharmony_ci u8 ats_qdep; 71862306a36Sopenharmony_ci struct device *dev; /* it's NULL for PCIe-to-PCI bridge */ 71962306a36Sopenharmony_ci struct intel_iommu *iommu; /* IOMMU used by this device */ 72062306a36Sopenharmony_ci struct dmar_domain *domain; /* pointer to domain */ 72162306a36Sopenharmony_ci struct pasid_table *pasid_table; /* pasid table */ 72262306a36Sopenharmony_ci}; 72362306a36Sopenharmony_ci 72462306a36Sopenharmony_cistruct dev_pasid_info { 72562306a36Sopenharmony_ci struct list_head link_domain; /* link to domain siblings */ 72662306a36Sopenharmony_ci struct device *dev; 72762306a36Sopenharmony_ci ioasid_t pasid; 72862306a36Sopenharmony_ci}; 72962306a36Sopenharmony_ci 73062306a36Sopenharmony_cistatic inline void __iommu_flush_cache( 73162306a36Sopenharmony_ci struct intel_iommu *iommu, void *addr, int size) 73262306a36Sopenharmony_ci{ 73362306a36Sopenharmony_ci if (!ecap_coherent(iommu->ecap)) 73462306a36Sopenharmony_ci clflush_cache_range(addr, size); 73562306a36Sopenharmony_ci} 73662306a36Sopenharmony_ci 73762306a36Sopenharmony_ci/* Convert generic struct iommu_domain to private struct dmar_domain */ 73862306a36Sopenharmony_cistatic inline struct dmar_domain *to_dmar_domain(struct iommu_domain *dom) 73962306a36Sopenharmony_ci{ 74062306a36Sopenharmony_ci return container_of(dom, struct dmar_domain, domain); 74162306a36Sopenharmony_ci} 74262306a36Sopenharmony_ci 74362306a36Sopenharmony_ci/* Retrieve the domain ID which has allocated to the domain */ 74462306a36Sopenharmony_cistatic inline u16 74562306a36Sopenharmony_cidomain_id_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) 74662306a36Sopenharmony_ci{ 74762306a36Sopenharmony_ci struct iommu_domain_info *info = 74862306a36Sopenharmony_ci xa_load(&domain->iommu_array, iommu->seq_id); 74962306a36Sopenharmony_ci 75062306a36Sopenharmony_ci return info->did; 75162306a36Sopenharmony_ci} 75262306a36Sopenharmony_ci 75362306a36Sopenharmony_ci/* 75462306a36Sopenharmony_ci * 0: readable 75562306a36Sopenharmony_ci * 1: writable 75662306a36Sopenharmony_ci * 2-6: reserved 75762306a36Sopenharmony_ci * 7: super page 75862306a36Sopenharmony_ci * 8-10: available 75962306a36Sopenharmony_ci * 11: snoop behavior 76062306a36Sopenharmony_ci * 12-63: Host physical address 76162306a36Sopenharmony_ci */ 76262306a36Sopenharmony_cistruct dma_pte { 76362306a36Sopenharmony_ci u64 val; 76462306a36Sopenharmony_ci}; 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_cistatic inline void dma_clear_pte(struct dma_pte *pte) 76762306a36Sopenharmony_ci{ 76862306a36Sopenharmony_ci pte->val = 0; 76962306a36Sopenharmony_ci} 77062306a36Sopenharmony_ci 77162306a36Sopenharmony_cistatic inline u64 dma_pte_addr(struct dma_pte *pte) 77262306a36Sopenharmony_ci{ 77362306a36Sopenharmony_ci#ifdef CONFIG_64BIT 77462306a36Sopenharmony_ci return pte->val & VTD_PAGE_MASK & (~DMA_FL_PTE_XD); 77562306a36Sopenharmony_ci#else 77662306a36Sopenharmony_ci /* Must have a full atomic 64-bit read */ 77762306a36Sopenharmony_ci return __cmpxchg64(&pte->val, 0ULL, 0ULL) & 77862306a36Sopenharmony_ci VTD_PAGE_MASK & (~DMA_FL_PTE_XD); 77962306a36Sopenharmony_ci#endif 78062306a36Sopenharmony_ci} 78162306a36Sopenharmony_ci 78262306a36Sopenharmony_cistatic inline bool dma_pte_present(struct dma_pte *pte) 78362306a36Sopenharmony_ci{ 78462306a36Sopenharmony_ci return (pte->val & 3) != 0; 78562306a36Sopenharmony_ci} 78662306a36Sopenharmony_ci 78762306a36Sopenharmony_cistatic inline bool dma_pte_superpage(struct dma_pte *pte) 78862306a36Sopenharmony_ci{ 78962306a36Sopenharmony_ci return (pte->val & DMA_PTE_LARGE_PAGE); 79062306a36Sopenharmony_ci} 79162306a36Sopenharmony_ci 79262306a36Sopenharmony_cistatic inline bool first_pte_in_page(struct dma_pte *pte) 79362306a36Sopenharmony_ci{ 79462306a36Sopenharmony_ci return IS_ALIGNED((unsigned long)pte, VTD_PAGE_SIZE); 79562306a36Sopenharmony_ci} 79662306a36Sopenharmony_ci 79762306a36Sopenharmony_cistatic inline int nr_pte_to_next_page(struct dma_pte *pte) 79862306a36Sopenharmony_ci{ 79962306a36Sopenharmony_ci return first_pte_in_page(pte) ? BIT_ULL(VTD_STRIDE_SHIFT) : 80062306a36Sopenharmony_ci (struct dma_pte *)ALIGN((unsigned long)pte, VTD_PAGE_SIZE) - pte; 80162306a36Sopenharmony_ci} 80262306a36Sopenharmony_ci 80362306a36Sopenharmony_cistatic inline bool context_present(struct context_entry *context) 80462306a36Sopenharmony_ci{ 80562306a36Sopenharmony_ci return (context->lo & 1); 80662306a36Sopenharmony_ci} 80762306a36Sopenharmony_ci 80862306a36Sopenharmony_cistruct dmar_drhd_unit *dmar_find_matched_drhd_unit(struct pci_dev *dev); 80962306a36Sopenharmony_ci 81062306a36Sopenharmony_ciint dmar_enable_qi(struct intel_iommu *iommu); 81162306a36Sopenharmony_civoid dmar_disable_qi(struct intel_iommu *iommu); 81262306a36Sopenharmony_ciint dmar_reenable_qi(struct intel_iommu *iommu); 81362306a36Sopenharmony_civoid qi_global_iec(struct intel_iommu *iommu); 81462306a36Sopenharmony_ci 81562306a36Sopenharmony_civoid qi_flush_context(struct intel_iommu *iommu, u16 did, 81662306a36Sopenharmony_ci u16 sid, u8 fm, u64 type); 81762306a36Sopenharmony_civoid qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr, 81862306a36Sopenharmony_ci unsigned int size_order, u64 type); 81962306a36Sopenharmony_civoid qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid, 82062306a36Sopenharmony_ci u16 qdep, u64 addr, unsigned mask); 82162306a36Sopenharmony_ci 82262306a36Sopenharmony_civoid qi_flush_piotlb(struct intel_iommu *iommu, u16 did, u32 pasid, u64 addr, 82362306a36Sopenharmony_ci unsigned long npages, bool ih); 82462306a36Sopenharmony_ci 82562306a36Sopenharmony_civoid qi_flush_dev_iotlb_pasid(struct intel_iommu *iommu, u16 sid, u16 pfsid, 82662306a36Sopenharmony_ci u32 pasid, u16 qdep, u64 addr, 82762306a36Sopenharmony_ci unsigned int size_order); 82862306a36Sopenharmony_civoid quirk_extra_dev_tlb_flush(struct device_domain_info *info, 82962306a36Sopenharmony_ci unsigned long address, unsigned long pages, 83062306a36Sopenharmony_ci u32 pasid, u16 qdep); 83162306a36Sopenharmony_civoid qi_flush_pasid_cache(struct intel_iommu *iommu, u16 did, u64 granu, 83262306a36Sopenharmony_ci u32 pasid); 83362306a36Sopenharmony_ci 83462306a36Sopenharmony_ciint qi_submit_sync(struct intel_iommu *iommu, struct qi_desc *desc, 83562306a36Sopenharmony_ci unsigned int count, unsigned long options); 83662306a36Sopenharmony_ci/* 83762306a36Sopenharmony_ci * Options used in qi_submit_sync: 83862306a36Sopenharmony_ci * QI_OPT_WAIT_DRAIN - Wait for PRQ drain completion, spec 6.5.2.8. 83962306a36Sopenharmony_ci */ 84062306a36Sopenharmony_ci#define QI_OPT_WAIT_DRAIN BIT(0) 84162306a36Sopenharmony_ci 84262306a36Sopenharmony_ciint dmar_ir_support(void); 84362306a36Sopenharmony_ci 84462306a36Sopenharmony_civoid *alloc_pgtable_page(int node, gfp_t gfp); 84562306a36Sopenharmony_civoid free_pgtable_page(void *vaddr); 84662306a36Sopenharmony_civoid iommu_flush_write_buffer(struct intel_iommu *iommu); 84762306a36Sopenharmony_cistruct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn); 84862306a36Sopenharmony_ci 84962306a36Sopenharmony_ci#ifdef CONFIG_INTEL_IOMMU_SVM 85062306a36Sopenharmony_civoid intel_svm_check(struct intel_iommu *iommu); 85162306a36Sopenharmony_ciint intel_svm_enable_prq(struct intel_iommu *iommu); 85262306a36Sopenharmony_ciint intel_svm_finish_prq(struct intel_iommu *iommu); 85362306a36Sopenharmony_ciint intel_svm_page_response(struct device *dev, struct iommu_fault_event *evt, 85462306a36Sopenharmony_ci struct iommu_page_response *msg); 85562306a36Sopenharmony_cistruct iommu_domain *intel_svm_domain_alloc(void); 85662306a36Sopenharmony_civoid intel_svm_remove_dev_pasid(struct device *dev, ioasid_t pasid); 85762306a36Sopenharmony_civoid intel_drain_pasid_prq(struct device *dev, u32 pasid); 85862306a36Sopenharmony_ci 85962306a36Sopenharmony_cistruct intel_svm_dev { 86062306a36Sopenharmony_ci struct list_head list; 86162306a36Sopenharmony_ci struct rcu_head rcu; 86262306a36Sopenharmony_ci struct device *dev; 86362306a36Sopenharmony_ci struct intel_iommu *iommu; 86462306a36Sopenharmony_ci u16 did; 86562306a36Sopenharmony_ci u16 sid, qdep; 86662306a36Sopenharmony_ci}; 86762306a36Sopenharmony_ci 86862306a36Sopenharmony_cistruct intel_svm { 86962306a36Sopenharmony_ci struct mmu_notifier notifier; 87062306a36Sopenharmony_ci struct mm_struct *mm; 87162306a36Sopenharmony_ci u32 pasid; 87262306a36Sopenharmony_ci struct list_head devs; 87362306a36Sopenharmony_ci}; 87462306a36Sopenharmony_ci#else 87562306a36Sopenharmony_cistatic inline void intel_svm_check(struct intel_iommu *iommu) {} 87662306a36Sopenharmony_cistatic inline void intel_drain_pasid_prq(struct device *dev, u32 pasid) {} 87762306a36Sopenharmony_cistatic inline struct iommu_domain *intel_svm_domain_alloc(void) 87862306a36Sopenharmony_ci{ 87962306a36Sopenharmony_ci return NULL; 88062306a36Sopenharmony_ci} 88162306a36Sopenharmony_ci 88262306a36Sopenharmony_cistatic inline void intel_svm_remove_dev_pasid(struct device *dev, ioasid_t pasid) 88362306a36Sopenharmony_ci{ 88462306a36Sopenharmony_ci} 88562306a36Sopenharmony_ci#endif 88662306a36Sopenharmony_ci 88762306a36Sopenharmony_ci#ifdef CONFIG_INTEL_IOMMU_DEBUGFS 88862306a36Sopenharmony_civoid intel_iommu_debugfs_init(void); 88962306a36Sopenharmony_ci#else 89062306a36Sopenharmony_cistatic inline void intel_iommu_debugfs_init(void) {} 89162306a36Sopenharmony_ci#endif /* CONFIG_INTEL_IOMMU_DEBUGFS */ 89262306a36Sopenharmony_ci 89362306a36Sopenharmony_ciextern const struct attribute_group *intel_iommu_groups[]; 89462306a36Sopenharmony_cistruct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus, 89562306a36Sopenharmony_ci u8 devfn, int alloc); 89662306a36Sopenharmony_ci 89762306a36Sopenharmony_ciextern const struct iommu_ops intel_iommu_ops; 89862306a36Sopenharmony_ci 89962306a36Sopenharmony_ci#ifdef CONFIG_INTEL_IOMMU 90062306a36Sopenharmony_ciextern int intel_iommu_sm; 90162306a36Sopenharmony_ciint iommu_calculate_agaw(struct intel_iommu *iommu); 90262306a36Sopenharmony_ciint iommu_calculate_max_sagaw(struct intel_iommu *iommu); 90362306a36Sopenharmony_ciint ecmd_submit_sync(struct intel_iommu *iommu, u8 ecmd, u64 oa, u64 ob); 90462306a36Sopenharmony_ci 90562306a36Sopenharmony_cistatic inline bool ecmd_has_pmu_essential(struct intel_iommu *iommu) 90662306a36Sopenharmony_ci{ 90762306a36Sopenharmony_ci return (iommu->ecmdcap[DMA_ECMD_ECCAP3] & DMA_ECMD_ECCAP3_ESSENTIAL) == 90862306a36Sopenharmony_ci DMA_ECMD_ECCAP3_ESSENTIAL; 90962306a36Sopenharmony_ci} 91062306a36Sopenharmony_ci 91162306a36Sopenharmony_ciextern int dmar_disabled; 91262306a36Sopenharmony_ciextern int intel_iommu_enabled; 91362306a36Sopenharmony_ci#else 91462306a36Sopenharmony_cistatic inline int iommu_calculate_agaw(struct intel_iommu *iommu) 91562306a36Sopenharmony_ci{ 91662306a36Sopenharmony_ci return 0; 91762306a36Sopenharmony_ci} 91862306a36Sopenharmony_cistatic inline int iommu_calculate_max_sagaw(struct intel_iommu *iommu) 91962306a36Sopenharmony_ci{ 92062306a36Sopenharmony_ci return 0; 92162306a36Sopenharmony_ci} 92262306a36Sopenharmony_ci#define dmar_disabled (1) 92362306a36Sopenharmony_ci#define intel_iommu_enabled (0) 92462306a36Sopenharmony_ci#define intel_iommu_sm (0) 92562306a36Sopenharmony_ci#endif 92662306a36Sopenharmony_ci 92762306a36Sopenharmony_cistatic inline const char *decode_prq_descriptor(char *str, size_t size, 92862306a36Sopenharmony_ci u64 dw0, u64 dw1, u64 dw2, u64 dw3) 92962306a36Sopenharmony_ci{ 93062306a36Sopenharmony_ci char *buf = str; 93162306a36Sopenharmony_ci int bytes; 93262306a36Sopenharmony_ci 93362306a36Sopenharmony_ci bytes = snprintf(buf, size, 93462306a36Sopenharmony_ci "rid=0x%llx addr=0x%llx %c%c%c%c%c pasid=0x%llx index=0x%llx", 93562306a36Sopenharmony_ci FIELD_GET(GENMASK_ULL(31, 16), dw0), 93662306a36Sopenharmony_ci FIELD_GET(GENMASK_ULL(63, 12), dw1), 93762306a36Sopenharmony_ci dw1 & BIT_ULL(0) ? 'r' : '-', 93862306a36Sopenharmony_ci dw1 & BIT_ULL(1) ? 'w' : '-', 93962306a36Sopenharmony_ci dw0 & BIT_ULL(52) ? 'x' : '-', 94062306a36Sopenharmony_ci dw0 & BIT_ULL(53) ? 'p' : '-', 94162306a36Sopenharmony_ci dw1 & BIT_ULL(2) ? 'l' : '-', 94262306a36Sopenharmony_ci FIELD_GET(GENMASK_ULL(51, 32), dw0), 94362306a36Sopenharmony_ci FIELD_GET(GENMASK_ULL(11, 3), dw1)); 94462306a36Sopenharmony_ci 94562306a36Sopenharmony_ci /* Private Data */ 94662306a36Sopenharmony_ci if (dw0 & BIT_ULL(9)) { 94762306a36Sopenharmony_ci size -= bytes; 94862306a36Sopenharmony_ci buf += bytes; 94962306a36Sopenharmony_ci snprintf(buf, size, " private=0x%llx/0x%llx\n", dw2, dw3); 95062306a36Sopenharmony_ci } 95162306a36Sopenharmony_ci 95262306a36Sopenharmony_ci return str; 95362306a36Sopenharmony_ci} 95462306a36Sopenharmony_ci 95562306a36Sopenharmony_ci#endif 956