From 5f61a0c9196dbe09e741828b3e2823a3c0053faf Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Tue, 11 May 2021 12:02:33 +0200 Subject: [PATCH] scripts/common: Cache the pci driver Signed-off-by: Michal Berger Change-Id: Ie0ab6b31757b0446c697f59bfc789e78207b6e34 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7847 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki --- scripts/common.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index d560107bfb..fd5d492ac0 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -32,16 +32,18 @@ cache_pci_init() { local -gA pci_bus_cache local -gA pci_ids_vendor local -gA pci_ids_device + local -gA pci_bus_driver [[ -z ${pci_bus_cache[*]} || $CMD == reset ]] || return 1 pci_bus_cache=() pci_bus_ids_vendor=() pci_bus_ids_device=() + pci_bus_driver=() } cache_pci() { - local pci=$1 class=$2 vendor=$3 device=$4 + local pci=$1 class=$2 vendor=$3 device=$4 driver=$5 if [[ -n $class ]]; then class=0x${class/0x/} @@ -54,6 +56,9 @@ cache_pci() { pci_ids_vendor["$pci"]=$vendor pci_ids_device["$pci"]=$device fi + if [[ -n $driver ]]; then + pci_bus_driver["$pci"]=$driver + fi } cache_pci_bus_sysfs() { @@ -62,11 +67,17 @@ cache_pci_bus_sysfs() { cache_pci_init || return 0 local pci - local class vendor device + local class vendor device driver for pci in /sys/bus/pci/devices/*; do - class=$(< "$pci/class") vendor=$(< "$pci/vendor") device=$(< "$pci/device") - cache_pci "${pci##*/}" "$class" "$vendor" "$device" + class=$(< "$pci/class") vendor=$(< "$pci/vendor") device=$(< "$pci/device") driver="" + if [[ -e $pci/driver ]]; then + driver=$(readlink -f "$pci/driver") + driver=${driver##*/} + else + driver=unbound + fi + cache_pci "${pci##*/}" "$class" "$vendor" "$device" "$driver" done }