@@ -32,13 +32,13 @@ pushd drm
32
32
# ##########################
33
33
patch -p1 << 'EOF '
34
34
diff --git a/amdgpu/amdgpu_asic_id.c b/amdgpu/amdgpu_asic_id.c
35
- index a5007ffc..a3627529 100644
35
+ index a5007ffc..13fa07fc 100644
36
36
--- a/amdgpu/amdgpu_asic_id.c
37
37
+++ b/amdgpu/amdgpu_asic_id.c
38
38
@@ -22,6 +22,13 @@
39
39
*
40
40
*/
41
-
41
+
42
42
+#define _XOPEN_SOURCE 700
43
43
+#define _LARGEFILE64_SOURCE
44
44
+#define _FILE_OFFSET_BITS 64
@@ -49,20 +49,18 @@ index a5007ffc..a3627529 100644
49
49
#include <ctype.h>
50
50
#include <stdio.h>
51
51
#include <stdlib.h>
52
- @@ -34,6 +41,21 @@
52
+ @@ -34,6 +41,19 @@
53
53
#include "amdgpu_drm.h"
54
54
#include "amdgpu_internal.h"
55
-
55
+
56
56
+static char *amdgpuids_path = NULL;
57
+ +static const char* amdgpuids_path_msg = NULL;
57
58
+
58
59
+static int check_for_location_of_amdgpuids(const char *filepath, const struct stat *info, const int typeflag, struct FTW *pathinfo)
59
60
+{
60
61
+ if (typeflag == FTW_F && strstr(filepath, "amdgpu.ids")) {
61
- + if (NULL != amdgpuids_path) {
62
- + free(amdgpuids_path);
63
- + }
64
62
+ amdgpuids_path = strdup(filepath);
65
- + return 0 ;
63
+ + return 1 ;
66
64
+ }
67
65
+
68
66
+ return 0;
@@ -71,16 +69,20 @@ index a5007ffc..a3627529 100644
71
69
static int parse_one_line(struct amdgpu_device *dev, const char *line)
72
70
{
73
71
char *buf, *saveptr;
74
- @@ -113,13 +135,48 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
72
+ @@ -113,10 +133,46 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
75
73
int line_num = 1;
76
74
int r = 0;
77
-
78
- - fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
75
+
76
+ + // attempt to find typical location for amdgpu.ids file
77
+ fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
78
+ +
79
+ + // if it doesn't exist, search
80
+ + if (!fp) {
81
+ +
79
82
+ char self_path[ PATH_MAX ];
80
83
+ ssize_t count;
81
84
+ ssize_t i;
82
85
+
83
- + fp = NULL;
84
86
+ count = readlink( "/proc/self/exe", self_path, PATH_MAX );
85
87
+ if (count > 0) {
86
88
+ self_path[count] = '\0';
@@ -97,30 +99,43 @@ index a5007ffc..a3627529 100644
97
99
+ }
98
100
+ self_path[i] = '\0';
99
101
+
100
- + if (0 == nftw(self_path, check_for_location_of_amdgpuids, 5, FTW_PHYS)) {
101
- + if (amdgpuids_path) {
102
- + fp = fopen(amdgpuids_path, "r");
103
- + if (!fp) {
104
- + fprintf(stderr, "%s: %s\n", amdgpuids_path, strerror(errno));
105
- + }
106
- + }
102
+ + if (1 == nftw(self_path, check_for_location_of_amdgpuids, 5, FTW_PHYS)) {
103
+ + fp = fopen(amdgpuids_path, "r");
104
+ + amdgpuids_path_msg = amdgpuids_path;
107
105
+ }
108
106
+ }
109
107
+
110
- + if (!fp) {
108
+ + }
109
+ + else {
110
+ + amdgpuids_path_msg = AMDGPU_ASIC_ID_TABLE;
111
+ + }
111
112
+
112
- + fp = fopen(AMDGPU_ASIC_ID_TABLE, "r");
113
+ + // both hard-coded location and search have failed
113
114
if (!fp) {
114
- fprintf(stderr, "%s: %s\n", AMDGPU_ASIC_ID_TABLE,
115
- strerror(errno));
115
+ - fprintf(stderr, "%s: %s\n", AMDGPU_ASIC_ID_TABLE,
116
+ - strerror(errno));
117
+ + fprintf(stderr, "amdgpu.ids: No such file or directory\n");
116
118
return;
117
119
}
118
-
119
- + }
120
- +
121
- /* 1st valid line is file version */
122
- while ((n = getline(&line, &len, fp)) != -1) {
123
- /* trim trailing newline */
120
+
121
+ @@ -132,7 +188,7 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
122
+ continue;
123
+ }
124
+
125
+ - drmMsg("%s version: %s\n", AMDGPU_ASIC_ID_TABLE, line);
126
+ + drmMsg("%s version: %s\n", amdgpuids_path_msg, line);
127
+ break;
128
+ }
129
+
130
+ @@ -150,7 +206,7 @@ void amdgpu_parse_asic_ids(struct amdgpu_device *dev)
131
+
132
+ if (r == -EINVAL) {
133
+ fprintf(stderr, "Invalid format: %s: line %d: %s\n",
134
+ - AMDGPU_ASIC_ID_TABLE, line_num, line);
135
+ + amdgpuids_path_msg, line_num, line);
136
+ } else if (r && r != -EAGAIN) {
137
+ fprintf(stderr, "%s: Cannot parse ASIC IDs: %s\n",
138
+ __func__, strerror(-r));
124
139
EOF
125
140
126
141
# ##########################
0 commit comments