Fix --force command for named and DID specified commands
PATCH 1/1 Fix --force command for named and DID specified commands
Signed-off-by Tom St Denis <[email protected]>
--- src/app/main.c | 2 +- src/lib/discover.c | 2 +- src/lib/discover_by_did.c | 37 ++++++++++++++++++++++++++++++++++++- src/lib/discover_by_name.c | 8 ++++---- 4 files changed, 42 insertions(+), 7 deletions(-)
src/app/main.c +1 -1
@@ -169,8 +169,8 @@ int main(int argc, char **argv)if (sscanf (argv[i+1 ],"0x%lx" , &options.forcedid) ==0 ) {strncpy (options.dev_name, argv[i+1 ],sizeof (options.dev_name) -1 ); options.forcedid =0 ; - options.instance =-1 ; } + options.instance =-1 ; ++i; }else {printf ("--force requires a number/name\n" );
src/lib/discover.c +1 -1
@@ -138,7 +138,7 @@ struct umr_asic *umr_discover_asic(struct umr_options *options) }// try to scan via debugfs -if (!options->no_kernel) { +if (options->instance >=0 && !options->no_kernel) { asic =calloc (1 ,sizeof *asic);if (asic) { asic->instance = options->instance;
src/lib/discover_by_did.c +36 -1
@@ -230,6 +230,41 @@ static const struct { { 0x687f, &umr_create_vega10 }, }; +static int find_first_did (long did) +{ +char name[128 ], device[128 ]; +FILE *f, *f2; + +int x; + +for (x =0 ; x <16 ; x++) { +snprintf (name,sizeof (name)-1 ,"/sys/kernel/debug/dri/%d/name" , x); + f =fopen (name,"r" ); +if (f) { +unsigned tmp_did; +fscanf (f,"%*s %s" , name); +fclose (f); + +// strip off dev= for kernels > 4.7 +if (strstr (name,"dev=" )) +memmove (name, name+4 ,strlen (name)-3 ); + +snprintf (device,sizeof (device)-1 ,"/sys/bus/pci/devices/%s/device" , name); + f2 =fopen (device,"r" ); +if (f2) { +fscanf (f,"0x%04x" , &tmp_did); +if (tmp_did == did) { +fclose (f2); +return x; + } + } +fclose (f2); + } + } +return -1 ; +} + +struct umr_asic *umr_discover_asic_by_did (struct umr_options *options,long did) {unsigned x;
@@ -242,7 +277,7 @@ struct umr_asic *umr_discover_asic_by_did(struct umr_options *options, long did)if (asic) { asic->did = did; - asic->instance = options->instance; + asic->instance =find_first_did (did);umr_scan_config (asic);// set all file handles to -1 (so a call to close_asic won't close handle 0)
src/lib/discover_by_name.c +4 -4
@@ -68,10 +68,10 @@ struct umr_asic *umr_discover_asic_by_name(struct umr_options *options, char *naif (options->instance ==-1 ) {// try and discover an instance that works struct umr_options tmp_opt; -memset (&tmp_opt,0 ,sizeof (tmp_opt)); - tmp_opt.forcedid =-1 ; - tmp_opt.quiet =1 ; -for (x =0 ; x <10 ; x++) { +for (x =0 ; x <16 ; x++) { +memset (&tmp_opt,0 ,sizeof (tmp_opt)); + tmp_opt.quiet =1 ; + tmp_opt.forcedid =-1 ; tmp_opt.instance = x; tmp =umr_discover_asic (&tmp_opt);if (tmp) {
Signature · 6 lines
2.14.3 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx