| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/info/common/gpuinfouevent.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "gpuinfouevent.h"cxx . . $ `<file>/src/core/info/common/gpuinfouevent.h`/ |
| 5 | |
| 6 | #include "../ihwidtranslator.h"cxx . . $ `<file>/src/core/info/ihwidtranslator.h`/ |
| 7 | #include "../infoproviderregistry.h"cxx . . $ `<file>/src/core/info/infoproviderregistry.h`/ |
| 8 | #include "gpuinfoueventdatasource.h"cxx . . $ `<file>/src/core/info/common/gpuinfoueventdatasource.h`/ |
| 9 | #include <algorithm> |
| 10 | #include <cctype> |
| 11 | #include <spdlog/spdlog.h> |
| 12 | #include <string_view> |
| 13 | #include <utility> |
| 14 | |
| 15 | GPUInfoUeventcxx . . $ GPUInfoUevent#::GPUInfoUeventcxx . . $ GPUInfoUevent#GPUInfoUevent(50458470b84e8b0c).( |
| 16 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IDataSourcecxx . . $ IDataSource#<stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#>, stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const>> |
| 17 | &&dataSource) noexcept |
| 18 | : dataSource_cxx . . $ GPUInfoUevent#dataSource_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(dataSource)) |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>> |
| 23 | GPUInfoUeventcxx . . $ GPUInfoUevent#::provideInfocxx . . $ GPUInfoUevent#provideInfo(5b65f7e996e13d80).(Vendorcxx . . $ Vendor#, int, IGPUInfocxx . . $ IGPUInfo#::Pathcxx . . $ IGPUInfo#Path# const &path, |
| 24 | IHWIDTranslatorcxx . . $ IHWIDTranslator# const &hwIDTranslator) const |
| 25 | { |
| 26 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>> infocxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 27 | |
| 28 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# driverStrcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).{"DRIVER"}; |
| 29 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# pciIdStrcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).{"PCI_ID"}; |
| 30 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# pciSubsysIdStrcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).{"PCI_SUBSYS_ID"}; |
| 31 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# pciSlotStrcxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).{"PCI_SLOT_NAME"}; |
| 32 | |
| 33 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> datacxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 34 | if (dataSource_cxx . . $ GPUInfoUevent#dataSource_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).readcxx . . $ IDataSource#read(ad81cd1bcc32f58b).(data, path.syscxx . . $ IGPUInfo#Path#sys.)) { |
| 35 | stdcxx . . $ std/::stringcxx . . $ std/string# vendorIdcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 36 | stdcxx . . $ std/::stringcxx . . $ std/string# deviceIdcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 37 | stdcxx . . $ std/::stringcxx . . $ std/string# subvendorIdcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 38 | stdcxx . . $ std/::stringcxx . . $ std/string# subdeviceIdcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 39 | stdcxx . . $ std/::stringcxx . . $ std/string# pciSlotcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 40 | stdcxx . . $ std/::stringcxx . . $ std/string# drivercxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 41 | |
| 42 | for (auto const &line : data) { |
| 43 | if (line.findcxx . . $ std/__cxx11/basic_string#find(f84f8bea57cb23bc).(driverStr) == 0) { |
| 44 | driver =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). line.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).(driverStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).() + 1, stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.); |
| 45 | } |
| 46 | else if (line.findcxx . . $ std/__cxx11/basic_string#find(f84f8bea57cb23bc).(pciIdStr) == 0) { |
| 47 | auto colonPos = line.findcxx . . $ std/__cxx11/basic_string#find(bec4eca5a23fda83).(':', pciIdStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).() + 1); |
| 48 | vendorId =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). line.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).(pciIdStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).() + 1, |
| 49 | colonPos - pciIdStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).() - 1); |
| 50 | deviceId =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). line.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).(colonPos + 1, stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.); |
| 51 | } |
| 52 | else if (line.findcxx . . $ std/__cxx11/basic_string#find(f84f8bea57cb23bc).(pciSubsysIdStr) == 0) { |
| 53 | auto colonPos = line.findcxx . . $ std/__cxx11/basic_string#find(bec4eca5a23fda83).(':', pciSubsysIdStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).() + 1); |
| 54 | subvendorId =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). line.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).(pciSubsysIdStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).() + 1, |
| 55 | colonPos - pciSubsysIdStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).() - 1); |
| 56 | subdeviceId =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). line.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).(colonPos + 1, stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.); |
| 57 | } |
| 58 | else if (line.findcxx . . $ std/__cxx11/basic_string#find(f84f8bea57cb23bc).(pciSlotStr) == 0) { |
| 59 | pciSlot =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). line.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).(pciSlotStr.lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).() + 1, stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | if (vendorId.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 64 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot retrieve vendor ID"); |
| 65 | if (deviceId.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 66 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot retrieve device ID"); |
| 67 | if (subvendorId.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 68 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot retrieve subvendor ID"); |
| 69 | if (subdeviceId.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 70 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot retrieve subdevice ID"); |
| 71 | if (pciSlot.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 72 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot retrieve pci slot"); |
| 73 | if (driver.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 74 | SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot retrieve driver"); |
| 75 | |
| 76 | // ensure that all ids are in uppercase |
| 77 | stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(vendorId.cbegincxx . . $ std/__cxx11/basic_string#cbegin(a865d278ca20c908).(), vendorId.cendcxx . . $ std/__cxx11/basic_string#cend(a865d278ca20c908).(), vendorId.begincxx . . $ std/__cxx11/basic_string#begin(fd29ebd65481b919).(), |
| 78 | ::toupper); |
| 79 | stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(deviceId.cbegincxx . . $ std/__cxx11/basic_string#cbegin(a865d278ca20c908).(), deviceId.cendcxx . . $ std/__cxx11/basic_string#cend(a865d278ca20c908).(), deviceId.begincxx . . $ std/__cxx11/basic_string#begin(fd29ebd65481b919).(), |
| 80 | ::toupper); |
| 81 | stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(subvendorId.cbegincxx . . $ std/__cxx11/basic_string#cbegin(a865d278ca20c908).(), subvendorId.cendcxx . . $ std/__cxx11/basic_string#cend(a865d278ca20c908).(), |
| 82 | subvendorId.begincxx . . $ std/__cxx11/basic_string#begin(fd29ebd65481b919).(), ::toupper); |
| 83 | stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(subdeviceId.cbegincxx . . $ std/__cxx11/basic_string#cbegin(a865d278ca20c908).(), subdeviceId.cendcxx . . $ std/__cxx11/basic_string#cend(a865d278ca20c908).(), |
| 84 | subdeviceId.begincxx . . $ std/__cxx11/basic_string#begin(fd29ebd65481b919).(), ::toupper); |
| 85 | |
| 86 | // populate info |
| 87 | auto vendorName = hwIDTranslator.vendorcxx . . $ IHWIDTranslator#vendor(ed3976f106e8bf8e).(vendorId); |
| 88 | if (!vendorName.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 89 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(IGPUInfocxx . . $ IGPUInfo#::Keyscxx . . $ IGPUInfo#Keys#::vendorNamecxx . . $ IGPUInfo#Keys#vendorName., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(vendorName)); |
| 90 | |
| 91 | auto deviceName = hwIDTranslator.devicecxx . . $ IHWIDTranslator#device(ee8c6c2661a93592).(vendorId, deviceId); |
| 92 | if (!deviceName.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 93 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(IGPUInfocxx . . $ IGPUInfo#::Keyscxx . . $ IGPUInfo#Keys#::deviceNamecxx . . $ IGPUInfo#Keys#deviceName., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(deviceName)); |
| 94 | |
| 95 | auto subdeviceName = hwIDTranslator.subdevicecxx . . $ IHWIDTranslator#subdevice(f1e1f68436fc7a45).(vendorId, deviceId, |
| 96 | subvendorId, subdeviceId); |
| 97 | if (!subdeviceName.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 98 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(IGPUInfocxx . . $ IGPUInfo#::Keyscxx . . $ IGPUInfo#Keys#::subdeviceNamecxx . . $ IGPUInfo#Keys#subdeviceName., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(subdeviceName)); |
| 99 | |
| 100 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(IGPUInfocxx . . $ IGPUInfo#::Keyscxx . . $ IGPUInfo#Keys#::drivercxx . . $ IGPUInfo#Keys#driver., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(driver)); |
| 101 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(IGPUInfocxx . . $ IGPUInfo#::Keyscxx . . $ IGPUInfo#Keys#::pciSlotcxx . . $ IGPUInfo#Keys#pciSlot., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(pciSlot)); |
| 102 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(IGPUInfocxx . . $ IGPUInfo#::Keyscxx . . $ IGPUInfo#Keys#::vendorIDcxx . . $ IGPUInfo#Keys#vendorID., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(vendorId)); |
| 103 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(IGPUInfocxx . . $ IGPUInfo#::Keyscxx . . $ IGPUInfo#Keys#::deviceIDcxx . . $ IGPUInfo#Keys#deviceID., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(deviceId)); |
| 104 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(IGPUInfocxx . . $ IGPUInfo#::Keyscxx . . $ IGPUInfo#Keys#::subvendorIDcxx . . $ IGPUInfo#Keys#subvendorID., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(subvendorId)); |
| 105 | info.emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(IGPUInfocxx . . $ IGPUInfo#::Keyscxx . . $ IGPUInfo#Keys#::subdeviceIDcxx . . $ IGPUInfo#Keys#subdeviceID., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(subdeviceId)); |
| 106 | } |
| 107 | |
| 108 | return infocxx . . $ std/vector#vector(6f559d22b039ccdb).; |
| 109 | } |
| 110 | |
| 111 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> |
| 112 | GPUInfoUeventcxx . . $ GPUInfoUevent#::provideCapabilitiescxx . . $ GPUInfoUevent#provideCapabilities(da28437f5803dad2).(Vendorcxx . . $ Vendor#, int, IGPUInfocxx . . $ IGPUInfo#::Pathcxx . . $ IGPUInfo#Path# const &) const |
| 113 | { |
| 114 | return {cxx . . $ std/vector#vector(49f6e7a06ebc5aa8).}; |
| 115 | } |
| 116 | |
| 117 | bool GPUInfoUeventcxx . . $ GPUInfoUevent#::registered_cxx . . $ GPUInfoUevent#registered_. = InfoProviderRegistrycxx . . $ InfoProviderRegistry#::addcxx . . $ InfoProviderRegistry#add(2c04d579dc484cde).( |
| 118 | stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<GPUInfoUeventcxx . . $ GPUInfoUevent#>(stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<GPUInfoUeventDataSourcecxx . . $ GPUInfoUeventDataSource#>())); |