162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. 362306a36Sopenharmony_ci */ 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#ifndef MSM_IOMMU_H 662306a36Sopenharmony_ci#define MSM_IOMMU_H 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <linux/interrupt.h> 962306a36Sopenharmony_ci#include <linux/iommu.h> 1062306a36Sopenharmony_ci#include <linux/clk.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci/* Sharability attributes of MSM IOMMU mappings */ 1362306a36Sopenharmony_ci#define MSM_IOMMU_ATTR_NON_SH 0x0 1462306a36Sopenharmony_ci#define MSM_IOMMU_ATTR_SH 0x4 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/* Cacheability attributes of MSM IOMMU mappings */ 1762306a36Sopenharmony_ci#define MSM_IOMMU_ATTR_NONCACHED 0x0 1862306a36Sopenharmony_ci#define MSM_IOMMU_ATTR_CACHED_WB_WA 0x1 1962306a36Sopenharmony_ci#define MSM_IOMMU_ATTR_CACHED_WB_NWA 0x2 2062306a36Sopenharmony_ci#define MSM_IOMMU_ATTR_CACHED_WT 0x3 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* Mask for the cache policy attribute */ 2362306a36Sopenharmony_ci#define MSM_IOMMU_CP_MASK 0x03 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci/* Maximum number of Machine IDs that we are allowing to be mapped to the same 2662306a36Sopenharmony_ci * context bank. The number of MIDs mapped to the same CB does not affect 2762306a36Sopenharmony_ci * performance, but there is a practical limit on how many distinct MIDs may 2862306a36Sopenharmony_ci * be present. These mappings are typically determined at design time and are 2962306a36Sopenharmony_ci * not expected to change at run time. 3062306a36Sopenharmony_ci */ 3162306a36Sopenharmony_ci#define MAX_NUM_MIDS 32 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci/* Maximum number of context banks that can be present in IOMMU */ 3462306a36Sopenharmony_ci#define IOMMU_MAX_CBS 128 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/** 3762306a36Sopenharmony_ci * struct msm_iommu_dev - a single IOMMU hardware instance 3862306a36Sopenharmony_ci * ncb Number of context banks present on this IOMMU HW instance 3962306a36Sopenharmony_ci * dev: IOMMU device 4062306a36Sopenharmony_ci * irq: Interrupt number 4162306a36Sopenharmony_ci * clk: The bus clock for this IOMMU hardware instance 4262306a36Sopenharmony_ci * pclk: The clock for the IOMMU bus interconnect 4362306a36Sopenharmony_ci * dev_node: list head in qcom_iommu_device_list 4462306a36Sopenharmony_ci * dom_node: list head for domain 4562306a36Sopenharmony_ci * ctx_list: list of 'struct msm_iommu_ctx_dev' 4662306a36Sopenharmony_ci * context_map: Bitmap to track allocated context banks 4762306a36Sopenharmony_ci */ 4862306a36Sopenharmony_cistruct msm_iommu_dev { 4962306a36Sopenharmony_ci void __iomem *base; 5062306a36Sopenharmony_ci int ncb; 5162306a36Sopenharmony_ci struct device *dev; 5262306a36Sopenharmony_ci int irq; 5362306a36Sopenharmony_ci struct clk *clk; 5462306a36Sopenharmony_ci struct clk *pclk; 5562306a36Sopenharmony_ci struct list_head dev_node; 5662306a36Sopenharmony_ci struct list_head dom_node; 5762306a36Sopenharmony_ci struct list_head ctx_list; 5862306a36Sopenharmony_ci DECLARE_BITMAP(context_map, IOMMU_MAX_CBS); 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci struct iommu_device iommu; 6162306a36Sopenharmony_ci}; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci/** 6462306a36Sopenharmony_ci * struct msm_iommu_ctx_dev - an IOMMU context bank instance 6562306a36Sopenharmony_ci * of_node node ptr of client device 6662306a36Sopenharmony_ci * num Index of this context bank within the hardware 6762306a36Sopenharmony_ci * mids List of Machine IDs that are to be mapped into this context 6862306a36Sopenharmony_ci * bank, terminated by -1. The MID is a set of signals on the 6962306a36Sopenharmony_ci * AXI bus that identifies the function associated with a specific 7062306a36Sopenharmony_ci * memory request. (See ARM spec). 7162306a36Sopenharmony_ci * num_mids Total number of mids 7262306a36Sopenharmony_ci * node list head in ctx_list 7362306a36Sopenharmony_ci */ 7462306a36Sopenharmony_cistruct msm_iommu_ctx_dev { 7562306a36Sopenharmony_ci struct device_node *of_node; 7662306a36Sopenharmony_ci int num; 7762306a36Sopenharmony_ci int mids[MAX_NUM_MIDS]; 7862306a36Sopenharmony_ci int num_mids; 7962306a36Sopenharmony_ci struct list_head list; 8062306a36Sopenharmony_ci}; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci/* 8362306a36Sopenharmony_ci * Interrupt handler for the IOMMU context fault interrupt. Hooking the 8462306a36Sopenharmony_ci * interrupt is not supported in the API yet, but this will print an error 8562306a36Sopenharmony_ci * message and dump useful IOMMU registers. 8662306a36Sopenharmony_ci */ 8762306a36Sopenharmony_ciirqreturn_t msm_iommu_fault_handler(int irq, void *dev_id); 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci#endif 90