tunables_static: New module to set up static tunables

This is for things that xnu hard-codes. This first one for AGX is
required to make coprocessor TLB coherency work properly...

Signed-off-by: Asahi Lina <lina@asahilina.net>
This commit is contained in:
Asahi Lina 2022-09-27 06:01:36 +09:00
parent a15eb0919d
commit fe0d3e8e34
4 changed files with 72 additions and 1 deletions

View file

@ -116,7 +116,7 @@ OBJECTS := \
start.o \
startup.o \
string.o \
tunables.o \
tunables.o tunables_static.o \
tps6598x.o \
uart.o \
uartproxy.o \

View file

@ -10,6 +10,7 @@
#include "pcie.h"
#include "sep.h"
#include "smp.h"
#include "tunables.h"
#include "types.h"
#include "usb.h"
#include "utils.h"
@ -1149,6 +1150,7 @@ int kboot_boot(void *kernel)
usb_init();
pcie_init();
dapf_init_all();
tunables_apply_static();
printf("Setting SMP mode to WFE...\n");
smp_set_wfe_mode(true);

View file

@ -37,4 +37,6 @@ int tunables_apply_local(const char *path, const char *prop, u32 reg_idx);
*/
int tunables_apply_local_addr(const char *path, const char *prop, uintptr_t base);
int tunables_apply_static(void);
#endif

67
src/tunables_static.c Normal file
View file

@ -0,0 +1,67 @@
/* SPDX-License-Identifier: MIT */
#include "tunables.h"
#include "adt.h"
#include "pmgr.h"
#include "soc.h"
#include "types.h"
#include "utils.h"
/*
* These magic tunable sequences are hardcoded in various places in XNU, and are required for
* proper operation of various fabric features and other miscellanea. Without them, things tend
* to subtly break...
*/
struct entry {
u32 offset;
u32 clear;
u32 set;
};
struct entry t8103_agx_tunables[] = {
{0x30, 0xffffffff, 0x50014}, {0x34, 0xffffffff, 0xa003c},
{0x400, 0x400103ff, 0x40010001}, {0x600, 0x1ffffff, 0x1ffffff},
{0x738, 0x1ff01ff, 0x140034}, {0x798, 0x1ff01ff, 0x14003c},
{0x800, 0x100, 0x100}, {-1, 0, 0},
};
static void tunables_apply(u64 base, struct entry *entry)
{
while (entry->offset != UINT32_MAX) {
mask32(base + entry->offset, entry->clear, entry->set);
entry++;
}
}
int power_and_apply(const char *path, u64 base, struct entry *entries)
{
if (pmgr_adt_power_enable(path) < 0) {
printf("tunables: Failed to enable power: %s\n", path);
return -1;
}
tunables_apply(base, entries);
if (pmgr_adt_power_disable(path) < 0) {
printf("tunables: Failed to disable power: %s\n", path);
return -1;
}
return 0;
}
int tunables_apply_static(void)
{
int ret = 0;
switch (chip_id) {
case T8103:
ret |= power_and_apply("/arm-io/sgx", 0x205000000, t8103_agx_tunables);
break;
default:
break;
}
return ret ? -1 : 0;
}