Hash :
0615bbde
Author :
Date :
2021-04-12T15:29:26
Ignore subclass when finding GPU PCI devices When enumerating PCI devices to find GPUs, only filter on the base class. This allows devices with class PCI_CLASS_DISPLAY_OTHER to be found. Bug: b/178748337 Change-Id: Ia0cd29dddc49a16428da16c1ef1b94040c1221f7 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2817973 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jonah Ryan-Davis <jonahr@google.com> Commit-Queue: Jonah Ryan-Davis <jonahr@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
//
// Copyright 2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SystemInfo_libpci.cpp: implementation of the libPCI-specific parts of SystemInfo.h
#include "gpu_info_util/SystemInfo_internal.h"
#include <dlfcn.h>
#include <pci/pci.h>
#include <unistd.h>
#include "common/angleutils.h"
#include "common/debug.h"
#if !defined(GPU_INFO_USE_LIBPCI)
# error SystemInfo_libpci.cpp compiled without GPU_INFO_USE_LIBPCI
#endif
namespace angle
{
namespace
{
struct LibPCI : private angle::NonCopyable
{
LibPCI()
{
if (access("/sys/bus/pci/", F_OK) != 0 && access("/sys/bs/pci_express/", F_OK) != 0)
{
return;
}
mHandle = dlopen("libpci.so.3", RTLD_LAZY);
if (mHandle == nullptr)
{
mHandle = dlopen("libpci.so", RTLD_LAZY);
}
if (mHandle == nullptr)
{
return;
}
mValid =
(Alloc = reinterpret_cast<decltype(Alloc)>(dlsym(mHandle, "pci_alloc"))) != nullptr &&
(Init = reinterpret_cast<decltype(Init)>(dlsym(mHandle, "pci_init"))) != nullptr &&
(Cleanup = reinterpret_cast<decltype(Cleanup)>(dlsym(mHandle, "pci_cleanup"))) !=
nullptr &&
(ScanBus = reinterpret_cast<decltype(ScanBus)>(dlsym(mHandle, "pci_scan_bus"))) !=
nullptr &&
(FillInfo = reinterpret_cast<decltype(FillInfo)>(dlsym(mHandle, "pci_fill_info"))) !=
nullptr &&
(LookupName = reinterpret_cast<decltype(LookupName)>(
dlsym(mHandle, "pci_lookup_name"))) != nullptr &&
(PCIReadByte = reinterpret_cast<decltype(PCIReadByte)>(
dlsym(mHandle, "pci_read_byte"))) != nullptr;
}
bool IsValid() const { return mValid; }
~LibPCI()
{
if (mHandle != nullptr)
{
dlclose(mHandle);
}
}
decltype(&::pci_alloc) Alloc = nullptr;
decltype(&::pci_init) Init = nullptr;
decltype(&::pci_cleanup) Cleanup = nullptr;
decltype(&::pci_scan_bus) ScanBus = nullptr;
decltype(&::pci_fill_info) FillInfo = nullptr;
decltype(&::pci_lookup_name) LookupName = nullptr;
decltype(&::pci_read_byte) PCIReadByte = nullptr;
private:
void *mHandle = nullptr;
bool mValid = false;
};
} // anonymous namespace
// Adds an entry per PCI GPU found and fills the device and vendor ID.
bool GetPCIDevicesWithLibPCI(std::vector<GPUDeviceInfo> *devices)
{
LibPCI pci;
if (!pci.IsValid())
{
return false;
}
pci_access *access = pci.Alloc();
ASSERT(access != nullptr);
pci.Init(access);
pci.ScanBus(access);
for (pci_dev *device = access->devices; device != nullptr; device = device->next)
{
pci.FillInfo(device, PCI_FILL_IDENT | PCI_FILL_CLASS);
// Skip non-GPU devices
if (device->device_class >> 8 != PCI_BASE_CLASS_DISPLAY)
{
continue;
}
// Skip unknown devices
if (device->vendor_id == 0 || device->device_id == 0)
{
continue;
}
GPUDeviceInfo info;
info.vendorId = device->vendor_id;
info.deviceId = device->device_id;
info.revisionId = pci.PCIReadByte(device, PCI_REVISION_ID);
devices->push_back(info);
}
pci.Cleanup(access);
return true;
}
} // namespace angle