diff --git a/src/chipid.c b/src/chipid.c index 1dfcff4..3cfe95c 100644 --- a/src/chipid.c +++ b/src/chipid.c @@ -71,6 +71,8 @@ static const manufacturers_t manufacturers[] = { #ifdef IPCHW_VENDOR_GM {"Grain", gm_detect_cpu, VENDOR_GM, gm_setup_hal}, #ifndef STANDALONE_LIBRARY + /* GM8126 / GM8128 on the vendor 2.6.28 kernel */ + {"Faraday", gm_faraday_detect_cpu, VENDOR_GM, gm_setup_hal}, {NULL /* Generic */, gm_dt_detect_cpu, VENDOR_GM, gm_setup_hal}, #endif #endif diff --git a/src/hal/gm.c b/src/hal/gm.c index a57bcb5..aa803bf 100644 --- a/src/hal/gm.c +++ b/src/hal/gm.c @@ -59,6 +59,53 @@ bool gm_dt_detect_cpu(char *chip_name) { } return false; } + +/* The PMU's ID word (0x99000000 >> 8) as the vendor 2.6.28 kernel shows it: + * the value under "Attribute name : pmuver" in /proc/pmu/attribute. */ +static unsigned long gm_pmuver() { + char line[128], name[32]; + bool ours = false; + unsigned long ver = 0; + + FILE *f = fopen("/proc/pmu/attribute", "r"); + if (!f) + return 0; + while (fgets(line, sizeof(line), f)) { + if (sscanf(line, "Attribute name : %31s", name) == 1) + ours = !strcmp(name, "pmuver"); + else if (ours && sscanf(line, "Attribute value: %lu", &ver) == 1) + break; + } + fclose(f); + return ver; +} + +/* The vendor 2.6.28 kernel of the GM8126 generation says "Hardware : + * Faraday GM8126" whatever the die, and has no /proc/pmu/chipver. It tells + * the dies apart on its boot line ("IC: GM8128 MP") from the PMU ID word: + * 0x812610 GM8126, 0x812620 GM8126 MP, 0x812621 GM8128 MP. Without one of + * those the Hardware line names only the generation, so that is all the + * report claims. */ +bool gm_faraday_detect_cpu(char *chip_name) { + char buf[256]; + + if (!line_from_file("/proc/cpuinfo", "Hardware.+:.Faraday.GM([0-9]+)", buf, + sizeof(buf))) + return false; + + switch (gm_pmuver()) { + case 0x812621: + strcpy(chip_name, "GM8128"); + break; + case 0x812610: + case 0x812620: + strcpy(chip_name, "GM8126"); + break; + default: + strcpy(chip_name, "GM812x"); + } + return true; +} #endif static unsigned long gm_media_mem() { diff --git a/src/hal/gm.h b/src/hal/gm.h index 98933c1..e415a0a 100644 --- a/src/hal/gm.h +++ b/src/hal/gm.h @@ -6,6 +6,7 @@ bool gm_detect_cpu(char *chip_name); #ifndef STANDALONE_LIBRARY bool gm_dt_detect_cpu(char *chip_name); +bool gm_faraday_detect_cpu(char *chip_name); #endif unsigned long gm_totalmem(unsigned long *media_mem); void gm_setup_hal();