Skip to content

Commit 4f956c9

Browse files
YongWu-HFwilldeacon
authored andcommitted
iommu/mediatek: Move domain_finalise into attach_device
Currently domain_alloc only has a parameter(type), We have no chance to input some special data. This patch moves the domain_finalise into attach_device which has the device information, then could update the domain's geometry.aperture ranges for each a device. Strictly, I should use the data from mtk_iommu_get_m4u_data as the parameter of mtk_iommu_domain_finalise in this patch. but dom->data only is used in tlb ops in which the data is get from the m4u_list, thus it is ok here. Signed-off-by: Yong Wu <[email protected]> Reviewed-by: Tomasz Figa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 08500c4 commit 4f956c9

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,9 @@ static void mtk_iommu_config(struct mtk_iommu_data *data,
328328
}
329329
}
330330

331-
static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom)
331+
static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
332+
struct mtk_iommu_data *data)
332333
{
333-
struct mtk_iommu_data *data = mtk_iommu_get_m4u_data();
334-
335334
dom->cfg = (struct io_pgtable_cfg) {
336335
.quirks = IO_PGTABLE_QUIRK_ARM_NS |
337336
IO_PGTABLE_QUIRK_NO_PERMS |
@@ -352,7 +351,6 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom)
352351
return -EINVAL;
353352
}
354353

355-
dom->data = data;
356354
/* Update our support page sizes bitmap */
357355
dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap;
358356
return 0;
@@ -369,30 +367,19 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)
369367
if (!dom)
370368
return NULL;
371369

372-
if (iommu_get_dma_cookie(&dom->domain))
373-
goto free_dom;
374-
375-
if (mtk_iommu_domain_finalise(dom))
376-
goto put_dma_cookie;
370+
if (iommu_get_dma_cookie(&dom->domain)) {
371+
kfree(dom);
372+
return NULL;
373+
}
377374

378375
dom->domain.geometry.aperture_start = 0;
379376
dom->domain.geometry.aperture_end = DMA_BIT_MASK(32);
380377
dom->domain.geometry.force_aperture = true;
381-
382378
return &dom->domain;
383-
384-
put_dma_cookie:
385-
iommu_put_dma_cookie(&dom->domain);
386-
free_dom:
387-
kfree(dom);
388-
return NULL;
389379
}
390380

391381
static void mtk_iommu_domain_free(struct iommu_domain *domain)
392382
{
393-
struct mtk_iommu_domain *dom = to_mtk_domain(domain);
394-
395-
free_io_pgtable_ops(dom->iop);
396383
iommu_put_dma_cookie(domain);
397384
kfree(to_mtk_domain(domain));
398385
}
@@ -408,6 +395,12 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
408395
if (!data)
409396
return -ENODEV;
410397

398+
if (!dom->data) {
399+
if (mtk_iommu_domain_finalise(dom, data))
400+
return -ENODEV;
401+
dom->data = data;
402+
}
403+
411404
if (!data->m4u_dom) { /* Initialize the M4U HW */
412405
ret = pm_runtime_resume_and_get(m4udev);
413406
if (ret < 0)

0 commit comments

Comments
 (0)