diff --git a/src/cpufreq.c b/src/cpufreq.c index ed541939..9db338b2 100644 --- a/src/cpufreq.c +++ b/src/cpufreq.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#include - #include "cpufreq.h" #include "adt.h" #include "firmware.h" @@ -9,9 +7,8 @@ #include "soc.h" #include "utils.h" -#define CLUSTER_PSTATE 0x20020 -#define CLUSTER_PSTATE_STATUS 0x20050 -#define CLUSTER_CPM 0x40000 +#define CLUSTER_PSTATE 0x20020 +#define CLUSTER_CPM 0x40000 #define CLUSTER_PSTATE_FIXED_FREQ_PLL_RECLOCK BIT(42) #define CLUSTER_PSTATE_BUSY BIT(31) @@ -25,9 +22,6 @@ #define CLUSTER_PSTATE_DESIRED1 GENMASK(4, 0) #define CLUSTER_PSTATE_DESIRED1_S5L8960X GENMASK(24, 22) -#define CLUSTER_PSTATE_STATUS_CURRENT_T8132 GENMASK(9, 5) -#define CLUSTER_PSTATE_STATUS_TARGET_T8132 GENMASK(4, 0) - #define PMGR_VOLTAGE_CTL_OFF_S5L8960X 0x20c00 #define PMGR_VOLTAGE_CTL_OFF_T7000 0x23000 #define PMGR_VOLTAGE_CTL_OFF_S8000 0xa0000 @@ -85,49 +79,8 @@ static u32 pstate_reg_to_pstate(u64 val) } } -static int set_pstate_t8132(const struct cluster_t *cluster, uint32_t pstate) -{ - u64 command = cluster->base + CLUSTER_PSTATE; - u64 status = cluster->base + CLUSTER_PSTATE_STATUS; - u64 value; - - /* - * T8132 uses Linux apple-soc-cpufreq's T8112 layout: DVFS +0x20 is - * the 64-bit command, +0x50 is 32-bit status. Wait for command bit 31 - * BEFORE submitting a request; current status need not reach the request. - */ - printf("cpufreq: T8132 %s request P%u: poll64 @0x%lx bit31=0 before write " - "(2us, %uus); status32 @0x%lx\n", - cluster->name, pstate, command, CLUSTER_SWITCH_TIMEOUT, status); - for (u32 elapsed = 0;; elapsed += 2) { - value = read64(command); - if (!(value & CLUSTER_PSTATE_BUSY)) - break; - if (elapsed == CLUSTER_SWITCH_TIMEOUT) { - printf("cpufreq: T8132 %s command busy timeout @0x%lx\n", cluster->name, command); - return -1; - } - udelay(2); - } - - value &= ~CLUSTER_PSTATE_DESIRED1; - value |= CLUSTER_PSTATE_SET | FIELD_PREP(CLUSTER_PSTATE_DESIRED1, pstate); - printf("cpufreq: T8132 %s write command @0x%lx = 0x%lx\n", cluster->name, command, value); - write64(command, value); - - /* Observe once; Linux does not wait for actual frequency after the write. */ - u32 observed = read32(status); - printf("cpufreq: T8132 %s status32 @0x%lx = 0x%x (current P%u target P%u)\n", cluster->name, - status, observed, (u32)FIELD_GET(CLUSTER_PSTATE_STATUS_CURRENT_T8132, observed), - (u32)FIELD_GET(CLUSTER_PSTATE_STATUS_TARGET_T8132, observed)); - return 0; -} - static int set_pstate(const struct cluster_t *cluster, uint32_t pstate) { - if (chip_id == T8132) - return set_pstate_t8132(cluster, pstate); - u64 val = read64(cluster->base + CLUSTER_PSTATE); if (pstate_reg_to_pstate(val) != pstate) { @@ -160,6 +113,7 @@ static int set_pstate(const struct cluster_t *cluster, uint32_t pstate) case T6031: case T6034: case T8122: + case T8132: val &= ~CLUSTER_PSTATE_DESIRED1; val |= CLUSTER_PSTATE_SET | FIELD_PREP(CLUSTER_PSTATE_DESIRED1, pstate); break; @@ -191,20 +145,9 @@ int cpufreq_init_cluster(const struct cluster_t *cluster, const struct feat_t *f if (features->pcluster_only && !cluster->pcluster) continue; - u32 enabled = pmgr_get_feature(features->name); - /* Disabled T8132 throttle gates can fault even on a diagnostic read. */ - if (chip_id == T8132 && !enabled && - (!strcmp(features->name, "ppt-thrtl") || !strcmp(features->name, "llc-thrtl") || - !strcmp(features->name, "amx-thrtl"))) { - printf("cpufreq: T8132 %s %s=0 skipped (ADT disabled; no MMIO)\n", cluster->name, - features->name); - continue; - } - u64 reg = cluster->base + features->offset; - u64 before = chip_id == T8132 ? read64(reg) : 0; - if (enabled) + if (pmgr_get_feature(features->name)) mask64(reg, features->clear, features->set); else mask64(reg, features->set, features->clear); @@ -214,19 +157,6 @@ int cpufreq_init_cluster(const struct cluster_t *cluster, const struct feat_t *f cluster->name); return -1; } - - if (chip_id == T8132) { - u64 after = read64(reg); - u64 mask = features->clear | features->set; - u64 expected = enabled ? features->set : features->clear; - - printf("cpufreq: T8132 %s %s=%u @0x%lx: 0x%lx -> 0x%lx\n", cluster->name, - features->name, enabled, reg, before, after); - if ((after & mask) != expected) { - printf("cpufreq: T8132 %s feature readback mismatch\n", cluster->name); - return -1; - } - } } int pmgr_path[8]; @@ -285,7 +215,7 @@ int cpufreq_init_cluster(const struct cluster_t *cluster, const struct feat_t *f write64(cluster->base + 0x440f8, 1); break; case T8132: - /* No ADT feature justifies the older SoCs' unknown +0x440f8 write. */ + /* Write to 0x440f8 serrors in raw boot mode */ break; default: printf("cpufreq: Chip 0x%x is unsupported\n", chip_id); @@ -313,10 +243,6 @@ int cpufreq_init_cluster(const struct cluster_t *cluster, const struct feat_t *f if (cluster->default_pstate && set_pstate(cluster, cluster->default_pstate)) return -1; - if (chip_id == T8132) - printf("cpufreq: T8132 %s initialized, base=0x%lx command=0x%lx\n", cluster->name, - cluster->base, read64(cluster->base + CLUSTER_PSTATE)); - return 0; } @@ -452,7 +378,7 @@ static const struct cluster_t t6030_clusters[] = { {}, }; -/* The boot states follow T6030; both J713 and J773g have these ADT OPPs. */ +/* Read bases from ADT */ static struct cluster_t t8132_clusters[] = { {"ECPU0", 0, false, 1, 5}, {"PCPU0", 0, true, 1, 6}, @@ -635,19 +561,8 @@ static const struct feat_t t6030_features[] = { {}, }; -/* - * T6030's CPU-complex layout is the template for T8132. J713/J773g advertise - * cpu-apsc, unlike the T8122 template, so retain the M2/M3 APSC enable handling. - * Access throttle gates only when ADT-enabled: disabled P-cluster PPT access - * faults on J713, even though the corresponding E-cluster access completes. - * This does not establish the M4 firmware's thermal thresholds or alarm action. - */ static const struct feat_t t8132_features[] = { {"cpu-apsc", CLUSTER_PSTATE, CLUSTER_PSTATE_M2_APSC_DIS, 0, CLUSTER_PSTATE_APSC_BUSY, false}, - {"ppt-thrtl", 0x48400, 0, BIT(63), 0, false}, - {"ppt-thrtl", 0x48408, 0, BIT(63), 0, false}, - {"llc-thrtl", 0x40270, 0, BIT(63), 0, false}, - {"amx-thrtl", 0x40250, 0, BIT(63), 0, false}, {"cpu-fixed-freq-pll-relock", CLUSTER_PSTATE, 0, CLUSTER_PSTATE_FIXED_FREQ_PLL_RECLOCK, 0, false}, {}, @@ -714,9 +629,6 @@ int cpufreq_init(void) err |= cpufreq_init_cluster(cluster++, features); } - if (chip_id == T8132) - printf("cpufreq: T8132 initialization %s\n", err ? "FAILED" : "complete"); - return err ? -1 : 0; } diff --git a/src/mcc.c b/src/mcc.c index b7939108..fe91ff93 100644 --- a/src/mcc.c +++ b/src/mcc.c @@ -456,30 +456,15 @@ int mcc_init_m3(int node, int *path) { u32 reg_len; u32 reg_offset = 3; - bool t8132 = adt_is_compatible(adt, node, "mcc,t8132"); if (!adt_getprop(adt, node, "reg", ®_len)) { printf("MCC: Failed to get reg property!\n"); return -1; } - if (t8132) { - u32 count; - - /* T8132 places SOCNI before the AMCC apertures and PMP/MCW after them. */ - if (ADT_GETPROP(adt, node, "amcc_aperture_reg_idx", ®_offset) < 0 || - ADT_GETPROP(adt, node, "amcc_aperture_count", &count) < 0 || !count || - reg_len % 16 || reg_offset >= reg_len / 16 || count > reg_len / 16 - reg_offset) { - printf("MCC: Invalid T8132 AMCC aperture layout!\n"); - return -1; - } - - mcc_count = count; - } else { - mcc_count = reg_len / 16 - reg_offset; - } + mcc_count = reg_len / 16 - reg_offset; - printf("MCC: Initializing M3/M4 MCCs (%d instances)...\n", mcc_count); + printf("MCC: Initializing M3* MCCs (%d instances)...\n", mcc_count); if (mcc_count > MAX_MCC_INSTANCES) { printf("MCC: Too many instances, increase MAX_MCC_INSTANCES!\n"); @@ -489,12 +474,12 @@ int mcc_init_m3(int node, int *path) u32 plane_count = 0; u32 dcs_count = 0; - if (ADT_GETPROP(adt, node, "dcs-count-per-amcc", &dcs_count) < 0 || !dcs_count) { + 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) < 0 || !plane_count) { + if (!ADT_GETPROP(adt, node, "plane-count-per-amcc", &plane_count)) { printf("MCC: Failed to get plane count!\n"); return -1; } @@ -502,9 +487,6 @@ int mcc_init_m3(int node, int *path) int ret = -1; if (adt_is_compatible(adt, node, "mcc,t8122")) ret = mcc_init_t8122(path, reg_offset, plane_count, dcs_count, &t8122_tz_regs); - else if (t8132) - /* T8132's iBoot TZ bounds match the ADT carveouts with the T6030 layout. */ - ret = mcc_init_t8122(path, reg_offset, plane_count, dcs_count, &t6030_tz_regs); else if (adt_is_compatible(adt, node, "mcc,t6030")) ret = mcc_init_t8122(path, reg_offset, plane_count, dcs_count, &t6030_tz_regs); else if (adt_is_compatible(adt, node, "mcc,t6031")) @@ -515,7 +497,62 @@ int mcc_init_m3(int node, int *path) if (ret) return ret; - printf("MCC: Initialized M3/M4 MCCs (%d instances, %d planes, %d channels)\n", mcc_count, + printf("MCC: Initialized M3* 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_m4(int node, int *path) +{ + u64 amcc_count = 0; + u32 count_len; + const void *count = adt_getprop(adt, node, "amcc_aperture_count", &count_len); + if (!count) + count = adt_getprop(adt, node, "amcc-count", &count_len); + if (!count || (count_len != sizeof(u32) && count_len != sizeof(u64))) { + printf("MCC: Failed to get mcc count!\n"); + return -1; + } + /* T8132 uses a 32-bit aperture count; other M4 ADTs use a 64-bit count. */ + memcpy(&amcc_count, count, count_len); + + if (amcc_count > MAX_MCC_INSTANCES) { + printf("MCC: Too many instances, increase MAX_MCC_INSTANCES!\n"); + mcc_count = MAX_MCC_INSTANCES; + } else { + mcc_count = amcc_count; + } + + u32 plane_count = 0; + u32 dcs_count = 0; + + if (ADT_GETPROP(adt, node, "dcs-count-per-amcc", &dcs_count) != sizeof(dcs_count)) { + printf("MCC: Failed to get dcs count!\n"); + return -1; + } + + if (ADT_GETPROP(adt, node, "plane-count-per-amcc", &plane_count) != sizeof(plane_count)) { + printf("MCC: Failed to get plane count!\n"); + return -1; + } + + printf("MCC: Initializing T%x MCCs (%d instances)...\n", chip_id, mcc_count); + + int ret = -1; + if (adt_is_compatible(adt, node, "mcc,t8132")) { + int reg_offset = 7; + ret = mcc_init_t8122(path, reg_offset, plane_count, dcs_count, &t6030_tz_regs); + } else { + printf("MCC: Unsupported version:%s\n", adt_get_property(adt, node, "compatible")->value); + } + + if (ret) + return ret; + + printf("MCC: Initialized T%x MCCs (%d instances, %d planes, %d channels)\n", chip_id, mcc_count, mcc_regs[0].plane_count, mcc_regs[0].dcs_count); mcc_initialized = true; @@ -609,7 +646,7 @@ int mcc_init(void) } else if (adt_is_compatible(adt, node, "mcc,t8122")) { return mcc_init_m3(node, path); } else if (adt_is_compatible(adt, node, "mcc,t8132")) { - return mcc_init_m3(node, path); + return mcc_init_m4(node, path); } else if (adt_is_compatible(adt, node, "mcc,t6030")) { return mcc_init_m3(node, path); } else if (adt_is_compatible(adt, node, "mcc,t6031")) { diff --git a/tests/host/test_cpufreq.c b/tests/host/test_cpufreq.c deleted file mode 100644 index 4624c389..00000000 --- a/tests/host/test_cpufreq.c +++ /dev/null @@ -1,403 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* Host-only MMIO/ADT model: cc -Wall -Wextra tests/host/test_cpufreq.c -o /tmp/test-cpufreq */ -#include -#include -#include - -#include "../../src/adt.h" -#include "../../src/types.h" - -/* Compile the production path, substituting only platform I/O. */ -#define UTILS_H -u32 chip_id; -static u64 read64(u64 addr); -static u32 read32(u64 addr); -static void udelay(u32 usec); -static void write64(u64 addr, u64 value); -static void write32(u64 addr, u32 value); -static u64 mask64(u64 addr, u64 clear, u64 set); -static u64 set64(u64 addr, u64 set); -static int poll32(u64 addr, u32 mask, u32 target, u32 timeout); -static int poll64(u64 addr, u64 mask, u64 target, u32 timeout); -#include "../../src/cpufreq.c" - -void *adt; -struct fw_version_info os_firmware; -static struct { - u32 id; - char type[2]; - u64 cpm[2]; -} cpus[10]; -static u32 cluster_count, child_count, ppt_throttle, llc_throttle, amx_throttle; -static unsigned int gate_accesses[2][4]; -static const u64 gate_offsets[] = {0x40250, 0x40270, 0x48400, 0x48408}; -static int missing_node; -static const char *missing_property; -static bool timeout_poll, drop_feature_write; -static bool command_stuck; -static unsigned int command_busy_reads[2]; -enum access_type { READ64, READ32, WRITE64, DELAY }; -static struct { - enum access_type type; - u64 addr, value; -} accesses[4096]; -static unsigned int naccesses; -static struct { - u64 addr, value; -} regs[64]; -static unsigned int nregs, writes; - -static void record(enum access_type type, u64 addr, u64 value) -{ - assert(naccesses < 4096); - accesses[naccesses].type = type; - accesses[naccesses].addr = addr; - accesses[naccesses++].value = value; -} - -static u64 *reg(u64 addr) -{ - for (unsigned int i = 0; i < nregs; i++) - if (regs[i].addr == addr) - return ®s[i].value; - assert(nregs < 64); - regs[nregs].addr = addr; - regs[nregs].value = 0; - return ®s[nregs++].value; -} - -static void check_access(u64 addr) -{ - if (chip_id != T8132) - return; - - unsigned int cluster = addr >= 0x211e00000; - u64 base = cluster ? 0x211e00000 : 0x210e00000; - assert(addr != base + 0x440f8 && "unexplained T8132 CPM register accessed"); - u32 enabled[] = {amx_throttle, llc_throttle, ppt_throttle, ppt_throttle}; - for (unsigned int i = 0; i < 4; i++) { - if (addr != base + gate_offsets[i]) - continue; - /* This includes diagnostic reads, read/modify/write and polling. */ - assert(enabled[i] && "disabled T8132 throttle gate accessed"); - gate_accesses[cluster][i]++; - } -} - -static u64 read64(u64 addr) -{ - check_access(addr); - assert(addr != 0x210e20050 && addr != 0x211e20050); - u64 value = *reg(addr); - if (chip_id == T8132 && (addr == 0x210e20020 || addr == 0x211e20020)) { - unsigned int cluster = addr == 0x211e20020; - if (command_stuck || command_busy_reads[cluster]) - value |= BIT(31); - if (command_busy_reads[cluster]) - command_busy_reads[cluster]--; - } - record(READ64, addr, value); - return value; -} -static u32 read32(u64 addr) -{ - assert(addr == 0x210e20050 || addr == 0x211e20050); - record(READ32, addr, (u32)*reg(addr)); - return *reg(addr); -} -static void udelay(u32 usec) -{ - record(DELAY, 0, usec); -} -static void write64(u64 addr, u64 value) -{ - check_access(addr); - /* Independent whitelist: no snooze, LUT, PMP SRAM or voltage writes. */ - u64 base = addr >= 0x211e00000 ? 0x211e00000 : 0x210e00000; - u64 offset = addr - base; - assert(offset == 0x20020 || offset == 0x40250 || offset == 0x40270 || offset == 0x440f8 || - offset == 0x48400 || offset == 0x48408); - record(WRITE64, addr, value); - writes++; - if (!(drop_feature_write && offset == 0x48400)) - *reg(addr) = value; -} -static void write32(u64 addr, u32 value) -{ - write64(addr, value); -} -static u64 mask64(u64 addr, u64 clear, u64 set) -{ - u64 before = read64(addr); - write64(addr, (before & ~clear) | set); - return before; -} -static u64 set64(u64 addr, u64 set) -{ - return mask64(addr, 0, set); -} -static int poll64(u64 addr, u64 mask, u64 target, u32 timeout) -{ - (void)timeout; - return timeout_poll || (read64(addr) & mask) != target ? -1 : 0; -} -static int poll32(u64 addr, u32 mask, u32 target, u32 timeout) -{ - return poll64(addr, mask, target, timeout); -} - -int adt_path_offset(const void *tree, const char *path) -{ - (void)tree; - return !strcmp(path, "/cpus") ? 100 : -1; -} -int adt_path_offset_trace(const void *tree, const char *path, int *offsets) -{ - (void)tree; - (void)path; - offsets[0] = 101; - return 101; -} -int adt_get_child_count(const void *tree, int node) -{ - (void)tree; - assert(node == 100); - return child_count; -} -int adt_first_child_offset(const void *tree, int node) -{ - (void)tree; - assert(node == 100); - return 0; -} -int adt_next_sibling_offset(const void *tree, int node) -{ - (void)tree; - return node + 1; -} -int adt_getprop_copy(const void *tree, int node, const char *key, void *out, size_t len) -{ - (void)tree; - if (node == missing_node && missing_property && !strcmp(key, missing_property)) - return -1; - const void *value = NULL; - size_t size = 0; - if (node == 100 && !strcmp(key, "cpu-cluster-count")) { - value = &cluster_count; - size = sizeof(cluster_count); - } else if (node >= 0 && node < 10) { - if (!strcmp(key, "cluster-id")) { - value = &cpus[node].id; - size = sizeof(cpus[node].id); - } else if (!strcmp(key, "cluster-type")) { - value = cpus[node].type; - size = sizeof(cpus[node].type); - } else if (!strcmp(key, "cpm-impl-reg")) { - value = cpus[node].cpm; - size = sizeof(cpus[node].cpm); - } - } - if (!value || len != size) - return -1; - memcpy(out, value, size); - return size; /* ADT's success is a positive byte count, including cluster ID 0. */ -} -int adt_get_reg(const void *tree, int *path, const char *prop, int idx, u64 *addr, u64 *size) -{ - (void)tree; - (void)path; - (void)prop; - (void)idx; - (void)size; - *addr = 0x380000000; - return 0; -} -u32 pmgr_get_feature(const char *name) -{ - if (!strcmp(name, "cpu-apsc")) - return 1; - if (!strcmp(name, "ppt-thrtl")) - return ppt_throttle; - if (!strcmp(name, "llc-thrtl")) - return llc_throttle; - if (!strcmp(name, "amx-thrtl")) - return amx_throttle; - return 0; -} -int pmgr_power_on(int die, const char *name) -{ - (void)die; - (void)name; - assert(false); - return -1; -} - -static void reset(void) -{ - chip_id = T8132; - nregs = writes = ppt_throttle = llc_throttle = amx_throttle = 0; - naccesses = 0; - command_stuck = false; - memset(command_busy_reads, 0, sizeof(command_busy_reads)); - memset(gate_accesses, 0, sizeof(gate_accesses)); - cluster_count = 2; - child_count = 10; - missing_node = -1; - missing_property = NULL; - timeout_poll = drop_feature_write = false; - /* J713 and J773g captured ADTs both describe 6 E + 4 P, same CPM apertures. */ - for (unsigned int i = 0; i < 10; i++) { - cpus[i].id = i >= 6; - strcpy(cpus[i].type, i >= 6 ? "P" : "E"); - cpus[i].cpm[0] = i >= 6 ? 0x211e40000 : 0x210e40000; - cpus[i].cpm[1] = 0xc010; - } - for (u64 base = 0x210e00000; base <= 0x211e00000; base += 0x1000000) { - *reg(base + 0x20020) = BIT(48) | BIT(42) | BIT(23) | 18; - /* Actual/target deliberately differ from requests; status is not polled. */ - *reg(base + 0x20050) = BIT(31) | (3 << 5) | 7; - for (unsigned int i = 0; i < 4; i++) - *reg(base + gate_offsets[i]) = BIT(63) | 0x12345678; - } -} - -static void reject(void) -{ - assert(cpufreq_init() < 0); - assert(writes == 0); -} - -static void test_t8132_transition(void) -{ - for (unsigned int cluster = 0; cluster < 2; cluster++) { - reset(); - const struct cluster_t *c = &cpufreq_get_clusters()[cluster]; - u64 command = cluster ? 0x211e20020 : 0x210e20020; - u64 status = cluster ? 0x211e20050 : 0x210e20050; - u64 expected = (*reg(command) & ~0x1f) | BIT(25) | 6; - command_busy_reads[cluster] = 2; - assert(set_pstate(c, 6) == 0); - /* Two busy samples, then readiness, one request, one 32-bit observation. */ - assert(naccesses == 7); - for (unsigned int i = 0; i <= 4; i += 2) { - assert(accesses[i].type == READ64 && accesses[i].addr == command); - assert(!!(accesses[i].value & BIT(31)) == (i < 4)); - } - assert(accesses[1].type == DELAY && accesses[1].value == 2); - assert(accesses[3].type == DELAY && accesses[3].value == 2); - assert(accesses[5].type == WRITE64 && accesses[5].addr == command); - assert(accesses[5].value == expected); - assert(accesses[6].type == READ32 && accesses[6].addr == status); - assert(accesses[6].value == (BIT(31) | (3 << 5) | 7)); - assert(writes == 1); - - /* Linux also submits an already-requested state, after checking busy. */ - naccesses = 0; - assert(set_pstate(c, 6) == 0); - assert(naccesses == 3); - assert(accesses[0].type == READ64 && accesses[0].addr == command); - assert(accesses[1].type == WRITE64 && accesses[1].addr == command); - assert(accesses[2].type == READ32 && accesses[2].addr == status); - - reset(); - command_stuck = true; - assert(set_pstate(c, 6) < 0); - assert(writes == 0 && naccesses == 401); - for (unsigned int i = 0; i < naccesses; i++) { - if (i & 1) - assert(accesses[i].type == DELAY && accesses[i].value == 2); - else - assert(accesses[i].type == READ64 && accesses[i].addr == command); - } - } -} - -int main(void) -{ - test_t8132_transition(); - reset(); - assert(cpufreq_init() == 0); - for (u64 base = 0x210e00000; base <= 0x211e00000; base += 0x1000000) { - u64 command = read64(base + 0x20020); - assert(command == (BIT(48) | BIT(25) | (base == 0x210e00000 ? 5 : 6))); - assert(*reg(base + 0x440f8) == 0); - for (unsigned int i = 0; i < 4; i++) { - /* Inspect model storage without simulating a forbidden MMIO read. */ - assert(*reg(base + gate_offsets[i]) == (BIT(63) | 0x12345678)); - assert(gate_accesses[base == 0x211e00000][i] == 0); - } - } - /* Check each gate independently, including all mixed enable combinations. */ - for (unsigned int enabled_mask = 1; enabled_mask < 8; enabled_mask++) { - reset(); - ppt_throttle = !!(enabled_mask & 1); - llc_throttle = !!(enabled_mask & 2); - amx_throttle = !!(enabled_mask & 4); - for (unsigned int cluster = 0; cluster < 2; cluster++) { - u64 base = cluster ? 0x211e00000 : 0x210e00000; - for (unsigned int i = 0; i < 4; i++) - *reg(base + gate_offsets[i]) = 0x12345678; - } - assert(cpufreq_init() == 0); - u32 enabled[] = {amx_throttle, llc_throttle, ppt_throttle, ppt_throttle}; - for (unsigned int cluster = 0; cluster < 2; cluster++) { - u64 base = cluster ? 0x211e00000 : 0x210e00000; - for (unsigned int i = 0; i < 4; i++) { - assert(*reg(base + gate_offsets[i]) == (0x12345678 | (enabled[i] ? BIT(63) : 0))); - assert((gate_accesses[cluster][i] != 0) == !!enabled[i]); - } - } - } - const char *keys[] = {"cluster-id", "cluster-type", "cpm-impl-reg"}; - for (unsigned int i = 0; i < 3; i++) { - reset(); - missing_node = 9; - missing_property = keys[i]; - reject(); - } - reset(); - missing_node = 100; - missing_property = "cpu-cluster-count"; - reject(); - reset(); - cluster_count = 3; - reject(); - reset(); - child_count = 6; - reject(); - reset(); - cpus[9].id = 2; - reject(); - reset(); - cpus[9].type[0] = 'E'; - reject(); - reset(); - cpus[9].cpm[0] += 0x10000; - reject(); - reset(); - cpus[9].cpm[0]++; - reject(); - reset(); - cpus[9].cpm[1] = 0x8408; - reject(); - reset(); - cpus[9].cpm[1] = UINT64_MAX; - reject(); - reset(); - timeout_poll = true; - assert(cpufreq_init() < 0); - reset(); - ppt_throttle = 1; - *reg(0x210e48400) &= ~BIT(63); - *reg(0x211e48400) &= ~BIT(63); - drop_feature_write = true; - assert(cpufreq_init() < 0); - reset(); - chip_id = T8122; - assert(cpufreq_get_clusters() == t6030_clusters); - assert(cpufreq_get_features() == t8122_features); - puts("PASS: T8132 ADT mapping, pre-write command polling, 32-bit status, busy timeout, " - "failure-before-write, register preservation, forbidden CPM access rejection, " - "mixed feature enables, failures, legacy dispatch"); - return 0; -}