0x00

记录一下查询IOMMU分组的命令

总共2个, 一个简单一个比较复杂

简单一句话

1
for d in /sys/kernel/iommu_groups/*/devices/*; do n=${d#*/iommu_groups/*}; n=${n%%/*}; printf 'IOMMU Group %s ' "$n"; lspci -nns "${d##*/}"; done

输出如下:

1
2
IOMMU Group 63 43:00.0 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] [1022:7901] (rev 51)
IOMMU Group 64 44:00.0 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD] FCH SATA Controller [AHCI mode] [1022:7901] (rev 51)

详细直观

from github

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

shopt -s nullglob
lastgroup=""
for g in `find /sys/kernel/iommu_groups/* -maxdepth 0 -type d | sort -V`; do
for d in $g/devices/*; do
if [ "${g##*/}" != "$lastgroup" ]; then
echo -en "Group ${g##*/}:\t"
else
echo -en "\t\t"
fi
lastgroup=${g##*/}
lspci -nms ${d##*/} | awk -F'"' '{printf "[%s:%s]", $4, $6}'
if [[ -e "$d"/reset ]]; then echo -en " [R] "; else echo -en " "; fi

lspci -mms ${d##*/} | awk -F'"' '{printf "%s %-40s %s\n", $1, $2, $6}'
for u in ${d}/usb*/; do
bus=$(cat "${u}/busnum")
lsusb -s $bus: | \
awk '{gsub(/:/,"",$4); printf "%s|%s %s %s %s|", $6, $1, $2, $3, $4; for(i=7;i<=NF;i++){printf "%s ", $i}; printf "\n"}' | \
awk -F'|' '{printf "USB:\t\t[%s]\t\t %-40s %s\n", $1, $2, $3}'
done
done
done

输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Group 0:	[1022:1482]     c0:01.0  Host bridge                              Starship/Matisse PCIe Dummy Host Bridge
Group 1: [1022:1482] c0:02.0 Host bridge Starship/Matisse PCIe Dummy Host Bridge
Group 2: [1022:1482] c0:03.0 Host bridge Starship/Matisse PCIe Dummy Host Bridge
[1022:1483] [R] c0:03.1 PCI bridge Starship/Matisse GPP Bridge
[1022:1483] [R] c0:03.2 PCI bridge Starship/Matisse GPP Bridge
[1022:1483] [R] c0:03.4 PCI bridge Starship/Matisse GPP Bridge
[1022:1483] [R] c0:03.5 PCI bridge Starship/Matisse GPP Bridge
[1a03:1150] [R] c1:00.0 PCI bridge AST1150 PCI-to-PCI Bridge
[1a03:2000] [R] c2:00.0 VGA compatible controller ASPEED Graphics Family
[1b21:1142] [R] c3:00.0 USB controller ASM1042A USB 3.0 Host Controller
USB: [051d:0002] Bus 001 Device 002 American Power Conversion Uninterruptible Power Supply
USB: [1d6b:0002] Bus 001 Device 001 Linux Foundation 2.0 root hub
USB: [1d6b:0003] Bus 002 Device 001 Linux Foundation 3.0 root hub
[8086:1533] [R] c4:00.0 Ethernet controller I210 Gigabit Network Connection
[8086:1533] [R] c5:00.0 Ethernet controller I210 Gigabit Network Connection
Group 3: [1022:1482] c0:04.0 Host bridge Starship/Matisse PCIe Dummy Host Bridge
Group 4: [1022:1482] c0:05.0 Host bridge Starship/Matisse PCIe Dummy Host Bridge

评论