1212
1313#include " sysman/pci/pci_imp.h"
1414
15+ #include < linux/pci_regs.h>
16+
1517namespace L0 {
1618
1719const std::string LinuxPciImp::deviceDir (" device" );
@@ -150,7 +152,34 @@ ze_result_t LinuxPciImp::initializeBarProperties(std::vector<zes_pci_bar_propert
150152 return result;
151153}
152154
155+ // Parse PCIe configuration space to see if resizable Bar is supported
153156bool LinuxPciImp::resizableBarSupported () {
157+ uint32_t pos = PCI_CFG_SPACE_SIZE;
158+ uint32_t header = 0 ;
159+
160+ if (!configMemory) {
161+ return false ;
162+ }
163+
164+ // Minimum 8 bytes per capability. Hence maximum capabilities that
165+ // could be present in PCI extended configuration space are
166+ // represented by loopCount.
167+ auto loopCount = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8 ;
168+ header = getDwordFromConfig (pos);
169+ if (!header) {
170+ return false ;
171+ }
172+
173+ while (loopCount-- > 0 ) {
174+ if (PCI_EXT_CAP_ID (header) == PCI_EXT_CAP_ID_REBAR) {
175+ return true ;
176+ }
177+ pos = PCI_EXT_CAP_NEXT (header);
178+ if (pos < PCI_CFG_SPACE_SIZE) {
179+ return false ;
180+ }
181+ header = getDwordFromConfig (pos);
182+ }
154183 return false ;
155184}
156185
@@ -161,12 +190,30 @@ bool LinuxPciImp::resizableBarEnabled() {
161190ze_result_t LinuxPciImp::getState (zes_pci_state_t *state) {
162191 return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
163192}
193+
194+ void LinuxPciImp::pciExtendedConfigRead () {
195+ std::string pciConfigNode;
196+ pSysfsAccess->getRealPath (" device/config" , pciConfigNode);
197+ int fdConfig = -1 ;
198+ fdConfig = this ->openFunction (pciConfigNode.c_str (), O_RDONLY);
199+ if (fdConfig < 0 ) {
200+ return ;
201+ }
202+ configMemory = std::make_unique<uint8_t []>(PCI_CFG_SPACE_EXP_SIZE);
203+ memset (configMemory.get (), 0 , PCI_CFG_SPACE_EXP_SIZE);
204+ this ->preadFunction (fdConfig, configMemory.get (), PCI_CFG_SPACE_EXP_SIZE, 0 );
205+ this ->closeFunction (fdConfig);
206+ }
207+
164208LinuxPciImp::LinuxPciImp (OsSysman *pOsSysman) {
165209 pLinuxSysmanImp = static_cast <LinuxSysmanImp *>(pOsSysman);
166210 pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess ();
167211 pfsAccess = &pLinuxSysmanImp->getFsAccess ();
168212 Device *pDevice = pLinuxSysmanImp->getDeviceHandle ();
169213 isLmemSupported = pDevice->getDriverHandle ()->getMemoryManager ()->isLocalMemorySupported (pDevice->getRootDeviceIndex ());
214+ if (pSysfsAccess->isRootUser ()) {
215+ pciExtendedConfigRead ();
216+ }
170217}
171218
172219OsPci *OsPci::create (OsSysman *pOsSysman) {
0 commit comments