Skip to contentSkip to conversation

Tidy up formatting in new discovery code.

PATCH New Tom St Denis 1 participant 2 messages Jul 4, 2017 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Tidy up formatting in new discovery code.

---
 src/lib/discover.c | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)
src/lib/discover.c +23 -13
index a95fe57c9b4d..2faed79334ee 100644
@@ -47,36 +47,44 @@ static int is_did_match(struct umr_asic *asic, unsigned did)
 	return r;
 }
 
-static int find_pci_instance(const char* pci_string) {
-	DIR* dir;
+static int find_pci_instance(const char* pci_string)
+{
+	DIR *dir;
+	struct dirent *dir_entry;
+
 	dir = opendir("/sys/kernel/debug/dri");
 	if (dir == NULL) {
 		perror("Couldn't open DRI under debugfs");
 		return -1;
 	}
-	struct dirent *dir_entry;
+
 	while ((dir_entry = readdir(dir)) != NULL) {
 		char device[256], name[256];
 		int parsed_device;
+		FILE *f;
+
 		// ignore . and ..
-		if (strcmp(dir_entry->d_name, ".") == 0 || strcmp(dir_entry->d_name,
-			"..") == 0) {
+		if (strcmp(dir_entry->d_name, ".") == 0 ||
+		    strcmp(dir_entry->d_name, "..") == 0)
 			continue;
-		}
+
 		snprintf(name, sizeof(name), "/sys/kernel/debug/dri/%s/name",
 			dir_entry->d_name);
-		FILE *f = fopen(name, "r");
-		if (!f) {
+
+		f = fopen(name, "r");
+		if (!f)
 			continue;
-		}
+
 		device[sizeof(device) - 1] = 0;
 		parsed_device = fscanf(f, "%*s %255s", device);
 		fclose(f);
+
 		if (parsed_device != 1)
 			continue;
+
 		// strip off dev= for kernels > 4.7
 		if (strstr(device, "dev="))
-			memmove(device, device+4, strlen(device)-3);
+			memmove(device, device + 4, strlen(device) - 3);
 		if (strcmp(pci_string, device) == 0) {
 			closedir(dir);
 			return atoi(dir_entry->d_name);
@@ -96,15 +104,17 @@ struct umr_asic *umr_discover_asic(struct umr_options *options)
 
 	// Try to map to instance if we have a specific pci device
 	if (options->pci.domain || options->pci.bus ||
-		options->pci.slot || options->pci.func) {
+	    options->pci.slot || options->pci.func) {
 		char pci_string[16];
 		int parsed_did;
+
 		snprintf(pci_string, sizeof(pci_string), "%04x:%02x:%02x.%x",
 			options->pci.domain, options->pci.bus, options->pci.slot,
 			options->pci.func);
-		if (!options->no_kernel) {
+
+		if (!options->no_kernel)
 			options->instance = find_pci_instance(pci_string);
-		}
+
 		snprintf(driver, sizeof(driver), "/sys/bus/pci/devices/%s/device", pci_string);
 		f = fopen(driver, "r");
 		if (!f) {
Signature · 6 lines
2.12.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH 2/2 Avoid using debugfs config data in no_kernel mode

---
 src/app/print_config.c |  2 +-
 src/lib/discover.c     | 21 ++++++++++++---------
 src/lib/scan_config.c  |  9 +++++++--
 src/umr.h              |  2 +-
 4 files changed, 21 insertions(+), 13 deletions(-)
src/app/print_config.c +1 -1
index 3ad95c0cd12f..051666d52e02 100644
@@ -100,6 +100,7 @@ void umr_print_config(struct umr_asic *asic)
 {
 	int r, x;
 
+	printf("\tasic.instance == %d\n\n", asic->instance);
 	printf("\tumr.version == %s\n\n", UMR_BUILD_REV);
 
 	for (r = 0; asic->config.fw[r].name[0]; r++) {
@@ -110,7 +111,6 @@ void umr_print_config(struct umr_asic *asic)
 	}
 	printf("\n");
 
-	printf("\tasic.instance == %d\n\n", asic->instance);
 	if (asic->pci.pdevice) {
 		ppx(vendor_id);
 		ppx(device_id);
src/lib/discover.c +12 -9
index 2faed79334ee..3e0c1f93fccd 100644
@@ -128,17 +128,20 @@ struct umr_asic *umr_discover_asic(struct umr_options *options)
 			return NULL;
 		}
 	}
+
 	// try to scan via debugfs
-	asic = calloc(1, sizeof *asic);
-	if (asic) {
-		asic->instance = options->instance;
-		asic->options  = *options;
-		umr_scan_config(asic);
-		if (asic->config.pci.device)
-			trydid = asic->config.pci.device;
-		umr_free_asic(asic);
-		asic = NULL;
+	if (!options->no_kernel) {
+		asic = calloc(1, sizeof *asic);
+		if (asic) {
+			asic->instance = options->instance;
+			asic->options  = *options;
+			if (!umr_scan_config(asic) && asic->config.pci.device)
+				trydid = asic->config.pci.device;
+			umr_free_asic(asic);
+			asic = NULL;
+		}
 	}
+
 	if (trydid < 0) {
 		snprintf(name, sizeof(name)-1, "/sys/kernel/debug/dri/%d/name", options->instance);
 		f = fopen(name, "r");
src/lib/scan_config.c +7 -2
index 2d9f0f419557..5d2975f33e34 100644
@@ -77,13 +77,16 @@ static void parse_rev3(struct umr_asic *asic, uint32_t *data, int *r)
 	asic->config.pci.subsystem_vendor = data[(*r)++];
 }
 
-void umr_scan_config(struct umr_asic *asic)
+int umr_scan_config(struct umr_asic *asic)
 {
 	uint32_t data[512];
 	FILE *f;
 	char fname[256];
 	int r;
 
+	if (asic->options.no_kernel)
+		return -1;
+
 	/* process FW block */
 	snprintf(fname, sizeof(fname)-1, "/sys/kernel/debug/dri/%d/amdgpu_firmware_info", asic->instance);
 	f = fopen(fname, "r");
@@ -104,7 +107,7 @@ gca_config:
 	snprintf(fname, sizeof(fname)-1, "/sys/kernel/debug/dri/%d/amdgpu_gca_config", asic->instance);
 	f = fopen(fname, "rb");
 	if (!f)
-		return;
+		return -1;
 	fread(data, 1, sizeof(data), f);
 	fclose(f);
 
@@ -119,5 +122,7 @@ gca_config:
 			break;
 		default:
 			printf("Invalid gca config data header\n");
+			return -1;
 	}
+	return 0;
 }
src/umr.h +1 -1
index 4d63708e1c15..f3d359172d03 100644
@@ -508,4 +508,4 @@ int umr_read_vram(struct umr_asic *asic, uint32_t vmid, uint64_t address, uint32
 #define RST     (options.use_colour ? "\x1b[0m" : "")
 
 void umr_bitfield_default(struct umr_asic *asic, char *asicname, char *ipname, char *regname, char *bitname, int start, int stop, uint32_t value);
-void umr_scan_config(struct umr_asic *asic);
+int umr_scan_config(struct umr_asic *asic);
Signature · 6 lines
2.12.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx