#!/bin/bash
PCI_IDS=$(find /usr/share -maxdepth 2 -name "pci.ids" -print -quit) #Some distros don't store it in the same place.
for CARD in /sys/class/drm/card[0-99]/device;
do
source $CARD/uevent
IFS=: PCI_ID=(${PCI_ID,,}) PCI_SUBSYS_ID=(${PCI_SUBSYS_ID,,})
VENDOR_DEVICELIST=$(awk "/^${PCI_ID[0]}/{a=1;next}/^.... /{a=0}a" $PCI_IDS)
NAME=$(sed -n "0,/\s*${PCI_SUBSYS_ID[0]} ${PCI_SUBSYS_ID[1]} /s///p" <<< $VENDOR_DEVICELIST)
[ -z $NAME ] && NAME=$(sed -n "0,/\s*${PCI_ID[1]} /s///p" <<< $VENDOR_DEVICELIST)
NAME=$(awk -F'[][]' '{if ($2) {print $2} else {print $0}}' <<< $NAME)
echo $NAME
done
It gets a little messy there at the end, but this should work now for both your pc and mine. Itâll try to find a refernece to the subsystem_id under the vendorâs device list, and if it cannot be found it defaults to the device id instead.
So it should always give the most specific result available now.
I would have liked to set $NAME in one line instead of 3. But if it works, it works.