diff --git a/scripts/common.sh b/scripts/common.sh index 5174487d1..e1328a669 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -128,18 +128,22 @@ cache_pci_bus_pciconf() { cache_pci_init || return 0 - local class vd vendor device - local pci domain bus device function + local class vendor device + local pci pci_info + local chip driver - while read -r pci class _ vd _; do - IFS=":" read -r domain bus device function _ <<< "${pci##*pci}" - pci=$(printf '%04x:%02x:%02x:%x' \ - "$domain" "$bus" "$device" "$function") - class=$(printf '0x%06x' $((class))) - vendor=$(printf '0x%04x' $((vd & 0xffff))) - device=$(printf '0x%04x' $(((vd >> 16) & 0xffff))) - - cache_pci "$pci" "$class" "$vendor" "$device" + while read -r pci pci_info; do + driver=${pci%@*} + pci=${pci##*pci} pci=${pci%:} + source <(echo "$pci_info") + # pciconf under FreeBSD 13.1 provides vendor and device IDs in its + # output under separate, dedicated fields. For 12.x they need to + # be extracted from the chip field. + if [[ -n $chip ]]; then + vendor=$(printf '0x%04x' $((chip & 0xffff))) + device=$(printf '0x%04x' $(((chip >> 16) & 0xffff))) + fi + cache_pci "$pci" "$class" "$vendor" "$device" "$driver" done < <(pciconf -l) } @@ -190,7 +194,7 @@ function iter_all_pci_class_code() { elif hash pciconf &> /dev/null; then local addr=($(pciconf -l | grep -i "class=0x${class}${subclass}${progif}" \ | cut -d$'\t' -f1 | sed -e 's/^[a-zA-Z0-9_]*@pci//g' | tr ':' ' ')) - printf "%04x:%02x:%02x:%x\n" ${addr[0]} ${addr[1]} ${addr[2]} ${addr[3]} + echo "${addr[0]}:${addr[1]}:${addr[2]}:${addr[3]}" elif iter_all_pci_sysfs "$(printf '0x%06x' $((0x$progif | 0x$subclass << 8 | 0x$class << 16)))"; then : else @@ -210,9 +214,9 @@ function iter_all_pci_dev_id() { lspci -mm -n -D | awk -v ven="\"$ven_id\"" -v dev="\"${dev_id}\"" -F " " \ '{if (ven ~ $3 && dev ~ $4) print $1}' | tr -d '"' elif hash pciconf &> /dev/null; then - local addr=($(pciconf -l | grep -i "chip=0x${dev_id}${ven_id}" \ + local addr=($(pciconf -l | grep -iE "chip=0x${dev_id}${ven_id}|vendor=0x$ven_id device=0x$dev_id" \ | cut -d$'\t' -f1 | sed -e 's/^[a-zA-Z0-9_]*@pci//g' | tr ':' ' ')) - printf "%04x:%02x:%02x:%x\n" ${addr[0]} ${addr[1]} ${addr[2]} ${addr[3]} + echo "${addr[0]}:${addr[1]}:${addr[2]}:${addr[3]}" elif iter_all_pci_sysfs "0x$ven_id:0x$dev_id"; then : else diff --git a/scripts/setup.sh b/scripts/setup.sh index 8a603a7db..00f13d8e4 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -689,13 +689,11 @@ function status_freebsd() { echo -e "BDF\t\tVendor\tDevice\tDriver" for pci; do - driver=$(pciconf -l "pci$pci") - driver=${driver%@*} printf '%s\t%s\t%s\t%s\n' \ "$pci" \ "${pci_ids_vendor["$pci"]}" \ "${pci_ids_device["$pci"]}" \ - "$driver" + "${pci_bus_driver["$pci"]}" done | sort -k1,1 )