| 1 |
/* |
| 2 |
* Copyright (C) 2020-2023 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#pragma once |
| 9 |
#include "level_zero/core/test/unit_tests/mock.h" |
| 10 |
#include "level_zero/tools/source/sysman/pci/pci_imp.h" |
| 11 |
#include "level_zero/tools/source/sysman/pci/windows/os_pci_imp.h" |
| 12 |
#include "level_zero/tools/test/unit_tests/sources/sysman/windows/mock_kmd_sys_manager.h" |
| 13 |
|
| 14 |
namespace L0 { |
| 15 |
namespace ult { |
| 16 |
|
| 17 |
struct MockMemoryManagerSysman : public MemoryManagerMock { |
| 18 |
MockMemoryManagerSysman(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {} |
| 19 |
}; |
| 20 |
|
| 21 |
class PciKmdSysManager : public Mock<MockKmdSysManager> {}; |
| 22 |
|
| 23 |
template <> |
| 24 |
struct Mock<PciKmdSysManager> : public PciKmdSysManager { |
| 25 |
// PciCurrentDevice, PciParentDevice, PciRootPort |
| 26 |
uint32_t mockDomain[3] = {0, 0, 0}; |
| 27 |
uint32_t mockBus[3] = {0, 0, 3}; |
| 28 |
uint32_t mockDevice[3] = {2, 0, 0}; |
| 29 |
uint32_t mockFunction[3] = {0, 0, 0}; |
| 30 |
uint32_t mockMaxLinkSpeed[3] = {1, 0, 4}; |
| 31 |
uint32_t mockMaxLinkWidth[3] = {1, 0, 8}; |
| 32 |
uint32_t mockCurrentLinkSpeed[3] = {1, 0, 3}; |
| 33 |
uint32_t mockCurrentLinkWidth[3] = {1, 0, 1}; |
| 34 |
int64_t mockCurrentMaxBandwidth[3] = {250000000, -1, 984615384}; |
| 35 |
uint32_t mockResizableBarSupported[3] = {1, 1, 1}; |
| 36 |
uint32_t mockResizableBarEnabled[3] = {1, 1, 1}; |
| 37 |
uint32_t pciBusReturnCode = KmdSysman::KmdSysmanSuccess; |
| 38 |
uint32_t pciDomainReturnCode = KmdSysman::KmdSysmanSuccess; |
| 39 |
uint32_t pciDeviceReturnCode = KmdSysman::KmdSysmanSuccess; |
| 40 |
uint32_t pciFunctionReturnCode = KmdSysman::KmdSysmanSuccess; |
| 41 |
uint32_t pciMaxLinkSpeedReturnCode = KmdSysman::KmdSysmanSuccess; |
| 42 |
uint32_t pciMaxLinkWidthReturnCode = KmdSysman::KmdSysmanSuccess; |
| 43 |
uint32_t pciCurrentLinkSpeedReturnCode = KmdSysman::KmdSysmanSuccess; |
| 44 |
uint32_t pciCurrentLinkWidthReturnCode = KmdSysman::KmdSysmanSuccess; |
| 45 |
uint32_t pciResizableBarSupportedReturnCode = KmdSysman::KmdSysmanSuccess; |
| 46 |
uint32_t pciResizableBarEnabledReturnCode = KmdSysman::KmdSysmanSuccess; |
| 47 |
|
| 48 |
void getPciProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override { |
| 49 |
uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pResponse); |
| 50 |
pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderOut); |
| 51 |
|
| 52 |
KmdSysman::PciDomainsType domain = static_cast<KmdSysman::PciDomainsType>(pRequest->inCommandParam); |
| 53 |
|
| 54 |
switch (pRequest->inRequestId) { |
| 55 |
case KmdSysman::Requests::Pci::Domain: { |
| 56 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 57 |
*pValue = mockDomain[domain]; |
| 58 |
pResponse->outReturnCode = pciDomainReturnCode; |
| 59 |
pResponse->outDataSize = sizeof(uint32_t); |
| 60 |
} break; |
| 61 |
case KmdSysman::Requests::Pci::Bus: { |
| 62 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 63 |
*pValue = mockBus[domain]; |
| 64 |
pResponse->outReturnCode = pciBusReturnCode; |
| 65 |
pResponse->outDataSize = sizeof(uint32_t); |
| 66 |
} break; |
| 67 |
case KmdSysman::Requests::Pci::Device: { |
| 68 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 69 |
*pValue = mockDevice[domain]; |
| 70 |
pResponse->outReturnCode = pciDeviceReturnCode; |
| 71 |
pResponse->outDataSize = sizeof(uint32_t); |
| 72 |
} break; |
| 73 |
case KmdSysman::Requests::Pci::Function: { |
| 74 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 75 |
*pValue = mockFunction[domain]; |
| 76 |
pResponse->outReturnCode = pciFunctionReturnCode; |
| 77 |
pResponse->outDataSize = sizeof(uint32_t); |
| 78 |
} break; |
| 79 |
case KmdSysman::Requests::Pci::MaxLinkSpeed: { |
| 80 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 81 |
*pValue = mockMaxLinkSpeed[domain]; |
| 82 |
pResponse->outReturnCode = pciMaxLinkSpeedReturnCode; |
| 83 |
pResponse->outDataSize = sizeof(uint32_t); |
| 84 |
} break; |
| 85 |
case KmdSysman::Requests::Pci::MaxLinkWidth: { |
| 86 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 87 |
*pValue = mockMaxLinkWidth[domain]; |
| 88 |
pResponse->outReturnCode = pciMaxLinkWidthReturnCode; |
| 89 |
pResponse->outDataSize = sizeof(uint32_t); |
| 90 |
} break; |
| 91 |
case KmdSysman::Requests::Pci::CurrentLinkSpeed: { |
| 92 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 93 |
*pValue = mockCurrentLinkSpeed[domain]; |
| 94 |
pResponse->outReturnCode = pciCurrentLinkSpeedReturnCode; |
| 95 |
pResponse->outDataSize = sizeof(uint32_t); |
| 96 |
} break; |
| 97 |
case KmdSysman::Requests::Pci::CurrentLinkWidth: { |
| 98 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 99 |
*pValue = mockCurrentLinkWidth[domain]; |
| 100 |
pResponse->outReturnCode = pciCurrentLinkWidthReturnCode; |
| 101 |
pResponse->outDataSize = sizeof(uint32_t); |
| 102 |
} break; |
| 103 |
case KmdSysman::Requests::Pci::ResizableBarSupported: { |
| 104 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 105 |
*pValue = mockResizableBarSupported[domain]; |
| 106 |
pResponse->outReturnCode = pciResizableBarSupportedReturnCode; |
| 107 |
pResponse->outDataSize = sizeof(uint32_t); |
| 108 |
} break; |
| 109 |
case KmdSysman::Requests::Pci::ResizableBarEnabled: { |
| 110 |
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer); |
| 111 |
*pValue = mockResizableBarEnabled[domain]; |
| 112 |
pResponse->outReturnCode = pciResizableBarEnabledReturnCode; |
| 113 |
pResponse->outDataSize = sizeof(uint32_t); |
| 114 |
} break; |
| 115 |
default: { |
| 116 |
pResponse->outDataSize = 0; |
| 117 |
pResponse->outReturnCode = KmdSysman::KmdSysmanFail; |
| 118 |
} break; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
void setPciProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override { |
| 123 |
pResponse->outDataSize = 0; |
| 124 |
pResponse->outReturnCode = KmdSysman::KmdSysmanFail; |
| 125 |
} |
| 126 |
|
| 127 |
Mock() = default; |
| 128 |
~Mock() = default; |
| 129 |
}; |
| 130 |
|
| 131 |
} // namespace ult |
| 132 |
} // namespace L0 |