判断某地址是否为合法的PCIE BAR空间地址
- 一.生成BAR空间范围表
- 二.判断脚本
- 三.测试
以下脚本用来判断某地址是否为合法的PCIE BAR空间地址
一.生成BAR空间范围表
lspci -d:0100 -vv | grep "Region 0:" | gawk --non-decimal-data '{A="0x"$5;B=0x200000;printf "0x%x,0x%x\n",A,A+B}' > range.csv
lspci -d:0100 -vv | grep "Region 1:" | gawk --non-decimal-data '{A="0x"$5;B=0x400000;printf "0x%x,0x%x\n",A,A+B}' >> range.csv
lspci -d:0100 -vv | grep "Region 2:" | gawk --non-decimal-data '{A="0x"$5;B=0x800000000;printf "0x%x,0x%x\n",A,A+B}' >> range.csv
二.判断脚本
cat > in_range.py <<-'EOF'
import sys
import os
addr=sys.argv[1]
addr=int(addr,16)
with open("range.csv","r") as f:data=[]for line in f.readlines():beg,end=line.split(",")beg=int(beg,16)end=int(end,16)if addr>=beg and addr<=end:print("0x%x in [%x:%x]" % (addr,beg,end))os._exit(0)
print("0x%x out of range" % (addr))
EOF
三.测试
python3 in_range.py 0xd90fa800