mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-07 21:50:08 +01:00
Chore: run clang-format
```bash find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) ! -path "src/3rdparty/*" -print0 | xargs -0 clang-format -i ```
This commit is contained in:
@@ -8,8 +8,7 @@
|
||||
#include <dev/pci/pcidevs.h>
|
||||
#include <sys/pciio.h>
|
||||
|
||||
static inline int pciReadConf(int fd, uint8_t bus, uint8_t device, uint8_t func, uint8_t reg, uint32_t* result)
|
||||
{
|
||||
static inline int pciReadConf(int fd, uint8_t bus, uint8_t device, uint8_t func, uint8_t reg, uint32_t* result) {
|
||||
struct pci_io bdfr = {
|
||||
.pi_sel = {
|
||||
.pc_bus = bus,
|
||||
@@ -20,55 +19,60 @@ static inline int pciReadConf(int fd, uint8_t bus, uint8_t device, uint8_t func,
|
||||
.pi_width = 4,
|
||||
};
|
||||
|
||||
if (ioctl(fd, PCIOCREAD, &bdfr) == -1)
|
||||
if (ioctl(fd, PCIOCREAD, &bdfr) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*result = bdfr.pi_data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus)
|
||||
{
|
||||
const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus) {
|
||||
char pciDevPath[] = "/dev/pci0";
|
||||
FF_AUTO_CLOSE_FD int pcifd = open(pciDevPath, O_RDONLY | O_CLOEXEC);
|
||||
if (pcifd < 0)
|
||||
if (pcifd < 0) {
|
||||
return "open(\"/dev/pci0\", O_RDONLY | O_CLOEXEC) failed";
|
||||
}
|
||||
|
||||
for (uint16_t bus = 0; bus <= 255; bus++)
|
||||
{
|
||||
for (uint8_t dev = 0; dev < 32; dev++)
|
||||
{
|
||||
for (uint16_t bus = 0; bus <= 255; bus++) {
|
||||
for (uint8_t dev = 0; dev < 32; dev++) {
|
||||
uint8_t maxfuncs = 0;
|
||||
for (uint8_t func = 0; func <= maxfuncs; func++)
|
||||
{
|
||||
for (uint8_t func = 0; func <= maxfuncs; func++) {
|
||||
uint32_t pciid, pciclass;
|
||||
if (pciReadConf(pcifd, (uint8_t) bus, dev, func, PCI_ID_REG, &pciid) != 0)
|
||||
if (pciReadConf(pcifd, (uint8_t) bus, dev, func, PCI_ID_REG, &pciid) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PCI_VENDOR(pciid) == PCI_VENDOR_INVALID || PCI_VENDOR(pciid) == 0)
|
||||
if (PCI_VENDOR(pciid) == PCI_VENDOR_INVALID || PCI_VENDOR(pciid) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pciReadConf(pcifd, (uint8_t) bus, dev, func, PCI_CLASS_REG, &pciclass) != 0)
|
||||
if (pciReadConf(pcifd, (uint8_t) bus, dev, func, PCI_CLASS_REG, &pciclass) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (func == 0)
|
||||
{
|
||||
if (func == 0) {
|
||||
// For some reason, pciReadConf returns success even for non-existing devices.
|
||||
// So we need to check for `PCI_VENDOR(pciid) == PCI_VENDOR_INVALID` above to filter them out.
|
||||
uint32_t bhlcr;
|
||||
if (pciReadConf(pcifd, (uint8_t) bus, dev, 0, PCI_BHLC_REG, &bhlcr) != 0)
|
||||
if (pciReadConf(pcifd, (uint8_t) bus, dev, 0, PCI_BHLC_REG, &bhlcr) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PCI_HDRTYPE_MULTIFN(bhlcr)) maxfuncs = 7;
|
||||
if (PCI_HDRTYPE_MULTIFN(bhlcr)) {
|
||||
maxfuncs = 7;
|
||||
}
|
||||
}
|
||||
|
||||
if (PCI_CLASS(pciclass) != PCI_CLASS_DISPLAY)
|
||||
if (PCI_CLASS(pciclass) != PCI_CLASS_DISPLAY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (func > 0 && PCI_SUBCLASS(pciclass) == PCI_SUBCLASS_DISPLAY_MISC)
|
||||
if (func > 0 && PCI_SUBCLASS(pciclass) == PCI_SUBCLASS_DISPLAY_MISC) {
|
||||
continue; // Likely an auxiliary display controller (#2034)
|
||||
}
|
||||
|
||||
FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
|
||||
FFGPUResult* gpu = (FFGPUResult*) ffListAdd(gpus);
|
||||
ffStrbufInitStatic(&gpu->vendor, ffGPUGetVendorString(PCI_VENDOR(pciid)));
|
||||
ffStrbufInit(&gpu->name);
|
||||
ffStrbufInit(&gpu->driver);
|
||||
@@ -83,10 +87,12 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
|
||||
gpu->deviceId = ffGPUPciAddr2Id(0, bus, dev, func);
|
||||
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
|
||||
|
||||
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
|
||||
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD) {
|
||||
ffGPUQueryAmdGpuName(PCI_PRODUCT(pciid), PCI_REVISION(pciid), gpu);
|
||||
if (gpu->name.length == 0)
|
||||
}
|
||||
if (gpu->name.length == 0) {
|
||||
ffGPUFillVendorAndName(PCI_SUBCLASS(pciclass), PCI_VENDOR(pciid), PCI_PRODUCT(pciid), gpu);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user