Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

@@ -0,0 +1,181 @@
/*************************************************************************/ /*!
@File allocmem.h
@Title memory allocation header
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Memory-Allocation API definitions
@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 ALLOCMEM_H
#define ALLOCMEM_H
#include "img_types.h"
#include "pvr_debug.h"
#if defined(__cplusplus)
extern "C" {
#endif
#if !defined(PVRSRV_DEBUG_LINUX_MEMORY_STATS) || !defined(DEBUG) || !defined(PVRSRV_ENABLE_PROCESS_STATS) || !defined(PVRSRV_ENABLE_MEMORY_STATS) || defined(DOXYGEN)
/**************************************************************************/ /*!
@Function OSAllocMem
@Description Allocates CPU memory. Contents are uninitialized.
If passed a size of zero, function should not assert,
but just return a NULL pointer.
@Input ui32Size Size of required allocation (in bytes)
@Return Pointer to allocated memory on success.
Otherwise NULL.
*/ /**************************************************************************/
void *OSAllocMem(IMG_UINT32 ui32Size);
#define OSAllocMem(_size) (OSAllocMem)((_size))
/**************************************************************************/ /*!
@Function OSAllocZMem
@Description Allocates CPU memory and initializes the contents to zero.
If passed a size of zero, function should not assert,
but just return a NULL pointer.
@Input ui32Size Size of required allocation (in bytes)
@Return Pointer to allocated memory on success.
Otherwise NULL.
*/ /**************************************************************************/
void *OSAllocZMem(IMG_UINT32 ui32Size);
#define OSAllocZMem(_size) (OSAllocZMem)((_size))
#else
void *OSAllocMem(IMG_UINT32 ui32Size, void *pvAllocFromFile, IMG_UINT32 ui32AllocFromLine);
void *OSAllocZMem(IMG_UINT32 ui32Size, void *pvAllocFromFile, IMG_UINT32 ui32AllocFromLine);
#define OSAllocMem(_size) (OSAllocMem)((_size), (__FILE__), (__LINE__))
#define OSAllocZMem(_size) (OSAllocZMem)((_size), (__FILE__), (__LINE__))
#endif
/**************************************************************************/ /*!
@Function OSAllocMemNoStats
@Description Allocates CPU memory. Contents are uninitialized.
If passed a size of zero, function should not assert,
but just return a NULL pointer.
The allocated memory is not accounted for by process stats.
Process stats are an optional feature (enabled only when
PVRSRV_ENABLE_PROCESS_STATS is defined) which track the amount
of memory allocated to help in debugging. Where this is not
required, OSAllocMem() and OSAllocMemNoStats() equate to
the same operation.
@Input ui32Size Size of required allocation (in bytes)
@Return Pointer to allocated memory on success.
Otherwise NULL.
*/ /**************************************************************************/
void *OSAllocMemNoStats(IMG_UINT32 ui32Size);
/**************************************************************************/ /*!
@Function OSAllocZMemNoStats
@Description Allocates CPU memory and initializes the contents to zero.
If passed a size of zero, function should not assert,
but just return a NULL pointer.
The allocated memory is not accounted for by process stats.
Process stats are an optional feature (enabled only when
PVRSRV_ENABLE_PROCESS_STATS is defined) which track the amount
of memory allocated to help in debugging. Where this is not
required, OSAllocZMem() and OSAllocZMemNoStats() equate to
the same operation.
@Input ui32Size Size of required allocation (in bytes)
@Return Pointer to allocated memory on success.
Otherwise NULL.
*/ /**************************************************************************/
void *OSAllocZMemNoStats(IMG_UINT32 ui32Size);
/**************************************************************************/ /*!
@Function OSFreeMem
@Description Frees previously allocated CPU memory.
@Input pvCpuVAddr Pointer to the memory to be freed.
@Return None.
*/ /**************************************************************************/
void OSFreeMem(void *pvCpuVAddr);
/**************************************************************************/ /*!
@Function OSFreeMemNoStats
@Description Frees previously allocated CPU memory.
The freed memory does not update the figures in process stats.
Process stats are an optional feature (enabled only when
PVRSRV_ENABLE_PROCESS_STATS is defined) which track the amount
of memory allocated to help in debugging. Where this is not
required, OSFreeMem() and OSFreeMemNoStats() equate to the
same operation.
@Input pvCpuVAddr Pointer to the memory to be freed.
@Return None.
*/ /**************************************************************************/
void OSFreeMemNoStats(void *pvCpuVAddr);
/*
* These macros allow us to catch double-free bugs on DEBUG builds and
* prevent crashes on RELEASE builds.
*/
/*! @cond Doxygen_Suppress */
#if defined(DEBUG)
#define double_free_sentinel ((void *)&OSFreeMem)
#define ALLOCMEM_ASSERT(exp) PVR_ASSERT(exp)
#else
#define double_free_sentinel NULL
#define ALLOCMEM_ASSERT(exp) do {} while (0)
#endif
/*! @endcond */
/*! Frees memory allocated by OSAllocMem(). */
#define OSFreeMem(_ptr) do { \
ALLOCMEM_ASSERT((_ptr) != double_free_sentinel); \
(OSFreeMem)(_ptr); \
(_ptr) = double_free_sentinel; \
MSC_SUPPRESS_4127 \
} while (0)
/*! Frees memory allocated by OSAllocMemNoStats(). */
#define OSFreeMemNoStats(_ptr) do { \
ALLOCMEM_ASSERT((_ptr) != double_free_sentinel); \
(OSFreeMemNoStats)(_ptr); \
(_ptr) = double_free_sentinel; \
MSC_SUPPRESS_4127 \
} while (0)
#if defined(__cplusplus)
}
#endif
#endif /* ALLOCMEM_H */
/******************************************************************************
End of file (allocmem.h)
******************************************************************************/
@@ -0,0 +1,117 @@
/*************************************************************************/ /*!
@File device_connection.h
@Title
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description
@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(DEVICE_CONNECTION_H)
#define DEVICE_CONNECTION_H
#include "img_types.h"
#include "img_defs.h"
#if defined(__KERNEL__)
typedef struct _PVRSRV_DEVICE_NODE_ *SHARED_DEV_CONNECTION;
#else
#include "connection.h"
typedef const struct PVRSRV_DEV_CONNECTION_TAG *SHARED_DEV_CONNECTION;
#endif
/******************************************************************************
* Device capability flags and masks
*
* Following bitmask shows allocated ranges and values for our device
* capability settings:
*
* 31 27 23 19 15 11 7 3 0
* |...|...|...|...|...|...|...|...
* ** CACHE_COHERENT [0x1..0x2]
* x PVRSRV_CACHE_COHERENT_DEVICE_FLAG
* x. PVRSRV_CACHE_COHERENT_CPU_FLAG
* *... NONMAPPABLE_MEMORY [0x8]
* x... PVRSRV_NONMAPPABLE_MEMORY_PRESENT_FLAG
* *.... PDUMP_IS_RECORDING [0x10]
* x.... PVRSRV_PDUMP_IS_RECORDING
* ***........ DEVMEM_SVM_ALLOC [0x100..0x400]
* x........ PVRSRV_DEVMEM_SVM_ALLOC_UNSUPPORTED
* x......... PVRSRV_DEVMEM_SVM_ALLOC_SUPPORTED
* x.......... PVRSRV_DEVMEM_SVM_ALLOC_CANFAIL
* *........... FBCDC_V3_1 [0x800]
* x........... FBCDC_V3_1_USED
* |...|...|...|...|...|...|...|...
*****************************************************************************/
/* Flag to be passed over the bridge during connection stating whether CPU cache coherent is available*/
#define PVRSRV_CACHE_COHERENT_SHIFT (0)
#define PVRSRV_CACHE_COHERENT_DEVICE_FLAG (1U << PVRSRV_CACHE_COHERENT_SHIFT)
#define PVRSRV_CACHE_COHERENT_CPU_FLAG (2U << PVRSRV_CACHE_COHERENT_SHIFT)
#define PVRSRV_CACHE_COHERENT_EMULATE_FLAG (4U << PVRSRV_CACHE_COHERENT_SHIFT)
#define PVRSRV_CACHE_COHERENT_MASK (7U << PVRSRV_CACHE_COHERENT_SHIFT)
/* Flag to be passed over the bridge during connection stating whether CPU non-mappable memory is present */
#define PVRSRV_NONMAPPABLE_MEMORY_PRESENT_SHIFT (7)
#define PVRSRV_NONMAPPABLE_MEMORY_PRESENT_FLAG (1U << PVRSRV_NONMAPPABLE_MEMORY_PRESENT_SHIFT)
/* Flag to be passed over the bridge to indicate PDump activity */
#define PVRSRV_PDUMP_IS_RECORDING_SHIFT (4)
#define PVRSRV_PDUMP_IS_RECORDING (1U << PVRSRV_PDUMP_IS_RECORDING_SHIFT)
/* Flag to be passed over the bridge during connection stating SVM allocation availability */
#define PVRSRV_DEVMEM_SVM_ALLOC_SHIFT (8)
#define PVRSRV_DEVMEM_SVM_ALLOC_UNSUPPORTED (1U << PVRSRV_DEVMEM_SVM_ALLOC_SHIFT)
#define PVRSRV_DEVMEM_SVM_ALLOC_SUPPORTED (2U << PVRSRV_DEVMEM_SVM_ALLOC_SHIFT)
#define PVRSRV_DEVMEM_SVM_ALLOC_CANFAIL (4U << PVRSRV_DEVMEM_SVM_ALLOC_SHIFT)
/* Flag to be passed over the bridge during connection stating whether GPU uses FBCDC v3.1 */
#define PVRSRV_FBCDC_V3_1_USED_SHIFT (11)
#define PVRSRV_FBCDC_V3_1_USED (1U << PVRSRV_FBCDC_V3_1_USED_SHIFT)
static INLINE IMG_HANDLE GetBridgeHandle(SHARED_DEV_CONNECTION hDevConnection)
{
#if defined(__KERNEL__)
return hDevConnection;
#else
return hDevConnection->hServices;
#endif
}
#endif /* !defined(DEVICE_CONNECTION_H) */
@@ -0,0 +1,729 @@
/*************************************************************************/ /*!
@File
@Title Device Memory Management core internal
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Services internal interface to core device memory management
functions that are shared between client and server code.
@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 SRVCLIENT_DEVICEMEM_H
#define SRVCLIENT_DEVICEMEM_H
/******************************************************************************
* *
* +------------+ +------------+ +--------------+ +--------------+ *
* | a sub- | | a sub- | | an | | allocation | *
* | allocation | | allocation | | allocation | | also mapped | *
* | | | | | in proc 1 | | into proc 2 | *
* +------------+ +------------+ +--------------+ +--------------+ *
* | | | | *
* +--------------+ +--------------+ +--------------+ *
* | page gran- | | page gran- | | page gran- | *
* | ular mapping | | ular mapping | | ular mapping | *
* +--------------+ +--------------+ +--------------+ *
* | | | *
* | | | *
* | | | *
* +--------------+ +--------------+ *
* | | | | *
* | A "P.M.R." | | A "P.M.R." | *
* | | | | *
* +--------------+ +--------------+ *
* *
******************************************************************************/
/*
All device memory allocations are ultimately a view upon (not
necessarily the whole of) a "PMR".
A PMR is a "Physical Memory Resource", which may be a
"pre-faulted" lump of physical memory, or it may be a
representation of some physical memory that will be instantiated
at some future time.
PMRs always represent multiple of some power-of-2 "contiguity"
promised by the PMR, which will allow them to be mapped in whole
pages into the device MMU. As memory allocations may be smaller
than a page, these mappings may be suballocated and thus shared
between multiple allocations in one process. A PMR may also be
mapped simultaneously into multiple device memory contexts
(cross-process scenario), however, for security reasons, it is not
legal to share a PMR "both ways" at once, that is, mapped into
multiple processes and divided up amongst several suballocations.
This PMR terminology is introduced here for background
information, but is generally of little concern to the caller of
this API. This API handles suballocations and mappings, and the
caller thus deals primarily with MEMORY DESCRIPTORS representing
an allocation or suballocation, HEAPS representing ranges of
virtual addresses in a CONTEXT.
*/
/*
|<---------------------------context------------------------------>|
|<-------heap------->| |<-------heap------->|<-------heap------->|
|<-alloc->| | |<-alloc->|<-alloc->|| |<-alloc->| |
*/
#include "img_types.h"
#include "img_defs.h"
#include "devicemem_typedefs.h"
#include "pdumpdefs.h"
#include "pvrsrv_error.h"
#include "pvrsrv_memallocflags.h"
#include "pdump.h"
#include "device_connection.h"
typedef IMG_UINT32 DEVMEM_HEAPCFGID;
#define DEVMEM_HEAPCFG_FORCLIENTS 0
#define DEVMEM_HEAPCFG_META 1
/*
In order to call the server side functions, we need a bridge handle.
We abstract that here, as we may wish to change its form.
*/
typedef IMG_HANDLE DEVMEM_BRIDGE_HANDLE;
/*************************************************************************/ /*!
@Function DevmemUnpin
@Description This is the counterpart to DevmemPin(). It is meant to be
called before repinning an allocation.
For a detailed description see client API documentation.
@Input phMemDesc The MemDesc that is going to be unpinned.
@Return PVRSRV_ERROR: PVRSRV_OK on success and the memory is
registered to be reclaimed. Error otherwise.
*/ /**************************************************************************/
IMG_INTERNAL PVRSRV_ERROR
DevmemUnpin(DEVMEM_MEMDESC *psMemDesc);
/*************************************************************************/ /*!
@Function DevmemPin
@Description This is the counterpart to DevmemUnpin(). It is meant to be
called after unpinning an allocation.
For a detailed description see client API documentation.
@Input phMemDesc The MemDesc that is going to be pinned.
@Return PVRSRV_ERROR: PVRSRV_OK on success and the allocation content
was successfully restored.
PVRSRV_ERROR_PMR_NEW_MEMORY when the content
could not be restored and new physical memory
was allocated.
A different error otherwise.
*/ /**************************************************************************/
IMG_INTERNAL PVRSRV_ERROR
DevmemPin(DEVMEM_MEMDESC *psMemDesc);
IMG_INTERNAL PVRSRV_ERROR
DevmemGetHeapInt(DEVMEM_HEAP *psHeap,
IMG_HANDLE *phDevmemHeap);
IMG_INTERNAL PVRSRV_ERROR
DevmemGetSize(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_SIZE_T* puiSize);
IMG_INTERNAL void
DevmemGetAnnotation(DEVMEM_MEMDESC *psMemDesc,
IMG_CHAR **pszAnnotation);
/*
* DevmemCreateContext()
*
* Create a device memory context
*
* This must be called before any heap is created in this context
*
* Caller to provide bridge handle which will be recorded internally and used
* for all future operations on items from this memory context. Caller also
* to provide devicenode handle, as this is used for MMU configuration and
* also to determine the heap configuration for the auto-instantiated heaps.
*
* Note that when compiled in services/server, the hBridge is not used and
* is thrown away by the "fake" direct bridge. (This may change. It is
* recommended that NULL be passed for the handle for now.)
*
* hDeviceNode and uiHeapBlueprintID shall together dictate which heap-config
* to use.
*
* This will cause the server side counterpart to be created also.
*
* If you call DevmemCreateContext() (and the call succeeds) you are promising
* that you will later call Devmem_ContextDestroy(), except for abnormal
* process termination in which case it is expected it will be destroyed as
* part of handle clean up.
*
* Caller to provide storage for the pointer to the newly created
* NEWDEVMEM_CONTEXT object.
*/
PVRSRV_ERROR
DevmemCreateContext(SHARED_DEV_CONNECTION hDevConnection,
DEVMEM_HEAPCFGID uiHeapBlueprintID,
DEVMEM_CONTEXT **ppsCtxPtr);
/*
* DevmemAcquireDevPrivData()
*
* Acquire the device private data for this memory context
*/
PVRSRV_ERROR
DevmemAcquireDevPrivData(DEVMEM_CONTEXT *psCtx,
IMG_HANDLE *hPrivData);
/*
* DevmemReleaseDevPrivData()
*
* Release the device private data for this memory context
*/
PVRSRV_ERROR
DevmemReleaseDevPrivData(DEVMEM_CONTEXT *psCtx);
/*
* DevmemDestroyContext()
*
* Undoes that done by DevmemCreateContext()
*/
PVRSRV_ERROR
DevmemDestroyContext(DEVMEM_CONTEXT *psCtx);
/*
* DevmemCreateHeap()
*
* Create a heap in the given context.
*
* N.B. Not intended to be called directly, though it can be.
* Normally, heaps are instantiated at context creation time according
* to the specified blueprint. See DevmemCreateContext() for details.
*
* This will cause MMU code to set up data structures for the heap,
* but may not cause page tables to be modified until allocations are
* made from the heap.
*
* uiReservedRegionLength Reserved address space for static VAs shared
* between clients and firmware
*
* The "Quantum" is both the device MMU page size to be configured for
* this heap, and the unit multiples of which "quantized" allocations
* are made (allocations smaller than this, known as "suballocations"
* will be made from a "sub alloc RA" and will "import" chunks
* according to this quantum)
*
* Where imported PMRs (or, for example, PMRs created by device class
* buffers) are mapped into this heap, it is important that the
* physical contiguity guarantee offered by the PMR is greater than or
* equal to the quantum size specified here, otherwise the attempt to
* map it will fail. "Normal" allocations via Devmem_Allocate
* shall automatically meet this requirement, as each "import" will
* trigger the creation of a PMR with the desired contiguity. The
* supported quantum sizes in that case shall be dictated by the OS
* specific implementation of PhysmemNewOSRamBackedPMR() (see)
*/
PVRSRV_ERROR
DevmemCreateHeap(DEVMEM_CONTEXT *psCtxPtr,
/* base and length of heap */
IMG_DEV_VIRTADDR sBaseAddress,
IMG_DEVMEM_SIZE_T uiLength,
IMG_DEVMEM_SIZE_T uiReservedRegionLength,
/* log2 of allocation quantum, i.e. "page" size.
All allocations (that go to server side) are
multiples of this. We use a client-side RA to
make sub-allocations from this */
IMG_UINT32 ui32Log2Quantum,
/* The minimum import alignment for this heap */
IMG_UINT32 ui32Log2ImportAlignment,
/* Name of heap for debug */
/* N.B. Okay to exist on caller's stack - this
func takes a copy if it needs it. */
const IMG_CHAR *pszName,
DEVMEM_HEAPCFGID uiHeapBlueprintID,
DEVMEM_HEAP **ppsHeapPtr);
/*
* DevmemDestroyHeap()
*
* Reverses DevmemCreateHeap()
*
* N.B. All allocations must have been freed and all mappings must
* have been unmapped before invoking this call
*/
PVRSRV_ERROR
DevmemDestroyHeap(DEVMEM_HEAP *psHeap);
/*
* DevmemExportalignAdjustSizeAndAlign()
* Compute the Size and Align passed to avoid suballocations
* (used when allocation with PVRSRV_MEMALLOCFLAG_EXPORTALIGN).
*
* Returns PVRSRV_ERROR_INVALID_PARAMS if uiLog2Quantum has invalid value.
*/
IMG_INTERNAL PVRSRV_ERROR
DevmemExportalignAdjustSizeAndAlign(IMG_UINT32 uiLog2Quantum,
IMG_DEVMEM_SIZE_T *puiSize,
IMG_DEVMEM_ALIGN_T *puiAlign);
/*
* DevmemSubAllocate()
*
* Makes an allocation (possibly a "suballocation", as described
* below) of device virtual memory from this heap.
*
* The size and alignment of the allocation will be honoured by the RA
* that allocates the "suballocation". The resulting allocation will
* be mapped into GPU virtual memory and the physical memory to back
* it will exist, by the time this call successfully completes.
*
* The size must be a positive integer multiple of the alignment.
* (i.e. the alignment specifies the alignment of both the start and
* the end of the resulting allocation.)
*
* Allocations made via this API are routed through a "suballocation
* RA" which is responsible for ensuring that small allocations can be
* made without wasting physical memory in the server. Furthermore,
* such suballocations can be made entirely client side without
* needing to go to the server unless the allocation spills into a new
* page.
*
* Such suballocations cause many allocations to share the same "PMR".
* This happens only when the flags match exactly.
*
*/
PVRSRV_ERROR
DevmemSubAllocate(IMG_UINT8 uiPreAllocMultiplier,
DEVMEM_HEAP *psHeap,
IMG_DEVMEM_SIZE_T uiSize,
IMG_DEVMEM_ALIGN_T uiAlign,
DEVMEM_FLAGS_T uiFlags,
const IMG_CHAR *pszText,
DEVMEM_MEMDESC **ppsMemDescPtr);
#define DevmemAllocate(...) \
DevmemSubAllocate(DEVMEM_NO_PRE_ALLOCATE_MULTIPLIER, __VA_ARGS__)
PVRSRV_ERROR
DevmemAllocateExportable(SHARED_DEV_CONNECTION hDevConnection,
IMG_DEVMEM_SIZE_T uiSize,
IMG_DEVMEM_ALIGN_T uiAlign,
IMG_UINT32 uiLog2HeapPageSize,
DEVMEM_FLAGS_T uiFlags,
const IMG_CHAR *pszText,
DEVMEM_MEMDESC **ppsMemDescPtr);
PVRSRV_ERROR
DeviceMemChangeSparse(DEVMEM_MEMDESC *psMemDesc,
IMG_UINT32 ui32AllocPageCount,
IMG_UINT32 *paui32AllocPageIndices,
IMG_UINT32 ui32FreePageCount,
IMG_UINT32 *pauiFreePageIndices,
SPARSE_MEM_RESIZE_FLAGS uiFlags);
PVRSRV_ERROR
DevmemAllocateSparse(SHARED_DEV_CONNECTION hDevConnection,
IMG_DEVMEM_SIZE_T uiSize,
IMG_DEVMEM_SIZE_T uiChunkSize,
IMG_UINT32 ui32NumPhysChunks,
IMG_UINT32 ui32NumVirtChunks,
IMG_UINT32 *pui32MappingTable,
IMG_DEVMEM_ALIGN_T uiAlign,
IMG_UINT32 uiLog2HeapPageSize,
DEVMEM_FLAGS_T uiFlags,
const IMG_CHAR *pszText,
DEVMEM_MEMDESC **ppsMemDescPtr);
PVRSRV_ERROR
DevmemSubAllocateAndMap(IMG_UINT8 uiPreAllocMultiplier,
DEVMEM_HEAP *psHeap,
IMG_DEVMEM_SIZE_T uiSize,
IMG_DEVMEM_ALIGN_T uiAlign,
DEVMEM_FLAGS_T uiFlags,
const IMG_CHAR *pszText,
DEVMEM_MEMDESC **ppsMemDescPtr,
IMG_DEV_VIRTADDR *psDevVirtAddr);
#define DevmemAllocateAndMap(...) \
DevmemSubAllocateAndMap(DEVMEM_NO_PRE_ALLOCATE_MULTIPLIER, __VA_ARGS__)
/*
* DevmemFree()
*
* Reverses that done by DevmemSubAllocate() N.B. The underlying
* mapping and server side allocation _may_ not be torn down, for
* example, if the allocation has been exported, or if multiple
* allocations were suballocated from the same mapping, but this is
* properly refcounted, so the caller does not have to care.
*/
IMG_BOOL
DevmemFree(DEVMEM_MEMDESC *psMemDesc);
IMG_BOOL
DevmemReleaseDevAddrAndFree(DEVMEM_MEMDESC *psMemDesc);
/*
DevmemMapToDevice:
Map an allocation to the device it was allocated from.
This function _must_ be called before any call to
DevmemAcquireDevVirtAddr is made as it binds the allocation
to the heap.
DevmemReleaseDevVirtAddr is used to release the reference
to the device mapping this function created, but it doesn't
mean that the memory will actually be unmapped from the
device as other references to the mapping obtained via
DevmemAcquireDevVirtAddr could still be active.
*/
PVRSRV_ERROR DevmemMapToDevice(DEVMEM_MEMDESC *psMemDesc,
DEVMEM_HEAP *psHeap,
IMG_DEV_VIRTADDR *psDevVirtAddr);
/*
DevmemMapToDeviceAddress:
Same as DevmemMapToDevice but the caller chooses the address
to map to.
*/
IMG_INTERNAL PVRSRV_ERROR
DevmemMapToDeviceAddress(DEVMEM_MEMDESC *psMemDesc,
DEVMEM_HEAP *psHeap,
IMG_DEV_VIRTADDR sDevVirtAddr);
/*
DevmemGetDevVirtAddr
Obtain the MemDesc's device virtual address.
This function _must_ be called after DevmemMapToDevice(Address)
and is expected to be used be functions which didn't allocate
the MemDesc but need to know it's address.
It will PVR_ASSERT if no device mapping exists and 0 is returned.
*/
IMG_DEV_VIRTADDR
DevmemGetDevVirtAddr(DEVMEM_MEMDESC *psMemDesc);
/*
DevmemAcquireDevVirtAddr
Acquire the MemDesc's device virtual address.
This function _must_ be called after DevmemMapToDevice
and is expected to be used be functions which didn't allocate
the MemDesc but need to know it's address
*/
PVRSRV_ERROR DevmemAcquireDevVirtAddr(DEVMEM_MEMDESC *psMemDesc,
IMG_DEV_VIRTADDR *psDevVirtAddrRet);
/*
* DevmemReleaseDevVirtAddr()
*
* give up the licence to use the device virtual address that was
* acquired by "Acquire" or "MapToDevice"
*/
void
DevmemReleaseDevVirtAddr(DEVMEM_MEMDESC *psMemDesc);
/*
* DevmemAcquireCpuVirtAddr()
*
* Acquires a license to use the cpu virtual address of this mapping.
* Note that the memory may not have been mapped into cpu virtual
* memory prior to this call. On first "acquire" the memory will be
* mapped in (if it wasn't statically mapped in) and on last put it
* _may_ become unmapped. Later calling "Acquire" again, _may_ cause
* the memory to be mapped at a different address.
*/
PVRSRV_ERROR DevmemAcquireCpuVirtAddr(DEVMEM_MEMDESC *psMemDesc,
void **ppvCpuVirtAddr);
/*
* DevmemReacquireCpuVirtAddr()
*
* (Re)acquires license to use the cpu virtual address of this mapping
* if (and only if) there is already a pre-existing license to use the
* cpu virtual address for the mapping, returns NULL otherwise.
*/
void DevmemReacquireCpuVirtAddr(DEVMEM_MEMDESC *psMemDesc,
void **ppvCpuVirtAddr);
/*
* DevmemReleaseDevVirtAddr()
*
* give up the licence to use the cpu virtual address that was granted
* with the "Get" call.
*/
void
DevmemReleaseCpuVirtAddr(DEVMEM_MEMDESC *psMemDesc);
#if defined(SUPPORT_INSECURE_EXPORT)
/*
* DevmemExport()
*
* Given a memory allocation allocated with DevmemAllocateExportable()
* create a "cookie" that can be passed intact by the caller's own choice
* of secure IPC to another process and used as the argument to "map"
* to map this memory into a heap in the target processes. N.B. This can
* also be used to map into multiple heaps in one process, though that's not
* the intention.
*
* Note, the caller must later call Unexport before freeing the
* memory.
*/
PVRSRV_ERROR DevmemExport(DEVMEM_MEMDESC *psMemDesc,
DEVMEM_EXPORTCOOKIE *psExportCookie);
void DevmemUnexport(DEVMEM_MEMDESC *psMemDesc,
DEVMEM_EXPORTCOOKIE *psExportCookie);
PVRSRV_ERROR
DevmemImport(SHARED_DEV_CONNECTION hDevConnection,
DEVMEM_EXPORTCOOKIE *psCookie,
DEVMEM_FLAGS_T uiFlags,
DEVMEM_MEMDESC **ppsMemDescPtr);
#endif /* SUPPORT_INSECURE_EXPORT */
/*
* DevmemMakeLocalImportHandle()
*
* This is a "special case" function for making a server export cookie
* which went through the direct bridge into an export cookie that can
* be passed through the client bridge.
*/
PVRSRV_ERROR
DevmemMakeLocalImportHandle(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hServerExport,
IMG_HANDLE *hClientExport);
/*
* DevmemUnmakeLocalImportHandle()
*
* Free any resource associated with the Make operation
*/
PVRSRV_ERROR
DevmemUnmakeLocalImportHandle(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hClientExport);
/*
*
* The following set of functions is specific to the heap "blueprint"
* stuff, for automatic creation of heaps when a context is created
*
*/
/* Devmem_HeapConfigCount: returns the number of heap configs that
this device has. Note that there is no acquire/release semantics
required, as this data is guaranteed to be constant for the
lifetime of the device node */
PVRSRV_ERROR
DevmemHeapConfigCount(SHARED_DEV_CONNECTION hDevConnection,
IMG_UINT32 *puiNumHeapConfigsOut);
/* Devmem_HeapCount: returns the number of heaps that a given heap
config on this device has. Note that there is no acquire/release
semantics required, as this data is guaranteed to be constant for
the lifetime of the device node */
PVRSRV_ERROR
DevmemHeapCount(SHARED_DEV_CONNECTION hDevConnection,
IMG_UINT32 uiHeapConfigIndex,
IMG_UINT32 *puiNumHeapsOut);
/* Devmem_HeapConfigName: return the name of the given heap config.
The caller is to provide the storage for the returned string and
indicate the number of bytes (including null terminator) for such
string in the BufSz arg. Note that there is no acquire/release
semantics required, as this data is guaranteed to be constant for
the lifetime of the device node.
*/
PVRSRV_ERROR
DevmemHeapConfigName(SHARED_DEV_CONNECTION hsDevConnection,
IMG_UINT32 uiHeapConfigIndex,
IMG_CHAR *pszConfigNameOut,
IMG_UINT32 uiConfigNameBufSz);
/* Devmem_HeapDetails: fetches all the metadata that is recorded in
this heap "blueprint". Namely: heap name (caller to provide
storage, and indicate buffer size (including null terminator) in
BufSz arg), device virtual address and length, log2 of data page
size (will be one of 12, 14, 16, 18, 20, 21, at time of writing).
Note that there is no acquire/release semantics required, as this
data is guaranteed to be constant for the lifetime of the device
node. */
PVRSRV_ERROR
DevmemHeapDetails(SHARED_DEV_CONNECTION hDevConnection,
IMG_UINT32 uiHeapConfigIndex,
IMG_UINT32 uiHeapIndex,
IMG_CHAR *pszHeapNameOut,
IMG_UINT32 uiHeapNameBufSz,
IMG_DEV_VIRTADDR *psDevVAddrBaseOut,
IMG_DEVMEM_SIZE_T *puiHeapLengthOut,
IMG_DEVMEM_SIZE_T *puiReservedRegionLengthOut,
IMG_UINT32 *puiLog2DataPageSize,
IMG_UINT32 *puiLog2ImportAlignmentOut);
/*
* Devmem_FindHeapByName()
*
* returns the heap handle for the named _automagic_ heap in this
* context. "automagic" heaps are those that are born with the
* context from a blueprint
*/
PVRSRV_ERROR
DevmemFindHeapByName(const DEVMEM_CONTEXT *psCtx,
const IMG_CHAR *pszHeapName,
DEVMEM_HEAP **ppsHeapRet);
/*
* DevmemGetHeapBaseDevVAddr()
*
* returns the device virtual address of the base of the heap.
*/
PVRSRV_ERROR
DevmemGetHeapBaseDevVAddr(DEVMEM_HEAP *psHeap,
IMG_DEV_VIRTADDR *pDevVAddr);
PVRSRV_ERROR
DevmemLocalGetImportHandle(DEVMEM_MEMDESC *psMemDesc,
IMG_HANDLE *phImport);
PVRSRV_ERROR
DevmemGetImportUID(DEVMEM_MEMDESC *psMemDesc,
IMG_UINT64 *pui64UID);
PVRSRV_ERROR
DevmemGetReservation(DEVMEM_MEMDESC *psMemDesc,
IMG_HANDLE *hReservation);
IMG_INTERNAL PVRSRV_ERROR
DevmemGetPMRData(DEVMEM_MEMDESC *psMemDesc,
IMG_HANDLE *hPMR,
IMG_DEVMEM_OFFSET_T *puiPMROffset);
IMG_INTERNAL void
DevmemGetFlags(DEVMEM_MEMDESC *psMemDesc,
DEVMEM_FLAGS_T *puiFlags);
IMG_INTERNAL SHARED_DEV_CONNECTION
DevmemGetConnection(DEVMEM_MEMDESC *psMemDesc);
PVRSRV_ERROR
DevmemLocalImport(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hExtHandle,
DEVMEM_FLAGS_T uiFlags,
DEVMEM_MEMDESC **ppsMemDescPtr,
IMG_DEVMEM_SIZE_T *puiSizePtr,
const IMG_CHAR *pszAnnotation);
IMG_INTERNAL PVRSRV_ERROR
DevmemIsDevVirtAddrValid(DEVMEM_CONTEXT *psContext,
IMG_DEV_VIRTADDR sDevVAddr);
IMG_INTERNAL PVRSRV_ERROR
DevmemGetFaultAddress(DEVMEM_CONTEXT *psContext,
IMG_DEV_VIRTADDR *psFaultAddress);
IMG_INTERNAL PVRSRV_ERROR
DevmemFlushDeviceSLCRange(DEVMEM_MEMDESC *psMemDesc,
IMG_DEV_VIRTADDR sDevVAddr,
IMG_DEVMEM_SIZE_T uiSize,
IMG_BOOL bInvalidate);
IMG_INTERNAL PVRSRV_ERROR
DevmemInvalidateFBSCTable(DEVMEM_CONTEXT *psContext,
IMG_UINT64 ui64FBSCEntries);
/* DevmemGetHeapLog2PageSize()
*
* Get the page size used for a certain heap.
*/
IMG_UINT32
DevmemGetHeapLog2PageSize(DEVMEM_HEAP *psHeap);
/*************************************************************************/ /*!
@Function RegisterDevMemPFNotify
@Description Registers that the application wants to be signaled when a page
fault occurs.
@Input psContext Memory context the process that would like to
be notified about.
@Input ui32PID The PID of the calling process.
@Input bRegister If true, register. If false, de-register.
@Return PVRSRV_ERROR: PVRSRV_OK on success. Otherwise, a PVRSRV_
error code
*/ /**************************************************************************/
IMG_INTERNAL PVRSRV_ERROR
RegisterDevmemPFNotify(DEVMEM_CONTEXT *psContext,
IMG_UINT32 ui32PID,
IMG_BOOL bRegister);
/*************************************************************************/ /*!
@Function GetMaxDevMemSize
@Description Get the amount of device memory on current platform
(memory size in Bytes)
@Output puiLMASize LMA memory size
@Output puiUMASize UMA memory size
@Return Error code
*/ /**************************************************************************/
IMG_INTERNAL PVRSRV_ERROR
GetMaxDevMemSize(SHARED_DEV_CONNECTION hDevConnection,
IMG_DEVMEM_SIZE_T *puiLMASize,
IMG_DEVMEM_SIZE_T *puiUMASize);
/*************************************************************************/ /*!
@Function DevmemHeapSetPremapStatus
@Description In some special cases like virtualisation, a device memory heap
must be entirely backed by physical memory and mapped into the
device's virtual address space. This is done at context creation.
When objects are allocated from such a heap, the mapping part
must be skipped. The 'bPremapped' flag dictates if allocations
are to be mapped or not.
@Input psHeap Device memory heap to be updated
@Input IsPremapped The premapping status to be set
*/ /**************************************************************************/
IMG_INTERNAL void
DevmemHeapSetPremapStatus(DEVMEM_HEAP *psHeap, IMG_BOOL IsPremapped);
#endif /* #ifndef SRVCLIENT_DEVICEMEM_H */
@@ -0,0 +1,363 @@
/*************************************************************************/ /*!
@File
@Title Device Memory Management PDump internal
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Services internal interface to PDump device memory management
functions that are shared between client and server code.
@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 DEVICEMEM_PDUMP_H
#define DEVICEMEM_PDUMP_H
#include "devicemem.h"
#include "pdumpdefs.h"
#include "pdump.h"
#if defined(PDUMP)
/*
* DevmemPDumpLoadMem()
*
* takes a memory descriptor, offset, and size, and takes the current contents
* of the memory at that location and writes it to the prm pdump file, and
* emits a pdump LDB to load the data from that file. The intention here is
* that the contents of the simulated buffer upon pdump playback will be made
* to be the same as they are when this command is run, enabling pdump of
* cases where the memory has been modified externally, i.e. by the host cpu
* or by a third party.
*/
void
DevmemPDumpLoadMem(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_DEVMEM_SIZE_T uiSize,
PDUMP_FLAGS_T uiPDumpFlags);
/*
* DevmemPDumpLoadZeroMem()
*
* As DevmemPDumpLoadMem() but the PDump allocation will be populated with
* zeros from the zero page in the parameter stream
*/
void
DevmemPDumpLoadZeroMem(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_DEVMEM_SIZE_T uiSize,
PDUMP_FLAGS_T uiPDumpFlags);
/*
* DevmemPDumpLoadMemValue32()
*
* As above but dumps the value at a dword-aligned address in plain text to
* the pdump script2 file. Useful for patching a buffer at pdump playback by
* simply editing the script output file.
*
* (The same functionality can be achieved by the above function but the
* binary PARAM file must be patched in that case.)
*/
IMG_INTERNAL void
DevmemPDumpLoadMemValue32(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_UINT32 ui32Value,
PDUMP_FLAGS_T uiPDumpFlags);
/*
* DevmemPDumpMemValue64()
*
* As above but dumps the 64bit-value at a dword-aligned address in plain text
* to the pdump script2 file. Useful for patching a buffer at pdump playback by
* simply editing the script output file.
*
* (The same functionality can be achieved by the above function but the
* binary PARAM file must be patched in that case.)
*/
IMG_INTERNAL void
DevmemPDumpLoadMemValue64(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_UINT64 ui64Value,
PDUMP_FLAGS_T uiPDumpFlags);
/*
* DevmemPDumpPageCatBaseToSAddr()
*
* Returns the symbolic address of a piece of memory represented by an offset
* into the mem descriptor.
*/
PVRSRV_ERROR
DevmemPDumpPageCatBaseToSAddr(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T *puiMemOffset,
IMG_CHAR *pszName,
IMG_UINT32 ui32Size);
/*
* DevmemPDumpSaveToFile()
*
* Emits a pdump SAB to cause the current contents of the memory to be written
* to the given file during playback
*/
void
DevmemPDumpSaveToFile(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_DEVMEM_SIZE_T uiSize,
const IMG_CHAR *pszFilename,
IMG_UINT32 uiFileOffset);
/*
* DevmemPDumpSaveToFileVirtual()
*
* Emits a pdump SAB, just like DevmemPDumpSaveToFile(), but uses the virtual
* address and device MMU context to cause the pdump player to traverse the
* MMU page tables itself.
*/
void
DevmemPDumpSaveToFileVirtual(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_DEVMEM_SIZE_T uiSize,
const IMG_CHAR *pszFilename,
IMG_UINT32 ui32FileOffset,
IMG_UINT32 ui32PdumpFlags);
/*
* DevmemPDumpDataDescriptor()
*
* Emits a pdump CMD:OutputData, using the virtual address and device MMU
* context. Provides more flexibility than a pdump SAB because metadata can
* be passed to an external pdump player library via the command header.
*/
void
DevmemPDumpDataDescriptor(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_DEVMEM_SIZE_T uiSize,
const IMG_CHAR *pszFilename,
IMG_UINT32 ui32HeaderType,
IMG_UINT32 ui32ElementType,
IMG_UINT32 ui32ElementCount,
IMG_UINT32 ui32PdumpFlags);
/*
*
* DevmemPDumpDevmemPol32()
*
* Writes a PDump 'POL' command to wait for a masked 32-bit memory location to
* become the specified value.
*/
PVRSRV_ERROR
DevmemPDumpDevmemPol32(const DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_UINT32 ui32Value,
IMG_UINT32 ui32Mask,
PDUMP_POLL_OPERATOR eOperator,
PDUMP_FLAGS_T ui32PDumpFlags);
#if defined(__KERNEL__)
/*
*
* DevmemPDumpDevmemCheck32()
*
* Writes a PDump 'POL' command to run a single-shot check for a masked
* 32-bit memory location to match the specified value.
*/
PVRSRV_ERROR
DevmemPDumpDevmemCheck32(const DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_UINT32 ui32Value,
IMG_UINT32 ui32Mask,
PDUMP_POLL_OPERATOR eOperator,
PDUMP_FLAGS_T ui32PDumpFlags);
#endif
/*
* DevmemPDumpCBP()
*
* Polls for space in circular buffer. Reads the read offset from memory and
* waits until there is enough space to write the packet.
*
* psMemDesc - MemDesc which contains the read offset
* uiReadOffset - Offset into MemDesc to the read offset
* uiWriteOffset - Current write offset
* uiPacketSize - Size of packet to write
* uiBufferSize - Size of circular buffer
*/
PVRSRV_ERROR
DevmemPDumpCBP(const DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiReadOffset,
IMG_DEVMEM_OFFSET_T uiWriteOffset,
IMG_DEVMEM_SIZE_T uiPacketSize,
IMG_DEVMEM_SIZE_T uiBufferSize);
#else /* PDUMP */
#ifdef INLINE_IS_PRAGMA
#pragma inline(DevmemPDumpLoadMem)
#endif
static INLINE void
DevmemPDumpLoadMem(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_DEVMEM_SIZE_T uiSize,
PDUMP_FLAGS_T uiPDumpFlags)
{
PVR_UNREFERENCED_PARAMETER(psMemDesc);
PVR_UNREFERENCED_PARAMETER(uiOffset);
PVR_UNREFERENCED_PARAMETER(uiSize);
PVR_UNREFERENCED_PARAMETER(uiPDumpFlags);
}
#ifdef INLINE_IS_PRAGMA
#pragma inline(DevmemPDumpLoadMemValue32)
#endif
static INLINE void
DevmemPDumpLoadMemValue32(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_UINT32 ui32Value,
PDUMP_FLAGS_T uiPDumpFlags)
{
PVR_UNREFERENCED_PARAMETER(psMemDesc);
PVR_UNREFERENCED_PARAMETER(uiOffset);
PVR_UNREFERENCED_PARAMETER(ui32Value);
PVR_UNREFERENCED_PARAMETER(uiPDumpFlags);
}
#ifdef INLINE_IS_PRAGMA
#pragma inline(DevmemPDumpLoadMemValue64)
#endif
static INLINE void
DevmemPDumpLoadMemValue64(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_UINT64 ui64Value,
PDUMP_FLAGS_T uiPDumpFlags)
{
PVR_UNREFERENCED_PARAMETER(psMemDesc);
PVR_UNREFERENCED_PARAMETER(uiOffset);
PVR_UNREFERENCED_PARAMETER(ui64Value);
PVR_UNREFERENCED_PARAMETER(uiPDumpFlags);
}
#ifdef INLINE_IS_PRAGMA
#pragma inline(DevmemPDumpPageCatBaseToSAddr)
#endif
static INLINE PVRSRV_ERROR
DevmemPDumpPageCatBaseToSAddr(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T *puiMemOffset,
IMG_CHAR *pszName,
IMG_UINT32 ui32Size)
{
PVR_UNREFERENCED_PARAMETER(psMemDesc);
PVR_UNREFERENCED_PARAMETER(puiMemOffset);
PVR_UNREFERENCED_PARAMETER(pszName);
PVR_UNREFERENCED_PARAMETER(ui32Size);
return PVRSRV_OK;
}
#ifdef INLINE_IS_PRAGMA
#pragma inline(DevmemPDumpSaveToFile)
#endif
static INLINE void
DevmemPDumpSaveToFile(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_DEVMEM_SIZE_T uiSize,
const IMG_CHAR *pszFilename,
IMG_UINT32 uiFileOffset)
{
PVR_UNREFERENCED_PARAMETER(psMemDesc);
PVR_UNREFERENCED_PARAMETER(uiOffset);
PVR_UNREFERENCED_PARAMETER(uiSize);
PVR_UNREFERENCED_PARAMETER(pszFilename);
PVR_UNREFERENCED_PARAMETER(uiFileOffset);
}
#ifdef INLINE_IS_PRAGMA
#pragma inline(DevmemPDumpSaveToFileVirtual)
#endif
static INLINE void
DevmemPDumpSaveToFileVirtual(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_DEVMEM_SIZE_T uiSize,
const IMG_CHAR *pszFilename,
IMG_UINT32 ui32FileOffset,
IMG_UINT32 ui32PdumpFlags)
{
PVR_UNREFERENCED_PARAMETER(psMemDesc);
PVR_UNREFERENCED_PARAMETER(uiOffset);
PVR_UNREFERENCED_PARAMETER(uiSize);
PVR_UNREFERENCED_PARAMETER(pszFilename);
PVR_UNREFERENCED_PARAMETER(ui32FileOffset);
PVR_UNREFERENCED_PARAMETER(ui32PdumpFlags);
}
#ifdef INLINE_IS_PRAGMA
#pragma inline(DevmemPDumpDevmemPol32)
#endif
static INLINE PVRSRV_ERROR
DevmemPDumpDevmemPol32(const DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_UINT32 ui32Value,
IMG_UINT32 ui32Mask,
PDUMP_POLL_OPERATOR eOperator,
PDUMP_FLAGS_T ui32PDumpFlags)
{
PVR_UNREFERENCED_PARAMETER(psMemDesc);
PVR_UNREFERENCED_PARAMETER(uiOffset);
PVR_UNREFERENCED_PARAMETER(ui32Value);
PVR_UNREFERENCED_PARAMETER(ui32Mask);
PVR_UNREFERENCED_PARAMETER(eOperator);
PVR_UNREFERENCED_PARAMETER(ui32PDumpFlags);
return PVRSRV_OK;
}
#ifdef INLINE_IS_PRAGMA
#pragma inline(DevmemPDumpCBP)
#endif
static INLINE PVRSRV_ERROR
DevmemPDumpCBP(const DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiReadOffset,
IMG_DEVMEM_OFFSET_T uiWriteOffset,
IMG_DEVMEM_SIZE_T uiPacketSize,
IMG_DEVMEM_SIZE_T uiBufferSize)
{
PVR_UNREFERENCED_PARAMETER(psMemDesc);
PVR_UNREFERENCED_PARAMETER(uiReadOffset);
PVR_UNREFERENCED_PARAMETER(uiWriteOffset);
PVR_UNREFERENCED_PARAMETER(uiPacketSize);
PVR_UNREFERENCED_PARAMETER(uiBufferSize);
return PVRSRV_OK;
}
#endif /* PDUMP */
#endif /* DEVICEMEM_PDUMP_H */
@@ -0,0 +1,513 @@
/*************************************************************************/ /*!
@File
@Title Device Memory Management internal utility functions
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Utility functions used internally by device memory management
code.
@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 DEVICEMEM_UTILS_H
#define DEVICEMEM_UTILS_H
#include "devicemem.h"
#include "img_types.h"
#include "pvrsrv_error.h"
#include "pvr_debug.h"
#include "allocmem.h"
#include "ra.h"
#include "osfunc.h"
#include "lock.h"
#include "osmmap.h"
#define DEVMEM_HEAPNAME_MAXLENGTH 160
#if defined(DEVMEM_DEBUG) && defined(REFCOUNT_DEBUG)
#define DEVMEM_REFCOUNT_PRINT(fmt, ...) PVRSRVDebugPrintf(PVR_DBG_ERROR, __FILE__, __LINE__, fmt, __VA_ARGS__)
#else
#define DEVMEM_REFCOUNT_PRINT(fmt, ...)
#endif
/* If we need a "hMapping" but we don't have a server-side mapping, we poison
* the entry with this value so that it's easily recognised in the debugger.
* Note that this is potentially a valid handle, but then so is NULL, which is
* no better, indeed worse, as it's not obvious in the debugger. The value
* doesn't matter. We _never_ use it (and because it's valid, we never assert
* it isn't this) but it's nice to have a value in the source code that we can
* grep for if things go wrong.
*/
#define LACK_OF_MAPPING_POISON ((IMG_HANDLE)0x6116dead)
#define LACK_OF_RESERVATION_POISON ((IMG_HANDLE)0x7117dead)
#define DEVICEMEM_HISTORY_ALLOC_INDEX_NONE 0xFFFFFFFF
struct DEVMEM_CONTEXT_TAG
{
SHARED_DEV_CONNECTION hDevConnection;
/* Number of heaps that have been created in this context
* (regardless of whether they have allocations)
*/
IMG_UINT32 uiNumHeaps;
/* Each "DEVMEM_CONTEXT" has a counterpart in the server, which
* is responsible for handling the mapping into device MMU.
* We have a handle to that here.
*/
IMG_HANDLE hDevMemServerContext;
/* Number of automagically created heaps in this context,
* i.e. those that are born at context creation time from the
* chosen "heap config" or "blueprint"
*/
IMG_UINT32 uiAutoHeapCount;
/* Pointer to array of such heaps */
struct DEVMEM_HEAP_TAG **ppsAutoHeapArray;
/* The cache line size for use when allocating memory,
* as it is not queryable on the client side
*/
IMG_UINT32 ui32CPUCacheLineSize;
/* Private data handle for device specific data */
IMG_HANDLE hPrivData;
};
/* Flag that allows the heap to be marked as user or RA managed
* at the time of first map.*/
#define DEVMEM_HEAP_MANAGER_UNKNOWN 0
/* User managed heap. Management of this heap is out of services scope */
#define DEVMEM_HEAP_MANAGER_USER (1U << 0)
/* Heap explicitly managed by services server module */
#define DEVMEM_HEAP_MANAGER_KERNEL (1U << 1)
/* Heap managed by resource allocator */
#define DEVMEM_HEAP_MANAGER_RA (1U << 2)
/* Heaps managed by the resource allocator and the user
* The reserved regions of the heap are managed explicitly by user
* The non-reserved region of the heap is managed by the RA */
#define DEVMEM_HEAP_MANAGER_DUAL_USER_RA (DEVMEM_HEAP_MANAGER_USER | DEVMEM_HEAP_MANAGER_RA)
struct DEVMEM_HEAP_TAG
{
/* Name of heap - for debug and lookup purposes. */
IMG_CHAR *pszName;
/* Number of live imports in the heap */
ATOMIC_T hImportCount;
/* Base address and size of heap, required by clients due to some
* requesters not being full range
*/
IMG_DEV_VIRTADDR sBaseAddress;
DEVMEM_SIZE_T uiSize;
DEVMEM_SIZE_T uiReservedRegionSize; /* uiReservedRegionLength in DEVMEM_HEAP_BLUEPRINT */
/* The heap manager, describing if the space is managed by the user, an RA,
* kernel or combination */
IMG_UINT32 ui32HeapManagerFlags;
/* This RA is for managing sub-allocations within the imports (PMRs)
* within the heap's virtual space. RA only used in DevmemSubAllocate()
* to track sub-allocated buffers.
*
* Resource Span - a PMR import added when the RA calls the
* imp_alloc CB (SubAllocImportAlloc) which returns the
* PMR import and size (span length).
* Resource - an allocation/buffer i.e. a MemDesc. Resource size represents
* the size of the sub-allocation.
*/
RA_ARENA *psSubAllocRA;
IMG_CHAR *pszSubAllocRAName;
/* The psQuantizedVMRA is for the coarse allocation (PMRs) of virtual
* space from the heap.
*
* Resource Span - the heap's VM space from base to base+length,
* only one is added at heap creation.
* Resource - a PMR import associated with the heap. Dynamic number
* as memory is allocated/freed from or mapped/unmapped to
* the heap. Resource size follows PMR logical size.
*/
RA_ARENA *psQuantizedVMRA;
IMG_CHAR *pszQuantizedVMRAName;
/* We also need to store a copy of the quantum size in order to feed
* this down to the server.
*/
IMG_UINT32 uiLog2Quantum;
/* Store a copy of the minimum import alignment */
IMG_UINT32 uiLog2ImportAlignment;
/* The relationship between tiled heap alignment and heap byte-stride
* (dependent on tiling mode, abstracted here)
*/
IMG_UINT32 uiLog2TilingStrideFactor;
/* The parent memory context for this heap */
struct DEVMEM_CONTEXT_TAG *psCtx;
/* Lock to protect this structure */
POS_LOCK hLock;
/* Each "DEVMEM_HEAP" has a counterpart in the server, which is
* responsible for handling the mapping into device MMU.
* We have a handle to that here.
*/
IMG_HANDLE hDevMemServerHeap;
/* This heap is fully allocated and premapped into the device address space.
* Used in virtualisation for firmware heaps of Guest and optionally Host drivers. */
IMG_BOOL bPremapped;
};
typedef IMG_UINT32 DEVMEM_PROPERTIES_T; /*!< Typedef for Devicemem properties */
#define DEVMEM_PROPERTIES_EXPORTABLE (1UL<<0) /*!< Is it exportable? */
#define DEVMEM_PROPERTIES_IMPORTED (1UL<<1) /*!< Is it imported from another process? */
#define DEVMEM_PROPERTIES_SUBALLOCATABLE (1UL<<2) /*!< Is it suballocatable? */
#define DEVMEM_PROPERTIES_UNPINNED (1UL<<3) /*!< Is it currently pinned? */
#define DEVMEM_PROPERTIES_IMPORT_IS_ZEROED (1UL<<4) /*!< Is the memory fully zeroed? */
#define DEVMEM_PROPERTIES_IMPORT_IS_CLEAN (1UL<<5) /*!< Is the memory clean, i.e. not been used before? */
#define DEVMEM_PROPERTIES_SECURE (1UL<<6) /*!< Is it a special secure buffer? No CPU maps allowed! */
#define DEVMEM_PROPERTIES_IMPORT_IS_POISONED (1UL<<7) /*!< Is the memory fully poisoned? */
#define DEVMEM_PROPERTIES_NO_CPU_MAPPING (1UL<<8) /* No CPU Mapping is allowed, RW attributes
are further derived from allocation memory flags */
#define DEVMEM_PROPERTIES_NO_LAYOUT_CHANGE (1UL<<9) /* No sparse resizing allowed, once a memory
layout is chosen, no change allowed later,
This includes pinning and unpinning */
typedef struct DEVMEM_DEVICE_IMPORT_TAG
{
DEVMEM_HEAP *psHeap; /*!< Heap this import is bound to */
IMG_DEV_VIRTADDR sDevVAddr; /*!< Device virtual address of the import */
IMG_UINT32 ui32RefCount; /*!< Refcount of the device virtual address */
IMG_HANDLE hReservation; /*!< Device memory reservation handle */
IMG_HANDLE hMapping; /*!< Device mapping handle */
IMG_BOOL bMapped; /*!< This is import mapped? */
POS_LOCK hLock; /*!< Lock to protect the device import */
} DEVMEM_DEVICE_IMPORT;
typedef struct DEVMEM_CPU_IMPORT_TAG
{
void *pvCPUVAddr; /*!< CPU virtual address of the import */
IMG_UINT32 ui32RefCount; /*!< Refcount of the CPU virtual address */
IMG_HANDLE hOSMMapData; /*!< CPU mapping handle */
POS_LOCK hLock; /*!< Lock to protect the CPU import */
} DEVMEM_CPU_IMPORT;
typedef struct DEVMEM_IMPORT_TAG
{
SHARED_DEV_CONNECTION hDevConnection;
IMG_DEVMEM_ALIGN_T uiAlign; /*!< Alignment of the PMR */
DEVMEM_SIZE_T uiSize; /*!< Size of import */
ATOMIC_T hRefCount; /*!< Refcount for this import */
DEVMEM_PROPERTIES_T uiProperties; /*!< Stores properties of an import like if
it is exportable, pinned or suballocatable */
IMG_HANDLE hPMR; /*!< Handle to the PMR */
DEVMEM_FLAGS_T uiFlags; /*!< Flags for this import */
POS_LOCK hLock; /*!< Lock to protect the import */
DEVMEM_DEVICE_IMPORT sDeviceImport; /*!< Device specifics of the import */
DEVMEM_CPU_IMPORT sCPUImport; /*!< CPU specifics of the import */
} DEVMEM_IMPORT;
typedef struct DEVMEM_DEVICE_MEMDESC_TAG
{
IMG_DEV_VIRTADDR sDevVAddr; /*!< Device virtual address of the allocation */
IMG_UINT32 ui32RefCount; /*!< Refcount of the device virtual address */
POS_LOCK hLock; /*!< Lock to protect device memdesc */
} DEVMEM_DEVICE_MEMDESC;
typedef struct DEVMEM_CPU_MEMDESC_TAG
{
void *pvCPUVAddr; /*!< CPU virtual address of the import */
IMG_UINT32 ui32RefCount; /*!< Refcount of the device CPU address */
POS_LOCK hLock; /*!< Lock to protect CPU memdesc */
} DEVMEM_CPU_MEMDESC;
struct DEVMEM_MEMDESC_TAG
{
DEVMEM_IMPORT *psImport; /*!< Import this memdesc is on */
IMG_DEVMEM_OFFSET_T uiOffset; /*!< Offset into import where our allocation starts */
IMG_DEVMEM_SIZE_T uiAllocSize; /*!< Size of the allocation */
ATOMIC_T hRefCount; /*!< Refcount of the memdesc */
POS_LOCK hLock; /*!< Lock to protect memdesc */
IMG_HANDLE hPrivData;
DEVMEM_DEVICE_MEMDESC sDeviceMemDesc; /*!< Device specifics of the memdesc */
DEVMEM_CPU_MEMDESC sCPUMemDesc; /*!< CPU specifics of the memdesc */
IMG_CHAR szText[DEVMEM_ANNOTATION_MAX_LEN]; /*!< Annotation for this memdesc */
IMG_UINT32 ui32AllocationIndex;
#if defined(PVRSRV_ENABLE_GPU_MEMORY_INFO)
IMG_HANDLE hRIHandle; /*!< Handle to RI information */
#endif
};
/* The physical descriptor used to store handles and information of device
* physical allocations.
*/
struct DEVMEMX_PHYS_MEMDESC_TAG
{
IMG_UINT32 uiNumPages; /*!< Number of pages that the import has*/
IMG_UINT32 uiLog2PageSize; /*!< Page size */
ATOMIC_T hRefCount; /*!< Refcount of the memdesc */
DEVMEM_FLAGS_T uiFlags; /*!< Flags for this import */
IMG_HANDLE hPMR; /*!< Handle to the PMR */
DEVMEM_CPU_IMPORT sCPUImport; /*!< CPU specifics of the memdesc */
DEVMEM_BRIDGE_HANDLE hBridge; /*!< Bridge connection for the server */
};
/* The virtual descriptor used to store handles and information of a device
* virtual range and the mappings to it.
*/
struct DEVMEMX_VIRT_MEMDESC_TAG
{
IMG_UINT32 uiNumPages; /*!< Number of pages that the import has*/
DEVMEM_FLAGS_T uiFlags; /*!< Flags for this import */
DEVMEMX_PHYSDESC **apsPhysDescTable; /*!< Table to store links to physical descs */
DEVMEM_DEVICE_IMPORT sDeviceImport; /*!< Device specifics of the memdesc */
IMG_CHAR szText[DEVMEM_ANNOTATION_MAX_LEN]; /*!< Annotation for this virt memdesc */
IMG_UINT32 ui32AllocationIndex; /*!< To track mappings in this range */
#if defined(PVRSRV_ENABLE_GPU_MEMORY_INFO)
IMG_HANDLE hRIHandle; /*!< Handle to RI information */
#endif
};
#define DEVICEMEM_UTILS_NO_ADDRESS 0
/******************************************************************************
@Function DevmemValidateParams
@Description Check if flags are conflicting and if align is a size multiple.
@Input uiSize Size of the import.
@Input uiAlign Alignment of the import.
@Input puiFlags Pointer to the flags for the import.
@return PVRSRV_ERROR
******************************************************************************/
PVRSRV_ERROR DevmemValidateParams(IMG_DEVMEM_SIZE_T uiSize,
IMG_DEVMEM_ALIGN_T uiAlign,
DEVMEM_FLAGS_T *puiFlags);
/******************************************************************************
@Function DevmemImportStructAlloc
@Description Allocates memory for an import struct. Does not allocate a PMR!
Create locks for CPU and Devmem mappings.
@Input hDevConnection Connection to use for calls from the import.
@Input ppsImport The import to allocate.
@return PVRSRV_ERROR
******************************************************************************/
PVRSRV_ERROR DevmemImportStructAlloc(SHARED_DEV_CONNECTION hDevConnection,
DEVMEM_IMPORT **ppsImport);
/******************************************************************************
@Function DevmemImportStructInit
@Description Initialises the import struct with the given parameters.
Set it's refcount to 1!
@Input psImport The import to initialise.
@Input uiSize Size of the import.
@Input uiAlign Alignment of allocations in the import.
@Input uiMapFlags
@Input hPMR Reference to the PMR of this import struct.
@Input uiProperties Properties of the import. Is it exportable,
imported, suballocatable, unpinned?
******************************************************************************/
void DevmemImportStructInit(DEVMEM_IMPORT *psImport,
IMG_DEVMEM_SIZE_T uiSize,
IMG_DEVMEM_ALIGN_T uiAlign,
PVRSRV_MEMALLOCFLAGS_T uiMapFlags,
IMG_HANDLE hPMR,
DEVMEM_PROPERTIES_T uiProperties);
/******************************************************************************
@Function DevmemImportStructDevMap
@Description NEVER call after the last DevmemMemDescRelease()
Maps the PMR referenced by the import struct to the device's
virtual address space.
Does nothing but increase the cpu mapping refcount if the
import struct was already mapped.
@Input psHeap The heap to map to.
@Input bMap Caller can choose if the import should be really
mapped in the page tables or if just a virtual range
should be reserved and the refcounts increased.
@Input psImport The import we want to map.
@Input uiOptionalMapAddress An optional address to map to.
Pass DEVICEMEM_UTILS_NOADDRESS if not used.
@return PVRSRV_ERROR
******************************************************************************/
PVRSRV_ERROR DevmemImportStructDevMap(DEVMEM_HEAP *psHeap,
IMG_BOOL bMap,
DEVMEM_IMPORT *psImport,
IMG_UINT64 uiOptionalMapAddress);
/******************************************************************************
@Function DevmemImportStructDevUnmap
@Description Unmaps the PMR referenced by the import struct from the
device's virtual address space.
If this was not the last remaining CPU mapping on the import
struct only the cpu mapping refcount is decreased.
@return A boolean to signify if the import was unmapped.
******************************************************************************/
IMG_BOOL DevmemImportStructDevUnmap(DEVMEM_IMPORT *psImport);
/******************************************************************************
@Function DevmemImportStructCPUMap
@Description NEVER call after the last DevmemMemDescRelease()
Maps the PMR referenced by the import struct to the CPU's
virtual address space.
Does nothing but increase the cpu mapping refcount if the
import struct was already mapped.
@return PVRSRV_ERROR
******************************************************************************/
PVRSRV_ERROR DevmemImportStructCPUMap(DEVMEM_IMPORT *psImport);
/******************************************************************************
@Function DevmemImportStructCPUUnmap
@Description Unmaps the PMR referenced by the import struct from the CPU's
virtual address space.
If this was not the last remaining CPU mapping on the import
struct only the cpu mapping refcount is decreased.
******************************************************************************/
void DevmemImportStructCPUUnmap(DEVMEM_IMPORT *psImport);
/******************************************************************************
@Function DevmemImportStructAcquire
@Description Acquire an import struct by increasing it's refcount.
******************************************************************************/
void DevmemImportStructAcquire(DEVMEM_IMPORT *psImport);
/******************************************************************************
@Function DevmemImportStructRelease
@Description Reduces the refcount of the import struct.
Destroys the import in the case it was the last reference.
Destroys underlying PMR if this import was the last reference
to it.
@return A boolean to signal if the import was destroyed. True = yes.
******************************************************************************/
IMG_BOOL DevmemImportStructRelease(DEVMEM_IMPORT *psImport);
/******************************************************************************
@Function DevmemImportDiscard
@Description Discard a created, but unitilised import structure.
This must only be called before DevmemImportStructInit
after which DevmemImportStructRelease must be used to
"free" the import structure.
******************************************************************************/
void DevmemImportDiscard(DEVMEM_IMPORT *psImport);
/******************************************************************************
@Function DevmemMemDescAlloc
@Description Allocates a MemDesc and create it's various locks.
Zero the allocated memory.
@return PVRSRV_ERROR
******************************************************************************/
PVRSRV_ERROR DevmemMemDescAlloc(DEVMEM_MEMDESC **ppsMemDesc);
/******************************************************************************
@Function DevmemMemDescInit
@Description Sets the given offset and import struct fields in the MemDesc.
Initialises refcount to 1 and other values to 0.
@Input psMemDesc MemDesc to initialise.
@Input uiOffset Offset in the import structure.
@Input psImport Import the MemDesc is on.
@Input uiAllocSize Size of the allocation
******************************************************************************/
void DevmemMemDescInit(DEVMEM_MEMDESC *psMemDesc,
IMG_DEVMEM_OFFSET_T uiOffset,
DEVMEM_IMPORT *psImport,
IMG_DEVMEM_SIZE_T uiAllocSize);
/******************************************************************************
@Function DevmemMemDescAcquire
@Description Acquires the MemDesc by increasing it's refcount.
******************************************************************************/
void DevmemMemDescAcquire(DEVMEM_MEMDESC *psMemDesc);
/******************************************************************************
@Function DevmemMemDescRelease
@Description Releases the MemDesc by reducing it's refcount.
Destroy the MemDesc if it's recount is 0.
Destroy the import struct the MemDesc is on if that was the
last MemDesc on the import, probably following the destruction
of the underlying PMR.
@return A boolean to signal if the MemDesc was destroyed. True = yes.
******************************************************************************/
IMG_BOOL DevmemMemDescRelease(DEVMEM_MEMDESC *psMemDesc);
/******************************************************************************
@Function DevmemMemDescDiscard
@Description Discard a created, but uninitialised MemDesc structure.
This must only be called before DevmemMemDescInit after
which DevmemMemDescRelease must be used to "free" the
MemDesc structure.
******************************************************************************/
void DevmemMemDescDiscard(DEVMEM_MEMDESC *psMemDesc);
/******************************************************************************
@Function GetImportProperties
@Description Atomically read psImport->uiProperties
It's possible that another thread modifies uiProperties
immediately after this function returns, making its result
stale. So, it's recommended to use this function only to
check if certain non-volatile flags were set.
******************************************************************************/
static INLINE DEVMEM_PROPERTIES_T GetImportProperties(DEVMEM_IMPORT *psImport)
{
DEVMEM_PROPERTIES_T uiProperties;
OSLockAcquire(psImport->hLock);
uiProperties = psImport->uiProperties;
OSLockRelease(psImport->hLock);
return uiProperties;
}
#endif /* DEVICEMEM_UTILS_H */
@@ -0,0 +1,217 @@
/*************************************************************************/ /*!
@File
@Title X Device Memory Management core internal
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Internal interface for extended device memory 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.
*/ /**************************************************************************/
#ifndef DEVICEMEMX_H
#define DEVICEMEMX_H
#include "img_types.h"
#include "devicemem_typedefs.h"
#include "devicemem_utils.h"
#include "pdumpdefs.h"
#include "pvrsrv_error.h"
#include "pvrsrv_memallocflags.h"
#include "osfunc.h"
/* DevmemXAllocPhysical()
*
* Allocate physical device memory and return a physical
* descriptor for it.
*/
PVRSRV_ERROR
DevmemXAllocPhysical(DEVMEM_CONTEXT *psCtx,
IMG_UINT32 uiNumPages,
IMG_UINT32 uiLog2PageSize,
DEVMEM_FLAGS_T uiFlags,
const IMG_CHAR *pszText,
DEVMEMX_PHYSDESC **ppsPhysDesc);
/* DevmemXReleasePhysical()
*
* Removes a physical device allocation if all references
* to it are dropped, otherwise just decreases the refcount.
*/
void
DevmemXReleasePhysical(DEVMEMX_PHYSDESC *psPhysDesc);
/* DevmemAllocVirtualAddr()
*
* Reserve a requested device virtual range and return
* a virtual descriptor for it.
*/
IMG_INTERNAL PVRSRV_ERROR
DevmemXAllocVirtualAddr(DEVMEM_HEAP* hHeap,
IMG_UINT32 uiNumPages,
DEVMEM_FLAGS_T uiFlags,
const IMG_CHAR *pszText,
IMG_DEV_VIRTADDR sVirtAddr,
DEVMEMX_VIRTDESC **ppsVirtDesc);
/* DevmemAllocVirtual()
*
* Allocate and reserve a device virtual range and return
* a virtual descriptor for it.
*/
PVRSRV_ERROR
DevmemXAllocVirtual(DEVMEM_HEAP* hHeap,
IMG_UINT32 uiNumPages,
DEVMEM_FLAGS_T uiFlags,
const IMG_CHAR *pszText,
DEVMEMX_VIRTDESC **ppsVirtDesc,
IMG_DEV_VIRTADDR *psVirtAddr);
/* DevmemXFreeVirtual()
*
* Removes a device virtual range if all mappings on it
* have been removed.
*/
PVRSRV_ERROR
DevmemXFreeVirtual(DEVMEMX_VIRTDESC *psVirtDesc);
/* DevmemXMapVirtualRange()
*
* Map memory from a physical descriptor into a virtual range.
*/
PVRSRV_ERROR
DevmemXMapVirtualRange(IMG_UINT32 ui32PageCount,
DEVMEMX_PHYSDESC *psPhysDesc,
IMG_UINT32 ui32PhysOffset,
DEVMEMX_VIRTDESC *psVirtDesc,
IMG_UINT32 ui32VirtOffset);
/* DevmemXUnmapVirtualRange()
*
* Unmap pages from a device virtual range.
*/
PVRSRV_ERROR
DevmemXUnmapVirtualRange(IMG_UINT32 ui32PageCount,
DEVMEMX_VIRTDESC *psVirtDesc,
IMG_UINT32 ui32VirtPgOffset);
/* DevmemXMapPhysicalToCPU()
*
* Map a full physical descriptor to CPU space.
*/
PVRSRV_ERROR
DevmemXMapPhysicalToCPU(DEVMEMX_PHYSDESC *psMemAllocPhys,
IMG_CPU_VIRTADDR *psVirtAddr);
/* DevmemXUnmapPhysicalToCPU()
*
* Remove the CPU mapping from the descriptor.
*/
PVRSRV_ERROR
DevmemXUnmapPhysicalToCPU(DEVMEMX_PHYSDESC *psMemAllocPhys);
/* DevmemXReacquireCpuVirtAddr()
*
* Reacquire the CPU mapping by incrementing the refcount.
*/
void
DevmemXReacquireCpuVirtAddr(DEVMEMX_PHYSDESC *psPhysDesc,
void **ppvCpuVirtAddr);
/* DevmemXReleaseCpuVirtAddr()
*
* Release CPU mapping by decrementing the refcount.
*/
void
DevmemXReleaseCpuVirtAddr(DEVMEMX_PHYSDESC *psPhysDesc);
/* DevmemXCreateDevmemMemDescVA()
*
* (Deprecated)
*
* Create a devmem memdesc from a virtual address.
* Always destroy with DevmemXFreeDevmemMemDesc().
*/
PVRSRV_ERROR
DevmemXCreateDevmemMemDescVA(const IMG_DEV_VIRTADDR sVirtualAddress,
DEVMEM_MEMDESC **ppsMemDesc);
/* DevmemXCreateDevmemMemDesc()
*
* Create a devmem memdesc from a physical and
* virtual descriptor.
* Always destroy with DevmemXFreeDevmemMemDesc().
*/
PVRSRV_ERROR
DevmemXCreateDevmemMemDesc(DEVMEMX_PHYSDESC *psPhysDesc,
DEVMEMX_VIRTDESC *psVirtDesc,
DEVMEM_MEMDESC **ppsMemDesc);
/* DevmemXFreeDevmemMemDesc()
*
* Free the memdesc again. Has no impact on the underlying
* physical and virtual descriptors.
*/
PVRSRV_ERROR
DevmemXFreeDevmemMemDesc(DEVMEM_MEMDESC *psMemDesc);
PVRSRV_ERROR
DevmemXFlagCompatibilityCheck(IMG_UINT32 uiPhysFlags,
IMG_UINT32 uiVirtFlags);
PVRSRV_ERROR
DevmemXPhysDescAlloc(DEVMEMX_PHYSDESC **ppsPhysDesc);
void
DevmemXPhysDescInit(DEVMEMX_PHYSDESC *psPhysDesc,
IMG_HANDLE hPMR,
IMG_UINT32 uiNumPages,
IMG_UINT32 uiLog2PageSize,
PVRSRV_MEMALLOCFLAGS_T uiFlags,
IMG_HANDLE hBridge);
void
DevmemXPhysDescFree(DEVMEMX_PHYSDESC *psPhysDesc);
void
DevmemXPhysDescAcquire(DEVMEMX_PHYSDESC *psPhysDesc,
IMG_UINT32 uiAcquireCount);
void
DevmemXPhysDescRelease(DEVMEMX_PHYSDESC *psPhysDesc,
IMG_UINT32 uiReleaseCount);
#endif /* DEVICEMEMX_H */
@@ -0,0 +1,81 @@
/*************************************************************************/ /*!
@File
@Title X Device Memory Management PDump internal
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Services internal interface to PDump device memory management
functions that are shared between client and server code.
@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 DEVICEMEMX_PDUMP_H
#define DEVICEMEMX_PDUMP_H
#include "devicememx.h"
#include "pdumpdefs.h"
#include "pdump.h"
#if defined(PDUMP)
/*
* DevmemXPDumpLoadMem()
*
* Same as DevmemPDumpLoadMem().
*/
IMG_INTERNAL void
DevmemXPDumpLoadMem(DEVMEMX_PHYSDESC *psMemDescPhys,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_DEVMEM_SIZE_T uiSize,
PDUMP_FLAGS_T uiPDumpFlags);
#else
#ifdef INLINE_IS_PRAGMA
#pragma inline(DevmemXPDumpLoadMem)
#endif
static INLINE void
DevmemXPDumpLoadMem(DEVMEMX_PHYSDESC *psMemDescPhys,
IMG_DEVMEM_OFFSET_T uiOffset,
IMG_DEVMEM_SIZE_T uiSize,
PDUMP_FLAGS_T uiPDumpFlags)
{
PVR_UNREFERENCED_PARAMETER(psMemDescPhys);
PVR_UNREFERENCED_PARAMETER(uiOffset);
PVR_UNREFERENCED_PARAMETER(uiSize);
PVR_UNREFERENCED_PARAMETER(uiPDumpFlags);
}
#endif /* PDUMP */
#endif /* DEVICEMEMX_PDUMP_H */
@@ -0,0 +1,246 @@
/*************************************************************************/ /*!
@File
@Title Self scaling hash tables
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Implements simple self scaling hash tables.
@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 _HASH_H_
#define _HASH_H_
#include "img_types.h"
#include "pvrsrv_error.h"
#if defined(__cplusplus)
extern "C" {
#endif
/*
* Keys passed to the comparison function are only guaranteed to be aligned on
* an uintptr_t boundary.
*/
typedef IMG_UINT32 HASH_FUNC(size_t uKeySize, void *pKey, IMG_UINT32 uHashTabLen);
typedef IMG_BOOL HASH_KEY_COMP(size_t uKeySize, void *pKey1, void *pKey2);
typedef struct _HASH_TABLE_ HASH_TABLE;
typedef PVRSRV_ERROR (*HASH_pfnCallback) (
uintptr_t k,
uintptr_t v
);
#if defined(DEBUG)
#else
#define HASH_CREATE(LEN) HASH_Create(LEN)
#endif
/*************************************************************************/ /*!
@Function HASH_Func_Default
@Description Hash function intended for hashing keys composed of uintptr_t
arrays.
@Input uKeySize The size of the hash key, in bytes.
@Input pKey A pointer to the key to hash.
@Input uHashTabLen The length of the hash table.
@Return The hash value.
*/ /**************************************************************************/
IMG_UINT32 HASH_Func_Default(size_t uKeySize, void *pKey, IMG_UINT32 uHashTabLen);
/*************************************************************************/ /*!
@Function HASH_Key_Comp_Default
@Description Compares keys composed of uintptr_t arrays.
@Input uKeySize The size of the hash key, in bytes.
@Input pKey1 Pointer to first hash key to compare.
@Input pKey2 Pointer to second hash key to compare.
@Return IMG_TRUE - The keys match.
IMG_FALSE - The keys don't match.
*/ /**************************************************************************/
IMG_BOOL HASH_Key_Comp_Default(size_t uKeySize, void *pKey1, void *pKey2);
/*************************************************************************/ /*!
@Function HASH_Create_Extended
@Description Create a self scaling hash table, using the supplied key size,
and the supplied hash and key comparison functions.
@Input uInitialLen Initial and minimum length of the hash table,
where the length refers to the number of entries
in the hash table, not its size in bytes.
@Input uKeySize The size of the key, in bytes.
@Input pfnHashFunc Pointer to hash function.
@Input pfnKeyComp Pointer to key comparison function.
@Return NULL or hash table handle.
*/ /**************************************************************************/
HASH_TABLE * HASH_Create_Extended_Int(IMG_UINT32 uInitialLen, size_t uKeySize, HASH_FUNC *pfnHashFunc, HASH_KEY_COMP *pfnKeyComp);
#if defined(DEBUG)
#define HASH_Create_Extended(LEN, KS, FUN, CMP) HASH_Create_Extended_Debug(LEN, KS, FUN, CMP, __FILE__, __LINE__)
HASH_TABLE * HASH_Create_Extended_Debug (IMG_UINT32 uInitialLen, size_t uKeySize, HASH_FUNC *pfnHashFunc, HASH_KEY_COMP *pfnKeyComp,
const char *file, const unsigned int line);
#else
#define HASH_Create_Extended HASH_Create_Extended_Int
#endif
/*************************************************************************/ /*!
@Function HASH_Create
@Description Create a self scaling hash table with a key consisting of a
single uintptr_t, and using the default hash and key
comparison functions.
@Input uInitialLen Initial and minimum length of the hash table,
where the length refers to the number of entries
in the hash table, not its size in bytes.
@Return NULL or hash table handle.
*/ /**************************************************************************/
HASH_TABLE * HASH_Create_Int(IMG_UINT32 uInitialLen);
#if defined(DEBUG)
#define HASH_Create(LEN) HASH_Create_Debug(LEN, __FILE__, __LINE__)
HASH_TABLE * HASH_Create_Debug (IMG_UINT32 uInitialLen, const char *file, const unsigned int line);
#else
#define HASH_Create HASH_Create_Int
#endif
/*************************************************************************/ /*!
@Function HASH_Delete_Extended
@Description Delete a hash table created by HASH_Create_Extended or
HASH_Create. All entries in the table should have been removed
before calling this function.
@Input pHash Hash table
@Input bWarn Set false to suppress warnings in the case of
deletion with active entries.
@Return None
*/ /**************************************************************************/
void HASH_Delete_Extended(HASH_TABLE *pHash, IMG_BOOL bWarn);
/*************************************************************************/ /*!
@Function HASH_Delete
@Description Delete a hash table created by HASH_Create_Extended or
HASH_Create. All entries in the table must have been removed
before calling this function.
@Input pHash Hash table
@Return None
*/ /**************************************************************************/
void HASH_Delete(HASH_TABLE *pHash);
/*************************************************************************/ /*!
@Function HASH_Insert_Extended
@Description Insert a key value pair into a hash table created with
HASH_Create_Extended.
@Input pHash The hash table.
@Input pKey Pointer to the key.
@Input v The value associated with the key.
@Return IMG_TRUE - success.
IMG_FALSE - failure.
*/ /**************************************************************************/
IMG_BOOL HASH_Insert_Extended(HASH_TABLE *pHash, void *pKey, uintptr_t v);
/*************************************************************************/ /*!
@Function HASH_Insert
@Description Insert a key value pair into a hash table created with
HASH_Create.
@Input pHash The hash table.
@Input k The key value.
@Input v The value associated with the key.
@Return IMG_TRUE - success.
IMG_FALSE - failure.
*/ /**************************************************************************/
IMG_BOOL HASH_Insert(HASH_TABLE *pHash, uintptr_t k, uintptr_t v);
/*************************************************************************/ /*!
@Function HASH_Remove_Extended
@Description Remove a key from a hash table created with
HASH_Create_Extended.
@Input pHash The hash table.
@Input pKey Pointer to key.
@Return 0 if the key is missing, or the value associated with the key.
*/ /**************************************************************************/
uintptr_t HASH_Remove_Extended(HASH_TABLE *pHash, void *pKey);
/*************************************************************************/ /*!
@Function HASH_Remove
@Description Remove a key value pair from a hash table created with
HASH_Create.
@Input pHash The hash table.
@Input k The key value.
@Return 0 if the key is missing, or the value associated with the key.
*/ /**************************************************************************/
uintptr_t HASH_Remove(HASH_TABLE *pHash, uintptr_t k);
/*************************************************************************/ /*!
@Function HASH_Retrieve_Extended
@Description Retrieve a value from a hash table created with
HASH_Create_Extended.
@Input pHash The hash table.
@Input pKey Pointer to key.
@Return 0 if the key is missing, or the value associated with the key.
*/ /**************************************************************************/
uintptr_t HASH_Retrieve_Extended(HASH_TABLE *pHash, void *pKey);
/*************************************************************************/ /*!
@Function HASH_Retrieve
@Description Retrieve a value from a hash table created with HASH_Create.
@Input pHash The hash table.
@Input k The key value.
@Return 0 if the key is missing, or the value associated with the key.
*/ /**************************************************************************/
uintptr_t HASH_Retrieve(HASH_TABLE *pHash, uintptr_t k);
/*************************************************************************/ /*!
@Function HASH_Iterate
@Description Iterate over every entry in the hash table.
@Input pHash Hash table to iterate.
@Input pfnCallback Callback to call with the key and data for each
. entry in the hash table
@Return Callback error if any, otherwise PVRSRV_OK
*/ /**************************************************************************/
PVRSRV_ERROR HASH_Iterate(HASH_TABLE *pHash, HASH_pfnCallback pfnCallback);
#ifdef HASH_TRACE
/*************************************************************************/ /*!
@Function HASH_Dump
@Description Dump out some information about a hash table.
@Input pHash The hash table.
*/ /**************************************************************************/
void HASH_Dump(HASH_TABLE *pHash);
#endif
#if defined(__cplusplus)
}
#endif
#endif /* _HASH_H_ */
/******************************************************************************
End of file (hash.h)
******************************************************************************/
@@ -0,0 +1,132 @@
/*************************************************************************/ /*!
@File htbuffer.h
@Title Host Trace Buffer shared API.
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Host Trace Buffer provides a mechanism to log Host events to a
buffer in a similar way to the Firmware Trace mechanism.
Host Trace Buffer logs data using a Transport Layer buffer.
The Transport Layer and pvrtld tool provides the mechanism to
retrieve the trace data.
@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 HTBUFFER_H
#define HTBUFFER_H
#if defined(__cplusplus)
extern "C" {
#endif
#include "img_types.h"
#include "img_defs.h"
#include "pvrsrv_error.h"
#include "htbuffer_sf.h"
#include "htbuffer_types.h"
#include "htbuffer_init.h"
#if defined(__KERNEL__)
#define HTBLOGK(SF, args...) do { if (HTB_GROUP_ENABLED(SF)) HTBLogSimple((IMG_HANDLE) NULL, SF, ## args); } while (0)
/* Host Trace Buffer name */
#define HTB_STREAM_NAME "PVRHTBuffer"
#else
#define HTBLOG(handle, SF, args...) do { if (HTB_GROUP_ENABLED(SF)) HTBLogSimple(handle, SF, ## args); } while (0)
#endif
/* macros to cast 64 or 32-bit pointers into 32-bit integer components for Host Trace */
#define HTBLOG_PTR_BITS_HIGH(p) ((IMG_UINT32)((((IMG_UINT64)((uintptr_t)p))>>32)&0xffffffff))
#define HTBLOG_PTR_BITS_LOW(p) ((IMG_UINT32)(((IMG_UINT64)((uintptr_t)p))&0xffffffff))
/* macros to cast 64-bit integers into 32-bit integer components for Host Trace */
#define HTBLOG_U64_BITS_HIGH(u) ((IMG_UINT32)((u>>32)&0xffffffff))
#define HTBLOG_U64_BITS_LOW(u) ((IMG_UINT32)(u&0xffffffff))
/*************************************************************************/ /*!
@Function HTBLog
@Description Record a Host Trace Buffer log event
@Input PID The PID of the process the event is associated
with. This is provided as an argument rather
than querying internally so that events associated
with a particular process, but performed by
another can be logged correctly.
@Input TimeStampus The timestamp in us for this event
@Input SF The log event ID
@Input ... Log parameters
@Return PVRSRV_OK Success.
*/ /**************************************************************************/
IMG_INTERNAL PVRSRV_ERROR
HTBLog(IMG_HANDLE hSrvHandle, IMG_UINT32 PID, IMG_UINT64 ui64TimeStampns, IMG_UINT32 SF, ...);
/*************************************************************************/ /*!
@Function HTBLogSimple
@Description Record a Host Trace Buffer log event with implicit PID and Timestamp
@Input SF The log event ID
@Input ... Log parameters
@Return PVRSRV_OK Success.
*/ /**************************************************************************/
IMG_INTERNAL PVRSRV_ERROR
HTBLogSimple(IMG_HANDLE hSrvHandle, IMG_UINT32 SF, ...);
/* DEBUG log group enable */
#if !defined(HTB_DEBUG_LOG_GROUP)
#undef HTB_LOG_TYPE_DBG /* No trace statements in this log group should be checked in */
#define HTB_LOG_TYPE_DBG __BUILDERROR__
#endif
#if defined(__cplusplus)
}
#endif
#endif /* HTBUFFER_H */
/*****************************************************************************
End of file (htbuffer.h)
*****************************************************************************/
@@ -0,0 +1,114 @@
/*************************************************************************/ /*!
@File htbuffer_init.h
@Title Host Trace Buffer functions needed for Services initialisation
@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 HTBUFFER_INIT_H
#define HTBUFFER_INIT_H
#if defined(__cplusplus)
extern "C" {
#endif
#include "img_types.h"
#include "img_defs.h"
/*************************************************************************/ /*!
@Function HTBConfigure
@Description Configure the Host Trace Buffer.
Once these parameters are set they may not be changed
@Input hSrvHandle Server Handle
@Input pszBufferName Name to use for the TL buffer, this will be
required to request trace data from the TL
@Input ui32BufferSize Requested TL buffer size in bytes
@Return eError Internal services call returned eError error
number
*/ /**************************************************************************/
IMG_INTERNAL PVRSRV_ERROR
HTBConfigure(
IMG_HANDLE hSrvHandle,
IMG_CHAR * pszBufferName,
IMG_UINT32 ui32BufferSize
);
/*************************************************************************/ /*!
@Function HTBControl
@Description Update the configuration of the Host Trace Buffer
@Input hSrvHandle Server Handle
@Input ui32NumFlagGroups Number of group enable flags words
@Input aui32GroupEnable Flags words controlling groups to be logged
@Input ui32LogLevel Log level to record
@Input ui32EnablePID PID to enable logging for a specific process
@Input eLogMode Enable logging for all or specific processes,
@Input eOpMode Control what trace data is dropped if the TL
buffer is full
@Return eError Internal services call returned eError error
number
*/ /**************************************************************************/
IMG_INTERNAL PVRSRV_ERROR
HTBControl(
IMG_HANDLE hSrvHandle,
IMG_UINT32 ui32NumFlagGroups,
IMG_UINT32 * aui32GroupEnable,
IMG_UINT32 ui32LogLevel,
IMG_UINT32 ui32EnablePID,
HTB_LOGMODE_CTRL eLogMode,
HTB_OPMODE_CTRL eOpMode
);
#if defined(__cplusplus)
}
#endif
#endif /* HTBUFFER_INIT_H */
/*****************************************************************************
End of file (htbuffer_init.h)
*****************************************************************************/
@@ -0,0 +1,430 @@
/*************************************************************************/ /*!
@File lock.h
@Title Locking interface
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Services internal locking interface
@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 LOCK_H
#define LOCK_H
/* In Linux kernel mode we are using the kernel mutex implementation directly
* with macros. This allows us to use the kernel lockdep feature for lock
* debugging. */
#include "lock_types.h"
#if defined(LINUX) && defined(__KERNEL__)
#include "allocmem.h"
#include <linux/atomic.h>
#include <linux/version.h>
#define OSLockCreateNoStats(phLock) ({ \
PVRSRV_ERROR e = PVRSRV_ERROR_OUT_OF_MEMORY; \
*(phLock) = OSAllocMemNoStats(sizeof(struct mutex)); \
if (*(phLock)) { mutex_init(*(phLock)); e = PVRSRV_OK; }; \
e;})
#define OSLockCreate(phLock) ({ \
PVRSRV_ERROR e = PVRSRV_ERROR_OUT_OF_MEMORY; \
*(phLock) = OSAllocMem(sizeof(struct mutex)); \
if (*(phLock)) { mutex_init(*(phLock)); e = PVRSRV_OK; }; \
e;})
#define OSLockDestroy(hLock) ({mutex_destroy((hLock)); OSFreeMem((hLock)); PVRSRV_OK;})
#define OSLockDestroyNoStats(hLock) ({mutex_destroy((hLock)); OSFreeMemNoStats((hLock)); PVRSRV_OK;})
#define OSLockAcquire(hLock) ({mutex_lock((hLock)); PVRSRV_OK;})
#define OSLockAcquireNested(hLock, subclass) ({mutex_lock_nested((hLock), (subclass)); PVRSRV_OK;})
#define OSLockRelease(hLock) ({mutex_unlock((hLock)); PVRSRV_OK;})
#define OSLockIsLocked(hLock) ((mutex_is_locked((hLock)) == 1) ? IMG_TRUE : IMG_FALSE)
#define OSTryLockAcquire(hLock) ((mutex_trylock(hLock) == 1) ? IMG_TRUE : IMG_FALSE)
#define OSSpinLockCreate(_ppsLock) ({ \
PVRSRV_ERROR e = PVRSRV_ERROR_OUT_OF_MEMORY; \
*(_ppsLock) = OSAllocMem(sizeof(spinlock_t)); \
if (*(_ppsLock)) {spin_lock_init(*(_ppsLock)); e = PVRSRV_OK;} \
e;})
#define OSSpinLockDestroy(_psLock) ({OSFreeMem(_psLock);})
typedef unsigned long OS_SPINLOCK_FLAGS;
#define OSSpinLockAcquire(_pLock, _flags) spin_lock_irqsave(_pLock, _flags)
#define OSSpinLockRelease(_pLock, _flags) spin_unlock_irqrestore(_pLock, _flags)
/* These _may_ be reordered or optimized away entirely by the compiler/hw */
#define OSAtomicRead(pCounter) atomic_read(pCounter)
#define OSAtomicWrite(pCounter, i) atomic_set(pCounter, i)
/* The following atomic operations, in addition to being SMP-safe, also
imply a memory barrier around the operation */
#define OSAtomicIncrement(pCounter) atomic_inc_return(pCounter)
#define OSAtomicDecrement(pCounter) atomic_dec_return(pCounter)
#define OSAtomicCompareExchange(pCounter, oldv, newv) atomic_cmpxchg(pCounter,oldv,newv)
#define OSAtomicExchange(pCounter, iNewVal) atomic_xchg(pCounter, iNewVal)
static inline IMG_INT OSAtomicOr(ATOMIC_T *pCounter, IMG_INT iVal)
{
IMG_INT iOldVal, iLastVal, iNewVal;
iLastVal = OSAtomicRead(pCounter);
do
{
iOldVal = iLastVal;
iNewVal = iOldVal | iVal;
iLastVal = OSAtomicCompareExchange(pCounter, iOldVal, iNewVal);
}
while (iOldVal != iLastVal);
return iNewVal;
}
#define OSAtomicAdd(pCounter, incr) atomic_add_return(incr,pCounter)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
#define OSAtomicAddUnless(pCounter, incr, test) atomic_fetch_add_unless(pCounter, (incr), (test))
#else
#define OSAtomicAddUnless(pCounter, incr, test) __atomic_add_unless(pCounter,incr,test)
#endif
#define OSAtomicSubtract(pCounter, incr) atomic_add_return(-(incr),pCounter)
#define OSAtomicSubtractUnless(pCounter, incr, test) OSAtomicAddUnless(pCounter, -(incr), (test))
#else /* defined(LINUX) && defined(__KERNEL__) */
#include "img_types.h"
#include "img_defs.h"
#include "pvrsrv_error.h"
/**************************************************************************/ /*!
@Function OSLockCreate
@Description Creates an operating system lock object.
@Output phLock The created lock.
@Return PVRSRV_OK on success. PVRSRV_ERROR_OUT_OF_MEMORY if the driver
cannot allocate CPU memory needed for the lock.
PVRSRV_ERROR_INIT_FAILURE if the Operating System fails to
allocate the lock.
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR OSLockCreate(POS_LOCK *phLock);
#if defined(INTEGRITY_OS)
#define OSLockCreateNoStats OSLockCreate
#endif
/**************************************************************************/ /*!
@Function OSLockDestroy
@Description Destroys an operating system lock object.
@Input hLock The lock to be destroyed.
@Return None.
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR OSLockDestroy(POS_LOCK hLock);
#if defined(INTEGRITY_OS)
#define OSLockDestroyNoStats OSLockDestroy
#endif
/**************************************************************************/ /*!
@Function OSLockAcquire
@Description Acquires an operating system lock.
NB. This function must not return until the lock is acquired
(meaning the implementation should not timeout or return with
an error, as the caller will assume they have the lock).
@Input hLock The lock to be acquired.
@Return None.
*/ /**************************************************************************/
IMG_INTERNAL
void OSLockAcquire(POS_LOCK hLock);
/**************************************************************************/ /*!
@Function OSTryLockAcquire
@Description Try to acquire an operating system lock.
NB. If lock is acquired successfully in the first attempt,
then the function returns true and else it will return false.
@Input hLock The lock to be acquired.
@Return IMG_TRUE if lock acquired successfully,
IMG_FALSE otherwise.
*/ /**************************************************************************/
IMG_INTERNAL
IMG_BOOL OSTryLockAcquire(POS_LOCK hLock);
/* Nested notation isn't used in UM or other OS's */
/**************************************************************************/ /*!
@Function OSLockAcquireNested
@Description For operating systems other than Linux, this equates to an
OSLockAcquire() call. On Linux, this function wraps a call
to mutex_lock_nested(). This recognises the scenario where
there may be multiple subclasses within a particular class
of lock. In such cases, the order in which the locks belonging
these various subclasses are acquired is important and must be
validated.
@Input hLock The lock to be acquired.
@Input subclass The subclass of the lock.
@Return None.
*/ /**************************************************************************/
#define OSLockAcquireNested(hLock, subclass) OSLockAcquire((hLock))
/**************************************************************************/ /*!
@Function OSLockRelease
@Description Releases an operating system lock.
@Input hLock The lock to be released.
@Return None.
*/ /**************************************************************************/
IMG_INTERNAL
void OSLockRelease(POS_LOCK hLock);
/**************************************************************************/ /*!
@Function OSLockIsLocked
@Description Tests whether or not an operating system lock is currently
locked.
@Input hLock The lock to be tested.
@Return IMG_TRUE if locked, IMG_FALSE if not locked.
*/ /**************************************************************************/
IMG_INTERNAL
IMG_BOOL OSLockIsLocked(POS_LOCK hLock);
#if defined(LINUX)
/* Use GCC intrinsics (read/write semantics consistent with kernel-side implementation) */
#define OSAtomicRead(pCounter) (*(volatile IMG_INT32 *)&(pCounter)->counter)
#define OSAtomicWrite(pCounter, i) ((pCounter)->counter = (IMG_INT32) i)
#define OSAtomicIncrement(pCounter) __sync_add_and_fetch((&(pCounter)->counter), 1)
#define OSAtomicDecrement(pCounter) __sync_sub_and_fetch((&(pCounter)->counter), 1)
#define OSAtomicCompareExchange(pCounter, oldv, newv) \
__sync_val_compare_and_swap((&(pCounter)->counter), oldv, newv)
#define OSAtomicOr(pCounter, iVal) __sync_or_and_fetch((&(pCounter)->counter), iVal)
static inline IMG_UINT32 OSAtomicExchange(ATOMIC_T *pCounter, IMG_UINT32 iNewVal)
{
IMG_UINT32 iOldVal;
IMG_UINT32 iLastVal;
iLastVal = OSAtomicRead(pCounter);
do
{
iOldVal = iLastVal;
iLastVal = OSAtomicCompareExchange(pCounter, iOldVal, iNewVal);
}
while (iOldVal != iLastVal);
return iOldVal;
}
#define OSAtomicAdd(pCounter, incr) __sync_add_and_fetch((&(pCounter)->counter), incr)
#define OSAtomicAddUnless(pCounter, incr, test) ({ \
IMG_INT32 c; IMG_INT32 old; \
c = OSAtomicRead(pCounter); \
while (1) { \
if (c == (test)) break; \
old = OSAtomicCompareExchange(pCounter, c, c+(incr)); \
if (old == c) break; \
c = old; \
} c; })
#define OSAtomicSubtract(pCounter, incr) OSAtomicAdd(pCounter, -(incr))
#define OSAtomicSubtractUnless(pCounter, incr, test) OSAtomicAddUnless(pCounter, -(incr), test)
#else
/*************************************************************************/ /*!
@Function OSAtomicRead
@Description Read the value of a variable atomically.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to read
@Return The value of the atomic variable
*/ /**************************************************************************/
IMG_INTERNAL
IMG_INT32 OSAtomicRead(const ATOMIC_T *pCounter);
/*************************************************************************/ /*!
@Function OSAtomicWrite
@Description Write the value of a variable atomically.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to be written to
@Input v The value to write
@Return None
*/ /**************************************************************************/
IMG_INTERNAL
void OSAtomicWrite(ATOMIC_T *pCounter, IMG_INT32 v);
/* For the following atomic operations, in addition to being SMP-safe,
should also have a memory barrier around each operation */
/*************************************************************************/ /*!
@Function OSAtomicIncrement
@Description Increment the value of a variable atomically.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to be incremented
@Return The new value of *pCounter.
*/ /**************************************************************************/
IMG_INTERNAL
IMG_INT32 OSAtomicIncrement(ATOMIC_T *pCounter);
/*************************************************************************/ /*!
@Function OSAtomicDecrement
@Description Decrement the value of a variable atomically.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to be decremented
@Return The new value of *pCounter.
*/ /**************************************************************************/
IMG_INTERNAL
IMG_INT32 OSAtomicDecrement(ATOMIC_T *pCounter);
/*************************************************************************/ /*!
@Function OSAtomicAdd
@Description Add a specified value to a variable atomically.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to add the value to
@Input v The value to be added
@Return The new value of *pCounter.
*/ /**************************************************************************/
IMG_INTERNAL
IMG_INT32 OSAtomicAdd(ATOMIC_T *pCounter, IMG_INT32 v);
/*************************************************************************/ /*!
@Function OSAtomicAddUnless
@Description Add a specified value to a variable atomically unless it
already equals a particular value.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to add the value to
@Input v The value to be added to 'pCounter'
@Input t The test value. If 'pCounter' equals this,
its value will not be adjusted
@Return The old value of *pCounter.
*/ /**************************************************************************/
IMG_INTERNAL
IMG_INT32 OSAtomicAddUnless(ATOMIC_T *pCounter, IMG_INT32 v, IMG_INT32 t);
/*************************************************************************/ /*!
@Function OSAtomicSubtract
@Description Subtract a specified value to a variable atomically.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to subtract the value from
@Input v The value to be subtracted
@Return The new value of *pCounter.
*/ /**************************************************************************/
IMG_INTERNAL
IMG_INT32 OSAtomicSubtract(ATOMIC_T *pCounter, IMG_INT32 v);
/*************************************************************************/ /*!
@Function OSAtomicSubtractUnless
@Description Subtract a specified value from a variable atomically unless
it already equals a particular value.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to subtract the value from
@Input v The value to be subtracted from 'pCounter'
@Input t The test value. If 'pCounter' equals this,
its value will not be adjusted
@Return The old value of *pCounter.
*/ /**************************************************************************/
IMG_INTERNAL
IMG_INT32 OSAtomicSubtractUnless(ATOMIC_T *pCounter, IMG_INT32 v, IMG_INT32 t);
/*************************************************************************/ /*!
@Function OSAtomicCompareExchange
@Description Set a variable to a given value only if it is currently
equal to a specified value. The whole operation must be atomic.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to be checked and
possibly updated
@Input oldv The value the atomic variable must have in
order to be modified
@Input newv The value to write to the atomic variable if
it equals 'oldv'
@Return The old value of *pCounter
*/ /**************************************************************************/
IMG_INTERNAL
IMG_INT32 OSAtomicCompareExchange(ATOMIC_T *pCounter, IMG_INT32 oldv, IMG_INT32 newv);
/*************************************************************************/ /*!
@Function OSAtomicExchange
@Description Set a variable to a given value and retrieve previous value.
The whole operation must be atomic.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to be updated
@Input iNewVal The value to write to the atomic variable
@Return The previous value of *pCounter.
*/ /**************************************************************************/
IMG_INTERNAL
IMG_INT32 OSAtomicExchange(ATOMIC_T *pCounter, IMG_INT32 iNewVal);
/*************************************************************************/ /*!
@Function OSAtomicOr
@Description Set a variable to the bitwise or of its current value and the
specified value. Equivalent to *pCounter |= iVal.
The whole operation must be atomic.
Atomic functions must be implemented in a manner that
is both symmetric multiprocessor (SMP) safe and has a memory
barrier around each operation.
@Input pCounter The atomic variable to be updated
@Input iVal The value to bitwise or against
@Return The new value of *pCounter.
*/ /**************************************************************************/
IMG_INTERNAL
IMG_INT32 OSAtomicOr(ATOMIC_T *pCounter, IMG_INT32 iVal);
/* For now, spin-locks are required on Linux only, so other platforms fake
* spinlocks with normal mutex locks */
typedef unsigned long OS_SPINLOCK_FLAGS;
#define POS_SPINLOCK POS_LOCK
#define OSSpinLockCreate(ppLock) OSLockCreate(ppLock)
#define OSSpinLockDestroy(pLock) OSLockDestroy(pLock)
#define OSSpinLockAcquire(pLock, flags) {flags = 0; OSLockAcquire(pLock);}
#define OSSpinLockRelease(pLock, flags) {flags = 0; OSLockRelease(pLock);}
#endif /* defined(LINUX) */
#endif /* defined(LINUX) && defined(__KERNEL__) */
#endif /* LOCK_H */
@@ -0,0 +1,115 @@
/*************************************************************************/ /*!
@File
@Title OS Interface for mapping PMRs into CPU space.
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description OS abstraction for the mmap2 interface for mapping PMRs into
User Mode memory
@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 OSMMAP_H
#define OSMMAP_H
#include <powervr/mem_types.h>
#include "img_types.h"
#include "pvrsrv_error.h"
/*************************************************************************/ /*!
@Function OSMMapPMR
@Description Maps the specified PMR into CPU memory so that it may be
accessed by the user process.
Whether the memory is mapped read only, read/write, or not at
all, is dependent on the PMR itself.
The PMR handle is opaque to the user, and lower levels of this
stack ensure that the handle is private to this process, such
that this API cannot be abused to gain access to other people's
PMRs. The OS implementation of this function should return the
virtual address and length for the User to use. The "PrivData"
is to be stored opaquely by the caller (N.B. he should make no
assumptions, in particular, NULL is a valid handle) and given
back to the call to OSMUnmapPMR.
The OS implementation is free to use the PrivData handle for
any purpose it sees fit.
@Input hBridge The bridge handle.
@Input hPMR The handle of the PMR to be mapped.
@Input uiPMRLength The size of the PMR.
@Input uiFlags Flags indicating how the mapping should
be done (read-only, etc). These may not
be honoured if the PMR does not permit
them.
@Input uiPMRLength The size of the PMR.
@Output phOSMMapPrivDataOut Returned private data.
@Output ppvMappingAddressOut The returned mapping.
@Output puiMappingLengthOut The size of the returned mapping.
@Return PVRSRV_OK on success, failure code otherwise.
*/ /*************************************************************************/
PVRSRV_ERROR
OSMMapPMR(IMG_HANDLE hBridge,
IMG_HANDLE hPMR,
IMG_DEVMEM_SIZE_T uiPMRLength,
IMG_UINT32 uiFlags,
IMG_HANDLE *phOSMMapPrivDataOut,
void **ppvMappingAddressOut,
size_t *puiMappingLengthOut);
/*************************************************************************/ /*!
@Function OSMUnmapPMR
@Description Unmaps the specified PMR from CPU memory.
This function is the counterpart to OSMMapPMR.
The caller is required to pass the PMR handle back in along
with the same 3-tuple of information that was returned by the
call to OSMMapPMR in phOSMMapPrivDataOut.
It is possible to unmap only part of the original mapping
with this call, by specifying only the address range to be
unmapped in pvMappingAddress and uiMappingLength.
@Input hBridge The bridge handle.
@Input hPMR The handle of the PMR to be unmapped.
@Input hOSMMapPrivData The OS private data of the mapping.
@Input pvMappingAddress The address to be unmapped.
@Input uiMappingLength The size to be unmapped.
@Return PVRSRV_OK on success, failure code otherwise.
*/ /*************************************************************************/
void
OSMUnmapPMR(IMG_HANDLE hBridge,
IMG_HANDLE hPMR,
IMG_HANDLE hOSMMapPrivData,
void *pvMappingAddress,
size_t uiMappingLength);
#endif /* OSMMAP_H */
@@ -0,0 +1,147 @@
/*************************************************************************/ /*!
@File
@Title Process and driver statistic definitions
@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 PROC_STATS_H
#define PROC_STATS_H
/* X-Macro for Process stat keys */
#define PVRSRV_PROCESS_STAT_KEY \
X(PVRSRV_PROCESS_STAT_TYPE_CONNECTIONS, "Connections") \
X(PVRSRV_PROCESS_STAT_TYPE_MAX_CONNECTIONS, "ConnectionsMax") \
X(PVRSRV_PROCESS_STAT_TYPE_RC_OOMS, "RenderContextOutOfMemoryEvents") \
X(PVRSRV_PROCESS_STAT_TYPE_RC_PRS, "RenderContextPartialRenders") \
X(PVRSRV_PROCESS_STAT_TYPE_RC_GROWS, "RenderContextGrows") \
X(PVRSRV_PROCESS_STAT_TYPE_RC_PUSH_GROWS, "RenderContextPushGrows") \
X(PVRSRV_PROCESS_STAT_TYPE_RC_TA_STORES, "RenderContextTAStores") \
X(PVRSRV_PROCESS_STAT_TYPE_RC_3D_STORES, "RenderContext3DStores") \
X(PVRSRV_PROCESS_STAT_TYPE_RC_CDM_STORES, "RenderContextCDMStores") \
X(PVRSRV_PROCESS_STAT_TYPE_RC_TDM_STORES, "RenderContextTDMStores") \
X(PVRSRV_PROCESS_STAT_TYPE_ZSBUFFER_REQS_BY_APP, "ZSBufferRequestsByApp") \
X(PVRSRV_PROCESS_STAT_TYPE_ZSBUFFER_REQS_BY_FW, "ZSBufferRequestsByFirmware") \
X(PVRSRV_PROCESS_STAT_TYPE_FREELIST_GROW_REQS_BY_APP, "FreeListGrowRequestsByApp") \
X(PVRSRV_PROCESS_STAT_TYPE_FREELIST_GROW_REQS_BY_FW, "FreeListGrowRequestsByFirmware") \
X(PVRSRV_PROCESS_STAT_TYPE_FREELIST_PAGES_INIT, "FreeListInitialPages") \
X(PVRSRV_PROCESS_STAT_TYPE_FREELIST_MAX_PAGES, "FreeListMaxPages") \
X(PVRSRV_PROCESS_STAT_TYPE_KMALLOC, "MemoryUsageKMalloc") \
X(PVRSRV_PROCESS_STAT_TYPE_KMALLOC_MAX, "MemoryUsageKMallocMax") \
X(PVRSRV_PROCESS_STAT_TYPE_VMALLOC, "MemoryUsageVMalloc") \
X(PVRSRV_PROCESS_STAT_TYPE_VMALLOC_MAX, "MemoryUsageVMallocMax") \
X(PVRSRV_PROCESS_STAT_TYPE_ALLOC_PAGES_PT_UMA, "MemoryUsageAllocPTMemoryUMA") \
X(PVRSRV_PROCESS_STAT_TYPE_ALLOC_PAGES_PT_UMA_MAX, "MemoryUsageAllocPTMemoryUMAMax") \
X(PVRSRV_PROCESS_STAT_TYPE_VMAP_PT_UMA, "MemoryUsageVMapPTUMA") \
X(PVRSRV_PROCESS_STAT_TYPE_VMAP_PT_UMA_MAX, "MemoryUsageVMapPTUMAMax") \
X(PVRSRV_PROCESS_STAT_TYPE_ALLOC_PAGES_PT_LMA, "MemoryUsageAllocPTMemoryLMA") \
X(PVRSRV_PROCESS_STAT_TYPE_ALLOC_PAGES_PT_LMA_MAX, "MemoryUsageAllocPTMemoryLMAMax") \
X(PVRSRV_PROCESS_STAT_TYPE_IOREMAP_PT_LMA, "MemoryUsageIORemapPTLMA") \
X(PVRSRV_PROCESS_STAT_TYPE_IOREMAP_PT_LMA_MAX, "MemoryUsageIORemapPTLMAMax") \
X(PVRSRV_PROCESS_STAT_TYPE_ALLOC_LMA_PAGES, "MemoryUsageAllocGPUMemLMA") \
X(PVRSRV_PROCESS_STAT_TYPE_ALLOC_LMA_PAGES_MAX, "MemoryUsageAllocGPUMemLMAMax") \
X(PVRSRV_PROCESS_STAT_TYPE_ZOMBIE_LMA_PAGES, "MemoryUsageZombieGPUMemLMA") \
X(PVRSRV_PROCESS_STAT_TYPE_ZOMBIE_LMA_PAGES_MAX, "MemoryUsageZombieGPUMemLMAMax") \
X(PVRSRV_PROCESS_STAT_TYPE_ALLOC_UMA_PAGES, "MemoryUsageAllocGPUMemUMA") \
X(PVRSRV_PROCESS_STAT_TYPE_ALLOC_UMA_PAGES_MAX, "MemoryUsageAllocGPUMemUMAMax") \
X(PVRSRV_PROCESS_STAT_TYPE_ZOMBIE_UMA_PAGES, "MemoryUsageZombieGPUMemUMA") \
X(PVRSRV_PROCESS_STAT_TYPE_ZOMBIE_UMA_PAGES_MAX, "MemoryUsageZombieGPUMemUMAMax") \
X(PVRSRV_PROCESS_STAT_TYPE_MAP_UMA_LMA_PAGES, "MemoryUsageMappedGPUMemUMA/LMA") \
X(PVRSRV_PROCESS_STAT_TYPE_MAP_UMA_LMA_PAGES_MAX, "MemoryUsageMappedGPUMemUMA/LMAMax") \
X(PVRSRV_PROCESS_STAT_TYPE_DMA_BUF_ZOMBIE, "MemoryUsageDmaBufZombie") \
X(PVRSRV_PROCESS_STAT_TYPE_DMA_BUF_ZOMBIE_MAX, "MemoryUsageDmaBufZombieMax") \
X(PVRSRV_PROCESS_STAT_TYPE_TOTAL, "MemoryUsageTotal") \
X(PVRSRV_PROCESS_STAT_TYPE_TOTAL_MAX, "MemoryUsageTotalMax") \
X(PVRSRV_PROCESS_STAT_TYPE_OOM_VIRTMEM_COUNT, "MemoryOOMCountDeviceVirtual") \
X(PVRSRV_PROCESS_STAT_TYPE_OOM_PHYSMEM_COUNT, "MemoryOOMCountPhysicalHeap") \
X(PVRSRV_PROCESS_STAT_TYPE_INVALID_VIRTMEM, "MemoryOOMCountDeviceVirtualAtAddress") \
X(PVRSRV_PROCESS_STAT_TYPE_DMA_BUF_IMPORT, "MemoryUsageDmaBufImport") \
X(PVRSRV_PROCESS_STAT_TYPE_DMA_BUF_IMPORT_MAX, "MemoryUsageDmaBufImportMax")
/* X-Macro for Driver stat keys */
#define PVRSRV_DRIVER_STAT_KEY \
X(PVRSRV_DRIVER_STAT_TYPE_KMALLOC, "MemoryUsageKMalloc") \
X(PVRSRV_DRIVER_STAT_TYPE_KMALLOC_MAX, "MemoryUsageKMallocMax") \
X(PVRSRV_DRIVER_STAT_TYPE_VMALLOC, "MemoryUsageVMalloc") \
X(PVRSRV_DRIVER_STAT_TYPE_VMALLOC_MAX, "MemoryUsageVMallocMax") \
X(PVRSRV_DRIVER_STAT_TYPE_ALLOC_PT_MEMORY_UMA, "MemoryUsageAllocPTMemoryUMA") \
X(PVRSRV_DRIVER_STAT_TYPE_ALLOC_PT_MEMORY_UMA_MAX, "MemoryUsageAllocPTMemoryUMAMax") \
X(PVRSRV_DRIVER_STAT_TYPE_VMAP_PT_UMA, "MemoryUsageVMapPTUMA") \
X(PVRSRV_DRIVER_STAT_TYPE_VMAP_PT_UMA_MAX, "MemoryUsageVMapPTUMAMax") \
X(PVRSRV_DRIVER_STAT_TYPE_ALLOC_PT_MEMORY_LMA, "MemoryUsageAllocPTMemoryLMA") \
X(PVRSRV_DRIVER_STAT_TYPE_ALLOC_PT_MEMORY_LMA_MAX, "MemoryUsageAllocPTMemoryLMAMax") \
X(PVRSRV_DRIVER_STAT_TYPE_IOREMAP_PT_LMA, "MemoryUsageIORemapPTLMA") \
X(PVRSRV_DRIVER_STAT_TYPE_IOREMAP_PT_LMA_MAX, "MemoryUsageIORemapPTLMAMax") \
X(PVRSRV_DRIVER_STAT_TYPE_ALLOC_GPUMEM_LMA, "MemoryUsageAllocGPUMemLMA") \
X(PVRSRV_DRIVER_STAT_TYPE_ALLOC_GPUMEM_LMA_MAX, "MemoryUsageAllocGPUMemLMAMax") \
X(PVRSRV_DRIVER_STAT_TYPE_ZOMBIE_GPUMEM_LMA, "MemoryUsageZombieGPUMemLMA") \
X(PVRSRV_DRIVER_STAT_TYPE_ZOMBIE_GPUMEM_LMA_MAX, "MemoryUsageZombieGPUMemLMAMax") \
X(PVRSRV_DRIVER_STAT_TYPE_ALLOC_GPUMEM_UMA, "MemoryUsageAllocGPUMemUMA") \
X(PVRSRV_DRIVER_STAT_TYPE_ALLOC_GPUMEM_UMA_MAX, "MemoryUsageAllocGPUMemUMAMax") \
X(PVRSRV_DRIVER_STAT_TYPE_ZOMBIE_GPUMEM_UMA, "MemoryUsageZombieGPUMemUMA") \
X(PVRSRV_DRIVER_STAT_TYPE_ZOMBIE_GPUMEM_UMA_MAX, "MemoryUsageZombieGPUMemUMAMax") \
X(PVRSRV_DRIVER_STAT_TYPE_ALLOC_GPUMEM_UMA_POOL, "MemoryUsageAllocGPUMemUMAPool") \
X(PVRSRV_DRIVER_STAT_TYPE_ALLOC_GPUMEM_UMA_POOL_MAX, "MemoryUsageAllocGPUMemUMAPoolMax") \
X(PVRSRV_DRIVER_STAT_TYPE_MAPPED_GPUMEM_UMA_LMA, "MemoryUsageMappedGPUMemUMA/LMA") \
X(PVRSRV_DRIVER_STAT_TYPE_MAPPED_GPUMEM_UMA_LMA_MAX, "MemoryUsageMappedGPUMemUMA/LMAMax") \
X(PVRSRV_DRIVER_STAT_TYPE_DMA_BUF_IMPORT, "MemoryUsageDmaBufImport") \
X(PVRSRV_DRIVER_STAT_TYPE_DMA_BUF_IMPORT_MAX, "MemoryUsageDmaBufImportMax") \
X(PVRSRV_DRIVER_STAT_TYPE_DMA_BUF_ZOMBIE, "MemoryUsageDmaBufZombie") \
X(PVRSRV_DRIVER_STAT_TYPE_DMA_BUF_ZOMBIE_MAX, "MemoryUsageDmaBufZombieMax")
typedef enum {
#define X(stat_type, stat_str) stat_type,
PVRSRV_PROCESS_STAT_KEY
#undef X
PVRSRV_PROCESS_STAT_TYPE_COUNT
}PVRSRV_PROCESS_STAT_TYPE;
typedef enum {
#define X(stat_type, stat_str) stat_type,
PVRSRV_DRIVER_STAT_KEY
#undef X
PVRSRV_DRIVER_STAT_TYPE_COUNT
}PVRSRV_DRIVER_STAT_TYPE;
extern const IMG_CHAR *const pszProcessStatType[];
extern const IMG_CHAR *const pszDriverStatType[];
#endif // PROC_STATS_H
@@ -0,0 +1,223 @@
/*************************************************************************/ /*!
@File
@Title Resource Allocator API
@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 RA_H
#define RA_H
#include "img_types.h"
#include "pvrsrv_error.h"
/** Resource arena.
* struct _RA_ARENA_ deliberately opaque
*/
typedef struct _RA_ARENA_ RA_ARENA; //PRQA S 3313
/*
* Per-Arena handle - this is private data for the caller of the RA.
* The RA knows nothing about this data. It is given it in RA_Create, and
* promises to pass it to calls to the ImportAlloc and ImportFree callbacks
*/
typedef IMG_HANDLE RA_PERARENA_HANDLE;
/*
* Per-Import handle - this is private data for the caller of the RA.
* The RA knows nothing about this data. It is given it on a per-import basis,
* basis, either the "initial" import at RA_Create time, or further imports
* via the ImportAlloc callback. It sends it back via the ImportFree callback,
* and also provides it in answer to any RA_Alloc request to signify from
* which "import" the allocation came.
*/
typedef IMG_HANDLE RA_PERISPAN_HANDLE;
typedef IMG_UINT64 RA_BASE_T;
typedef IMG_UINT32 RA_LOG2QUANTUM_T;
typedef IMG_UINT64 RA_LENGTH_T;
/* Lock classes: describes the level of nesting between different arenas. */
#define RA_LOCKCLASS_0 0
#define RA_LOCKCLASS_1 1
#define RA_LOCKCLASS_2 2
#define RA_NO_IMPORT_MULTIPLIER 1
/*
* Flags in an "import" must match the flags for an allocation
*/
typedef IMG_UINT32 RA_FLAGS_T;
/**
* @Function RA_Create
*
* @Description To create a resource arena.
*
* @Input name - the name of the arena for diagnostic purposes.
* @Input uLog2Quantum - the arena allocation quantum.
* @Input ui32LockClass - the lock class level this arena uses.
* @Input imp_alloc - a resource allocation callback or 0.
* @Input imp_free - a resource de-allocation callback or 0.
* @Input per_arena_handle - private handle passed to alloc and free or 0.
* @Input bNoSplit - Disable splitting up imports.
* @Return pointer to arena, or NULL.
*/
RA_ARENA *
RA_Create(IMG_CHAR *name,
/* subsequent imports: */
RA_LOG2QUANTUM_T uLog2Quantum,
IMG_UINT32 ui32LockClass,
PVRSRV_ERROR (*imp_alloc)(RA_PERARENA_HANDLE _h,
RA_LENGTH_T uSize,
RA_FLAGS_T uFlags,
const IMG_CHAR *pszAnnotation,
RA_BASE_T *pBase,
RA_LENGTH_T *pActualSize,
RA_PERISPAN_HANDLE *phPriv),
void (*imp_free) (RA_PERARENA_HANDLE,
RA_BASE_T,
RA_PERISPAN_HANDLE),
RA_PERARENA_HANDLE per_arena_handle,
IMG_BOOL bNoSplit);
/**
* @Function RA_Delete
*
* @Description
*
* To delete a resource arena. All resources allocated from the arena
* must be freed before deleting the arena.
*
* @Input pArena - the arena to delete.
* @Return None
*/
void
RA_Delete (RA_ARENA *pArena);
/**
* @Function RA_Add
*
* @Description
*
* To add a resource span to an arena. The span must not overlap with
* any span previously added to the arena.
*
* @Input pArena - the arena to add a span into.
* @Input base - the base of the span.
* @Input uSize - the extent of the span.
* @Input hPriv - handle associated to the span (reserved for user uses)
* @Return IMG_TRUE - success, IMG_FALSE - failure
*/
IMG_BOOL
RA_Add(RA_ARENA *pArena,
RA_BASE_T base,
RA_LENGTH_T uSize,
RA_FLAGS_T uFlags,
RA_PERISPAN_HANDLE hPriv);
/**
* @Function RA_Alloc
*
* @Description To allocate resource from an arena.
*
* @Input pArena - the arena
* @Input uRequestSize - the size of resource segment requested.
* @Input uImportMultiplier - Import x-times of the uRequestSize
* for future RA_Alloc calls.
* Use RA_NO_IMPORT_MULTIPLIER to import the exact size.
* @Input uImportFlags - flags influencing allocation policy.
* @Input uAlignment - the alignment constraint required for the
* allocated segment, use 0 if alignment not required.
* @Input pszAnnotation - a string to describe the allocation
* @Output pBase - allocated base resource
* @Output pActualSize - the actual_size of resource segment allocated,
* typically rounded up by quantum.
* @Output phPriv - the user reference associated with allocated
* resource span.
* @Return PVRSRV_OK - success
*/
PVRSRV_ERROR
RA_Alloc(RA_ARENA *pArena,
RA_LENGTH_T uRequestSize,
IMG_UINT8 uImportMultiplier,
RA_FLAGS_T uImportFlags,
RA_LENGTH_T uAlignment,
const IMG_CHAR *pszAnnotation,
RA_BASE_T *pBase,
RA_LENGTH_T *pActualSize,
RA_PERISPAN_HANDLE *phPriv);
/**
* @Function RA_Alloc_Range
*
* @Description
*
* To allocate a resource at a specified base from an arena.
*
* @Input pArena - the arena
* @Input uRequestSize - the size of resource segment requested.
* @Input uImportFlags - flags influencing allocation policy.
* @Input uAlignment - the alignment constraint required for the
* allocated segment, use 0 if alignment not required.
* @Input pBase - allocated base resource
* @Output pActualSize - the actual_size of resource segment allocated,
* typically rounded up by quantum.
* @Return PVRSRV_OK - success
*/
PVRSRV_ERROR
RA_Alloc_Range (RA_ARENA *pArena,
RA_LENGTH_T uRequestSize,
RA_FLAGS_T uImportFlags,
RA_LENGTH_T uAlignment,
RA_BASE_T base,
RA_LENGTH_T *pActualSize);
/**
* @Function RA_Free
*
* @Description To free a resource segment.
*
* @Input pArena - the arena the segment was originally allocated from.
* @Input base - the base of the resource span to free.
*
* @Return None
*/
void
RA_Free(RA_ARENA *pArena, RA_BASE_T base);
#endif
@@ -0,0 +1,316 @@
/*************************************************************************/ /*!
@File
@Title Synchronisation interface header
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Defines the client side interface for synchronisation
@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 SYNC_H
#define SYNC_H
#include "img_types.h"
#include "img_defs.h"
#include "pvrsrv_error.h"
#include "sync_prim_internal.h"
#include "pdumpdefs.h"
#include "dllist.h"
#include "pvr_debug.h"
#include "device_connection.h"
#if defined(__KERNEL__) && defined(LINUX) && !defined(__GENKSYMS__)
#define __pvrsrv_defined_struct_enum__
#include <services_kernel_client.h>
#endif
/*************************************************************************/ /*!
@Function SyncPrimContextCreate
@Description Create a new synchronisation context
@Input hBridge Bridge handle
@Input hDeviceNode Device node handle
@Output hSyncPrimContext Handle to the created synchronisation
primitive context
@Return PVRSRV_OK if the synchronisation primitive context was
successfully created
*/
/*****************************************************************************/
PVRSRV_ERROR
SyncPrimContextCreate(SHARED_DEV_CONNECTION hDevConnection,
PSYNC_PRIM_CONTEXT *hSyncPrimContext);
/*************************************************************************/ /*!
@Function SyncPrimContextDestroy
@Description Destroy a synchronisation context
@Input hSyncPrimContext Handle to the synchronisation
primitive context to destroy
@Return None
*/
/*****************************************************************************/
void
SyncPrimContextDestroy(PSYNC_PRIM_CONTEXT hSyncPrimContext);
/*************************************************************************/ /*!
@Function SyncPrimAlloc
@Description Allocate a new synchronisation primitive on the specified
synchronisation context
@Input hSyncPrimContext Handle to the synchronisation
primitive context
@Output ppsSync Created synchronisation primitive
@Input pszClassName Sync source annotation
@Return PVRSRV_OK if the synchronisation primitive was
successfully created
*/
/*****************************************************************************/
PVRSRV_ERROR
SyncPrimAlloc(PSYNC_PRIM_CONTEXT hSyncPrimContext,
PVRSRV_CLIENT_SYNC_PRIM **ppsSync,
const IMG_CHAR *pszClassName);
#if defined(__KERNEL__)
/*************************************************************************/ /*!
@Function SyncPrimAllocForServerSync
@Description Allocate a new synchronisation primitive on the specified
synchronisation context for a server sync
@Input hSyncPrimContext Handle to the synchronisation
primitive context
@Output ppsSync Created synchronisation primitive
@Input pszClassName Sync source annotation
@Return PVRSRV_OK if the synchronisation primitive was
successfully created
*/
/*****************************************************************************/
PVRSRV_ERROR
SyncPrimAllocForServerSync(PSYNC_PRIM_CONTEXT hSyncPrimContext,
PVRSRV_CLIENT_SYNC_PRIM **ppsSync,
const IMG_CHAR *pszClassName);
#endif
/*************************************************************************/ /*!
@Function SyncPrimFree
@Description Free a synchronisation primitive
@Input psSync The synchronisation primitive to free
@Return PVRSRV_OK if the synchronisation primitive was
successfully freed
*/
/*****************************************************************************/
PVRSRV_ERROR
SyncPrimFree(PVRSRV_CLIENT_SYNC_PRIM *psSync);
/*************************************************************************/ /*!
@Function SyncPrimSet
@Description Set the synchronisation primitive to a value
@Input psSync The synchronisation primitive to set
@Input ui32Value Value to set it to
@Return PVRSRV_OK on success
*/
/*****************************************************************************/
PVRSRV_ERROR
SyncPrimSet(PVRSRV_CLIENT_SYNC_PRIM *psSync, IMG_UINT32 ui32Value);
#if defined(NO_HARDWARE)
/*************************************************************************/ /*!
@Function SyncPrimNoHwUpdate
@Description Updates the synchronisation primitive value (in NoHardware drivers)
@Input psSync The synchronisation primitive to update
@Input ui32Value Value to update it to
@Return PVRSRV_OK on success
*/
/*****************************************************************************/
PVRSRV_ERROR
SyncPrimNoHwUpdate(PVRSRV_CLIENT_SYNC_PRIM *psSync, IMG_UINT32 ui32Value);
#endif
#if defined(PDUMP)
/*************************************************************************/ /*!
@Function SyncPrimPDump
@Description PDump the current value of the synchronisation primitive
@Input psSync The synchronisation primitive to PDump
@Return None
*/
/*****************************************************************************/
void
SyncPrimPDump(PVRSRV_CLIENT_SYNC_PRIM *psSync);
/*************************************************************************/ /*!
@Function SyncPrimPDumpValue
@Description PDump the ui32Value as the value of the synchronisation
primitive (regardless of the current value).
@Input psSync The synchronisation primitive to PDump
@Input ui32Value Value to give to the sync prim on the pdump
@Return None
*/
/*****************************************************************************/
void
SyncPrimPDumpValue(PVRSRV_CLIENT_SYNC_PRIM *psSync, IMG_UINT32 ui32Value);
/*************************************************************************/ /*!
@Function SyncPrimPDumpPol
@Description Do a PDump poll of the synchronisation primitive
@Input psSync The synchronisation primitive to PDump
@Input ui32Value Value to poll for
@Input ui32Mask PDump mask operator
@Input ui32PDumpFlags PDump flags
@Return None
*/
/*****************************************************************************/
void
SyncPrimPDumpPol(PVRSRV_CLIENT_SYNC_PRIM *psSync,
IMG_UINT32 ui32Value,
IMG_UINT32 ui32Mask,
PDUMP_POLL_OPERATOR eOperator,
IMG_UINT32 ui32PDumpFlags);
/*************************************************************************/ /*!
@Function SyncPrimPDumpCBP
@Description Do a PDump CB poll using the synchronisation primitive
@Input psSync The synchronisation primitive to PDump
@Input uiWriteOffset Current write offset of buffer
@Input uiPacketSize Size of the packet to write into CB
@Input uiBufferSize Size of the CB
@Return None
*/
/*****************************************************************************/
void
SyncPrimPDumpCBP(PVRSRV_CLIENT_SYNC_PRIM *psSync,
IMG_UINT64 uiWriteOffset,
IMG_UINT64 uiPacketSize,
IMG_UINT64 uiBufferSize);
#else
#ifdef INLINE_IS_PRAGMA
#pragma inline(SyncPrimPDumpValue)
#endif
static INLINE void
SyncPrimPDumpValue(PVRSRV_CLIENT_SYNC_PRIM *psSync, IMG_UINT32 ui32Value)
{
PVR_UNREFERENCED_PARAMETER(psSync);
PVR_UNREFERENCED_PARAMETER(ui32Value);
}
#ifdef INLINE_IS_PRAGMA
#pragma inline(SyncPrimPDump)
#endif
static INLINE void
SyncPrimPDump(PVRSRV_CLIENT_SYNC_PRIM *psSync)
{
PVR_UNREFERENCED_PARAMETER(psSync);
}
#ifdef INLINE_IS_PRAGMA
#pragma inline(SyncPrimPDumpPol)
#endif
static INLINE void
SyncPrimPDumpPol(PVRSRV_CLIENT_SYNC_PRIM *psSync,
IMG_UINT32 ui32Value,
IMG_UINT32 ui32Mask,
PDUMP_POLL_OPERATOR eOperator,
IMG_UINT32 ui32PDumpFlags)
{
PVR_UNREFERENCED_PARAMETER(psSync);
PVR_UNREFERENCED_PARAMETER(ui32Value);
PVR_UNREFERENCED_PARAMETER(ui32Mask);
PVR_UNREFERENCED_PARAMETER(eOperator);
PVR_UNREFERENCED_PARAMETER(ui32PDumpFlags);
}
#ifdef INLINE_IS_PRAGMA
#pragma inline(SyncPrimPDumpCBP)
#endif
static INLINE void
SyncPrimPDumpCBP(PVRSRV_CLIENT_SYNC_PRIM *psSync,
IMG_UINT64 uiWriteOffset,
IMG_UINT64 uiPacketSize,
IMG_UINT64 uiBufferSize)
{
PVR_UNREFERENCED_PARAMETER(psSync);
PVR_UNREFERENCED_PARAMETER(uiWriteOffset);
PVR_UNREFERENCED_PARAMETER(uiPacketSize);
PVR_UNREFERENCED_PARAMETER(uiBufferSize);
}
#endif /* PDUMP */
#endif /* SYNC_H */
@@ -0,0 +1,118 @@
/*************************************************************************/ /*!
@File
@Title Services internal synchronisation interface header
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Defines the internal client side interface for services
synchronisation
@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 SYNC_INTERNAL
#define SYNC_INTERNAL
#include "img_types.h"
#include "img_defs.h"
#include "ra.h"
#include "dllist.h"
#include "lock.h"
#include "devicemem.h"
#include "sync_prim_internal.h"
#define LOCAL_SYNC_PRIM_RESET_VALUE 0
#define LOCAL_SYNC_PRIM_POISON_VALUE 0xa5a5a5a5u
/*
Private structure's
*/
#define SYNC_PRIM_NAME_SIZE 50
typedef struct SYNC_PRIM_CONTEXT
{
SHARED_DEV_CONNECTION hDevConnection;
IMG_CHAR azName[SYNC_PRIM_NAME_SIZE]; /*!< Name of the RA */
RA_ARENA *psSubAllocRA; /*!< RA context */
IMG_CHAR azSpanName[SYNC_PRIM_NAME_SIZE];/*!< Name of the span RA */
RA_ARENA *psSpanRA; /*!< RA used for span management of SubAllocRA */
ATOMIC_T hRefCount; /*!< Ref count for this context */
} SYNC_PRIM_CONTEXT;
typedef struct SYNC_PRIM_BLOCK_TAG
{
SYNC_PRIM_CONTEXT *psContext; /*!< Our copy of the services connection */
IMG_HANDLE hServerSyncPrimBlock; /*!< Server handle for this block */
IMG_UINT32 ui32SyncBlockSize; /*!< Size of the sync prim block */
IMG_UINT32 ui32FirmwareAddr; /*!< Firmware address */
DEVMEM_MEMDESC *hMemDesc; /*!< Host mapping handle */
IMG_UINT32 __iomem *pui32LinAddr; /*!< User CPU mapping */
IMG_UINT64 uiSpanBase; /*!< Base of this import in the span RA */
DLLIST_NODE sListNode; /*!< List node for the sync block list */
} SYNC_PRIM_BLOCK;
typedef enum SYNC_PRIM_TYPE_TAG
{
SYNC_PRIM_TYPE_UNKNOWN = 0,
SYNC_PRIM_TYPE_LOCAL,
SYNC_PRIM_TYPE_SERVER,
} SYNC_PRIM_TYPE;
typedef struct SYNC_PRIM_LOCAL_TAG
{
ATOMIC_T hRefCount; /*!< Ref count for this sync */
SYNC_PRIM_BLOCK *psSyncBlock; /*!< Synchronisation block this primitive is allocated on */
IMG_UINT64 uiSpanAddr; /*!< Span address of the sync */
IMG_HANDLE hRecord; /*!< Sync record handle */
} SYNC_PRIM_LOCAL;
typedef struct SYNC_PRIM_TAG
{
PVRSRV_CLIENT_SYNC_PRIM sCommon; /*!< Client visible part of the sync prim */
SYNC_PRIM_TYPE eType; /*!< Sync primitive type */
union {
SYNC_PRIM_LOCAL sLocal; /*!< Local sync primitive data */
} u;
} SYNC_PRIM;
IMG_INTERNAL PVRSRV_ERROR
SyncPrimGetFirmwareAddr(PVRSRV_CLIENT_SYNC_PRIM *psSync, IMG_UINT32 *pui32FwAddr);
IMG_INTERNAL PVRSRV_ERROR SyncPrimLocalGetHandleAndOffset(PVRSRV_CLIENT_SYNC_PRIM *psSync,
IMG_HANDLE *phBlock,
IMG_UINT32 *pui32Offset);
#endif /* SYNC_INTERNAL */
@@ -0,0 +1,257 @@
/*************************************************************************/ /*!
@File tlclient.h
@Title Services Transport Layer shared API
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Transport layer common API used in both clients and server
@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 TLCLIENT_H
#define TLCLIENT_H
#include "img_defs.h"
#include "pvrsrv_tlcommon.h"
#include "pvrsrv_error.h"
/* This value is used for the hSrvHandle argument in the client API when
* called directly from the kernel which will lead to a direct bridge access.
*/
#define DIRECT_BRIDGE_HANDLE ((IMG_HANDLE)0xDEADBEEFU)
/*************************************************************************/ /*!
@Function TLClientOpenStream
@Description Open a descriptor onto an existing kernel transport stream.
@Input hDevConnection Address of a pointer to a connection object
@Input pszName Address of the stream name string, no longer
than PRVSRVTL_MAX_STREAM_NAME_SIZE.
@Input ui32Mode Unused
@Output phSD Address of a pointer to an stream object
@Return PVRSRV_ERROR_NOT_FOUND when named stream not found
@Return PVRSRV_ERROR_ALREADY_OPEN stream already open by another
@Return PVRSRV_ERROR_STREAM_ERROR internal driver state error
@Return PVRSRV_ERROR_TIMEOUT timed out, stream not found
@Return PVRSRV_ERROR for other system codes
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR TLClientOpenStream(SHARED_DEV_CONNECTION hDevConnection,
const IMG_CHAR* pszName,
IMG_UINT32 ui32Mode,
IMG_HANDLE* phSD);
/*************************************************************************/ /*!
@Function TLClientCloseStream
@Description Close and release the stream connection to Services kernel
server transport layer. Any outstanding Acquire will be
released.
@Input hDevConnection Address of a pointer to a connection object
@Input hSD Handle of the stream object to close
@Return PVRSRV_ERROR_HANDLE_NOT_FOUND when SD handle is not known
@Return PVRSRV_ERROR_STREAM_ERROR internal driver state error
@Return PVRSRV_ERROR for system codes
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR TLClientCloseStream(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hSD);
/*************************************************************************/ /*!
@Function TLClientDiscoverStreams
@Description Finds all streams that's name starts with pszNamePattern and
ends with a number.
@Input hDevConnection Address of a pointer to a connection object
@Input pszNamePattern Name pattern. Must be beginning of a string.
@Output aszStreams Array of numbers from end of the discovered
names.
@inOut pui32NumFound When input, max number that can fit into
pui32Streams. When output, number of
discovered streams.
@Return PVRSRV_ERROR for system codes
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR TLClientDiscoverStreams(SHARED_DEV_CONNECTION hDevConnection,
const IMG_CHAR *pszNamePattern,
IMG_CHAR aszStreams[][PRVSRVTL_MAX_STREAM_NAME_SIZE],
IMG_UINT32 *pui32NumFound);
/*************************************************************************/ /*!
@Function TLClientReserveStream
@Description Reserves a region with given size in the stream. If the stream
is already reserved the function will return an error.
@Input hDevConnection Address of a pointer to a connection object
@Input hSD Handle of the stream object to close
@Output ppui8Data pointer to the buffer
@Input ui32Size size of the data
@Return
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR TLClientReserveStream(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hSD,
IMG_UINT8 **ppui8Data,
IMG_UINT32 ui32Size);
/*************************************************************************/ /*!
@Function TLClientStreamReserve2
@Description Reserves a region with given size in the stream. If the stream
is already reserved the function will return an error.
@Input hDevConnection Address of a pointer to a connection object
@Input hSD Handle of the stream object to close
@Output ppui8Data pointer to the buffer
@Input ui32Size size of the data
@Input ui32SizeMin minimum size of the data
@Input ui32Available available space in buffer
@Return
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR TLClientReserveStream2(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hSD,
IMG_UINT8 **ppui8Data,
IMG_UINT32 ui32Size,
IMG_UINT32 ui32SizeMin,
IMG_UINT32 *pui32Available);
/*************************************************************************/ /*!
@Function TLClientStreamCommit
@Description Commits previously reserved region in the stream and therefore
allows next reserves.
This function call has to be preceded by the call to
TLClientReserveStream or TLClientReserveStream2.
@Input hDevConnection Address of a pointer to a connection object
@Input hSD Handle of the stream object to close
@Input ui32Size Size of the data
@Return
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR TLClientCommitStream(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hSD,
IMG_UINT32 ui32Size);
/*************************************************************************/ /*!
@Function TLClientAcquireData
@Description When there is data available in the stream buffer this call
returns with the address and length of the data buffer the
client can safely read. This buffer may contain one or more
packets of data.
If no data is available then this call blocks until it becomes
available. However if the stream has been destroyed while
waiting then a resource unavailable error will be returned to
the caller. Clients must pair this call with a ReleaseData
call.
@Input hDevConnection Address of a pointer to a connection object
@Input hSD Handle of the stream object to read
@Output ppPacketBuf Address of a pointer to an byte buffer. On exit
pointer contains address of buffer to read from
@Output puiBufLen Pointer to an integer. On exit it is the size
of the data to read from the packet buffer
@Return PVRSRV_ERROR_RESOURCE_UNAVAILABLE when stream no longer exists
@Return PVRSRV_ERROR_HANDLE_NOT_FOUND when SD handle not known
@Return PVRSRV_ERROR_STREAM_ERROR internal driver state error
@Return PVRSRV_ERROR_RETRY release not called beforehand
@Return PVRSRV_ERROR_TIMEOUT block timed out, no data
@Return PVRSRV_ERROR for other system codes
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR TLClientAcquireData(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hSD,
IMG_PBYTE* ppPacketBuf,
IMG_UINT32* puiBufLen);
/*************************************************************************/ /*!
@Function TLClientReleaseData
@Description Called after client has read the stream data out of the buffer
The data is subsequently flushed from the stream buffer to make
room for more data packets from the stream source.
@Input hDevConnection Address of a pointer to a connection object
@Input hSD Handle of the stream object to read
@Return PVRSRV_ERROR_RESOURCE_UNAVAILABLE when stream no longer exists
@Return PVRSRV_ERROR_HANDLE_NOT_FOUND when SD handle not known to TL
@Return PVRSRV_ERROR_STREAM_ERROR internal driver state error
@Return PVRSRV_ERROR_RETRY acquire not called beforehand
@Return PVRSRV_ERROR for system codes
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR TLClientReleaseData(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hSD);
/*************************************************************************/ /*!
@Function TLClientReleaseDataLess
@Description Called after client has read only some data out of the buffer
and wishes to complete the read early i.e. does not want to
read the full data that the acquire call returned e.g read just
one packet from the stream.
The data is subsequently flushed from the stream buffer to make
room for more data packets from the stream source.
@Input hDevConnection Address of a pointer to a connection object
@Input hSD Handle of the stream object to read
@Input uiActualReadLen Size of data read, in bytes. Must be on a TL
packet boundary.
@Return PVRSRV_ERROR_INVALID_PARAMS when read length too big
@Return PVRSRV_ERROR_RESOURCE_UNAVAILABLE when stream no longer exists
@Return PVRSRV_ERROR_HANDLE_NOT_FOUND when SD handle not known to TL
@Return PVRSRV_ERROR_STREAM_ERROR internal driver state error
@Return PVRSRV_ERROR_RETRY acquire not called beforehand
@Return PVRSRV_ERROR for system codes
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR TLClientReleaseDataLess(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hSD, IMG_UINT32 uiActualReadLen);
/*************************************************************************/ /*!
@Function TLClientWriteData
@Description Writes data to the stream.
@Input hDevConnection Address of a pointer to a connection object
@Input hSD Handle of the stream object to read
@Input ui32Size Size of the data
@Input pui8Data Pointer to data
*/ /**************************************************************************/
IMG_INTERNAL
PVRSRV_ERROR TLClientWriteData(SHARED_DEV_CONNECTION hDevConnection,
IMG_HANDLE hSD,
IMG_UINT32 ui32Size,
IMG_BYTE *pui8Data);
#endif /* TLCLIENT_H */
/******************************************************************************
End of file (tlclient.h)
******************************************************************************/
@@ -0,0 +1,237 @@
/*************************************************************************/ /*!
@File tutilsdefs.h
@Title Testing utils bridge defines
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description Shared structures and constants between client and server sides
of tutils bridge
@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 TUTILSDEFS_H
#define TUTILSDEFS_H
#include "pvrsrv_tlcommon.h"
#include "pvrsrv_sync_km.h"
/******************************************************************************
*
* TEST Related definitions and constants
*/
#define PVR_TL_TEST_STREAM_BRIDGE_NAME "TLBRIDGE_TEST"
#define PVR_TL_TEST_UMBASE 0x00202000
#define PVR_TL_TEST_OFFSET 0x0008
#define PVR_TL_TEST_LEN 0x0010
#define PVR_TL_TEST_STREAM2_NAME "TLSTREAM2_TEST"
#define PVR_TL_TEST_STREAM2_SIZE 2
#define PVR_TL_TEST_STREAM3_NAME "TLSTREAM3_TEST"
#define PVR_TL_TEST_STREAM3_SIZE 256
// This constant, when used as a parameter in StreamCreate, lessens the size of
// the buffer that is created for a stream, to avoid going over a page boundary.
#define PVR_TL_TEST_STREAM_BUFFER_REDUCTION 32
#define PVR_TL_TEST_CMD_SOURCE_START 10
typedef struct _PVR_TL_TEST_CMD_SOURCE_START_IN_
{
/* Stream name must always be first in struct */
IMG_CHAR pszStreamName[PRVSRVTL_MAX_STREAM_NAME_SIZE];
IMG_UINT16 uiStreamSizeInPages; /* # of 4Kb pages */
IMG_UINT16 uiInterval; /* in milliseconds */
IMG_UINT16 uiCallbackKicks; /* 0 for no limit of timer call backs */
IMG_UINT16 uiEOSMarkerKicks; /* Insert EOS Marker every N Kicks, 0 for none */
IMG_UINT16 uiPacketSizeInBytes; /* 0 for random size between 1..255 size in bytes */
IMG_UINT32 uiStreamCreateFlags; /* See TLStreamCreate() */
IMG_UINT16 uiStartDelay; /* 0 for normal uiInterval delay, one off delay in ms */
IMG_BOOL bDoNotDeleteStream; /* When true the stream is not deleted on self
* cleanup sources only the timers and other resources are */
IMG_BOOL bDelayStreamCreate; /* When true the stream used in the source is created
* in the first kick. False for normal behaviour where
* the stream is created in the bridge source start context */
} PVR_TL_TEST_CMD_SOURCE_START_IN;
#define PVR_TL_TEST_CMD_SOURCE_STOP 11
typedef struct _PVR_TL_TEST_CMD_SOURCE_STOP_IN_
{
/* Stream name must always be first in struct */
IMG_CHAR pszStreamName[PRVSRVTL_MAX_STREAM_NAME_SIZE];
IMG_BOOL bDoNotDeleteStream;
} PVR_TL_TEST_CMD_SOURCE_STOP_IN;
#define PVR_TL_TEST_CMD_SOURCE_START2 12 /* Uses two stage data submit */
typedef PVR_TL_TEST_CMD_SOURCE_START_IN PVR_TL_TEST_CMD_SOURCE_START2_IN;
#define PVR_TL_TEST_CMD_DEBUG_LEVEL 13
/* No typedef, uses integer uiIn1 in union */
#define PVR_TL_TEST_CMD_DUMP_TL_STATE 14
/* No typedef, uses integer uiIn1 in union */
#define PVR_TL_TEST_CMD_STREAM_CREATE 15
typedef struct _PVR_TL_TEST_CMD_STREAM_CREATE_IN_
{
/* Stream name must always be first in struct */
IMG_CHAR pszStreamName[PRVSRVTL_MAX_STREAM_NAME_SIZE];
IMG_UINT16 uiStreamSizeInPages;
IMG_UINT32 uiStreamCreateFlags;
IMG_BOOL bWithOpenCallback;
} PVR_TL_TEST_CMD_STREAM_CREATE_IN;
#define PVR_TL_TEST_CMD_STREAM_CLOSE 16
typedef struct _PVR_TL_TEST_CMD_STREAM_NAME_IN_
{
IMG_CHAR pszStreamName[PRVSRVTL_MAX_STREAM_NAME_SIZE];
} PVR_TL_TEST_CMD_STREAM_NAME_IN;
#define PVR_TL_TEST_CMD_STREAM_OPEN 17
#define PVR_TL_TEST_CMD_DUMP_HWPERF_STATE 18
#define PVR_TL_TEST_CMD_FLUSH_HWPERF_FWBUF 19
#define PVR_TL_TEST_CMD_DUMP_PDUMP_STATE 21
typedef union _PVR_TL_TEST_CMD_IN_
{
PVR_TL_TEST_CMD_SOURCE_START_IN sStart;
PVR_TL_TEST_CMD_SOURCE_STOP_IN sStop;
/* PVR_TL_TEST_CMD_SOURCE_START_IN sStart2; Used by #12, use sStart instead */
IMG_UINT32 uiIn1; /* Used by #13, #14 */
PVR_TL_TEST_CMD_STREAM_CREATE_IN sCreate;
PVR_TL_TEST_CMD_STREAM_NAME_IN sName;
IMG_UINT32 uiParams[6];
} PVR_TL_TEST_CMD_IN;
/* Has to be the largest test IN structure */
#define PVR_TL_TEST_PARAM_MAX_SIZE (sizeof(PVR_TL_TEST_CMD_IN)+4)
#define PVR_TL_TEST_CMD_SET_PWR_STATE 22
#define PVR_TL_TEST_CMD_GET_PWR_STATE 23
#define PVR_TL_TEST_CMD_SET_DWT_PWR_CHANGE_COUNTER 24
#define PVR_TL_TEST_CMD_GET_DWT_PWR_CHANGE_COUNTER 25
#define PVR_TL_TEST_PWR_STATE_ON 1
#define PVR_TL_TEST_PWR_STATE_OFF 0
/****************************************************************************
* PowMonTestThread IOCTL calls and constants
*/
#define PVR_POWMON_CMD_GET_ESTIMATES 1
#define PVR_POWMON_CMD_SET_THREAD_LATENCY 2
#define PVR_POWMON_CMD_TEST_THREAD_UPDATE_STATE 3
#define PVR_POWMON_TEST_THREAD_RESUME 1
#define PVR_POWMON_TEST_THREAD_PAUSE 0
/****************************************************************************
* PowerTestThread IOCTL calls and constants
*/
#define PVR_POWER_TEST_CMD_DVFS 1
#define PVR_POWER_TEST_CMD_FORCED_IDLE 2
#define PVR_POWER_TEST_CMD_CANCEL_FORCED_IDLE 3
#define PVR_POWER_TEST_CMD_POWER_ON 4
#define PVR_POWER_TEST_CMD_POWER_OFF 5
#define PVR_POWER_TEST_CMD_APM_LATENCY 6
#define PVR_POWER_TEST_CMD_INVALID 7
#define PVR_POWER_TEST_NON_FORCED 0
#define PVR_POWER_TEST_FORCED 1
/****************************************************************************
* SyncCheckpointTest IOCTL types
*/
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_CONTEXT_CREATE 26
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_CONTEXT_DESTROY 27
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_REGISTER_FUNCS 28
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_CREATE 29
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_CREATE_NULL_CTXT 30
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_CREATE_NULL_RTRN 31
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_DESTROY 32
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_SIGNAL 33
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_ERROR 34
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_IS_SIGNALLED 35
#define PVR_TL_TEST_CMD_SYNC_CHECKPOINT_IS_ERRORED 36
typedef struct _PVR_TL_TEST_CMD_CHECKPOINT_CREATE_IN_
{
/* Checkpoint name must always be first in struct */
IMG_CHAR pszCheckpointName[PVRSRV_SYNC_NAME_LENGTH];
IMG_UINT16 uiStreamSizeInPages;
IMG_UINT32 uiStreamCreateFlags;
} PVR_TL_TEST_CMD_CHECKPOINT_CREATE_IN;
#define PVR_TL_TEST_CMD_SET_STREAM_OPEN_COUNTER 37
#define PVR_TL_TEST_CMD_GET_STREAM_OPEN_COUNTER 38
typedef struct _PVR_TL_TEST_CMD_STREAM_OPEN_COUNTER_IN_
{
IMG_CHAR pszStreamName[PRVSRVTL_MAX_STREAM_NAME_SIZE];
IMG_UINT32 ui32Counter;
} PVR_TL_TEST_CMD_STREAM_OPEN_COUNTER_IN;
/****************************************************************************
* KmallocThreshold IOCTL types
*/
#define PVR_TL_TEST_CMD_KMALLOC 39
typedef struct _PVR_TL_TEST_CMD_KMALLOC_IN_
{
IMG_UINT32 uiAllocCount;
IMG_UINT32 uiAllocSize;
IMG_UINT32 uiFailedAllocThreshold;
IMG_UINT32 uiFailedAllocFrequency;
} PVR_TL_TEST_CMD_KMALLOC_IN;
/****************************************************************************
* ZombiePMRCount IOCTL types
*/
#define PVR_TL_TEST_CMD_FLUSH_ZOMBIE_PMRS 40
#define PVR_TL_TEST_CMD_ZOMBIE_PMR_COUNT 41
#endif /* TUTILSDEFS_H */
/******************************************************************************
End of file (tutilsdefs.h)
******************************************************************************/