Skip to content

Commit 136a714

Browse files
authored
Merge pull request #5914 from martin-frbg/u74detect
Add cpu detection for Sifive U74
2 parents a5dcb2a + 41aad11 commit 136a714

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

cpuid_riscv64.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ static char *cpuname_lower[] = {
9898
int detect(void){
9999
#ifdef __linux
100100
FILE *infile;
101-
char buffer[512],isa_buffer[512],model_buffer[512];
101+
char buffer[512],isa_buffer[512],model_buffer[512], uarch_buffer[512];
102102
const char* check_c910_str = "T-HEAD C910";
103-
char *pmodel = NULL, *pisa = NULL;
103+
const char* check_u74_str = "sifive,u74";
104+
char *pmodel = NULL, *pisa = NULL, *puarch = NULL;
104105

105106
infile = fopen("/proc/cpuinfo", "r");
106107
if (!infile)
@@ -113,6 +114,13 @@ int detect(void){
113114
pmodel++;
114115
}
115116

117+
if(!strncmp(buffer, "uarch", 5)){
118+
strcpy(uarch_buffer, buffer);
119+
puarch = strchr(uarch_buffer, ':');
120+
if (puarch)
121+
puarch++;
122+
}
123+
116124
if(!strncmp(buffer, "isa", 3)){
117125
strcpy(isa_buffer, buffer);
118126
pisa = strchr(isa_buffer, '4');
@@ -123,12 +131,16 @@ int detect(void){
123131

124132
fclose(infile);
125133

126-
if (!pmodel || !pisa)
134+
if ((!pmodel && !puarch) || !pisa)
127135
return(CPU_GENERIC);
128136

129-
if (strstr(pmodel, check_c910_str) && strchr(pisa, 'v'))
130-
return CPU_C910V;
131-
137+
if (pmodel) {
138+
if (strstr(pmodel, check_c910_str) && strchr(pisa, 'v'))
139+
return CPU_C910V;
140+
} else if (puarch) {
141+
if (strstr(puarch, check_u74_str) && !strchr(pisa, 'v'))
142+
return CPU_U74;
143+
}
132144
return CPU_GENERIC;
133145
#endif
134146

0 commit comments

Comments
 (0)