From 2165408c7f64fcaa66a024fada65639f4a334347 Mon Sep 17 00:00:00 2001 From: popcornmix Date: Mon, 14 Nov 2016 16:01:04 +0000 Subject: [PATCH] vcdbg: Use dma driver to access gpu memory --- .../linux/libs/debug_sym/debug_sym.c | 44 +++++++++++++++++++ host_support/include/vc_mem.h | 1 + 2 files changed, 45 insertions(+) diff --git a/host_applications/linux/libs/debug_sym/debug_sym.c b/host_applications/linux/libs/debug_sym/debug_sym.c index 655a0f4..51ee49a 100755 --- a/host_applications/linux/libs/debug_sym/debug_sym.c +++ b/host_applications/linux/libs/debug_sym/debug_sym.c @@ -139,6 +139,40 @@ int OpenVideoCoreMemory( VC_MEM_ACCESS_HANDLE_T *vcHandlePtr ) * ***************************************************************************/ +struct fb_dmacopy { + uint32_t dst; + uint32_t src; + uint32_t length; +}; +#define FBIODMACOPY _IOW('z', 0x22, struct fb_dmacopy) + +static int vc_mem_copy(uint32_t dst, uint32_t src, uint32_t length) +{ + const char *filename = "/dev/fb0"; + int memFd; + struct fb_dmacopy ioparam; + + ioparam.dst = dst; + ioparam.src = src; + ioparam.length = length; + + if (( memFd = open( filename, O_RDWR | O_SYNC )) < 0 ) + { + ERR( "Unable to open '%s': %s(%d)\n", filename, strerror( errno ), errno ); + return -errno; + } + + if ( ioctl( memFd, FBIODMACOPY, &ioparam ) != 0 ) + { + ERR( "Failed to get memory size via ioctl: %s(%d)\n", + strerror( errno ), errno ); + close( memFd ); + return -errno; + } + close( memFd ); + return 0; +} + int OpenVideoCoreMemoryFile( const char *filename, VC_MEM_ACCESS_HANDLE_T *vcHandlePtr ) { return OpenVideoCoreMemoryFileWithOffset( filename, vcHandlePtr, 0 ); @@ -533,6 +567,7 @@ static int AccessVideoCoreMemory( VC_MEM_ACCESS_HANDLE_T vcHandle, VC_MEM_ADDR_T vcMemAddr, size_t numBytes ) { + VC_MEM_ADDR_T origVcMemAddr = vcMemAddr; DBG( "%s %zu bytes @ 0x%08x", mem_op == WRITE_MEM ? "Write" : "Read", numBytes, vcMemAddr ); /* @@ -587,6 +622,15 @@ static int AccessVideoCoreMemory( VC_MEM_ACCESS_HANDLE_T vcHandle, return 0; } #else + // DMA allows memory to be accessed above 1008M and is more coherent so try this first + if (mem_op == READ_MEM) + { + DBG( "AccessVideoCoreMemory: %p, %x, %d", buf, origVcMemAddr, numBytes ); + int s = vc_mem_copy((uint32_t)buf, (uint32_t)origVcMemAddr, numBytes); + if (s == 0) + return 1; + } + { uint8_t *mapAddr; size_t mapSize; diff --git a/host_support/include/vc_mem.h b/host_support/include/vc_mem.h index 0b5a53c..7de7e0b 100755 --- a/host_support/include/vc_mem.h +++ b/host_support/include/vc_mem.h @@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int ) #define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int ) #define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int ) +#define VC_MEM_IOC_MEM_COPY _IOWR( VC_MEM_IOC_MAGIC, 4, char *) #if defined( __KERNEL__ ) #define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF