Skip to content

Commit 0f0f657

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

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

drivers/iommu/bcm2712-iommu.c

Lines changed: 25 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,25 @@ 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+
234+
if (!bcm2712_iommu_get_page(mmu, &mmu->top_table))
235+
return -ENOMEM;
236+
237+
if (!bcm2712_iommu_get_page(mmu, &mmu->default_page)) {
238+
bcm2712_iommu_free_page(mmu, mmu->top_table);
239+
return -ENOMEM;
240+
}
241+
242+
return bcm2712_iommu_hw_init(mmu);
243+
}
244+
245245
static int bcm2712_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
246246
{
247247
struct bcm2712_iommu *mmu = dev ? dev_iommu_priv_get(dev) : 0;
@@ -766,7 +766,7 @@ static int bcm2712_iommu_resume(struct device *dev)
766766
{
767767
struct bcm2712_iommu *mmu = dev_get_drvdata(dev);
768768

769-
return bcm2712_iommu_init(mmu);
769+
return bcm2712_iommu_hw_init(mmu);
770770
}
771771

772772
static DEFINE_SIMPLE_DEV_PM_OPS(bcm2712_iommu_pm_ops, bcm2712_iommu_suspend,

0 commit comments

Comments
 (0)