186be9f0dSKonstantin Belousov /*- 24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3ebf5747bSPedro F. Giffuni * 4e17c0a1eSKonstantin Belousov * Copyright (c) 2013-2015 The FreeBSD Foundation 586be9f0dSKonstantin Belousov * 686be9f0dSKonstantin Belousov * This software was developed by Konstantin Belousov <kib@FreeBSD.org> 786be9f0dSKonstantin Belousov * under sponsorship from the FreeBSD Foundation. 886be9f0dSKonstantin Belousov * 986be9f0dSKonstantin Belousov * Redistribution and use in source and binary forms, with or without 1086be9f0dSKonstantin Belousov * modification, are permitted provided that the following conditions 1186be9f0dSKonstantin Belousov * are met: 1286be9f0dSKonstantin Belousov * 1. Redistributions of source code must retain the above copyright 1386be9f0dSKonstantin Belousov * notice, this list of conditions and the following disclaimer. 1486be9f0dSKonstantin Belousov * 2. Redistributions in binary form must reproduce the above copyright 1586be9f0dSKonstantin Belousov * notice, this list of conditions and the following disclaimer in the 1686be9f0dSKonstantin Belousov * documentation and/or other materials provided with the distribution. 1786be9f0dSKonstantin Belousov * 1886be9f0dSKonstantin Belousov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1986be9f0dSKonstantin Belousov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2086be9f0dSKonstantin Belousov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2186be9f0dSKonstantin Belousov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2286be9f0dSKonstantin Belousov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2386be9f0dSKonstantin Belousov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2486be9f0dSKonstantin Belousov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2586be9f0dSKonstantin Belousov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2686be9f0dSKonstantin Belousov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2786be9f0dSKonstantin Belousov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2886be9f0dSKonstantin Belousov * SUCH DAMAGE. 2986be9f0dSKonstantin Belousov */ 3086be9f0dSKonstantin Belousov 3186be9f0dSKonstantin Belousov #ifndef __X86_IOMMU_INTEL_REG_H 3286be9f0dSKonstantin Belousov #define __X86_IOMMU_INTEL_REG_H 3386be9f0dSKonstantin Belousov 3486be9f0dSKonstantin Belousov typedef struct dmar_root_entry { 3586be9f0dSKonstantin Belousov uint64_t r1; 3686be9f0dSKonstantin Belousov uint64_t r2; 3786be9f0dSKonstantin Belousov } dmar_root_entry_t; 3886be9f0dSKonstantin Belousov #define DMAR_ROOT_R1_P 1 /* Present */ 3986be9f0dSKonstantin Belousov #define DMAR_ROOT_R1_CTP_MASK 0xfffffffffffff000 /* Mask for Context-Entry 4086be9f0dSKonstantin Belousov Table Pointer */ 4186be9f0dSKonstantin Belousov 42*40d951bcSKonstantin Belousov #define DMAR_CTX_CNT (IOMMU_PAGE_SIZE / sizeof(dmar_root_entry_t)) 4386be9f0dSKonstantin Belousov 4486be9f0dSKonstantin Belousov typedef struct dmar_ctx_entry { 4586be9f0dSKonstantin Belousov uint64_t ctx1; 4686be9f0dSKonstantin Belousov uint64_t ctx2; 4786be9f0dSKonstantin Belousov } dmar_ctx_entry_t; 4886be9f0dSKonstantin Belousov #define DMAR_CTX1_P 1 /* Present */ 4986be9f0dSKonstantin Belousov #define DMAR_CTX1_FPD 2 /* Fault Processing Disable */ 5086be9f0dSKonstantin Belousov /* Translation Type: */ 5186be9f0dSKonstantin Belousov #define DMAR_CTX1_T_UNTR 0 /* only Untranslated */ 5286be9f0dSKonstantin Belousov #define DMAR_CTX1_T_TR 4 /* both Untranslated 5386be9f0dSKonstantin Belousov and Translated */ 5486be9f0dSKonstantin Belousov #define DMAR_CTX1_T_PASS 8 /* Pass-Through */ 5586be9f0dSKonstantin Belousov #define DMAR_CTX1_ASR_MASK 0xfffffffffffff000 /* Mask for the Address 5686be9f0dSKonstantin Belousov Space Root */ 5786be9f0dSKonstantin Belousov #define DMAR_CTX2_AW_2LVL 0 /* 2-level page tables */ 5886be9f0dSKonstantin Belousov #define DMAR_CTX2_AW_3LVL 1 /* 3-level page tables */ 5986be9f0dSKonstantin Belousov #define DMAR_CTX2_AW_4LVL 2 /* 4-level page tables */ 6086be9f0dSKonstantin Belousov #define DMAR_CTX2_AW_5LVL 3 /* 5-level page tables */ 6186be9f0dSKonstantin Belousov #define DMAR_CTX2_AW_6LVL 4 /* 6-level page tables */ 62264cd108SJohn Baldwin #define DMAR_CTX2_DID_MASK 0xffff0 6386be9f0dSKonstantin Belousov #define DMAR_CTX2_DID(x) ((x) << 8) /* Domain Identifier */ 64264cd108SJohn Baldwin #define DMAR_CTX2_GET_DID(ctx2) (((ctx2) & DMAR_CTX2_DID_MASK) >> 8) 6586be9f0dSKonstantin Belousov 6686be9f0dSKonstantin Belousov #define DMAR_PTE_R 1 /* Read */ 6786be9f0dSKonstantin Belousov #define DMAR_PTE_W (1 << 1) /* Write */ 6886be9f0dSKonstantin Belousov #define DMAR_PTE_SP (1 << 7) /* Super Page */ 6986be9f0dSKonstantin Belousov #define DMAR_PTE_SNP (1 << 11) /* Snoop Behaviour */ 7086be9f0dSKonstantin Belousov #define DMAR_PTE_ADDR_MASK 0xffffffffff000 /* Address Mask */ 7186be9f0dSKonstantin Belousov #define DMAR_PTE_TM (1ULL << 62) /* Transient Mapping */ 7286be9f0dSKonstantin Belousov 73e17c0a1eSKonstantin Belousov typedef struct dmar_irte { 74e17c0a1eSKonstantin Belousov uint64_t irte1; 75e17c0a1eSKonstantin Belousov uint64_t irte2; 76e17c0a1eSKonstantin Belousov } dmar_irte_t; 77e17c0a1eSKonstantin Belousov /* Source Validation Type */ 78e17c0a1eSKonstantin Belousov #define DMAR_IRTE2_SVT_NONE (0ULL << (82 - 64)) 79e17c0a1eSKonstantin Belousov #define DMAR_IRTE2_SVT_RID (1ULL << (82 - 64)) 80e17c0a1eSKonstantin Belousov #define DMAR_IRTE2_SVT_BUS (2ULL << (82 - 64)) 81e17c0a1eSKonstantin Belousov /* Source-id Qualifier */ 82e17c0a1eSKonstantin Belousov #define DMAR_IRTE2_SQ_RID (0ULL << (80 - 64)) 83e17c0a1eSKonstantin Belousov #define DMAR_IRTE2_SQ_RID_N2 (1ULL << (80 - 64)) 84e17c0a1eSKonstantin Belousov #define DMAR_IRTE2_SQ_RID_N21 (2ULL << (80 - 64)) 85e17c0a1eSKonstantin Belousov #define DMAR_IRTE2_SQ_RID_N210 (3ULL << (80 - 64)) 86e17c0a1eSKonstantin Belousov /* Source Identifier */ 87e17c0a1eSKonstantin Belousov #define DMAR_IRTE2_SID_RID(x) ((uint64_t)(x)) 88e17c0a1eSKonstantin Belousov #define DMAR_IRTE2_SID_BUS(start, end) ((((uint64_t)(start)) << 8) | (end)) 89e17c0a1eSKonstantin Belousov /* Destination Id */ 90e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_DST_xAPIC(x) (((uint64_t)(x)) << 40) 91e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_DST_x2APIC(x) (((uint64_t)(x)) << 32) 92e17c0a1eSKonstantin Belousov /* Vector */ 93e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_V(x) (((uint64_t)x) << 16) 94e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_IM_POSTED (1ULL << 15) /* Posted */ 95e17c0a1eSKonstantin Belousov /* Delivery Mode */ 96e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_DLM_FM (0ULL << 5) 970f5830b0SKonstantin Belousov #define DMAR_IRTE1_DLM_LP (1ULL << 5) 98e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_DLM_SMI (2ULL << 5) 99e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_DLM_NMI (4ULL << 5) 100e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_DLM_INIT (5ULL << 5) 101e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_DLM_ExtINT (7ULL << 5) 102e17c0a1eSKonstantin Belousov /* Trigger Mode */ 103e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_TM_EDGE (0ULL << 4) 104e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_TM_LEVEL (1ULL << 4) 105e17c0a1eSKonstantin Belousov /* Redirection Hint */ 106e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_RH_DIRECT (0ULL << 3) 107e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_RH_SELECT (1ULL << 3) 108e17c0a1eSKonstantin Belousov /* Destination Mode */ 109e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_DM_PHYSICAL (0ULL << 2) 110e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_DM_LOGICAL (1ULL << 2) 111e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_FPD (1ULL << 1) /* Fault Processing Disable */ 112e17c0a1eSKonstantin Belousov #define DMAR_IRTE1_P (1ULL) /* Present */ 113e17c0a1eSKonstantin Belousov 11486be9f0dSKonstantin Belousov /* Version register */ 11586be9f0dSKonstantin Belousov #define DMAR_VER_REG 0 11686be9f0dSKonstantin Belousov #define DMAR_MAJOR_VER(x) (((x) >> 4) & 0xf) 11786be9f0dSKonstantin Belousov #define DMAR_MINOR_VER(x) ((x) & 0xf) 11886be9f0dSKonstantin Belousov 11986be9f0dSKonstantin Belousov /* Capabilities register */ 12086be9f0dSKonstantin Belousov #define DMAR_CAP_REG 0x8 121e17c0a1eSKonstantin Belousov #define DMAR_CAP_PI (1ULL << 59) /* Posted Interrupts */ 122e17c0a1eSKonstantin Belousov #define DMAR_CAP_FL1GP (1ULL << 56) /* First Level 1GByte Page */ 12386be9f0dSKonstantin Belousov #define DMAR_CAP_DRD (1ULL << 55) /* DMA Read Draining */ 12486be9f0dSKonstantin Belousov #define DMAR_CAP_DWD (1ULL << 54) /* DMA Write Draining */ 12586be9f0dSKonstantin Belousov #define DMAR_CAP_MAMV(x) ((u_int)(((x) >> 48) & 0x3f)) 12686be9f0dSKonstantin Belousov /* Maximum Address Mask */ 12786be9f0dSKonstantin Belousov #define DMAR_CAP_NFR(x) ((u_int)(((x) >> 40) & 0xff) + 1) 12886be9f0dSKonstantin Belousov /* Num of Fault-recording regs */ 12986be9f0dSKonstantin Belousov #define DMAR_CAP_PSI (1ULL << 39) /* Page Selective Invalidation */ 13086be9f0dSKonstantin Belousov #define DMAR_CAP_SPS(x) ((u_int)(((x) >> 34) & 0xf)) /* Super-Page Support */ 13186be9f0dSKonstantin Belousov #define DMAR_CAP_SPS_2M 0x1 13286be9f0dSKonstantin Belousov #define DMAR_CAP_SPS_1G 0x2 13386be9f0dSKonstantin Belousov #define DMAR_CAP_SPS_512G 0x4 13486be9f0dSKonstantin Belousov #define DMAR_CAP_SPS_1T 0x8 13586be9f0dSKonstantin Belousov #define DMAR_CAP_FRO(x) ((u_int)(((x) >> 24) & 0x1ff)) 13686be9f0dSKonstantin Belousov /* Fault-recording reg offset */ 13786be9f0dSKonstantin Belousov #define DMAR_CAP_ISOCH (1 << 23) /* Isochrony */ 13886be9f0dSKonstantin Belousov #define DMAR_CAP_ZLR (1 << 22) /* Zero-length reads */ 13986be9f0dSKonstantin Belousov #define DMAR_CAP_MGAW(x) ((u_int)(((x) >> 16) & 0x3f)) 14086be9f0dSKonstantin Belousov /* Max Guest Address Width */ 14186be9f0dSKonstantin Belousov #define DMAR_CAP_SAGAW(x) ((u_int)(((x) >> 8) & 0x1f)) 14286be9f0dSKonstantin Belousov /* Adjusted Guest Address Width */ 14386be9f0dSKonstantin Belousov #define DMAR_CAP_SAGAW_2LVL 0x01 14486be9f0dSKonstantin Belousov #define DMAR_CAP_SAGAW_3LVL 0x02 14586be9f0dSKonstantin Belousov #define DMAR_CAP_SAGAW_4LVL 0x04 14686be9f0dSKonstantin Belousov #define DMAR_CAP_SAGAW_5LVL 0x08 14786be9f0dSKonstantin Belousov #define DMAR_CAP_SAGAW_6LVL 0x10 14886be9f0dSKonstantin Belousov #define DMAR_CAP_CM (1 << 7) /* Caching mode */ 14986be9f0dSKonstantin Belousov #define DMAR_CAP_PHMR (1 << 6) /* Protected High-mem Region */ 15086be9f0dSKonstantin Belousov #define DMAR_CAP_PLMR (1 << 5) /* Protected Low-mem Region */ 15186be9f0dSKonstantin Belousov #define DMAR_CAP_RWBF (1 << 4) /* Required Write-Buffer Flushing */ 15286be9f0dSKonstantin Belousov #define DMAR_CAP_AFL (1 << 3) /* Advanced Fault Logging */ 15386be9f0dSKonstantin Belousov #define DMAR_CAP_ND(x) ((u_int)((x) & 0x3)) /* Number of domains */ 15486be9f0dSKonstantin Belousov 15586be9f0dSKonstantin Belousov /* Extended Capabilities register */ 15686be9f0dSKonstantin Belousov #define DMAR_ECAP_REG 0x10 157e17c0a1eSKonstantin Belousov #define DMAR_ECAP_PSS(x) (((x) >> 35) & 0xf) /* PASID Size Supported */ 158e17c0a1eSKonstantin Belousov #define DMAR_ECAP_EAFS (1ULL << 34) /* Extended Accessed Flag */ 159e17c0a1eSKonstantin Belousov #define DMAR_ECAP_NWFS (1ULL << 33) /* No Write Flag */ 160e17c0a1eSKonstantin Belousov #define DMAR_ECAP_SRS (1ULL << 31) /* Supervisor Request */ 161e17c0a1eSKonstantin Belousov #define DMAR_ECAP_ERS (1ULL << 30) /* Execute Request */ 162e17c0a1eSKonstantin Belousov #define DMAR_ECAP_PRS (1ULL << 29) /* Page Request */ 163e17c0a1eSKonstantin Belousov #define DMAR_ECAP_PASID (1ULL << 28) /* Process Address Space Id */ 164e17c0a1eSKonstantin Belousov #define DMAR_ECAP_DIS (1ULL << 27) /* Deferred Invalidate */ 165e17c0a1eSKonstantin Belousov #define DMAR_ECAP_NEST (1ULL << 26) /* Nested Translation */ 166e17c0a1eSKonstantin Belousov #define DMAR_ECAP_MTS (1ULL << 25) /* Memory Type */ 167e17c0a1eSKonstantin Belousov #define DMAR_ECAP_ECS (1ULL << 24) /* Extended Context */ 16886be9f0dSKonstantin Belousov #define DMAR_ECAP_MHMV(x) ((u_int)(((x) >> 20) & 0xf)) 16986be9f0dSKonstantin Belousov /* Maximum Handle Mask Value */ 17086be9f0dSKonstantin Belousov #define DMAR_ECAP_IRO(x) ((u_int)(((x) >> 8) & 0x3ff)) 17186be9f0dSKonstantin Belousov /* IOTLB Register Offset */ 17286be9f0dSKonstantin Belousov #define DMAR_ECAP_SC (1 << 7) /* Snoop Control */ 17386be9f0dSKonstantin Belousov #define DMAR_ECAP_PT (1 << 6) /* Pass Through */ 174dcc33b0aSKonstantin Belousov #define DMAR_ECAP_EIM (1 << 4) /* Extended Interrupt Mode (x2APIC) */ 17586be9f0dSKonstantin Belousov #define DMAR_ECAP_IR (1 << 3) /* Interrupt Remapping */ 17686be9f0dSKonstantin Belousov #define DMAR_ECAP_DI (1 << 2) /* Device IOTLB */ 17786be9f0dSKonstantin Belousov #define DMAR_ECAP_QI (1 << 1) /* Queued Invalidation */ 17886be9f0dSKonstantin Belousov #define DMAR_ECAP_C (1 << 0) /* Coherency */ 17986be9f0dSKonstantin Belousov 18086be9f0dSKonstantin Belousov /* Global Command register */ 18186be9f0dSKonstantin Belousov #define DMAR_GCMD_REG 0x18 1827a22215cSEitan Adler #define DMAR_GCMD_TE (1U << 31) /* Translation Enable */ 18386be9f0dSKonstantin Belousov #define DMAR_GCMD_SRTP (1 << 30) /* Set Root Table Pointer */ 18486be9f0dSKonstantin Belousov #define DMAR_GCMD_SFL (1 << 29) /* Set Fault Log */ 18586be9f0dSKonstantin Belousov #define DMAR_GCMD_EAFL (1 << 28) /* Enable Advanced Fault Logging */ 18686be9f0dSKonstantin Belousov #define DMAR_GCMD_WBF (1 << 27) /* Write Buffer Flush */ 18786be9f0dSKonstantin Belousov #define DMAR_GCMD_QIE (1 << 26) /* Queued Invalidation Enable */ 18886be9f0dSKonstantin Belousov #define DMAR_GCMD_IRE (1 << 25) /* Interrupt Remapping Enable */ 18986be9f0dSKonstantin Belousov #define DMAR_GCMD_SIRTP (1 << 24) /* Set Interrupt Remap Table Pointer */ 19086be9f0dSKonstantin Belousov #define DMAR_GCMD_CFI (1 << 23) /* Compatibility Format Interrupt */ 19186be9f0dSKonstantin Belousov 19286be9f0dSKonstantin Belousov /* Global Status register */ 19386be9f0dSKonstantin Belousov #define DMAR_GSTS_REG 0x1c 1947a22215cSEitan Adler #define DMAR_GSTS_TES (1U << 31) /* Translation Enable Status */ 19586be9f0dSKonstantin Belousov #define DMAR_GSTS_RTPS (1 << 30) /* Root Table Pointer Status */ 19686be9f0dSKonstantin Belousov #define DMAR_GSTS_FLS (1 << 29) /* Fault Log Status */ 19786be9f0dSKonstantin Belousov #define DMAR_GSTS_AFLS (1 << 28) /* Advanced Fault Logging Status */ 19886be9f0dSKonstantin Belousov #define DMAR_GSTS_WBFS (1 << 27) /* Write Buffer Flush Status */ 19986be9f0dSKonstantin Belousov #define DMAR_GSTS_QIES (1 << 26) /* Queued Invalidation Enable Status */ 20086be9f0dSKonstantin Belousov #define DMAR_GSTS_IRES (1 << 25) /* Interrupt Remapping Enable Status */ 20186be9f0dSKonstantin Belousov #define DMAR_GSTS_IRTPS (1 << 24) /* Interrupt Remapping Table 20286be9f0dSKonstantin Belousov Pointer Status */ 20386be9f0dSKonstantin Belousov #define DMAR_GSTS_CFIS (1 << 23) /* Compatibility Format 20486be9f0dSKonstantin Belousov Interrupt Status */ 20586be9f0dSKonstantin Belousov 20686be9f0dSKonstantin Belousov /* Root-Entry Table Address register */ 20786be9f0dSKonstantin Belousov #define DMAR_RTADDR_REG 0x20 208264cd108SJohn Baldwin #define DMAR_RTADDR_RTT (1 << 11) /* Root Table Type */ 209264cd108SJohn Baldwin #define DMAR_RTADDR_RTA_MASK 0xfffffffffffff000 21086be9f0dSKonstantin Belousov 21186be9f0dSKonstantin Belousov /* Context Command register */ 21286be9f0dSKonstantin Belousov #define DMAR_CCMD_REG 0x28 21386be9f0dSKonstantin Belousov #define DMAR_CCMD_ICC (1ULL << 63) /* Invalidate Context-Cache */ 2147a22215cSEitan Adler #define DMAR_CCMD_ICC32 (1U << 31) 21586be9f0dSKonstantin Belousov #define DMAR_CCMD_CIRG_MASK (0x3ULL << 61) /* Context Invalidation 21686be9f0dSKonstantin Belousov Request Granularity */ 21786be9f0dSKonstantin Belousov #define DMAR_CCMD_CIRG_GLOB (0x1ULL << 61) /* Global */ 21886be9f0dSKonstantin Belousov #define DMAR_CCMD_CIRG_DOM (0x2ULL << 61) /* Domain */ 21986be9f0dSKonstantin Belousov #define DMAR_CCMD_CIRG_DEV (0x3ULL << 61) /* Device */ 22086be9f0dSKonstantin Belousov #define DMAR_CCMD_CAIG(x) (((x) >> 59) & 0x3) /* Context Actual 22186be9f0dSKonstantin Belousov Invalidation Granularity */ 22286be9f0dSKonstantin Belousov #define DMAR_CCMD_CAIG_GLOB 0x1 /* Global */ 22386be9f0dSKonstantin Belousov #define DMAR_CCMD_CAIG_DOM 0x2 /* Domain */ 22486be9f0dSKonstantin Belousov #define DMAR_CCMD_CAIG_DEV 0x3 /* Device */ 22586be9f0dSKonstantin Belousov #define DMAR_CCMD_FM (0x3UUL << 32) /* Function Mask */ 22686be9f0dSKonstantin Belousov #define DMAR_CCMD_SID(x) (((x) & 0xffff) << 16) /* Source-ID */ 22786be9f0dSKonstantin Belousov #define DMAR_CCMD_DID(x) ((x) & 0xffff) /* Domain-ID */ 22886be9f0dSKonstantin Belousov 22986be9f0dSKonstantin Belousov /* Invalidate Address register */ 23086be9f0dSKonstantin Belousov #define DMAR_IVA_REG_OFF 0 23186be9f0dSKonstantin Belousov #define DMAR_IVA_IH (1 << 6) /* Invalidation Hint */ 23286be9f0dSKonstantin Belousov #define DMAR_IVA_AM(x) ((x) & 0x1f) /* Address Mask */ 23386be9f0dSKonstantin Belousov #define DMAR_IVA_ADDR(x) ((x) & ~0xfffULL) /* Address */ 23486be9f0dSKonstantin Belousov 23586be9f0dSKonstantin Belousov /* IOTLB Invalidate register */ 23686be9f0dSKonstantin Belousov #define DMAR_IOTLB_REG_OFF 0x8 23786be9f0dSKonstantin Belousov #define DMAR_IOTLB_IVT (1ULL << 63) /* Invalidate IOTLB */ 2387a22215cSEitan Adler #define DMAR_IOTLB_IVT32 (1U << 31) 23986be9f0dSKonstantin Belousov #define DMAR_IOTLB_IIRG_MASK (0x3ULL << 60) /* Invalidation Request 24086be9f0dSKonstantin Belousov Granularity */ 24186be9f0dSKonstantin Belousov #define DMAR_IOTLB_IIRG_GLB (0x1ULL << 60) /* Global */ 24286be9f0dSKonstantin Belousov #define DMAR_IOTLB_IIRG_DOM (0x2ULL << 60) /* Domain-selective */ 24386be9f0dSKonstantin Belousov #define DMAR_IOTLB_IIRG_PAGE (0x3ULL << 60) /* Page-selective */ 24486be9f0dSKonstantin Belousov #define DMAR_IOTLB_IAIG_MASK (0x3ULL << 57) /* Actual Invalidation 24586be9f0dSKonstantin Belousov Granularity */ 24686be9f0dSKonstantin Belousov #define DMAR_IOTLB_IAIG_INVLD 0 /* Hw detected error */ 24786be9f0dSKonstantin Belousov #define DMAR_IOTLB_IAIG_GLB (0x1ULL << 57) /* Global */ 24886be9f0dSKonstantin Belousov #define DMAR_IOTLB_IAIG_DOM (0x2ULL << 57) /* Domain-selective */ 24986be9f0dSKonstantin Belousov #define DMAR_IOTLB_IAIG_PAGE (0x3ULL << 57) /* Page-selective */ 25086be9f0dSKonstantin Belousov #define DMAR_IOTLB_DR (0x1ULL << 49) /* Drain Reads */ 25186be9f0dSKonstantin Belousov #define DMAR_IOTLB_DW (0x1ULL << 48) /* Drain Writes */ 25286be9f0dSKonstantin Belousov #define DMAR_IOTLB_DID(x) (((uint64_t)(x) & 0xffff) << 32) /* Domain Id */ 25386be9f0dSKonstantin Belousov 25486be9f0dSKonstantin Belousov /* Fault Status register */ 25586be9f0dSKonstantin Belousov #define DMAR_FSTS_REG 0x34 25686be9f0dSKonstantin Belousov #define DMAR_FSTS_FRI(x) (((x) >> 8) & 0xff) /* Fault Record Index */ 25786be9f0dSKonstantin Belousov #define DMAR_FSTS_ITE (1 << 6) /* Invalidation Time-out */ 25886be9f0dSKonstantin Belousov #define DMAR_FSTS_ICE (1 << 5) /* Invalidation Completion */ 25986be9f0dSKonstantin Belousov #define DMAR_FSTS_IQE (1 << 4) /* Invalidation Queue */ 26086be9f0dSKonstantin Belousov #define DMAR_FSTS_APF (1 << 3) /* Advanced Pending Fault */ 26186be9f0dSKonstantin Belousov #define DMAR_FSTS_AFO (1 << 2) /* Advanced Fault Overflow */ 26286be9f0dSKonstantin Belousov #define DMAR_FSTS_PPF (1 << 1) /* Primary Pending Fault */ 26386be9f0dSKonstantin Belousov #define DMAR_FSTS_PFO 1 /* Fault Overflow */ 26486be9f0dSKonstantin Belousov 26586be9f0dSKonstantin Belousov /* Fault Event Control register */ 26686be9f0dSKonstantin Belousov #define DMAR_FECTL_REG 0x38 2677a22215cSEitan Adler #define DMAR_FECTL_IM (1U << 31) /* Interrupt Mask */ 26886be9f0dSKonstantin Belousov #define DMAR_FECTL_IP (1 << 30) /* Interrupt Pending */ 26986be9f0dSKonstantin Belousov 27086be9f0dSKonstantin Belousov /* Fault Event Data register */ 27186be9f0dSKonstantin Belousov #define DMAR_FEDATA_REG 0x3c 27286be9f0dSKonstantin Belousov 27386be9f0dSKonstantin Belousov /* Fault Event Address register */ 27486be9f0dSKonstantin Belousov #define DMAR_FEADDR_REG 0x40 27586be9f0dSKonstantin Belousov 27686be9f0dSKonstantin Belousov /* Fault Event Upper Address register */ 27786be9f0dSKonstantin Belousov #define DMAR_FEUADDR_REG 0x44 27886be9f0dSKonstantin Belousov 27986be9f0dSKonstantin Belousov /* Advanced Fault Log register */ 28086be9f0dSKonstantin Belousov #define DMAR_AFLOG_REG 0x58 28186be9f0dSKonstantin Belousov 28286be9f0dSKonstantin Belousov /* Fault Recording Register, also usable for Advanced Fault Log records */ 28386be9f0dSKonstantin Belousov #define DMAR_FRCD2_F (1ULL << 63) /* Fault */ 2847a22215cSEitan Adler #define DMAR_FRCD2_F32 (1U << 31) 28586be9f0dSKonstantin Belousov #define DMAR_FRCD2_T(x) ((int)((x >> 62) & 1)) /* Type */ 28686be9f0dSKonstantin Belousov #define DMAR_FRCD2_T_W 0 /* Write request */ 28786be9f0dSKonstantin Belousov #define DMAR_FRCD2_T_R 1 /* Read or AtomicOp */ 28886be9f0dSKonstantin Belousov #define DMAR_FRCD2_AT(x) ((int)((x >> 60) & 0x3)) /* Address Type */ 28986be9f0dSKonstantin Belousov #define DMAR_FRCD2_FR(x) ((int)((x >> 32) & 0xff)) /* Fault Reason */ 29086be9f0dSKonstantin Belousov #define DMAR_FRCD2_SID(x) ((int)(x & 0xffff)) /* Source Identifier */ 29186be9f0dSKonstantin Belousov #define DMAR_FRCS1_FI_MASK 0xffffffffff000 /* Fault Info, Address Mask */ 29286be9f0dSKonstantin Belousov 29386be9f0dSKonstantin Belousov /* Protected Memory Enable register */ 29486be9f0dSKonstantin Belousov #define DMAR_PMEN_REG 0x64 2957a22215cSEitan Adler #define DMAR_PMEN_EPM (1U << 31) /* Enable Protected Memory */ 29686be9f0dSKonstantin Belousov #define DMAR_PMEN_PRS 1 /* Protected Region Status */ 29786be9f0dSKonstantin Belousov 29886be9f0dSKonstantin Belousov /* Protected Low-Memory Base register */ 29986be9f0dSKonstantin Belousov #define DMAR_PLMBASE_REG 0x68 30086be9f0dSKonstantin Belousov 30186be9f0dSKonstantin Belousov /* Protected Low-Memory Limit register */ 30286be9f0dSKonstantin Belousov #define DMAR_PLMLIMIT_REG 0x6c 30386be9f0dSKonstantin Belousov 30486be9f0dSKonstantin Belousov /* Protected High-Memory Base register */ 30586be9f0dSKonstantin Belousov #define DMAR_PHMBASE_REG 0x70 30686be9f0dSKonstantin Belousov 30786be9f0dSKonstantin Belousov /* Protected High-Memory Limit register */ 30886be9f0dSKonstantin Belousov #define DMAR_PHMLIMIT_REG 0x78 30986be9f0dSKonstantin Belousov 31068eeb96aSKonstantin Belousov /* Queued Invalidation Descriptors */ 31168eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_SZ_SHIFT 4 /* Shift for descriptor count 31268eeb96aSKonstantin Belousov to ring offset */ 31368eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_SZ (1 << DMAR_IQ_DESCR_SZ_SHIFT) 31468eeb96aSKonstantin Belousov /* Descriptor size */ 31568eeb96aSKonstantin Belousov 316dcc33b0aSKonstantin Belousov /* Context-cache Invalidate Descriptor */ 317dcc33b0aSKonstantin Belousov #define DMAR_IQ_DESCR_CTX_INV 0x1 31868eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_CTX_GLOB (0x1 << 4) /* Granularity: Global */ 31968eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_CTX_DOM (0x2 << 4) /* Granularity: Domain */ 32068eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_CTX_DEV (0x3 << 4) /* Granularity: Device */ 32168eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_CTX_DID(x) (((uint32_t)(x)) << 16) /* Domain Id */ 32268eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_CTX_SRC(x) (((uint64_t)(x)) << 32) /* Source Id */ 32368eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_CTX_FM(x) (((uint64_t)(x)) << 48) /* Function Mask */ 32468eeb96aSKonstantin Belousov 325dcc33b0aSKonstantin Belousov /* IOTLB Invalidate Descriptor */ 326dcc33b0aSKonstantin Belousov #define DMAR_IQ_DESCR_IOTLB_INV 0x2 32768eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_IOTLB_GLOB (0x1 << 4) /* Granularity: Global */ 32868eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_IOTLB_DOM (0x2 << 4) /* Granularity: Domain */ 32968eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_IOTLB_PAGE (0x3 << 4) /* Granularity: Page */ 33068eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_IOTLB_DW (1 << 6) /* Drain Writes */ 33168eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_IOTLB_DR (1 << 7) /* Drain Reads */ 33268eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_IOTLB_DID(x) (((uint32_t)(x)) << 16) /* Domain Id */ 33368eeb96aSKonstantin Belousov 334dcc33b0aSKonstantin Belousov /* Device-TLB Invalidate Descriptor */ 335dcc33b0aSKonstantin Belousov #define DMAR_IQ_DESCR_DTLB_INV 0x3 336dcc33b0aSKonstantin Belousov 337dcc33b0aSKonstantin Belousov /* Invalidate Interrupt Entry Cache */ 338dcc33b0aSKonstantin Belousov #define DMAR_IQ_DESCR_IEC_INV 0x4 339e17c0a1eSKonstantin Belousov #define DMAR_IQ_DESCR_IEC_IDX (1 << 4) /* Index-Selective Invalidation */ 340e17c0a1eSKonstantin Belousov #define DMAR_IQ_DESCR_IEC_IIDX(x) (((uint64_t)x) << 32) /* Interrupt Index */ 341e17c0a1eSKonstantin Belousov #define DMAR_IQ_DESCR_IEC_IM(x) ((x) << 27) /* Index Mask */ 342e17c0a1eSKonstantin Belousov 343dcc33b0aSKonstantin Belousov /* Invalidation Wait Descriptor */ 344dcc33b0aSKonstantin Belousov #define DMAR_IQ_DESCR_WAIT_ID 0x5 34568eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_WAIT_IF (1 << 4) /* Interrupt Flag */ 34668eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_WAIT_SW (1 << 5) /* Status Write */ 34768eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_WAIT_FN (1 << 6) /* Fence */ 34868eeb96aSKonstantin Belousov #define DMAR_IQ_DESCR_WAIT_SD(x) (((uint64_t)(x)) << 32) /* Status Data */ 34968eeb96aSKonstantin Belousov 350dcc33b0aSKonstantin Belousov /* Extended IOTLB Invalidate Descriptor */ 351dcc33b0aSKonstantin Belousov #define DMAR_IQ_DESCR_EIOTLB_INV 0x6 352dcc33b0aSKonstantin Belousov 353dcc33b0aSKonstantin Belousov /* PASID-Cache Invalidate Descriptor */ 354dcc33b0aSKonstantin Belousov #define DMAR_IQ_DESCR_PASIDC_INV 0x7 355dcc33b0aSKonstantin Belousov 356dcc33b0aSKonstantin Belousov /* Extended Device-TLB Invalidate Descriptor */ 357dcc33b0aSKonstantin Belousov #define DMAR_IQ_DESCR_EDTLB_INV 0x8 358dcc33b0aSKonstantin Belousov 35986be9f0dSKonstantin Belousov /* Invalidation Queue Head register */ 36086be9f0dSKonstantin Belousov #define DMAR_IQH_REG 0x80 36168eeb96aSKonstantin Belousov #define DMAR_IQH_MASK 0x7fff0 /* Next cmd index mask */ 36286be9f0dSKonstantin Belousov 36386be9f0dSKonstantin Belousov /* Invalidation Queue Tail register */ 36486be9f0dSKonstantin Belousov #define DMAR_IQT_REG 0x88 36568eeb96aSKonstantin Belousov #define DMAR_IQT_MASK 0x7fff0 36686be9f0dSKonstantin Belousov 36786be9f0dSKonstantin Belousov /* Invalidation Queue Address register */ 36886be9f0dSKonstantin Belousov #define DMAR_IQA_REG 0x90 36968eeb96aSKonstantin Belousov #define DMAR_IQA_IQA_MASK 0xfffffffffffff000 /* Invalidation Queue 37068eeb96aSKonstantin Belousov Base Address mask */ 37168eeb96aSKonstantin Belousov #define DMAR_IQA_QS_MASK 0x7 /* Queue Size in pages */ 37268eeb96aSKonstantin Belousov #define DMAR_IQA_QS_MAX 0x7 /* Max Queue size */ 37368eeb96aSKonstantin Belousov #define DMAR_IQA_QS_DEF 3 37486be9f0dSKonstantin Belousov 37586be9f0dSKonstantin Belousov /* Invalidation Completion Status register */ 37686be9f0dSKonstantin Belousov #define DMAR_ICS_REG 0x9c 37786be9f0dSKonstantin Belousov #define DMAR_ICS_IWC 1 /* Invalidation Wait 37886be9f0dSKonstantin Belousov Descriptor Complete */ 37986be9f0dSKonstantin Belousov 38086be9f0dSKonstantin Belousov /* Invalidation Event Control register */ 38186be9f0dSKonstantin Belousov #define DMAR_IECTL_REG 0xa0 3827a22215cSEitan Adler #define DMAR_IECTL_IM (1U << 31) /* Interrupt Mask */ 38386be9f0dSKonstantin Belousov #define DMAR_IECTL_IP (1 << 30) /* Interrupt Pending */ 38486be9f0dSKonstantin Belousov 38586be9f0dSKonstantin Belousov /* Invalidation Event Data register */ 38686be9f0dSKonstantin Belousov #define DMAR_IEDATA_REG 0xa4 38786be9f0dSKonstantin Belousov 38886be9f0dSKonstantin Belousov /* Invalidation Event Address register */ 38986be9f0dSKonstantin Belousov #define DMAR_IEADDR_REG 0xa8 39086be9f0dSKonstantin Belousov 39186be9f0dSKonstantin Belousov /* Invalidation Event Upper Address register */ 39286be9f0dSKonstantin Belousov #define DMAR_IEUADDR_REG 0xac 39386be9f0dSKonstantin Belousov 39486be9f0dSKonstantin Belousov /* Interrupt Remapping Table Address register */ 39586be9f0dSKonstantin Belousov #define DMAR_IRTA_REG 0xb8 396e17c0a1eSKonstantin Belousov #define DMAR_IRTA_EIME (1 << 11) /* Extended Interrupt Mode 397e17c0a1eSKonstantin Belousov Enable */ 398e17c0a1eSKonstantin Belousov #define DMAR_IRTA_S_MASK 0xf /* Size Mask */ 39986be9f0dSKonstantin Belousov 40086be9f0dSKonstantin Belousov #endif 401