|
| 1 | +/* |
| 2 | + * Copyright (C) 2021 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#include "shared/source/command_stream/linear_stream.h" |
| 9 | +#include "shared/source/gen_common/reg_configs_common.h" |
| 10 | +#include "shared/source/helpers/preamble.h" |
| 11 | +#include "shared/test/common/cmd_parse/gen_cmd_parse.h" |
| 12 | + |
| 13 | +#include "test.h" |
| 14 | + |
| 15 | +#include "level_zero/core/source/cmdqueue/cmdqueue_hw.h" |
| 16 | +#include "level_zero/core/test/unit_tests/mocks/mock_cmdqueue.h" |
| 17 | +#include "level_zero/core/test/unit_tests/sources/debugger/active_debugger_fixture.h" |
| 18 | +#include "level_zero/core/test/unit_tests/sources/debugger/l0_debugger_fixture.h" |
| 19 | +#include <level_zero/ze_api.h> |
| 20 | + |
| 21 | +namespace L0 { |
| 22 | +namespace ult { |
| 23 | + |
| 24 | +using CommandQueueDebugCommandsForSldXeHP = Test<ActiveDebuggerFixture>; |
| 25 | +using CommandQueueDebugCommandsDebuggerL0XeHP = Test<L0DebuggerHwFixture>; |
| 26 | + |
| 27 | +XEHPTEST_F(CommandQueueDebugCommandsForSldXeHP, givenSteppingA0OrBWhenGlobalSipIsUsedThenMmioIsRestoredAtTheEndOfCmdBuffer) { |
| 28 | + using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM; |
| 29 | + ze_command_queue_desc_t queueDesc = {}; |
| 30 | + ze_result_t returnValue; |
| 31 | + HwHelper &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); |
| 32 | + |
| 33 | + std::array<uint32_t, 2> revisions = {hwHelper.getHwRevIdFromStepping(REVID::REVISION_A0, hwInfo), |
| 34 | + hwHelper.getHwRevIdFromStepping(REVID::REVISION_B, hwInfo)}; |
| 35 | + |
| 36 | + for (auto revision : revisions) { |
| 37 | + hwInfo.platform.usRevId = revision; |
| 38 | + |
| 39 | + auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, deviceL0, device->getDefaultEngine().commandStreamReceiver, &queueDesc, false, false, returnValue)); |
| 40 | + ASSERT_NE(nullptr, commandQueue->commandStream); |
| 41 | + |
| 42 | + ze_command_list_handle_t commandLists[] = { |
| 43 | + CommandList::create(productFamily, deviceL0, NEO::EngineGroupType::RenderCompute, 0u, returnValue)->toHandle()}; |
| 44 | + |
| 45 | + uint32_t globalSipFound = 0; |
| 46 | + uint32_t debugModeFound = 0; |
| 47 | + uint32_t tdCtlFound = 0; |
| 48 | + std::vector<MI_LOAD_REGISTER_IMM *> globalSip; |
| 49 | + |
| 50 | + for (uint32_t execCount = 0; execCount < 2; execCount++) { |
| 51 | + auto startPointer = ptrOffset(commandQueue->commandStream->getCpuBase(), commandQueue->commandStream->getUsed()); |
| 52 | + auto usedSpaceBefore = commandQueue->commandStream->getUsed(); |
| 53 | + |
| 54 | + auto result = commandQueue->executeCommandLists(1, commandLists, nullptr, true); |
| 55 | + ASSERT_EQ(ZE_RESULT_SUCCESS, result); |
| 56 | + commandQueue->synchronize(0); |
| 57 | + |
| 58 | + auto usedSpaceAfter = commandQueue->commandStream->getUsed(); |
| 59 | + EXPECT_GT(usedSpaceAfter, usedSpaceBefore); |
| 60 | + |
| 61 | + GenCmdList cmdList; |
| 62 | + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(cmdList, startPointer, usedSpaceAfter - usedSpaceBefore)); |
| 63 | + |
| 64 | + auto miLoadImm = findAll<MI_LOAD_REGISTER_IMM *>(cmdList.begin(), cmdList.end()); |
| 65 | + |
| 66 | + for (size_t i = 0; i < miLoadImm.size(); i++) { |
| 67 | + MI_LOAD_REGISTER_IMM *miLoad = genCmdCast<MI_LOAD_REGISTER_IMM *>(*miLoadImm[i]); |
| 68 | + ASSERT_NE(nullptr, miLoad); |
| 69 | + |
| 70 | + if (miLoad->getRegisterOffset() == GlobalSipRegister<FamilyType>::registerOffset) { |
| 71 | + globalSip.push_back(miLoad); |
| 72 | + globalSipFound++; |
| 73 | + } else if (miLoad->getRegisterOffset() == DebugModeRegisterOffset<FamilyType>::registerOffset) { |
| 74 | + debugModeFound++; |
| 75 | + } else if (miLoad->getRegisterOffset() == TdDebugControlRegisterOffset<FamilyType>::registerOffset) { |
| 76 | + tdCtlFound++; |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + EXPECT_EQ(1u, debugModeFound); |
| 82 | + EXPECT_EQ(1u, tdCtlFound); |
| 83 | + |
| 84 | + ASSERT_EQ(4u, globalSipFound); |
| 85 | + |
| 86 | + auto sipAddress = globalSip[0]->getDataDword(); |
| 87 | + auto sipAllocation = SipKernel::getSipKernel(*device).getSipAllocation(); |
| 88 | + EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress & 0xfffffff8); |
| 89 | + |
| 90 | + auto sipAddress2 = globalSip[1]->getDataDword(); |
| 91 | + EXPECT_EQ(0u, sipAddress2); |
| 92 | + |
| 93 | + auto sipAddress3 = globalSip[2]->getDataDword(); |
| 94 | + EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress3 & 0xfffffff8); |
| 95 | + |
| 96 | + auto sipAddress4 = globalSip[3]->getDataDword(); |
| 97 | + EXPECT_EQ(0u, sipAddress4); |
| 98 | + |
| 99 | + auto commandList = CommandList::fromHandle(commandLists[0]); |
| 100 | + commandList->destroy(); |
| 101 | + |
| 102 | + commandQueue->destroy(); |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +XEHPTEST_F(CommandQueueDebugCommandsDebuggerL0XeHP, givenSteppingA0OrBWhenGlobalSipIsUsedThenMmioIsRestoredAtTheEndOfCmdBuffer) { |
| 107 | + using MI_LOAD_REGISTER_IMM = typename FamilyType::MI_LOAD_REGISTER_IMM; |
| 108 | + ze_command_queue_desc_t queueDesc = {}; |
| 109 | + ze_result_t returnValue; |
| 110 | + HwHelper &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); |
| 111 | + |
| 112 | + std::array<uint32_t, 2> revisions = {hwHelper.getHwRevIdFromStepping(REVID::REVISION_A0, hwInfo), |
| 113 | + hwHelper.getHwRevIdFromStepping(REVID::REVISION_B, hwInfo)}; |
| 114 | + |
| 115 | + for (auto revision : revisions) { |
| 116 | + hwInfo.platform.usRevId = revision; |
| 117 | + |
| 118 | + auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, false, returnValue)); |
| 119 | + ASSERT_NE(nullptr, commandQueue->commandStream); |
| 120 | + |
| 121 | + ze_command_list_handle_t commandLists[] = { |
| 122 | + CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)->toHandle()}; |
| 123 | + |
| 124 | + uint32_t globalSipFound = 0; |
| 125 | + std::vector<MI_LOAD_REGISTER_IMM *> globalSip; |
| 126 | + |
| 127 | + for (uint32_t execCount = 0; execCount < 2; execCount++) { |
| 128 | + auto startPointer = ptrOffset(commandQueue->commandStream->getCpuBase(), commandQueue->commandStream->getUsed()); |
| 129 | + auto usedSpaceBefore = commandQueue->commandStream->getUsed(); |
| 130 | + |
| 131 | + auto result = commandQueue->executeCommandLists(1, commandLists, nullptr, true); |
| 132 | + ASSERT_EQ(ZE_RESULT_SUCCESS, result); |
| 133 | + commandQueue->synchronize(0); |
| 134 | + |
| 135 | + auto usedSpaceAfter = commandQueue->commandStream->getUsed(); |
| 136 | + EXPECT_GT(usedSpaceAfter, usedSpaceBefore); |
| 137 | + |
| 138 | + GenCmdList cmdList; |
| 139 | + ASSERT_TRUE(FamilyType::PARSE::parseCommandBuffer(cmdList, startPointer, usedSpaceAfter - usedSpaceBefore)); |
| 140 | + |
| 141 | + auto miLoadImm = findAll<MI_LOAD_REGISTER_IMM *>(cmdList.begin(), cmdList.end()); |
| 142 | + |
| 143 | + for (size_t i = 0; i < miLoadImm.size(); i++) { |
| 144 | + MI_LOAD_REGISTER_IMM *miLoad = genCmdCast<MI_LOAD_REGISTER_IMM *>(*miLoadImm[i]); |
| 145 | + ASSERT_NE(nullptr, miLoad); |
| 146 | + |
| 147 | + if (miLoad->getRegisterOffset() == GlobalSipRegister<FamilyType>::registerOffset) { |
| 148 | + globalSip.push_back(miLoad); |
| 149 | + globalSipFound++; |
| 150 | + } |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + ASSERT_EQ(4u, globalSipFound); |
| 155 | + |
| 156 | + auto sipAddress = globalSip[0]->getDataDword(); |
| 157 | + auto sipAllocation = SipKernel::getSipKernel(*neoDevice).getSipAllocation(); |
| 158 | + EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress & 0xfffffff8); |
| 159 | + |
| 160 | + auto sipAddress2 = globalSip[1]->getDataDword(); |
| 161 | + EXPECT_EQ(0u, sipAddress2); |
| 162 | + |
| 163 | + auto sipAddress3 = globalSip[2]->getDataDword(); |
| 164 | + EXPECT_EQ(sipAllocation->getGpuAddressToPatch(), sipAddress3 & 0xfffffff8); |
| 165 | + |
| 166 | + auto sipAddress4 = globalSip[3]->getDataDword(); |
| 167 | + EXPECT_EQ(0u, sipAddress4); |
| 168 | + |
| 169 | + auto commandList = CommandList::fromHandle(commandLists[0]); |
| 170 | + commandList->destroy(); |
| 171 | + |
| 172 | + commandQueue->destroy(); |
| 173 | + } |
| 174 | +} |
| 175 | + |
| 176 | +} // namespace ult |
| 177 | +} // namespace L0 |
0 commit comments