From 128062a1dc7ab6529508e36072c1ea9437c0bbe8 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Wed, 21 Aug 2024 22:50:21 +0100 Subject: [PATCH] [v1.06][ARM] Support for M1 in Asahi Linux --- src/arm/soc.c | 37 +++++++++++++++++++++++++++++++++++++ src/arm/uarch.c | 2 ++ src/common/udev.c | 14 ++++++++++++++ src/common/udev.h | 1 + 4 files changed, 54 insertions(+) diff --git a/src/arm/soc.c b/src/arm/soc.c index c76a876..fdc9983 100644 --- a/src/arm/soc.c +++ b/src/arm/soc.c @@ -895,6 +895,39 @@ struct system_on_chip* guess_soc_from_uarch(struct system_on_chip* soc, struct c return soc; } +bool match_dt(struct system_on_chip* soc, char* dt, char* expected_name, char* soc_name, SOC soc_model, int32_t process) { + if (strstr(dt, expected_name) == NULL) { + return false; + } + else { + fill_soc(soc, soc_name, soc_model, process); + return true; + } +} + +#define DT_START if (false) {} +#define DT_EQ(dt, soc, expected_name, soc_name, soc_model, process) \ + else if (match_dt(soc, dt, expected_name, soc_name, soc_model, process)) return soc; +#define DT_END else { return false; } + +// TODO: Move this to doc +// The number of fields seems non-standard, so for now it seems wiser +// to just get the entire string with all fields and just look for the +// substring. +struct system_on_chip* guess_soc_from_devtree(struct system_on_chip* soc) { + char* dt = get_devtree_compatible(); + if (dt == NULL) { + return soc; + } + + DT_START + DT_EQ(dt, soc, "t6000apple", "M1 Pro", SOC_APPLE_M1_PRO, 5) + DT_END + + printWarn("guess_soc_from_devtree: No match found"); + return soc; +} + struct system_on_chip* guess_soc_from_pci(struct system_on_chip* soc, struct cpuInfo* cpu) { struct pci_devices * pci = get_pci_devices(); if (pci == NULL) { @@ -1103,6 +1136,10 @@ struct system_on_chip* get_soc(struct cpuInfo* cpu) { 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) { + soc = guess_soc_from_devtree(soc); + } // If previous steps failed, try with nvmem if(soc->soc_vendor == SOC_VENDOR_UNKNOWN) { soc = guess_soc_from_nvmem(soc); diff --git a/src/arm/uarch.c b/src/arm/uarch.c index 32d6e33..08865b9 100644 --- a/src/arm/uarch.c +++ b/src/arm/uarch.c @@ -248,6 +248,8 @@ struct uarch* get_uarch_from_midr(uint32_t midr, struct cpuInfo* cpu) { CHECK_UARCH(arch, cpu, 'a', 0x022, NA, NA, "Icestorm", UARCH_ICESTORM, CPU_VENDOR_APPLE) CHECK_UARCH(arch, cpu, 'a', 0x023, NA, NA, "Firestorm", UARCH_FIRESTORM, CPU_VENDOR_APPLE) + CHECK_UARCH(arch, cpu, 'a', 0x024, NA, NA, "Icestorm", UARCH_ICESTORM, CPU_VENDOR_APPLE) // https://github.com/Dr-Noob/cpufetch/issues/263 + CHECK_UARCH(arch, cpu, 'a', 0x025, NA, NA, "Firestorm", UARCH_FIRESTORM, CPU_VENDOR_APPLE) // https://github.com/Dr-Noob/cpufetch/issues/263 CHECK_UARCH(arch, cpu, 'a', 0x030, NA, NA, "Blizzard", UARCH_BLIZZARD, CPU_VENDOR_APPLE) CHECK_UARCH(arch, cpu, 'a', 0x031, NA, NA, "Avalanche", UARCH_AVALANCHE, CPU_VENDOR_APPLE) CHECK_UARCH(arch, cpu, 'a', 0x048, NA, NA, "Sawtooth", UARCH_SAWTOOTH, CPU_VENDOR_APPLE) diff --git a/src/common/udev.c b/src/common/udev.c index 953ae71..069c605 100644 --- a/src/common/udev.c +++ b/src/common/udev.c @@ -1,7 +1,10 @@ +#include "../common/global.h" #include "udev.h" #include "global.h" #include "cpu.h" +#define _PATH_DEVTREE "/proc/device-tree/compatible" + // https://www.kernel.org/doc/html/latest/core-api/cpu_hotplug.html int get_ncores_from_cpuinfo(void) { // Examples: @@ -349,3 +352,14 @@ bool is_devtree_compatible(char* str) { } return true; } + +char* get_devtree_compatible(void) { + int filelen; + char* buf; + + if ((buf = read_file(_PATH_DEVTREE, &filelen)) == NULL) { + printWarn("read_file: %s: %s", _PATH_DEVTREE, strerror(errno)); + } + + return buf; +} diff --git a/src/common/udev.h b/src/common/udev.h index f2c4c2e..4cb6825 100644 --- a/src/common/udev.h +++ b/src/common/udev.h @@ -43,5 +43,6 @@ int get_num_sockets_package_cpus(struct topology* topo); int get_ncores_from_cpuinfo(void); char* get_field_from_cpuinfo(char* CPUINFO_FIELD); bool is_devtree_compatible(char* str); +char* get_devtree_compatible(void); #endif