-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.sh
executable file
·116 lines (106 loc) · 2.56 KB
/
2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
PCI_PATH="/sys/bus/pci/devices"
TBT_PATH="/sys/bus/thunderbolt/devices"
REGEX_ITEM="-"
HOST_EXCLUDE="\-0"
PCI_HEX_FILE="/tmp/PCI_HEX.txt"
PCI_DEC_FILE="/tmp/PCI_DEC.txt"
PCI_HEX=""
PCI_DEC=""
find_root_pci()
{
local icl=$(dmidecode | grep "ICL")
if [[ -n "$icl" ]]; then
echo "ICL platform"
tbt_dev=$(ls ${TBT_PATH} \
| grep "$REGEX_ITEM" \
| grep -v "$HOST_EXCLUDE" \
| awk '{ print length(), $0 | "sort -n" }' \
| grep ^3 \
| cut -d ' ' -f 2 \
| head -n1)
case ${tbt_dev} in
0-1)
ROOT_PCI="0000:00:07.0"
;;
0-3)
ROOT_PCI="0000:00:07.1"
;;
1-1)
ROOT_PCI="0000:00:07.2"
;;
1-3)
ROOT_PCI="0000:00:07.3"
;;
*)
echo "ICL platform didn't find root pci, set 0000:00:07.0 as default!!!"
ROOT_PCI="0000:00:07.0"
;;
esac
else
ROOT_PCI=$(udevadm info --attribute-walk --path=/sys/bus/thunderbolt/devices/0-0 | grep KERNEL | tail -n 2 | grep -v pci0000 | cut -d "\"" -f 2)
#ROOT_PCI="0000:03:00.0"
fi
}
tbt_ds_pci()
{
local pcis=""
local pci=""
local pci_ds=""
local pci_content=""
pcis=$(ls -1 $PCI_PATH)
for pci in $pcis; do
pci_ds=""
pci_content=$(ls -ltra $PCI_PATH/$pci)
pci_ds=$(lspci -v -s $pci | grep -i downstream)
if [[ -z "$pci_ds" ]]; then
continue
else
echo "Downstream pci:$pci"
fi
done
}
tbt_us_pci()
{
local pcis=""
local pci=""
local pci_us=""
local pci_content=""
[[ -n "$ROOT_PCI" ]] || {
echo "Could not find tbt root PCI, exit!"
exit 2
}
pcis=$(ls -1 $PCI_PATH)
cat /dev/null > $PCI_HEX_FILE
cat /dev/null > $PCI_DEC_FILE
for pci in $pcis; do
pci_ds=""
PCI_HEX=""
PCI_DEC=""
pci_content=$(ls -ltra $PCI_PATH/$pci)
[[ "$pci_content" == *"$ROOT_PCI"* ]] || continue
pci_us=$(lspci -v -s $pci | grep -i upstream)
if [[ -z "$pci_us" ]]; then
continue
else
echo "Upstream pci:$pci"
PCI_HEX=$(echo $pci | cut -d ':' -f 2)
PCI_DEC=$((0x"$PCI_HEX"))
# Due to ICL tbt driver PCI 00:0d.2 and 00:0d.3
# hard code to greater than 3: tbt driver pci
[[ "$PCI_DEC" -gt 3 ]] || {
echo "$PCI_DEC not greater than 3, skip"
continue
}
echo $PCI_HEX >> $PCI_HEX_FILE
echo $PCI_DEC >> $PCI_DEC_FILE
fi
done
echo "TBT device upstream PCI in hex:"
cat $PCI_HEX_FILE
echo "TBT device upstream PCI in dec:"
cat $PCI_DEC_FILE
}
find_root_pci
#tbt_ds_pci
tbt_us_pci