numam-spdk/scripts/get-pmr
Michal Berger eb4b79919a pkgdep/git: Bump vanilla qemu to v6.0.0
Older version wasn't providing full support for PMR setup, this one
does.

Rewrite get-pmr such that it supports CMB/PMR sizes greater than 4GB.
Also, since CMB and PMR can coexist in newer versions of qemu try to
detect both under single device.

E.g.:

nvme0:0000:00:04.0:64-bit:prefetchable:0x700000000:0x707ffffff:0x08000000:cmb
nvme0:0000:00:04.0:64-bit:prefetchable:0x400000000:0x5ffffffff:0x200000000:pmr
nvme1:0000:00:05.0:64-bit:prefetchable:0x708000000:0x70fffffff:0x08000000:cmb
nvme2:0000:00:06.0:64-bit:prefetchable:0x600000000:0x6ffffffff:0x100000000:cmb

Signed-off-by: Michal Berger <michalx.berger@intel.com>
Change-Id: Ic159f5c12d3ef39db77617f7d64f825356c255a4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7539
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
2021-05-11 11:51:01 +00:00

80 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# We simply check if BAR2 is present as that's where PMR or CMB is
# meant to be located under qemu. If found, print some stats then exit.
shopt -s nullglob
[[ $(uname -s) == Linux ]] || exit 0
# Use MSR instead?
[[ $(< /sys/class/dmi/id/chassis_vendor) == QEMU ]] || exit 0
get_bar() {
echo "0x$(setpci -s "$1" "$2.L")"
}
get_size() {
local addr=$1
local start end type
while IFS="- " read -r start end type; do
start=0x$start end=0x$end
if ((start == addr)) && [[ $type == *"$pci"* ]]; then
printf '0x%08x:0x%08x:0x%08x\n' \
"$start" "$end" $((end - start + 1))
return 0
fi
done < /proc/iomem
echo "unknown/unassigned"
}
info() {
local dev=$1
local pref loc
local base_addr2
local base_addr4
local bar local bar2 bar3 bar4 bar5
local bar_type2
pref[0]=non-prefetchable
pref[1]=prefetchable
print_info() {
local bar=$1 base_addr=$2 bar_type=$3
printf '%s:%s:%s:%s:%s:%s\n' \
"${nvme##*/}" \
"$dev" \
"64-bit" \
"${pref[bar & 1 << 3 ? 1 : 0]}" \
"$(get_size "$base_addr")" \
"$bar_type"
}
bar2=$(get_bar "$dev" 0x18)
bar3=$(get_bar "$dev" 0x1c)
bar4=$(get_bar "$dev" 0x20)
bar5=$(get_bar "$dev" 0x24)
# QEMU uses 64-bit BARs
if ((bar2 & 1 << 2)); then
bar_type2=pmr
if [[ -e $nvme/cmb ]]; then
bar_type2=cmb
fi
base_addr2=$(((bar2 & ~0xf) + (bar3 << 32)))
print_info "$bar2" "$base_addr2" "$bar_type2"
fi
# QEMU uses 64-bit BARs
if ((bar4 & 1 << 2)); then
base_addr4=$(((bar4 & ~0xf) + (bar5 << 32)))
print_info "$bar4" "$base_addr4" pmr
fi
}
for nvme in /sys/class/nvme/nvme*; do
pci=$(readlink -f "$nvme/device") pci=${pci##*/}
info "$pci"
done