1 /*
2  * Copyright (C) 2018-2021 Intel Corporation
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  */
7 
8 #include "shared/source/command_stream/stream_properties.h"
9 #include "shared/source/command_stream/thread_arbitration_policy.h"
10 #include "shared/source/gen8/reg_configs.h"
11 #include "shared/source/helpers/preamble.h"
12 #include "shared/test/unit_test/preamble/preamble_fixture.h"
13 
14 using namespace NEO;
15 
16 typedef PreambleFixture BdwSlm;
17 
BDWTEST_F(BdwSlm,WhenL3ConfigIsDispatchedThenProperRegisterAddressAndValueAreProgrammed)18 BDWTEST_F(BdwSlm, WhenL3ConfigIsDispatchedThenProperRegisterAddressAndValueAreProgrammed) {
19     typedef BDWFamily::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM;
20     LinearStream &cs = linearStream;
21     uint32_t l3Config = PreambleHelper<BDWFamily>::getL3Config(*defaultHwInfo, true);
22     PreambleHelper<BDWFamily>::programL3(&cs, l3Config);
23 
24     parseCommands<BDWFamily>(cs);
25 
26     auto itorLRI = find<MI_LOAD_REGISTER_IMM *>(cmdList.begin(), cmdList.end());
27     ASSERT_NE(cmdList.end(), itorLRI);
28 
29     const auto &lri = *reinterpret_cast<MI_LOAD_REGISTER_IMM *>(*itorLRI);
30     auto RegisterOffset = L3CNTLRegisterOffset<BDWFamily>::registerOffset;
31     EXPECT_EQ(RegisterOffset, lri.getRegisterOffset());
32     EXPECT_EQ(1u, lri.getDataDword() & 1);
33 }
34 
35 typedef PreambleFixture Gen8L3Config;
36 
BDWTEST_F(Gen8L3Config,GivenNoSlmWhenProgrammingL3ThenProgrammingIsCorrect)37 BDWTEST_F(Gen8L3Config, GivenNoSlmWhenProgrammingL3ThenProgrammingIsCorrect) {
38     bool slmUsed = false;
39     uint32_t l3Config = 0;
40 
41     l3Config = getL3ConfigHelper<IGFX_BROADWELL>(slmUsed);
42     EXPECT_EQ(0x80000340u, l3Config);
43 
44     uint32_t errorDetectionBehaviorControlBit = 1 << 9;
45     EXPECT_TRUE((l3Config & errorDetectionBehaviorControlBit) != 0);
46 }
47 
BDWTEST_F(Gen8L3Config,GivenlmWhenProgrammingL3ThenProgrammingIsCorrect)48 BDWTEST_F(Gen8L3Config, GivenlmWhenProgrammingL3ThenProgrammingIsCorrect) {
49     bool slmUsed = true;
50     uint32_t l3Config = 0;
51 
52     l3Config = getL3ConfigHelper<IGFX_BROADWELL>(slmUsed);
53     EXPECT_EQ(0x60000321u, l3Config);
54 
55     uint32_t errorDetectionBehaviorControlBit = 1 << 9;
56     EXPECT_TRUE((l3Config & errorDetectionBehaviorControlBit) != 0);
57 }
58 
BDWTEST_F(Gen8L3Config,WhenPreambleIsCreatedThenL3ProgrammingIsCorrect)59 BDWTEST_F(Gen8L3Config, WhenPreambleIsCreatedThenL3ProgrammingIsCorrect) {
60     bool l3ConfigDifference;
61     bool isL3Programmable;
62 
63     l3ConfigDifference =
64         PreambleHelper<BDWFamily>::getL3Config(*defaultHwInfo, true) !=
65         PreambleHelper<BDWFamily>::getL3Config(*defaultHwInfo, false);
66     isL3Programmable =
67         PreambleHelper<BDWFamily>::isL3Configurable(*defaultHwInfo);
68 
69     EXPECT_EQ(l3ConfigDifference, isL3Programmable);
70 }
71 
72 typedef PreambleFixture ThreadArbitrationGen8;
BDWTEST_F(ThreadArbitrationGen8,givenPolicyWhenThreadArbitrationProgrammedThenDoNothing)73 BDWTEST_F(ThreadArbitrationGen8, givenPolicyWhenThreadArbitrationProgrammedThenDoNothing) {
74     typedef BDWFamily::MI_LOAD_REGISTER_IMM MI_LOAD_REGISTER_IMM;
75     LinearStream &cs = linearStream;
76 
77     PreambleHelper<BDWFamily>::programThreadArbitration(&cs, ThreadArbitrationPolicy::RoundRobin);
78 
79     EXPECT_EQ(0u, cs.getUsed());
80 
81     MockDevice device;
82     EXPECT_EQ(0u, PreambleHelper<BDWFamily>::getAdditionalCommandsSize(device));
83     EXPECT_EQ(0u, PreambleHelper<BDWFamily>::getThreadArbitrationCommandsSize());
84     EXPECT_EQ(0u, HwHelperHw<BDWFamily>::get().getDefaultThreadArbitrationPolicy());
85 }
86 
BDWTEST_F(ThreadArbitrationGen8,whenGetSupportThreadArbitrationPoliciesIsCalledThenEmptyVectorIsReturned)87 BDWTEST_F(ThreadArbitrationGen8, whenGetSupportThreadArbitrationPoliciesIsCalledThenEmptyVectorIsReturned) {
88     auto supportedPolicies = PreambleHelper<BDWFamily>::getSupportedThreadArbitrationPolicies();
89 
90     EXPECT_EQ(0u, supportedPolicies.size());
91 }
92 
93 typedef PreambleFixture Gen8UrbEntryAllocationSize;
BDWTEST_F(Gen8UrbEntryAllocationSize,WhenPreambleIsCreatedThenUrbEntryAllocationSizeIsCorrect)94 BDWTEST_F(Gen8UrbEntryAllocationSize, WhenPreambleIsCreatedThenUrbEntryAllocationSizeIsCorrect) {
95     uint32_t actualVal = PreambleHelper<FamilyType>::getUrbEntryAllocationSize();
96     EXPECT_EQ(0x782u, actualVal);
97 }
98 
BDWTEST_F(PreambleVfeState,WhenProgrammingVfeStateThenProgrammingIsCorrect)99 BDWTEST_F(PreambleVfeState, WhenProgrammingVfeStateThenProgrammingIsCorrect) {
100     typedef BDWFamily::PIPE_CONTROL PIPE_CONTROL;
101 
102     LinearStream &cs = linearStream;
103     auto pVfeCmd = PreambleHelper<BDWFamily>::getSpaceForVfeState(&linearStream, *defaultHwInfo, EngineGroupType::RenderCompute);
104     StreamProperties emptyProperties{};
105     PreambleHelper<BDWFamily>::programVfeState(pVfeCmd, *defaultHwInfo, 0u, 0, 168u, emptyProperties);
106 
107     parseCommands<BDWFamily>(cs);
108 
109     auto itorPC = find<PIPE_CONTROL *>(cmdList.begin(), cmdList.end());
110     ASSERT_NE(cmdList.end(), itorPC);
111 
112     const auto &pc = *reinterpret_cast<PIPE_CONTROL *>(*itorPC);
113     EXPECT_TRUE(pc.getDcFlushEnable());
114     EXPECT_EQ(1u, pc.getCommandStreamerStallEnable());
115 }
116