From 30afcb6ddc16f6d25525cc3c98fed1e34cf15759 Mon Sep 17 00:00:00 2001 From: joevt Date: Wed, 24 Apr 2024 06:35:19 -0700 Subject: [PATCH] ppcmmu: Allow map dma for last byte of region. cur_dma_rgn->end is the last byte of a region. It is not the byte after the region. Therefore, subtract 1 from size before doing compare. Also add more detail to the abort messages. --- cpu/ppc/ppcmmu.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cpu/ppc/ppcmmu.cpp b/cpu/ppc/ppcmmu.cpp index 0f849e8..f73e7c0 100644 --- a/cpu/ppc/ppcmmu.cpp +++ b/cpu/ppc/ppcmmu.cpp @@ -313,11 +313,23 @@ MapDmaResult mmu_map_dma_mem(uint32_t addr, uint32_t size, bool allow_mmio) { AddressMapEntry *cur_dma_rgn; cur_dma_rgn = mem_ctrl_instance->find_range(addr); - if (!cur_dma_rgn || (addr + size) > cur_dma_rgn->end) - ABORT_F("SOS: DMA access to unmapped physical memory %08X!", addr); + if (!cur_dma_rgn) { + ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X!", + addr, addr + size - 1 + ); + } - if ((cur_dma_rgn->type & RT_MMIO) && !allow_mmio) - ABORT_F("SOS: DMA access to a MMIO region is not allowed"); + if (addr + size - 1 > cur_dma_rgn->end) { + ABORT_F("SOS: DMA access to unmapped physical memory 0x%08X..0x%08X because size extends outside region 0x%08X..0x%08X!", + addr, addr + size - 1, cur_dma_rgn->start, cur_dma_rgn->end + ); + } + + if ((cur_dma_rgn->type & RT_MMIO) && !allow_mmio) { + ABORT_F("SOS: DMA access to a MMIO region 0x%08X..0x%08X (%s) for physical memory 0x%08X..0x%08X is not allowed.", + cur_dma_rgn->start, cur_dma_rgn->end, cur_dma_rgn->devobj->get_name().c_str(), addr, addr + size - 1 + ); + } if (cur_dma_rgn->type & (RT_ROM | RT_RAM)) { host_va = cur_dma_rgn->mem_ptr + (addr - cur_dma_rgn->start);