1*08dbd0f8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 20b559df5SStephen Boyd /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. 30b559df5SStephen Boyd */ 40b559df5SStephen Boyd 50b559df5SStephen Boyd #ifndef MSM_IOMMU_H 60b559df5SStephen Boyd #define MSM_IOMMU_H 70b559df5SStephen Boyd 80b559df5SStephen Boyd #include <linux/interrupt.h> 942df43b3SJoerg Roedel #include <linux/iommu.h> 100b559df5SStephen Boyd #include <linux/clk.h> 110b559df5SStephen Boyd 120b559df5SStephen Boyd /* Sharability attributes of MSM IOMMU mappings */ 130b559df5SStephen Boyd #define MSM_IOMMU_ATTR_NON_SH 0x0 140b559df5SStephen Boyd #define MSM_IOMMU_ATTR_SH 0x4 150b559df5SStephen Boyd 160b559df5SStephen Boyd /* Cacheability attributes of MSM IOMMU mappings */ 170b559df5SStephen Boyd #define MSM_IOMMU_ATTR_NONCACHED 0x0 180b559df5SStephen Boyd #define MSM_IOMMU_ATTR_CACHED_WB_WA 0x1 190b559df5SStephen Boyd #define MSM_IOMMU_ATTR_CACHED_WB_NWA 0x2 200b559df5SStephen Boyd #define MSM_IOMMU_ATTR_CACHED_WT 0x3 210b559df5SStephen Boyd 220b559df5SStephen Boyd /* Mask for the cache policy attribute */ 230b559df5SStephen Boyd #define MSM_IOMMU_CP_MASK 0x03 240b559df5SStephen Boyd 250b559df5SStephen Boyd /* Maximum number of Machine IDs that we are allowing to be mapped to the same 260b559df5SStephen Boyd * context bank. The number of MIDs mapped to the same CB does not affect 270b559df5SStephen Boyd * performance, but there is a practical limit on how many distinct MIDs may 280b559df5SStephen Boyd * be present. These mappings are typically determined at design time and are 290b559df5SStephen Boyd * not expected to change at run time. 300b559df5SStephen Boyd */ 310b559df5SStephen Boyd #define MAX_NUM_MIDS 32 320b559df5SStephen Boyd 33109bd48eSSricharan R /* Maximum number of context banks that can be present in IOMMU */ 34109bd48eSSricharan R #define IOMMU_MAX_CBS 128 35109bd48eSSricharan R 360b559df5SStephen Boyd /** 370b559df5SStephen Boyd * struct msm_iommu_dev - a single IOMMU hardware instance 380b559df5SStephen Boyd * ncb Number of context banks present on this IOMMU HW instance 39109bd48eSSricharan R * dev: IOMMU device 40109bd48eSSricharan R * irq: Interrupt number 41109bd48eSSricharan R * clk: The bus clock for this IOMMU hardware instance 42109bd48eSSricharan R * pclk: The clock for the IOMMU bus interconnect 43109bd48eSSricharan R * dev_node: list head in qcom_iommu_device_list 44109bd48eSSricharan R * dom_node: list head for domain 45109bd48eSSricharan R * ctx_list: list of 'struct msm_iommu_ctx_dev' 46109bd48eSSricharan R * context_map: Bitmap to track allocated context banks 470b559df5SStephen Boyd */ 480b559df5SStephen Boyd struct msm_iommu_dev { 49109bd48eSSricharan R void __iomem *base; 500b559df5SStephen Boyd int ncb; 51109bd48eSSricharan R struct device *dev; 52109bd48eSSricharan R int irq; 53109bd48eSSricharan R struct clk *clk; 54109bd48eSSricharan R struct clk *pclk; 55109bd48eSSricharan R struct list_head dev_node; 56109bd48eSSricharan R struct list_head dom_node; 57109bd48eSSricharan R struct list_head ctx_list; 58109bd48eSSricharan R DECLARE_BITMAP(context_map, IOMMU_MAX_CBS); 5942df43b3SJoerg Roedel 6042df43b3SJoerg Roedel struct iommu_device iommu; 610b559df5SStephen Boyd }; 620b559df5SStephen Boyd 630b559df5SStephen Boyd /** 640b559df5SStephen Boyd * struct msm_iommu_ctx_dev - an IOMMU context bank instance 65109bd48eSSricharan R * of_node node ptr of client device 660b559df5SStephen Boyd * num Index of this context bank within the hardware 670b559df5SStephen Boyd * mids List of Machine IDs that are to be mapped into this context 680b559df5SStephen Boyd * bank, terminated by -1. The MID is a set of signals on the 690b559df5SStephen Boyd * AXI bus that identifies the function associated with a specific 700b559df5SStephen Boyd * memory request. (See ARM spec). 71109bd48eSSricharan R * num_mids Total number of mids 72109bd48eSSricharan R * node list head in ctx_list 730b559df5SStephen Boyd */ 740b559df5SStephen Boyd struct msm_iommu_ctx_dev { 75109bd48eSSricharan R struct device_node *of_node; 760b559df5SStephen Boyd int num; 770b559df5SStephen Boyd int mids[MAX_NUM_MIDS]; 78109bd48eSSricharan R int num_mids; 79109bd48eSSricharan R struct list_head list; 800b559df5SStephen Boyd }; 810b559df5SStephen Boyd 820b559df5SStephen Boyd /* 830b559df5SStephen Boyd * Interrupt handler for the IOMMU context fault interrupt. Hooking the 840b559df5SStephen Boyd * interrupt is not supported in the API yet, but this will print an error 850b559df5SStephen Boyd * message and dump useful IOMMU registers. 860b559df5SStephen Boyd */ 870b559df5SStephen Boyd irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id); 880b559df5SStephen Boyd 890b559df5SStephen Boyd #endif 90