Skip to content

Commit

Permalink
More support for M3 chips
Browse files Browse the repository at this point in the history
The UART base has moved from the M2 chips.
Everest settings introduce some changes to unknown registers
The MCC data has changed as well.
This is not totally complete (crashes setting MMU register),
but is good enough to run bringup mode.

Signed-off-by: Daniel Berlin <[email protected]>
  • Loading branch information
dberlin committed Nov 24, 2023
1 parent 232836b commit a8e9348
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ OBJECTS := \
chickens.o \
chickens_avalanche.o \
chickens_blizzard.o \
chickens_everest.o \
chickens_firestorm.o \
chickens_icestorm.o \
chickens_sawtooth.o \
clk.o \
cpufreq.o \
dapf.o \
Expand Down
14 changes: 14 additions & 0 deletions src/chickens.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#define MIDR_PART_T6020_AVALANCHE 0x35
#define MIDR_PART_T6021_BLIZZARD 0x38
#define MIDR_PART_T6021_AVALANCHE 0x39
#define MIDR_PART_T6031_EVEREST 0x49
#define MIDR_PART_T6031_SAWTOOTH 0x48

#define MIDR_REV_LOW GENMASK(3, 0)
#define MIDR_PART GENMASK(15, 4)
Expand All @@ -37,6 +39,8 @@ void init_t6020_blizzard(void);
void init_t6020_avalanche(int rev);
void init_t6021_blizzard(void);
void init_t6021_avalanche(int rev);
void init_t6031_sawtooth(void);
void init_t6031_everest(int rev);

const char *init_cpu(void)
{
Expand Down Expand Up @@ -123,6 +127,16 @@ const char *init_cpu(void)
init_t6021_blizzard();
break;

case MIDR_PART_T6031_EVEREST:
cpu = "M3 Max Everest";
init_t6031_everest(rev);
break;

case MIDR_PART_T6031_SAWTOOTH:
cpu = "M3 Max Sawtooth";
init_t6031_sawtooth();
break;

default:
uart_puts(" Unknown CPU type");
break;
Expand Down
50 changes: 50 additions & 0 deletions src/chickens_everest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* SPDX-License-Identifier: MIT */

#include "cpu_regs.h"
#include "uart.h"
#include "utils.h"
static void init_common_everest(void)
{
reg_set(SYS_IMP_APL_HID12, BIT(46));
if (is_ecore())
reg_set(SYS_IMP_APL_EHID0, EHID0_BLI_UNK32);
// "configure dummy cycles to work around incorrect temp sensor readings on
// NEX power gating" (maybe)
reg_mask(SYS_IMP_APL_HID13,
HID13_POST_OFF_CYCLES_MASK | HID13_POST_ON_CYCLES_MASK | HID13_PRE_CYCLES_MASK |
HID13_GROUP0_FF1_DELAY_MASK | HID13_GROUP0_FF2_DELAY_MASK |
HID13_GROUP0_FF3_DELAY_MASK | HID13_GROUP0_FF4_DELAY_MASK |
HID13_GROUP0_FF5_DELAY_MASK | HID13_GROUP0_FF6_DELAY_MASK |
HID13_GROUP0_FF7_DELAY_MASK | HID13_RESET_CYCLES_MASK,
HID13_POST_OFF_CYCLES(4) | HID13_POST_ON_CYCLES(5) | HID13_PRE_CYCLES(1) |
HID13_GROUP0_FF1_DELAY(4) | HID13_GROUP0_FF2_DELAY(4) | HID13_GROUP0_FF3_DELAY(4) |
HID13_GROUP0_FF4_DELAY(4) | HID13_GROUP0_FF5_DELAY(4) | HID13_GROUP0_FF6_DELAY(4) |
HID13_GROUP0_FF7_DELAY(4) | HID13_RESET_CYCLES(0));

/* Figure out how this really changed later */
/* reg_mask(SYS_IMP_APL_HID26, HID26_GROUP1_OFFSET_MASK | HID26_GROUP2_OFFSET_MASK,
HID26_GROUP1_OFFSET(26) | HID26_GROUP2_OFFSET(31));*/
msr(SYS_IMP_APL_HID26, HID26_GROUP1_OFFSET(0xF88F65588LL) | HID26_GROUP2_OFFSET(0x3F28));
/* reg_mask(SYS_IMP_APL_HID27, BIT(40)HID27_GROUP3_OFFSET_MASK, HID27_GROUP3_OFFSET(31)); */
/* ditto on this */
msr(SYS_IMP_APL_HID27, BIT(0) | BIT(4) | (0x2B << 8) | BIT(16) | BIT(20) | BIT(24) | BIT(28) |
BIT(32) | BIT(36) | BIT(40));
reg_set(SYS_IMP_APL_HID16, BIT(54));
/* This is new to M3 and i have no idea what it is yet */
reg_clr(s3_0_c15_c2_4, BIT(0) | BIT(1) | BIT(16) | BIT(17) | BIT(18) | BIT(22));
}

void init_t6031_everest(int rev)
{
UNUSED(rev);
uart_puts("Everest\n");
init_common_everest();
reg_set(SYS_IMP_APL_HID3, BIT(63));
// The T6031 code seems to have changed the pcie throttle mask
reg_mask(SYS_IMP_APL_HID3, GENMASK(ULONG(62), ULONG(56)), BIT(60) | BIT(59) | BIT(58));
reg_clr(SYS_IMP_APL_HID3, BIT(4));
reg_set(SYS_IMP_APL_HID18, HID18_AVL_UNK27 | HID18_AVL_UNK29);
reg_set(SYS_IMP_APL_HID16, HID16_AVL_UNK12);

reg_mask(SYS_IMP_APL_HID5, HID5_BLZ_UNK_19_18_MASK, HID5_BLZ_UNK19);
}
20 changes: 20 additions & 0 deletions src/chickens_sawtooth.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* SPDX-License-Identifier: MIT */

#include "cpu_regs.h"
#include "utils.h"

static void init_common_sawtooth(void)
{
reg_set(SYS_IMP_APL_EHID0, EHID0_BLI_UNK32);
}

void init_t6031_sawtooth(void)
{
init_common_sawtooth();

reg_mask(SYS_IMP_APL_EHID9, EHID9_DEV_2_THROTTLE_LIMIT_MASK, EHID9_DEV_2_THROTTLE_LIMIT(62));
reg_set(SYS_IMP_APL_EHID9, EHID9_DEV_2_THROTTLE_ENABLE);
reg_set(SYS_IMP_APL_EHID18, EHID18_BLZ_UNK34);

reg_mask(SYS_IMP_APL_HID5, HID5_BLZ_UNK_19_18_MASK, HID5_BLZ_UNK19);
}
2 changes: 2 additions & 0 deletions src/cpu_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@
#define HID11_ENABLE_FIX_UC_55719865 BIT(15)
#define HID11_DISABLE_LD_NT_WIDGET BIT(59)

#define SYS_IMP_APL_HID12 sys_reg(3, 0, 15, 12, 0)

#define SYS_IMP_APL_HID13 sys_reg(3, 0, 15, 14, 0)
#define HID13_POST_OFF_CYCLES(x) ((ULONG(x)))
#define HID13_POST_OFF_CYCLES_MASK GENMASK(6, 0)
Expand Down
97 changes: 96 additions & 1 deletion src/mcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ static bool mcc_initialized = false;
#define T6000_DCS_STRIDE 0x100000
#define T6000_DCS_COUNT 4

#define T6031_PLANE_OFFSET 0
#define T6031_PLANE_STRIDE 0x40000
#define T6031_GLOBAL_OFFSET 0x100000
#define T6031_DCS_OFFSET 0x400000
#define T6031_DCS_STRIDE 0x200000

#define PLANE_TZ_MAX_REGS 4

struct tz_regs {
Expand All @@ -49,6 +55,14 @@ struct tz_regs t602x_tz_regs = {
.enable = 0x6c8,
};

struct tz_regs t603x_tz_regs = {
.count = 4,
.stride = 0x14,
.start = 0x6d8,
.end = 0x6dc,
.enable = 0x6e4,
};

#define PLANE_CACHE_ENABLE 0x1c00
#define PLANE_CACHE_STATUS 0x1c04

Expand All @@ -64,6 +78,12 @@ struct tz_regs t602x_tz_regs = {
(FIELD_PREP(T6000_CACHE_STATUS_DATA_COUNT, T6000_CACHE_WAYS) | \
FIELD_PREP(T6000_CACHE_STATUS_TAG_COUNT, T6000_CACHE_WAYS))

#define T6031_CACHE_WAYS 16
#define T6031_CACHE_STATUS_MASK (T6000_CACHE_STATUS_DATA_COUNT | T6000_CACHE_STATUS_TAG_COUNT)
#define T6031_CACHE_STATUS_VAL \
(FIELD_PREP(T6000_CACHE_STATUS_DATA_COUNT, T6031_CACHE_WAYS) | \
FIELD_PREP(T6000_CACHE_STATUS_TAG_COUNT, T6031_CACHE_WAYS))

#define T8103_CACHE_WAYS 16
#define T8103_CACHE_STATUS_MASK (T8103_CACHE_STATUS_DATA_COUNT | T8103_CACHE_STATUS_TAG_COUNT)
#define T8103_CACHE_STATUS_VAL \
Expand Down Expand Up @@ -134,6 +154,8 @@ int mcc_enable_cache(void)
if (!mcc_initialized)
return -1;

/* The 6030 memory controller supports setting a waymask, but the desktop chips do not appear to
use it */
for (int mcc = 0; mcc < mcc_count; mcc++) {
for (int plane = 0; plane < mcc_regs[mcc].plane_count; plane++) {
plane_write32(mcc, plane, PLANE_CACHE_ENABLE, mcc_regs[mcc].cache_enable_val);
Expand Down Expand Up @@ -161,7 +183,12 @@ int mcc_unmap_carveouts(void)

mcc_carveout_count = 0;
memset(mcc_carveouts, 0, sizeof mcc_carveouts);

// All MCCs and planes should have identical configs
// Note: For unhandled machines, the TZ regions can be found (on m1, m2, m3) by looking at
// region-id-2 and region-id-4 on a booted macos, in the /chosen/carveout-memory-map DT node.
// This can be used along with dumping the mcc reg space to find the correct start/end/enable
// above.
for (u32 i = 0; i < mcc_regs[0].tz->count; i++) {
uint64_t off = mcc_regs[0].tz->stride * i;
uint64_t start = plane_read32(0, 0, mcc_regs[0].tz->start + off);
Expand Down Expand Up @@ -291,6 +318,72 @@ int mcc_init_t6000(int node, int *path, bool t602x)
return 0;
}

int mcc_init_t6031(int node, int *path)
{
u32 reg_len;
u32 reg_offset = 3;

if (!adt_getprop(adt, node, "reg", &reg_len)) {
printf("MCC: Failed to get reg property!\n");
return -1;
}

mcc_count = reg_len / 16 - reg_offset;

printf("MCC: Initializing T6031 MCCs (%d instances)...\n", mcc_count);

if (mcc_count > MAX_MCC_INSTANCES) {
printf("MCC: Too many instances, increase MAX_MCC_INSTANCES!\n");
mcc_count = MAX_MCC_INSTANCES;
}

u32 plane_count = 0;
u32 dcs_count = 0;

if (!ADT_GETPROP(adt, node, "dcs-count-per-amcc", &dcs_count)) {
printf("MCC: Failed to get dcs count!\n");
return -1;
}

if (!ADT_GETPROP(adt, node, "plane-count-per-amcc", &plane_count)) {
printf("MCC: Failed to get plane count!\n");
return -1;
}

for (int i = 0; i < mcc_count; i++) {
u64 base;
if (adt_get_reg(adt, path, "reg", i + reg_offset, &base, NULL)) {
printf("MCC: Failed to get reg index %d!\n", i + reg_offset);
return -1;
}

mcc_regs[i].plane_base = base + T6031_PLANE_OFFSET;
mcc_regs[i].plane_stride = T6031_PLANE_STRIDE;
mcc_regs[i].plane_count = plane_count;

mcc_regs[i].global_base = base + T6031_GLOBAL_OFFSET;

mcc_regs[i].dcs_base = base + T6031_DCS_OFFSET;
mcc_regs[i].dcs_stride = T6031_DCS_STRIDE;
mcc_regs[i].dcs_count = dcs_count;

mcc_regs[i].cache_enable_val = 1;
mcc_regs[i].cache_ways = T6031_CACHE_WAYS;
mcc_regs[i].cache_status_mask = T6031_CACHE_STATUS_MASK;
mcc_regs[i].cache_status_val = T6031_CACHE_STATUS_VAL;
mcc_regs[i].cache_disable = 0;

mcc_regs[i].tz = &t603x_tz_regs;
}

printf("MCC: Initialized T6031 MCCs (%d instances, %d planes, %d channels)\n", mcc_count,
mcc_regs[0].plane_count, mcc_regs[0].dcs_count);

mcc_initialized = true;

return 0;
}

int mcc_init(void)
{
int path[8];
Expand All @@ -309,8 +402,10 @@ int mcc_init(void)
return mcc_init_t6000(node, path, false);
} else if (adt_is_compatible(adt, node, "mcc,t6020")) {
return mcc_init_t6000(node, path, true);
} else if (adt_is_compatible(adt, node, "mcc,t6031")) {
return mcc_init_t6031(node, path);
} else {
printf("MCC: Unsupported version\n");
printf("MCC: Unsupported version:%s\n", adt_get_property(adt, node, "compatible")->value);
return -1;
}
}
2 changes: 2 additions & 0 deletions src/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#define EARLY_UART_BASE 0x39b200000
#elif TARGET == T8112
#define EARLY_UART_BASE 0x235200000
#elif TARGET == T6034 || TARGET == T6031
#define EARLY_UART_BASE 0x391200000
#endif

#endif
Expand Down

0 comments on commit a8e9348

Please sign in to comment.