[RESEND][PATCH] DSPBRIDGE: Replacing custom implementation for Mapping
From: Omar Ramirez Luna x0084...@ti.com Currently, we walk through the entire page table translating the addresses from virtual to physical whenever we map a buffer. This custom implementation is meant to be optimized for performance, but it bypasses the standard memory management subsystem. This patch removes the custom implementation and uses the kernel APIs to get the virtual to physical maps. Map times for DMM Buffer | Kernel APIs | Custom Implement. | Size | time (usec) |time (usec)| 4 KB | 427 |396| 64 KB |1038 |824| 1 MB |9827 | 7110| 4 MB | 37811 | 26916| 6 MB | 56366 | 39978| Signed-off-by: Hari Kanigeri h-kanige...@ti.com Signed-off-by: Omar Ramirez Luna x0084...@ti.com --- drivers/dsp/bridge/wmd/tiomap3430.c | 491 +++ 1 files changed, 149 insertions(+), 342 deletions(-) diff --git a/drivers/dsp/bridge/wmd/tiomap3430.c b/drivers/dsp/bridge/wmd/tiomap3430.c index df350c6..ff0db9a 100644 --- a/drivers/dsp/bridge/wmd/tiomap3430.c +++ b/drivers/dsp/bridge/wmd/tiomap3430.c @@ -1,4 +1,3 @@ - /* * tiomap.c * @@ -133,9 +132,7 @@ static DSP_STATUS WMD_DEV_Create(OUT struct WMD_DEV_CONTEXT **ppDevContext, static DSP_STATUS WMD_DEV_Ctrl(struct WMD_DEV_CONTEXT *pDevContext, u32 dwCmd, IN OUT void *pArgs); static DSP_STATUS WMD_DEV_Destroy(struct WMD_DEV_CONTEXT *pDevContext); -static DSP_STATUS TIOMAP_VirtToPhysical(struct mm_struct *mm, u32 ulMpuAddr, - u32 ulNumBytes, u32 *numOfTableEntries, - u32 *physicalAddrTable); +static u32 user_va2pa(struct mm_struct *mm, u32 address); static DSP_STATUS PteUpdate(struct WMD_DEV_CONTEXT *hDevContext, u32 pa, u32 va, u32 size, struct HW_MMUMapAttrs_t *mapAttrs); @@ -270,6 +267,21 @@ static inline void flush_all(struct WMD_DEV_CONTEXT *pDevContext) tlb_flush_all(pDevContext-dwDSPMmuBase); } +void badpagedump(u32 pa, struct page *pg) +{ + printk(KERN_EMERG DSPBRIDGE:MAP function: COUNT 0 FOR PA 0x%x\n, pa); + printk(KERN_EMERG Bad page state in process '%s'\n + page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n + Trying to fix it up, but a reboot is needed\n + Backtrace:\n, + current-comm, pg, (int)(2*sizeof(unsigned long)), + (unsigned long)pg-flags, pg-mapping, + page_mapcount(pg), page_count(pg)); + dump_stack(); + BUG_ON(1); + +} + /* * WMD_DRV_Entry * purpose: @@ -1352,11 +1364,16 @@ static DSP_STATUS WMD_BRD_MemMap(struct WMD_DEV_CONTEXT *hDevContext, DSP_STATUS status = DSP_SOK; struct WMD_DEV_CONTEXT *pDevContext = hDevContext; struct HW_MMUMapAttrs_t hwAttrs; - u32 numOfActualTabEntries = 0; - u32 *pPhysAddrPageTbl = NULL; struct vm_area_struct *vma; struct mm_struct *mm = current-mm; - u32 temp = 0; + u32 write = 0; + u32 numUsrPgs = 0; + struct page *mappedPage, *pg; + s32 pgNum; + u32 va = ulVirtAddr; + struct task_struct *curr_task = current; + u32 pgI = 0; + u32 mpuAddr, pa; DBG_Trace(DBG_ENTER, WMD_BRD_MemMap hDevContext %x, pa %x, va %x, size %x, ulMapAttr %x\n, hDevContext, ulMpuAddr, ulVirtAddr, @@ -1424,7 +1441,6 @@ static DSP_STATUS WMD_BRD_MemMap(struct WMD_DEV_CONTEXT *hDevContext, * virtual memory address space in order to be of use to us here! */ down_read(mm-mmap_sem); vma = find_vma(mm, ulMpuAddr); - up_read(mm-mmap_sem); if (vma) DBG_Trace(DBG_LEVEL6, VMAfor UserBuf: ulMpuAddr=%x, ulNumBytes=%x, vm_start=%x vm_end=%x vm_flags=%x \n, @@ -1436,9 +1452,7 @@ static DSP_STATUS WMD_BRD_MemMap(struct WMD_DEV_CONTEXT *hDevContext, * user buffer is covered */ while ((vma != NULL) (ulMpuAddr + ulNumBytes vma-vm_end)) { /* jump to the next VMA region */ - down_read(mm-mmap_sem); vma = find_vma(mm, vma-vm_end + 1); - up_read(mm-mmap_sem); DBG_Trace(DBG_LEVEL6, VMAfor UserBuf ulMpuAddr=%x, ulNumBytes=%x, vm_start=%x vm_end=%x vm_flags=%x\n, ulMpuAddr, ulNumBytes, vma-vm_start, @@ -1449,44 +1463,100 @@ static DSP_STATUS WMD_BRD_MemMap(struct WMD_DEV_CONTEXT *hDevContext, MPU Buffer !!! \n); status = DSP_EINVALIDARG; } - if (DSP_FAILED(status)) - goto func_cont; - pPhysAddrPageTbl = DMM_GetPhysicalAddrTable(); - /* Build the array with virtual to physical translations */ - status = TIOMAP_VirtToPhysical(mm, ulMpuAddr, ulNumBytes, -
[PATCH] DSPBRIDGE: Replacing custom implementation for Mapping
From: Omar Ramirez Luna x0084...@ti.com Date: Mon, 20 Apr 2009 21:45:46 -0500 Subject: [PATCH] DSPBRIDGE: Replacing custom implementation for Mapping DSPBRIDGE: Replacing custom implementation for Mapping Currently, we walk through the entire page table translating the addresses from virtual to physical whenever we map a buffer. This custom implementation is meant to be optimized for performance, but it bypasses the standard memory management subsystem. This patch removes the custom implementation and uses the kernel APIs to get the virtual to physical maps. Map times for DMM Buffer | Kernel APIs | Custom Implement. | Size | time (usec) |time (usec)| 4 KB | 427 |396| 64 KB |1038 |824| 1 MB |9827 | 7110| 4 MB | 37811 | 26916| 6 MB | 56366 | 39978| Signed-off-by: Hari Kanigeri h-kanige...@ti.com Signed-off-by: Omar Ramirez Luna x0084...@ti.com --- drivers/dsp/bridge/wmd/tiomap3430.c | 484 +++ 1 files changed, 149 insertions(+), 335 deletions(-) diff --git a/drivers/dsp/bridge/wmd/tiomap3430.c b/drivers/dsp/bridge/wmd/tiomap3430.c index 208f752..c32ee78 100644 --- a/drivers/dsp/bridge/wmd/tiomap3430.c +++ b/drivers/dsp/bridge/wmd/tiomap3430.c @@ -1,4 +1,3 @@ - /* * tiomap.c * @@ -133,9 +132,7 @@ static DSP_STATUS WMD_DEV_Create(OUT struct WMD_DEV_CONTEXT **ppDevContext, static DSP_STATUS WMD_DEV_Ctrl(struct WMD_DEV_CONTEXT *pDevContext, u32 dwCmd, IN OUT void *pArgs); static DSP_STATUS WMD_DEV_Destroy(struct WMD_DEV_CONTEXT *pDevContext); -static DSP_STATUS TIOMAP_VirtToPhysical(struct mm_struct *mm, u32 ulMpuAddr, - u32 ulNumBytes, u32 *numOfTableEntries, - u32 *physicalAddrTable); +static u32 user_va2pa(struct mm_struct *mm, u32 address); static DSP_STATUS PteUpdate(struct WMD_DEV_CONTEXT *hDevContext, u32 pa, u32 va, u32 size, struct HW_MMUMapAttrs_t *mapAttrs); @@ -270,6 +267,21 @@ static inline void flush_all(struct WMD_DEV_CONTEXT *pDevContext) tlb_flush_all(pDevContext-dwDSPMmuBase); } +void badpagedump(u32 pa, struct page *pg) +{ + printk(KERN_EMERG DSPBRIDGE:MAP function: COUNT 0 FOR PA 0x%x\n, pa); + printk(KERN_EMERG Bad page state in process '%s'\n + page:%p flags:0x%0*lx mapping:%p mapcount:%d count:%d\n + Trying to fix it up, but a reboot is needed\n + Backtrace:\n, + current-comm, pg, (int)(2*sizeof(unsigned long)), + (unsigned long)pg-flags, pg-mapping, + page_mapcount(pg), page_count(pg)); + dump_stack(); + BUG_ON(1); + +} + /* * WMD_DRV_Entry * purpose: @@ -1352,11 +1364,16 @@ static DSP_STATUS WMD_BRD_MemMap(struct WMD_DEV_CONTEXT *hDevContext, DSP_STATUS status = DSP_SOK; struct WMD_DEV_CONTEXT *pDevContext = hDevContext; struct HW_MMUMapAttrs_t hwAttrs; - u32 numOfActualTabEntries = 0; - u32 *pPhysAddrPageTbl = NULL; struct vm_area_struct *vma; struct mm_struct *mm = current-mm; - u32 temp = 0; + u32 write = 0; + u32 numUsrPgs = 0; + struct page *mappedPage, *pg; + s32 pgNum; + u32 va = ulVirtAddr; + struct task_struct *curr_task = current; + u32 pgI = 0; + u32 mpuAddr, pa; DBG_Trace(DBG_ENTER, WMD_BRD_MemMap hDevContext %x, pa %x, va %x, size %x, ulMapAttr %x\n, hDevContext, ulMpuAddr, ulVirtAddr, @@ -1424,7 +1441,6 @@ static DSP_STATUS WMD_BRD_MemMap(struct WMD_DEV_CONTEXT *hDevContext, * virtual memory address space in order to be of use to us here! */ down_read(mm-mmap_sem); vma = find_vma(mm, ulMpuAddr); - up_read(mm-mmap_sem); if (vma) DBG_Trace(DBG_LEVEL6, VMAfor UserBuf: ulMpuAddr=%x, ulNumBytes=%x, vm_start=%x vm_end=%x vm_flags=%x \n, @@ -1436,9 +1452,7 @@ static DSP_STATUS WMD_BRD_MemMap(struct WMD_DEV_CONTEXT *hDevContext, * user buffer is covered */ while ((vma != NULL) (ulMpuAddr + ulNumBytes vma-vm_end)) { /* jump to the next VMA region */ - down_read(mm-mmap_sem); vma = find_vma(mm, vma-vm_end + 1); - up_read(mm-mmap_sem); DBG_Trace(DBG_LEVEL6, VMAfor UserBuf ulMpuAddr=%x, ulNumBytes=%x, vm_start=%x vm_end=%x vm_flags=%x\n, ulMpuAddr, ulNumBytes, vma-vm_start, @@ -1449,44 +1463,100 @@ static DSP_STATUS WMD_BRD_MemMap(struct WMD_DEV_CONTEXT *hDevContext, MPU Buffer !!! \n); status = DSP_EINVALIDARG; } - if (DSP_FAILED(status)) - goto func_cont; - pPhysAddrPageTbl