Skip to content

Commit

Permalink
[v1.06] Remove soc_ prefix from field names in system_on_chip struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Noob committed Aug 24, 2024
1 parent 13605ed commit 7ad19d1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
66 changes: 33 additions & 33 deletions src/arm/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool get_sunxisoc_from_sid(struct system_on_chip* soc, char* raw_name, uint32_t
int index = 0;
while(socFromSid[index].sid != 0x0) {
if(socFromSid[index].sid == sid) {
fill_soc(soc, socFromSid[index].soc.soc_name, socFromSid[index].soc.soc_model, socFromSid[index].soc.process);
fill_soc(soc, socFromSid[index].soc.name, socFromSid[index].soc.model, socFromSid[index].soc.process);
return true;
}
index++;
Expand All @@ -128,7 +128,7 @@ bool match_broadcom(char* soc_name, struct system_on_chip* soc) {
if((tmp = strstr(soc_name, "BCM")) == NULL)
return false;

soc->soc_vendor = SOC_VENDOR_BROADCOM;
soc->vendor = SOC_VENDOR_BROADCOM;

SOC_START
SOC_EQ(tmp, "BCM2835", "BCM2835", SOC_BCM_2835, soc, 65)
Expand Down Expand Up @@ -156,7 +156,7 @@ bool match_google(char* soc_name, struct system_on_chip* soc) {
if((tmp = strstr(soc_name, "gs")) == NULL)
return false;

soc->soc_vendor = SOC_VENDOR_GOOGLE;
soc->vendor = SOC_VENDOR_GOOGLE;

SOC_START
SOC_EQ(tmp, "gs101", "Tensor", SOC_GOOGLE_TENSOR, soc, 5)
Expand All @@ -175,7 +175,7 @@ bool match_hisilicon(char* soc_name, struct system_on_chip* soc) {
else if((tmp = strstr(soc_name, "kirin")) != NULL);
else return false;

soc->soc_vendor = SOC_VENDOR_KIRIN;
soc->vendor = SOC_VENDOR_KIRIN;

SOC_START
SOC_EQ(tmp, "hi3620GFC", "K3V2", SOC_HISILICON_3620, soc, 40)
Expand Down Expand Up @@ -217,7 +217,7 @@ bool match_exynos(char* soc_name, struct system_on_chip* soc) {
else if((tmp = strstr(soc_name, "exynos")) != NULL);
else return false;

soc->soc_vendor = SOC_VENDOR_EXYNOS;
soc->vendor = SOC_VENDOR_EXYNOS;

// Because exynos are recently using "exynosXXXX" instead
// of "universalXXXX" as codenames, SOC_EXY_EQ will check for
Expand Down Expand Up @@ -277,7 +277,7 @@ bool match_mediatek(char* soc_name, struct system_on_chip* soc) {
if((tmp = strstr(soc_name_upper, "MT")) == NULL)
return false;

soc->soc_vendor = SOC_VENDOR_MEDIATEK;
soc->vendor = SOC_VENDOR_MEDIATEK;

SOC_START
// Dimensity //
Expand Down Expand Up @@ -460,7 +460,7 @@ bool match_qualcomm(char* soc_name, struct system_on_chip* soc) {
else if((tmp = strstr(soc_name_upper, "QSD")) != NULL);
else return false;

soc->soc_vendor = SOC_VENDOR_SNAPDRAGON;
soc->vendor = SOC_VENDOR_SNAPDRAGON;

SOC_START
// Snapdragon S1 //
Expand Down Expand Up @@ -613,7 +613,7 @@ bool match_allwinner(char* soc_name, struct system_on_chip* soc) {
if((tmp = strstr(soc_name, "sun")) == NULL)
return false;

soc->soc_vendor = SOC_VENDOR_ALLWINNER;
soc->vendor = SOC_VENDOR_ALLWINNER;

SOC_START
// SoCs we can detect just with with the name
Expand Down Expand Up @@ -737,7 +737,7 @@ void try_parse_soc_from_string(struct system_on_chip* soc, int soc_len, char* so
soc->raw_name = emalloc(sizeof(char) * (soc_len + 1));
strncpy(soc->raw_name, soc_str, soc_len + 1);
soc->raw_name[soc_len] = '\0';
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
soc->vendor = SOC_VENDOR_UNKNOWN;
parse_soc_from_string(soc);
}

Expand All @@ -748,7 +748,7 @@ struct system_on_chip* guess_soc_from_android(struct system_on_chip* soc) {
property_len = android_property_get("ro.mediatek.platform", (char *) &tmp);
if(property_len > 0) {
try_parse_soc_from_string(soc, property_len, tmp);
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) printWarn("SoC detection failed using Android property ro.mediatek.platform: %s", tmp);
if(soc->vendor == SOC_VENDOR_UNKNOWN) printWarn("SoC detection failed using Android property ro.mediatek.platform: %s", tmp);
else return soc;
}

Expand All @@ -758,21 +758,21 @@ struct system_on_chip* guess_soc_from_android(struct system_on_chip* soc) {
property_len = android_property_get("ro.soc.model", (char *) &tmp);
if(property_len > 0) {
try_parse_soc_from_string(soc, property_len, tmp);
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) printWarn("SoC detection failed using Android property ro.soc.model: %s", tmp);
if(soc->vendor == SOC_VENDOR_UNKNOWN) printWarn("SoC detection failed using Android property ro.soc.model: %s", tmp);
else return soc;
}

property_len = android_property_get("ro.product.board", (char *) &tmp);
if(property_len > 0) {
try_parse_soc_from_string(soc, property_len, tmp);
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) printWarn("SoC detection failed using Android property ro.product.board: %s", tmp);
if(soc->vendor == SOC_VENDOR_UNKNOWN) printWarn("SoC detection failed using Android property ro.product.board: %s", tmp);
else return soc;
}

property_len = android_property_get("ro.board.platform", (char *) &tmp);
if(property_len > 0) {
try_parse_soc_from_string(soc, property_len, tmp);
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) printWarn("SoC detection failed using Android property ro.board.platform: %s", tmp);
if(soc->vendor == SOC_VENDOR_UNKNOWN) printWarn("SoC detection failed using Android property ro.board.platform: %s", tmp);
else return soc;
}

Expand Down Expand Up @@ -838,7 +838,7 @@ bool get_rk_soc_from_efuse(struct system_on_chip* soc, char* efuse) {
int index = 0;
while(socFromRK[index].rk_soc != 0x0) {
if(socFromRK[index].rk_soc == rk_soc) {
fill_soc(soc, socFromRK[index].soc.soc_name, socFromRK[index].soc.soc_model, socFromRK[index].soc.process);
fill_soc(soc, socFromRK[index].soc.name, socFromRK[index].soc.model, socFromRK[index].soc.process);
return true;
}
index++;
Expand Down Expand Up @@ -885,7 +885,7 @@ struct system_on_chip* guess_soc_from_uarch(struct system_on_chip* soc, struct c
int index = 0;
while(socFromUarch[index].u != UARCH_UNKNOWN) {
if(socFromUarch[index].u == get_uarch(arch)) {
fill_soc(soc, socFromUarch[index].soc.soc_name, socFromUarch[index].soc.soc_model, socFromUarch[index].soc.process);
fill_soc(soc, socFromUarch[index].soc.name, socFromUarch[index].soc.model, socFromUarch[index].soc.process);
return soc;
}
index++;
Expand Down Expand Up @@ -995,7 +995,7 @@ struct system_on_chip* guess_soc_from_pci(struct system_on_chip* soc, struct cpu

if (socFromPCI[index].vendor_id == dev->vendor_id &&
socFromPCI[index].device_id == dev->device_id) {
fill_soc(soc, socFromPCI[index].soc.soc_name, socFromPCI[index].soc.soc_model, socFromPCI[index].soc.process);
fill_soc(soc, socFromPCI[index].soc.name, socFromPCI[index].soc.model, socFromPCI[index].soc.process);
return soc;
}
}
Expand Down Expand Up @@ -1079,12 +1079,12 @@ struct system_on_chip* guess_soc_apple(struct system_on_chip* soc) {
}
else {
printBug("Found invalid physical cpu number: %d", physicalcpu);
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
soc->vendor = SOC_VENDOR_UNKNOWN;
}
}
else {
printBugCheckRelease("Found invalid cpu_subfamily: 0x%.8X", cpu_subfamily);
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
soc->vendor = SOC_VENDOR_UNKNOWN;
}
}
else if(cpu_family == CPUFAMILY_ARM_AVALANCHE_BLIZZARD) {
Expand All @@ -1106,12 +1106,12 @@ struct system_on_chip* guess_soc_apple(struct system_on_chip* soc) {
}
else {
printBug("Found invalid physical cpu number: %d", physicalcpu);
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
soc->vendor = SOC_VENDOR_UNKNOWN;
}
}
else {
printBugCheckRelease("Found invalid cpu_subfamily: 0x%.8X", cpu_subfamily);
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
soc->vendor = SOC_VENDOR_UNKNOWN;
}
}
else if(cpu_family == CPUFAMILY_ARM_EVEREST_SAWTOOTH ||
Expand All @@ -1129,12 +1129,12 @@ struct system_on_chip* guess_soc_apple(struct system_on_chip* soc) {
}
else {
printBugCheckRelease("Found invalid cpu_family: 0x%.8X", cpu_family);
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
soc->vendor = SOC_VENDOR_UNKNOWN;
}
}
else {
printBugCheckRelease("Found invalid cpu_family: 0x%.8X", cpu_family);
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
soc->vendor = SOC_VENDOR_UNKNOWN;
}
return soc;
}
Expand All @@ -1143,15 +1143,15 @@ struct system_on_chip* guess_soc_apple(struct system_on_chip* soc) {
struct system_on_chip* get_soc(struct cpuInfo* cpu) {
struct system_on_chip* soc = emalloc(sizeof(struct system_on_chip));
soc->raw_name = NULL;
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
soc->soc_model = SOC_MODEL_UNKNOWN;
soc->vendor = SOC_VENDOR_UNKNOWN;
soc->model = SOC_MODEL_UNKNOWN;
soc->process = UNKNOWN;

#ifdef __linux__
bool isRPi = is_raspberry_pi();
if(isRPi) {
soc = guess_soc_raspbery_pi(soc);
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
if(soc->vendor == SOC_VENDOR_UNKNOWN) {
printErr("[RPi] SoC detection failed using revision code, falling back to cpuinfo detection");
}
else {
Expand All @@ -1160,7 +1160,7 @@ struct system_on_chip* get_soc(struct cpuInfo* cpu) {
}

soc = guess_soc_from_cpuinfo(soc);
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
if(soc->vendor == SOC_VENDOR_UNKNOWN) {
if(soc->raw_name != NULL) {
printWarn("SoC detection failed using /proc/cpuinfo: Found '%s' string", soc->raw_name);
}
Expand All @@ -1172,38 +1172,38 @@ struct system_on_chip* get_soc(struct cpuInfo* cpu) {
if(soc->raw_name == NULL) {
printWarn("SoC detection failed using Android: No string found");
}
else if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
else if(soc->vendor == SOC_VENDOR_UNKNOWN) {
printWarn("SoC detection failed using Android: Found '%s' string", soc->raw_name);
}
#endif // ifdef __ANDROID__
// If previous steps failed, try with the device tree
if (soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
if (soc->vendor == SOC_VENDOR_UNKNOWN) {
soc = guess_soc_from_devtree(soc);
}
// If previous steps failed, try with nvmem
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
if(soc->vendor == SOC_VENDOR_UNKNOWN) {
soc = guess_soc_from_nvmem(soc);
}
// If previous steps failed, try infering it from the microarchitecture
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
if(soc->vendor == SOC_VENDOR_UNKNOWN) {
soc = guess_soc_from_uarch(soc, cpu);
}
// If previous steps failed, try infering it from the pci device id
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
if(soc->vendor == SOC_VENDOR_UNKNOWN) {
soc = guess_soc_from_pci(soc, cpu);
}
}
#elif defined __APPLE__ || __MACH__
soc = guess_soc_apple(soc);
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
if(soc->vendor == SOC_VENDOR_UNKNOWN) {
printWarn("SoC detection failed using cpu_subfamily");
}
else {
return soc;
}
#endif // ifdef __linux__

if(soc->soc_model == SOC_MODEL_UNKNOWN) {
if(soc->model == SOC_MODEL_UNKNOWN) {
// raw_name might not be NULL, but if we were unable to find
// the exact SoC, just print "Unkwnown"
soc->raw_name = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
Expand Down
26 changes: 13 additions & 13 deletions src/common/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static char* soc_trademark_string[] = {
};

VENDOR get_soc_vendor(struct system_on_chip* soc) {
return soc->soc_vendor;
return soc->vendor;
}

char* get_str_process(struct system_on_chip* soc) {
Expand All @@ -50,31 +50,31 @@ char* get_str_process(struct system_on_chip* soc) {
}

char* get_soc_name(struct system_on_chip* soc) {
if(soc->soc_model == SOC_MODEL_UNKNOWN)
if(soc->model == SOC_MODEL_UNKNOWN)
return soc->raw_name;
return soc->soc_name;
return soc->name;
}

void fill_soc(struct system_on_chip* soc, char* soc_name, SOC soc_model, int32_t process) {
soc->soc_model = soc_model;
soc->soc_vendor = get_soc_vendor_from_soc(soc_model);
soc->model = soc_model;
soc->vendor = get_soc_vendor_from_soc(soc_model);
soc->process = process;
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
printBug("fill_soc: soc->soc_vendor == SOC_VENDOR_UNKOWN");
if(soc->vendor == SOC_VENDOR_UNKNOWN) {
printBug("fill_soc: soc->vendor == SOC_VENDOR_UNKOWN");
// If we fall here there is a bug in socs.h
// Reset everything to avoid segfault
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
soc->soc_model = SOC_MODEL_UNKNOWN;
soc->vendor = SOC_VENDOR_UNKNOWN;
soc->model = SOC_MODEL_UNKNOWN;
soc->process = UNKNOWN;
soc->raw_name = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
snprintf(soc->raw_name, strlen(STRING_UNKNOWN)+1, STRING_UNKNOWN);
}
else {
soc->process = process;
int len = strlen(soc_name) + strlen(soc_trademark_string[soc->soc_vendor]) + 1;
soc->soc_name = emalloc(sizeof(char) * len);
memset(soc->soc_name, 0, sizeof(char) * len);
sprintf(soc->soc_name, "%s%s", soc_trademark_string[soc->soc_vendor], soc_name);
int len = strlen(soc_name) + strlen(soc_trademark_string[soc->vendor]) + 1;
soc->name = emalloc(sizeof(char) * len);
memset(soc->name, 0, sizeof(char) * len);
sprintf(soc->name, "%s%s", soc_trademark_string[soc->vendor], soc_name);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/common/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ enum {
};

struct system_on_chip {
SOC soc_model;
VENDOR soc_vendor;
SOC model;
VENDOR vendor;
int32_t process;
char* soc_name;
char* name;
char* raw_name;
};

Expand Down
10 changes: 5 additions & 5 deletions src/riscv/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bool match_sifive(char* soc_name, struct system_on_chip* soc) {
/*if((tmp = strstr(soc_name, "???")) == NULL)
return false;*/

//soc->soc_vendor = ???
//soc->vendor = ???

SOC_START
SOC_EQ(tmp, "fu740", "Freedom U740", SOC_SIFIVE_U740, soc, 40)
Expand Down Expand Up @@ -68,12 +68,12 @@ struct system_on_chip* guess_soc_from_devtree(struct system_on_chip* soc) {
struct system_on_chip* get_soc(struct cpuInfo* cpu) {
struct system_on_chip* soc = emalloc(sizeof(struct system_on_chip));
soc->raw_name = NULL;
soc->soc_vendor = SOC_VENDOR_UNKNOWN;
soc->soc_model = SOC_MODEL_UNKNOWN;
soc->vendor = SOC_VENDOR_UNKNOWN;
soc->model = SOC_MODEL_UNKNOWN;
soc->process = UNKNOWN;

soc = guess_soc_from_devtree(soc);
if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) {
if(soc->vendor == SOC_VENDOR_UNKNOWN) {
if(soc->raw_name != NULL) {
printWarn("SoC detection failed using device tree: Found '%s' string", soc->raw_name);
}
Expand All @@ -82,7 +82,7 @@ struct system_on_chip* get_soc(struct cpuInfo* cpu) {
}
}

if(soc->soc_model == SOC_MODEL_UNKNOWN) {
if(soc->model == SOC_MODEL_UNKNOWN) {
// raw_name might not be NULL, but if we were unable to find
// the exact SoC, just print "Unkwnown"
soc->raw_name = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN)+1));
Expand Down

0 comments on commit 7ad19d1

Please sign in to comment.