18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. 38c2ecf20Sopenharmony_ci */ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#ifndef MSM_IOMMU_H 68c2ecf20Sopenharmony_ci#define MSM_IOMMU_H 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 98c2ecf20Sopenharmony_ci#include <linux/iommu.h> 108c2ecf20Sopenharmony_ci#include <linux/clk.h> 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* Sharability attributes of MSM IOMMU mappings */ 138c2ecf20Sopenharmony_ci#define MSM_IOMMU_ATTR_NON_SH 0x0 148c2ecf20Sopenharmony_ci#define MSM_IOMMU_ATTR_SH 0x4 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* Cacheability attributes of MSM IOMMU mappings */ 178c2ecf20Sopenharmony_ci#define MSM_IOMMU_ATTR_NONCACHED 0x0 188c2ecf20Sopenharmony_ci#define MSM_IOMMU_ATTR_CACHED_WB_WA 0x1 198c2ecf20Sopenharmony_ci#define MSM_IOMMU_ATTR_CACHED_WB_NWA 0x2 208c2ecf20Sopenharmony_ci#define MSM_IOMMU_ATTR_CACHED_WT 0x3 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* Mask for the cache policy attribute */ 238c2ecf20Sopenharmony_ci#define MSM_IOMMU_CP_MASK 0x03 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* Maximum number of Machine IDs that we are allowing to be mapped to the same 268c2ecf20Sopenharmony_ci * context bank. The number of MIDs mapped to the same CB does not affect 278c2ecf20Sopenharmony_ci * performance, but there is a practical limit on how many distinct MIDs may 288c2ecf20Sopenharmony_ci * be present. These mappings are typically determined at design time and are 298c2ecf20Sopenharmony_ci * not expected to change at run time. 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ci#define MAX_NUM_MIDS 32 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* Maximum number of context banks that can be present in IOMMU */ 348c2ecf20Sopenharmony_ci#define IOMMU_MAX_CBS 128 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/** 378c2ecf20Sopenharmony_ci * struct msm_iommu_dev - a single IOMMU hardware instance 388c2ecf20Sopenharmony_ci * ncb Number of context banks present on this IOMMU HW instance 398c2ecf20Sopenharmony_ci * dev: IOMMU device 408c2ecf20Sopenharmony_ci * irq: Interrupt number 418c2ecf20Sopenharmony_ci * clk: The bus clock for this IOMMU hardware instance 428c2ecf20Sopenharmony_ci * pclk: The clock for the IOMMU bus interconnect 438c2ecf20Sopenharmony_ci * dev_node: list head in qcom_iommu_device_list 448c2ecf20Sopenharmony_ci * dom_node: list head for domain 458c2ecf20Sopenharmony_ci * ctx_list: list of 'struct msm_iommu_ctx_dev' 468c2ecf20Sopenharmony_ci * context_map: Bitmap to track allocated context banks 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_cistruct msm_iommu_dev { 498c2ecf20Sopenharmony_ci void __iomem *base; 508c2ecf20Sopenharmony_ci int ncb; 518c2ecf20Sopenharmony_ci struct device *dev; 528c2ecf20Sopenharmony_ci int irq; 538c2ecf20Sopenharmony_ci struct clk *clk; 548c2ecf20Sopenharmony_ci struct clk *pclk; 558c2ecf20Sopenharmony_ci struct list_head dev_node; 568c2ecf20Sopenharmony_ci struct list_head dom_node; 578c2ecf20Sopenharmony_ci struct list_head ctx_list; 588c2ecf20Sopenharmony_ci DECLARE_BITMAP(context_map, IOMMU_MAX_CBS); 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci struct iommu_device iommu; 618c2ecf20Sopenharmony_ci}; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/** 648c2ecf20Sopenharmony_ci * struct msm_iommu_ctx_dev - an IOMMU context bank instance 658c2ecf20Sopenharmony_ci * of_node node ptr of client device 668c2ecf20Sopenharmony_ci * num Index of this context bank within the hardware 678c2ecf20Sopenharmony_ci * mids List of Machine IDs that are to be mapped into this context 688c2ecf20Sopenharmony_ci * bank, terminated by -1. The MID is a set of signals on the 698c2ecf20Sopenharmony_ci * AXI bus that identifies the function associated with a specific 708c2ecf20Sopenharmony_ci * memory request. (See ARM spec). 718c2ecf20Sopenharmony_ci * num_mids Total number of mids 728c2ecf20Sopenharmony_ci * node list head in ctx_list 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_cistruct msm_iommu_ctx_dev { 758c2ecf20Sopenharmony_ci struct device_node *of_node; 768c2ecf20Sopenharmony_ci int num; 778c2ecf20Sopenharmony_ci int mids[MAX_NUM_MIDS]; 788c2ecf20Sopenharmony_ci int num_mids; 798c2ecf20Sopenharmony_ci struct list_head list; 808c2ecf20Sopenharmony_ci}; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* 838c2ecf20Sopenharmony_ci * Interrupt handler for the IOMMU context fault interrupt. Hooking the 848c2ecf20Sopenharmony_ci * interrupt is not supported in the API yet, but this will print an error 858c2ecf20Sopenharmony_ci * message and dump useful IOMMU registers. 868c2ecf20Sopenharmony_ci */ 878c2ecf20Sopenharmony_ciirqreturn_t msm_iommu_fault_handler(int irq, void *dev_id); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci#endif 90