Skip to content

Commit 8dd4579

Browse files
committed
riscv: Fix machine recognition for c910v
Signed-off-by: Han Gao <gaohan@uniontech.com>
1 parent ed8b377 commit 8dd4579

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

cpuid_riscv64.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,27 @@ static char *cpuname[] = {
8181
int detect(void){
8282
#ifdef __linux
8383
FILE *infile;
84-
char buffer[512], *p;
84+
char buffer[512],isa_buffer[512],model_buffer[512];
85+
const char* check_c910_str = "T-HEAD C910";
86+
char *pmodel = NULL, *pisa = NULL;
8587

86-
p = (char *)NULL;
8788
infile = fopen("/proc/cpuinfo", "r");
8889
while (fgets(buffer, sizeof(buffer), infile)){
89-
if (!strncmp("isa", buffer, 3)){
90-
p = strchr(buffer, '4') + 1; /* the 4 in rv64ima... */
91-
#if 0
92-
fprintf(stderr, "%s\n", p);
93-
#endif
94-
break;
95-
}
90+
if(!strncmp(buffer, "model name", 10)){
91+
strcpy(model_buffer, buffer)
92+
pmodel = strchr(isa_buffer, ':') + 1;
93+
}
94+
95+
if(!strncmp(buffer, "isa", 3)){
96+
strcpy(isa_buffer, buffer)
97+
pisa = strchr(isa_buffer, '4') + 1;
98+
}
9699
}
97100

98101
fclose(infile);
99102

100-
if (strchr(p, 'v')) return CPU_C910V;
103+
if (strstr(pmodel, check_c910_str) && strchr(p, 'v'))
104+
return CPU_C910V;
101105

102106
return CPU_GENERIC;
103107
#endif

0 commit comments

Comments
 (0)