| 1 |
/* |
| 2 |
* Copyright (C) 2020-2024 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#pragma once |
| 9 |
|
| 10 |
#include "level_zero/sysman/test/unit_tests/sources/windows/mock_kmd_sys_manager.h" |
| 11 |
|
| 12 |
namespace L0 { |
| 13 |
namespace Sysman { |
| 14 |
namespace ult { |
| 15 |
constexpr uint32_t mockLimitCount = 4u; |
| 16 |
|
| 17 |
struct PowerKmdSysManager : public MockKmdSysManager { |
| 18 |
|
| 19 |
uint32_t mockPowerDomainCount = 2; |
| 20 |
uint32_t mockPowerLimit1Enabled = 1; |
| 21 |
uint32_t mockPowerLimit2Enabled = 1; |
| 22 |
int32_t mockPowerLimit1 = 25000; |
| 23 |
int32_t mockPowerLimit2 = 41000; |
| 24 |
int32_t mockTauPowerLimit1 = 20800; |
| 25 |
uint32_t mockTpdDefault = 34000; |
| 26 |
uint32_t mockMinPowerLimit = 1000; |
| 27 |
uint32_t mockMaxPowerLimit = 80000; |
| 28 |
int32_t mockAcPowerPeak = 0; |
| 29 |
int32_t mockDcPowerPeak = 0; |
| 30 |
uint32_t mockEnergyThreshold = 0; |
| 31 |
uint32_t mockEnergyCounter = 3231121; |
| 32 |
uint32_t mockTimeStamp = 1123412412; |
| 33 |
uint32_t mockEnergyUnit = 14; |
| 34 |
uint64_t mockEnergyCounter64Bit = 32323232323232; |
| 35 |
uint32_t mockFrequencyTimeStamp = 38400000; |
| 36 |
uint32_t mockPowerFailure[KmdSysman::Requests::Power::MaxPowerRequests] = {0}; |
| 37 |
|
| 38 |
void getActivityProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override { |
| 39 |
uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pResponse); |
| 40 |
pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderOut); |
| 41 |
|
| 42 |
switch (pRequest->inRequestId) { |
| 43 |
case KmdSysman::Requests::Activity::TimestampFrequency: { |
| 44 |
uint32_t *pValueFrequency = reinterpret_cast<uint32_t *>(pBuffer); |
| 45 |
*pValueFrequency = mockFrequencyTimeStamp; |
| 46 |
pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess; |
| 47 |
pResponse->outDataSize = sizeof(uint32_t); |
| 48 |
} break; |
| 49 |
default: { |
| 50 |
pResponse->outDataSize = 0; |
| 51 |
pResponse->outReturnCode = KmdSysman::KmdSysmanFail; |
| 52 |
} break; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
uint32_t getReturnCode(uint32_t powerRequestCode) { |
| 57 |
return mockPowerFailure[powerRequestCode] ? KmdSysman::KmdSysmanFail : KmdSysman::KmdSysmanSuccess; |
| 58 |
} |
| 59 |
|
| 60 |
void getPowerProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override { |
| 61 |
uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pResponse); |
| 62 |
pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderOut); |
| 63 |
|
| 64 |
switch (pRequest->inRequestId) { |
| 65 |
case KmdSysman::Requests::Power::NumPowerDomains: { |
| 66 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 67 |
*pValue = mockPowerDomainCount; |
| 68 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 69 |
pResponse->outDataSize = sizeof(uint32_t); |
| 70 |
} break; |
| 71 |
case KmdSysman::Requests::Power::EnergyThresholdSupported: { |
| 72 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 73 |
*pValue = static_cast<uint32_t>(this->allowSetCalls); |
| 74 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 75 |
pResponse->outDataSize = sizeof(uint32_t); |
| 76 |
} break; |
| 77 |
case KmdSysman::Requests::Power::TdpDefault: { |
| 78 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 79 |
*pValue = mockTpdDefault; |
| 80 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 81 |
pResponse->outDataSize = sizeof(uint32_t); |
| 82 |
} break; |
| 83 |
case KmdSysman::Requests::Power::MinPowerLimitDefault: { |
| 84 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 85 |
*pValue = mockMinPowerLimit; |
| 86 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 87 |
pResponse->outDataSize = sizeof(uint32_t); |
| 88 |
} break; |
| 89 |
case KmdSysman::Requests::Power::MaxPowerLimitDefault: { |
| 90 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 91 |
*pValue = mockMaxPowerLimit; |
| 92 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 93 |
pResponse->outDataSize = sizeof(uint32_t); |
| 94 |
} break; |
| 95 |
case KmdSysman::Requests::Power::PowerLimit1Enabled: { |
| 96 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 97 |
*pValue = mockPowerLimit1Enabled; |
| 98 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 99 |
pResponse->outDataSize = sizeof(uint32_t); |
| 100 |
} break; |
| 101 |
case KmdSysman::Requests::Power::PowerLimit2Enabled: { |
| 102 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 103 |
*pValue = mockPowerLimit2Enabled; |
| 104 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 105 |
pResponse->outDataSize = sizeof(uint32_t); |
| 106 |
} break; |
| 107 |
case KmdSysman::Requests::Power::CurrentPowerLimit1: { |
| 108 |
int32_t *pValue = reinterpret_cast<int32_t *>(pBuffer); |
| 109 |
*pValue = mockPowerLimit1; |
| 110 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 111 |
pResponse->outDataSize = sizeof(int32_t); |
| 112 |
} break; |
| 113 |
case KmdSysman::Requests::Power::CurrentPowerLimit1Tau: { |
| 114 |
int32_t *pValue = reinterpret_cast<int32_t *>(pBuffer); |
| 115 |
*pValue = mockTauPowerLimit1; |
| 116 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 117 |
pResponse->outDataSize = sizeof(int32_t); |
| 118 |
} break; |
| 119 |
case KmdSysman::Requests::Power::CurrentPowerLimit2: { |
| 120 |
int32_t *pValue = reinterpret_cast<int32_t *>(pBuffer); |
| 121 |
*pValue = mockPowerLimit2; |
| 122 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 123 |
pResponse->outDataSize = sizeof(int32_t); |
| 124 |
} break; |
| 125 |
case KmdSysman::Requests::Power::CurrentPowerLimit4Ac: { |
| 126 |
int32_t *pValue = reinterpret_cast<int32_t *>(pBuffer); |
| 127 |
*pValue = mockAcPowerPeak; |
| 128 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 129 |
pResponse->outDataSize = sizeof(int32_t); |
| 130 |
} break; |
| 131 |
case KmdSysman::Requests::Power::CurrentPowerLimit4Dc: { |
| 132 |
int32_t *pValue = reinterpret_cast<int32_t *>(pBuffer); |
| 133 |
*pValue = mockDcPowerPeak; |
| 134 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 135 |
pResponse->outDataSize = sizeof(int32_t); |
| 136 |
} break; |
| 137 |
case KmdSysman::Requests::Power::CurrentEnergyThreshold: { |
| 138 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 139 |
*pValue = mockEnergyThreshold; |
| 140 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 141 |
pResponse->outDataSize = sizeof(uint32_t); |
| 142 |
} break; |
| 143 |
case KmdSysman::Requests::Power::CurrentEnergyCounter: { |
| 144 |
uint32_t *pValueCounter = reinterpret_cast<uint32_t *>(pBuffer); |
| 145 |
uint64_t *pValueTS = reinterpret_cast<uint64_t *>(pBuffer + sizeof(uint32_t)); |
| 146 |
*pValueCounter = mockEnergyCounter; |
| 147 |
*pValueTS = mockTimeStamp; |
| 148 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 149 |
pResponse->outDataSize = sizeof(uint32_t) + sizeof(uint64_t); |
| 150 |
} break; |
| 151 |
case KmdSysman::Requests::Power::EnergyCounterUnits: { |
| 152 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 153 |
*pValue = mockEnergyUnit; |
| 154 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 155 |
pResponse->outDataSize = sizeof(uint32_t); |
| 156 |
} break; |
| 157 |
case KmdSysman::Requests::Power::CurrentEnergyCounter64Bit: { |
| 158 |
uint64_t *pValueCounter = reinterpret_cast<uint64_t *>(pBuffer); |
| 159 |
uint64_t *pValueTS = reinterpret_cast<uint64_t *>(pBuffer + sizeof(uint64_t)); |
| 160 |
memcpy_s(pValueCounter, sizeof(uint64_t), &mockEnergyCounter64Bit, sizeof(mockEnergyCounter64Bit)); |
| 161 |
memcpy_s(pValueTS, sizeof(uint64_t), &mockTimeStamp, sizeof(mockEnergyCounter64Bit)); |
| 162 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 163 |
pResponse->outDataSize = sizeof(uint64_t) + sizeof(uint64_t); |
| 164 |
} break; |
| 165 |
default: { |
| 166 |
pResponse->outDataSize = 0; |
| 167 |
pResponse->outReturnCode = KmdSysman::KmdSysmanFail; |
| 168 |
} break; |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
void setPowerProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override { |
| 173 |
uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pRequest); |
| 174 |
pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderIn); |
| 175 |
|
| 176 |
switch (pRequest->inRequestId) { |
| 177 |
case KmdSysman::Requests::Power::CurrentPowerLimit1: { |
| 178 |
int32_t *pValue = reinterpret_cast<int32_t *>(pBuffer); |
| 179 |
mockPowerLimit1 = *pValue; |
| 180 |
pResponse->outDataSize = 0; |
| 181 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 182 |
} break; |
| 183 |
case KmdSysman::Requests::Power::CurrentPowerLimit1Tau: { |
| 184 |
int32_t *pValue = reinterpret_cast<int32_t *>(pBuffer); |
| 185 |
mockTauPowerLimit1 = *pValue; |
| 186 |
pResponse->outDataSize = 0; |
| 187 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 188 |
} break; |
| 189 |
case KmdSysman::Requests::Power::CurrentPowerLimit2: { |
| 190 |
int32_t *pValue = reinterpret_cast<int32_t *>(pBuffer); |
| 191 |
mockPowerLimit2 = *pValue; |
| 192 |
pResponse->outDataSize = 0; |
| 193 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 194 |
} break; |
| 195 |
case KmdSysman::Requests::Power::CurrentPowerLimit4Ac: { |
| 196 |
int32_t *pValue = reinterpret_cast<int32_t *>(pBuffer); |
| 197 |
mockAcPowerPeak = *pValue; |
| 198 |
pResponse->outDataSize = 0; |
| 199 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 200 |
} break; |
| 201 |
case KmdSysman::Requests::Power::CurrentPowerLimit4Dc: { |
| 202 |
int32_t *pValue = reinterpret_cast<int32_t *>(pBuffer); |
| 203 |
mockDcPowerPeak = *pValue; |
| 204 |
pResponse->outDataSize = 0; |
| 205 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 206 |
} break; |
| 207 |
case KmdSysman::Requests::Power::CurrentEnergyThreshold: { |
| 208 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 209 |
mockEnergyThreshold = *pValue; |
| 210 |
pResponse->outDataSize = 0; |
| 211 |
pResponse->outReturnCode = getReturnCode(pRequest->inRequestId); |
| 212 |
} break; |
| 213 |
default: { |
| 214 |
pResponse->outDataSize = 0; |
| 215 |
pResponse->outReturnCode = KmdSysman::KmdSysmanFail; |
| 216 |
} break; |
| 217 |
} |
| 218 |
} |
| 219 |
}; |
| 220 |
|
| 221 |
} // namespace ult |
| 222 |
} // namespace Sysman |
| 223 |
} // namespace L0 |