All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luben Tuikov <luben.tuikov@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: "Alex Deucher" <Alexander.Deucher@amd.com>,
	"Pierre-Eric Pelloux-Prayer" <pierre-eric.pelloux-prayer@amd.com>,
	"Luben Tuikov" <luben.tuikov@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Tom StDenis" <tom.stdenis@amd.com>
Subject: [PATCH 5/6] umr: Replace and reuse ipblock completion
Date: Wed, 23 Mar 2022 07:48:41 -0400	[thread overview]
Message-ID: <20220323114842.78516-6-luben.tuikov@amd.com> (raw)
In-Reply-To: <20220323114842.78516-1-luben.tuikov@amd.com>

Replace and reuse ip block completion.

Cc: Alex Deucher <Alexander.Deucher@amd.com>
Cc: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Cc: Tom StDenis <tom.stdenis@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Signed-off-by: Luben Tuikov <luben.tuikov@amd.com>
---
 scripts/umr-completion.bash | 73 +++++++++++++++++--------------------
 1 file changed, 33 insertions(+), 40 deletions(-)

diff --git a/scripts/umr-completion.bash b/scripts/umr-completion.bash
index ab1637a090e5d6..0e1444357c82a9 100644
--- a/scripts/umr-completion.bash
+++ b/scripts/umr-completion.bash
@@ -16,45 +16,6 @@ if [[ ! -d $UMR_DATABASE_PATH ]]; then
     echo " See the FILES section in umr(1)."
 fi
 
-_umr_setup_ips()
-{
-    select_gpu=""
-    if [ $COMP_CWORD -ge 4 ]; then
-        for i in ${!COMP_WORDS[@]}; do
-            if [[ ${COMP_WORDS[$i]} = "--gpu" ]] ||
-                [[ ${COMP_WORDS[$i]} = "-g" ]] ||
-                [[ ${COMP_WORDS[$i]} = "--instance" ]] ||
-                [[ ${COMP_WORDS[$i]} = "-i" ]]; then
-                select_gpu=${COMP_WORDS[$i]}" "${COMP_WORDS[$i+1]}
-                break
-            fi
-        done
-    fi
-
-    ips=( $( sudo $(which umr) $select_gpu -lb ) )
-    asicname=${ips%%.*}
-    unset ip_names
-    for ip in ${ips[@]}
-    do
-        ipname=${ip#*.}
-        ip_names+=($ipname)
-    done
-}
-
-_umr_comp_blocks()
-{
-    _umr_setup_ips
-
-    if [ -z "$cur" ]; then
-        COMPREPLY=( $(compgen -W "${ips[*]}" -- "$cur") )
-    fi
-
-    if [ -n "$cur" ]; then
-        local array=( "${ips[@]}" "${ip_names[@]}" "${ip_names[@]/#/*.}" )
-        COMPREPLY=( $(compgen -W "${array[*]}" -- "$cur") )
-    fi
-}
-
 _umr_comp_option_flags()
 {
     local FLAGS=(bits bitsfull empty_log follow no_follow_ib use_pci use_colour read_smc quiet no_kernel verbose halt_waves disasm_early_term no_disasm disasm_anyways wave64 full_shader no_fold_vm_decode no_scan_waves)
@@ -289,6 +250,38 @@ _umr_comp_lookup()
     unset GPU_NAME GPU_NAME2 DEFAULT_GPU_NAME IP_BLOCKS
 }
 
+_umr_comp_ipblock()
+{
+    # Handle --list-regs and --scan, using the --scan model
+
+    _umr_setup_gpu_ipblocks
+
+    # If compline specifes a GPU, then complete a block of that GPU;
+    # else complete all GPUs and the current GPU's blocks in one list.
+
+    if [[ $COMP_LINE =~ (--force|-f|--gpu|-g|--instance|-i) ]] ; then
+	COMPREPLY=( $(compgen -W "${IP_BLOCKS[*]}" -- "$cur") )
+    elif [[ $cur =~ .*\..* ]] ; then
+	# The ASIC here is the default one recommended in the "else"
+	# case below.  Because of this, we don't use "--force" with
+	# "--list-block" and so also get the instance numbers of the
+	# blocks. Then we combine that with the ASIC and offer it as
+	# completion. See _umr_comp_asic_ipblock_registers() below.
+	local asic=${cur%%.*}
+	local blocks=( `sudo umr --list-blocks | sed -E -e "s/^[[:space:]]*.*\.(.*) \(.*$/\1/g"` )
+	local F=( $(compgen -P "${asic}." -W "${blocks[*]}") )
+	COMPREPLY=( $(compgen -W "${F[*]}" -- "$cur") )
+    else
+	COMPREPLY=( $(compgen -W "${DEFAULT_GPU_NAME}. ${IP_BLOCKS[*]}" -- "$cur") )
+	# This uses the zero element
+	if [[ $COMPREPLY =~ .*\. ]] ; then
+	    compopt -o nospace
+	fi
+    fi
+
+    unset GPU_NAME GPU_NAME2 DEFAULT_GPU_NAME IP_BLOCKS
+}
+
 _umr_comp_asic_ipblock_registers()
 {
     # The format is --writebit asic.ipblock.regname,
@@ -373,7 +366,7 @@ _umr_completion()
 	    COMPREPLY=( $(compgen -W "0 1" -- "$cur") )
 	    ;;
         -lr|--list-regs|-s|--scan)
-            _umr_comp_blocks
+            _umr_comp_ipblock
             ;;
 	--lookup|-lu)
 	    _umr_comp_lookup
-- 
2.35.1.607.gf01e51a7cf


  parent reply	other threads:[~2022-03-23 11:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23 11:48 [PATCH 0/6] Complete and add dynamic completion to umr Luben Tuikov
2022-03-23 11:48 ` [PATCH 1/6] umr: Rename "scripts/umr" --> "scripts/umr-completion.bash" Luben Tuikov
2022-03-23 11:48 ` [PATCH 2/6] umr: Rename completion function Luben Tuikov
2022-03-23 11:48 ` [PATCH 3/6] umr: Complete umr completion Luben Tuikov
2022-03-23 11:48 ` [PATCH 4/6] umr: Replace and reuse asic.ipblock.reg completion Luben Tuikov
2022-03-23 11:48 ` Luben Tuikov [this message]
2022-03-23 11:48 ` [PATCH 6/6] umr: Add FILES section to the man page Luben Tuikov
2022-03-23 12:01 ` [PATCH 0/6] Complete and add dynamic completion to umr StDenis, Tom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220323114842.78516-6-luben.tuikov@amd.com \
    --to=luben.tuikov@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=pierre-eric.pelloux-prayer@amd.com \
    --cc=tom.stdenis@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.