2021-01-25 10:08:59 +00:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
|
|
|
#include "chickens.h"
|
2021-01-30 08:02:35 +00:00
|
|
|
#include "cpu_regs.h"
|
2021-01-25 10:08:59 +00:00
|
|
|
#include "uart.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
/* Part IDs in MIDR_EL1 */
|
2021-11-01 09:56:49 +00:00
|
|
|
#define MIDR_PART_T8181_ICESTORM 0x20
|
|
|
|
#define MIDR_PART_T8181_FIRESTORM 0x21
|
|
|
|
#define MIDR_PART_T8103_ICESTORM 0x22
|
|
|
|
#define MIDR_PART_T8103_FIRESTORM 0x23
|
|
|
|
#define MIDR_PART_T6000_ICESTORM 0x24
|
|
|
|
#define MIDR_PART_T6000_FIRESTORM 0x25
|
|
|
|
#define MIDR_PART_T6001_ICESTORM 0x28
|
|
|
|
#define MIDR_PART_T6001_FIRESTORM 0x29
|
2021-01-25 10:08:59 +00:00
|
|
|
|
2021-11-01 04:41:12 +00:00
|
|
|
#define MIDR_REV_LOW GENMASK(3, 0)
|
|
|
|
#define MIDR_PART GENMASK(15, 4)
|
|
|
|
#define MIDR_REV_HIGH GENMASK(23, 20)
|
|
|
|
|
2021-11-10 15:48:50 +00:00
|
|
|
static void init_common_icestorm(void)
|
2021-01-25 10:08:59 +00:00
|
|
|
{
|
|
|
|
// "Sibling Merge in LLC can cause UC load to violate ARM Memory Ordering Rules."
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_set(SYS_IMP_APL_HID5, HID5_DISABLE_FILL_2C_MERGE);
|
2021-01-25 10:08:59 +00:00
|
|
|
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_clr(SYS_IMP_APL_EHID9, EHID9_DEV_THROTTLE_2_ENABLE);
|
2021-01-27 17:38:30 +00:00
|
|
|
|
|
|
|
// "Prevent store-to-load forwarding for UC memory to avoid barrier ordering
|
|
|
|
// violation"
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_set(SYS_IMP_APL_EHID10, HID10_FORCE_WAIT_STATE_DRAIN_UC | HID10_DISABLE_ZVA_TEMPORAL_TSO);
|
2021-01-25 10:08:59 +00:00
|
|
|
|
|
|
|
// FIXME: do we actually need this?
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_set(SYS_IMP_APL_EHID20, EHID20_TRAP_SMC);
|
2021-11-01 04:41:12 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 15:48:50 +00:00
|
|
|
static void init_common_firestorm(void)
|
2021-11-01 04:41:12 +00:00
|
|
|
{
|
|
|
|
reg_set(SYS_IMP_APL_HID0, HID0_SAME_PG_POWER_OPTIMIZATION);
|
|
|
|
|
|
|
|
// FIXME: do we actually need this?
|
|
|
|
reg_set(SYS_IMP_APL_HID1, HID1_TRAP_SMC);
|
|
|
|
|
|
|
|
reg_clr(SYS_IMP_APL_HID3, HID3_DEV_PCIE_THROTTLE_ENABLE | HID3_DISABLE_ARBITER_FIX_BIF_CRD);
|
|
|
|
|
|
|
|
// "Post-silicon tuning of STNT widget contiguous counter threshold"
|
|
|
|
reg_mask(SYS_IMP_APL_HID4, HID4_STNT_COUNTER_THRESHOLD_MASK, HID4_STNT_COUNTER_THRESHOLD(3));
|
|
|
|
|
|
|
|
// "Sibling Merge in LLC can cause UC load to violate ARM Memory Ordering Rules."
|
|
|
|
reg_set(SYS_IMP_APL_HID5, HID5_DISABLE_FILL_2C_MERGE);
|
|
|
|
|
|
|
|
reg_set(SYS_IMP_APL_HID9, HID9_TSO_ALLOW_DC_ZVA_WC);
|
|
|
|
|
|
|
|
reg_set(SYS_IMP_APL_HID11, HID11_DISABLE_LD_NT_WIDGET);
|
|
|
|
|
|
|
|
// "configure dummy cycles to work around incorrect temp sensor readings on
|
|
|
|
// NEX power gating"
|
|
|
|
reg_mask(SYS_IMP_APL_HID13, HID13_PRE_CYCLES_MASK, HID13_PRE_CYCLES(4));
|
|
|
|
|
|
|
|
// Best bit names...
|
|
|
|
// Maybe: "RF bank and Multipass conflict forward progress widget does not
|
|
|
|
// handle 3+ cycle livelock"
|
|
|
|
reg_set(SYS_IMP_APL_HID16, HID16_SPAREBIT0 | HID16_SPAREBIT3 | HID16_ENABLE_MPX_PICK_45 |
|
|
|
|
HID16_ENABLE_MP_CYCLONE_7);
|
|
|
|
}
|
|
|
|
|
2021-11-10 15:48:50 +00:00
|
|
|
static void init_m1_icestorm(void)
|
2021-11-01 04:41:12 +00:00
|
|
|
{
|
|
|
|
init_common_icestorm();
|
2021-01-25 10:08:59 +00:00
|
|
|
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_set(SYS_IMP_APL_EHID20, EHID20_FORCE_NONSPEC_IF_OLDEST_REDIR_VALID_AND_OLDER |
|
|
|
|
EHID20_FORCE_NONSPEC_IF_SPEC_FLUSH_POINTER_NE_BLK_RTR_POINTER);
|
2021-01-25 10:08:59 +00:00
|
|
|
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_mask(SYS_IMP_APL_EHID20, EHID20_FORCE_NONSPEC_TARGETED_TIMER_SEL_MASK,
|
2021-01-25 10:08:59 +00:00
|
|
|
EHID20_FORCE_NONSPEC_TARGETED_TIMER_SEL(3));
|
|
|
|
}
|
|
|
|
|
2021-11-10 15:48:50 +00:00
|
|
|
static void init_m1_firestorm(void)
|
2021-01-25 10:08:59 +00:00
|
|
|
{
|
2021-11-01 04:41:12 +00:00
|
|
|
init_common_firestorm();
|
|
|
|
|
2021-01-27 17:38:30 +00:00
|
|
|
// "Cross-beat Crypto(AES/PMUL) ICache fusion is not disabled for branch
|
|
|
|
// uncondtional "recoded instruction."
|
2021-11-01 04:41:12 +00:00
|
|
|
reg_set(SYS_IMP_APL_HID0, HID0_FETCH_WIDTH_DISABLE | HID0_CACHE_FUSION_DISABLE);
|
2021-01-27 17:38:30 +00:00
|
|
|
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_set(SYS_IMP_APL_HID7, HID7_FORCE_NONSPEC_IF_STEPPING |
|
|
|
|
HID7_FORCE_NONSPEC_IF_SPEC_FLUSH_POINTER_INVALID_AND_MP_VALID);
|
2021-01-27 17:38:30 +00:00
|
|
|
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_mask(SYS_IMP_APL_HID7, HID7_FORCE_NONSPEC_TARGET_TIMER_SEL_MASK,
|
2021-01-27 17:38:30 +00:00
|
|
|
HID7_FORCE_NONSPEC_TARGET_TIMER_SEL(3));
|
|
|
|
|
2021-11-10 15:48:50 +00:00
|
|
|
reg_set(SYS_IMP_APL_HID9, HID9_TSO_SERIALIZE_VLD_MICROOPS | HID9_FIX_BUG_51667805);
|
2021-01-27 17:38:30 +00:00
|
|
|
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_set(SYS_IMP_APL_HID18, HID18_HVC_SPECULATION_DISABLE);
|
2021-01-27 17:38:30 +00:00
|
|
|
|
2021-11-10 15:48:50 +00:00
|
|
|
reg_clr(SYS_IMP_APL_HID21, HID21_ENABLE_LDREX_FILL_REPLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_t8103_firestorm(int rev)
|
|
|
|
{
|
|
|
|
init_m1_firestorm();
|
|
|
|
|
|
|
|
reg_mask(SYS_IMP_APL_HID6, HID6_UP_CRD_TKN_INIT_C2_MASK, HID6_UP_CRD_TKN_INIT_C2(0));
|
|
|
|
|
|
|
|
if (rev >= 0x10) {
|
|
|
|
reg_set(SYS_IMP_APL_HID4,
|
|
|
|
HID4_ENABLE_LFSR_STALL_LOAD_PIPE_2_ISSUE | HID4_ENABLE_LFSR_STALL_STQ_REPLAY);
|
|
|
|
|
|
|
|
reg_set(SYS_IMP_APL_HID9, HID9_FIX_BUG_55719865);
|
|
|
|
reg_set(SYS_IMP_APL_HID11, HID11_ENABLE_FIX_UC_55719865);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rev == 0x11)
|
|
|
|
reg_set(SYS_IMP_APL_HID1, HID1_ENABLE_MDSB_STALL_PIPELINE_ECO | HID1_ENABLE_BR_KILL_LIMIT);
|
|
|
|
|
2021-11-01 04:41:12 +00:00
|
|
|
if (rev >= 0x11)
|
|
|
|
reg_set(SYS_IMP_APL_HID18, HID18_SPAREBIT17);
|
2021-11-10 15:48:50 +00:00
|
|
|
}
|
2021-11-01 04:41:12 +00:00
|
|
|
|
2021-11-10 15:48:50 +00:00
|
|
|
static void init_t6000_firestorm(int rev)
|
|
|
|
{
|
|
|
|
init_m1_firestorm();
|
|
|
|
|
|
|
|
reg_set(SYS_IMP_APL_HID9, HID9_FIX_BUG_55719865);
|
|
|
|
reg_set(SYS_IMP_APL_HID11, HID11_ENABLE_FIX_UC_55719865);
|
|
|
|
|
|
|
|
if (rev >= 0x10) {
|
|
|
|
reg_set(SYS_IMP_APL_HID1, HID1_ENABLE_MDSB_STALL_PIPELINE_ECO | HID1_ENABLE_BR_KILL_LIMIT);
|
|
|
|
|
|
|
|
reg_set(SYS_IMP_APL_HID4,
|
|
|
|
HID4_ENABLE_LFSR_STALL_LOAD_PIPE_2_ISSUE | HID4_ENABLE_LFSR_STALL_STQ_REPLAY);
|
2021-01-25 10:08:59 +00:00
|
|
|
|
2021-11-10 15:48:50 +00:00
|
|
|
reg_set(SYS_IMP_APL_HID18, HID18_SPAREBIT17);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_t6001_firestorm(int rev)
|
|
|
|
{
|
|
|
|
init_m1_firestorm();
|
|
|
|
|
|
|
|
reg_set(SYS_IMP_APL_HID1, HID1_ENABLE_MDSB_STALL_PIPELINE_ECO);
|
|
|
|
|
|
|
|
reg_set(SYS_IMP_APL_HID4,
|
|
|
|
HID4_ENABLE_LFSR_STALL_LOAD_PIPE_2_ISSUE | HID4_ENABLE_LFSR_STALL_STQ_REPLAY);
|
|
|
|
|
|
|
|
reg_set(SYS_IMP_APL_HID9, HID9_FIX_BUG_55719865);
|
|
|
|
|
|
|
|
reg_set(SYS_IMP_APL_HID11, HID11_ENABLE_FIX_UC_55719865);
|
|
|
|
|
|
|
|
if (rev >= 0x10) {
|
|
|
|
reg_set(SYS_IMP_APL_HID1, HID1_ENABLE_BR_KILL_LIMIT);
|
|
|
|
|
|
|
|
reg_set(SYS_IMP_APL_HID18, HID18_SPAREBIT17);
|
|
|
|
}
|
2021-01-25 10:08:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *init_cpu(void)
|
|
|
|
{
|
|
|
|
const char *cpu = "Unknown";
|
|
|
|
|
|
|
|
msr(OSLAR_EL1, 0);
|
|
|
|
|
|
|
|
/* This is performed unconditionally on all cores (necessary?) */
|
2021-01-30 06:12:23 +00:00
|
|
|
if (is_ecore())
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_set(SYS_IMP_APL_EHID4, HID4_DISABLE_DC_MVA | HID4_DISABLE_DC_SW_L2_OPS);
|
2021-01-25 10:08:59 +00:00
|
|
|
else
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_set(SYS_IMP_APL_HID4, HID4_DISABLE_DC_MVA | HID4_DISABLE_DC_SW_L2_OPS);
|
2021-01-25 10:08:59 +00:00
|
|
|
|
2021-11-01 04:41:12 +00:00
|
|
|
uint64_t midr = mrs(MIDR_EL1);
|
|
|
|
int part = FIELD_GET(MIDR_PART, midr);
|
|
|
|
int rev = (FIELD_GET(MIDR_REV_HIGH, midr) << 4) | FIELD_GET(MIDR_REV_LOW, midr);
|
|
|
|
|
|
|
|
printf(" CPU part: 0x%x rev: 0x%x\n", part, rev);
|
2021-01-25 10:08:59 +00:00
|
|
|
|
|
|
|
switch (part) {
|
2021-11-01 09:56:49 +00:00
|
|
|
case MIDR_PART_T8103_FIRESTORM:
|
2021-11-10 15:48:50 +00:00
|
|
|
cpu = "M1 Firestorm";
|
|
|
|
init_t8103_firestorm(rev);
|
|
|
|
break;
|
|
|
|
|
2021-11-01 09:56:49 +00:00
|
|
|
case MIDR_PART_T6000_FIRESTORM:
|
2021-11-10 15:48:50 +00:00
|
|
|
cpu = "M1 Pro Firestorm";
|
|
|
|
init_t6000_firestorm(rev);
|
|
|
|
break;
|
|
|
|
|
2021-11-01 09:56:49 +00:00
|
|
|
case MIDR_PART_T6001_FIRESTORM:
|
2021-11-10 15:48:50 +00:00
|
|
|
cpu = "M1 Max Firestorm";
|
|
|
|
init_t6001_firestorm(rev);
|
2021-01-25 10:08:59 +00:00
|
|
|
break;
|
|
|
|
|
2021-11-01 09:56:49 +00:00
|
|
|
case MIDR_PART_T8103_ICESTORM:
|
2021-01-25 10:08:59 +00:00
|
|
|
cpu = "M1 Icestorm";
|
2021-11-10 15:48:50 +00:00
|
|
|
init_m1_icestorm();
|
2021-01-25 10:08:59 +00:00
|
|
|
break;
|
|
|
|
|
2021-11-01 09:56:49 +00:00
|
|
|
case MIDR_PART_T6000_ICESTORM:
|
|
|
|
cpu = "M1 Pro Icestorm";
|
2021-11-10 15:48:50 +00:00
|
|
|
init_m1_icestorm();
|
2021-11-01 09:56:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MIDR_PART_T6001_ICESTORM:
|
|
|
|
cpu = "M1 Max Icestorm";
|
2021-11-10 15:48:50 +00:00
|
|
|
init_m1_icestorm();
|
2021-11-01 09:56:49 +00:00
|
|
|
break;
|
|
|
|
|
2021-01-25 10:08:59 +00:00
|
|
|
default:
|
2021-11-01 04:41:12 +00:00
|
|
|
uart_puts(" Unknown CPU type");
|
2021-01-25 10:08:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-10 15:48:50 +00:00
|
|
|
int core = mrs(MPIDR_EL1) & 0xff;
|
|
|
|
|
|
|
|
// Unknown, related to SMP?
|
|
|
|
msr(s3_4_c15_c5_0, core);
|
|
|
|
msr(SYS_IMP_APL_AMX_CTL_EL1, 0x100);
|
|
|
|
|
|
|
|
// Enable IRQs (at least necessary on t600x)
|
|
|
|
msr(s3_4_c15_c10_4, 0);
|
|
|
|
|
|
|
|
sysop("isb");
|
|
|
|
|
2021-02-04 16:08:35 +00:00
|
|
|
/* Unmask external IRQs, set WFI mode to up (2) */
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_mask(SYS_IMP_APL_CYC_OVRD,
|
2021-02-13 18:28:30 +00:00
|
|
|
CYC_OVRD_FIQ_MODE_MASK | CYC_OVRD_IRQ_MODE_MASK | CYC_OVRD_WFI_MODE_MASK,
|
2021-02-04 16:08:35 +00:00
|
|
|
CYC_OVRD_FIQ_MODE(0) | CYC_OVRD_IRQ_MODE(0) | CYC_OVRD_WFI_MODE(2));
|
2021-01-25 10:08:59 +00:00
|
|
|
|
|
|
|
/* Enable branch prediction state retention across ACC sleep */
|
2021-04-29 06:45:44 +00:00
|
|
|
reg_mask(SYS_IMP_APL_ACC_CFG, ACC_CFG_BP_SLEEP_MASK, ACC_CFG_BP_SLEEP(3));
|
2021-01-25 10:08:59 +00:00
|
|
|
|
|
|
|
return cpu;
|
|
|
|
}
|