Skip to content

Commit 9485a04

Browse files
YongWu-HFjoergroedel
authored andcommitted
iommu/mediatek: Separate mtk_iommu_data for v1 and v2
Prepare for adding the structure "mtk_iommu_bank_data". No functional change. The mtk_iommu_domain in v1 and v2 are different, we could not add current data as bank[0] in v1 simplistically. Currently we have no plan to add new SoC for v1, in order to avoid affect v1 when we add many new features for v2, I totally separate v1 and v2 in this patch, there are many structures only for v2. Signed-off-by: Yong Wu <yong.wu@mediatek.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> Link: https://lore.kernel.org/r/20220503071427.2285-27-yong.wu@mediatek.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 634f57d commit 9485a04

3 files changed

Lines changed: 106 additions & 86 deletions

File tree

drivers/iommu/mtk_iommu.c

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,69 @@
146146

147147
#define MTK_INVALID_LARBID MTK_LARB_NR_MAX
148148

149+
#define MTK_LARB_COM_MAX 8
150+
#define MTK_LARB_SUBCOM_MAX 8
151+
152+
#define MTK_IOMMU_GROUP_MAX 8
153+
154+
enum mtk_iommu_plat {
155+
M4U_MT2712,
156+
M4U_MT6779,
157+
M4U_MT8167,
158+
M4U_MT8173,
159+
M4U_MT8183,
160+
M4U_MT8192,
161+
M4U_MT8195,
162+
};
163+
164+
struct mtk_iommu_iova_region {
165+
dma_addr_t iova_base;
166+
unsigned long long size;
167+
};
168+
169+
struct mtk_iommu_plat_data {
170+
enum mtk_iommu_plat m4u_plat;
171+
u32 flags;
172+
u32 inv_sel_reg;
173+
174+
char *pericfg_comp_str;
175+
struct list_head *hw_list;
176+
unsigned int iova_region_nr;
177+
const struct mtk_iommu_iova_region *iova_region;
178+
unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX];
179+
};
180+
181+
struct mtk_iommu_data {
182+
void __iomem *base;
183+
int irq;
184+
struct device *dev;
185+
struct clk *bclk;
186+
phys_addr_t protect_base; /* protect memory base */
187+
struct mtk_iommu_suspend_reg reg;
188+
struct mtk_iommu_domain *m4u_dom;
189+
struct iommu_group *m4u_group[MTK_IOMMU_GROUP_MAX];
190+
bool enable_4GB;
191+
spinlock_t tlb_lock; /* lock for tlb range flush */
192+
193+
struct iommu_device iommu;
194+
const struct mtk_iommu_plat_data *plat_data;
195+
struct device *smicomm_dev;
196+
197+
struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */
198+
struct regmap *pericfg;
199+
200+
struct mutex mutex; /* Protect m4u_group/m4u_dom above */
201+
202+
/*
203+
* In the sharing pgtable case, list data->list to the global list like m4ulist.
204+
* In the non-sharing pgtable case, list data->list to the itself hw_list_head.
205+
*/
206+
struct list_head *hw_list;
207+
struct list_head hw_list_head;
208+
struct list_head list;
209+
struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX];
210+
};
211+
149212
struct mtk_iommu_domain {
150213
struct io_pgtable_cfg cfg;
151214
struct io_pgtable_ops *iop;
@@ -156,6 +219,20 @@ struct mtk_iommu_domain {
156219
struct mutex mutex; /* Protect "data" in this structure */
157220
};
158221

222+
static int mtk_iommu_bind(struct device *dev)
223+
{
224+
struct mtk_iommu_data *data = dev_get_drvdata(dev);
225+
226+
return component_bind_all(dev, &data->larb_imu);
227+
}
228+
229+
static void mtk_iommu_unbind(struct device *dev)
230+
{
231+
struct mtk_iommu_data *data = dev_get_drvdata(dev);
232+
233+
component_unbind_all(dev, &data->larb_imu);
234+
}
235+
159236
static const struct iommu_ops mtk_iommu_ops;
160237

161238
static int mtk_iommu_hw_init(const struct mtk_iommu_data *data);
@@ -193,11 +270,6 @@ static LIST_HEAD(m4ulist); /* List all the M4U HWs */
193270

194271
#define for_each_m4u(data, head) list_for_each_entry(data, head, list)
195272

196-
struct mtk_iommu_iova_region {
197-
dma_addr_t iova_base;
198-
unsigned long long size;
199-
};
200-
201273
static const struct mtk_iommu_iova_region single_domain[] = {
202274
{.iova_base = 0, .size = SZ_4G},
203275
};

drivers/iommu/mtk_iommu.h

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,14 @@
77
#ifndef _MTK_IOMMU_H_
88
#define _MTK_IOMMU_H_
99

10-
#include <linux/clk.h>
11-
#include <linux/component.h>
1210
#include <linux/device.h>
1311
#include <linux/io.h>
1412
#include <linux/io-pgtable.h>
1513
#include <linux/iommu.h>
16-
#include <linux/list.h>
1714
#include <linux/spinlock.h>
18-
#include <linux/dma-mapping.h>
1915
#include <soc/mediatek/smi.h>
2016
#include <dt-bindings/memory/mtk-memory-port.h>
2117

22-
#define MTK_LARB_COM_MAX 8
23-
#define MTK_LARB_SUBCOM_MAX 8
24-
25-
#define MTK_IOMMU_GROUP_MAX 8
26-
2718
struct mtk_iommu_suspend_reg {
2819
union {
2920
u32 standard_axi_mode;/* v1 */
@@ -38,76 +29,4 @@ struct mtk_iommu_suspend_reg {
3829
u32 wr_len_ctrl;
3930
};
4031

41-
enum mtk_iommu_plat {
42-
M4U_MT2701,
43-
M4U_MT2712,
44-
M4U_MT6779,
45-
M4U_MT8167,
46-
M4U_MT8173,
47-
M4U_MT8183,
48-
M4U_MT8192,
49-
M4U_MT8195,
50-
};
51-
52-
struct mtk_iommu_iova_region;
53-
54-
struct mtk_iommu_plat_data {
55-
enum mtk_iommu_plat m4u_plat;
56-
u32 flags;
57-
u32 inv_sel_reg;
58-
59-
char *pericfg_comp_str;
60-
struct list_head *hw_list;
61-
unsigned int iova_region_nr;
62-
const struct mtk_iommu_iova_region *iova_region;
63-
unsigned char larbid_remap[MTK_LARB_COM_MAX][MTK_LARB_SUBCOM_MAX];
64-
};
65-
66-
struct mtk_iommu_domain;
67-
68-
struct mtk_iommu_data {
69-
void __iomem *base;
70-
int irq;
71-
struct device *dev;
72-
struct clk *bclk;
73-
phys_addr_t protect_base; /* protect memory base */
74-
struct mtk_iommu_suspend_reg reg;
75-
struct mtk_iommu_domain *m4u_dom;
76-
struct iommu_group *m4u_group[MTK_IOMMU_GROUP_MAX];
77-
bool enable_4GB;
78-
spinlock_t tlb_lock; /* lock for tlb range flush */
79-
80-
struct iommu_device iommu;
81-
const struct mtk_iommu_plat_data *plat_data;
82-
struct device *smicomm_dev;
83-
84-
struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */
85-
struct regmap *pericfg;
86-
87-
struct mutex mutex; /* Protect m4u_group/m4u_dom above */
88-
89-
/*
90-
* In the sharing pgtable case, list data->list to the global list like m4ulist.
91-
* In the non-sharing pgtable case, list data->list to the itself hw_list_head.
92-
*/
93-
struct list_head *hw_list;
94-
struct list_head hw_list_head;
95-
struct list_head list;
96-
struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX];
97-
};
98-
99-
static inline int mtk_iommu_bind(struct device *dev)
100-
{
101-
struct mtk_iommu_data *data = dev_get_drvdata(dev);
102-
103-
return component_bind_all(dev, &data->larb_imu);
104-
}
105-
106-
static inline void mtk_iommu_unbind(struct device *dev)
107-
{
108-
struct mtk_iommu_data *data = dev_get_drvdata(dev);
109-
110-
component_unbind_all(dev, &data->larb_imu);
111-
}
112-
11332
#endif

drivers/iommu/mtk_iommu_v1.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@
8787
*/
8888
#define M2701_IOMMU_PGT_SIZE SZ_4M
8989

90+
struct mtk_iommu_data {
91+
void __iomem *base;
92+
int irq;
93+
struct device *dev;
94+
struct clk *bclk;
95+
phys_addr_t protect_base; /* protect memory base */
96+
struct mtk_iommu_domain *m4u_dom;
97+
98+
struct iommu_device iommu;
99+
struct dma_iommu_mapping *mapping;
100+
struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX];
101+
102+
struct mtk_iommu_suspend_reg reg;
103+
};
104+
90105
struct mtk_iommu_domain {
91106
spinlock_t pgtlock; /* lock for page table */
92107
struct iommu_domain domain;
@@ -95,6 +110,20 @@ struct mtk_iommu_domain {
95110
struct mtk_iommu_data *data;
96111
};
97112

113+
static int mtk_iommu_bind(struct device *dev)
114+
{
115+
struct mtk_iommu_data *data = dev_get_drvdata(dev);
116+
117+
return component_bind_all(dev, &data->larb_imu);
118+
}
119+
120+
static void mtk_iommu_unbind(struct device *dev)
121+
{
122+
struct mtk_iommu_data *data = dev_get_drvdata(dev);
123+
124+
component_unbind_all(dev, &data->larb_imu);
125+
}
126+
98127
static struct mtk_iommu_domain *to_mtk_domain(struct iommu_domain *dom)
99128
{
100129
return container_of(dom, struct mtk_iommu_domain, domain);

0 commit comments

Comments
 (0)