Skip to content

Commit e71c9a3

Browse files
alternate iommu fix
Signed-off-by: Peter Bailey <peter.bailey@raspberrypi.com>
1 parent 28ba948 commit e71c9a3

1 file changed

Lines changed: 24 additions & 25 deletions

File tree

drivers/iommu/bcm2712-iommu.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static void bcm2712_iommu_free_page(struct bcm2712_iommu *mmu, void *ptr)
145145
}
146146
}
147147

148-
static int bcm2712_iommu_init(struct bcm2712_iommu *mmu)
148+
static int bcm2712_iommu_hw_init(struct bcm2712_iommu *mmu)
149149
{
150150
u32 u = MMU_RD(MMMU_DEBUG_INFO_OFFSET);
151151

@@ -203,30 +203,11 @@ static int bcm2712_iommu_init(struct bcm2712_iommu *mmu)
203203
MMU_WR(MMMU_BYPASS_END_OFFSET, 0);
204204
}
205205

206-
/*
207-
* Configure the addresses of the top-level table (offset because
208-
* the aperture does not start from zero), and of the default page.
209-
* For simplicity, both these regions are whole Linux pages.
210-
*/
211-
if (mmu->top_table) {
212-
u = (u32)(virt_to_phys(mmu->top_table) >> IOMMU_PAGE_SHIFT);
213-
} else {
214-
u = bcm2712_iommu_get_page(mmu, &mmu->top_table);
215-
if (!u)
216-
return -ENOMEM;
217-
}
218206
MMU_WR(MMMU_PT_PA_BASE_OFFSET,
219-
u - ((mmu->aperture_base - mmu->dma_iova_offset) >> L1_AP_BASE_SHIFT));
220-
if (mmu->default_page) {
221-
u = (u32)(virt_to_phys(mmu->default_page) >> IOMMU_PAGE_SHIFT);
222-
} else {
223-
u = bcm2712_iommu_get_page(mmu, &mmu->default_page);
224-
if (!u) {
225-
bcm2712_iommu_free_page(mmu, mmu->top_table);
226-
return -ENOMEM;
227-
}
228-
}
229-
MMU_WR(MMMU_ILLEGAL_ADR_OFFSET, MMMU_ILLEGAL_ADR_ENABLE + u);
207+
(u32)(virt_to_phys(mmu->top_table) >> IOMMU_PAGE_SHIFT) -
208+
((mmu->aperture_base - mmu->dma_iova_offset) >> L1_AP_BASE_SHIFT));
209+
MMU_WR(MMMU_ILLEGAL_ADR_OFFSET, MMMU_ILLEGAL_ADR_ENABLE +
210+
(u32)(virt_to_phys(mmu->default_page) >> IOMMU_PAGE_SHIFT));
230211

231212
/* Flush (and enable) the shared TLB cache; enable this MMU. */
232213
if (mmu->cache)
@@ -242,6 +223,24 @@ static int bcm2712_iommu_init(struct bcm2712_iommu *mmu)
242223
return 0;
243224
}
244225

226+
static int bcm2712_iommu_init(struct bcm2712_iommu *mmu)
227+
{
228+
/*
229+
* Configure the addresses of the top-level table (offset because
230+
* the aperture does not start from zero), and of the default page.
231+
* For simplicity, both these regions are whole Linux pages.
232+
*/
233+
if (!bcm2712_iommu_get_page(mmu, &mmu->top_table))
234+
return -ENOMEM;
235+
236+
if (!bcm2712_iommu_get_page(mmu, &mmu->default_page)) {
237+
bcm2712_iommu_free_page(mmu, mmu->top_table);
238+
return -ENOMEM;
239+
}
240+
241+
return bcm2712_iommu_hw_init(mmu);
242+
}
243+
245244
static int bcm2712_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
246245
{
247246
struct bcm2712_iommu *mmu = dev ? dev_iommu_priv_get(dev) : 0;
@@ -766,7 +765,7 @@ static int bcm2712_iommu_resume(struct device *dev)
766765
{
767766
struct bcm2712_iommu *mmu = dev_get_drvdata(dev);
768767

769-
return bcm2712_iommu_init(mmu);
768+
return bcm2712_iommu_hw_init(mmu);
770769
}
771770

772771
static DEFINE_SIMPLE_DEV_PM_OPS(bcm2712_iommu_pm_ops, bcm2712_iommu_suspend,

0 commit comments

Comments
 (0)