mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 23:03:02 +08:00
Enable Windows Os Layer for Sysman
Adding KmdSysman with ULT Change-Id: If080e6327171d3634a0c461c4169ea8c84461e13
This commit is contained in:
committed by
sys_ocldev
parent
acc4a44b15
commit
278505ca4d
@@ -7,6 +7,9 @@
|
||||
set(L0_SRCS_TOOLS_SYSMAN_WINDOWS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kmd_sys.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kmd_sys_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kmd_sys_manager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_sysman_imp.cpp)
|
||||
|
||||
if(WIN32)
|
||||
|
||||
516
level_zero/tools/source/sysman/windows/kmd_sys.h
Normal file
516
level_zero/tools/source/sysman/windows/kmd_sys.h
Normal file
@@ -0,0 +1,516 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
namespace KmdSysman {
|
||||
constexpr uint32_t KmdMaxBufferSize = 2048;
|
||||
constexpr uint32_t MaxPropertyBufferSize = 128;
|
||||
constexpr uint32_t PcEscapeOperation = 35;
|
||||
constexpr uint32_t KmdSysmanSuccess = 0;
|
||||
constexpr uint32_t KmdSysmanFail = 1;
|
||||
constexpr uint32_t KmdMajorVersion = 1;
|
||||
constexpr uint32_t KmdMinorVersion = 0;
|
||||
constexpr uint32_t KmdPatchNumber = 0;
|
||||
|
||||
struct GfxSysmanMainHeaderIn {
|
||||
uint32_t inVersion;
|
||||
uint32_t inNumElements;
|
||||
uint32_t inTotalsize;
|
||||
uint8_t inBuffer[KmdMaxBufferSize];
|
||||
};
|
||||
|
||||
struct GfxSysmanMainHeaderOut {
|
||||
uint32_t outStatus;
|
||||
uint32_t outNumElements;
|
||||
uint32_t outTotalSize;
|
||||
uint8_t outBuffer[KmdMaxBufferSize];
|
||||
};
|
||||
|
||||
struct GfxSysmanReqHeaderIn {
|
||||
uint32_t inRequestId;
|
||||
uint32_t inCommand;
|
||||
uint32_t inComponent;
|
||||
uint32_t inCommandParam;
|
||||
uint32_t inDataSize;
|
||||
};
|
||||
|
||||
struct GfxSysmanReqHeaderOut {
|
||||
uint32_t outRequestId;
|
||||
uint32_t outComponent;
|
||||
uint32_t outReturnCode;
|
||||
uint32_t outDataSize;
|
||||
};
|
||||
|
||||
enum Command {
|
||||
Get = 0,
|
||||
Set,
|
||||
RegisterEvent,
|
||||
UnregisterEvent,
|
||||
|
||||
MaxCommands,
|
||||
};
|
||||
|
||||
enum Events {
|
||||
EnergyThresholdCrossed = 0,
|
||||
EnterD0,
|
||||
EnterD3,
|
||||
EnterTDR,
|
||||
ExitTDR,
|
||||
FrequencyThrottled,
|
||||
CriticalTemperature,
|
||||
TemperatureThreshold1,
|
||||
TemperatureThreshold2,
|
||||
ResetDeviceRequired,
|
||||
|
||||
MaxEvents,
|
||||
};
|
||||
|
||||
enum Component {
|
||||
InterfaceProperties = 0,
|
||||
PowerComponent,
|
||||
FrequencyComponent,
|
||||
ActivityComponent,
|
||||
FanComponent,
|
||||
TemperatureComponent,
|
||||
FpsComponent,
|
||||
SchedulerComponent,
|
||||
MemoryComponent,
|
||||
PciComponent,
|
||||
|
||||
MaxComponents,
|
||||
};
|
||||
|
||||
namespace Requests {
|
||||
|
||||
enum Interface {
|
||||
InterfaceVersion = 0,
|
||||
|
||||
MaxInterfaceRequests,
|
||||
};
|
||||
|
||||
enum Power {
|
||||
NumPowerDomains = 0,
|
||||
|
||||
// support / enabled
|
||||
EnergyThresholdSupported,
|
||||
EnergyThresholdEnabled,
|
||||
PowerLimit1Enabled,
|
||||
PowerLimit2Enabled,
|
||||
|
||||
// default fused values
|
||||
PowerLimit1Default,
|
||||
PowerLimit2Default,
|
||||
PowerLimit1TauDefault,
|
||||
PowerLimit4AcDefault,
|
||||
PowerLimit4DcDefault,
|
||||
EnergyThresholdDefault,
|
||||
TdpDefault,
|
||||
MinPowerLimitDefault,
|
||||
MaxPowerLimitDefault,
|
||||
EnergyCounterUnits,
|
||||
|
||||
// current runtime values
|
||||
CurrentPowerLimit1,
|
||||
CurrentPowerLimit2,
|
||||
CurrentPowerLimit1Tau,
|
||||
CurrentPowerLimit4Ac,
|
||||
CurrentPowerLimit4Dc,
|
||||
CurrentEnergyThreshold,
|
||||
DisableEnergyThreshold,
|
||||
CurrentEnergyCounter,
|
||||
|
||||
MaxPowerRequests,
|
||||
};
|
||||
|
||||
enum Activity {
|
||||
NumActivityDomains = 0,
|
||||
|
||||
// default fused values
|
||||
ActivityCounterNumberOfBits,
|
||||
ActivityCounterFrequency,
|
||||
TimestampFrequency,
|
||||
|
||||
// current runtime values
|
||||
CurrentActivityCounter,
|
||||
|
||||
MaxActivityRequests,
|
||||
};
|
||||
|
||||
enum Temperature {
|
||||
NumTemperatureDomains = 0,
|
||||
|
||||
// support / enabled
|
||||
TempCriticalEventSupported,
|
||||
TempThreshold1EventSupported,
|
||||
TempThreshold2EventSupported,
|
||||
TempCriticalEventEnabled,
|
||||
TempThreshold1EventEnabled,
|
||||
TempThreshold2EventEnabled,
|
||||
|
||||
// default fused values
|
||||
MaxTempSupported,
|
||||
|
||||
// current runtime values
|
||||
CurrentTemperature,
|
||||
|
||||
MaxTemperatureRequests,
|
||||
};
|
||||
|
||||
enum Frequency {
|
||||
NumFrequencyDomains = 0,
|
||||
|
||||
// support / enabled
|
||||
FrequencyOcSupported,
|
||||
VoltageOverrideSupported,
|
||||
VoltageOffsetSupported,
|
||||
HighVoltageModeSupported,
|
||||
ExtendedOcSupported,
|
||||
FixedModeSupported,
|
||||
HighVoltageEnabled,
|
||||
CanControlFrequency,
|
||||
FrequencyThrottledEventSupported,
|
||||
|
||||
// default fused values
|
||||
TjMaxDefault,
|
||||
IccMaxDefault,
|
||||
MaxOcFrequencyDefault,
|
||||
MaxNonOcFrequencyDefault,
|
||||
MaxOcVoltageDefault,
|
||||
MaxNonOcVoltageDefault,
|
||||
FrequencyRangeMinDefault,
|
||||
FrequencyRangeMaxDefault,
|
||||
|
||||
// current runtime values
|
||||
CurrentFrequencyTarget,
|
||||
CurrentVoltageTarget,
|
||||
CurrentVoltageOffset,
|
||||
CurrentVoltageMode,
|
||||
CurrentFixedMode,
|
||||
CurrentTjMax,
|
||||
CurrentIccMax,
|
||||
CurrentVoltage,
|
||||
CurrentRequestedFrequency,
|
||||
CurrentTdpFrequency,
|
||||
CurrentEfficientFrequency,
|
||||
CurrentResolvedFrequency,
|
||||
CurrentThrottleReasons,
|
||||
CurrentThrottleTime,
|
||||
CurrentFrequencyRange,
|
||||
|
||||
MaxFrequencyRequests,
|
||||
};
|
||||
|
||||
enum Fans {
|
||||
NumFanDomains = 0,
|
||||
|
||||
// default fused values
|
||||
MaxFanControlPointsSupported,
|
||||
MaxFanSpeedSupported,
|
||||
|
||||
// current runtime values
|
||||
CurrentNumOfControlPoints,
|
||||
CurrentFanPoint,
|
||||
CurrentFanSpeed,
|
||||
|
||||
MaxFanRequests,
|
||||
};
|
||||
|
||||
enum Fps {
|
||||
NumFpsDomains = 0,
|
||||
IsDisplayAttached,
|
||||
InstRenderTime,
|
||||
TimeToFlip,
|
||||
AvgFps,
|
||||
AvgRenderTime,
|
||||
AvgInstFps,
|
||||
|
||||
MaxFpsRequests,
|
||||
};
|
||||
|
||||
enum Scheduler {
|
||||
NumSchedulerDomains = 0,
|
||||
|
||||
MaxSchedulerRequests,
|
||||
};
|
||||
|
||||
enum Memory {
|
||||
NumMemoryDomains = 0,
|
||||
|
||||
// default fused values
|
||||
MemoryType,
|
||||
MemoryLocation,
|
||||
PhysicalSize,
|
||||
StolenSize,
|
||||
SystemSize,
|
||||
DedicatedSize,
|
||||
MemoryWidth,
|
||||
NumChannels,
|
||||
MaxBandwidth,
|
||||
|
||||
// current runtime values
|
||||
CurrentBandwidthRead,
|
||||
CurrentBandwidthWrite,
|
||||
CurrentFreeMemorySize,
|
||||
CurrentTotalAllocableMem,
|
||||
|
||||
MaxMemoryRequests
|
||||
};
|
||||
|
||||
enum Pci {
|
||||
NumPciDomains = 0,
|
||||
|
||||
// support / enabled
|
||||
BandwidthCountersSupported,
|
||||
PacketCountersSupported,
|
||||
ReplayCountersSupported,
|
||||
|
||||
// default fused values
|
||||
DeviceId,
|
||||
VendorId,
|
||||
Domain,
|
||||
Bus,
|
||||
Device,
|
||||
Function,
|
||||
Gen,
|
||||
DevType,
|
||||
MaxLinkWidth,
|
||||
MaxLinkSpeed,
|
||||
BusInterface,
|
||||
BusWidth,
|
||||
BarType,
|
||||
BarIndex,
|
||||
BarBase,
|
||||
BarSize,
|
||||
|
||||
// current runtime values
|
||||
CurrentLinkWidth,
|
||||
CurrentLinkSpeed,
|
||||
CurrentLinkStatus,
|
||||
CurrentLinkQualityFlags,
|
||||
CurrentLinkStabilityFlags,
|
||||
CurrentLinkReplayCounter,
|
||||
CurrentLinkPacketCounter,
|
||||
CurrentLinkRxCounter,
|
||||
CurrentLinkTxCounter,
|
||||
|
||||
MaxPciRequests,
|
||||
};
|
||||
} // namespace Requests
|
||||
|
||||
enum FlipType {
|
||||
MMIOFlip = 0,
|
||||
MMIOAsyncFlip,
|
||||
DMAFlip,
|
||||
DMAAsyncFlip,
|
||||
|
||||
MaxFlipTypes,
|
||||
};
|
||||
|
||||
enum GeneralDomainsType {
|
||||
GeneralDomainDGPU = 0,
|
||||
GeneralDomainHBM,
|
||||
|
||||
GeneralDomainMaxTypes,
|
||||
};
|
||||
|
||||
enum TemperatureDomainsType {
|
||||
TemperatureDomainPackage = 0,
|
||||
TemperatureDomainDGPU,
|
||||
TemperatureDomainHBM,
|
||||
|
||||
TempetatureMaxDomainTypes,
|
||||
};
|
||||
|
||||
enum ActivityDomainsType {
|
||||
ActitvityDomainGT = 0,
|
||||
ActivityDomainRenderCompute,
|
||||
ActivityDomainMedia,
|
||||
|
||||
ActivityDomainMaxTypes,
|
||||
};
|
||||
|
||||
enum PciDomainsType {
|
||||
PciCurrentDevice = 0,
|
||||
PciParentDevice,
|
||||
PciRootPort,
|
||||
|
||||
PciDomainMaxTypes,
|
||||
};
|
||||
|
||||
enum MemoryType {
|
||||
DDR4 = 0,
|
||||
DDR5,
|
||||
LPDDR5,
|
||||
LPDDR4,
|
||||
DDR3,
|
||||
LPDDR3,
|
||||
UknownMemType,
|
||||
|
||||
MaxMemoryTypes,
|
||||
};
|
||||
|
||||
enum MemoryWidthType {
|
||||
MemWidth8x = 0,
|
||||
MemWidth16x,
|
||||
MemWidth32x,
|
||||
|
||||
UnknownMemWidth,
|
||||
|
||||
MaxMemoryWidthTypes,
|
||||
};
|
||||
|
||||
enum MemoryLocationsType {
|
||||
SystemMemory = 0,
|
||||
DeviceMemory,
|
||||
|
||||
UnknownMemoryLocation,
|
||||
|
||||
MaxMemoryLocationTypes,
|
||||
};
|
||||
|
||||
enum PciGensType {
|
||||
PciGen1_1 = 0,
|
||||
PciGen2_0,
|
||||
PciGen3_0,
|
||||
PciGen4_0,
|
||||
|
||||
UnknownPciGen,
|
||||
|
||||
MaxPciGenTypes,
|
||||
};
|
||||
|
||||
enum PciLinkSpeedType {
|
||||
UnknownPciLinkSpeed = 0,
|
||||
PciLinkSpeed2_5 = 1,
|
||||
PciLinkSpeed5_0,
|
||||
PciLinkSpeed8_0,
|
||||
PciLinkSpeed16_0,
|
||||
|
||||
MaxPciLinkSpeedTypes,
|
||||
};
|
||||
|
||||
enum PciLinkWidthType {
|
||||
PciLinkWidth1x = 0,
|
||||
PciLinkWidth2x,
|
||||
PciLinkWidth4x,
|
||||
PciLinkWidth8x,
|
||||
PciLinkWidth12x,
|
||||
PciLinkWidth16x,
|
||||
PciLinkWidth32x,
|
||||
|
||||
UnknownPciLinkWidth,
|
||||
|
||||
MaxPciLinkWidthTypes,
|
||||
};
|
||||
|
||||
struct KmdSysmanVersion {
|
||||
KmdSysmanVersion() : data(0) {}
|
||||
union {
|
||||
struct {
|
||||
uint32_t reservedBits : 8;
|
||||
uint32_t majorVersion : 8;
|
||||
uint32_t minorVersion : 8;
|
||||
uint32_t patchNumber : 8;
|
||||
};
|
||||
uint32_t data;
|
||||
};
|
||||
};
|
||||
|
||||
struct RequestProperty {
|
||||
RequestProperty() : requestId(0), commandId(0), componentId(0), paramInfo(0), dataSize(0) {}
|
||||
RequestProperty(const RequestProperty &other) {
|
||||
requestId = other.requestId;
|
||||
commandId = other.commandId;
|
||||
componentId = other.componentId;
|
||||
paramInfo = other.paramInfo;
|
||||
dataSize = other.dataSize;
|
||||
if (other.dataSize > 0 && other.dataSize < MaxPropertyBufferSize && other.dataBuffer) {
|
||||
memcpy_s(dataBuffer, other.dataSize, other.dataBuffer, other.dataSize);
|
||||
}
|
||||
}
|
||||
RequestProperty(uint32_t _requestId,
|
||||
uint32_t _commandId,
|
||||
uint32_t _componentId,
|
||||
uint32_t _paramInfo,
|
||||
uint32_t _dataSize,
|
||||
uint8_t *_dataBuffer) {
|
||||
requestId = _requestId;
|
||||
commandId = _commandId;
|
||||
componentId = _componentId;
|
||||
paramInfo = _paramInfo;
|
||||
dataSize = _dataSize;
|
||||
if (dataSize > 0 && dataSize < MaxPropertyBufferSize && _dataBuffer) {
|
||||
memcpy_s(dataBuffer, dataSize, _dataBuffer, dataSize);
|
||||
}
|
||||
}
|
||||
RequestProperty &operator=(const RequestProperty &other) {
|
||||
requestId = other.requestId;
|
||||
commandId = other.commandId;
|
||||
componentId = other.componentId;
|
||||
paramInfo = other.paramInfo;
|
||||
dataSize = other.dataSize;
|
||||
if (other.dataSize > 0 && other.dataSize < MaxPropertyBufferSize && other.dataBuffer) {
|
||||
memcpy_s(dataBuffer, other.dataSize, other.dataBuffer, other.dataSize);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
uint32_t requestId;
|
||||
uint32_t commandId;
|
||||
uint32_t componentId;
|
||||
uint32_t paramInfo;
|
||||
uint32_t dataSize;
|
||||
uint8_t dataBuffer[MaxPropertyBufferSize];
|
||||
};
|
||||
|
||||
struct ResponseProperty {
|
||||
ResponseProperty() : requestId(0), returnCode(0), componentId(0), dataSize(0) {}
|
||||
ResponseProperty(const ResponseProperty &other) {
|
||||
requestId = other.requestId;
|
||||
returnCode = other.returnCode;
|
||||
componentId = other.componentId;
|
||||
dataSize = other.dataSize;
|
||||
if (other.dataSize > 0 && other.dataSize < MaxPropertyBufferSize && other.dataBuffer) {
|
||||
memcpy_s(dataBuffer, other.dataSize, other.dataBuffer, other.dataSize);
|
||||
}
|
||||
}
|
||||
ResponseProperty(uint32_t _requestId,
|
||||
uint32_t _returnCode,
|
||||
uint32_t _componentId,
|
||||
uint32_t _dataSize,
|
||||
uint8_t *_dataBuffer) {
|
||||
requestId = _requestId;
|
||||
returnCode = _returnCode;
|
||||
componentId = _componentId;
|
||||
dataSize = _dataSize;
|
||||
if (dataSize > 0 && dataSize < MaxPropertyBufferSize && _dataBuffer) {
|
||||
memcpy_s(dataBuffer, dataSize, _dataBuffer, dataSize);
|
||||
}
|
||||
}
|
||||
ResponseProperty &operator=(const ResponseProperty &other) {
|
||||
this->requestId = other.requestId;
|
||||
this->returnCode = other.returnCode;
|
||||
this->componentId = other.componentId;
|
||||
this->dataSize = other.dataSize;
|
||||
if (other.dataSize > 0 && other.dataSize < MaxPropertyBufferSize && other.dataBuffer) {
|
||||
memcpy_s(this->dataBuffer, other.dataSize, other.dataBuffer, other.dataSize);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
uint32_t requestId;
|
||||
uint32_t returnCode;
|
||||
uint32_t componentId;
|
||||
uint32_t dataSize;
|
||||
uint8_t dataBuffer[MaxPropertyBufferSize];
|
||||
};
|
||||
} // namespace KmdSysman
|
||||
} // namespace L0
|
||||
240
level_zero/tools/source/sysman/windows/kmd_sys_manager.cpp
Normal file
240
level_zero/tools/source/sysman/windows/kmd_sys_manager.cpp
Normal file
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/tools/source/sysman/windows/kmd_sys_manager.h"
|
||||
|
||||
#include "gfxEscape.h"
|
||||
|
||||
namespace L0 {
|
||||
struct PcEscapeInfo {
|
||||
GFX_ESCAPE_HEADER_T headerGfx;
|
||||
uint32_t escapeOpInput;
|
||||
uint32_t escapeErrorType;
|
||||
|
||||
uint32_t dataInSize;
|
||||
uint64_t pDataIn;
|
||||
|
||||
uint32_t dataOutSize;
|
||||
uint64_t pDataOut;
|
||||
};
|
||||
|
||||
uint32_t sumOfBufferData(void *pBuffer, uint32_t bufferSize) {
|
||||
uint32_t index;
|
||||
uint32_t ulCheckSum;
|
||||
uint32_t numOfUnsignedLongs = bufferSize / sizeof(uint32_t);
|
||||
uint32_t *pElement = static_cast<uint32_t *>(pBuffer);
|
||||
|
||||
ulCheckSum = 0;
|
||||
for (index = 0; index < numOfUnsignedLongs; index++) {
|
||||
ulCheckSum += *pElement;
|
||||
pElement++;
|
||||
}
|
||||
|
||||
return ulCheckSum;
|
||||
}
|
||||
|
||||
KmdSysManager::KmdSysManager(NEO::Wddm *pWddm) {
|
||||
pWddmAccess = pWddm;
|
||||
}
|
||||
|
||||
KmdSysManager *KmdSysManager::create(NEO::Wddm *pWddm) {
|
||||
return new KmdSysManager(pWddm);
|
||||
}
|
||||
ze_result_t KmdSysManager::requestSingle(KmdSysman::RequestProperty &inputRequest, KmdSysman::ResponseProperty &outputResponse) {
|
||||
KmdSysman::GfxSysmanMainHeaderIn inMainHeader;
|
||||
KmdSysman::GfxSysmanMainHeaderOut outMainHeader;
|
||||
|
||||
memset(&inMainHeader, 0, sizeof(KmdSysman::GfxSysmanMainHeaderIn));
|
||||
memset(&outMainHeader, 0, sizeof(KmdSysman::GfxSysmanMainHeaderOut));
|
||||
|
||||
std::vector<KmdSysman::RequestProperty> vectorInput;
|
||||
vectorInput.push_back(inputRequest);
|
||||
|
||||
if (!parseBufferIn(&inMainHeader, vectorInput)) {
|
||||
return ZE_RESULT_ERROR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
KmdSysman::KmdSysmanVersion versionKmd;
|
||||
versionKmd.data = 0;
|
||||
versionKmd.majorVersion = KmdSysman::KmdMajorVersion;
|
||||
versionKmd.minorVersion = KmdSysman::KmdMinorVersion;
|
||||
versionKmd.patchNumber = KmdSysman::KmdPatchNumber;
|
||||
|
||||
inMainHeader.inVersion = versionKmd.data;
|
||||
uint64_t inPointerToLongInt = reinterpret_cast<uint64_t>(&inMainHeader);
|
||||
uint64_t outPointerToLongInt = reinterpret_cast<uint64_t>(&outMainHeader);
|
||||
auto status = escape(KmdSysman::PcEscapeOperation, inPointerToLongInt, sizeof(KmdSysman::GfxSysmanMainHeaderIn),
|
||||
outPointerToLongInt, sizeof(KmdSysman::GfxSysmanMainHeaderOut));
|
||||
|
||||
if (status) {
|
||||
std::vector<KmdSysman::ResponseProperty> vecOutput;
|
||||
if (!parseBufferOut(&outMainHeader, vecOutput)) {
|
||||
return ZE_RESULT_ERROR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
if (vecOutput.size() > 0) {
|
||||
outputResponse = vecOutput[0];
|
||||
} else {
|
||||
return ZE_RESULT_ERROR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
return (outputResponse.returnCode == KmdSysman::KmdSysmanSuccess) ? ZE_RESULT_SUCCESS : ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
return (status) ? ZE_RESULT_SUCCESS : ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
ze_result_t KmdSysManager::requestMultiple(std::vector<KmdSysman::RequestProperty> &inputRequest, std::vector<KmdSysman::ResponseProperty> &outputResponse) {
|
||||
KmdSysman::GfxSysmanMainHeaderIn inMainHeader;
|
||||
KmdSysman::GfxSysmanMainHeaderOut outMainHeader;
|
||||
|
||||
if (inputRequest.size() == 0) {
|
||||
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
|
||||
}
|
||||
|
||||
memset(&inMainHeader, 0, sizeof(KmdSysman::GfxSysmanMainHeaderIn));
|
||||
memset(&outMainHeader, 0, sizeof(KmdSysman::GfxSysmanMainHeaderOut));
|
||||
|
||||
if (!parseBufferIn(&inMainHeader, inputRequest)) {
|
||||
return ZE_RESULT_ERROR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
KmdSysman::KmdSysmanVersion versionKmd;
|
||||
versionKmd.data = 0;
|
||||
versionKmd.majorVersion = 1;
|
||||
versionKmd.minorVersion = 0;
|
||||
versionKmd.patchNumber = 0;
|
||||
|
||||
inMainHeader.inVersion = versionKmd.data;
|
||||
uint64_t inPointerToLongInt = reinterpret_cast<uint64_t>(&inMainHeader);
|
||||
uint64_t outPointerToLongInt = reinterpret_cast<uint64_t>(&outMainHeader);
|
||||
auto status = escape(KmdSysman::PcEscapeOperation, inPointerToLongInt, sizeof(KmdSysman::GfxSysmanMainHeaderIn),
|
||||
outPointerToLongInt, sizeof(KmdSysman::GfxSysmanMainHeaderOut));
|
||||
|
||||
if (status) {
|
||||
if (!parseBufferOut(&outMainHeader, outputResponse)) {
|
||||
return ZE_RESULT_ERROR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
if (outputResponse.size() == 0) {
|
||||
return ZE_RESULT_ERROR_INVALID_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
return (status) ? ZE_RESULT_SUCCESS : ZE_RESULT_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
bool KmdSysManager::escape(uint32_t escapeOp, uint64_t pDataIn, uint32_t dataInSize, uint64_t pDataOut, uint32_t dataOutSize) {
|
||||
if (pWddmAccess) {
|
||||
D3DKMT_ESCAPE escapeCommand = {0};
|
||||
PcEscapeInfo pcEscape = {0};
|
||||
escapeCommand.Flags.HardwareAccess = 0;
|
||||
escapeCommand.Flags.Reserved = 0;
|
||||
escapeCommand.hAdapter = (D3DKMT_HANDLE)0;
|
||||
escapeCommand.hContext = (D3DKMT_HANDLE)0;
|
||||
escapeCommand.hDevice = (D3DKMT_HANDLE)pWddmAccess->getDevice();
|
||||
escapeCommand.pPrivateDriverData = &pcEscape;
|
||||
escapeCommand.PrivateDriverDataSize = sizeof(pcEscape);
|
||||
escapeCommand.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
|
||||
|
||||
pcEscape.headerGfx.EscapeCode = GFX_ESCAPE_PWRCONS_CONTROL;
|
||||
pcEscape.escapeErrorType = 0;
|
||||
pcEscape.escapeOpInput = escapeOp;
|
||||
pcEscape.headerGfx.Size = sizeof(pcEscape) - sizeof(pcEscape.headerGfx);
|
||||
|
||||
pcEscape.pDataIn = pDataIn;
|
||||
pcEscape.pDataOut = pDataOut;
|
||||
|
||||
pcEscape.dataInSize = dataInSize;
|
||||
pcEscape.dataOutSize = dataOutSize;
|
||||
void *pBuffer = &pcEscape;
|
||||
pBuffer = reinterpret_cast<uint8_t *>(pBuffer) + sizeof(pcEscape.headerGfx);
|
||||
pcEscape.headerGfx.CheckSum = sumOfBufferData(pBuffer, pcEscape.headerGfx.Size);
|
||||
|
||||
auto status = pWddmAccess->escape(escapeCommand);
|
||||
if (status == STATUS_SUCCESS) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool KmdSysManager::parseBufferIn(KmdSysman::GfxSysmanMainHeaderIn *pInMainHeader, std::vector<KmdSysman::RequestProperty> &vectorInput) {
|
||||
memset(pInMainHeader, 0, sizeof(KmdSysman::GfxSysmanMainHeaderIn));
|
||||
for (uint32_t i = 0; i < vectorInput.size(); i++) {
|
||||
KmdSysman::GfxSysmanReqHeaderIn headerIn;
|
||||
headerIn.inRequestId = vectorInput[i].requestId;
|
||||
headerIn.inCommand = vectorInput[i].commandId;
|
||||
headerIn.inComponent = vectorInput[i].componentId;
|
||||
headerIn.inCommandParam = vectorInput[i].paramInfo;
|
||||
headerIn.inDataSize = vectorInput[i].dataSize;
|
||||
|
||||
if ((pInMainHeader->inTotalsize + sizeof(KmdSysman::GfxSysmanReqHeaderIn)) >= KmdSysman::KmdMaxBufferSize) {
|
||||
memset(pInMainHeader, 0, sizeof(KmdSysman::GfxSysmanMainHeaderIn));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((pInMainHeader->inTotalsize + sizeof(KmdSysman::GfxSysmanReqHeaderIn) + headerIn.inDataSize) >= KmdSysman::KmdMaxBufferSize) {
|
||||
memset(pInMainHeader, 0, sizeof(KmdSysman::GfxSysmanMainHeaderIn));
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t *pBuff = reinterpret_cast<uint8_t *>(&pInMainHeader->inBuffer[pInMainHeader->inTotalsize]);
|
||||
memcpy_s(pBuff, sizeof(KmdSysman::GfxSysmanReqHeaderIn), &headerIn, sizeof(KmdSysman::GfxSysmanReqHeaderIn));
|
||||
|
||||
pBuff += sizeof(KmdSysman::GfxSysmanReqHeaderIn);
|
||||
pInMainHeader->inTotalsize += sizeof(KmdSysman::GfxSysmanReqHeaderIn);
|
||||
|
||||
if (headerIn.inDataSize > 0) {
|
||||
memcpy_s(pBuff, headerIn.inDataSize, vectorInput[i].dataBuffer, headerIn.inDataSize);
|
||||
pInMainHeader->inTotalsize += headerIn.inDataSize;
|
||||
}
|
||||
|
||||
pInMainHeader->inNumElements++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KmdSysManager::parseBufferOut(KmdSysman::GfxSysmanMainHeaderOut *pOutMainHeader, std::vector<KmdSysman::ResponseProperty> &vectorOutput) {
|
||||
uint8_t *pBuff = reinterpret_cast<uint8_t *>(pOutMainHeader->outBuffer);
|
||||
uint32_t totalSize = 0;
|
||||
vectorOutput.clear();
|
||||
for (uint32_t i = 0; i < pOutMainHeader->outNumElements; i++) {
|
||||
KmdSysman::ResponseProperty propertyResponse;
|
||||
KmdSysman::GfxSysmanReqHeaderOut headerOut;
|
||||
|
||||
memcpy_s(&headerOut, sizeof(KmdSysman::GfxSysmanReqHeaderOut), pBuff, sizeof(KmdSysman::GfxSysmanReqHeaderOut));
|
||||
|
||||
propertyResponse.requestId = headerOut.outRequestId;
|
||||
propertyResponse.returnCode = headerOut.outReturnCode;
|
||||
propertyResponse.componentId = headerOut.outComponent;
|
||||
propertyResponse.dataSize = headerOut.outDataSize;
|
||||
|
||||
pBuff += sizeof(KmdSysman::GfxSysmanReqHeaderOut);
|
||||
|
||||
if (headerOut.outDataSize > 0) {
|
||||
memcpy_s(propertyResponse.dataBuffer, headerOut.outDataSize, pBuff, headerOut.outDataSize);
|
||||
pBuff += headerOut.outDataSize;
|
||||
}
|
||||
|
||||
vectorOutput.push_back(propertyResponse);
|
||||
|
||||
totalSize += sizeof(KmdSysman::GfxSysmanReqHeaderOut);
|
||||
totalSize += headerOut.outDataSize;
|
||||
}
|
||||
|
||||
if (totalSize != pOutMainHeader->outTotalSize) {
|
||||
vectorOutput.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
39
level_zero/tools/source/sysman/windows/kmd_sys_manager.h
Normal file
39
level_zero/tools/source/sysman/windows/kmd_sys_manager.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/os_interface/windows/os_interface.h"
|
||||
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
||||
|
||||
#include "level_zero/tools/source/sysman/windows/kmd_sys.h"
|
||||
#include "level_zero/ze_api.h"
|
||||
#include "level_zero/zet_api.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace L0 {
|
||||
class KmdSysManager {
|
||||
public:
|
||||
static KmdSysManager *create(NEO::Wddm *pWddm);
|
||||
KmdSysManager() = default;
|
||||
~KmdSysManager() = default;
|
||||
|
||||
MOCKABLE_VIRTUAL ze_result_t requestSingle(KmdSysman::RequestProperty &In, KmdSysman::ResponseProperty &Out);
|
||||
ze_result_t requestMultiple(std::vector<KmdSysman::RequestProperty> &vIn, std::vector<KmdSysman::ResponseProperty> &vOut);
|
||||
|
||||
private:
|
||||
MOCKABLE_VIRTUAL bool escape(uint32_t escapeOp, uint64_t pDataIn, uint32_t dataInSize, uint64_t pDataOut, uint32_t dataOutSize);
|
||||
|
||||
bool parseBufferIn(KmdSysman::GfxSysmanMainHeaderIn *pIn, std::vector<KmdSysman::RequestProperty> &vIn);
|
||||
bool parseBufferOut(KmdSysman::GfxSysmanMainHeaderOut *pOut, std::vector<KmdSysman::ResponseProperty> &vOut);
|
||||
|
||||
KmdSysManager(NEO::Wddm *pWddm);
|
||||
NEO::Wddm *pWddmAccess = nullptr;
|
||||
};
|
||||
} // namespace L0
|
||||
@@ -10,9 +10,41 @@
|
||||
namespace L0 {
|
||||
|
||||
ze_result_t WddmSysmanImp::init() {
|
||||
Device *pDevice = nullptr;
|
||||
if (pParentSysmanImp != nullptr) {
|
||||
pDevice = Device::fromHandle(pParentSysmanImp->hCoreDevice);
|
||||
} else if (pParentSysmanDeviceImp != nullptr) {
|
||||
pDevice = Device::fromHandle(pParentSysmanDeviceImp->hCoreDevice);
|
||||
} else {
|
||||
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
|
||||
}
|
||||
UNRECOVERABLE_IF(nullptr == pDevice);
|
||||
|
||||
NEO::OSInterface &OsInterface = pDevice->getOsInterface();
|
||||
pWddm = OsInterface.get()->getWddm();
|
||||
pKmdSysManager = KmdSysManager::create(pWddm);
|
||||
UNRECOVERABLE_IF(nullptr == pKmdSysManager);
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
NEO::Wddm &WddmSysmanImp::getWddm() {
|
||||
UNRECOVERABLE_IF(nullptr == pWddm);
|
||||
return *pWddm;
|
||||
}
|
||||
|
||||
KmdSysManager &WddmSysmanImp::getKmdSysManager() {
|
||||
UNRECOVERABLE_IF(nullptr == pKmdSysManager);
|
||||
return *pKmdSysManager;
|
||||
}
|
||||
|
||||
WddmSysmanImp::~WddmSysmanImp() {
|
||||
if (nullptr != pKmdSysManager) {
|
||||
delete pKmdSysManager;
|
||||
pKmdSysManager = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
OsSysman *OsSysman::create(SysmanImp *pParentSysmanImp) {
|
||||
WddmSysmanImp *pWddmSysmanImp = new WddmSysmanImp(pParentSysmanImp);
|
||||
return static_cast<OsSysman *>(pWddmSysmanImp);
|
||||
|
||||
@@ -7,23 +7,34 @@
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
#include "shared/source/os_interface/windows/os_interface.h"
|
||||
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
||||
|
||||
#include "level_zero/tools/source/sysman/sysman_imp.h"
|
||||
#include "level_zero/tools/source/sysman/windows/kmd_sys.h"
|
||||
#include "level_zero/tools/source/sysman/windows/kmd_sys_manager.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class WddmSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
WddmSysmanImp() = default;
|
||||
WddmSysmanImp(SysmanImp *pParentSysmanImp) : pParentSysmanImp(pParentSysmanImp){};
|
||||
WddmSysmanImp(SysmanDeviceImp *pParentSysmanDeviceImp) : pParentSysmanDeviceImp(pParentSysmanDeviceImp){};
|
||||
~WddmSysmanImp() override = default;
|
||||
~WddmSysmanImp() override;
|
||||
|
||||
ze_result_t init() override;
|
||||
|
||||
KmdSysManager &getKmdSysManager();
|
||||
NEO::Wddm &getWddm();
|
||||
|
||||
protected:
|
||||
KmdSysManager *pKmdSysManager = nullptr;
|
||||
|
||||
private:
|
||||
WddmSysmanImp() = delete;
|
||||
SysmanImp *pParentSysmanImp = nullptr;
|
||||
SysmanDeviceImp *pParentSysmanDeviceImp = nullptr;
|
||||
NEO::Wddm *pWddm = nullptr;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(WIN32)
|
||||
target_sources(${TARGET_NAME}
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mock_kmd_sys_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_sysman_manager.cpp
|
||||
)
|
||||
endif()
|
||||
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "level_zero/core/test/unit_tests/mock.h"
|
||||
#include "level_zero/tools/source/sysman/windows/os_sysman_imp.h"
|
||||
|
||||
#include "sysman/windows/kmd_sys_manager.h"
|
||||
|
||||
using ::testing::_;
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
class MockKmdSysManager : public KmdSysManager {};
|
||||
|
||||
constexpr uint32_t mockKmdVersionMajor = 1;
|
||||
constexpr uint32_t mockKmdVersionMinor = 0;
|
||||
constexpr uint32_t mockKmdPatchNumber = 0;
|
||||
|
||||
template <>
|
||||
struct Mock<MockKmdSysManager> : public MockKmdSysManager {
|
||||
|
||||
ze_bool_t allowSetCalls = false;
|
||||
|
||||
uint32_t mockPowerLimit1 = 2500;
|
||||
|
||||
MOCK_METHOD(bool, escape, (uint32_t escapeOp, uint64_t pDataIn, uint32_t dataInSize, uint64_t pDataOut, uint32_t dataOutSize));
|
||||
|
||||
MOCKABLE_VIRTUAL void getInterfaceProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void setInterfaceProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void getPowerProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pResponse);
|
||||
pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderOut);
|
||||
|
||||
if (pRequest->inRequestId == KmdSysman::Requests::Power::CurrentPowerLimit1) {
|
||||
uint32_t *pPl1 = reinterpret_cast<uint32_t *>(pBuffer);
|
||||
*pPl1 = mockPowerLimit1;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
|
||||
pResponse->outDataSize = sizeof(uint32_t);
|
||||
} else {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void setPowerProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pRequest);
|
||||
pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderIn);
|
||||
|
||||
if (pRequest->inRequestId == KmdSysman::Requests::Power::CurrentPowerLimit1) {
|
||||
uint32_t *pPl1 = reinterpret_cast<uint32_t *>(pBuffer);
|
||||
mockPowerLimit1 = *pPl1;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
|
||||
} else {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void getFrequencyProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void setFrequencyProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void getActivityProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void setActivityProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void getFanProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void setFanProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void getTemperatureProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void setTemperatureProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void getFpsProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void setFpsProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void getSchedulerProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void setSchedulerProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void getMemoryProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void setMemoryProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void getPciProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void setPciProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
}
|
||||
|
||||
void retrieveCorrectVersion(KmdSysman::GfxSysmanMainHeaderOut *pHeaderOut) {
|
||||
pHeaderOut->outNumElements = 1;
|
||||
pHeaderOut->outTotalSize = 0;
|
||||
|
||||
KmdSysman::GfxSysmanReqHeaderOut *pResponse = reinterpret_cast<KmdSysman::GfxSysmanReqHeaderOut *>(pHeaderOut->outBuffer);
|
||||
uint8_t *pBuffer = nullptr;
|
||||
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
|
||||
pResponse->outDataSize = sizeof(KmdSysman::KmdSysmanVersion);
|
||||
pBuffer = reinterpret_cast<uint8_t *>(pResponse);
|
||||
pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderOut);
|
||||
pHeaderOut->outTotalSize += sizeof(KmdSysman::GfxSysmanReqHeaderOut);
|
||||
|
||||
KmdSysman::KmdSysmanVersion *pCurrentVersion = reinterpret_cast<KmdSysman::KmdSysmanVersion *>(pBuffer);
|
||||
pCurrentVersion->majorVersion = mockKmdVersionMajor;
|
||||
pCurrentVersion->minorVersion = mockKmdVersionMinor;
|
||||
pCurrentVersion->patchNumber = mockKmdPatchNumber;
|
||||
|
||||
pHeaderOut->outTotalSize += sizeof(KmdSysman::KmdSysmanVersion);
|
||||
}
|
||||
|
||||
bool validateInputBuffer(KmdSysman::GfxSysmanMainHeaderIn *pHeaderIn) {
|
||||
uint32_t sizeCheck = pHeaderIn->inTotalsize;
|
||||
uint8_t *pBufferPtr = pHeaderIn->inBuffer;
|
||||
|
||||
for (uint32_t i = 0; i < pHeaderIn->inNumElements; i++) {
|
||||
KmdSysman::GfxSysmanReqHeaderIn *pRequest = reinterpret_cast<KmdSysman::GfxSysmanReqHeaderIn *>(pBufferPtr);
|
||||
if (pRequest->inCommand == KmdSysman::Command::Get || pRequest->inCommand == KmdSysman::Command::Set) {
|
||||
if (pRequest->inComponent >= KmdSysman::Component::InterfaceProperties && pRequest->inComponent < KmdSysman::Component::MaxComponents) {
|
||||
pBufferPtr += sizeof(KmdSysman::GfxSysmanReqHeaderIn);
|
||||
sizeCheck -= sizeof(KmdSysman::GfxSysmanReqHeaderIn);
|
||||
|
||||
if (pRequest->inCommand == KmdSysman::Command::Set) {
|
||||
if (pRequest->inDataSize == 0) {
|
||||
return false;
|
||||
}
|
||||
pBufferPtr += pRequest->inDataSize;
|
||||
sizeCheck -= pRequest->inDataSize;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (sizeCheck != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void setProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
if (!allowSetCalls) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (pRequest->inComponent) {
|
||||
case KmdSysman::Component::InterfaceProperties: {
|
||||
setInterfaceProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::PowerComponent: {
|
||||
setPowerProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::FrequencyComponent: {
|
||||
setFrequencyProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::ActivityComponent: {
|
||||
setActivityProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::FanComponent: {
|
||||
setFanProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::TemperatureComponent: {
|
||||
setTemperatureProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::FpsComponent: {
|
||||
setFpsProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::SchedulerComponent: {
|
||||
setSchedulerProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::MemoryComponent: {
|
||||
setMemoryProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::PciComponent: {
|
||||
setPciProperty(pRequest, pResponse);
|
||||
} break;
|
||||
default: {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void getProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) {
|
||||
switch (pRequest->inComponent) {
|
||||
case KmdSysman::Component::InterfaceProperties: {
|
||||
getInterfaceProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::PowerComponent: {
|
||||
getPowerProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::FrequencyComponent: {
|
||||
getFrequencyProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::ActivityComponent: {
|
||||
getActivityProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::FanComponent: {
|
||||
getFanProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::TemperatureComponent: {
|
||||
getTemperatureProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::FpsComponent: {
|
||||
getFpsProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::SchedulerComponent: {
|
||||
getSchedulerProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::MemoryComponent: {
|
||||
getMemoryProperty(pRequest, pResponse);
|
||||
} break;
|
||||
case KmdSysman::Component::PciComponent: {
|
||||
getPciProperty(pRequest, pResponse);
|
||||
} break;
|
||||
default: {
|
||||
pResponse->outDataSize = 0;
|
||||
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
bool mock_escape(uint32_t escapeOp, uint64_t pInPtr, uint32_t dataInSize, uint64_t pOutPtr, uint32_t dataOutSize) {
|
||||
void *pDataIn = reinterpret_cast<void *>(pInPtr);
|
||||
void *pDataOut = reinterpret_cast<void *>(pOutPtr);
|
||||
|
||||
if (pDataIn == nullptr || pDataOut == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dataInSize != sizeof(KmdSysman::GfxSysmanMainHeaderIn) || dataOutSize != sizeof(KmdSysman::GfxSysmanMainHeaderOut)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (escapeOp != KmdSysman::PcEscapeOperation) {
|
||||
return false;
|
||||
}
|
||||
|
||||
KmdSysman::GfxSysmanMainHeaderIn *pSysmanMainHeaderIn = reinterpret_cast<KmdSysman::GfxSysmanMainHeaderIn *>(pDataIn);
|
||||
KmdSysman::GfxSysmanMainHeaderOut *pSysmanMainHeaderOut = reinterpret_cast<KmdSysman::GfxSysmanMainHeaderOut *>(pDataOut);
|
||||
|
||||
KmdSysman::KmdSysmanVersion versionSysman;
|
||||
versionSysman.data = pSysmanMainHeaderIn->inVersion;
|
||||
|
||||
if (versionSysman.majorVersion != KmdSysman::KmdMajorVersion) {
|
||||
if (versionSysman.majorVersion == 0) {
|
||||
retrieveCorrectVersion(pSysmanMainHeaderOut);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pSysmanMainHeaderIn->inTotalsize == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pSysmanMainHeaderIn->inNumElements == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!validateInputBuffer(pSysmanMainHeaderIn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t *pBufferIn = pSysmanMainHeaderIn->inBuffer;
|
||||
uint8_t *pBufferOut = pSysmanMainHeaderOut->outBuffer;
|
||||
uint32_t requestOffset = 0;
|
||||
uint32_t responseOffset = 0;
|
||||
pSysmanMainHeaderOut->outTotalSize = 0;
|
||||
|
||||
for (uint32_t i = 0; i < pSysmanMainHeaderIn->inNumElements; i++) {
|
||||
KmdSysman::GfxSysmanReqHeaderIn *pRequest = reinterpret_cast<KmdSysman::GfxSysmanReqHeaderIn *>(pBufferIn);
|
||||
KmdSysman::GfxSysmanReqHeaderOut *pResponse = reinterpret_cast<KmdSysman::GfxSysmanReqHeaderOut *>(pBufferOut);
|
||||
|
||||
switch (pRequest->inCommand) {
|
||||
case KmdSysman::Command::Get: {
|
||||
getProperty(pRequest, pResponse);
|
||||
requestOffset = sizeof(KmdSysman::GfxSysmanReqHeaderIn);
|
||||
responseOffset = sizeof(KmdSysman::GfxSysmanReqHeaderOut);
|
||||
responseOffset += pResponse->outDataSize;
|
||||
} break;
|
||||
case KmdSysman::Command::Set: {
|
||||
setProperty(pRequest, pResponse);
|
||||
requestOffset = sizeof(KmdSysman::GfxSysmanReqHeaderIn);
|
||||
requestOffset += pRequest->inDataSize;
|
||||
responseOffset = sizeof(KmdSysman::GfxSysmanReqHeaderOut);
|
||||
} break;
|
||||
default: {
|
||||
return false;
|
||||
} break;
|
||||
}
|
||||
|
||||
pResponse->outRequestId = pRequest->inRequestId;
|
||||
pResponse->outComponent = pRequest->inComponent;
|
||||
pBufferIn += requestOffset;
|
||||
pBufferOut += responseOffset;
|
||||
pSysmanMainHeaderOut->outTotalSize += responseOffset;
|
||||
}
|
||||
|
||||
pSysmanMainHeaderOut->outNumElements = pSysmanMainHeaderIn->inNumElements;
|
||||
pSysmanMainHeaderOut->outStatus = KmdSysman::KmdSysmanSuccess;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Mock() = default;
|
||||
~Mock() = default;
|
||||
};
|
||||
|
||||
class PublicWddmSysmanImp : public L0::WddmSysmanImp {
|
||||
public:
|
||||
using WddmSysmanImp::pKmdSysManager;
|
||||
};
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h"
|
||||
#include "level_zero/tools/source/sysman/sysman_imp.h"
|
||||
#include "level_zero/tools/source/sysman/windows/os_sysman_imp.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "mock_kmd_sys_manager.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::DoAll;
|
||||
using ::testing::InSequence;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::Return;
|
||||
|
||||
namespace L0 {
|
||||
namespace ult {
|
||||
|
||||
class SysmanKmdManagerFixture : public ::testing::Test {
|
||||
|
||||
protected:
|
||||
std::unique_ptr<SysmanImp> sysmanImp;
|
||||
zet_sysman_handle_t hSysman;
|
||||
Mock<MockKmdSysManager> *pKmdSysManager = nullptr;
|
||||
OsSysman *pOsSysman = nullptr;
|
||||
PublicWddmSysmanImp wddmSysmanImp;
|
||||
|
||||
void SetUp() {
|
||||
;
|
||||
pKmdSysManager = new Mock<MockKmdSysManager>;
|
||||
|
||||
EXPECT_CALL(*pKmdSysManager, escape(_, _, _, _, _))
|
||||
.WillRepeatedly(::testing::Invoke(pKmdSysManager, &Mock<MockKmdSysManager>::mock_escape));
|
||||
}
|
||||
void TearDown() override {
|
||||
if (pKmdSysManager != nullptr) {
|
||||
delete pKmdSysManager;
|
||||
pKmdSysManager = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SysmanKmdManagerFixture, CheckRequestSingleSucceedsAndPowerValueIsRetreivedCorrectlyAllowingSetToFalse) {
|
||||
pKmdSysManager->allowSetCalls = false;
|
||||
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
KmdSysman::RequestProperty request;
|
||||
KmdSysman::ResponseProperty response;
|
||||
|
||||
request.commandId = KmdSysman::Command::Get;
|
||||
request.componentId = KmdSysman::Component::PowerComponent;
|
||||
request.requestId = KmdSysman::Requests::Power::CurrentPowerLimit1;
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
uint32_t value = 0;
|
||||
memcpy_s(&value, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
|
||||
value = static_cast<uint32_t>(value);
|
||||
|
||||
EXPECT_EQ(value, pKmdSysManager->mockPowerLimit1);
|
||||
}
|
||||
|
||||
TEST_F(SysmanKmdManagerFixture, CheckRequestSingleSucceedsAndPowerValueIsRetreivedChangedSetThenRetreivedAgainCorrectlyAllowingSetToTrue) {
|
||||
pKmdSysManager->allowSetCalls = true;
|
||||
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
KmdSysman::RequestProperty request;
|
||||
KmdSysman::ResponseProperty response;
|
||||
|
||||
constexpr uint32_t increase = 500;
|
||||
uint32_t iniitialPl1 = pKmdSysManager->mockPowerLimit1;
|
||||
|
||||
request.commandId = KmdSysman::Command::Get;
|
||||
request.componentId = KmdSysman::Component::PowerComponent;
|
||||
request.requestId = KmdSysman::Requests::Power::CurrentPowerLimit1;
|
||||
request.dataSize = 0;
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
uint32_t value = 0;
|
||||
memcpy_s(&value, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
|
||||
value = static_cast<uint32_t>(value);
|
||||
|
||||
EXPECT_EQ(value, iniitialPl1);
|
||||
|
||||
value += increase;
|
||||
|
||||
request.commandId = KmdSysman::Command::Set;
|
||||
request.componentId = KmdSysman::Component::PowerComponent;
|
||||
request.requestId = KmdSysman::Requests::Power::CurrentPowerLimit1;
|
||||
request.dataSize = sizeof(uint32_t);
|
||||
|
||||
memcpy_s(request.dataBuffer, sizeof(uint32_t), &value, sizeof(uint32_t));
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
request.commandId = KmdSysman::Command::Get;
|
||||
request.componentId = KmdSysman::Component::PowerComponent;
|
||||
request.requestId = KmdSysman::Requests::Power::CurrentPowerLimit1;
|
||||
request.dataSize = 0;
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
value = 0;
|
||||
memcpy_s(&value, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
|
||||
value = static_cast<uint32_t>(value);
|
||||
|
||||
EXPECT_EQ(value, (iniitialPl1 + increase));
|
||||
}
|
||||
|
||||
TEST_F(SysmanKmdManagerFixture, CheckRequestSingleGetCommandWithCorruptInformationVerifyCallFails) {
|
||||
pKmdSysManager->allowSetCalls = false;
|
||||
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
KmdSysman::RequestProperty request;
|
||||
KmdSysman::ResponseProperty response;
|
||||
|
||||
request.commandId = KmdSysman::Command::Get;
|
||||
request.componentId = KmdSysman::Component::PowerComponent;
|
||||
request.requestId = KmdSysman::Requests::Power::CurrentPowerLimit1;
|
||||
request.dataSize = sizeof(uint64_t);
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_NE(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
request.commandId = KmdSysman::Command::MaxCommands;
|
||||
request.componentId = KmdSysman::Component::PowerComponent;
|
||||
request.requestId = KmdSysman::Requests::Power::CurrentPowerLimit1;
|
||||
request.dataSize = 0;
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_NE(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
request.commandId = KmdSysman::Command::Get;
|
||||
request.componentId = KmdSysman::Component::MaxComponents;
|
||||
request.requestId = KmdSysman::Requests::Power::CurrentPowerLimit1;
|
||||
request.dataSize = 0;
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_NE(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
request.commandId = KmdSysman::Command::Get;
|
||||
request.componentId = KmdSysman::Component::PowerComponent;
|
||||
request.requestId = KmdSysman::Requests::Power::MaxPowerRequests;
|
||||
request.dataSize = 0;
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_NE(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
TEST_F(SysmanKmdManagerFixture, CheckRequestSingleSetCommandWithCorruptInformationVerifyCallFails) {
|
||||
pKmdSysManager->allowSetCalls = true;
|
||||
|
||||
ze_result_t result = ZE_RESULT_SUCCESS;
|
||||
KmdSysman::RequestProperty request;
|
||||
KmdSysman::ResponseProperty response;
|
||||
uint32_t value = 0;
|
||||
|
||||
request.commandId = KmdSysman::Command::Set;
|
||||
request.componentId = KmdSysman::Component::PowerComponent;
|
||||
request.requestId = KmdSysman::Requests::Power::CurrentPowerLimit1;
|
||||
request.dataSize = 0;
|
||||
memcpy_s(request.dataBuffer, sizeof(uint32_t), &value, sizeof(uint32_t));
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_NE(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
request.commandId = KmdSysman::Command::MaxCommands;
|
||||
request.componentId = KmdSysman::Component::PowerComponent;
|
||||
request.requestId = KmdSysman::Requests::Power::CurrentPowerLimit1;
|
||||
request.dataSize = sizeof(uint32_t);
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_NE(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
request.commandId = KmdSysman::Command::Get;
|
||||
request.componentId = KmdSysman::Component::MaxComponents;
|
||||
request.requestId = KmdSysman::Requests::Power::CurrentPowerLimit1;
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_NE(ZE_RESULT_SUCCESS, result);
|
||||
|
||||
request.commandId = KmdSysman::Command::Get;
|
||||
request.componentId = KmdSysman::Component::PowerComponent;
|
||||
request.requestId = KmdSysman::Requests::Power::MaxPowerRequests;
|
||||
|
||||
result = pKmdSysManager->requestSingle(request, response);
|
||||
|
||||
EXPECT_NE(ZE_RESULT_SUCCESS, result);
|
||||
}
|
||||
|
||||
} // namespace ult
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user