From 41c20a6a4957d667b4979e53c63186da3381ab13 Mon Sep 17 00:00:00 2001 From: portellam Date: Wed, 14 Aug 2024 12:15:48 -0400 Subject: [PATCH 1/5] Update parse-iommu-devices --- bin/parse-iommu-devices | 625 +++++++++++++++++++++++----------------- 1 file changed, 356 insertions(+), 269 deletions(-) diff --git a/bin/parse-iommu-devices b/bin/parse-iommu-devices index 52a4ca5..4b76c5b 100755 --- a/bin/parse-iommu-devices +++ b/bin/parse-iommu-devices @@ -37,6 +37,203 @@ declare -A OUTPUTS=( ["FOUND_VGA_GROUP_IDS"]="" ) +function append_output_to_lists +{ + # + # Delete output given conditions (1/2) + # + if "${ARGUMENTS["MATCH_EXTERNALS"]}" \ + && ! "${has_external}"; then + group_output=( ) + fi + + if "${ARGUMENTS["MATCH_INTERNALS"]}" \ + && ! "${has_internal}"; then + group_output=( ) + fi + + # + # Append output given conditions + # + if ! is_quiet_enabled \ + && [[ "${#group_output[@]}" -gt 0 ]]; then + group_output=( + "IOMMU Group ${group_id}:" + "${group_output[@]}" + "" + ) + fi + + # + # Delete output given conditions (2/2) + # + if "${has_vga}"; then + vga_group_id_list+="${group_id}," + (( vga_group_index++ )) + fi + + if "${ARGUMENTS["MATCH_VGA_GROUP_INDEX"]}" \ + && "${has_vga}" \ + && [[ ",${ARGUMENTS["VGA_GROUP_INDEX_TO_MATCH"],,}," \ + != *",${vga_group_index},"* ]]; then + group_id_list="" + vga_group_id_list="" + driver_list="" + hardware_id_list="" + fi + + OUTPUTS["FOUND_GROUP_IDS"]+="${group_id_list}" + OUTPUTS["FOUND_VGA_GROUP_IDS"]+="${vga_group_id_list}" + OUTPUTS["FOUND_DRIVERS"]+="${driver_list}" + OUTPUTS["FOUND_HW_IDS"]+="${hardware_id_list}" +} + +function append_output_to_temp_lists +{ + if ! is_quiet_enabled; then + group_output+=( + "\t${index}.\tSlot ID:\t\t${bus_id}" + "\t\tName:\t\t${name}" + "\t\tHardware ID:\t${hardware_id}" + "\t\tDriver:\t\t" + ) + + if [[ ! -z "${driver}" ]]; then + group_output[-1]+="${driver}" + else + group_output[-1]+="N/A" + fi + + group_output+=( "" ) + fi + + if [[ ",${group_id_list,,}," != *",${group_id},"* ]]; then + group_id_list+="${group_id}," + fi + + if [[ ",${driver_list,,}," != *",${driver},"* ]]; then + driver_list+="${driver}," + fi + + if [[ ",${hardware_id_list,,}," != *",${hardware_id},"* ]]; then + hardware_id_list+="${hardware_id}," + fi +} + +function convert_driver_list_to_delimited_string +{ + if [[ -z "${OUTPUTS["FOUND_DRIVERS"]}" ]]; then + OUTPUTS["FOUND_DRIVERS"]="N/A" + return 0 + fi + + OUTPUTS["FOUND_DRIVERS"]="${OUTPUTS["FOUND_DRIVERS"]::-1}" + + OUTPUTS["FOUND_DRIVERS"]="$( \ + echo "${OUTPUTS["FOUND_DRIVERS"]}" \ + | sed --expression $'s/,/\\\n/g' \ + | sort --numeric-sort \ + | tr '\n' ',' \ + | sed 's/.$//' \ + | tr ',' '\n' \ + | sort --unique \ + | xargs \ + | tr ' ' ',' + )" +} + +function convert_group_id_list_to_delimited_string +{ + if [[ -z "${OUTPUTS["FOUND_GROUP_IDS"]}" ]]; then + OUTPUTS["FOUND_GROUP_IDS"]="N/A" + return 0 + fi + + OUTPUTS["FOUND_GROUP_IDS"]="${OUTPUTS["FOUND_GROUP_IDS"]::-1}" + + OUTPUTS["FOUND_GROUP_IDS"]="$( \ + echo "${OUTPUTS["FOUND_GROUP_IDS"]}" \ + | sed --expression $'s/,/\\\n/g' \ + | sort --numeric-sort \ + | tr '\n' ',' \ + | sed 's/.$//' \ + | tr ',' '\n' \ + | sort --unique \ + | xargs \ + | tr ' ' ',' + )" +} + +function convert_hardware_id_list_to_delimited_string +{ + if [[ -z "${OUTPUTS["FOUND_HW_IDS"]}" ]]; then + OUTPUTS["FOUND_HW_IDS"]="N/A" + return 0 + fi + + OUTPUTS["FOUND_HW_IDS"]="${OUTPUTS["FOUND_HW_IDS"]::-1}" + + OUTPUTS["FOUND_HW_IDS"]="$( \ + echo "${OUTPUTS["FOUND_HW_IDS"]}" \ + | sed --expression $'s/,/\\\n/g' \ + | sort --numeric-sort \ + | tr '\n' ',' \ + | sed 's/.$//' \ + | tr ',' '\n' \ + | sort --unique \ + | xargs \ + | tr ' ' ',' + )" +} + +function convert_vga_group_id_list_to_delimited_string +{ + if [[ -z "${OUTPUTS["FOUND_VGA_GROUP_IDS"]}" ]]; then + OUTPUTS["FOUND_VGA_GROUP_IDS"]="N/A" + return 0 + fi + + OUTPUTS["FOUND_VGA_GROUP_IDS"]="${OUTPUTS["FOUND_VGA_GROUP_IDS"]::-1}" + + OUTPUTS["FOUND_VGA_GROUP_IDS"]="$( \ + echo "${OUTPUTS["FOUND_VGA_GROUP_IDS"]}" \ + | sed --expression $'s/,/\\\n/g' \ + | sort --numeric-sort \ + | tr '\n' ',' \ + | sed 's/.$//' \ + | tr ',' '\n' \ + | sort --unique \ + | xargs \ + | tr ' ' ',' + )" +} + +function is_quiet_enabled +{ + if ! "${ARGUMENTS["GET_MINIMUM_OUTPUT"]}"; then + return 1 + fi + + return 0 +} + +function output_info +{ + if ! is_quiet_enabled; then + echo -e "Groups:\n${OUTPUTS["FOUND_GROUP_IDS"]}" + echo + echo -e "Groups with VGA device(s):\n${OUTPUTS["FOUND_VGA_GROUP_IDS"]}" + echo + echo -e "Drivers:\n${OUTPUTS["FOUND_DRIVERS"]}" + echo + echo -e "Hardware IDs:\n${OUTPUTS["FOUND_HW_IDS"]}" + return 0 + fi + + echo "${OUTPUTS["FOUND_DRIVERS"]}" + echo "${OUTPUTS["FOUND_HW_IDS"]}" +} + function parse_arguments { if [[ "${1}" == "-"* ]] \ @@ -66,59 +263,54 @@ function parse_argument while [[ ! -z "${1}" ]]; do case "${1,,}" in "-i" | "--internal" ) - ARGUMENTS["MATCH_INTERNALS"]=true - ARGUMENTS["MATCH_EXTERNALS"]=false + ARGUMENTS["MATCH_INTERNALS"]=true ;; "-e" | "--external" ) - ARGUMENTS["MATCH_EXTERNALS"]=true - ARGUMENTS["MATCH_INTERNALS"]=false + ARGUMENTS["MATCH_EXTERNALS"]=true ;; "-g" | "--group" ) - ARGUMENTS["MATCH_GROUPS"]=true - shift - parse_invalid_option "${1}" - ARGUMENTS["GROUPS_TO_MATCH"]="${1}" + ARGUMENTS["MATCH_GROUPS"]=true + shift + parse_invalid_option "${1}" + ARGUMENTS["GROUPS_TO_MATCH"]="${1}" ;; "-q" | "--quiet" ) - ARGUMENTS["GET_MINIMUM_OUTPUT"]=true + ARGUMENTS["GET_MINIMUM_OUTPUT"]=true ;; "-v" | "--vga-index" ) - ARGUMENTS["MATCH_VGA_GROUP_INDEX"]=true - shift - parse_invalid_option "${1}" - - if ! $( \ - echo "${1}" \ - | grep --extended-regexp --quiet '^[0-9]+(,[0-9]+)*$' - ) || [[ "${1}" -lt "${MIN_VGA_INDEX_VALUE}" ]]; then - if "${ARGUMENTS["GET_MINIMUM_OUTPUT"]}"; then - exit 1 - fi - - echo -e "Error: Invalid input specified." - echo "Please enter a positive non-zero number." - exit 1 - fi - - ARGUMENTS["VGA_GROUP_INDEX_TO_MATCH"]="${1}" + ARGUMENTS["MATCH_VGA_GROUP_INDEX"]=true + shift + parse_invalid_option "${1}" + + if ! $( \ + echo "${1}" \ + | grep --extended-regexp --quiet '^[0-9]+(,[0-9]+)*$' + ) || [[ "${1}" -lt "${MIN_VGA_INDEX_VALUE}" ]]; then + is_quiet_enabled && exit 1 + echo -e "Error: Invalid input specified." + echo "Please enter a positive non-zero number." + exit 1 + fi + + ARGUMENTS["VGA_GROUP_INDEX_TO_MATCH"]="${1}" ;; - "-n" | "--name" ) - ARGUMENTS["MATCH_NAMES"]=true - shift - parse_invalid_option "${1}" - ARGUMENTS["NAMES_TO_MATCH"]="${1}" + "-n" | "--name" ) + ARGUMENTS["MATCH_NAMES"]=true + shift + parse_invalid_option "${1}" + ARGUMENTS["NAMES_TO_MATCH"]="${1}" ;; "--reverse-name" ) - ARGUMENTS["REVERSE_MATCH_NAMES"]=true - shift - parse_invalid_option "${1}" - ARGUMENTS["NAMES_TO_REVERSE_MATCH"]="${1}" + ARGUMENTS["REVERSE_MATCH_NAMES"]=true + shift + parse_invalid_option "${1}" + ARGUMENTS["NAMES_TO_REVERSE_MATCH"]="${1}" ;; "" ) @@ -147,28 +339,22 @@ function parse_invalid_option return 0 fi - if ! "${ARGUMENTS["GET_MINIMUM_OUTPUT"]}"; then - echo -e "Error: Invalid option specified." - fi - + is_quiet_enabled && exit 1 + echo -e "Error: Invalid option specified." exit 1 } function print_invalid_argument { - if "${ARGUMENTS["GET_MINIMUM_OUTPUT"]}"; then - exit 1 - fi - + echo -e "Error: Invalid option specified." echo -e "Error: Invalid argument(s) specified." - print_usage exit 1 } function print_usage { - if "${ARGUMENTS["GET_MINIMUM_OUTPUT"]}"; then + if is_quiet_enabled; then return 0 fi @@ -209,7 +395,96 @@ function print_usage "groups with VGA device(s) before and after the second found group." } -function show_groups +function set_device_properties +{ + (( index++ )) + name="$( lspci -s ${device##*/} )" + name="${name:8}" + + bus_id="$( \ + lspci -ns ${device##*/} \ + | awk 'END {print $1}' + )" + + hardware_id="$( \ + lspci -ns ${device##*/} \ + | awk 'END {print $3}' + )" + + driver="$( \ + lspci -kns ${device##*/} \ + | grep "driver" \ + | awk 'END {print $5}' + )" +} + +function set_group_properties +{ + internal_bus_id="00" + this_bus_id="${bus_id::2}" + + if [[ "${this_bus_id}" == "${internal_bus_id}" ]]; then + has_internal=true + else + has_external=true + fi +} + +function set_name_match_property +{ + if "${has_name}" \ + || ! "${ARGUMENTS["MATCH_NAMES"]}"; then + return 0 + fi + + for this_name in $( \ + echo "${ARGUMENTS["NAMES_TO_MATCH"]}" \ + | sed "s/,/ /g" + ); do + if $( \ + echo "${name,,}" \ + | grep --invert-match --quiet "${this_name,,}" + ); then + continue + fi + + has_name=true + done +} + +function set_reverse_name_match_property +{ + if "${has_reverse_name}" \ + || ! "${ARGUMENTS["REVERSE_MATCH_NAMES"]}"; then + return 0 + fi + + for this_name in $( \ + echo "${ARGUMENTS["NAMES_TO_REVERSE_MATCH"]}" \ + | sed "s/,/ /g" + ); do + if $( \ + echo "${name,,}" \ + | grep --quiet "${this_name,,}" + ); then + continue + fi + + has_reverse_name=true + done +} + +function set_vga_type_match_property +{ + if $( \ + echo "${name,,}" \ + | grep --quiet "vga" + ); then + has_vga=true + fi +} + +function print_groups { vga_group_index=0 declare -a group_output=() @@ -232,82 +507,19 @@ function show_groups group_id_list="" driver_list="" hardware_id_list="" + has_external=false + has_internal=false has_name=false has_reverse_name=false has_vga=false vga_group_id_list="" for device in ${group##}/devices/*; do - (( index++ )) - name="$( lspci -s ${device##*/} )" - name="${name:8}" - - bus_id="$( \ - lspci -ns ${device##*/} \ - | awk 'END {print $1}' - )" - - hardware_id="$( \ - lspci -ns ${device##*/} \ - | awk 'END {print $3}' - )" - - driver="$( \ - lspci -kns ${device##*/} \ - | grep "driver" \ - | awk 'END {print $5}' - )" - - if ! "${ARGUMENTS["MATCH_EXTERNALS"]}" \ - && [[ "${bus_id::2}" != "00" ]]; then - continue - fi - - if ! "${ARGUMENTS["MATCH_INTERNALS"]}" \ - && [[ "${bus_id::2}" == "00" ]]; then - continue - fi - - if ! "${has_reverse_name}" \ - && "${ARGUMENTS["REVERSE_MATCH_NAMES"]}"; then - for this_name in $( \ - echo "${ARGUMENTS["NAMES_TO_REVERSE_MATCH"]}" \ - | sed "s/,/ /g" - ); do - if $( \ - echo "${name,,}" \ - | grep --quiet "${this_name,,}" - ); then - continue - fi - - has_reverse_name=true - done - fi - - if ! "${has_name}" \ - && "${ARGUMENTS["MATCH_NAMES"]}"; then - for this_name in $( \ - echo "${ARGUMENTS["NAMES_TO_MATCH"]}" \ - | sed "s/,/ /g" - ); do - if $( \ - echo "${name,,}" \ - | grep --invert-match --quiet "${this_name,,}" - ); then - continue - fi - - has_name=true - done - fi - - if $( \ - echo "${name,,}" \ - | grep --quiet "vga" - ); then - has_vga=true - fi + set_device_properties + set_group_properties + set_name_match_property + set_reverse_name_match_property + set_vga_type_match_property if "${ARGUMENTS["REVERSE_MATCH_NAMES"]}" \ && ! "${has_reverse_name}"; then @@ -319,173 +531,48 @@ function show_groups continue fi - if ! "${ARGUMENTS["GET_MINIMUM_OUTPUT"]}"; then - group_output+=( - "\t${index}.\tBus ID:\t\t${bus_id}" - "\t\tName:\t\t${name}" - "\t\tHardware ID:\t${hardware_id}" - "\t\tDriver:\t\t" - ) - - if [[ ! -z "${driver}" ]]; then - group_output[-1]+="${driver}" - else - group_output[-1]+="N/A" - fi - - group_output+=( "" ) - fi - - if [[ ",${group_id_list,,}," != *",${group_id},"* ]]; then - group_id_list+="${group_id}," - fi - - if [[ ",${driver_list,,}," != *",${driver},"* ]]; then - driver_list+="${driver}," - fi - - if [[ ",${hardware_id_list,,}," != *",${hardware_id},"* ]]; then - hardware_id_list+="${hardware_id}," - fi + append_output_to_temp_lists done - if ! "${ARGUMENTS["GET_MINIMUM_OUTPUT"]}" \ - && [[ "${#group_output[@]}" -gt 0 ]]; then - group_output=( - "IOMMU Group ${group_id}:" - "${group_output[@]}" - "" - ) - fi - - if "${has_vga}"; then - vga_group_id_list+="${group_id}," - (( vga_group_index++ )) - fi - - if "${ARGUMENTS["MATCH_VGA_GROUP_INDEX"]}" \ - && "${has_vga}" \ - && [[ ",${ARGUMENTS["VGA_GROUP_INDEX_TO_MATCH"],,}," \ - != *",${vga_group_index},"* ]]; then - group_id_list="" - vga_group_id_list="" - driver_list="" - hardware_id_list="" - fi - - OUTPUTS["FOUND_GROUP_IDS"]+="${group_id_list}" - OUTPUTS["FOUND_VGA_GROUP_IDS"]+="${vga_group_id_list}" - OUTPUTS["FOUND_DRIVERS"]+="${driver_list}" - OUTPUTS["FOUND_HW_IDS"]+="${hardware_id_list}" - done - - if [[ ! -z "${ARGUMENTS["VGA_GROUP_INDEX_TO_MATCH"]}" ]]; then - ARGUMENTS["VGA_GROUP_INDEX_TO_MATCH"]="$( \ - echo "${ARGUMENTS["VGA_GROUP_INDEX_TO_MATCH"]}" \ - | sed --expression $'s/,/\\\n/g' \ - | sort --numeric-sort \ - | tr '\n' ',' \ - | sed 's/.$//' \ - | tr ',' '\n' \ - | sort --unique \ - | xargs \ - | tr ' ' ',' - )" - - for this_vga_group_index in $( \ - echo "${ARGUMENTS["VGA_GROUP_INDEX_TO_MATCH"]}" \ - | sed "s/,/ /g" - ); do - if [[ "${this_vga_group_index}" -le "${vga_group_index}" ]]; then - continue - fi - - if "${ARGUMENTS["GET_MINIMUM_OUTPUT"]}"; then - exit 1 - fi - - echo -e "Error: Invalid index specified." - echo "Please enter a value between '${MIN_VGA_INDEX_VALUE}' and" \ - "'${vga_group_index}'." - - exit 1 - done - fi - - for line in "${group_output[@]}"; do - echo -e "${line}" + append_output_to_lists done - if [[ ! -z "${OUTPUTS["FOUND_GROUP_IDS"]}" ]]; then - OUTPUTS["FOUND_GROUP_IDS"]="${OUTPUTS["FOUND_GROUP_IDS"]::-1}" - else - OUTPUTS["FOUND_GROUP_IDS"]="N/A" - fi - - if [[ ! -z "${OUTPUTS["FOUND_VGA_GROUP_IDS"]}" ]]; then - OUTPUTS["FOUND_VGA_GROUP_IDS"]="${OUTPUTS["FOUND_VGA_GROUP_IDS"]::-1}" - else - OUTPUTS["FOUND_VGA_GROUP_IDS"]="N/A" - fi - - if [[ ! -z "${OUTPUTS["FOUND_DRIVERS"]}" ]]; then - OUTPUTS["FOUND_DRIVERS"]="${OUTPUTS["FOUND_DRIVERS"]::-1}" - - OUTPUTS["FOUND_DRIVERS"]="$( \ - echo "${OUTPUTS["FOUND_DRIVERS"]}" \ - | sed --expression $'s/,/\\\n/g' \ - | sort --numeric-sort \ - | tr '\n' ',' \ - | sed 's/.$//' \ - | tr ',' '\n' \ - | sort --unique \ - | xargs \ - | tr ' ' ',' - )" - else - OUTPUTS["FOUND_DRIVERS"]="N/A" - fi - - if [[ ! -z "${OUTPUTS["FOUND_HW_IDS"]}" ]]; then - OUTPUTS["FOUND_HW_IDS"]="${OUTPUTS["FOUND_HW_IDS"]::-1}" - - OUTPUTS["FOUND_HW_IDS"]="$( \ - echo "${OUTPUTS["FOUND_HW_IDS"]}" \ - | sed --expression $'s/,/\\\n/g' \ - | sort --numeric-sort \ - | tr '\n' ',' \ - | sed 's/.$//' \ - | tr ',' '\n' \ - | sort --unique \ - | xargs \ - | tr ' ' ',' - )" - else - OUTPUTS["FOUND_HW_IDS"]="N/A" - fi + verify_vga_group_index "${vga_group_index}" + convert_driver_list_to_delimited_string + convert_group_id_list_to_delimited_string + convert_hardware_id_list_to_delimited_string + convert_vga_group_id_list_to_delimited_string } -function output_info +function verify_vga_group_index { - if ! "${ARGUMENTS["GET_MINIMUM_OUTPUT"]}"; then - echo -e "Groups:\n${OUTPUTS["FOUND_GROUP_IDS"]}" - echo - echo -e "Groups with VGA device(s):\n${OUTPUTS["FOUND_VGA_GROUP_IDS"]}" - echo - echo -e "Drivers:\n${OUTPUTS["FOUND_DRIVERS"]}" - echo - echo -e "Hardware IDs:\n${OUTPUTS["FOUND_HW_IDS"]}" + vga_group_index="${1}" + + if [[ -z "${ARGUMENTS["VGA_GROUP_INDEX_TO_MATCH"]}" ]]; then return 0 fi - echo "${OUTPUTS["FOUND_DRIVERS"]}" - echo "${OUTPUTS["FOUND_HW_IDS"]}" + for this_vga_group_index in $( \ + echo "${ARGUMENTS["VGA_GROUP_INDEX_TO_MATCH"]}" \ + | sed "s/,/ /g" + ); do + if [[ "${this_vga_group_index}" -le "${vga_group_index}" ]]; then + continue + fi + + is_quiet_enabled && exit 1 + echo -e "Error: Invalid index specified." + echo "Please enter a value between '${MIN_VGA_INDEX_VALUE}' and" \ + "'${vga_group_index}'." + + exit 1 + done } function main { parse_arguments "${@}" - show_groups + print_groups output_info } From 3f6eefd9491dddfb2b84b18300d8c99660bf496f Mon Sep 17 00:00:00 2001 From: portellam Date: Wed, 14 Aug 2024 12:20:58 -0400 Subject: [PATCH 2/5] Update parse-iommu-devices --- bin/parse-iommu-devices | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/bin/parse-iommu-devices b/bin/parse-iommu-devices index 4b76c5b..eedff6f 100755 --- a/bin/parse-iommu-devices +++ b/bin/parse-iommu-devices @@ -39,19 +39,6 @@ declare -A OUTPUTS=( function append_output_to_lists { - # - # Delete output given conditions (1/2) - # - if "${ARGUMENTS["MATCH_EXTERNALS"]}" \ - && ! "${has_external}"; then - group_output=( ) - fi - - if "${ARGUMENTS["MATCH_INTERNALS"]}" \ - && ! "${has_internal}"; then - group_output=( ) - fi - # # Append output given conditions # @@ -65,7 +52,7 @@ function append_output_to_lists fi # - # Delete output given conditions (2/2) + # Delete output given conditions # if "${has_vga}"; then vga_group_id_list+="${group_id}," @@ -521,8 +508,15 @@ function print_groups set_reverse_name_match_property set_vga_type_match_property - if "${ARGUMENTS["REVERSE_MATCH_NAMES"]}" \ - && ! "${has_reverse_name}"; then + if "${ARGUMENTS["MATCH_EXTERNALS"]}" \ + && ! "${has_external}" \ + && ! "${ARGUMENTS["MATCH_INTERNALS"]}"; then + continue + fi + + if "${ARGUMENTS["MATCH_INTERNALS"]}" \ + && ! "${has_internal}" \ + && ! "${ARGUMENTS["MATCH_EXTERNALS"]}"; then continue fi @@ -531,6 +525,11 @@ function print_groups continue fi + if "${ARGUMENTS["REVERSE_MATCH_NAMES"]}" \ + && ! "${has_reverse_name}"; then + continue + fi + append_output_to_temp_lists done From 6ecaee2a0b613359e7b44437e8d7d7676c50edf0 Mon Sep 17 00:00:00 2001 From: portellam Date: Wed, 14 Aug 2024 12:28:23 -0400 Subject: [PATCH 3/5] Update parse-iommu-devices --- bin/parse-iommu-devices | 154 ++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/bin/parse-iommu-devices b/bin/parse-iommu-devices index eedff6f..1eb5a2b 100755 --- a/bin/parse-iommu-devices +++ b/bin/parse-iommu-devices @@ -7,12 +7,12 @@ # output. # Author(s): Alex Portell # Maintainer(s): Alex Portell -# Version: 1.0.0 +# Version: 1.0.1 # shopt -s nullglob -declare -r SCRIPT_VERSION="1.0.0" +declare -r SCRIPT_VERSION="1.0.1" declare -r SCRIPT_NAME="$( basename "${0}" )" declare -i MIN_VGA_INDEX_VALUE=1 @@ -145,7 +145,7 @@ function convert_group_id_list_to_delimited_string | tr '\n' ',' \ | sed 's/.$//' \ | tr ',' '\n' \ - | sort --unique \ + | sort --human-numeric-sort --unique \ | xargs \ | tr ' ' ',' )" @@ -339,6 +339,78 @@ function print_invalid_argument exit 1 } +function print_groups +{ + vga_group_index=0 + declare -a group_output=() + + for group in $( \ + find /sys/kernel/iommu_groups/* -maxdepth 0 -type d \ + | sort --version-sort + ); do + group_id="${group##*/}" + + if "${ARGUMENTS["MATCH_GROUPS"]}" \ + && ! $( \ + echo ",${ARGUMENTS["GROUPS_TO_MATCH"]}," \ + | grep --quiet ",${group_id}," + ); then + continue + fi + + index=0 + group_id_list="" + driver_list="" + hardware_id_list="" + has_external=false + has_internal=false + has_name=false + has_reverse_name=false + has_vga=false + vga_group_id_list="" + + for device in ${group##}/devices/*; do + set_device_properties + set_group_properties + set_name_match_property + set_reverse_name_match_property + set_vga_type_match_property + + if "${ARGUMENTS["MATCH_EXTERNALS"]}" \ + && ! "${has_external}" \ + && ! "${ARGUMENTS["MATCH_INTERNALS"]}"; then + continue + fi + + if "${ARGUMENTS["MATCH_INTERNALS"]}" \ + && ! "${has_internal}" \ + && ! "${ARGUMENTS["MATCH_EXTERNALS"]}"; then + continue + fi + + if "${ARGUMENTS["MATCH_NAMES"]}" \ + && ! "${has_name}"; then + continue + fi + + if "${ARGUMENTS["REVERSE_MATCH_NAMES"]}" \ + && ! "${has_reverse_name}"; then + continue + fi + + append_output_to_temp_lists + done + + append_output_to_lists + done + + verify_vga_group_index "${vga_group_index}" + convert_driver_list_to_delimited_string + convert_group_id_list_to_delimited_string + convert_hardware_id_list_to_delimited_string + convert_vga_group_id_list_to_delimited_string +} + function print_usage { if is_quiet_enabled; then @@ -378,8 +450,8 @@ function print_usage echo -e "Examples:" echo -e " ${SCRIPT_NAME} -eq -v 2 Quiet output except for drivers and" \ - "hardware IDs, of IOMMU groups with external devices, and exclude IOMMU" \ - "groups with VGA device(s) before and after the second found group." + "hardware IDs (of IOMMU groups with external devices) and exclude IOMMU" \ + "groups with VGA device(s) before and after the second matched group." } function set_device_properties @@ -471,78 +543,6 @@ function set_vga_type_match_property fi } -function print_groups -{ - vga_group_index=0 - declare -a group_output=() - - for group in $( \ - find /sys/kernel/iommu_groups/* -maxdepth 0 -type d \ - | sort --version-sort - ); do - group_id="${group##*/}" - - if "${ARGUMENTS["MATCH_GROUPS"]}" \ - && ! $( \ - echo ",${ARGUMENTS["GROUPS_TO_MATCH"]}," \ - | grep --quiet ",${group_id}," - ); then - continue - fi - - index=0 - group_id_list="" - driver_list="" - hardware_id_list="" - has_external=false - has_internal=false - has_name=false - has_reverse_name=false - has_vga=false - vga_group_id_list="" - - for device in ${group##}/devices/*; do - set_device_properties - set_group_properties - set_name_match_property - set_reverse_name_match_property - set_vga_type_match_property - - if "${ARGUMENTS["MATCH_EXTERNALS"]}" \ - && ! "${has_external}" \ - && ! "${ARGUMENTS["MATCH_INTERNALS"]}"; then - continue - fi - - if "${ARGUMENTS["MATCH_INTERNALS"]}" \ - && ! "${has_internal}" \ - && ! "${ARGUMENTS["MATCH_EXTERNALS"]}"; then - continue - fi - - if "${ARGUMENTS["MATCH_NAMES"]}" \ - && ! "${has_name}"; then - continue - fi - - if "${ARGUMENTS["REVERSE_MATCH_NAMES"]}" \ - && ! "${has_reverse_name}"; then - continue - fi - - append_output_to_temp_lists - done - - append_output_to_lists - done - - verify_vga_group_index "${vga_group_index}" - convert_driver_list_to_delimited_string - convert_group_id_list_to_delimited_string - convert_hardware_id_list_to_delimited_string - convert_vga_group_id_list_to_delimited_string -} - function verify_vga_group_index { vga_group_index="${1}" From 71be6ea5a9a222e6789799433818fb35da9b254b Mon Sep 17 00:00:00 2001 From: portellam Date: Wed, 14 Aug 2024 12:28:26 -0400 Subject: [PATCH 4/5] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c75d52d..dfcc0f3 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Parse IOMMU Devices -### v1.0.0 +### v1.0.1 Bash script to parse, sort, and display hardware devices by IOMMU group, and return the device drivers and hardware IDs as output. -**[Latest release](https://github.com/portellam/parse-iommu-devices/releases/latest)** +### [Download](#5-download) ## Table of Contents - [1. Why?](#1-why) @@ -113,10 +113,10 @@ sudo bash installer.sh (not an IOMMU group ID). Comma delimited. Examples: - parse-iommu-devices -eq -v 2 Quiet output except for drivers and hardware IDs, - of IOMMU groups with external devices, and exclude - IOMMU groups with VGA device(s) before and after - the second found group. + parse-iommu-devices -eq -v 2 Quiet output except for drivers and hardware IDs + (of IOMMU groups with external devices) and + exclude IOMMU groups with VGA device(s) before and + after the second matched group. ``` ### 7. Contact From e7669f9fcae38f535e94267e194ba9238ca3dfd1 Mon Sep 17 00:00:00 2001 From: portellam Date: Wed, 14 Aug 2024 12:37:50 -0400 Subject: [PATCH 5/5] Update README.md --- README.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dfcc0f3..543cd6b 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,20 @@ and return the device drivers and hardware IDs as output. ## Contents ### 1. Why? -If you wish to determine if your current machine's hardware specifications are able to support VFIO, this script is for you. The script allows one to query exactly what hardware you wish to allocate for a VFIO setup, and returns the relevant output to deploy a VFIO setup. +If you wish to determine if your current machine's hardware specifications are +able to support VFIO, then this script is for you. The script allows one to +query exactly what hardware you wish to allocate for a VFIO setup, and returns +the relevant output to deploy a VFIO setup. + +#### Disclaimer +This script must be run on a system without VFIO setup already. If not, the +script output will not show a complete list of **valid** device drivers. +This is due to the fact that a VFIO setup involves replacing the device drivers +(example: NVIDIA GPUs use `nouveau` or `nvidia`) with the VFIO driver +(`vfio-pci`). + +Other outputs such as lists for IOMMU group IDs and hardware IDs are **not** +affected by this. ### 2. Related Projects | Project | Codeberg | GitHub | @@ -142,4 +155,13 @@ The linux kernel. Accessed June 14, 2024. #### 4. **XML Design Format** GitHub - libvirt/libvirt. Accessed June 18, 2024. -https://github.com/libvirt/libvirt/blob/master/docs/formatdomain.rst. \ No newline at end of file +https://github.com/libvirt/libvirt/blob/master/docs/formatdomain.rst. + +### TO DO +- [ ] reference and query database for original device drivers. + - Query manifest of hardware IDs and drivers. If any devices or groups are + ever binded to the VFIO driver, the feature should be able to grab the + original drivers (should the system's hardware configuration not change). +- [ ] use XML file? **This will work** +- [ ] use Internet database? Not sure if this is possible, but `lspci` mentions + something to this effect. \ No newline at end of file