Skip to content

Commit c6013f0

Browse files
joevtdingusdev
authored andcommitted
ppcmmu: Fix DMA for adjacent cross region ranges.
If a DMA range extends beyond the end of a region into a second region of the same type (either RAM or ROM), and the regions are adjacent in both the guest and host address spaces, then allow the DMA to proceed.
1 parent 9c6a7de commit c6013f0

1 file changed

Lines changed: 39 additions & 3 deletions

File tree

cpu/ppc/ppcmmu.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
311311
uint32_t dev_base = 0;
312312
bool is_writable;
313313
AddressMapEntry *cur_dma_rgn;
314+
AddressMapEntry *next_dma_rgn;
314315

315316
cur_dma_rgn = mem_ctrl_instance->find_range(addr);
316317
if (!cur_dma_rgn) {
@@ -320,9 +321,44 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) {
320321
}
321322

322323
if (addr + size - 1 > cur_dma_rgn->end) {
323-
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region 0x%08X..0x%08X!",
324-
addr, addr + size - 1, cur_dma_rgn->start, cur_dma_rgn->end
325-
);
324+
if (cur_dma_rgn->type & (RT_ROM | RT_RAM))
325+
LOG_F(WARNING, "this region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
326+
cur_dma_rgn->start, cur_dma_rgn->end,
327+
uint64_t(cur_dma_rgn->mem_ptr),
328+
uint64_t(cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start)
329+
);
330+
else
331+
LOG_F(ERROR, "this region: 0x%08X..0x%08X",
332+
cur_dma_rgn->start, cur_dma_rgn->end
333+
);
334+
next_dma_rgn = mem_ctrl_instance->find_range(cur_dma_rgn->end + 1);
335+
if (next_dma_rgn) {
336+
if (next_dma_rgn->type & (RT_ROM | RT_RAM))
337+
LOG_F(WARNING, "next region: 0x%08X..0x%08X (host: 0x%08llX..0x%08llX)",
338+
next_dma_rgn->start, next_dma_rgn->end,
339+
uint64_t(next_dma_rgn->mem_ptr),
340+
uint64_t(next_dma_rgn->mem_ptr + next_dma_rgn->end - next_dma_rgn->start)
341+
);
342+
else
343+
LOG_F(ERROR, "next region: 0x%08X..0x%08X",
344+
next_dma_rgn->start, next_dma_rgn->end
345+
);
346+
}
347+
if (next_dma_rgn &&
348+
(cur_dma_rgn->type & (RT_ROM | RT_RAM)) &&
349+
((cur_dma_rgn->type & (RT_ROM | RT_RAM)) == (next_dma_rgn->type & (RT_ROM | RT_RAM))) &&
350+
(next_dma_rgn->mem_ptr == cur_dma_rgn->mem_ptr + cur_dma_rgn->end - cur_dma_rgn->start + 1) &&
351+
(addr + size - 1 <= next_dma_rgn->end)
352+
) {
353+
LOG_F(INFO, "DMA to physical memory 0x%08X..0x%08X is OK!"
354+
" The regions are the same type and adjacent in host and guest spaces.",
355+
addr, addr + size - 1
356+
);
357+
} else {
358+
ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region!",
359+
addr, addr + size - 1
360+
);
361+
}
326362
}
327363

328364
if ((cur_dma_rgn->type & RT_MMIO) && !allow_mmio) {

0 commit comments

Comments
 (0)