diff options
Diffstat (limited to 'pvr-source/tools/intern/debug')
-rw-r--r-- | pvr-source/tools/intern/debug/client/linuxsrv.h | 64 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/Kbuild.mk | 51 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/Linux.mk | 45 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv.c | 2883 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv.h | 155 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv_ioctl.h | 57 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/common/handle.c | 141 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/common/hostfunc.h | 82 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/common/hotkey.c | 199 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/common/hotkey.h | 82 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/common/ioctl.c | 827 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/linux/hostfunc.c | 395 | ||||
-rw-r--r-- | pvr-source/tools/intern/debug/dbgdriv/linux/main.c | 355 |
13 files changed, 5336 insertions, 0 deletions
diff --git a/pvr-source/tools/intern/debug/client/linuxsrv.h b/pvr-source/tools/intern/debug/client/linuxsrv.h new file mode 100644 index 0000000..d9fd825 --- /dev/null +++ b/pvr-source/tools/intern/debug/client/linuxsrv.h @@ -0,0 +1,64 @@ +/*************************************************************************/ /*! +@File linuxsrv.h +@Title Module defs for pvr core drivers. +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ + +#ifndef _LINUXSRV_H__ +#define _LINUXSRV_H__ + +typedef struct tagIOCTL_PACKAGE +{ + IMG_UINT32 ui32Cmd; // ioctl command + IMG_UINT32 ui32Size; // needs to be correctly set + IMG_VOID *pInBuffer; // input data buffer + IMG_UINT32 ui32InBufferSize; // size of input data buffer + IMG_VOID *pOutBuffer; // output data buffer + IMG_UINT32 ui32OutBufferSize; // size of output data buffer +} IOCTL_PACKAGE; + +IMG_UINT32 DeviceIoControl(IMG_UINT32 hDevice, + IMG_UINT32 ui32ControlCode, + IMG_VOID *pInBuffer, + IMG_UINT32 ui32InBufferSize, + IMG_VOID *pOutBuffer, + IMG_UINT32 ui32OutBufferSize, + IMG_UINT32 *pui32BytesReturned); + +#endif /* _LINUXSRV_H__*/ diff --git a/pvr-source/tools/intern/debug/dbgdriv/Kbuild.mk b/pvr-source/tools/intern/debug/dbgdriv/Kbuild.mk new file mode 100644 index 0000000..e1e8868 --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/Kbuild.mk @@ -0,0 +1,51 @@ +########################################################################### ### +#@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +#@License Dual MIT/GPLv2 +# +# The contents of this file are subject to the MIT license as set out below. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# Alternatively, the contents of this file may be used under the terms of +# the GNU General Public License Version 2 ("GPL") in which case the provisions +# of GPL are applicable instead of those above. +# +# If you wish to allow use of your version of this file only under the terms of +# GPL, and not to allow others to use your version of this file under the terms +# of the MIT license, indicate your decision by deleting the provisions above +# and replace them with the notice and other provisions required by GPL as set +# out in the file called "GPL-COPYING" included in this distribution. If you do +# not delete the provisions above, a recipient may use your version of this file +# under the terms of either the MIT license or GPL. +# +# This License is also included in this distribution in the file called +# "MIT-COPYING". +# +# EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +# PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +# PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +### ########################################################################### + +ccflags-y += \ + -I$(TOP)/tools/intern/debug/dbgdriv/common \ + -I$(TOP)/tools/intern/debug/client + +dbgdrv-y += \ + tools/intern/debug/dbgdriv/common/dbgdriv.o \ + tools/intern/debug/dbgdriv/common/ioctl.o \ + tools/intern/debug/dbgdriv/common/handle.o \ + tools/intern/debug/dbgdriv/common/hotkey.o \ + tools/intern/debug/dbgdriv/linux/main.o \ + tools/intern/debug/dbgdriv/linux/hostfunc.o diff --git a/pvr-source/tools/intern/debug/dbgdriv/Linux.mk b/pvr-source/tools/intern/debug/dbgdriv/Linux.mk new file mode 100644 index 0000000..e050879 --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/Linux.mk @@ -0,0 +1,45 @@ +########################################################################### ### +#@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +#@License Dual MIT/GPLv2 +# +# The contents of this file are subject to the MIT license as set out below. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# Alternatively, the contents of this file may be used under the terms of +# the GNU General Public License Version 2 ("GPL") in which case the provisions +# of GPL are applicable instead of those above. +# +# If you wish to allow use of your version of this file only under the terms of +# GPL, and not to allow others to use your version of this file under the terms +# of the MIT license, indicate your decision by deleting the provisions above +# and replace them with the notice and other provisions required by GPL as set +# out in the file called "GPL-COPYING" included in this distribution. If you do +# not delete the provisions above, a recipient may use your version of this file +# under the terms of either the MIT license or GPL. +# +# This License is also included in this distribution in the file called +# "MIT-COPYING". +# +# EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +# PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +# PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +### ########################################################################### + +modules := dbgdrv + +dbgdrv_type := kernel_module +dbgdrv_target := dbgdrv.ko +dbgdrv_makefile := $(THIS_DIR)/Kbuild.mk diff --git a/pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv.c b/pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv.c new file mode 100644 index 0000000..0b8d445 --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv.c @@ -0,0 +1,2883 @@ +/*************************************************************************/ /*! +@Title Debug Driver +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@Description 32 Bit kernel mode debug driver +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ + +#ifdef LINUX +#include <linux/string.h> +#endif +#ifdef __QNXNTO__ +#include <string.h> +#endif + +#include "img_types.h" +#include "pvr_debug.h" +#include "dbgdrvif.h" +#include "dbgdriv.h" +#include "hotkey.h" +#include "hostfunc.h" +#include "pvr_debug.h" + + + + +#define LAST_FRAME_BUF_SIZE 1024 + +typedef struct _DBG_LASTFRAME_BUFFER_ +{ + PDBG_STREAM psStream; + IMG_UINT8 ui8Buffer[LAST_FRAME_BUF_SIZE]; + IMG_UINT32 ui32BufLen; + struct _DBG_LASTFRAME_BUFFER_ *psNext; +} *PDBG_LASTFRAME_BUFFER; + +/****************************************************************************** + Global vars +******************************************************************************/ + +static PDBG_STREAM g_psStreamList = 0; +static PDBG_LASTFRAME_BUFFER g_psLFBufferList; + +static IMG_UINT32 g_ui32LOff = 0; +static IMG_UINT32 g_ui32Line = 0; +static IMG_UINT32 g_ui32MonoLines = 25; + +static IMG_BOOL g_bHotkeyMiddump = IMG_FALSE; +static IMG_UINT32 g_ui32HotkeyMiddumpStart = 0xffffffff; +static IMG_UINT32 g_ui32HotkeyMiddumpEnd = 0xffffffff; + +IMG_VOID * g_pvAPIMutex=IMG_NULL; + +extern IMG_UINT32 g_ui32HotKeyFrame; +extern IMG_BOOL g_bHotKeyPressed; +extern IMG_BOOL g_bHotKeyRegistered; + +IMG_BOOL gbDumpThisFrame = IMG_FALSE; + + +IMG_UINT32 SpaceInStream(PDBG_STREAM psStream); +IMG_BOOL ExpandStreamBuffer(PDBG_STREAM psStream, IMG_UINT32 ui32NewSize); +PDBG_LASTFRAME_BUFFER FindLFBuf(PDBG_STREAM psStream); + +/*************************************************************************** + Declare kernel mode service table. +***************************************************************************/ +DBGKM_SERVICE_TABLE g_sDBGKMServices = +{ + sizeof (DBGKM_SERVICE_TABLE), + ExtDBGDrivCreateStream, + ExtDBGDrivDestroyStream, + ExtDBGDrivFindStream, + ExtDBGDrivWriteString, + ExtDBGDrivReadString, + ExtDBGDrivWrite, + ExtDBGDrivRead, + ExtDBGDrivSetCaptureMode, + ExtDBGDrivSetOutputMode, + ExtDBGDrivSetDebugLevel, + ExtDBGDrivSetFrame, + ExtDBGDrivGetFrame, + ExtDBGDrivOverrideMode, + ExtDBGDrivDefaultMode, + ExtDBGDrivWrite2, + ExtDBGDrivWriteStringCM, + ExtDBGDrivWriteCM, + ExtDBGDrivSetMarker, + ExtDBGDrivGetMarker, + ExtDBGDrivStartInitPhase, + ExtDBGDrivStopInitPhase, + ExtDBGDrivIsCaptureFrame, + ExtDBGDrivWriteLF, + ExtDBGDrivReadLF, + ExtDBGDrivGetStreamOffset, + ExtDBGDrivSetStreamOffset, + ExtDBGDrivIsLastCaptureFrame, + ExtDBGDrivWaitForEvent, + ExtDBGDrivSetConnectNotifier, + ExtDBGDrivWritePersist +}; + + +/* Static function declarations */ +static IMG_UINT32 DBGDrivWritePersist(PDBG_STREAM psMainStream,IMG_UINT8 * pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level); +static IMG_VOID InvalidateAllStreams(IMG_VOID); + +/***************************************************************************** + Code +*****************************************************************************/ + + + +DBGKM_CONNECT_NOTIFIER g_fnDBGKMNotifier; + +/*! + @name ExtDBGDrivSetConnectNotifier + @brief Registers one or more services callback functions which are called on events in the dbg driver + @param fn_notifier - services callbacks + @return none + */ +IMG_VOID IMG_CALLCONV ExtDBGDrivSetConnectNotifier(DBGKM_CONNECT_NOTIFIER fn_notifier) +{ + /* Set the callback function which enables the debug driver to + * communicate to services KM when pdump is connected. + */ + g_fnDBGKMNotifier = fn_notifier; +} + +/*! + @name ExtDBGDrivCreateStream + */ +IMG_VOID * IMG_CALLCONV ExtDBGDrivCreateStream(IMG_CHAR * pszName, IMG_UINT32 ui32CapMode, IMG_UINT32 ui32OutMode, IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size) +{ + IMG_VOID * pvRet; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + pvRet=DBGDrivCreateStream(pszName, ui32CapMode, ui32OutMode, ui32Flags, ui32Size); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return pvRet; +} + +/*! + @name ExtDBGDrivDestroyStream + */ +void IMG_CALLCONV ExtDBGDrivDestroyStream(PDBG_STREAM psStream) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivDestroyStream(psStream); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return; +} + +/*! + @name ExtDBGDrivFindStream + */ +IMG_VOID * IMG_CALLCONV ExtDBGDrivFindStream(IMG_CHAR * pszName, IMG_BOOL bResetStream) +{ + IMG_VOID * pvRet; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + pvRet=DBGDrivFindStream(pszName, bResetStream); + if(g_fnDBGKMNotifier.pfnConnectNotifier) + { + g_fnDBGKMNotifier.pfnConnectNotifier(); + } + else + { + PVR_DPF((PVR_DBG_ERROR, "pfnConnectNotifier not initialised.\n")); + } + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return pvRet; +} + +/*! + @name ExtDBGDrivWriteString + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWriteString(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Level) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret=DBGDrivWriteString(psStream, pszString, ui32Level); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivReadString + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivReadString(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Limit) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret=DBGDrivReadString(psStream, pszString, ui32Limit); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivWrite + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWrite(PDBG_STREAM psStream,IMG_UINT8 * pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret=DBGDrivWrite(psStream, pui8InBuf, ui32InBuffSize, ui32Level); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivRead + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivRead(PDBG_STREAM psStream, IMG_BOOL bReadInitBuffer, IMG_UINT32 ui32OutBuffSize,IMG_UINT8 * pui8OutBuf) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret=DBGDrivRead(psStream, bReadInitBuffer, ui32OutBuffSize, pui8OutBuf); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivSetCaptureMode + */ +void IMG_CALLCONV ExtDBGDrivSetCaptureMode(PDBG_STREAM psStream,IMG_UINT32 ui32Mode,IMG_UINT32 ui32Start,IMG_UINT32 ui32End,IMG_UINT32 ui32SampleRate) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivSetCaptureMode(psStream, ui32Mode, ui32Start, ui32End, ui32SampleRate); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return; +} + +/*! + @name ExtDBGDrivSetOutputMode + */ +void IMG_CALLCONV ExtDBGDrivSetOutputMode(PDBG_STREAM psStream,IMG_UINT32 ui32OutMode) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivSetOutputMode(psStream, ui32OutMode); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return; +} + +/*! + @name ExtDBGDrivSetDebugLevel + */ +void IMG_CALLCONV ExtDBGDrivSetDebugLevel(PDBG_STREAM psStream,IMG_UINT32 ui32DebugLevel) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivSetDebugLevel(psStream, ui32DebugLevel); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return; +} + +/*! + @name ExtDBGDrivSetFrame + */ +void IMG_CALLCONV ExtDBGDrivSetFrame(PDBG_STREAM psStream,IMG_UINT32 ui32Frame) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivSetFrame(psStream, ui32Frame); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return; +} + +/*! + @name ExtDBGDrivGetFrame + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivGetFrame(PDBG_STREAM psStream) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret=DBGDrivGetFrame(psStream); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivIsLastCaptureFrame + */ +IMG_BOOL IMG_CALLCONV ExtDBGDrivIsLastCaptureFrame(PDBG_STREAM psStream) +{ + IMG_BOOL bRet; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + bRet = DBGDrivIsLastCaptureFrame(psStream); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return bRet; +} + +/*! + @name ExtDBGDrivIsCaptureFrame + */ +IMG_BOOL IMG_CALLCONV ExtDBGDrivIsCaptureFrame(PDBG_STREAM psStream, IMG_BOOL bCheckPreviousFrame) +{ + IMG_BOOL bRet; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + bRet = DBGDrivIsCaptureFrame(psStream, bCheckPreviousFrame); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return bRet; +} + +/*! + @name ExtDBGDrivOverrideMode + */ +void IMG_CALLCONV ExtDBGDrivOverrideMode(PDBG_STREAM psStream,IMG_UINT32 ui32Mode) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivOverrideMode(psStream, ui32Mode); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return; +} + +/*! + @name ExtDBGDrivDefaultMode + */ +void IMG_CALLCONV ExtDBGDrivDefaultMode(PDBG_STREAM psStream) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivDefaultMode(psStream); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return; +} + +/*! + @name ExtDBGDrivWrite2 + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWrite2(PDBG_STREAM psStream,IMG_UINT8 * pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret=DBGDrivWrite2(psStream, pui8InBuf, ui32InBuffSize, ui32Level); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivWritePersist + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWritePersist(PDBG_STREAM psStream,IMG_UINT8 *pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret=DBGDrivWritePersist(psStream, pui8InBuf, ui32InBuffSize, ui32Level); + if(ui32Ret==0xFFFFFFFFU) + { + PVR_DPF((PVR_DBG_ERROR, "An error occurred in DBGDrivWritePersist.")); + } + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivWriteStringCM + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWriteStringCM(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Level) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret=DBGDrivWriteStringCM(psStream, pszString, ui32Level); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivWriteCM + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWriteCM(PDBG_STREAM psStream,IMG_UINT8 * pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret=DBGDrivWriteCM(psStream, pui8InBuf, ui32InBuffSize, ui32Level); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivSetMarker + */ +void IMG_CALLCONV ExtDBGDrivSetMarker(PDBG_STREAM psStream, IMG_UINT32 ui32Marker) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivSetMarker(psStream, ui32Marker); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return; +} + +/*! + @name ExtDBGDrivGetMarker + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivGetMarker(PDBG_STREAM psStream) +{ + IMG_UINT32 ui32Marker; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Marker = DBGDrivGetMarker(psStream); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Marker; +} + +/*! + @name ExtDBGDrivWriteLF + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWriteLF(PDBG_STREAM psStream, IMG_UINT8 * pui8InBuf, IMG_UINT32 ui32InBuffSize, IMG_UINT32 ui32Level, IMG_UINT32 ui32Flags) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret = DBGDrivWriteLF(psStream, pui8InBuf, ui32InBuffSize, ui32Level, ui32Flags); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivReadLF + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivReadLF(PDBG_STREAM psStream, IMG_UINT32 ui32OutBuffSize, IMG_UINT8 * pui8OutBuf) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret = DBGDrivReadLF(psStream, ui32OutBuffSize, pui8OutBuf); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + + +/*! + @name ExtDBGDrivStartInitPhase + */ +IMG_VOID IMG_CALLCONV ExtDBGDrivStartInitPhase(PDBG_STREAM psStream) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivStartInitPhase(psStream); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return; +} + +/*! + @name ExtDBGDrivStopInitPhase + */ +IMG_VOID IMG_CALLCONV ExtDBGDrivStopInitPhase(PDBG_STREAM psStream) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivStopInitPhase(psStream); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return; +} + +/*! + @name ExtDBGDrivGetStreamOffset + */ +IMG_UINT32 IMG_CALLCONV ExtDBGDrivGetStreamOffset(PDBG_STREAM psStream) +{ + IMG_UINT32 ui32Ret; + + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + ui32Ret = DBGDrivGetStreamOffset(psStream); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); + + return ui32Ret; +} + +/*! + @name ExtDBGDrivSetStreamOffset + */ +IMG_VOID IMG_CALLCONV ExtDBGDrivSetStreamOffset(PDBG_STREAM psStream, IMG_UINT32 ui32StreamOffset) +{ + /* Aquire API Mutex */ + HostAquireMutex(g_pvAPIMutex); + + DBGDrivSetStreamOffset(psStream, ui32StreamOffset); + + /* Release API Mutex */ + HostReleaseMutex(g_pvAPIMutex); +} + +/*! + @name ExtDBGDrivWaitForEvent + */ +IMG_VOID IMG_CALLCONV ExtDBGDrivWaitForEvent(DBG_EVENT eEvent) +{ +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) + DBGDrivWaitForEvent(eEvent); +#else /* defined(SUPPORT_DBGDRV_EVENT_OBJECTS) */ + PVR_UNREFERENCED_PARAMETER(eEvent); /* PRQA S 3358 */ +#endif /* defined(SUPPORT_DBGDRV_EVENT_OBJECTS) */ +} + +/*!**************************************************************************** + @name AtoI + @brief Returns the integer value of a decimal string + @param szIn - String with hexadecimal value + @return IMG_UINT32 integer value, 0 if string is null or not valid + Based on Max`s one, now copes with (only) hex ui32ords, upper or lower case a-f. +*****************************************************************************/ +IMG_UINT32 AtoI(IMG_CHAR *szIn) +{ + IMG_INT iLen = 0; + IMG_UINT32 ui32Value = 0; + IMG_UINT32 ui32Digit=1; + IMG_UINT32 ui32Base=10; + IMG_INT iPos; + IMG_CHAR bc; + + //get len of string + while (szIn[iLen] > 0) + { + iLen ++; + } + + //nothing to do + if (iLen == 0) + { + return (0); + } + + /* See if we have an 'x' or 'X' before the number to make it a hex number */ + iPos=0; + while (szIn[iPos] == '0') + { + iPos++; + } + if (szIn[iPos] == '\0') + { + return 0; + } + if (szIn[iPos] == 'x' || szIn[iPos] == 'X') + { + ui32Base=16; + szIn[iPos]='0'; + } + + //go through string from right (least significant) to left + for (iPos = iLen - 1; iPos >= 0; iPos --) + { + bc = szIn[iPos]; + + if ( (bc >= 'a') && (bc <= 'f') && ui32Base == 16) //handle lower case a-f + { + bc -= 'a' - 0xa; + } + else + if ( (bc >= 'A') && (bc <= 'F') && ui32Base == 16) //handle upper case A-F + { + bc -= 'A' - 0xa; + } + else + if ((bc >= '0') && (bc <= '9')) //if char out of range, return 0 + { + bc -= '0'; + } + else + return (0); + + ui32Value += (IMG_UINT32)bc * ui32Digit; + + ui32Digit = ui32Digit * ui32Base; + } + return (ui32Value); +} + + +/*!**************************************************************************** + @name StreamValid + @brief Validates supplied debug buffer. + @param psStream - debug stream + @return true if valid +*****************************************************************************/ +static IMG_BOOL StreamValid(PDBG_STREAM psStream) +{ + PDBG_STREAM psThis; + + psThis = g_psStreamList; + + while (psThis) + { + if (psStream && (psThis == psStream) ) + { + return(IMG_TRUE); + } + else + { + psThis = psThis->psNext; + } + } + + return(IMG_FALSE); +} + + +/*!**************************************************************************** + @name StreamValidForRead + @brief Validates supplied debug buffer for read op. + @param psStream - debug stream + @return true if readable +*****************************************************************************/ +static IMG_BOOL StreamValidForRead(PDBG_STREAM psStream) +{ + if( StreamValid(psStream) && + ((psStream->psCtrl->ui32Flags & DEBUG_FLAGS_WRITEONLY) == 0) ) + { + return(IMG_TRUE); + } + + return(IMG_FALSE); +} + +/*!**************************************************************************** + @name StreamValidForWrite + @brief Validates supplied debug buffer for write op. + @param psStream - debug stream + @return true if writable +*****************************************************************************/ +static IMG_BOOL StreamValidForWrite(PDBG_STREAM psStream) +{ + if( StreamValid(psStream) && + ((psStream->psCtrl->ui32Flags & DEBUG_FLAGS_READONLY) == 0) ) + { + return(IMG_TRUE); + } + + return(IMG_FALSE); +} + + +/*!**************************************************************************** + @name Write + @brief Copies data from a buffer into selected stream. Stream size is fixed. + @param psStream - stream for output + @param pui8Data - input buffer + @param ui32InBuffSize - size of input + @return none +*****************************************************************************/ +static void Write(PDBG_STREAM psStream,IMG_PUINT8 pui8Data,IMG_UINT32 ui32InBuffSize) +{ + /* + Split copy into two bits as necessary (if we're allowed to wrap). + */ + if (!psStream->bCircularAllowed) + { + //PVR_ASSERT( (psStream->ui32WPtr + ui32InBuffSize) < psStream->ui32Size ); + } + + if ((psStream->ui32WPtr + ui32InBuffSize) > psStream->ui32Size) + { + /* Yes we need two bits, calculate their sizes */ + IMG_UINT32 ui32B1 = psStream->ui32Size - psStream->ui32WPtr; + IMG_UINT32 ui32B2 = ui32InBuffSize - ui32B1; + + /* Copy first block to current location */ + HostMemCopy((IMG_PVOID)((IMG_UINTPTR_T)psStream->pvBase + psStream->ui32WPtr), + (IMG_PVOID) pui8Data, + ui32B1); + + /* Copy second block to start of buffer */ + HostMemCopy(psStream->pvBase, + (IMG_PVOID)(pui8Data + ui32B1), + ui32B2); + + /* Set pointer to be the new end point */ + psStream->ui32WPtr = ui32B2; + } + else + { /* Can fit block in single chunk */ + HostMemCopy((IMG_PVOID)((IMG_UINTPTR_T)psStream->pvBase + psStream->ui32WPtr), + (IMG_PVOID) pui8Data, + ui32InBuffSize); + + psStream->ui32WPtr += ui32InBuffSize; + + if (psStream->ui32WPtr == psStream->ui32Size) + { + psStream->ui32WPtr = 0; + } + } + psStream->ui32DataWritten += ui32InBuffSize; +} + + +/*!**************************************************************************** + @name MonoOut + @brief Output data to mono display. [Possibly deprecated] + @param pszString - input + @param bNewLine - line wrapping + @return none +*****************************************************************************/ +void MonoOut(IMG_CHAR * pszString,IMG_BOOL bNewLine) +{ +#if defined (_WIN64) + PVR_UNREFERENCED_PARAMETER(pszString); + PVR_UNREFERENCED_PARAMETER(bNewLine); + +#else + IMG_UINT32 i; + IMG_CHAR * pScreen; + + pScreen = (IMG_CHAR *) DBGDRIV_MONOBASE; + + pScreen += g_ui32Line * 160; + + /* + Write the string. + */ + i=0; + do + { + pScreen[g_ui32LOff + (i*2)] = pszString[i]; + pScreen[g_ui32LOff + (i*2)+1] = 127; + i++; + } + while ((pszString[i] != 0) && (i < 4096)); + + g_ui32LOff += i * 2; + + if (bNewLine) + { + g_ui32LOff = 0; + g_ui32Line++; + } + + /* + Scroll if necssary. + */ + if (g_ui32Line == g_ui32MonoLines) + { + g_ui32Line = g_ui32MonoLines - 1; + + HostMemCopy((IMG_VOID *)DBGDRIV_MONOBASE,(IMG_VOID *)(DBGDRIV_MONOBASE + 160),160 * (g_ui32MonoLines - 1)); + + HostMemSet((IMG_VOID *)(DBGDRIV_MONOBASE + (160 * (g_ui32MonoLines - 1))),0,160); + } +#endif +} + +/*!**************************************************************************** + @name WriteExpandingBuffer + @brief Copies data from a buffer into selected stream. Stream size may be expandable. + @param psStream - stream for output + @param pui8InBuf - input buffer + @param ui32InBuffSize - size of input + @return bytes copied +*****************************************************************************/ +static IMG_UINT32 WriteExpandingBuffer(PDBG_STREAM psStream,IMG_UINT8 * pui8InBuf,IMG_UINT32 ui32InBuffSize) +{ + IMG_UINT ui32Space; + + /* + How much space have we got in the buffer ? + */ + ui32Space = SpaceInStream(psStream); + + /* + Don't copy anything if we don't have space or buffers not enabled. + */ + if ((psStream->psCtrl->ui32OutMode & DEBUG_OUTMODE_STREAMENABLE) == 0) + { + PVR_DPF((PVR_DBG_ERROR, "WriteExpandingBuffer: buffer %x is disabled", (IMG_UINTPTR_T) psStream)); + return(0); + } + + /* + Check if we can expand the buffer + */ + if (psStream->psCtrl->ui32Flags & DEBUG_FLAGS_NO_BUF_EXPANDSION) + { + /* + Don't do anything if we've got less that 32 ui8tes of space and + we're not allowing expansion of buffer space... + */ + if (ui32Space < 32) + { + PVR_DPF((PVR_DBG_ERROR, "WriteExpandingBuffer: buffer %x is full and isn't expandable", (IMG_UINTPTR_T) psStream)); + return(0); + } + } + else + { + if ((ui32Space < 32) || (ui32Space <= (ui32InBuffSize + 4))) + { + IMG_UINT32 ui32NewBufSize; + + /* + Find new buffer size + */ + ui32NewBufSize = 2 * psStream->ui32Size; + + PVR_DPF((PVR_DBGDRIV_MESSAGE, "Expanding buffer size = %x, new size = %x", + psStream->ui32Size, ui32NewBufSize)); + + if (ui32InBuffSize > psStream->ui32Size) + { + ui32NewBufSize += ui32InBuffSize; + } + + /* + Attempt to expand the buffer + */ + if (!ExpandStreamBuffer(psStream,ui32NewBufSize)) + { + if (ui32Space < 32) + { + if(psStream->bCircularAllowed) + { + return(0); + } + else + { + /* out of memory */ + PVR_DPF((PVR_DBG_ERROR, "WriteExpandingBuffer: Unable to expand %x. Out of memory.", (IMG_UINTPTR_T) psStream)); + InvalidateAllStreams(); + return (0xFFFFFFFFUL); + } + } + } + + /* + Recalc the space in the buffer + */ + ui32Space = SpaceInStream(psStream); + PVR_DPF((PVR_DBGDRIV_MESSAGE, "Expanded buffer, free space = %x", + ui32Space)); + } + } + + /* + Only copy what we can.. + */ + if (ui32Space <= (ui32InBuffSize + 4)) + { + ui32InBuffSize = ui32Space - 4; + } + + /* + Write the stuff... + */ + Write(psStream,pui8InBuf,ui32InBuffSize); + +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) + if (ui32InBuffSize) + { + HostSignalEvent(DBG_EVENT_STREAM_DATA); + } +#endif + return(ui32InBuffSize); +} + +/***************************************************************************** +****************************************************************************** +****************************************************************************** + THE ACTUAL FUNCTIONS +****************************************************************************** +****************************************************************************** +*****************************************************************************/ + +/*!**************************************************************************** + @name DBGDrivCreateStream + @brief Creates a pdump/debug stream + @param pszName - stream name + @param ui32CapMode - capture mode (framed, continuous, hotkey) + @param ui32OutMode - output mode (see dbgdrvif.h) + @param ui32Flags - output flags, text stream bit is set for pdumping + @param ui32Size - size of stream buffer in pages + @return none +*****************************************************************************/ +IMG_VOID * IMG_CALLCONV DBGDrivCreateStream(IMG_CHAR * pszName, + IMG_UINT32 ui32CapMode, + IMG_UINT32 ui32OutMode, + IMG_UINT32 ui32Flags, + IMG_UINT32 ui32Size) +{ + PDBG_STREAM psStream; + PDBG_STREAM psInitStream; + PDBG_LASTFRAME_BUFFER psLFBuffer; + PDBG_STREAM_CONTROL psCtrl; + IMG_UINT32 ui32Off; + IMG_VOID * pvBase; + static IMG_CHAR pszNameInitSuffix[] = "_Init"; + IMG_UINT32 ui32OffSuffix; + + /* + If we already have a buffer using this name just return + its handle. + */ + psStream = (PDBG_STREAM) DBGDrivFindStream(pszName, IMG_FALSE); + + if (psStream) + { + return ((IMG_VOID *) psStream); + } + + /* + Allocate memory for control structures + */ + psStream = HostNonPageablePageAlloc(1); + psInitStream = HostNonPageablePageAlloc(1); + psLFBuffer = HostNonPageablePageAlloc(1); + psCtrl = HostNonPageablePageAlloc(1); + if ( + (!psStream) || + (!psInitStream) || + (!psLFBuffer) || + (!psCtrl) + ) + { + PVR_DPF((PVR_DBG_ERROR,"DBGDriv: Couldn't alloc control structs\n\r")); + return((IMG_VOID *) 0); + } + + /* Allocate memory for buffer */ + if ((ui32Flags & DEBUG_FLAGS_USE_NONPAGED_MEM) != 0) + { + pvBase = HostNonPageablePageAlloc(ui32Size); + } + else + { + pvBase = HostPageablePageAlloc(ui32Size); + } + + if (!pvBase) + { + PVR_DPF((PVR_DBG_ERROR,"DBGDriv: Couldn't alloc Stream buffer\n\r")); + HostNonPageablePageFree(psStream); + return((IMG_VOID *) 0); + } + + /* Setup control state */ + psCtrl->ui32Flags = ui32Flags; + psCtrl->ui32CapMode = ui32CapMode; + psCtrl->ui32OutMode = ui32OutMode; + psCtrl->ui32DebugLevel = DEBUG_LEVEL_0; + psCtrl->ui32DefaultMode = ui32CapMode; + psCtrl->ui32Start = 0; + psCtrl->ui32End = 0; + psCtrl->ui32Current = 0; + psCtrl->ui32SampleRate = 1; + psCtrl->bInitPhaseComplete = IMG_FALSE; + + /* + Setup internal debug buffer state. + */ + psStream->psNext = 0; + psStream->pvBase = pvBase; + psStream->psCtrl = psCtrl; + psStream->ui32Size = ui32Size * 4096UL; + psStream->ui32RPtr = 0; + psStream->ui32WPtr = 0; + psStream->ui32DataWritten = 0; + psStream->ui32Marker = 0; + psStream->bCircularAllowed = IMG_TRUE; + psStream->ui32InitPhaseWOff = 0; + + /* Allocate memory for buffer */ + if ((ui32Flags & DEBUG_FLAGS_USE_NONPAGED_MEM) != 0) + { + pvBase = HostNonPageablePageAlloc(ui32Size); + } + else + { + pvBase = HostPageablePageAlloc(ui32Size); + } + + if (!pvBase) + { + PVR_DPF((PVR_DBG_ERROR,"DBGDriv: Couldn't alloc InitStream buffer\n\r")); + + if ((psStream->psCtrl->ui32Flags & DEBUG_FLAGS_USE_NONPAGED_MEM) != 0) + { + HostNonPageablePageFree(psStream->pvBase); + } + else + { + HostPageablePageFree(psStream->pvBase); + } + HostNonPageablePageFree(psStream); + return((IMG_VOID *) 0); + } + + /* Initialise the stream for the init phase */ + psInitStream->psNext = 0; + psInitStream->pvBase = pvBase; + psInitStream->psCtrl = psCtrl; + psInitStream->ui32Size = ui32Size * 4096UL; + psInitStream->ui32RPtr = 0; + psInitStream->ui32WPtr = 0; + psInitStream->ui32DataWritten = 0; + psInitStream->ui32Marker = 0; + psInitStream->bCircularAllowed = IMG_FALSE; + psInitStream->ui32InitPhaseWOff = 0; + psStream->psInitStream = psInitStream; + + /* Setup last frame buffer */ + psLFBuffer->psStream = psStream; + psLFBuffer->ui32BufLen = 0UL; + + g_bHotkeyMiddump = IMG_FALSE; + g_ui32HotkeyMiddumpStart = 0xffffffffUL; + g_ui32HotkeyMiddumpEnd = 0xffffffffUL; + + /* + Copy buffer name. + */ + ui32Off = 0; + + do + { + psStream->szName[ui32Off] = pszName[ui32Off]; + psInitStream->szName[ui32Off] = pszName[ui32Off]; + ui32Off++; + } + while ((pszName[ui32Off] != 0) && (ui32Off < (4096UL - sizeof(DBG_STREAM)))); + psStream->szName[ui32Off] = pszName[ui32Off]; /* PRQA S 3689 */ + + /* + Append suffix to init phase name + */ + ui32OffSuffix = 0; + do + { + psInitStream->szName[ui32Off] = pszNameInitSuffix[ui32OffSuffix]; + ui32Off++; + ui32OffSuffix++; + } + while ( (pszNameInitSuffix[ui32OffSuffix] != 0) && + (ui32Off < (4096UL - sizeof(DBG_STREAM)))); + psInitStream->szName[ui32Off] = pszNameInitSuffix[ui32OffSuffix]; /* PRQA S 3689 */ + + /* + Insert into list. + */ + psStream->psNext = g_psStreamList; + g_psStreamList = psStream; + + psLFBuffer->psNext = g_psLFBufferList; + g_psLFBufferList = psLFBuffer; + + AddSIDEntry(psStream); + + return((IMG_VOID *) psStream); +} + +/*!**************************************************************************** + @name DBGDrivDestroyStream + @brief Delete a stream and free its memory + @param psStream - stream to be removed + @return none +*****************************************************************************/ +void IMG_CALLCONV DBGDrivDestroyStream(PDBG_STREAM psStream) +{ + PDBG_STREAM psStreamThis; + PDBG_STREAM psStreamPrev; + PDBG_LASTFRAME_BUFFER psLFBuffer; + PDBG_LASTFRAME_BUFFER psLFThis; + PDBG_LASTFRAME_BUFFER psLFPrev; + + PVR_DPF((PVR_DBG_MESSAGE, "DBGDriv: Destroying stream %s\r\n", psStream->szName )); + + /* + Validate buffer. + */ + if (!StreamValid(psStream)) + { + return; + } + + RemoveSIDEntry(psStream); + + psLFBuffer = FindLFBuf(psStream); + + /* + Remove from linked list. + */ + psStreamThis = g_psStreamList; + psStreamPrev = 0; + + while (psStreamThis) + { + if (psStreamThis == psStream) + { + if (psStreamPrev) + { + psStreamPrev->psNext = psStreamThis->psNext; + } + else + { + g_psStreamList = psStreamThis->psNext; + } + + psStreamThis = 0; + } + else + { + psStreamPrev = psStreamThis; + psStreamThis = psStreamThis->psNext; + } + } + + psLFThis = g_psLFBufferList; + psLFPrev = 0; + + while (psLFThis) + { + if (psLFThis == psLFBuffer) + { + if (psLFPrev) + { + psLFPrev->psNext = psLFThis->psNext; + } + else + { + g_psLFBufferList = psLFThis->psNext; + } + + psLFThis = 0; + } + else + { + psLFPrev = psLFThis; + psLFThis = psLFThis->psNext; + } + } + /* + Dectivate hotkey it the stream is of this type. + */ + if (psStream->psCtrl->ui32CapMode & DEBUG_CAPMODE_HOTKEY) + { + DeactivateHotKeys(); + } + + /* + And free its memory. + */ + if ((psStream->psCtrl->ui32Flags & DEBUG_FLAGS_USE_NONPAGED_MEM) != 0) + { + HostNonPageablePageFree(psStream->psCtrl); + HostNonPageablePageFree(psStream->pvBase); + HostNonPageablePageFree(psStream->psInitStream->pvBase); + } + else + { + HostNonPageablePageFree(psStream->psCtrl); + HostPageablePageFree(psStream->pvBase); + HostPageablePageFree(psStream->psInitStream->pvBase); + } + + HostNonPageablePageFree(psStream->psInitStream); + HostNonPageablePageFree(psStream); + HostNonPageablePageFree(psLFBuffer); + + if (g_psStreamList == 0) + { + PVR_DPF((PVR_DBG_MESSAGE,"DBGDriv: Stream list now empty" )); + } + + return; +} + +/*!**************************************************************************** + @name DBGDrivFindStream + @brief Finds/resets a named stream + @param pszName - stream name + @param bResetStream - whether to reset the stream, e.g. to end pdump init phase + @return none +*****************************************************************************/ +IMG_VOID * IMG_CALLCONV DBGDrivFindStream(IMG_CHAR * pszName, IMG_BOOL bResetStream) +{ + PDBG_STREAM psStream; + PDBG_STREAM psThis; + IMG_UINT32 ui32Off; + IMG_BOOL bAreSame; + + psStream = 0; + + PVR_DPF((PVR_DBGDRIV_MESSAGE, "PDump client connecting to %s %s", + pszName, + (bResetStream == IMG_TRUE) ? "with reset" : "no reset")); + + /* + Scan buffer names for supplied one. + */ + for (psThis = g_psStreamList; psThis != IMG_NULL; psThis = psThis->psNext) + { + bAreSame = IMG_TRUE; + ui32Off = 0; + + if (strlen(psThis->szName) == strlen(pszName)) + { + while ((psThis->szName[ui32Off] != 0) && (pszName[ui32Off] != 0) && (ui32Off < 128) && bAreSame) + { + if (psThis->szName[ui32Off] != pszName[ui32Off]) + { + bAreSame = IMG_FALSE; + } + + ui32Off++; + } + } + else + { + bAreSame = IMG_FALSE; + } + + if (bAreSame) + { + psStream = psThis; + break; + } + } + + if(bResetStream && psStream) + { + static IMG_CHAR szComment[] = "-- Init phase terminated\r\n"; + psStream->psInitStream->ui32RPtr = 0; + psStream->ui32RPtr = 0; + psStream->ui32WPtr = 0; + psStream->ui32DataWritten = psStream->psInitStream->ui32DataWritten; + if (psStream->psCtrl->bInitPhaseComplete == IMG_FALSE) + { + if (psStream->psCtrl->ui32Flags & DEBUG_FLAGS_TEXTSTREAM) + { + DBGDrivWrite2(psStream, (IMG_UINT8 *)szComment, sizeof(szComment) - 1, 0x01); + } + psStream->psCtrl->bInitPhaseComplete = IMG_TRUE; + } + + { + /* mark init stream to prevent further reading by pdump client */ + psStream->psInitStream->ui32InitPhaseWOff = psStream->psInitStream->ui32WPtr; + PVR_DPF((PVR_DBGDRIV_MESSAGE, "Set %s client marker bo %x, total bw %x", + psStream->szName, + psStream->psInitStream->ui32InitPhaseWOff, + psStream->psInitStream->ui32DataWritten )); + } + } + + return((IMG_VOID *) psStream); +} + +static void IMG_CALLCONV DBGDrivInvalidateStream(PDBG_STREAM psStream) +{ + IMG_CHAR pszErrorMsg[] = "**OUTOFMEM\n"; + IMG_UINT32 ui32Space; + IMG_UINT32 ui32Off = 0; + IMG_UINT32 ui32WPtr = psStream->ui32WPtr; + IMG_PUINT8 pui8Buffer = (IMG_UINT8 *) psStream->pvBase; + + PVR_DPF((PVR_DBG_ERROR, "DBGDrivInvalidateStream: An error occurred for stream %s\r\n", psStream->szName )); + + /* + Validate buffer. + */ + /* + if (!StreamValid(psStream)) + { + return; + } +*/ + /* Write what we can of the error message */ + ui32Space = SpaceInStream(psStream); + + /* Make sure there's space for termination character */ + if(ui32Space > 0) + { + ui32Space--; + } + else + { + PVR_DPF((PVR_DBG_ERROR, "DBGDrivInvalidateStream: Buffer full.")); + } + + while((pszErrorMsg[ui32Off] != 0) && (ui32Off < ui32Space)) + { + pui8Buffer[ui32WPtr] = (IMG_UINT8)pszErrorMsg[ui32Off]; + ui32Off++; + ui32WPtr++; + } + pui8Buffer[ui32WPtr++] = '\0'; + psStream->ui32WPtr = ui32WPtr; + + /* Buffer will accept no more params from Services/client driver */ + psStream->psCtrl->ui32Flags |= DEBUG_FLAGS_READONLY; +} + +/*!**************************************************************************** + @name InvalidateAllStreams + @brief invalidate all streams in list + @return none +*****************************************************************************/ +static IMG_VOID InvalidateAllStreams(IMG_VOID) +{ + PDBG_STREAM psStream = g_psStreamList; + while (psStream != IMG_NULL) + { + DBGDrivInvalidateStream(psStream); + psStream = psStream->psNext; + } + return; +} + + + +/*!**************************************************************************** + @name DBGDrivWriteStringCM + @brief Write capture mode data, wraps DBGDrivWriteString + @param psStream - stream + @param pszString - input buffer + @param ui32Level - debug level +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivWriteStringCM(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Level) +{ + /* + Validate buffer. + */ + if (!StreamValidForWrite(psStream)) + { + return(0xFFFFFFFFUL); + } + + /* + Only write string if debug capture mode adds up... + */ + if (psStream->psCtrl->ui32CapMode & DEBUG_CAPMODE_FRAMED) + { + if ((psStream->psCtrl->ui32Flags & DEBUG_FLAGS_ENABLESAMPLE) == 0) + { + return(0); + } + } + else + { + if (psStream->psCtrl->ui32CapMode == DEBUG_CAPMODE_HOTKEY) + { + if ((psStream->psCtrl->ui32Current != g_ui32HotKeyFrame) || (g_bHotKeyPressed == IMG_FALSE)) + { + return(0); + } + } + } + + return(DBGDrivWriteString(psStream,pszString,ui32Level)); + +} + +/*!**************************************************************************** + @name DBGDrivWriteString + @brief Write string to stream (note stream buffer size is assumed fixed) + @param psStream - stream + @param pszString - string to write + @param ui32Level - verbosity level + @return -1; invalid stream + 0; other error (e.g. stream not enabled) + else number of characters written +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivWriteString(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Level) +{ + IMG_UINT32 ui32Len; + IMG_UINT32 ui32Space; + IMG_UINT32 ui32WPtr; + IMG_UINT8 * pui8Buffer; + + /* + Validate buffer. + */ + if (!StreamValidForWrite(psStream)) + { + return(0xFFFFFFFFUL); + } + + /* + Check debug level. + */ + if ((psStream->psCtrl->ui32DebugLevel & ui32Level) == 0) + { + return(0xFFFFFFFFUL); + } + + /* + Output to standard debug out ? (don't if async out + flag is set). + */ + if ((psStream->psCtrl->ui32OutMode & DEBUG_OUTMODE_ASYNC) == 0) + { + if (psStream->psCtrl->ui32OutMode & DEBUG_OUTMODE_STANDARDDBG) + { + PVR_DPF((PVR_DBG_MESSAGE,"%s: %s\r\n",psStream->szName, pszString)); + } + + /* + Output to mono monitor ? + */ + if (psStream->psCtrl->ui32OutMode & DEBUG_OUTMODE_MONO) + { + MonoOut(psStream->szName,IMG_FALSE); + MonoOut(": ",IMG_FALSE); + MonoOut(pszString,IMG_TRUE); + } + } + + /* + Don't bother writing the string if it's not flagged + */ + if ( + !( + ((psStream->psCtrl->ui32OutMode & DEBUG_OUTMODE_STREAMENABLE) != 0) || + ((psStream->psCtrl->ui32OutMode & DEBUG_OUTMODE_ASYNC) != 0) + ) + ) + { + return(0xFFFFFFFFUL); + } + + /* + How much space have we got in the buffer ? + */ + ui32Space=SpaceInStream(psStream); + + /* Make sure there's space for termination character */ + if(ui32Space > 0) + { + ui32Space--; + } + + ui32Len = 0; + ui32WPtr = psStream->ui32WPtr; + pui8Buffer = (IMG_UINT8 *) psStream->pvBase; + + while((pszString[ui32Len] != 0) && (ui32Len < ui32Space)) + { + pui8Buffer[ui32WPtr] = (IMG_UINT8)pszString[ui32Len]; + ui32Len++; + ui32WPtr++; + if (ui32WPtr == psStream->ui32Size) + { + ui32WPtr = 0; + } + } + + if (ui32Len < ui32Space) + { + /* copy terminator */ + pui8Buffer[ui32WPtr] = (IMG_UINT8)pszString[ui32Len]; + ui32Len++; + ui32WPtr++; + if (ui32WPtr == psStream->ui32Size) + { + ui32WPtr = 0; + } + + /* Write pointer, and length */ + psStream->ui32WPtr = ui32WPtr; + psStream->ui32DataWritten+= ui32Len; + } else + { + ui32Len = 0; + } + +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) + if (ui32Len) + { + HostSignalEvent(DBG_EVENT_STREAM_DATA); + } +#endif + + return(ui32Len); +} + +/*!**************************************************************************** + @name DBGDrivReadString + @brief Reads string from debug stream + @param psStream - stream + @param pszString - string to read + @param ui32Limit - max size to read + @return -1; invalid stream + 0; other error (e.g. stream not enabled) + else number of characters read +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivReadString(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Limit) +{ + IMG_UINT32 ui32OutLen; + IMG_UINT32 ui32Len; + IMG_UINT32 ui32Offset; + IMG_UINT8 *pui8Buff; + + /* + Validate buffer. + */ + if (!StreamValidForRead(psStream)) + { + return(0); + } + + /* + Stream appears to be in list so carry on. + */ + pui8Buff = (IMG_UINT8 *)psStream->pvBase; + ui32Offset = psStream->ui32RPtr; + + if (psStream->ui32RPtr == psStream->ui32WPtr) + { + return(0); + } + + /* + Find length of string. + */ + ui32Len = 0; + while((pui8Buff[ui32Offset] != 0) && (ui32Offset != psStream->ui32WPtr)) + { + ui32Offset++; + ui32Len++; + + /* + Reset offset if buffer wrapped. + */ + if (ui32Offset == psStream->ui32Size) + { + ui32Offset = 0; + } + } + + ui32OutLen = ui32Len + 1; + + /* + Only copy string if target has enough space. + */ + if (ui32Len > ui32Limit) + { + return(0); + } + + /* + Copy it. + */ + ui32Offset = psStream->ui32RPtr; + ui32Len = 0; + + while ((pui8Buff[ui32Offset] != 0) && (ui32Len < ui32Limit)) + { + pszString[ui32Len] = (IMG_CHAR)pui8Buff[ui32Offset]; + ui32Offset++; + ui32Len++; + + /* + If wrap as necessary + */ + if (ui32Offset == psStream->ui32Size) + { + ui32Offset = 0; + } + } + + pszString[ui32Len] = (IMG_CHAR)pui8Buff[ui32Offset]; + + psStream->ui32RPtr = ui32Offset + 1; + + if (psStream->ui32RPtr == psStream->ui32Size) + { + psStream->ui32RPtr = 0; + } + + return(ui32OutLen); +} + +/*!**************************************************************************** + @name DBGDrivWrite + @brief Write binary buffer to stream (fixed size) + @param psStream - stream + @param pui8InBuf - buffer to write + @param ui32InBuffSize - size + @param ui32Level - verbosity level + @return bytes written, 0 if recoverable error, -1 if unrecoverable error +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivWrite(PDBG_STREAM psMainStream,IMG_UINT8 * pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level) +{ + IMG_UINT32 ui32Space; + DBG_STREAM *psStream; + + /* + Validate buffer. + */ + if (!StreamValidForWrite(psMainStream)) + { + return(0xFFFFFFFFUL); + } + + /* + Check debug level. + */ + if ((psMainStream->psCtrl->ui32DebugLevel & ui32Level) == 0) + { + return(0xFFFFFFFFUL); + } + + /* + Only write data if debug mode adds up... + */ + if (psMainStream->psCtrl->ui32CapMode & DEBUG_CAPMODE_FRAMED) + { + if ((psMainStream->psCtrl->ui32Flags & DEBUG_FLAGS_ENABLESAMPLE) == 0) + { + /* throw away non-capturing data */ + return(ui32InBuffSize); + } + } + else if (psMainStream->psCtrl->ui32CapMode == DEBUG_CAPMODE_HOTKEY) + { + if ((psMainStream->psCtrl->ui32Current != g_ui32HotKeyFrame) || (g_bHotKeyPressed == IMG_FALSE)) + { + /* throw away non-capturing data */ + return(ui32InBuffSize); + } + } + + if(psMainStream->psCtrl->bInitPhaseComplete) + { + psStream = psMainStream; + } + else + { + psStream = psMainStream->psInitStream; + } + + /* + How much space have we got in the buffer ? + */ + ui32Space=SpaceInStream(psStream); + + PVR_DPF((PVR_DBGDRIV_MESSAGE, "Recv %d b for %s: Roff = %x, WOff = %x", + ui32InBuffSize, + psStream->szName, + psStream->ui32RPtr, + psStream->ui32WPtr)); + + /* + Don't copy anything if we don't have space or buffers not enabled. + */ + if ((psStream->psCtrl->ui32OutMode & DEBUG_OUTMODE_STREAMENABLE) == 0) + { + PVR_DPF((PVR_DBG_ERROR, "DBGDrivWrite: buffer %x is disabled", (IMG_UINTPTR_T) psStream)); + return(0); + } + + if (ui32Space < 8) + { + PVR_DPF((PVR_DBG_ERROR, "DBGDrivWrite: buffer %x is full", (IMG_UINTPTR_T) psStream)); + return(0); + } + + /* + Only copy what we can.. + */ + if (ui32Space <= (ui32InBuffSize + 4)) + { + ui32InBuffSize = ui32Space - 8; + } + + /* + Write the stuff... + */ + Write(psStream,(IMG_UINT8 *) &ui32InBuffSize,4); + Write(psStream,pui8InBuf,ui32InBuffSize); + +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) + if (ui32InBuffSize) + { + HostSignalEvent(DBG_EVENT_STREAM_DATA); + } +#endif + return(ui32InBuffSize); +} + +/*!**************************************************************************** + @name DBGDrivWriteCM + @brief Write capture mode data, wraps DBGDrivWrite + @param psStream - stream + @param pui8InBuf - input buffer + @param ui32InBuffSize - buffer size + @param ui32Level - verbosity level + @return bytes written, 0 if recoverable error, -1 if unrecoverable error +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivWriteCM(PDBG_STREAM psStream,IMG_UINT8 * pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level) +{ + /* + Validate buffer. + */ + if (!StreamValidForWrite(psStream)) + { + return(0xFFFFFFFFUL); + } + + /* + Only write data if debug mode adds up... + */ + if (psStream->psCtrl->ui32CapMode & DEBUG_CAPMODE_FRAMED) + { + if ((psStream->psCtrl->ui32Flags & DEBUG_FLAGS_ENABLESAMPLE) == 0) + { + /* throw away non-capturing data */ + return(ui32InBuffSize); + } + } + else + { + if (psStream->psCtrl->ui32CapMode == DEBUG_CAPMODE_HOTKEY) + { + if ((psStream->psCtrl->ui32Current != g_ui32HotKeyFrame) || (g_bHotKeyPressed == IMG_FALSE)) + { + /* throw away non-capturing data */ + return(ui32InBuffSize); + } + } + } + + return(DBGDrivWrite2(psStream,pui8InBuf,ui32InBuffSize,ui32Level)); +} + + +/*!**************************************************************************** + @name DBGDrivWritePersist + @brief Copies data from a buffer into selected stream's init phase. Stream size should be expandable. + @param psStream - stream for output + @param pui8InBuf - input buffer + @param ui32InBuffSize - size of input + @param ui32Level - not used + @return bytes copied, 0 if recoverable error, -1 if unrecoverable error +*****************************************************************************/ +static IMG_UINT32 DBGDrivWritePersist(PDBG_STREAM psMainStream,IMG_UINT8 * pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level) +{ + DBG_STREAM *psStream; + PVR_UNREFERENCED_PARAMETER(ui32Level); + + /* + Validate buffer. + */ + if (!StreamValidForWrite(psMainStream)) + { + return(0xFFFFFFFFUL); + } + + /* Always append persistent data to init phase so it's available on + * subsequent app runs. + */ + psStream = psMainStream->psInitStream; + if(psStream->bCircularAllowed == IMG_TRUE) + { + PVR_DPF((PVR_DBG_WARNING, "DBGDrivWritePersist: Init phase is a circular buffer, some data may be lost")); + } + + PVR_DPF((PVR_DBGDRIV_MESSAGE, "Append %x b to %s: Roff = %x, WOff = %x [bw = %x]", + ui32InBuffSize, + psStream->szName, + psStream->ui32RPtr, + psStream->ui32WPtr, + psStream->ui32DataWritten)); + + return( WriteExpandingBuffer(psStream, pui8InBuf, ui32InBuffSize) ); +} + +/*!**************************************************************************** + @name DBGDrivWrite2 + @brief Copies data from a buffer into selected (expandable) stream. + @param psMainStream - stream for output + @param pui8InBuf - input buffer + @param ui32InBuffSize - size of input + @param ui32Level - debug level of input + @return bytes copied, 0 if recoverable error, -1 if unrecoverable error +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivWrite2(PDBG_STREAM psMainStream,IMG_UINT8 * pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level) +{ + DBG_STREAM *psStream; + + /* + Validate buffer. + */ + if (!StreamValidForWrite(psMainStream)) + { + PVR_DPF((PVR_DBG_ERROR, "DBGDrivWrite2: stream not valid")); + return(0xFFFFFFFFUL); + } + + /* + Check debug level. + */ + if ((psMainStream->psCtrl->ui32DebugLevel & ui32Level) == 0) + { + return(0); + } + + if(psMainStream->psCtrl->bInitPhaseComplete) + { + psStream = psMainStream; + } + else + { + psStream = psMainStream->psInitStream; + } + + PVR_DPF((PVR_DBGDRIV_MESSAGE, "Recv(exp) %d b for %s: Roff = %x, WOff = %x", + ui32InBuffSize, + psStream->szName, + psStream->ui32RPtr, + psStream->ui32WPtr)); + + return( WriteExpandingBuffer(psStream, pui8InBuf, ui32InBuffSize) ); +} + +/*!**************************************************************************** + @name DBGDrivRead + @brief Read from debug driver buffers + @param psMainStream - stream + @param bReadInitBuffer - whether to read from the init stream or the main stream + @param ui32OutBuffSize - available space in client buffer + @param pui8OutBuf - output buffer + @return bytes read, 0 if failure occurred +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivRead(PDBG_STREAM psMainStream, IMG_BOOL bReadInitBuffer, IMG_UINT32 ui32OutBuffSize,IMG_UINT8 * pui8OutBuf) +{ + IMG_UINT32 ui32Data; + DBG_STREAM *psStream; + + /* + Validate buffer. + */ + if (!StreamValidForRead(psMainStream)) + { + PVR_DPF((PVR_DBG_ERROR, "DBGDrivRead: buffer %x is invalid", (IMG_UINTPTR_T) psMainStream)); + return(0); + } + + if(bReadInitBuffer) + { + psStream = psMainStream->psInitStream; + } + else + { + psStream = psMainStream; + } + + /* Don't read beyond the init phase marker point */ + if (psStream->ui32RPtr == psStream->ui32WPtr || + ((psStream->ui32InitPhaseWOff > 0) && + (psStream->ui32RPtr >= psStream->ui32InitPhaseWOff)) ) + { + return(0); + } + + /* + Get amount of data in buffer. + */ + if (psStream->ui32RPtr <= psStream->ui32WPtr) + { + ui32Data = psStream->ui32WPtr - psStream->ui32RPtr; + } + else + { + ui32Data = psStream->ui32WPtr + (psStream->ui32Size - psStream->ui32RPtr); + } + + /* + Don't read beyond the init phase marker point + */ + if ((psStream->ui32InitPhaseWOff > 0) && + (psStream->ui32InitPhaseWOff < psStream->ui32WPtr)) + { + ui32Data = psStream->ui32InitPhaseWOff - psStream->ui32RPtr; + } + + /* + Only transfer what target buffer can handle. + */ + if (ui32Data > ui32OutBuffSize) + { + ui32Data = ui32OutBuffSize; + } + + PVR_DPF((PVR_DBGDRIV_MESSAGE, "Send %x b from %s: Roff = %x, WOff = %x", + ui32Data, + psStream->szName, + psStream->ui32RPtr, + psStream->ui32WPtr)); + + /* + Split copy into two bits as necessay. + */ + if ((psStream->ui32RPtr + ui32Data) > psStream->ui32Size) + { /* Calc block 1 and block 2 sizes */ + IMG_UINT32 ui32B1 = psStream->ui32Size - psStream->ui32RPtr; + IMG_UINT32 ui32B2 = ui32Data - ui32B1; + + /* Copy up to end of circular buffer */ + HostMemCopy((IMG_VOID *) pui8OutBuf, + (IMG_VOID *)((IMG_UINTPTR_T)psStream->pvBase + psStream->ui32RPtr), + ui32B1); + + /* Copy from start of circular buffer */ + HostMemCopy((IMG_VOID *)(pui8OutBuf + ui32B1), + psStream->pvBase, + ui32B2); + + /* Update read pointer now that we've copied the data out */ + psStream->ui32RPtr = ui32B2; + } + else + { /* Copy data from wherever */ + HostMemCopy((IMG_VOID *) pui8OutBuf, + (IMG_VOID *)((IMG_UINTPTR_T)psStream->pvBase + psStream->ui32RPtr), + ui32Data); + + /* Update read pointer now that we've copied the data out */ + psStream->ui32RPtr += ui32Data; + + /* Check for wrapping */ + if (psStream->ui32RPtr == psStream->ui32Size) + { + psStream->ui32RPtr = 0; + } + } + + return(ui32Data); +} + +/*!**************************************************************************** + @name DBGDrivSetCaptureMode + @brief Set capture mode + @param psStream - stream + @param ui32Mode - capturing mode + @param ui32Start - start frame (frame mode only) + @param ui32End - end frame (frame mode) + @param ui32SampleRate - sampling frequency (frame mode) +*****************************************************************************/ +void IMG_CALLCONV DBGDrivSetCaptureMode(PDBG_STREAM psStream,IMG_UINT32 ui32Mode,IMG_UINT32 ui32Start,IMG_UINT32 ui32End,IMG_UINT32 ui32SampleRate) +{ + /* + Validate buffer. + */ + if (!StreamValid(psStream)) + { + return; + } + + psStream->psCtrl->ui32CapMode = ui32Mode; + psStream->psCtrl->ui32DefaultMode = ui32Mode; + psStream->psCtrl->ui32Start = ui32Start; + psStream->psCtrl->ui32End = ui32End; + psStream->psCtrl->ui32SampleRate = ui32SampleRate; + + /* + Activate hotkey it the stream is of this type. + */ + if (psStream->psCtrl->ui32CapMode & DEBUG_CAPMODE_HOTKEY) + { + ActivateHotKeys(psStream); + } +} + +/*!**************************************************************************** + @name DBGDrivSetOutputMode + @brief Change output mode + @param psStream - stream + @param ui32OutMode - output mode + @return none +*****************************************************************************/ +void IMG_CALLCONV DBGDrivSetOutputMode(PDBG_STREAM psStream,IMG_UINT32 ui32OutMode) +{ + /* + Validate buffer. + */ + if (!StreamValid(psStream)) + { + return; + } + + psStream->psCtrl->ui32OutMode = ui32OutMode; +} + +/*!**************************************************************************** + @name DBGDrivSetDebugLevel + @brief Change debug level + @param psStream - stream + @param ui32DebugLevel - verbosity level + @return none +*****************************************************************************/ +void IMG_CALLCONV DBGDrivSetDebugLevel(PDBG_STREAM psStream,IMG_UINT32 ui32DebugLevel) +{ + /* + Validate buffer. + */ + if (!StreamValid(psStream)) + { + return; + } + + psStream->psCtrl->ui32DebugLevel = ui32DebugLevel; +} + +/*!**************************************************************************** + @name DBGDrivSetFrame + @brief Advance frame counter + @param psStream - stream + @param ui32Frame - frame number + @return none +*****************************************************************************/ +void IMG_CALLCONV DBGDrivSetFrame(PDBG_STREAM psStream,IMG_UINT32 ui32Frame) +{ + /* + Validate buffer. + */ + if (!StreamValid(psStream)) + { + return; + } + + psStream->psCtrl->ui32Current = ui32Frame; + + if ((ui32Frame >= psStream->psCtrl->ui32Start) && + (ui32Frame <= psStream->psCtrl->ui32End) && + (((ui32Frame - psStream->psCtrl->ui32Start) % psStream->psCtrl->ui32SampleRate) == 0)) + { + psStream->psCtrl->ui32Flags |= DEBUG_FLAGS_ENABLESAMPLE; + } + else + { + psStream->psCtrl->ui32Flags &= ~DEBUG_FLAGS_ENABLESAMPLE; + } + + if (g_bHotkeyMiddump) + { + if ((ui32Frame >= g_ui32HotkeyMiddumpStart) && + (ui32Frame <= g_ui32HotkeyMiddumpEnd) && + (((ui32Frame - g_ui32HotkeyMiddumpStart) % psStream->psCtrl->ui32SampleRate) == 0)) + { + psStream->psCtrl->ui32Flags |= DEBUG_FLAGS_ENABLESAMPLE; + } + else + { + psStream->psCtrl->ui32Flags &= ~DEBUG_FLAGS_ENABLESAMPLE; + if (psStream->psCtrl->ui32Current > g_ui32HotkeyMiddumpEnd) + { + g_bHotkeyMiddump = IMG_FALSE; + } + } + } + + /* Check to see if hotkey press has been registered (from keyboard filter) */ + if (g_bHotKeyRegistered) + { + g_bHotKeyRegistered = IMG_FALSE; + + PVR_DPF((PVR_DBG_MESSAGE,"Hotkey pressed (%p)!\n",psStream)); + + if (!g_bHotKeyPressed) + { + /* + Capture the next frame. + */ + g_ui32HotKeyFrame = psStream->psCtrl->ui32Current + 2; + + /* + Do the flag. + */ + g_bHotKeyPressed = IMG_TRUE; + } + + /* + If in framed hotkey mode, then set start frame. + */ + if (((psStream->psCtrl->ui32CapMode & DEBUG_CAPMODE_FRAMED) != 0) && + ((psStream->psCtrl->ui32CapMode & DEBUG_CAPMODE_HOTKEY) != 0)) + { + if (!g_bHotkeyMiddump) + { + /* Turn on */ + g_ui32HotkeyMiddumpStart = g_ui32HotKeyFrame + 1; + g_ui32HotkeyMiddumpEnd = 0xffffffff; + g_bHotkeyMiddump = IMG_TRUE; + PVR_DPF((PVR_DBG_MESSAGE,"Sampling every %d frame(s)\n", psStream->psCtrl->ui32SampleRate)); + } + else + { + /* Turn off */ + g_ui32HotkeyMiddumpEnd = g_ui32HotKeyFrame; + PVR_DPF((PVR_DBG_MESSAGE,"Turning off sampling\n")); + } + } + + } + + /* + Clear the hotkey frame indicator when over that frame. + */ + if (psStream->psCtrl->ui32Current > g_ui32HotKeyFrame) + { + g_bHotKeyPressed = IMG_FALSE; + } +} + +/*!**************************************************************************** + @name DBGDrivGetFrame + @brief Retrieve current frame number + @param psStream - stream + @return frame number +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivGetFrame(PDBG_STREAM psStream) +{ + /* + Validate buffer. + */ + if (!StreamValid(psStream)) + { + return(0); + } + + return(psStream->psCtrl->ui32Current); +} + +/*!**************************************************************************** + @name DBGDrivIsLastCaptureFrame + @brief Is this the last frame to be captured? + @param psStream - stream + @return true if last capture frame, false otherwise +*****************************************************************************/ +IMG_BOOL IMG_CALLCONV DBGDrivIsLastCaptureFrame(PDBG_STREAM psStream) +{ + IMG_UINT32 ui32NextFrame; + + /* + Validate buffer. + */ + if (!StreamValid(psStream)) + { + return IMG_FALSE; + } + + if (psStream->psCtrl->ui32CapMode & DEBUG_CAPMODE_FRAMED) + { + ui32NextFrame = psStream->psCtrl->ui32Current + psStream->psCtrl->ui32SampleRate; + if (ui32NextFrame > psStream->psCtrl->ui32End) + { + return IMG_TRUE; + } + } + return IMG_FALSE; +} + +/*!**************************************************************************** + @name DBGDrivIsCaptureFrame + @brief Is this a capture frame? + @param psStream - stream + @param bCheckPreviousFrame - set if it needs to be 1 frame ahead + @return true if capturing this frame, false otherwise +*****************************************************************************/ +IMG_BOOL IMG_CALLCONV DBGDrivIsCaptureFrame(PDBG_STREAM psStream, IMG_BOOL bCheckPreviousFrame) +{ + IMG_UINT32 ui32FrameShift = bCheckPreviousFrame ? 1UL : 0UL; + + /* + Validate buffer. + */ + if (!StreamValid(psStream)) + { + return IMG_FALSE; + } + + if (psStream->psCtrl->ui32CapMode & DEBUG_CAPMODE_FRAMED) + { + /* Needs to be one frame ahead, so disppatch can turn everything on */ + if (g_bHotkeyMiddump) + { + if ((psStream->psCtrl->ui32Current >= (g_ui32HotkeyMiddumpStart - ui32FrameShift)) && + (psStream->psCtrl->ui32Current <= (g_ui32HotkeyMiddumpEnd - ui32FrameShift)) && + ((((psStream->psCtrl->ui32Current + ui32FrameShift) - g_ui32HotkeyMiddumpStart) % psStream->psCtrl->ui32SampleRate) == 0)) + { + return IMG_TRUE; + } + } + else + { + if ((psStream->psCtrl->ui32Current >= (psStream->psCtrl->ui32Start - ui32FrameShift)) && + (psStream->psCtrl->ui32Current <= (psStream->psCtrl->ui32End - ui32FrameShift)) && + ((((psStream->psCtrl->ui32Current + ui32FrameShift) - psStream->psCtrl->ui32Start) % psStream->psCtrl->ui32SampleRate) == 0)) + { + return IMG_TRUE; + } + } + } + else if (psStream->psCtrl->ui32CapMode == DEBUG_CAPMODE_HOTKEY) + { + if ((psStream->psCtrl->ui32Current == (g_ui32HotKeyFrame-ui32FrameShift)) && (g_bHotKeyPressed)) + { + return IMG_TRUE; + } + } + return IMG_FALSE; +} + +/*!**************************************************************************** + @name DBGDrivOverrideMode + @brief Override capture mode + @param psStream - stream + @param ui32Mode - capture mode + @return none +*****************************************************************************/ +void IMG_CALLCONV DBGDrivOverrideMode(PDBG_STREAM psStream,IMG_UINT32 ui32Mode) +{ + /* + Validate buffer. + */ + if (!StreamValid(psStream)) + { + return; + } + + psStream->psCtrl->ui32CapMode = ui32Mode; +} + +/*!**************************************************************************** + @name DBGDrivDefaultMode + @param psStream - stream + @return none +*****************************************************************************/ +void IMG_CALLCONV DBGDrivDefaultMode(PDBG_STREAM psStream) +{ + /* + Validate buffer. + */ + if (!StreamValid(psStream)) + { + return; + } + + psStream->psCtrl->ui32CapMode = psStream->psCtrl->ui32DefaultMode; +} + +/*!**************************************************************************** + @name DBGDrivSetClientMarker + @brief Sets the marker to prevent reading initphase beyond data on behalf of previous app + @param psStream - stream + @param ui32Marker - byte offset in init buffer + @return nothing +*****************************************************************************/ +IMG_VOID IMG_CALLCONV DBGDrivSetClientMarker(PDBG_STREAM psStream, IMG_UINT32 ui32Marker) +{ + /* + Validate buffer + */ + if (!StreamValid(psStream)) + { + return; + } + + psStream->ui32InitPhaseWOff = ui32Marker; +} + +/*!**************************************************************************** + @name DBGDrivSetMarker + @brief Sets the marker in the stream to split output files + @param psStream, ui32Marker + @return nothing +*****************************************************************************/ +void IMG_CALLCONV DBGDrivSetMarker(PDBG_STREAM psStream, IMG_UINT32 ui32Marker) +{ + /* + Validate buffer + */ + if (!StreamValid(psStream)) + { + return; + } + + psStream->ui32Marker = ui32Marker; +} + +/*!**************************************************************************** + @name DBGDrivGetMarker + @brief Gets the marker in the stream to split output files + @param psStream - stream + @return marker offset +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivGetMarker(PDBG_STREAM psStream) +{ + /* + Validate buffer + */ + if (!StreamValid(psStream)) + { + return 0; + } + + return psStream->ui32Marker; +} + + +/*!**************************************************************************** + @name DBGDrivGetStreamOffset + @brief Gets the amount of data written to the stream + @param psMainStream - stream + @return bytes written +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivGetStreamOffset(PDBG_STREAM psMainStream) +{ + PDBG_STREAM psStream; + + /* + Validate buffer + */ + if (!StreamValid(psMainStream)) + { + return 0; + } + + if(psMainStream->psCtrl->bInitPhaseComplete) + { + psStream = psMainStream; + } + else + { + psStream = psMainStream->psInitStream; + } + + return psStream->ui32DataWritten; +} + +/*!**************************************************************************** + @name DBGDrivSetStreamOffset + @brief Sets the amount of data written to the stream + @param psMainStream - stream + @param ui32StreamOffset - stream offset + @return Nothing +*****************************************************************************/ +IMG_VOID IMG_CALLCONV DBGDrivSetStreamOffset(PDBG_STREAM psMainStream, IMG_UINT32 ui32StreamOffset) +{ + PDBG_STREAM psStream; + + /* + Validate buffer + */ + if (!StreamValid(psMainStream)) + { + return; + } + + if(psMainStream->psCtrl->bInitPhaseComplete) + { + psStream = psMainStream; + } + else + { + psStream = psMainStream->psInitStream; + } + + PVR_DPF((PVR_DBGDRIV_MESSAGE, "DBGDrivSetStreamOffset: %s set to %x b", + psStream->szName, + ui32StreamOffset)); + psStream->ui32DataWritten = ui32StreamOffset; +} + +/*!**************************************************************************** + @name DBGDrivGetServiceTable + @brief get jump table for Services driver + @return pointer to jump table +*****************************************************************************/ +IMG_PVOID IMG_CALLCONV DBGDrivGetServiceTable(IMG_VOID) +{ + return((IMG_PVOID)&g_sDBGKMServices); +} + +/*!**************************************************************************** + @name DBGDrivWriteLF + @brief Store data that should only be kept from the last frame dumped + @param psStream - stream + @param pui8InBuf - input buffer + @param ui32InBuffSize - size + @param ui32Level - verbosity level + @param ui32Flags - flags + @return bytes written +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivWriteLF(PDBG_STREAM psStream, IMG_UINT8 * pui8InBuf, IMG_UINT32 ui32InBuffSize, IMG_UINT32 ui32Level, IMG_UINT32 ui32Flags) +{ + PDBG_LASTFRAME_BUFFER psLFBuffer; + + /* + Validate buffer. + */ + if (!StreamValidForWrite(psStream)) + { + return(0xFFFFFFFFUL); + } + + /* + Check debug level. + */ + if ((psStream->psCtrl->ui32DebugLevel & ui32Level) == 0) + { + return(0xFFFFFFFFUL); + } + + /* + Only write data if debug mode adds up... + */ + if ((psStream->psCtrl->ui32CapMode & DEBUG_CAPMODE_FRAMED) != 0) + { + if ((psStream->psCtrl->ui32Flags & DEBUG_FLAGS_ENABLESAMPLE) == 0) + { + /* throw away non-capturing data */ + return(ui32InBuffSize); + } + } + else if (psStream->psCtrl->ui32CapMode == DEBUG_CAPMODE_HOTKEY) + { + if ((psStream->psCtrl->ui32Current != g_ui32HotKeyFrame) || (g_bHotKeyPressed == IMG_FALSE)) + { + /* throw away non-capturing data */ + return(ui32InBuffSize); + } + } + + psLFBuffer = FindLFBuf(psStream); + + if (ui32Flags & WRITELF_FLAGS_RESETBUF) + { + /* + Copy the data into the buffer + */ + ui32InBuffSize = (ui32InBuffSize > LAST_FRAME_BUF_SIZE) ? LAST_FRAME_BUF_SIZE : ui32InBuffSize; + HostMemCopy((IMG_VOID *)psLFBuffer->ui8Buffer, (IMG_VOID *)pui8InBuf, ui32InBuffSize); + psLFBuffer->ui32BufLen = ui32InBuffSize; + } + else + { + /* + Append the data to the end of the buffer + */ + ui32InBuffSize = ((psLFBuffer->ui32BufLen + ui32InBuffSize) > LAST_FRAME_BUF_SIZE) ? (LAST_FRAME_BUF_SIZE - psLFBuffer->ui32BufLen) : ui32InBuffSize; + HostMemCopy((IMG_VOID *)(&psLFBuffer->ui8Buffer[psLFBuffer->ui32BufLen]), (IMG_VOID *)pui8InBuf, ui32InBuffSize); + psLFBuffer->ui32BufLen += ui32InBuffSize; + } + + return(ui32InBuffSize); +} + +/*!**************************************************************************** + @name DBGDrivReadLF + @brief Read data that should only be kept from the last frame dumped + @param psStream - stream + @param ui32OutBuffSize - buffer size + @param pui8OutBuf - output buffer + @return bytes read +*****************************************************************************/ +IMG_UINT32 IMG_CALLCONV DBGDrivReadLF(PDBG_STREAM psStream, IMG_UINT32 ui32OutBuffSize, IMG_UINT8 * pui8OutBuf) +{ + PDBG_LASTFRAME_BUFFER psLFBuffer; + IMG_UINT32 ui32Data; + + /* + Validate buffer. + */ + if (!StreamValidForRead(psStream)) + { + return(0); + } + + psLFBuffer = FindLFBuf(psStream); + + /* + Get amount of data to copy + */ + ui32Data = (ui32OutBuffSize < psLFBuffer->ui32BufLen) ? ui32OutBuffSize : psLFBuffer->ui32BufLen; + + /* + Copy the data into the buffer + */ + HostMemCopy((IMG_VOID *)pui8OutBuf, (IMG_VOID *)psLFBuffer->ui8Buffer, ui32Data); + + return ui32Data; +} + +/*!**************************************************************************** + @name DBGDrivStartInitPhase + @brief Marks start of init phase + @param psStream - stream + @return void +*****************************************************************************/ +IMG_VOID IMG_CALLCONV DBGDrivStartInitPhase(PDBG_STREAM psStream) +{ + psStream->psCtrl->bInitPhaseComplete = IMG_FALSE; +} + +/*!**************************************************************************** + @name DBGDrivStopInitPhase + @brief Marks end of init phase + @param psStream - stream + @return void +*****************************************************************************/ +IMG_VOID IMG_CALLCONV DBGDrivStopInitPhase(PDBG_STREAM psStream) +{ + psStream->psCtrl->bInitPhaseComplete = IMG_TRUE; +} + +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) +/*!**************************************************************************** + @name DBGDrivWaitForEvent + @brief waits for an event + @param eEvent - debug driver event + @return void +*****************************************************************************/ +IMG_VOID IMG_CALLCONV DBGDrivWaitForEvent(DBG_EVENT eEvent) +{ + HostWaitForEvent(eEvent); +} +#endif + +/*!**************************************************************************** + @name ExpandStreamBuffer + @brief allocates a new buffer when the current one is full + @param psStream - stream + @param ui32NewSize - new size + @return IMG_TRUE - if allocation succeeded, IMG_FALSE - if not +*****************************************************************************/ +IMG_BOOL ExpandStreamBuffer(PDBG_STREAM psStream, IMG_UINT32 ui32NewSize) +{ + IMG_VOID * pvNewBuf; + IMG_UINT32 ui32NewSizeInPages; + IMG_UINT32 ui32NewWOffset; + IMG_UINT32 ui32NewROffset; + IMG_UINT32 ui32SpaceInOldBuf; + + /* + First check new size is bigger than existing size + */ + if (psStream->ui32Size >= ui32NewSize) + { + return IMG_FALSE; + } + + /* + Calc space in old buffer + */ + ui32SpaceInOldBuf = SpaceInStream(psStream); + + /* + Allocate new buffer + */ + ui32NewSizeInPages = ((ui32NewSize + 0xfffUL) & ~0xfffUL) / 4096UL; + + if ((psStream->psCtrl->ui32Flags & DEBUG_FLAGS_USE_NONPAGED_MEM) != 0) + { + pvNewBuf = HostNonPageablePageAlloc(ui32NewSizeInPages); + } + else + { + pvNewBuf = HostPageablePageAlloc(ui32NewSizeInPages); + } + + if (pvNewBuf == IMG_NULL) + { + return IMG_FALSE; + } + + if(psStream->bCircularAllowed) + { + /* + Copy over old buffer to new one, we place data at start of buffer + even if Read offset is not at start of buffer + */ + if (psStream->ui32RPtr <= psStream->ui32WPtr) + { + /* + No wrapping of data so copy data to start of new buffer + */ + HostMemCopy(pvNewBuf, + (IMG_VOID *)((IMG_UINTPTR_T)psStream->pvBase + psStream->ui32RPtr), + psStream->ui32WPtr - psStream->ui32RPtr); + } + else + { + IMG_UINT32 ui32FirstCopySize; + + /* + The data has wrapped around the buffer, copy beginning of buffer first + */ + ui32FirstCopySize = psStream->ui32Size - psStream->ui32RPtr; + + HostMemCopy(pvNewBuf, + (IMG_VOID *)((IMG_UINTPTR_T)psStream->pvBase + psStream->ui32RPtr), + ui32FirstCopySize); + + /* + Now second half + */ + HostMemCopy((IMG_VOID *)((IMG_UINTPTR_T)pvNewBuf + ui32FirstCopySize), + (IMG_VOID *)(IMG_PBYTE)psStream->pvBase, + psStream->ui32WPtr); + } + ui32NewROffset = 0; + } + else + { + /* Copy everything in the old buffer to the new one */ + HostMemCopy(pvNewBuf, psStream->pvBase, psStream->ui32WPtr); + ui32NewROffset = psStream->ui32RPtr; + } + + /* + New Write offset is at end of data + */ + ui32NewWOffset = psStream->ui32Size - ui32SpaceInOldBuf; + + /* + Free old buffer + */ + if ((psStream->psCtrl->ui32Flags & DEBUG_FLAGS_USE_NONPAGED_MEM) != 0) + { + HostNonPageablePageFree(psStream->pvBase); + } + else + { + HostPageablePageFree(psStream->pvBase); + } + + /* + Now set new params up + */ + psStream->pvBase = pvNewBuf; + psStream->ui32RPtr = ui32NewROffset; + psStream->ui32WPtr = ui32NewWOffset; + psStream->ui32Size = ui32NewSizeInPages * 4096; + + return IMG_TRUE; +} + +/*!**************************************************************************** + @name SpaceInStream + @brief remaining space in stream + @param psStream - stream + @return bytes remaining +*****************************************************************************/ +IMG_UINT32 SpaceInStream(PDBG_STREAM psStream) +{ + IMG_UINT32 ui32Space; + + if (psStream->bCircularAllowed) + { + /* Allow overwriting the buffer which was already read */ + if (psStream->ui32RPtr > psStream->ui32WPtr) + { + ui32Space = psStream->ui32RPtr - psStream->ui32WPtr; + } + else + { + ui32Space = psStream->ui32RPtr + (psStream->ui32Size - psStream->ui32WPtr); + } + } + else + { + /* Don't overwrite anything */ + ui32Space = psStream->ui32Size - psStream->ui32WPtr; + } + + return ui32Space; +} + + +/*!**************************************************************************** + @name DestroyAllStreams + @brief delete all streams in list + @return none +*****************************************************************************/ +void DestroyAllStreams(void) +{ + while (g_psStreamList != IMG_NULL) + { + DBGDrivDestroyStream(g_psStreamList); + } + return; +} + +/*!**************************************************************************** + @name FindLFBuf + @brief finds last frame stream + @param psStream - stream to find + @return stream if found, NULL otherwise +*****************************************************************************/ +PDBG_LASTFRAME_BUFFER FindLFBuf(PDBG_STREAM psStream) +{ + PDBG_LASTFRAME_BUFFER psLFBuffer; + + psLFBuffer = g_psLFBufferList; + + while (psLFBuffer) + { + if (psLFBuffer->psStream == psStream) + { + break; + } + + psLFBuffer = psLFBuffer->psNext; + } + + return psLFBuffer; +} + +/****************************************************************************** + End of file (DBGDRIV.C) +******************************************************************************/ diff --git a/pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv.h b/pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv.h new file mode 100644 index 0000000..d58c62d --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv.h @@ -0,0 +1,155 @@ +/*************************************************************************/ /*! +@Title Debug Driver interface definition. +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ + +#ifndef _DBGDRIV_ +#define _DBGDRIV_ + +/***************************************************************************** + The odd constant or two +*****************************************************************************/ +#define BUFFER_SIZE 64*PAGESIZE + +#define DBGDRIV_VERSION 0x100 +#define MAX_PROCESSES 2 +#define BLOCK_USED 0x01 +#define BLOCK_LOCKED 0x02 +#define DBGDRIV_MONOBASE 0x000B0000 + + +extern IMG_VOID * g_pvAPIMutex; + +/***************************************************************************** + KM mode functions +*****************************************************************************/ +IMG_VOID * IMG_CALLCONV DBGDrivCreateStream(IMG_CHAR * pszName, + IMG_UINT32 ui32CapMode, + IMG_UINT32 ui32OutMode, + IMG_UINT32 ui32Flags, + IMG_UINT32 ui32Pages); +IMG_VOID IMG_CALLCONV DBGDrivDestroyStream(PDBG_STREAM psStream); +IMG_VOID * IMG_CALLCONV DBGDrivFindStream(IMG_CHAR * pszName, IMG_BOOL bResetStream); +IMG_UINT32 IMG_CALLCONV DBGDrivWriteString(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Level); +IMG_UINT32 IMG_CALLCONV DBGDrivReadString(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Limit); +IMG_UINT32 IMG_CALLCONV DBGDrivWrite(PDBG_STREAM psStream,IMG_UINT8 *pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level); +IMG_UINT32 IMG_CALLCONV DBGDrivWrite2(PDBG_STREAM psStream,IMG_UINT8 *pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level); +IMG_UINT32 IMG_CALLCONV DBGDrivRead(PDBG_STREAM psStream, IMG_BOOL bReadInitBuffer, IMG_UINT32 ui32OutBufferSize,IMG_UINT8 *pui8OutBuf); +IMG_VOID IMG_CALLCONV DBGDrivSetCaptureMode(PDBG_STREAM psStream,IMG_UINT32 ui32Mode,IMG_UINT32 ui32Start,IMG_UINT32 ui32Stop,IMG_UINT32 ui32SampleRate); +IMG_VOID IMG_CALLCONV DBGDrivSetOutputMode(PDBG_STREAM psStream,IMG_UINT32 ui32OutMode); +IMG_VOID IMG_CALLCONV DBGDrivSetDebugLevel(PDBG_STREAM psStream,IMG_UINT32 ui32DebugLevel); +IMG_VOID IMG_CALLCONV DBGDrivSetFrame(PDBG_STREAM psStream,IMG_UINT32 ui32Frame); +IMG_UINT32 IMG_CALLCONV DBGDrivGetFrame(PDBG_STREAM psStream); +IMG_VOID IMG_CALLCONV DBGDrivOverrideMode(PDBG_STREAM psStream,IMG_UINT32 ui32Mode); +IMG_VOID IMG_CALLCONV DBGDrivDefaultMode(PDBG_STREAM psStream); +IMG_PVOID IMG_CALLCONV DBGDrivGetServiceTable(IMG_VOID); +IMG_UINT32 IMG_CALLCONV DBGDrivWriteStringCM(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Level); +IMG_UINT32 IMG_CALLCONV DBGDrivWriteCM(PDBG_STREAM psStream,IMG_UINT8 *pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level); +IMG_VOID IMG_CALLCONV DBGDrivSetClientMarker(PDBG_STREAM psStream, IMG_UINT32 ui32Marker); +IMG_VOID IMG_CALLCONV DBGDrivSetMarker(PDBG_STREAM psStream, IMG_UINT32 ui32Marker); +IMG_UINT32 IMG_CALLCONV DBGDrivGetMarker(PDBG_STREAM psStream); +IMG_BOOL IMG_CALLCONV DBGDrivIsLastCaptureFrame(PDBG_STREAM psStream); +IMG_BOOL IMG_CALLCONV DBGDrivIsCaptureFrame(PDBG_STREAM psStream, IMG_BOOL bCheckPreviousFrame); +IMG_UINT32 IMG_CALLCONV DBGDrivWriteLF(PDBG_STREAM psStream, IMG_UINT8 *pui8InBuf, IMG_UINT32 ui32InBuffSize, IMG_UINT32 ui32Level, IMG_UINT32 ui32Flags); +IMG_UINT32 IMG_CALLCONV DBGDrivReadLF(PDBG_STREAM psStream, IMG_UINT32 ui32OutBuffSize, IMG_UINT8 *pui8OutBuf); +IMG_VOID IMG_CALLCONV DBGDrivStartInitPhase(PDBG_STREAM psStream); +IMG_VOID IMG_CALLCONV DBGDrivStopInitPhase(PDBG_STREAM psStream); +IMG_UINT32 IMG_CALLCONV DBGDrivGetStreamOffset(PDBG_STREAM psStream); +IMG_VOID IMG_CALLCONV DBGDrivSetStreamOffset(PDBG_STREAM psStream, IMG_UINT32 ui32StreamOffset); +IMG_VOID IMG_CALLCONV DBGDrivWaitForEvent(DBG_EVENT eEvent); + +IMG_VOID DestroyAllStreams(IMG_VOID); + +/***************************************************************************** + Function prototypes +*****************************************************************************/ +IMG_UINT32 AtoI(IMG_CHAR *szIn); + +IMG_VOID HostMemSet(IMG_VOID *pvDest,IMG_UINT8 ui8Value,IMG_UINT32 ui32Size); +IMG_VOID HostMemCopy(IMG_VOID *pvDest,IMG_VOID *pvSrc,IMG_UINT32 ui32Size); +IMG_VOID MonoOut(IMG_CHAR * pszString,IMG_BOOL bNewLine); + +/***************************************************************************** + Secure handle Function prototypes +*****************************************************************************/ +IMG_SID PStream2SID(PDBG_STREAM psStream); +PDBG_STREAM SID2PStream(IMG_SID hStream); +IMG_BOOL AddSIDEntry(PDBG_STREAM psStream); +IMG_BOOL RemoveSIDEntry(PDBG_STREAM psStream); + +/***************************************************************************** + Declarations for Service table entry points +*****************************************************************************/ +IMG_VOID * IMG_CALLCONV ExtDBGDrivCreateStream(IMG_CHAR * pszName, IMG_UINT32 ui32CapMode, IMG_UINT32 ui32OutMode, IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size); +IMG_VOID IMG_CALLCONV ExtDBGDrivDestroyStream(PDBG_STREAM psStream); +IMG_VOID * IMG_CALLCONV ExtDBGDrivFindStream(IMG_CHAR * pszName, IMG_BOOL bResetStream); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWriteString(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Level); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivReadString(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Limit); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWrite(PDBG_STREAM psStream,IMG_UINT8 *pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivRead(PDBG_STREAM psStream, IMG_BOOL bReadInitBuffer, IMG_UINT32 ui32OutBuffSize,IMG_UINT8 *pui8OutBuf); +IMG_VOID IMG_CALLCONV ExtDBGDrivSetCaptureMode(PDBG_STREAM psStream,IMG_UINT32 ui32Mode,IMG_UINT32 ui32Start,IMG_UINT32 ui32End,IMG_UINT32 ui32SampleRate); +IMG_VOID IMG_CALLCONV ExtDBGDrivSetOutputMode(PDBG_STREAM psStream,IMG_UINT32 ui32OutMode); +IMG_VOID IMG_CALLCONV ExtDBGDrivSetDebugLevel(PDBG_STREAM psStream,IMG_UINT32 ui32DebugLevel); +IMG_VOID IMG_CALLCONV ExtDBGDrivSetFrame(PDBG_STREAM psStream,IMG_UINT32 ui32Frame); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivGetFrame(PDBG_STREAM psStream); +IMG_VOID IMG_CALLCONV ExtDBGDrivOverrideMode(PDBG_STREAM psStream,IMG_UINT32 ui32Mode); +IMG_VOID IMG_CALLCONV ExtDBGDrivDefaultMode(PDBG_STREAM psStream); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWrite2(PDBG_STREAM psStream,IMG_UINT8 *pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWriteStringCM(PDBG_STREAM psStream,IMG_CHAR * pszString,IMG_UINT32 ui32Level); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWriteCM(PDBG_STREAM psStream,IMG_UINT8 *pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level); +IMG_VOID IMG_CALLCONV ExtDBGDrivSetMarker(PDBG_STREAM psStream, IMG_UINT32 ui32Marker); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivGetMarker(PDBG_STREAM psStream); +IMG_VOID IMG_CALLCONV ExtDBGDrivStartInitPhase(PDBG_STREAM psStream); +IMG_VOID IMG_CALLCONV ExtDBGDrivStopInitPhase(PDBG_STREAM psStream); +IMG_BOOL IMG_CALLCONV ExtDBGDrivIsLastCaptureFrame(PDBG_STREAM psStream); +IMG_BOOL IMG_CALLCONV ExtDBGDrivIsCaptureFrame(PDBG_STREAM psStream, IMG_BOOL bCheckPreviousFrame); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWriteLF(PDBG_STREAM psStream, IMG_UINT8 *pui8InBuf, IMG_UINT32 ui32InBuffSize, IMG_UINT32 ui32Level, IMG_UINT32 ui32Flags); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivReadLF(PDBG_STREAM psStream, IMG_UINT32 ui32OutBuffSize, IMG_UINT8 *pui8OutBuf); +IMG_UINT32 IMG_CALLCONV ExtDBGDrivGetStreamOffset(PDBG_STREAM psStream); +IMG_VOID IMG_CALLCONV ExtDBGDrivSetStreamOffset(PDBG_STREAM psStream, IMG_UINT32 ui32StreamOffset); +IMG_VOID IMG_CALLCONV ExtDBGDrivWaitForEvent(DBG_EVENT eEvent); +IMG_VOID IMG_CALLCONV ExtDBGDrivSetConnectNotifier(DBGKM_CONNECT_NOTIFIER fn_notifier); + +IMG_UINT32 IMG_CALLCONV ExtDBGDrivWritePersist(PDBG_STREAM psStream,IMG_UINT8 *pui8InBuf,IMG_UINT32 ui32InBuffSize,IMG_UINT32 ui32Level); + +#endif + +/***************************************************************************** + End of file (DBGDRIV.H) +*****************************************************************************/ diff --git a/pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv_ioctl.h b/pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv_ioctl.h new file mode 100644 index 0000000..0909e6d --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/common/dbgdriv_ioctl.h @@ -0,0 +1,57 @@ +/*************************************************************************/ /*! +@Title IOCTL implementations for debug device. +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ + +#ifndef _IOCTL_ +#define _IOCTL_ + +/***************************************************************************** + Global vars +*****************************************************************************/ + +#define MAX_DBGVXD_W32_API 25 + +extern IMG_UINT32 (*g_DBGDrivProc[MAX_DBGVXD_W32_API])(IMG_VOID *, IMG_VOID *); + +#endif + +/***************************************************************************** + End of file (IOCTL.H) +*****************************************************************************/ diff --git a/pvr-source/tools/intern/debug/dbgdriv/common/handle.c b/pvr-source/tools/intern/debug/dbgdriv/common/handle.c new file mode 100644 index 0000000..a9d37a6 --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/common/handle.c @@ -0,0 +1,141 @@ +/*************************************************************************/ /*! +@Title Resource Handle Manager +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@Description Provide resource handle management +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ + +#include "img_defs.h" +#include "dbgdrvif.h" +#include "dbgdriv.h" + +/* max number of streams held in SID info table */ +#define MAX_SID_ENTRIES 8 + +typedef struct _SID_INFO +{ + PDBG_STREAM psStream; +} SID_INFO, *PSID_INFO; + +static SID_INFO gaSID_Xlat_Table[MAX_SID_ENTRIES]; + +IMG_SID PStream2SID(PDBG_STREAM psStream) +{ + if (psStream != (PDBG_STREAM)IMG_NULL) + { + IMG_INT32 iIdx; + + for (iIdx = 0; iIdx < MAX_SID_ENTRIES; iIdx++) + { + if (psStream == gaSID_Xlat_Table[iIdx].psStream) + { + /* idx is one based */ + return (IMG_SID)iIdx+1; + } + } + } + + return (IMG_SID)0; +} + + +PDBG_STREAM SID2PStream(IMG_SID hStream) +{ + /* changed to zero based */ + IMG_INT32 iIdx = (IMG_INT32)hStream-1; + + if (iIdx >= 0 && iIdx < MAX_SID_ENTRIES) + { + return gaSID_Xlat_Table[iIdx].psStream; + } + else + { + return (PDBG_STREAM)IMG_NULL; + } +} + + +IMG_BOOL AddSIDEntry(PDBG_STREAM psStream) +{ + if (psStream != (PDBG_STREAM)IMG_NULL) + { + IMG_INT32 iIdx; + + for (iIdx = 0; iIdx < MAX_SID_ENTRIES; iIdx++) + { + if (psStream == gaSID_Xlat_Table[iIdx].psStream) + { + /* already created */ + return IMG_TRUE; + } + + if (gaSID_Xlat_Table[iIdx].psStream == (PDBG_STREAM)IMG_NULL) + { + /* free entry */ + gaSID_Xlat_Table[iIdx].psStream = psStream; + return IMG_TRUE; + } + } + } + + return IMG_FALSE; +} + +IMG_BOOL RemoveSIDEntry(PDBG_STREAM psStream) +{ + if (psStream != (PDBG_STREAM)IMG_NULL) + { + IMG_INT32 iIdx; + + for (iIdx = 0; iIdx < MAX_SID_ENTRIES; iIdx++) + { + if (psStream == gaSID_Xlat_Table[iIdx].psStream) + { + gaSID_Xlat_Table[iIdx].psStream = (PDBG_STREAM)IMG_NULL; + return IMG_TRUE; + } + } + } + + return IMG_FALSE; +} + + +/****************************************************************************** + End of file (handle.c) +******************************************************************************/ diff --git a/pvr-source/tools/intern/debug/dbgdriv/common/hostfunc.h b/pvr-source/tools/intern/debug/dbgdriv/common/hostfunc.h new file mode 100644 index 0000000..e92ad9a --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/common/hostfunc.h @@ -0,0 +1,82 @@ +/*************************************************************************/ /*! +@Title Host function definitions for debug device. +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ + +#ifndef _HOSTFUNC_ +#define _HOSTFUNC_ + +/***************************************************************************** + Defines +*****************************************************************************/ +#define HOST_PAGESIZE (4096) +#define DBG_MEMORY_INITIALIZER (0xe2) + +/***************************************************************************** + Function prototypes +*****************************************************************************/ +IMG_UINT32 HostReadRegistryDWORDFromString(IMG_CHAR *pcKey, IMG_CHAR *pcValueName, IMG_UINT32 *pui32Data); + +IMG_VOID * HostPageablePageAlloc(IMG_UINT32 ui32Pages); +IMG_VOID HostPageablePageFree(IMG_VOID * pvBase); +IMG_VOID * HostNonPageablePageAlloc(IMG_UINT32 ui32Pages); +IMG_VOID HostNonPageablePageFree(IMG_VOID * pvBase); + +IMG_VOID * HostMapKrnBufIntoUser(IMG_VOID * pvKrnAddr, IMG_UINT32 ui32Size, IMG_VOID * *ppvMdl); +IMG_VOID HostUnMapKrnBufFromUser(IMG_VOID * pvUserAddr, IMG_VOID * pvMdl, IMG_VOID * pvProcess); + +IMG_VOID HostCreateRegDeclStreams(IMG_VOID); + +IMG_VOID * HostCreateMutex(IMG_VOID); +IMG_VOID HostAquireMutex(IMG_VOID * pvMutex); +IMG_VOID HostReleaseMutex(IMG_VOID * pvMutex); +IMG_VOID HostDestroyMutex(IMG_VOID * pvMutex); + +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) +IMG_INT32 HostCreateEventObjects(IMG_VOID); +IMG_VOID HostWaitForEvent(DBG_EVENT eEvent); +IMG_VOID HostSignalEvent(DBG_EVENT eEvent); +IMG_VOID HostDestroyEventObjects(IMG_VOID); +#endif /*defined(SUPPORT_DBGDRV_EVENT_OBJECTS) */ + +#endif + +/***************************************************************************** + End of file (HOSTFUNC.H) +*****************************************************************************/ diff --git a/pvr-source/tools/intern/debug/dbgdriv/common/hotkey.c b/pvr-source/tools/intern/debug/dbgdriv/common/hotkey.c new file mode 100644 index 0000000..6bf20a6 --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/common/hotkey.c @@ -0,0 +1,199 @@ +/*************************************************************************/ /*! +@Title Debug driver utilities implementations. +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@Description Hotkey stuff +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ + + +#if !defined(LINUX) && !defined(__QNXNTO__) +#include <ntddk.h> +#include <windef.h> +#endif + +#include "img_types.h" +#include "pvr_debug.h" +#include "dbgdrvif.h" +#include "dbgdriv.h" +#include "hotkey.h" +#include "hostfunc.h" + + + + +/***************************************************************************** + Global vars +*****************************************************************************/ + +IMG_UINT32 g_ui32HotKeyFrame = 0xFFFFFFFF; +IMG_BOOL g_bHotKeyPressed = IMG_FALSE; +IMG_BOOL g_bHotKeyRegistered = IMG_FALSE; + +/* Hotkey stuff */ +PRIVATEHOTKEYDATA g_PrivateHotKeyData; + + +/***************************************************************************** + Code +*****************************************************************************/ + + +/****************************************************************************** + * Function Name: ReadInHotKeys + * + * Inputs : none + * Outputs : - + * Returns : nothing + * Globals Used : - + * + * Description : Gets Hot key entries from system.ini + *****************************************************************************/ +IMG_VOID ReadInHotKeys(IMG_VOID) +{ + g_PrivateHotKeyData.ui32ScanCode = 0x58; /* F12 */ + g_PrivateHotKeyData.ui32ShiftState = 0x0; + + /* + Find buffer names etc.. + */ + HostReadRegistryDWORDFromString("DEBUG\\Streams", "ui32ScanCode" , &g_PrivateHotKeyData.ui32ScanCode); + HostReadRegistryDWORDFromString("DEBUG\\Streams", "ui32ShiftState", &g_PrivateHotKeyData.ui32ShiftState); +} + +/****************************************************************************** + * Function Name: RegisterKeyPressed + * + * Inputs : IMG_UINT32 dwui32ScanCode, PHOTKEYINFO pInfo + * Outputs : - + * Returns : nothing + * Globals Used : - + * + * Description : Called when hotkey pressed. + *****************************************************************************/ +IMG_VOID RegisterKeyPressed(IMG_UINT32 dwui32ScanCode, PHOTKEYINFO pInfo) +{ + PDBG_STREAM psStream; + + PVR_UNREFERENCED_PARAMETER(pInfo); + + if (dwui32ScanCode == g_PrivateHotKeyData.ui32ScanCode) + { + PVR_DPF((PVR_DBG_MESSAGE,"PDUMP Hotkey pressed !\n")); + + psStream = (PDBG_STREAM) g_PrivateHotKeyData.sHotKeyInfo.pvStream; + + if (!g_bHotKeyPressed) + { + /* + Capture the next frame. + */ + g_ui32HotKeyFrame = psStream->psCtrl->ui32Current + 2; + + /* + Do the flag. + */ + g_bHotKeyPressed = IMG_TRUE; + } + } +} + +/****************************************************************************** + * Function Name: ActivateHotKeys + * + * Inputs : - + * Outputs : - + * Returns : - + * Globals Used : - + * + * Description : Installs HotKey callbacks + *****************************************************************************/ +IMG_VOID ActivateHotKeys(PDBG_STREAM psStream) +{ + /* + Setup hotkeys. + */ + ReadInHotKeys(); + + /* + Has it already been allocated. + */ + if (!g_PrivateHotKeyData.sHotKeyInfo.hHotKey) + { + if (g_PrivateHotKeyData.ui32ScanCode != 0) + { + PVR_DPF((PVR_DBG_MESSAGE,"Activate HotKey for PDUMP.\n")); + + /* + Add in stream data. + */ + g_PrivateHotKeyData.sHotKeyInfo.pvStream = psStream; + + DefineHotKey(g_PrivateHotKeyData.ui32ScanCode, g_PrivateHotKeyData.ui32ShiftState, &g_PrivateHotKeyData.sHotKeyInfo); + } + else + { + g_PrivateHotKeyData.sHotKeyInfo.hHotKey = 0; + } + } +} + +/****************************************************************************** + * Function Name: DeactivateHotKeys + * + * Inputs : - + * Outputs : - + * Returns : - + * Globals Used : - + * + * Description : Removes HotKey callbacks + *****************************************************************************/ +IMG_VOID DeactivateHotKeys(IMG_VOID) +{ + if (g_PrivateHotKeyData.sHotKeyInfo.hHotKey != 0) + { + PVR_DPF((PVR_DBG_MESSAGE,"Deactivate HotKey.\n")); + + RemoveHotKey(g_PrivateHotKeyData.sHotKeyInfo.hHotKey); + g_PrivateHotKeyData.sHotKeyInfo.hHotKey = 0; + } +} + + +/***************************************************************************** + End of file (HOTKEY.C) +*****************************************************************************/ diff --git a/pvr-source/tools/intern/debug/dbgdriv/common/hotkey.h b/pvr-source/tools/intern/debug/dbgdriv/common/hotkey.h new file mode 100644 index 0000000..7aa2952 --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/common/hotkey.h @@ -0,0 +1,82 @@ +/*************************************************************************/ /*! +@Title Debug driver utilities header file. +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@Description Hotkey stuff +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ + +#ifndef _HOTKEY_ +#define _HOTKEY_ + + +typedef struct _hotkeyinfo +{ + IMG_UINT8 ui8ScanCode; + IMG_UINT8 ui8Type; + IMG_UINT8 ui8Flag; + IMG_UINT8 ui8Filler1; + IMG_UINT32 ui32ShiftState; + IMG_UINT32 ui32HotKeyProc; + IMG_VOID *pvStream; + IMG_UINT32 hHotKey; /* handle. */ +} HOTKEYINFO, *PHOTKEYINFO; + +typedef struct _privatehotkeydata +{ + IMG_UINT32 ui32ScanCode; + IMG_UINT32 ui32ShiftState; + HOTKEYINFO sHotKeyInfo; +} PRIVATEHOTKEYDATA, *PPRIVATEHOTKEYDATA; + + +/***************************************************************************** + Hotkey stuff +*****************************************************************************/ +IMG_VOID ReadInHotKeys (IMG_VOID); +IMG_VOID ActivateHotKeys(PDBG_STREAM psStream); +IMG_VOID DeactivateHotKeys(IMG_VOID); + +IMG_VOID RemoveHotKey (IMG_UINT32 hHotKey); +IMG_VOID DefineHotKey (IMG_UINT32 ui32ScanCode, IMG_UINT32 ui32ShiftState, PHOTKEYINFO psInfo); +IMG_VOID RegisterKeyPressed (IMG_UINT32 ui32ScanCode, PHOTKEYINFO psInfo); + +#endif + +/***************************************************************************** + End of file (HOTKEY.H) +*****************************************************************************/ diff --git a/pvr-source/tools/intern/debug/dbgdriv/common/ioctl.c b/pvr-source/tools/intern/debug/dbgdriv/common/ioctl.c new file mode 100644 index 0000000..1767a9b --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/common/ioctl.c @@ -0,0 +1,827 @@ +/*************************************************************************/ /*! +@Title IOCTL implementations for debug device. +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ + + +#ifdef LINUX +#include <asm/uaccess.h> +#include "pvr_uaccess.h" +#endif /* LINUX */ + +#include "img_types.h" +#include "dbgdrvif.h" +#include "dbgdriv.h" +#include "hotkey.h" +#include "dbgdriv_ioctl.h" + + +/***************************************************************************** + Code +*****************************************************************************/ + +/***************************************************************************** + FUNCTION : DBGDrivCreateStream + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivCreateStream(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_CREATESTREAM psIn; + IMG_VOID * *ppvOut; + #ifdef LINUX + static IMG_CHAR name[32]; + #endif + + psIn = (PDBG_IN_CREATESTREAM) pvInBuffer; + ppvOut = (IMG_VOID * *) pvOutBuffer; + + #ifdef LINUX + + if(pvr_copy_from_user(name, psIn->u.pszName, 32) != 0) + { + return IMG_FALSE; + } + + *ppvOut = ExtDBGDrivCreateStream(name, psIn->ui32CapMode, psIn->ui32OutMode, 0, psIn->ui32Pages); + + #else + *ppvOut = ExtDBGDrivCreateStream(psIn->u.pszName, psIn->ui32CapMode, psIn->ui32OutMode, DEBUG_FLAGS_NO_BUF_EXPANDSION, psIn->ui32Pages); + #endif + + + return(IMG_TRUE); +} + +/***************************************************************************** + FUNCTION : DBGDrivDestroyStream + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivDestroyStream(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_STREAM *ppsStream; + PDBG_STREAM psStream; + + ppsStream = (PDBG_STREAM *) pvInBuffer; + psStream = (PDBG_STREAM) *ppsStream; + + PVR_UNREFERENCED_PARAMETER( pvOutBuffer); + + ExtDBGDrivDestroyStream(psStream); + + return(IMG_TRUE); +} + +/***************************************************************************** + FUNCTION : DBGDrivGetStream + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivGetStream(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_FINDSTREAM psParams; + IMG_SID * phStream; + + psParams = (PDBG_IN_FINDSTREAM)pvInBuffer; + phStream = (IMG_SID *)pvOutBuffer; + + *phStream = PStream2SID(ExtDBGDrivFindStream(psParams->u.pszName, psParams->bResetStream)); + + return(IMG_TRUE); +} + +/***************************************************************************** + FUNCTION : DBGDrivWriteString + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivWriteString(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_WRITESTRING psParams; + IMG_UINT32 *pui32OutLen; + PDBG_STREAM psStream; + + psParams = (PDBG_IN_WRITESTRING) pvInBuffer; + pui32OutLen = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(psParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32OutLen = ExtDBGDrivWriteString(psStream,psParams->u.pszString,psParams->ui32Level); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32OutLen = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivWriteStringCM + + PURPOSE : Same as DBGDrivWriteString, but takes notice of capture mode. + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivWriteStringCM(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_WRITESTRING psParams; + IMG_UINT32 *pui32OutLen; + PDBG_STREAM psStream; + + psParams = (PDBG_IN_WRITESTRING) pvInBuffer; + pui32OutLen = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(psParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32OutLen = ExtDBGDrivWriteStringCM(psStream,psParams->u.pszString,psParams->ui32Level); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32OutLen = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivReadString + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivReadString(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + IMG_UINT32 * pui32OutLen; + PDBG_IN_READSTRING psParams; + PDBG_STREAM psStream; + + psParams = (PDBG_IN_READSTRING) pvInBuffer; + pui32OutLen = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(psParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32OutLen = ExtDBGDrivReadString(psStream, + psParams->u.pszString,psParams->ui32StringLen); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32OutLen = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivWrite + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivWrite(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + IMG_UINT32 * pui32BytesCopied; + PDBG_IN_WRITE psInParams; + PDBG_STREAM psStream; + + psInParams = (PDBG_IN_WRITE) pvInBuffer; + pui32BytesCopied = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(psInParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32BytesCopied = ExtDBGDrivWrite(psStream, + psInParams->u.pui8InBuffer, + psInParams->ui32TransferSize, + psInParams->ui32Level); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32BytesCopied = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivWrite2 + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivWrite2(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + IMG_UINT32 * pui32BytesCopied; + PDBG_IN_WRITE psInParams; + PDBG_STREAM psStream; + + psInParams = (PDBG_IN_WRITE) pvInBuffer; + pui32BytesCopied = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(psInParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32BytesCopied = ExtDBGDrivWrite2(psStream, + psInParams->u.pui8InBuffer, + psInParams->ui32TransferSize, + psInParams->ui32Level); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32BytesCopied = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivWriteCM + + PURPOSE : Same as DBGDIOCDrivWrite2, but takes notice of capture mode. + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivWriteCM(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + IMG_UINT32 * pui32BytesCopied; + PDBG_IN_WRITE psInParams; + PDBG_STREAM psStream; + + psInParams = (PDBG_IN_WRITE) pvInBuffer; + pui32BytesCopied = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(psInParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32BytesCopied = ExtDBGDrivWriteCM(psStream, + psInParams->u.pui8InBuffer, + psInParams->ui32TransferSize, + psInParams->ui32Level); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32BytesCopied = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivRead + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivRead(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + IMG_UINT32 * pui32BytesCopied; + PDBG_IN_READ psInParams; + PDBG_STREAM psStream; + + psInParams = (PDBG_IN_READ) pvInBuffer; + pui32BytesCopied = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(psInParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32BytesCopied = ExtDBGDrivRead(psStream, + psInParams->bReadInitBuffer, + psInParams->ui32OutBufferSize, + psInParams->u.pui8OutBuffer); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32BytesCopied = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDIOCDrivSetCaptureMode + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivSetCaptureMode(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_SETDEBUGMODE psParams; + PDBG_STREAM psStream; + + psParams = (PDBG_IN_SETDEBUGMODE) pvInBuffer; + PVR_UNREFERENCED_PARAMETER(pvOutBuffer); + + psStream = SID2PStream(psParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + ExtDBGDrivSetCaptureMode(psStream, + psParams->ui32Mode, + psParams->ui32Start, + psParams->ui32End, + psParams->ui32SampleRate); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDIOCDrivSetOutMode + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivSetOutMode(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_SETDEBUGOUTMODE psParams; + PDBG_STREAM psStream; + + psParams = (PDBG_IN_SETDEBUGOUTMODE) pvInBuffer; + PVR_UNREFERENCED_PARAMETER(pvOutBuffer); + + psStream = SID2PStream(psParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + ExtDBGDrivSetOutputMode(psStream,psParams->ui32Mode); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDIOCDrivSetDebugLevel + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivSetDebugLevel(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_SETDEBUGLEVEL psParams; + PDBG_STREAM psStream; + + psParams = (PDBG_IN_SETDEBUGLEVEL) pvInBuffer; + PVR_UNREFERENCED_PARAMETER(pvOutBuffer); + + psStream = SID2PStream(psParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + ExtDBGDrivSetDebugLevel(psStream,psParams->ui32Level); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivSetFrame + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivSetFrame(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_SETFRAME psParams; + PDBG_STREAM psStream; + + psParams = (PDBG_IN_SETFRAME) pvInBuffer; + PVR_UNREFERENCED_PARAMETER(pvOutBuffer); + + psStream = SID2PStream(psParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + ExtDBGDrivSetFrame(psStream,psParams->ui32Frame); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivGetFrame + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivGetFrame(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_STREAM psStream; + IMG_UINT32 *pui32Current; + + pui32Current = (IMG_UINT32 *) pvOutBuffer; + psStream = SID2PStream(*(IMG_SID *)pvInBuffer); + + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32Current = ExtDBGDrivGetFrame(psStream); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32Current = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDIOCDrivIsCaptureFrame + + PURPOSE : Determines if this frame is a capture frame + + PARAMETERS : + + RETURNS : IMG_TRUE if current frame is to be captured +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivIsCaptureFrame(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_ISCAPTUREFRAME psParams; + IMG_UINT32 * pui32Current; + PDBG_STREAM psStream; + + psParams = (PDBG_IN_ISCAPTUREFRAME) pvInBuffer; + pui32Current = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(psParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32Current = ExtDBGDrivIsCaptureFrame(psStream, + psParams->bCheckPreviousFrame); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32Current = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivOverrideMode + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivOverrideMode(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_OVERRIDEMODE psParams; + PDBG_STREAM psStream; + + psParams = (PDBG_IN_OVERRIDEMODE) pvInBuffer; + PVR_UNREFERENCED_PARAMETER( pvOutBuffer); + + psStream = SID2PStream(psParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + ExtDBGDrivOverrideMode(psStream,psParams->ui32Mode); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivDefaultMode + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivDefaultMode(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_STREAM psStream; + + PVR_UNREFERENCED_PARAMETER(pvOutBuffer); + + psStream = SID2PStream(*(IMG_SID *)pvInBuffer); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + ExtDBGDrivDefaultMode(psStream); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDIOCDrivSetMarker + + PURPOSE : Sets the marker in the stream to split output files + + PARAMETERS : pvInBuffer, pvOutBuffer + + RETURNS : success +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivSetMarker(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_SETMARKER psParams; + PDBG_STREAM psStream; + + psParams = (PDBG_IN_SETMARKER) pvInBuffer; + PVR_UNREFERENCED_PARAMETER(pvOutBuffer); + + psStream = SID2PStream(psParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + ExtDBGDrivSetMarker(psStream, psParams->ui32Marker); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDIOCDrivGetMarker + + PURPOSE : Gets the marker in the stream to split output files + + PARAMETERS : pvInBuffer, pvOutBuffer + + RETURNS : success +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivGetMarker(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_STREAM psStream; + IMG_UINT32 *pui32Current; + + pui32Current = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(*(IMG_SID *)pvInBuffer); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32Current = ExtDBGDrivGetMarker(psStream); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32Current = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDrivGetServiceTable + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivGetServiceTable(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + IMG_PVOID * ppvOut; + + PVR_UNREFERENCED_PARAMETER(pvInBuffer); + ppvOut = (IMG_PVOID *) pvOutBuffer; + + *ppvOut = DBGDrivGetServiceTable(); + + return(IMG_TRUE); +} + +/***************************************************************************** + FUNCTION : DBGDIOCDrivWriteLF + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivWriteLF(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + PDBG_IN_WRITE_LF psInParams; + IMG_UINT32 *pui32BytesCopied; + PDBG_STREAM psStream; + + psInParams = (PDBG_IN_WRITE_LF) pvInBuffer; + pui32BytesCopied = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(psInParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32BytesCopied = ExtDBGDrivWriteLF(psStream, + psInParams->u.pui8InBuffer, + psInParams->ui32BufferSize, + psInParams->ui32Level, + psInParams->ui32Flags); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDIOCDrivReadLF + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivReadLF(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + IMG_UINT32 * pui32BytesCopied; + PDBG_IN_READ psInParams; + PDBG_STREAM psStream; + + psInParams = (PDBG_IN_READ) pvInBuffer; + pui32BytesCopied = (IMG_UINT32 *) pvOutBuffer; + + psStream = SID2PStream(psInParams->hStream); + if (psStream != (PDBG_STREAM)IMG_NULL) + { + *pui32BytesCopied = ExtDBGDrivReadLF(psStream, + psInParams->ui32OutBufferSize, + psInParams->u.pui8OutBuffer); + return(IMG_TRUE); + } + else + { + /* invalid SID */ + *pui32BytesCopied = 0; + return(IMG_FALSE); + } +} + +/***************************************************************************** + FUNCTION : DBGDIOCDrivWaitForEvent + + PURPOSE : + + PARAMETERS : + + RETURNS : +*****************************************************************************/ +static IMG_UINT32 DBGDIOCDrivWaitForEvent(IMG_VOID * pvInBuffer, IMG_VOID * pvOutBuffer) +{ + DBG_EVENT eEvent = (DBG_EVENT)(*(IMG_UINT32 *)pvInBuffer); + + PVR_UNREFERENCED_PARAMETER(pvOutBuffer); + + ExtDBGDrivWaitForEvent(eEvent); + + return(IMG_TRUE); +} + +/* + VxD DIOC interface jump table. +*/ +IMG_UINT32 (*g_DBGDrivProc[25])(IMG_VOID *, IMG_VOID *) = +{ + DBGDIOCDrivCreateStream, + DBGDIOCDrivDestroyStream, + DBGDIOCDrivGetStream, + DBGDIOCDrivWriteString, + DBGDIOCDrivReadString, + DBGDIOCDrivWrite, + DBGDIOCDrivRead, + DBGDIOCDrivSetCaptureMode, + DBGDIOCDrivSetOutMode, + DBGDIOCDrivSetDebugLevel, + DBGDIOCDrivSetFrame, + DBGDIOCDrivGetFrame, + DBGDIOCDrivOverrideMode, + DBGDIOCDrivDefaultMode, + DBGDIOCDrivGetServiceTable, + DBGDIOCDrivWrite2, + DBGDIOCDrivWriteStringCM, + DBGDIOCDrivWriteCM, + DBGDIOCDrivSetMarker, + DBGDIOCDrivGetMarker, + DBGDIOCDrivIsCaptureFrame, + DBGDIOCDrivWriteLF, + DBGDIOCDrivReadLF, + DBGDIOCDrivWaitForEvent +}; + +/***************************************************************************** + End of file (IOCTL.C) +*****************************************************************************/ diff --git a/pvr-source/tools/intern/debug/dbgdriv/linux/hostfunc.c b/pvr-source/tools/intern/debug/dbgdriv/linux/hostfunc.c new file mode 100644 index 0000000..5d5e9ef --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/linux/hostfunc.c @@ -0,0 +1,395 @@ +/*************************************************************************/ /*! +@Title Debug driver file +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ +#include <linux/version.h> +#include <linux/errno.h> +#include <linux/module.h> +#include <linux/fs.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/mm.h> +#include <linux/string.h> +#include <asm/page.h> +#include <linux/vmalloc.h> +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)) +#include <linux/mutex.h> +#else +#include <asm/semaphore.h> +#endif +#include <linux/hardirq.h> + +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) +#include <linux/sched.h> +#include <linux/wait.h> +#include <linux/jiffies.h> +#include <linux/delay.h> +#endif /* defined(SUPPORT_DBGDRV_EVENT_OBJECTS) */ + +#include "img_types.h" +#include "pvr_debug.h" + +#include "dbgdrvif.h" +#include "hostfunc.h" +#include "dbgdriv.h" + +#if defined(MODULE) && defined(DEBUG) && !defined(SUPPORT_DRI_DRM) +IMG_UINT32 gPVRDebugLevel = (DBGPRIV_FATAL | DBGPRIV_ERROR | DBGPRIV_WARNING); + +#define PVR_STRING_TERMINATOR '\0' +#define PVR_IS_FILE_SEPARATOR(character) ( ((character) == '\\') || ((character) == '/') ) + +/******************************************************************************/ + + +/*! +****************************************************************************** + + @Function PVRSRVDebugPrintf + + @Description To output a debug message to the user + + @Input uDebugLevel: The current debug level + @Input pszFile: The source file generating the message + @Input uLine: The line of the source file + @Input pszFormat: The message format string + @Input ...: Zero or more arguments for use by the format string + + @Return none +******************************************************************************/ +void PVRSRVDebugPrintf ( + IMG_UINT32 ui32DebugLevel, + const IMG_CHAR* pszFileName, + IMG_UINT32 ui32Line, + const IMG_CHAR* pszFormat, + ... + ) +{ + IMG_BOOL bTrace; +#if !defined(__sh__) + IMG_CHAR *pszLeafName; + + pszLeafName = (char *)strrchr (pszFileName, '\\'); + + if (pszLeafName) + { + pszFileName = pszLeafName; + } +#endif /* __sh__ */ + + bTrace = (IMG_BOOL)(ui32DebugLevel & DBGPRIV_CALLTRACE) ? IMG_TRUE : IMG_FALSE; + + if (gPVRDebugLevel & ui32DebugLevel) + { + va_list vaArgs; + char szBuffer[256]; + char *szBufferEnd = szBuffer; + char *szBufferLimit = szBuffer + sizeof(szBuffer) - 1; + + /* The Limit - End pointer arithmetic we're doing in snprintf + ensures that our buffer remains null terminated from this */ + *szBufferLimit = '\0'; + + snprintf(szBufferEnd, szBufferLimit - szBufferEnd, "PVR_K:"); + szBufferEnd += strlen(szBufferEnd); + + /* Add in the level of warning */ + if (bTrace == IMG_FALSE) + { + switch(ui32DebugLevel) + { + case DBGPRIV_FATAL: + { + snprintf(szBufferEnd, szBufferLimit - szBufferEnd, "(Fatal):"); + break; + } + case DBGPRIV_ERROR: + { + snprintf(szBufferEnd, szBufferLimit - szBufferEnd, "(Error):"); + break; + } + case DBGPRIV_WARNING: + { + snprintf(szBufferEnd, szBufferLimit - szBufferEnd, "(Warning):"); + break; + } + case DBGPRIV_MESSAGE: + { + snprintf(szBufferEnd, szBufferLimit - szBufferEnd, "(Message):"); + break; + } + case DBGPRIV_VERBOSE: + { + snprintf(szBufferEnd, szBufferLimit - szBufferEnd, "(Verbose):"); + break; + } + default: + { + snprintf(szBufferEnd, szBufferLimit - szBufferEnd, "(Unknown message level)"); + break; + } + } + szBufferEnd += strlen(szBufferEnd); + } + snprintf(szBufferEnd, szBufferLimit - szBufferEnd, " "); + szBufferEnd += strlen(szBufferEnd); + + va_start (vaArgs, pszFormat); + vsnprintf(szBufferEnd, szBufferLimit - szBufferEnd, pszFormat, vaArgs); + va_end (vaArgs); + szBufferEnd += strlen(szBufferEnd); + + /* + * Metrics and Traces don't need a location + */ + if (bTrace == IMG_FALSE) + { + snprintf(szBufferEnd, szBufferLimit - szBufferEnd, + " [%d, %s]", (int)ui32Line, pszFileName); + szBufferEnd += strlen(szBufferEnd); + } + + printk(KERN_INFO "%s\r\n", szBuffer); + } +} +#endif /* defined(DEBUG) && !defined(SUPPORT_DRI_DRM) */ + +/*! +****************************************************************************** + + @Function HostMemSet + + @Description Function that does the same as the C memset() function + + @Modified *pvDest : pointer to start of buffer to be set + + @Input ui8Value: value to set each byte to + + @Input ui32Size : number of bytes to set + + @Return IMG_VOID + +******************************************************************************/ +IMG_VOID HostMemSet(IMG_VOID *pvDest, IMG_UINT8 ui8Value, IMG_UINT32 ui32Size) +{ + memset(pvDest, (int) ui8Value, (size_t) ui32Size); +} + +/*! +****************************************************************************** + + @Function HostMemCopy + + @Description Function that does the same as the C memscpy() function + + @Input pvDst - pointer to dst + @Output pvSrc - pointer to src + @Input ui32Size - bytes to copy + + @Return none + +******************************************************************************/ +IMG_VOID HostMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_UINT32 ui32Size) +{ +#if defined(USE_UNOPTIMISED_MEMCPY) + unsigned char *src,*dst; + int i; + + src=(unsigned char *)pvSrc; + dst=(unsigned char *)pvDst; + for(i=0;i<ui32Size;i++) + { + dst[i]=src[i]; + } +#else + memcpy(pvDst, pvSrc, ui32Size); +#endif +} + +IMG_UINT32 HostReadRegistryDWORDFromString(char *pcKey, char *pcValueName, IMG_UINT32 *pui32Data) +{ + /* FIXME: Not yet implemented */ + return 0; +} + +IMG_VOID * HostPageablePageAlloc(IMG_UINT32 ui32Pages) +{ + return (void*)vmalloc(ui32Pages * PAGE_SIZE);/*, GFP_KERNEL);*/ +} + +IMG_VOID HostPageablePageFree(IMG_VOID * pvBase) +{ + vfree(pvBase); +} + +IMG_VOID * HostNonPageablePageAlloc(IMG_UINT32 ui32Pages) +{ + return (void*)vmalloc(ui32Pages * PAGE_SIZE);/*, GFP_KERNEL);*/ +} + +IMG_VOID HostNonPageablePageFree(IMG_VOID * pvBase) +{ + vfree(pvBase); +} + +IMG_VOID * HostMapKrnBufIntoUser(IMG_VOID * pvKrnAddr, IMG_UINT32 ui32Size, IMG_VOID **ppvMdl) +{ + /* FIXME: Not yet implemented */ + return IMG_NULL; +} + +IMG_VOID HostUnMapKrnBufFromUser(IMG_VOID * pvUserAddr, IMG_VOID * pvMdl, IMG_VOID * pvProcess) +{ + /* FIXME: Not yet implemented */ +} + +IMG_VOID HostCreateRegDeclStreams(IMG_VOID) +{ + /* FIXME: Not yet implemented */ +} + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) +typedef struct mutex MUTEX; +#define INIT_MUTEX(m) mutex_init(m) +#define DOWN_TRYLOCK(m) (!mutex_trylock(m)) +#define DOWN(m) mutex_lock(m) +#define UP(m) mutex_unlock(m) +#else +typedef struct semaphore MUTEX; +#define INIT_MUTEX(m) init_MUTEX(m) +#define DOWN_TRYLOCK(m) down_trylock(m) +#define DOWN(m) down(m) +#define UP(m) up(m) +#endif + +IMG_VOID *HostCreateMutex(IMG_VOID) +{ + MUTEX *psMutex; + + psMutex = kmalloc(sizeof(*psMutex), GFP_KERNEL); + if (psMutex) + { + INIT_MUTEX(psMutex); + } + + return psMutex; +} + +IMG_VOID HostAquireMutex(IMG_VOID * pvMutex) +{ + BUG_ON(in_interrupt()); + +#if defined(PVR_DEBUG_DBGDRV_DETECT_HOST_MUTEX_COLLISIONS) + if (DOWN_TRYLOCK((MUTEX *)pvMutex)) + { + printk(KERN_INFO "HostAquireMutex: Waiting for mutex\n"); + DOWN((MUTEX *)pvMutex); + } +#else + DOWN((MUTEX *)pvMutex); +#endif +} + +IMG_VOID HostReleaseMutex(IMG_VOID * pvMutex) +{ + UP((MUTEX *)pvMutex); +} + +IMG_VOID HostDestroyMutex(IMG_VOID * pvMutex) +{ + if (pvMutex) + { + kfree(pvMutex); + } +} + +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) + +#define EVENT_WAIT_TIMEOUT_MS 500 +#define EVENT_WAIT_TIMEOUT_JIFFIES (EVENT_WAIT_TIMEOUT_MS * HZ / 1000) + +static int iStreamData; +static wait_queue_head_t sStreamDataEvent; + +IMG_INT32 HostCreateEventObjects(IMG_VOID) +{ + init_waitqueue_head(&sStreamDataEvent); + + return 0; +} + +IMG_VOID HostWaitForEvent(DBG_EVENT eEvent) +{ + switch(eEvent) + { + case DBG_EVENT_STREAM_DATA: + /* + * More than one process may be woken up. + * Any process that wakes up should consume + * all the data from the streams. + */ + wait_event_interruptible_timeout(sStreamDataEvent, iStreamData != 0, EVENT_WAIT_TIMEOUT_JIFFIES); + iStreamData = 0; + break; + default: + /* + * For unknown events, enter an interruptible sleep. + */ + msleep_interruptible(EVENT_WAIT_TIMEOUT_MS); + break; + } +} + +IMG_VOID HostSignalEvent(DBG_EVENT eEvent) +{ + switch(eEvent) + { + case DBG_EVENT_STREAM_DATA: + iStreamData = 1; + wake_up_interruptible(&sStreamDataEvent); + break; + default: + break; + } +} + +IMG_VOID HostDestroyEventObjects(IMG_VOID) +{ +} +#endif /* defined(SUPPORT_DBGDRV_EVENT_OBJECTS) */ diff --git a/pvr-source/tools/intern/debug/dbgdriv/linux/main.c b/pvr-source/tools/intern/debug/dbgdriv/linux/main.c new file mode 100644 index 0000000..c1ca85b --- /dev/null +++ b/pvr-source/tools/intern/debug/dbgdriv/linux/main.c @@ -0,0 +1,355 @@ +/*************************************************************************/ /*! +@Title Debug driver main file +@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved +@License Dual MIT/GPLv2 + +The contents of this file are subject to the MIT license as set out below. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +Alternatively, the contents of this file may be used under the terms of +the GNU General Public License Version 2 ("GPL") in which case the provisions +of GPL are applicable instead of those above. + +If you wish to allow use of your version of this file only under the terms of +GPL, and not to allow others to use your version of this file under the terms +of the MIT license, indicate your decision by deleting the provisions above +and replace them with the notice and other provisions required by GPL as set +out in the file called "GPL-COPYING" included in this distribution. If you do +not delete the provisions above, a recipient may use your version of this file +under the terms of either the MIT license or GPL. + +This License is also included in this distribution in the file called +"MIT-COPYING". + +EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS +PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ /**************************************************************************/ +#include <linux/errno.h> +#include <linux/module.h> +#include <linux/fs.h> +#include <linux/kernel.h> +#include <linux/kdev_t.h> +#include <linux/pci.h> +#include <linux/list.h> +#include <linux/init.h> +#include <linux/vmalloc.h> +#include <linux/version.h> + +#if defined(LDM_PLATFORM) && !defined(SUPPORT_DRI_DRM) +#include <linux/platform_device.h> +#endif + +#if defined(LDM_PCI) && !defined(SUPPORT_DRI_DRM) +#include <linux/pci.h> +#endif + +#include <asm/uaccess.h> + +#if defined(SUPPORT_DRI_DRM) +#include "drmP.h" +#include "drm.h" +#endif + +#include "img_types.h" +#include "linuxsrv.h" +#include "dbgdriv_ioctl.h" +#include "dbgdrvif.h" +#include "dbgdriv.h" +#include "hostfunc.h" +#include "hotkey.h" +#include "pvr_debug.h" +#include "pvrmodule.h" +#include "pvr_uaccess.h" + +#if defined(SUPPORT_DRI_DRM) + +#include "pvr_drm_shared.h" +#include "pvr_drm.h" + +#else /* defined(SUPPORT_DRI_DRM) */ + +#define DRVNAME "dbgdrv" +MODULE_SUPPORTED_DEVICE(DRVNAME); + +#if (defined(LDM_PLATFORM) || defined(LDM_PCI)) && !defined(SUPPORT_DRI_DRM) +static struct class *psDbgDrvClass; +#endif + +static int AssignedMajorNumber = 0; + +long dbgdrv_ioctl(struct file *, unsigned int, unsigned long); + +static int dbgdrv_open(struct inode unref__ * pInode, struct file unref__ * pFile) +{ + return 0; +} + +static int dbgdrv_release(struct inode unref__ * pInode, struct file unref__ * pFile) +{ + return 0; +} + +static int dbgdrv_mmap(struct file* pFile, struct vm_area_struct* ps_vma) +{ + return 0; +} + +static struct file_operations dbgdrv_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = dbgdrv_ioctl, + .open = dbgdrv_open, + .release = dbgdrv_release, + .mmap = dbgdrv_mmap, +}; + +#endif /* defined(SUPPORT_DRI_DRM) */ + +IMG_VOID DBGDrvGetServiceTable(DBGKM_SERVICE_TABLE **fn_table) +{ + extern DBGKM_SERVICE_TABLE g_sDBGKMServices; + + *fn_table = &g_sDBGKMServices; +} + +#if defined(SUPPORT_DRI_DRM) +void dbgdrv_cleanup(void) +#else +static void __exit dbgdrv_cleanup(void) +#endif +{ +#if !defined(SUPPORT_DRI_DRM) +#if defined(LDM_PLATFORM) || defined(LDM_PCI) + device_destroy(psDbgDrvClass, MKDEV(AssignedMajorNumber, 0)); + class_destroy(psDbgDrvClass); +#endif + unregister_chrdev(AssignedMajorNumber, DRVNAME); +#endif /* !defined(SUPPORT_DRI_DRM) */ +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) + HostDestroyEventObjects(); +#endif + HostDestroyMutex(g_pvAPIMutex); + return; +} + +#if defined(SUPPORT_DRI_DRM) +IMG_INT dbgdrv_init(void) +#else +static int __init dbgdrv_init(void) +#endif +{ +#if (defined(LDM_PLATFORM) || defined(LDM_PCI)) && !defined(SUPPORT_DRI_DRM) + struct device *psDev; +#endif + +#if !defined(SUPPORT_DRI_DRM) + int err = -EBUSY; +#endif + + /* Init API mutex */ + if ((g_pvAPIMutex=HostCreateMutex()) == IMG_NULL) + { + return -ENOMEM; + } + +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) + /* + * The current implementation of HostCreateEventObjects on Linux + * can never fail, so there is no need to check for error. + */ + (void) HostCreateEventObjects(); +#endif + +#if !defined(SUPPORT_DRI_DRM) + AssignedMajorNumber = + register_chrdev(AssignedMajorNumber, DRVNAME, &dbgdrv_fops); + + if (AssignedMajorNumber <= 0) + { + PVR_DPF((PVR_DBG_ERROR," unable to get major\n")); + goto ErrDestroyEventObjects; + } + +#if defined(LDM_PLATFORM) || defined(LDM_PCI) + /* + * This code (using GPL symbols) facilitates automatic device + * node creation on platforms with udev (or similar). + */ + psDbgDrvClass = class_create(THIS_MODULE, DRVNAME); + if (IS_ERR(psDbgDrvClass)) + { + PVR_DPF((PVR_DBG_ERROR, "%s: unable to create class (%ld)", + __func__, PTR_ERR(psDbgDrvClass))); + goto ErrUnregisterCharDev; + } + + psDev = device_create(psDbgDrvClass, NULL, MKDEV(AssignedMajorNumber, 0), +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) + NULL, +#endif + DRVNAME); + if (IS_ERR(psDev)) + { + PVR_DPF((PVR_DBG_ERROR, "%s: unable to create device (%ld)", + __func__, PTR_ERR(psDev))); + goto ErrDestroyClass; + } +#endif /* defined(LDM_PLATFORM) || defined(LDM_PCI) */ +#endif /* !defined(SUPPORT_DRI_DRM) */ + + return 0; + +#if !defined(SUPPORT_DRI_DRM) +ErrDestroyEventObjects: +#if defined(SUPPORT_DBGDRV_EVENT_OBJECTS) + HostDestroyEventObjects(); +#endif +#if defined(LDM_PLATFORM) || defined(LDM_PCI) +ErrUnregisterCharDev: + unregister_chrdev(AssignedMajorNumber, DRVNAME); +ErrDestroyClass: + class_destroy(psDbgDrvClass); +#endif + return err; +#endif /* !defined(SUPPORT_DRI_DRM) */ +} + +#if defined(SUPPORT_DRI_DRM) +int dbgdrv_ioctl(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile) +#else +long dbgdrv_ioctl(struct file *file, unsigned int ioctlCmd, unsigned long arg) +#endif +{ + IOCTL_PACKAGE *pIP = (IOCTL_PACKAGE *) arg; + char *buffer, *in, *out; + unsigned int cmd; + + if((pIP->ui32InBufferSize > (PAGE_SIZE >> 1) ) || (pIP->ui32OutBufferSize > (PAGE_SIZE >> 1))) + { + PVR_DPF((PVR_DBG_ERROR,"Sizes of the buffers are too large, cannot do ioctl\n")); + return -1; + } + + buffer = (char *) HostPageablePageAlloc(1); + if(!buffer) + { + PVR_DPF((PVR_DBG_ERROR,"Failed to allocate buffer, cannot do ioctl\n")); + return -EFAULT; + } + + in = buffer; + out = buffer + (PAGE_SIZE >>1); + + if(pvr_copy_from_user(in, pIP->pInBuffer, pIP->ui32InBufferSize) != 0) + { + goto init_failed; + } + + /* Extra -1 because ioctls start at DEBUG_SERVICE_IOCTL_BASE + 1 */ + cmd = MAKEIOCTLINDEX(pIP->ui32Cmd) - DEBUG_SERVICE_IOCTL_BASE - 1; + + if(pIP->ui32Cmd == DEBUG_SERVICE_READ) + { + IMG_UINT32 *pui32BytesCopied = (IMG_UINT32 *)out; + DBG_IN_READ *psReadInParams = (DBG_IN_READ *)in; + DBG_STREAM *psStream; + IMG_CHAR *ui8Tmp; + + ui8Tmp = vmalloc(psReadInParams->ui32OutBufferSize); + + if(!ui8Tmp) + { + goto init_failed; + } + + psStream = SID2PStream(psReadInParams->hStream); + if(!psStream) + { + goto init_failed; + } + + *pui32BytesCopied = ExtDBGDrivRead(psStream, + psReadInParams->bReadInitBuffer, + psReadInParams->ui32OutBufferSize, + ui8Tmp); + + if(pvr_copy_to_user(psReadInParams->u.pui8OutBuffer, + ui8Tmp, + *pui32BytesCopied) != 0) + { + vfree(ui8Tmp); + goto init_failed; + } + + vfree(ui8Tmp); + } + else + { + (g_DBGDrivProc[cmd])(in, out); + } + + if(copy_to_user(pIP->pOutBuffer, out, pIP->ui32OutBufferSize) != 0) + { + goto init_failed; + } + + HostPageablePageFree((IMG_VOID *)buffer); + return 0; + +init_failed: + HostPageablePageFree((IMG_VOID *)buffer); + return -EFAULT; +} + + +/****************************************************************************** + * Function Name: RemoveHotKey + * + * Inputs : - + * Outputs : - + * Returns : - + * Globals Used : - + * + * Description : Removes HotKey callbacks + *****************************************************************************/ +IMG_VOID RemoveHotKey (IMG_UINT32 hHotKey) +{ + PVR_UNREFERENCED_PARAMETER(hHotKey); +} + +/****************************************************************************** + * Function Name: DefineHotKey + * + * Inputs : - + * Outputs : - + * Returns : - + * Globals Used : - + * + * Description : Removes HotKey callbacks + *****************************************************************************/ +IMG_VOID DefineHotKey (IMG_UINT32 ui32ScanCode, IMG_UINT32 ui32ShiftState, PHOTKEYINFO psInfo) +{ + PVR_UNREFERENCED_PARAMETER(ui32ScanCode); + PVR_UNREFERENCED_PARAMETER(ui32ShiftState); + PVR_UNREFERENCED_PARAMETER(psInfo); +} + +EXPORT_SYMBOL(DBGDrvGetServiceTable); + +#if !defined(SUPPORT_DRI_DRM) +subsys_initcall(dbgdrv_init); +module_exit(dbgdrv_cleanup); +#endif |