#!/bin/sh # Trim the PCI ID database to the graphics devices of the GPU vendors, for embedding in # the binary (internal/metrics/pciids_gpu.txt): a machine without pciutils — OpenWrt has # neither lspci nor pci.ids — then names its GPU exactly as every other machine does. # # scripts/pci-ids-gpu.sh [/path/to/pci.ids] default: /usr/share/misc/pci.ids # # Kept: the vendor lines and device lines (never subsystems) of Intel 8086, AMD 1002 and # NVIDIA 10de whose name is bracketed (how pci.ids writes a marketing name) or mentions # graphics, and everything of the three virtual-GPU vendors (virtio 1af4, VMware 15ad, # Bochs 1234). A non-GPU device slipping through costs a line; it is only ever consulted # for a card the kernel already drives as a GPU. set -eu src=${1:-/usr/share/misc/pci.ids} out=$(dirname "$0")/../internal/metrics/pciids_gpu.txt { echo "# Trimmed from pci.ids ($(grep -m1 -i 'version:' "$src" | sed 's/^#[[:space:]]*//')) by scripts/pci-ids-gpu.sh." echo "# Vendor lines and the graphics device lines of Intel, AMD and NVIDIA, plus the virtual GPUs." echo "# pci.ids is distributed under the 3-clause BSD license (https://pci-ids.ucw.cz/)." awk ' /^[0-9a-f][0-9a-f][0-9a-f][0-9a-f] / { vendor = substr($0, 1, 4) keep = (vendor == "8086" || vendor == "1002" || vendor == "10de") all = (vendor == "1af4" || vendor == "15ad" || vendor == "1234") if (keep || all) print next } /^\t[0-9a-f][0-9a-f][0-9a-f][0-9a-f] / { if (all) { print; next } if (!keep) next if ($0 ~ /\[/ || $0 ~ /Graphics|Radeon|GeForce|Quadro|Tesla|Arc |Iris|Xe |GPU|Display|VGA|FirePro|Instinct|Data Center/) print } ' "$src" } > "$out" echo "$out: $(wc -l < "$out") lines, $(wc -c < "$out") bytes"