Skip to content

Commit

Permalink
update script according to feedback this time
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsmithTT committed Dec 13, 2024
1 parent 7688beb commit e80bbcb
Showing 1 changed file with 32 additions and 36 deletions.
68 changes: 32 additions & 36 deletions scripts/iommu_detect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ GS_PID="faca"
WH_PID="401e"
BH_PID="b140"

function check_iommu() {
local dev=$1
if [ -f "/sys/bus/pci/devices/${dev}/iommu_group/type" ]; then
iommu_type=$(cat "/sys/bus/pci/devices/${dev}/iommu_group/type")
if [[ "$iommu_type" == *"DMA"* ]]; then
echo "enabled" "$iommu_type"
else
echo "passthrough" "$iommu_type"
fi
else
echo "disabled" "none"
fi
}

tt_devices=$(lspci -D -d ${TT_VID}: | cut -d' ' -f1)

if [ -z "$tt_devices" ]; then
Expand All @@ -29,35 +15,45 @@ fi

found_gs_wh=false
found_bh=false
iommu_enabled=false

# First identify devices
for dev in $tt_devices; do
device_id=$(lspci -D -n -s "$dev" | cut -d' ' -f3 | cut -d: -f2)
echo "Checking device $dev (ID: $device_id):"

read iommu_status iommu_type < <(check_iommu "$dev")

case $device_id in
$GS_PID|$WH_PID)
found_gs_wh=true
if [ "$iommu_status" = "enabled" ]; then
echo " WARNING: Grayskull/Wormhole device with IOMMU enabled (type: $iommu_type) - this configuration is not supported"
else
echo " Grayskull/Wormhole device detected - hugepages required"
fi
;;
$BH_PID)
found_bh=true
case "$iommu_status" in
"enabled") echo " Blackhole device with IOMMU enabled (type: $iommu_type) - hugepages unneeded" ;;
*) echo " Blackhole device with no IOMMU/passthrough (type: $iommu_type) - hugepages required" ;;
esac
;;
*)
echo " Unknown device ID: $device_id"
;;
$GS_PID|$WH_PID) found_gs_wh=true ;;
$BH_PID) found_bh=true ;;
esac
done

# Then check IOMMU status
if [ -f "/sys/bus/pci/devices/${dev}/iommu_group/type" ]; then
iommu_type=$(cat "/sys/bus/pci/devices/${dev}/iommu_group/type")
[[ "$iommu_type" == *"DMA"* ]] && iommu_enabled=true
fi

# Finally output messages based on device type and IOMMU status
for dev in $tt_devices; do
device_id=$(lspci -D -n -s "$dev" | cut -d' ' -f3 | cut -d: -f2)
echo "Checking device $dev (ID: $device_id):"

if [[ "$device_id" == "$GS_PID" || "$device_id" == "$WH_PID" ]]; then
if [ "$iommu_enabled" = true ]; then
echo " WARNING: Grayskull/Wormhole device with IOMMU enabled (type: $iommu_type) - this configuration is not supported"
else
echo " Grayskull/Wormhole device detected - hugepages required"
fi
elif [[ "$device_id" == "$BH_PID" ]]; then
if [ "$iommu_enabled" = true ]; then
echo " Blackhole device with IOMMU enabled (type: $iommu_type) - hugepages optional"
else
echo " Blackhole device with no IOMMU/passthrough (type: $iommu_type) - hugepages required"
fi
else
echo " Unknown device ID: $device_id"
fi
done

echo -e "\nSummary:"
if [ "$found_gs_wh" = true ]; then
echo "- System has Grayskull/Wormhole devices - hugepages required"
Expand Down

0 comments on commit e80bbcb

Please sign in to comment.