Spdk/scripts/get-pmr
paul luse eb53c23236 add (c) and SPDX header to bash files as needed
per Intel policy to include file commit date using git cmd
below.  The policy does not apply to non-Intel (C) notices.

git log --follow -C90% --format=%ad --date default <file> | tail -1

and then pull just the year from the result.

Intel copyrights were not added to files where Intel either had
no contribution ot the contribution lacked substance (ie license
header updates, formatting changes, etc)

For intel copyrights added, --follow and -C95% were used.

Signed-off-by: paul luse <paul.e.luse@intel.com>
Change-Id: I2ef86976095b88a9bf5b1003e59f3943cd6bbe4c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15209
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Krzysztof Karas <krzysztof.karas@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2022-11-29 08:27:51 +00:00

84 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (C) 2021 Intel Corporation
# All rights reserved.
# 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