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>
This commit is contained in:
Daniel Enriquez 2021-06-22 19:03:31 -07:00 committed by Compute-Runtime-Automation
parent 625e81f1f2
commit 2f7ad764ad
11 changed files with 275 additions and 4 deletions

View File

@ -125,6 +125,7 @@ ze_result_t LinuxPciImp::initializeBarProperties(std::vector<zes_pci_bar_propert
getBarBaseAndSize(ReadBytes[i], baseAddr, barSize, barFlags);
if (baseAddr && !(barFlags & 0x1)) { // we do not update for I/O ports
zes_pci_bar_properties_t *pBarProp = new zes_pci_bar_properties_t;
memset(pBarProp, 0, sizeof(zes_pci_bar_properties_t));
pBarProp->index = i;
pBarProp->base = baseAddr;
pBarProp->size = barSize;
@ -149,6 +150,14 @@ ze_result_t LinuxPciImp::initializeBarProperties(std::vector<zes_pci_bar_propert
return result;
}
bool LinuxPciImp::resizableBarSupported() {
return false;
}
bool LinuxPciImp::resizableBarEnabled() {
return false;
}
ze_result_t LinuxPciImp::getState(zes_pci_state_t *state) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

View File

@ -23,6 +23,8 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
ze_result_t getMaxLinkWidth(int32_t &maxLinkwidth) override;
ze_result_t getState(zes_pci_state_t *state) override;
ze_result_t getProperties(zes_pci_properties_t *properties) override;
bool resizableBarSupported() override;
bool resizableBarEnabled() override;
ze_result_t initializeBarProperties(std::vector<zes_pci_bar_properties_t *> &pBarProperties) override;
LinuxPciImp() = default;
LinuxPciImp(OsSysman *pOsSysman);

View File

@ -24,6 +24,8 @@ class OsPci {
virtual ze_result_t getMaxLinkWidth(int32_t &maxLinkWidth) = 0;
virtual ze_result_t getState(zes_pci_state_t *state) = 0;
virtual ze_result_t getProperties(zes_pci_properties_t *properties) = 0;
virtual bool resizableBarSupported() = 0;
virtual bool resizableBarEnabled() = 0;
virtual ze_result_t initializeBarProperties(std::vector<zes_pci_bar_properties_t *> &pBarProperties) = 0;
static OsPci *create(OsSysman *pOsSysman);
virtual ~OsPci() = default;

View File

@ -94,7 +94,21 @@ ze_result_t PciImp::pciGetInitializedBars(uint32_t *pCount, zes_pci_bar_properti
}
if (nullptr != pProperties) {
for (uint32_t i = 0; i < numToCopy; i++) {
pProperties[i] = *pciBarProperties[i];
pProperties[i].base = pciBarProperties[i]->base;
pProperties[i].index = pciBarProperties[i]->index;
pProperties[i].size = pciBarProperties[i]->size;
pProperties[i].type = pciBarProperties[i]->type;
if (pProperties[i].pNext != nullptr && pProperties[i].stype == zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2) {
zes_pci_bar_properties_1_2_t *pBarPropsExt = static_cast<zes_pci_bar_properties_1_2_t *>(pProperties[i].pNext);
// base, index, size and type are the same as the non 1.2 struct.
pBarPropsExt->base = pciBarProperties[i]->base;
pBarPropsExt->index = pciBarProperties[i]->index;
pBarPropsExt->size = pciBarProperties[i]->size;
pBarPropsExt->type = pciBarProperties[i]->type;
pBarPropsExt->resizableBarEnabled = resizableBarEnabled;
pBarPropsExt->resizableBarSupported = resizableBarSupported;
}
}
}
return ZE_RESULT_SUCCESS;
@ -109,6 +123,8 @@ void PciImp::init() {
}
UNRECOVERABLE_IF(nullptr == pOsPci);
pOsPci->getProperties(&pciProperties);
resizableBarEnabled = pOsPci->resizableBarEnabled();
resizableBarSupported = pOsPci->resizableBarSupported();
std::string bdf;
pOsPci->getPciBdf(bdf);
if (bdf.empty()) {

View File

@ -33,6 +33,8 @@ class PciImp : public Pci, NEO::NonCopyableOrMovableClass {
private:
OsSysman *pOsSysman = nullptr;
bool resizableBarSupported = false;
bool resizableBarEnabled = false;
zes_pci_properties_t pciProperties = {};
std::vector<zes_pci_bar_properties_t *> pciBarProperties = {};
};

View File

@ -171,8 +171,49 @@ ze_result_t WddmPciImp::getState(zes_pci_state_t *state) {
return status;
}
bool WddmPciImp::resizableBarSupported() {
uint32_t valueSmall = 0;
bool supported = false;
KmdSysman::RequestProperty request;
KmdSysman::ResponseProperty response;
request.commandId = KmdSysman::Command::Get;
request.componentId = KmdSysman::Component::PciComponent;
request.paramInfo = KmdSysman::PciDomainsType::PciCurrentDevice;
request.requestId = KmdSysman::Requests::Pci::ResizableBarSupported;
if (pKmdSysManager->requestSingle(request, response) == ZE_RESULT_SUCCESS) {
memcpy_s(&valueSmall, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
supported = static_cast<bool>(valueSmall);
}
return supported;
}
bool WddmPciImp::resizableBarEnabled() {
uint32_t valueSmall = 0;
bool enabled = false;
KmdSysman::RequestProperty request;
KmdSysman::ResponseProperty response;
request.commandId = KmdSysman::Command::Get;
request.componentId = KmdSysman::Component::PciComponent;
request.paramInfo = KmdSysman::PciDomainsType::PciCurrentDevice;
request.requestId = KmdSysman::Requests::Pci::ResizableBarEnabled;
if (pKmdSysManager->requestSingle(request, response) == ZE_RESULT_SUCCESS) {
memcpy_s(&valueSmall, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
enabled = static_cast<bool>(valueSmall);
}
return enabled;
}
ze_result_t WddmPciImp::initializeBarProperties(std::vector<zes_pci_bar_properties_t *> &pBarProperties) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
zes_pci_bar_properties_t *pBarProp = new zes_pci_bar_properties_t;
memset(pBarProp, 0, sizeof(zes_pci_bar_properties_t));
pBarProperties.push_back(pBarProp);
return ZE_RESULT_SUCCESS;
}
WddmPciImp::WddmPciImp(OsSysman *pOsSysman) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -20,6 +20,8 @@ class WddmPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
ze_result_t getMaxLinkWidth(int32_t &maxLinkwidth) override;
ze_result_t getState(zes_pci_state_t *state) override;
ze_result_t getProperties(zes_pci_properties_t *properties) override;
bool resizableBarSupported() override;
bool resizableBarEnabled() override;
ze_result_t initializeBarProperties(std::vector<zes_pci_bar_properties_t *> &pBarProperties) override;
WddmPciImp(OsSysman *pOsSysman);
WddmPciImp() = default;

View File

@ -303,6 +303,10 @@ enum Pci {
CurrentLinkRxCounter,
CurrentLinkTxCounter,
// resizable bar
ResizableBarSupported,
ResizableBarEnabled,
MaxPciRequests,
};

View File

@ -211,6 +211,117 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVe
}
}
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2Extension) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
EXPECT_NE(count, 0u);
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
zes_pci_bar_properties_1_2_t *props1_2 = new zes_pci_bar_properties_1_2_t;
memset(props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t));
for (uint32_t i = 0; i < count; i++) {
pBarProps[i].pNext = static_cast<void *>(props1_2);
pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2;
}
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
for (uint32_t i = 0; i < count; i++) {
EXPECT_EQ(pBarProps[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2);
EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM);
EXPECT_NE(pBarProps[i].base, 0u);
EXPECT_NE(pBarProps[i].size, 0u);
}
EXPECT_EQ(props1_2->resizableBarSupported, false);
EXPECT_EQ(props1_2->resizableBarEnabled, false);
EXPECT_LE(props1_2->type, ZES_PCI_BAR_TYPE_MEM);
EXPECT_NE(props1_2->base, 0u);
EXPECT_NE(props1_2->size, 0u);
delete[] pBarProps;
delete props1_2;
}
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWrongType) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
EXPECT_NE(count, 0u);
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
zes_pci_bar_properties_1_2_t *props1_2 = new zes_pci_bar_properties_1_2_t;
memset(props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t));
for (uint32_t i = 0; i < count; i++) {
pBarProps[i].pNext = static_cast<void *>(props1_2);
pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE;
}
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
for (uint32_t i = 0; i < count; i++) {
EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM);
EXPECT_NE(pBarProps[i].base, 0u);
EXPECT_NE(pBarProps[i].size, 0u);
}
EXPECT_EQ(props1_2->resizableBarSupported, false);
EXPECT_EQ(props1_2->resizableBarEnabled, false);
EXPECT_EQ(props1_2->type, ZES_PCI_BAR_TYPE_MMIO);
EXPECT_EQ(props1_2->base, 0u);
EXPECT_EQ(props1_2->size, 0u);
delete[] pBarProps;
delete props1_2;
}
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWithNullPtr) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
EXPECT_NE(count, 0u);
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
for (uint32_t i = 0; i < count; i++) {
pBarProps[i].pNext = nullptr;
pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2;
}
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
for (uint32_t i = 0; i < count; i++) {
EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM);
EXPECT_NE(pBarProps[i].base, 0u);
EXPECT_NE(pBarProps[i].size, 0u);
}
delete[] pBarProps;
}
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWithWrongtypeNullPtr) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
EXPECT_NE(count, 0u);
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
for (uint32_t i = 0; i < count; i++) {
pBarProps[i].pNext = nullptr;
pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE;
}
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
for (uint32_t i = 0; i < count; i++) {
EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM);
EXPECT_NE(pBarProps[i].base, 0u);
EXPECT_NE(pBarProps[i].size, 0u);
}
delete[] pBarProps;
}
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetStateThenVerifyzetSysmanPciGetStateCallReturnNotSupported) {
zes_pci_state_t state;
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, zesDevicePciGetState(device, &state));

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -32,6 +32,8 @@ struct Mock<PciKmdSysManager> : public PciKmdSysManager {
uint32_t mockMaxLinkWidth[3] = {1, 0, 8};
uint32_t mockCurrentLinkSpeed[3] = {1, 0, 3};
uint32_t mockCurrentLinkWidth[3] = {1, 0, 1};
uint32_t mockResizableBarSupported[3] = {1, 1, 1};
uint32_t mockResizableBarEnabled[3] = {1, 1, 1};
void getPciProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override {
uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pResponse);
@ -88,6 +90,18 @@ struct Mock<PciKmdSysManager> : public PciKmdSysManager {
pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::ResizableBarSupported: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockResizableBarSupported[domain];
pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::ResizableBarEnabled: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockResizableBarEnabled[domain];
pResponse->outReturnCode = KmdSysman::KmdSysmanSuccess;
pResponse->outDataSize = sizeof(uint32_t);
} break;
default: {
pResponse->outDataSize = 0;
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;

View File

@ -112,6 +112,74 @@ TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetB
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2Extension) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
EXPECT_NE(count, 0u);
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
zes_pci_bar_properties_1_2_t *props1_2 = new zes_pci_bar_properties_1_2_t;
memset(props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t));
for (uint32_t i = 0; i < count; i++) {
pBarProps[i].pNext = static_cast<void *>(props1_2);
pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2;
}
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
EXPECT_EQ(props1_2->resizableBarSupported, true);
EXPECT_EQ(props1_2->resizableBarEnabled, true);
delete[] pBarProps;
pBarProps = nullptr;
delete props1_2;
props1_2 = nullptr;
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWithNullPtr) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
EXPECT_NE(count, 0u);
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
for (uint32_t i = 0; i < count; i++) {
pBarProps[i].pNext = nullptr;
pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2;
}
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
delete[] pBarProps;
pBarProps = nullptr;
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWrongType) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, nullptr));
EXPECT_NE(count, 0u);
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
zes_pci_bar_properties_1_2_t *props1_2 = new zes_pci_bar_properties_1_2_t;
memset(props1_2, 0, sizeof(zes_pci_bar_properties_1_2_t));
for (uint32_t i = 0; i < count; i++) {
pBarProps[i].pNext = static_cast<void *>(props1_2);
pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE;
}
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(device, &count, pBarProps));
EXPECT_EQ(props1_2->resizableBarSupported, false);
EXPECT_EQ(props1_2->resizableBarEnabled, false);
delete[] pBarProps;
pBarProps = nullptr;
delete props1_2;
props1_2 = nullptr;
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetStatsWithLocalMemoryThenVerifyzetSysmanPciGetBarsCallSucceeds) {
setLocalMemorySupportedAndReinit(true);