blob: b07a4bb520b54e2e7d436c8c09e192294d2eab3a [file] [log] [blame]
/*************************************************************************/ /*!
@File
@Title System Configuration
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@Description System Configuration functions
@License MIT
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.
This License is also included in this distribution in the file called
"MIT-COPYING".
EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ /**************************************************************************/
#include <thread>
extern "C" {
#include "sysinfo.h"
#include "pvrsrv_device.h"
#include "rgxdevice.h"
#include "syscommon.h"
}
#include "fuchsia/fuchsia_sys_info.h"
#include "fuchsia/msd_img_device.h"
#define NOT_IMPLEMENTED() fprintf(stderr, "msd-img-rgx-mtk:Not implemented in %s:%s:%d\n", __func__, __FILE__, __LINE__);
class LisrData
{
public:
LisrData(PFN_LISR pfnLISR, void *pvData, std::unique_ptr<magma::PlatformInterrupt> interrupt)
: pfnLISR_(pfnLISR), pvData_(pvData), interrupt_(std::move(interrupt))
{
}
~LisrData()
{
interrupt_->Signal();
if (thrd_.joinable())
thrd_.join();
}
void StartThread()
{
thrd_ = std::thread([this]() { ProcessInterrupts(); });
}
private:
void ProcessInterrupts()
{
while (true)
{
if (!interrupt_->Wait())
{
DLOG("Interrupt thread exiting");
break;
}
pfnLISR_(pvData_);
}
}
PFN_LISR pfnLISR_;
void *pvData_;
std::thread thrd_;
std::unique_ptr<magma::PlatformInterrupt> interrupt_;
};
static void
UMAPhysHeapCpuPAddrToDevPAddr(IMG_HANDLE hPrivData,
IMG_UINT32 ui32NumOfAddr,
IMG_DEV_PHYADDR *psDevPAddr,
IMG_CPU_PHYADDR *psCpuPAddr)
{
PVR_UNREFERENCED_PARAMETER(hPrivData);
/* Optimise common case */
psDevPAddr[0].uiAddr = psCpuPAddr[0].uiAddr;
if (ui32NumOfAddr > 1)
{
IMG_UINT32 ui32Idx;
for (ui32Idx = 1; ui32Idx < ui32NumOfAddr; ++ui32Idx)
{
psDevPAddr[ui32Idx].uiAddr = psCpuPAddr[ui32Idx].uiAddr;
}
}
}
/*
Device to CPU physical address translation
*/
static void
UMAPhysHeapDevPAddrToCpuPAddr(IMG_HANDLE hPrivData,
IMG_UINT32 ui32NumOfAddr,
IMG_CPU_PHYADDR *psCpuPAddr,
IMG_DEV_PHYADDR *psDevPAddr)
{
PVR_UNREFERENCED_PARAMETER(hPrivData);
/* Optimise common case */
psCpuPAddr[0].uiAddr = psDevPAddr[0].uiAddr;
if (ui32NumOfAddr > 1)
{
IMG_UINT32 ui32Idx;
for (ui32Idx = 1; ui32Idx < ui32NumOfAddr; ++ui32Idx)
{
psCpuPAddr[ui32Idx].uiAddr = psDevPAddr[ui32Idx].uiAddr;
}
}
}
/* BIF Tiling mode configuration */
static RGXFWIF_BIFTILINGMODE geBIFTilingMode = RGXFWIF_BIFTILINGMODE_256x16;
/* default BIF tiling heap x-stride configurations. */
static IMG_UINT32 gauiBIFTilingHeapXStrides[RGXFWIF_NUM_BIF_TILING_CONFIGS] = {
0, /* BIF tiling heap 1 x-stride */
1, /* BIF tiling heap 2 x-stride */
2, /* BIF tiling heap 3 x-stride */
3 /* BIF tiling heap 4 x-stride */
};
// MT8167s. The default clock speed is actually 400 MHz, but it can be scaled up
// if necessary.
static char pdump_namespace_name_s[] = "SYSMEM";
static char device_name_s[] = "mt8167-gpu";
PVRSRV_ERROR
SysDevInit(void *pvOSDevice, PVRSRV_DEVICE_CONFIG **ppsDevConfig)
{
MsdImgDevice *msd_device = reinterpret_cast<MsdImgDevice *>(pvOSDevice);
FuchsiaSysInfo *sys_info = msd_device->sys_info();
/*
* Setup information about physical memory heap(s) we have
*/
sys_info->physHeapFuncs.pfnCpuPAddrToDevPAddr = UMAPhysHeapCpuPAddrToDevPAddr;
sys_info->physHeapFuncs.pfnDevPAddrToCpuPAddr = UMAPhysHeapDevPAddrToCpuPAddr;
sys_info->physHeapConfig[0].ui32PhysHeapID = 0u;
sys_info->physHeapConfig[0].pszPDumpMemspaceName = pdump_namespace_name_s;
sys_info->physHeapConfig[0].eType = PHYS_HEAP_TYPE_UMA;
sys_info->physHeapConfig[0].psMemFuncs = &sys_info->physHeapFuncs;
sys_info->physHeapConfig[0].hPrivData = NULL;
constexpr uint32_t kRgxHwCoreClockSpeed = 500'000'000;
constexpr uint32_t kRgxActivePowerLatencyMs = 50;
/*
* Setup RGX specific timing data
*/
sys_info->RGXTimingInfo.ui32CoreClockSpeed = kRgxHwCoreClockSpeed;
sys_info->RGXTimingInfo.bEnableActivePM = IMG_TRUE;
sys_info->RGXTimingInfo.bEnableRDPowIsland = IMG_TRUE;
sys_info->RGXTimingInfo.ui32ActivePMLatencyms = kRgxActivePowerLatencyMs;
/*
*Setup RGX specific data
*/
sys_info->RGXData.psRGXTimingInfo = &sys_info->RGXTimingInfo;
/*
* Setup device
*/
sys_info->device.pvOSDevice = pvOSDevice;
sys_info->device.pszName = device_name_s;
sys_info->device.pszVersion = NULL;
/* Device's physical heaps */
sys_info->device.pasPhysHeaps = sys_info->physHeapConfig;
sys_info->device.ui32PhysHeapCount = ARRAY_SIZE(sys_info->physHeapConfig);
sys_info->device.hSysData = pvOSDevice;
/* Device's physical heap IDs */
sys_info->device.aui32PhysHeapID[PVRSRV_DEVICE_PHYS_HEAP_GPU_LOCAL] = 0;
sys_info->device.aui32PhysHeapID[PVRSRV_DEVICE_PHYS_HEAP_CPU_LOCAL] = 0;
sys_info->device.aui32PhysHeapID[PVRSRV_DEVICE_PHYS_HEAP_FW_LOCAL] = 0;
sys_info->device.aui32PhysHeapID[PVRSRV_DEVICE_PHYS_HEAP_EXTERNAL] = 0;
sys_info->device.eBIFTilingMode = geBIFTilingMode;
sys_info->device.pui32BIFTilingHeapConfigs = gauiBIFTilingHeapXStrides;
sys_info->device.ui32BIFTilingHeapCount = ARRAY_SIZE(gauiBIFTilingHeapXStrides);
// TODO(MA-581) - Enable. The GPU is currently always powered on for now.
sys_info->device.pfnPrePowerState = NULL;
sys_info->device.pfnPostPowerState = nullptr;
/* No clock frequency */
sys_info->device.pfnClockFreqGet = NULL;
sys_info->device.hDevData = &sys_info->RGXData;
sys_info->device.eCacheSnoopingMode = PVRSRV_DEVICE_SNOOP_NONE;
sys_info->device.pfnSysDriverMode = NULL;
sys_info->device.sRegsCpuPBase.uiAddr = MsdImgDevice::GetRegistersPhysicalAddress();
sys_info->device.ui32RegsSize = msd_device->mmio()->size();
sys_info->device.ui32IRQ = 1;
*ppsDevConfig = &sys_info->device;
return PVRSRV_OK;
}
void
SysDevDeInit(PVRSRV_DEVICE_CONFIG *psDevConfig)
{
NOT_IMPLEMENTED();
}
PVRSRV_ERROR
SysDebugInfo(PVRSRV_DEVICE_CONFIG *psDevConfig, DUMPDEBUG_PRINTF_FUNC *pfnDumpDebugPrintf, void *pvDumpDebugFile)
{
NOT_IMPLEMENTED();
return PVRSRV_ERROR_NOT_SUPPORTED;
}
PVRSRV_ERROR
SysInstallDeviceLISR(IMG_HANDLE hSysData,
IMG_UINT32 ui32IRQ,
const IMG_CHAR *pszName,
PFN_LISR pfnLISR,
void *pvData,
IMG_HANDLE *phLISRData)
{
MsdImgDevice *device = MsdImgDevice::cast(hSysData);
std::unique_ptr<magma::PlatformInterrupt> interrupt = device->interrupt();
if (!interrupt)
{
return DRET(PVRSRV_ERROR_UNABLE_TO_INITIALISE_INTERRUPT);
}
auto lisr_data = std::make_unique<LisrData>(pfnLISR, pvData, std::move(interrupt));
lisr_data->StartThread();
*phLISRData = lisr_data.release();
return PVRSRV_OK;
}
PVRSRV_ERROR
SysUninstallDeviceLISR(IMG_HANDLE hLISRData)
{
auto lisr_data = reinterpret_cast<LisrData *>(hLISRData);
delete lisr_data;
return PVRSRV_OK;
}