From a00ab4eff12883d5886a69237f67b993ac06c2d7 Mon Sep 17 00:00:00 2001 From: Luc Verhaegen Date: Fri, 11 Mar 2011 15:02:40 +0100 Subject: [PATCH] gpu: pvr: pdump: rewrite PDumpMemUM() Now that we have cleared up the streams, we can delay the copy_from_user() until copying into the streams. This makes PDumpMemUM highly similar to PDumpMemKM. So, split out the printing part from PDumpMemKM, and handle parameter stream dumping separately for PDumpMemKM and PDumpMemUM. In turn, this allows the removal of the separate buffer which was the heart of pdump_common.c, which is removed as well. No functional change. Signed-off-by: Luc Verhaegen Signed-off-by: Imre Deak --- pvr/Makefile | 3 +- pvr/bridged_pvr_bridge.c | 4 +- pvr/bridged_sgx_bridge.c | 8 +-- pvr/pdump.c | 92 ++++++++++++++++++------- pvr/pdump_common.c | 141 --------------------------------------- pvr/pdump_km.h | 9 +-- 6 files changed, 76 insertions(+), 181 deletions(-) delete mode 100644 pvr/pdump_common.c diff --git a/pvr/Makefile b/pvr/Makefile index 34259ad..db1f491 100644 --- a/pvr/Makefile +++ b/pvr/Makefile @@ -10,8 +10,7 @@ pvrsrvkm-objs := osfunc.o mmap.o module.o pdump.o proc.o \ sgxinit.o sgxreset.o sgxutils.o sgxkick.o \ sgxtransfer.o mmu.o pb.o perproc.o sysconfig.o \ sysutils.o osperproc.o bridged_support.o \ - bridged_sgx_bridge.o sgxpower.o pdump_common.o \ - pvr_events.o + bridged_sgx_bridge.o sgxpower.o pvr_events.o pvrsrvkm-objs-$(CONFIG_PVR_DEBUG) += pvr_debug.o pvrsrvkm-objs-$(CONFIG_DEBUG_FS) += pvr_debugfs.o diff --git a/pvr/bridged_pvr_bridge.c b/pvr/bridged_pvr_bridge.c index 81e5309..6568cb6 100644 --- a/pvr/bridged_pvr_bridge.c +++ b/pvr/bridged_pvr_bridge.c @@ -1159,7 +1159,7 @@ static int PDumpMemBW(u32 ui32BridgeID, if (psRetOUT->eError != PVRSRV_OK) return 0; - psRetOUT->eError = PDumpMemUM(psPerProc, psPDumpMemDumpIN->pvAltLinAddr, + psRetOUT->eError = PDumpMemUM(psPDumpMemDumpIN->pvAltLinAddr, psPDumpMemDumpIN->pvLinAddr, pvMemInfo, psPDumpMemDumpIN->ui32Offset, psPDumpMemDumpIN->ui32Bytes, @@ -1211,7 +1211,7 @@ static int PDumpSyncDumpBW(u32 ui32BridgeID, return 0; psRetOUT->eError = - PDumpMemUM(psPerProc, psPDumpSyncDumpIN->pvAltLinAddr, NULL, + PDumpMemUM(psPDumpSyncDumpIN->pvAltLinAddr, NULL, ((struct PVRSRV_KERNEL_SYNC_INFO *)pvSyncInfo)-> psSyncDataMemInfoKM, psPDumpSyncDumpIN->ui32Offset, ui32Bytes, 0, diff --git a/pvr/bridged_sgx_bridge.c b/pvr/bridged_sgx_bridge.c index 3a1aaec..7f61b30 100644 --- a/pvr/bridged_sgx_bridge.c +++ b/pvr/bridged_sgx_bridge.c @@ -1470,8 +1470,7 @@ static void DumpBufferArray(struct PVRSRV_PER_PROCESS_DATA *psPerProc, } PDUMPCOMMENTWITHFLAGS(0, "%s\r\n", pszName); - PDUMPMEMUM(psPerProc, - NULL, psBuffer->pvLinAddr, + PDUMPMEMUM(NULL, psBuffer->pvLinAddr, (struct PVRSRV_KERNEL_MEM_INFO *)psBuffer-> hKernelMemInfo, psBuffer->ui32Start, @@ -1490,8 +1489,7 @@ static void DumpBufferArray(struct PVRSRV_PER_PROCESS_DATA *psPerProc, MAKEUNIQUETAG(psCtrlMemInfoKM)); } PDUMPCOMMENTWITHFLAGS(0, "%s (part 1)\r\n", pszName); - PDUMPMEMUM(psPerProc, - NULL, psBuffer->pvLinAddr, + PDUMPMEMUM(NULL, psBuffer->pvLinAddr, (struct PVRSRV_KERNEL_MEM_INFO *)psBuffer-> hKernelMemInfo, psBuffer->ui32Start, @@ -1512,7 +1510,7 @@ static void DumpBufferArray(struct PVRSRV_PER_PROCESS_DATA *psPerProc, MAKEUNIQUETAG(psCtrlMemInfoKM)); } PDUMPCOMMENTWITHFLAGS(0, "%s (part 2)\r\n", pszName); - PDUMPMEMUM(psPerProc, NULL, psBuffer->pvLinAddr, + PDUMPMEMUM(NULL, psBuffer->pvLinAddr, (struct PVRSRV_KERNEL_MEM_INFO *)psBuffer-> hKernelMemInfo, 0, psBuffer->ui32End, 0, hUniqueTag); diff --git a/pvr/pdump.c b/pvr/pdump.c index f87e10d..daf50a3 100644 --- a/pvr/pdump.c +++ b/pvr/pdump.c @@ -86,7 +86,7 @@ dbgdrv_frame_set(u32 frame) } static enum PVRSRV_ERROR -dbgdrv_write_data(void *buffer, int size) +dbgdrv_write_data(void *buffer, int size, bool from_user) { return PVRSRV_OK; } @@ -138,7 +138,7 @@ pdump_print(u32 flags, char *format, ...) } static enum PVRSRV_ERROR -pdump_dump(u32 flags, void *buffer, u32 size) +pdump_dump(u32 flags, void *buffer, u32 size, bool from_user) { if (PDumpSuspended()) return PVRSRV_OK; @@ -146,7 +146,7 @@ pdump_dump(u32 flags, void *buffer, u32 size) if (!dbgdrv_flags_check(flags)) return PVRSRV_OK; - return dbgdrv_write_data(buffer, size); + return dbgdrv_write_data(buffer, size, from_user); } void PDumpCommentKM(char *pszComment, u32 ui32Flags) @@ -448,31 +448,13 @@ void PDumpMemPolKM(struct PVRSRV_KERNEL_MEM_INFO *psMemInfo, MEMPOLL_COUNT, MEMPOLL_DELAY); } -enum PVRSRV_ERROR -PDumpMemKM(void *pvAltLinAddr, struct PVRSRV_KERNEL_MEM_INFO *psMemInfo, - u32 ui32Offset, u32 ui32Bytes, u32 ui32Flags, void *hUniqueTag) +static void +pdump_mem_print(u32 ui32Flags, struct PVRSRV_KERNEL_MEM_INFO *psMemInfo, + u32 ui32Offset, u32 ui32Bytes, void *hUniqueTag) { struct IMG_DEV_VIRTADDR sDevVPageAddr; struct IMG_DEV_PHYADDR sDevPAddr; u32 ui32PageOffset; - enum PVRSRV_ERROR eError; - - PVR_ASSERT((ui32Offset + ui32Bytes) <= psMemInfo->ui32AllocSize); - - if (ui32Bytes == 0) - return PVRSRV_ERROR_GENERIC; - - if (pvAltLinAddr) - eError = pdump_dump(ui32Flags, pvAltLinAddr, ui32Bytes); - else if (psMemInfo->pvLinAddrKM) - eError = pdump_dump(ui32Flags, - psMemInfo->pvLinAddrKM + ui32Offset, - ui32Bytes); - else - return PVRSRV_ERROR_GENERIC; - - if (eError != PVRSRV_OK) - return eError; PDumpCommentWithFlags(ui32Flags, "LDB :SGXMEM:VA_%8.8X:0x%8.8X " "0x%8.8X\r\n", @@ -499,6 +481,66 @@ PDumpMemKM(void *pvAltLinAddr, struct PVRSRV_KERNEL_MEM_INFO *psMemInfo, ui32Bytes -= ui32BlockBytes; ui32Offset += ui32BlockBytes; } +} + +enum PVRSRV_ERROR +PDumpMemKM(void *pvAltLinAddr, struct PVRSRV_KERNEL_MEM_INFO *psMemInfo, + u32 ui32Offset, u32 ui32Bytes, u32 ui32Flags, void *hUniqueTag) +{ + enum PVRSRV_ERROR eError; + + PVR_ASSERT((ui32Offset + ui32Bytes) <= psMemInfo->ui32AllocSize); + + if (!ui32Bytes) + return PVRSRV_ERROR_GENERIC; + + if (pvAltLinAddr) + eError = pdump_dump(ui32Flags, pvAltLinAddr, ui32Bytes, false); + else if (psMemInfo->pvLinAddrKM) + eError = pdump_dump(ui32Flags, + psMemInfo->pvLinAddrKM + ui32Offset, + ui32Bytes, false); + else + return PVRSRV_ERROR_GENERIC; + + if (eError != PVRSRV_OK) + return eError; + + pdump_mem_print(ui32Flags, psMemInfo, ui32Offset, ui32Bytes, + hUniqueTag); + + return PVRSRV_OK; +} + +enum PVRSRV_ERROR +PDumpMemUM(void *pvAltLinAddrUM, void *pvLinAddrUM, + struct PVRSRV_KERNEL_MEM_INFO *psMemInfo, + u32 ui32Offset, u32 ui32Bytes, u32 ui32Flags, void *hUniqueTag) +{ + enum PVRSRV_ERROR eError; + + PVR_ASSERT((ui32Offset + ui32Bytes) <= psMemInfo->ui32AllocSize); + + if (!ui32Bytes) + return PVRSRV_ERROR_GENERIC; + + if (pvAltLinAddrUM) + eError = pdump_dump(ui32Flags, pvAltLinAddrUM, ui32Bytes, true); + else if (psMemInfo->pvLinAddrKM) + eError = pdump_dump(ui32Flags, + psMemInfo->pvLinAddrKM + ui32Offset, + ui32Bytes, false); + else if (pvLinAddrUM) + eError = pdump_dump(ui32Flags, pvLinAddrUM + ui32Offset, + ui32Bytes, true); + else + return PVRSRV_ERROR_GENERIC; + + if (eError != PVRSRV_OK) + return eError; + + pdump_mem_print(ui32Flags, psMemInfo, ui32Offset, ui32Bytes, + hUniqueTag); return PVRSRV_OK; } @@ -517,7 +559,7 @@ PDumpMem2KM(enum PVRSRV_DEVICE_TYPE eDeviceType, void *pvLinAddr, if (bInitialisePages) { eError = pdump_dump(PDUMP_FLAGS_CONTINUOUS, pvLinAddr, - ui32Bytes); + ui32Bytes, false); if (eError != PVRSRV_OK) return eError; } diff --git a/pvr/pdump_common.c b/pvr/pdump_common.c deleted file mode 100644 index 14ce8f6..0000000 --- a/pvr/pdump_common.c +++ /dev/null @@ -1,141 +0,0 @@ -/********************************************************************** - * - * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful but, except - * as otherwise stated in writing, without any warranty; without even the - * implied warranty of merchantability or fitness for a particular purpose. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * - * The full GNU General Public License is included in this distribution in - * the file called "COPYING". - * - * Contact Information: - * Imagination Technologies Ltd. - * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK - * - ******************************************************************************/ - -#if defined(PDUMP) -#include "services_headers.h" -#include "pdump_km.h" - -#if !defined(PDUMP_TEMP_BUFFER_SIZE) -#define PDUMP_TEMP_BUFFER_SIZE (64 * 1024L) -#endif - -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) -#define PTR_PLUS(t, p, x) ((t *)(((char *)(p)) + (x))) -#define VPTR_PLUS(p, x) PTR_PLUS(void, p, x) -#define VPTR_INC(p, x) (p = VPTR_PLUS(p, x)) - -static void *gpvTempBuffer; -static void *ghTempBufferBlockAlloc; - -static void *GetTempBuffer(void) -{ - if (gpvTempBuffer == NULL) { - enum PVRSRV_ERROR eError = OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, - PDUMP_TEMP_BUFFER_SIZE, - &gpvTempBuffer, - &ghTempBufferBlockAlloc); - if (eError != PVRSRV_OK) - PVR_DPF(PVR_DBG_ERROR, - "GetTempBuffer: OSAllocMem failed: %d", - eError); - } - - return gpvTempBuffer; -} - -static void FreeTempBuffer(void) -{ - if (gpvTempBuffer != NULL) { - OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, PDUMP_TEMP_BUFFER_SIZE, - gpvTempBuffer, ghTempBufferBlockAlloc); - gpvTempBuffer = NULL; - } -} - -void PDumpInitCommon(void) -{ - (void)GetTempBuffer(); - PDumpInit(); -} - -void PDumpDeInitCommon(void) -{ - FreeTempBuffer(); - PDumpDeInit(); -} - -enum PVRSRV_ERROR -PDumpMemUM(struct PVRSRV_PER_PROCESS_DATA *psPerProc, - void *pvAltLinAddrUM, void *pvLinAddrUM, - struct PVRSRV_KERNEL_MEM_INFO *psMemInfo, - u32 ui32Offset, u32 ui32Bytes, u32 ui32Flags, - void *hUniqueTag) -{ - void *pvAddrUM; - void *pvAddrKM; - u32 ui32BytesDumped; - u32 ui32CurrentOffset; - - if (psMemInfo->pvLinAddrKM != NULL && pvAltLinAddrUM == NULL) { - return PDumpMemKM(NULL, psMemInfo, ui32Offset, ui32Bytes, - ui32Flags, hUniqueTag); - } - - pvAddrUM = (pvAltLinAddrUM != NULL) ? pvAltLinAddrUM : - ((pvLinAddrUM != NULL) ? VPTR_PLUS(pvLinAddrUM, - ui32Offset) : NULL); - - pvAddrKM = GetTempBuffer(); - - PVR_ASSERT(pvAddrUM != NULL && pvAddrKM != NULL); - if (pvAddrUM == NULL || pvAddrKM == NULL) { - PVR_DPF(PVR_DBG_ERROR, "PDumpMemUM: Nothing to dump"); - return PVRSRV_ERROR_GENERIC; - } - - if (ui32Bytes > PDUMP_TEMP_BUFFER_SIZE) - PDumpCommentWithFlags(ui32Flags, - "Dumping 0x%8.8lx bytes of memory, in blocks of 0x%8.8lx bytes", - ui32Bytes, (u32) PDUMP_TEMP_BUFFER_SIZE); - - ui32CurrentOffset = ui32Offset; - for (ui32BytesDumped = 0; ui32BytesDumped < ui32Bytes;) { - enum PVRSRV_ERROR eError; - u32 ui32BytesToDump = - MIN(PDUMP_TEMP_BUFFER_SIZE, ui32Bytes - ui32BytesDumped); - - eError = OSCopyFromUser(psPerProc, - pvAddrKM, pvAddrUM, ui32BytesToDump); - if (eError != PVRSRV_OK) { - PVR_DPF(PVR_DBG_ERROR, - "PDumpMemUM: OSCopyFromUser failed (%d)", eError); - return eError; - } - - eError = PDumpMemKM(pvAddrKM, psMemInfo, ui32CurrentOffset, - ui32BytesToDump, ui32Flags, hUniqueTag); - if (eError != PVRSRV_OK) - return eError; - - VPTR_INC(pvAddrUM, ui32BytesToDump); - ui32CurrentOffset += ui32BytesToDump; - ui32BytesDumped += ui32BytesToDump; - } - - return PVRSRV_OK; -} - -#endif diff --git a/pvr/pdump_km.h b/pvr/pdump_km.h index 91ca87f..f3d7146 100644 --- a/pvr/pdump_km.h +++ b/pvr/pdump_km.h @@ -49,8 +49,7 @@ void PDumpMemPolKM(struct PVRSRV_KERNEL_MEM_INFO enum PDUMP_POLL_OPERATOR eOperator, void *hUniqueTag); -enum PVRSRV_ERROR PDumpMemUM(struct PVRSRV_PER_PROCESS_DATA *psProcData, - void *pvAltLinAddr, void *pvLinAddr, +enum PVRSRV_ERROR PDumpMemUM(void *pvAltLinAddr, void *pvLinAddr, struct PVRSRV_KERNEL_MEM_INFO *psMemInfo, u32 ui32Offset, u32 ui32Bytes, u32 ui32Flags, void *hUniqueTag); @@ -66,8 +65,6 @@ enum PVRSRV_ERROR PDumpMem2KM(enum PVRSRV_DEVICE_TYPE eDeviceType, u32 ui32Flags, IMG_BOOL bInitialisePages, void *hUniqueTag1, void *hUniqueTag2); -void PDumpInitCommon(void); -void PDumpDeInitCommon(void); void PDumpInit(void); void PDumpDeInit(void); void PDumpSetFrameKM(u32 ui32Frame); @@ -141,8 +138,8 @@ void PDumpResumeKM(void); #define PDUMPMEM PDumpMemKM #define PDUMPMEM2 PDumpMem2KM #define PDUMPMEMUM PDumpMemUM -#define PDUMPINIT PDumpInitCommon -#define PDUMPDEINIT PDumpDeInitCommon +#define PDUMPINIT PDumpInit +#define PDUMPDEINIT PDumpDeInit #define PDUMPREGWITHFLAGS PDumpRegWithFlagsKM #define PDUMPREG PDumpReg #define PDUMPCOMMENT PDumpComment -- 2.39.2