utils: Add more functions to detect CPU features

These functions will be used to skip over parts not supported by A7-A11 SoCs.

Signed-off-by: Nick Chan <towinchenmi@gmail.com>
This commit is contained in:
Nick Chan 2024-09-23 23:20:27 +08:00 committed by Hector Martin
parent 226ec5298d
commit 5560190b36
6 changed files with 68 additions and 2 deletions

View file

@ -629,3 +629,13 @@
/* Lockdown registers */
#define SYS_IMP_APL_SPR_LOCKDOWN_EL2 sys_reg(3, 4, 15, 0, 5)
#define SYS_IMP_APL_SPR_LOCKDOWN_EL1 sys_reg(3, 4, 15, 0, 6)
/* Feature ID registers */
#define AIDR_EL1_MUL53 BIT(0)
#define AIDR_EL1_WKDM BIT(1)
#define AIDR_EL1_ARCH_RETENTION BIT(2)
#define AIDR_EL1_AMX BIT(4)
#define AIDR_EL1_TSO BIT(9)
#define AIDR_EL1_GXF BIT(16)
#define AIDR_EL1_APFLG BIT(19)
#define AIDR_EL1_PSRV BIT(20)

View file

@ -39,9 +39,18 @@ u32 board_id = ~0, chip_id = ~0;
void get_device_info(void)
{
const char *model = (const char *)adt_getprop(adt, 0, "model", NULL);
const char *target = (const char *)adt_getprop(adt, 0, "target-type", NULL);
printf("Device info:\n");
printf(" Model: %s\n", (const char *)adt_getprop(adt, 0, "model", NULL));
printf(" Target: %s\n", (const char *)adt_getprop(adt, 0, "target-type", NULL));
if (model)
printf(" Model: %s\n", model);
if (target)
printf(" Target: %s\n", target);
is_mac = !!strstr(model, "Mac");
int chosen = adt_path_offset(adt, "/chosen");
if (chosen > 0) {

View file

@ -188,6 +188,30 @@ char *strrchr(const char *s, int c)
return NULL;
}
char *strstr(const char *s1, const char *s2)
{
const char *p1 = s1;
const char *p2;
while (*s1) {
p2 = s2;
while (*p2 && (*p1 == *p2)) {
++p1;
++p2;
}
if (!*p2) {
return (char *)s1;
}
++s1;
p1 = s1;
}
return NULL;
}
/* Very naive, no attempt to check for errors */
long atol(const char *s)
{

View file

@ -4,12 +4,15 @@
#include <stdarg.h>
#include "utils.h"
#include "cpu_regs.h"
#include "iodev.h"
#include "smp.h"
#include "types.h"
#include "vsprintf.h"
#include "xnuboot.h"
bool is_mac = false;
static char ascii(char s)
{
if (s < 0x20)
@ -181,6 +184,21 @@ bool is_heap(void *addr)
return p > top_of_kernel_data && p < top_of_ram;
}
bool supports_arch_retention(void)
{
return mrs(AIDR_EL1) & AIDR_EL1_ARCH_RETENTION;
}
bool supports_gxf(void)
{
return mrs(AIDR_EL1) & AIDR_EL1_GXF;
}
bool supports_pan(void)
{
return (mrs(ID_AA64MMFR1_EL1) >> 20) & 0xf;
}
// TODO: update mapping?
u64 top_of_memory_alloc(size_t size)
{

View file

@ -429,6 +429,7 @@ struct vector_args {
};
extern u32 board_id, chip_id;
extern bool is_mac;
extern bool cpufeat_actlr_el2;
extern struct vector_args next_stage;
@ -437,6 +438,9 @@ void cpu_sleep(bool deep) __attribute__((noreturn));
void deep_wfi(void);
bool is_heap(void *addr);
bool supports_arch_retention(void);
bool supports_gxf(void);
bool supports_pan(void);
u64 top_of_memory_alloc(size_t size);
#endif

View file

@ -18,6 +18,7 @@ size_t strlen(const char *s);
size_t strnlen(const char *s, size_t n);
char *strchr(const char *s, int c);
char *strrchr(const char *s, int c);
char *strstr(const char *s1, const char *s2);
long atol(const char *s);
static inline int tolower(int c)