[v1.06][ARM] Support for M1 in Asahi Linux

This commit is contained in:
Dr-Noob
2024-08-21 22:50:21 +01:00
parent 321a1ec375
commit 128062a1dc
4 changed files with 54 additions and 0 deletions

View File

@@ -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);

View File

@@ -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)

View File

@@ -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;
}

View File

@@ -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