Skip to content

Commit 2f7ad76

Browse files
Daniel EnriquezCompute-Runtime-Automation
authored andcommitted
Implementation of the BAR Properties 1.2.
Windows Implementation for Resizable Bar on 1.2. Signed-off-by: Daniel Enriquez <daniel.enriquez.montanez@intel.com>
1 parent 625e81f commit 2f7ad76

File tree

11 files changed

+275
-4
lines changed

11 files changed

+275
-4
lines changed

level_zero/tools/source/sysman/pci/linux/os_pci_imp.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ ze_result_t LinuxPciImp::initializeBarProperties(std::vector<zes_pci_bar_propert
125125
getBarBaseAndSize(ReadBytes[i], baseAddr, barSize, barFlags);
126126
if (baseAddr && !(barFlags & 0x1)) { // we do not update for I/O ports
127127
zes_pci_bar_properties_t *pBarProp = new zes_pci_bar_properties_t;
128+
memset(pBarProp, 0, sizeof(zes_pci_bar_properties_t));
128129
pBarProp->index = i;
129130
pBarProp->base = baseAddr;
130131
pBarProp->size = barSize;
@@ -149,6 +150,14 @@ ze_result_t LinuxPciImp::initializeBarProperties(std::vector<zes_pci_bar_propert
149150
return result;
150151
}
151152

153+
bool LinuxPciImp::resizableBarSupported() {
154+
return false;
155+
}
156+
157+
bool LinuxPciImp::resizableBarEnabled() {
158+
return false;
159+
}
160+
152161
ze_result_t LinuxPciImp::getState(zes_pci_state_t *state) {
153162
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
154163
}

level_zero/tools/source/sysman/pci/linux/os_pci_imp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
2323
ze_result_t getMaxLinkWidth(int32_t &maxLinkwidth) override;
2424
ze_result_t getState(zes_pci_state_t *state) override;
2525
ze_result_t getProperties(zes_pci_properties_t *properties) override;
26+
bool resizableBarSupported() override;
27+
bool resizableBarEnabled() override;
2628
ze_result_t initializeBarProperties(std::vector<zes_pci_bar_properties_t *> &pBarProperties) override;
2729
LinuxPciImp() = default;
2830
LinuxPciImp(OsSysman *pOsSysman);

level_zero/tools/source/sysman/pci/os_pci.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class OsPci {
2424
virtual ze_result_t getMaxLinkWidth(int32_t &maxLinkWidth) = 0;
2525
virtual ze_result_t getState(zes_pci_state_t *state) = 0;
2626
virtual ze_result_t getProperties(zes_pci_properties_t *properties) = 0;
27+
virtual bool resizableBarSupported() = 0;
28+
virtual bool resizableBarEnabled() = 0;
2729
virtual ze_result_t initializeBarProperties(std::vector<zes_pci_bar_properties_t *> &pBarProperties) = 0;
2830
static OsPci *create(OsSysman *pOsSysman);
2931
virtual ~OsPci() = default;

level_zero/tools/source/sysman/pci/pci_imp.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,21 @@ ze_result_t PciImp::pciGetInitializedBars(uint32_t *pCount, zes_pci_bar_properti
9494
}
9595
if (nullptr != pProperties) {
9696
for (uint32_t i = 0; i < numToCopy; i++) {
97-
pProperties[i] = *pciBarProperties[i];
97+
pProperties[i].base = pciBarProperties[i]->base;
98+
pProperties[i].index = pciBarProperties[i]->index;
99+
pProperties[i].size = pciBarProperties[i]->size;
100+
pProperties[i].type = pciBarProperties[i]->type;
101+
102+
if (pProperties[i].pNext != nullptr && pProperties[i].stype == zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2) {
103+
zes_pci_bar_properties_1_2_t *pBarPropsExt = static_cast<zes_pci_bar_properties_1_2_t *>(pProperties[i].pNext);
104+
// base, index, size and type are the same as the non 1.2 struct.
105+
pBarPropsExt->base = pciBarProperties[i]->base;
106+
pBarPropsExt->index = pciBarProperties[i]->index;
107+
pBarPropsExt->size = pciBarProperties[i]->size;
108+
pBarPropsExt->type = pciBarProperties[i]->type;
109+
pBarPropsExt->resizableBarEnabled = resizableBarEnabled;
110+
pBarPropsExt->resizableBarSupported = resizableBarSupported;
111+
}
98112
}
99113
}
100114
return ZE_RESULT_SUCCESS;
@@ -109,6 +123,8 @@ void PciImp::init() {
109123
}
110124
UNRECOVERABLE_IF(nullptr == pOsPci);
111125
pOsPci->getProperties(&pciProperties);
126+
resizableBarEnabled = pOsPci->resizableBarEnabled();
127+
resizableBarSupported = pOsPci->resizableBarSupported();
112128
std::string bdf;
113129
pOsPci->getPciBdf(bdf);
114130
if (bdf.empty()) {

level_zero/tools/source/sysman/pci/pci_imp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class PciImp : public Pci, NEO::NonCopyableOrMovableClass {
3333

3434
private:
3535
OsSysman *pOsSysman = nullptr;
36+
bool resizableBarSupported = false;
37+
bool resizableBarEnabled = false;
3638
zes_pci_properties_t pciProperties = {};
3739
std::vector<zes_pci_bar_properties_t *> pciBarProperties = {};
3840
};

level_zero/tools/source/sysman/pci/windows/os_pci_imp.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,49 @@ ze_result_t WddmPciImp::getState(zes_pci_state_t *state) {
171171
return status;
172172
}
173173

174+
bool WddmPciImp::resizableBarSupported() {
175+
uint32_t valueSmall = 0;
176+
bool supported = false;
177+
KmdSysman::RequestProperty request;
178+
KmdSysman::ResponseProperty response;
179+
180+
request.commandId = KmdSysman::Command::Get;
181+
request.componentId = KmdSysman::Component::PciComponent;
182+
request.paramInfo = KmdSysman::PciDomainsType::PciCurrentDevice;
183+
request.requestId = KmdSysman::Requests::Pci::ResizableBarSupported;
184+
185+
if (pKmdSysManager->requestSingle(request, response) == ZE_RESULT_SUCCESS) {
186+
memcpy_s(&valueSmall, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
187+
supported = static_cast<bool>(valueSmall);
188+
}
189+
190+
return supported;
191+
}
192+
193+
bool WddmPciImp::resizableBarEnabled() {
194+
uint32_t valueSmall = 0;
195+
bool enabled = false;
196+
KmdSysman::RequestProperty request;
197+
KmdSysman::ResponseProperty response;
198+
199+
request.commandId = KmdSysman::Command::Get;
200+
request.componentId = KmdSysman::Component::PciComponent;
201+
request.paramInfo = KmdSysman::PciDomainsType::PciCurrentDevice;
202+
request.requestId = KmdSysman::Requests::Pci::ResizableBarEnabled;
203+
204+
if (pKmdSysManager->requestSingle(request, response) == ZE_RESULT_SUCCESS) {
205+
memcpy_s(&valueSmall, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
206+
enabled = static_cast<bool>(valueSmall);
207+
}
208+
209+
return enabled;
210+
}
211+
174212
ze_result_t WddmPciImp::initializeBarProperties(std::vector<zes_pci_bar_properties_t *> &pBarProperties) {
175-
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
213+
zes_pci_bar_properties_t *pBarProp = new zes_pci_bar_properties_t;
214+
memset(pBarProp, 0, sizeof(zes_pci_bar_properties_t));
215+
pBarProperties.push_back(pBarProp);
216+
return ZE_RESULT_SUCCESS;
176217
}
177218

178219
WddmPciImp::WddmPciImp(OsSysman *pOsSysman) {

level_zero/tools/source/sysman/pci/windows/os_pci_imp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -20,6 +20,8 @@ class WddmPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
2020
ze_result_t getMaxLinkWidth(int32_t &maxLinkwidth) override;
2121
ze_result_t getState(zes_pci_state_t *state) override;
2222
ze_result_t getProperties(zes_pci_properties_t *properties) override;
23+
bool resizableBarSupported() override;
24+
bool resizableBarEnabled() override;
2325
ze_result_t initializeBarProperties(std::vector<zes_pci_bar_properties_t *> &pBarProperties) override;
2426
WddmPciImp(OsSysman *pOsSysman);
2527
WddmPciImp() = default;

level_zero/tools/source/sysman/windows/kmd_sys.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ enum Pci {
303303
CurrentLinkRxCounter,
304304
CurrentLinkTxCounter,
305305

306+
// resizable bar
307+
ResizableBarSupported,
308+
ResizableBarEnabled,
309+
306310
MaxPciRequests,
307311
};
308312

level_zero/tools/test/unit_tests/sources/sysman/pci/linux/test_zes_pci.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,117 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVe
211211
}
212212
}
213213

214+
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2Extension) {
215+
uint32_t count = 0;
216+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
217+
EXPECT_NE(count, 0u);
218+
219+
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
220+
zes_pci_bar_properties_1_2_t *props1_2 = new zes_pci_bar_properties_1_2_t;
221+
memset(props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t));
222+
223+
for (uint32_t i = 0; i < count; i++) {
224+
pBarProps[i].pNext = static_cast<void *>(props1_2);
225+
pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2;
226+
}
227+
228+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
229+
230+
for (uint32_t i = 0; i < count; i++) {
231+
EXPECT_EQ(pBarProps[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2);
232+
EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM);
233+
EXPECT_NE(pBarProps[i].base, 0u);
234+
EXPECT_NE(pBarProps[i].size, 0u);
235+
}
236+
237+
EXPECT_EQ(props1_2->resizableBarSupported, false);
238+
EXPECT_EQ(props1_2->resizableBarEnabled, false);
239+
EXPECT_LE(props1_2->type, ZES_PCI_BAR_TYPE_MEM);
240+
EXPECT_NE(props1_2->base, 0u);
241+
EXPECT_NE(props1_2->size, 0u);
242+
243+
delete[] pBarProps;
244+
delete props1_2;
245+
}
246+
247+
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWrongType) {
248+
uint32_t count = 0;
249+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
250+
EXPECT_NE(count, 0u);
251+
252+
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
253+
zes_pci_bar_properties_1_2_t *props1_2 = new zes_pci_bar_properties_1_2_t;
254+
memset(props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t));
255+
256+
for (uint32_t i = 0; i < count; i++) {
257+
pBarProps[i].pNext = static_cast<void *>(props1_2);
258+
pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE;
259+
}
260+
261+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
262+
263+
for (uint32_t i = 0; i < count; i++) {
264+
EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM);
265+
EXPECT_NE(pBarProps[i].base, 0u);
266+
EXPECT_NE(pBarProps[i].size, 0u);
267+
}
268+
269+
EXPECT_EQ(props1_2->resizableBarSupported, false);
270+
EXPECT_EQ(props1_2->resizableBarEnabled, false);
271+
EXPECT_EQ(props1_2->type, ZES_PCI_BAR_TYPE_MMIO);
272+
EXPECT_EQ(props1_2->base, 0u);
273+
EXPECT_EQ(props1_2->size, 0u);
274+
275+
delete[] pBarProps;
276+
delete props1_2;
277+
}
278+
279+
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWithNullPtr) {
280+
uint32_t count = 0;
281+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
282+
EXPECT_NE(count, 0u);
283+
284+
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
285+
286+
for (uint32_t i = 0; i < count; i++) {
287+
pBarProps[i].pNext = nullptr;
288+
pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2;
289+
}
290+
291+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
292+
293+
for (uint32_t i = 0; i < count; i++) {
294+
EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM);
295+
EXPECT_NE(pBarProps[i].base, 0u);
296+
EXPECT_NE(pBarProps[i].size, 0u);
297+
}
298+
299+
delete[] pBarProps;
300+
}
301+
302+
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWithWrongtypeNullPtr) {
303+
uint32_t count = 0;
304+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
305+
EXPECT_NE(count, 0u);
306+
307+
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
308+
309+
for (uint32_t i = 0; i < count; i++) {
310+
pBarProps[i].pNext = nullptr;
311+
pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE;
312+
}
313+
314+
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
315+
316+
for (uint32_t i = 0; i < count; i++) {
317+
EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM);
318+
EXPECT_NE(pBarProps[i].base, 0u);
319+
EXPECT_NE(pBarProps[i].size, 0u);
320+
}
321+
322+
delete[] pBarProps;
323+
}
324+
214325
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetStateThenVerifyzetSysmanPciGetStateCallReturnNotSupported) {
215326
zes_pci_state_t state;
216327
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDevicePciGetState(device, &state));

level_zero/tools/test/unit_tests/sources/sysman/pci/windows/mock_pci.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 Intel Corporation
2+
* Copyright (C) 2020-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -32,6 +32,8 @@ struct Mock<PciKmdSysManager> : public PciKmdSysManager {
3232
uint32_t mockMaxLinkWidth[3] = {1, 0, 8};
3333
uint32_t mockCurrentLinkSpeed[3] = {1, 0, 3};
3434
uint32_t mockCurrentLinkWidth[3] = {1, 0, 1};
35+
uint32_t mockResizableBarSupported[3] = {1, 1, 1};
36+
uint32_t mockResizableBarEnabled[3] = {1, 1, 1};
3537

3638
void getPciProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override {
3739
uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pResponse);
@@ -88,6 +90,18 @@ struct Mock<PciKmdSysManager> : public PciKmdSysManager {
8890
pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
8991
pResponse->outDataSize = sizeof(uint32_t);
9092
} break;
93+
case KmdSysman::Requests::Pci::ResizableBarSupported: {
94+
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
95+
*pValue = mockResizableBarSupported[domain];
96+
pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
97+
pResponse->outDataSize = sizeof(uint32_t);
98+
} break;
99+
case KmdSysman::Requests::Pci::ResizableBarEnabled: {
100+
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
101+
*pValue = mockResizableBarEnabled[domain];
102+
pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
103+
pResponse->outDataSize = sizeof(uint32_t);
104+
} break;
91105
default: {
92106
pResponse->outDataSize = 0;
93107
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;

0 commit comments

Comments
 (0)