Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions drivers/pmdomain/apple/pmp-j613-floor-gov.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,35 @@ static inline bool pmp_floor_drop_confirmed(unsigned long long resp, unsigned lo
*/
/* Firmware identity qualified by the J613 hypervisor and Linux trials. */
#define PMP_FLOOR_J613_UUID "EFD60284-7C58-33A9-8522-CB3366AF6040"
/*
* J615 (15-inch M3 MacBook Air, same SoC, DRAM and PMP tables): the 14.x PMP
* image that Linux starts from a legacy handoff tree. On owner hardware a
* PACC0 DCS 4/SOC 2 store read back from DVFS-STATE as 0x24 within 5.1 ms,
* and the valid floor 0 as 0x0.
*/
#define PMP_FLOOR_J615_UUID "3B18C886-4C70-349B-B1C4-70F35DE2C5CD"

/*
* J615 is admitted only on the path tested on owner hardware, the generic
* T8122 report of a legacy handoff tree whose driver starts the 14.x PMP.
* The native J613 report of the experimental J615 25G83 tree is not covered.
* The parameter may veto the J615 like the J613. A J615 also needs its own
* opt-in until the floor is qualified on that board.
*/
static inline bool pmp_floor_j615_enabled(bool j615, bool native_default,
bool legacy_report, bool allowed,
bool opted_in)
{
return j615 && !native_default && legacy_report && allowed && opted_in;
}

/* J613 runs only on its qualified firmware, J615 only on its 14.x image. */
static inline bool pmp_floor_uuid_ok(const char *uuid, bool j615)
{
if (j615)
return !strcmp(uuid, PMP_FLOOR_J615_UUID);
return !strcmp(uuid, PMP_FLOOR_J613_UUID);
}
#define PMP_FLOOR_REC_SIZE 0x7c /* soc-device record */
#define PMP_FLOOR_REC_NAME 0x74 /* its 8-byte, NUL-padded name */
#define PMP_FLOOR_RANGE_SIZE 32 /* ptd-range record: id, base, count, name at 16 */
Expand Down
70 changes: 61 additions & 9 deletions drivers/pmdomain/apple/pmp-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,14 @@ EXPORT_SYMBOL_GPL(apple_pmp_report_wait_ready);
static bool j613_floor = true;
module_param(j613_floor, bool, 0444);
MODULE_PARM_DESC(j613_floor, "J613: own the CPU memory-floor request and run its governor (default: on for the native J613 report; 0 disables)");
/*
* J615 legacy handoff trees: off until the floor is qualified on that board
* (disable and re-enable, boot veto, suspend, policy teardown, sustained
* power). j613_floor=0 still vetoes it.
*/
static bool j615_floor;
module_param(j615_floor, bool, 0444);
MODULE_PARM_DESC(j615_floor, "J615: run the memory floor on a legacy handoff tree (default: off; j613_floor=0 still vetoes it)");
static unsigned int j613_floor_dcs = 4;
module_param(j613_floor_dcs, uint, 0444);
/* Fabric 2: 4-thread CPU copy 67 -> 92 GB/s, GPU copy 62 -> 76 GB/s over fabric 0. */
Expand Down Expand Up @@ -2143,29 +2151,68 @@ static void j613_floor_put_pmp(void *pmp)
of_node_put(pmp);
}

/*
* J615: the J613's SoC, DRAM, PMP tables and PACC0 layout. It is admitted
* only on the generic T8122 report of a legacy handoff tree, whose driver
* starts the 14.x PMP and names it with apple,pmp. The native J613 report of
* the experimental J615 25G83 tree is not covered. A refused J615 identity
* leaves the floor off and the report probing.
*/
static bool j615_floor_eligible(const struct apple_pmp_report *rep)
{
return pmp_floor_j615_enabled(of_machine_is_compatible("apple,j615"),
rep->offsets->j613_floor_default,
of_device_is_compatible(rep->dev->of_node,
"apple,t8122-pmp-v2-report"),
j613_floor, j615_floor);
}

/* The PMP names this report; a J615 legacy report names its PMP instead. */
static bool j613_floor_linked(struct device_node *pmp, struct device_node *report,
bool j615)
{
struct device_node *link;
bool linked;

if (j615) {
link = of_parse_phandle(report, "apple,pmp", 0);
linked = link == pmp;
} else {
link = of_parse_phandle(pmp, "apple,pmp-report", 0);
linked = link == report;
}
of_node_put(link);
return linked;
}

static int j613_floor_probe(struct apple_pmp_report *rep)
{
struct device *dev = rep->dev;
struct j613_floor *f;
struct device_node *pmp, *link;
struct device_node *pmp;
const char *uuid;
unsigned long flags;
bool j615 = j615_floor_eligible(rep);
int ret;

if (!pmp_floor_enabled(of_machine_is_compatible("apple,j613"),
rep->offsets->j613_floor_default, j613_floor))
rep->offsets->j613_floor_default, j613_floor) && !j615)
return 0;
f = devm_kzalloc(dev, sizeof(*f), GFP_KERNEL);
if (!f)
return -ENOMEM;
/* Native PMP startup remains owned by its existing supplier driver. */
/*
* Native PMP startup remains owned by its existing supplier driver; on a
* J615 legacy tree this report's driver starts the PMP. That PMP is still
* disabled here: apple_pmp_start_init() takes it over after this probe and
* enables it once the display asks, and the floor's start work waits for
* the report to read READY before it writes anything.
*/
for_each_compatible_node(pmp, NULL, "apple,t8122-pmp-v2") {
link = of_parse_phandle(pmp, "apple,pmp-report", 0);
if (link != dev->of_node || !of_device_is_available(pmp)) {
of_node_put(link);
if (!j613_floor_linked(pmp, dev->of_node, j615))
continue;
if (!of_device_is_available(pmp) && !(j615 && rep->offsets->starts_pmp))
continue;
}
of_node_put(link);
if (f->pmp) {
of_node_put(pmp);
return -EINVAL;
Expand All @@ -2178,8 +2225,13 @@ static int j613_floor_probe(struct apple_pmp_report *rep)
}
}
if (!f->pmp || of_property_read_string(f->pmp, "apple,tunable-uuid", &uuid) ||
strcmp(uuid, PMP_FLOOR_J613_UUID))
!pmp_floor_uuid_ok(uuid, j615)) {
if (j615) {
dev_warn(dev, "J615 floor PMP identity refused; floor off\n");
return 0;
}
return dev_err_probe(dev, -EINVAL, "J613 floor PMP identity refused\n");
}
f->cpu_idle = devm_kcalloc(dev, nr_cpu_ids, sizeof(u64), GFP_KERNEL);
f->cpu_wall = devm_kcalloc(dev, nr_cpu_ids, sizeof(u64), GFP_KERNEL);
f->cluster_sum = devm_kcalloc(dev, nr_cpu_ids, sizeof(unsigned int), GFP_KERNEL);
Expand Down
61 changes: 61 additions & 0 deletions tools/asahi/pmp-j613-floor-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@
'no-sum': ('(c->cpu_sum_pct && cluster_sum_pct >= c->cpu_sum_pct)', '(cluster_sum_pct && 0)'),
# Skip the CPU-client name check.
'no-names': ('return "CPU clients EACC0/PACC0 not named once";', '(void)0;'),
# J613 would accept the J615 14.x firmware.
'j613-takes-j615-uuid': ('return !strcmp(uuid, PMP_FLOOR_J613_UUID);',
'return !strcmp(uuid, PMP_FLOOR_J613_UUID) || !strcmp(uuid, PMP_FLOOR_J615_UUID);'),
# J615 would accept any firmware.
'j615-any-uuid': ('return !strcmp(uuid, PMP_FLOOR_J615_UUID);', 'return (void)uuid, true;'),
# J615 would accept the J613 firmware.
'j615-takes-j613-uuid': ('return !strcmp(uuid, PMP_FLOOR_J615_UUID);',
'return !strcmp(uuid, PMP_FLOOR_J615_UUID) || !strcmp(uuid, PMP_FLOOR_J613_UUID);'),
# J615 would be admitted on the native J613 report (the untested 25G83 tree).
'j615-native': ('return j615 && !native_default && legacy_report && allowed && opted_in;',
'return j615 && (native_default || legacy_report) && allowed && opted_in;'),
# The parameter would not veto the J615.
'j615-no-disable': ('return j615 && !native_default && legacy_report && allowed && opted_in;',
'return (void)allowed, j615 && !native_default && legacy_report && opted_in;'),
# The J615 would run the floor without its opt-in.
'j615-no-optin': ('return j615 && !native_default && legacy_report && allowed && opted_in;',
'return (void)opted_in, j615 && !native_default && legacy_report && allowed;'),
}

HARNESS = r'''
Expand Down Expand Up @@ -79,6 +96,21 @@
CHECK(pmp_floor_raise_confirmed(0x3204, 4, 0) && !pmp_floor_raise_confirmed(0x3200, 4, 0));
CHECK(!pmp_floor_raise_confirmed(0x3204, 4, 1) && pmp_floor_raise_confirmed(0x3224, 4, 2));
CHECK(pmp_floor_drop_confirmed(0x3200, 0x3204) && !pmp_floor_drop_confirmed(0x3204, 0x3204));
/* J615 only on the generic report of a legacy tree, never the native one. */
for (unsigned int j615 = 0; j615 <= 1; j615++)
for (unsigned int native = 0; native <= 1; native++)
for (unsigned int legacy = 0; legacy <= 1; legacy++)
for (unsigned int allowed = 0; allowed <= 1; allowed++)
for (unsigned int opt = 0; opt <= 1; opt++)
CHECK(pmp_floor_j615_enabled(j615, native, legacy, allowed, opt) ==
(bool)(j615 && !native && legacy && allowed && opt));
/* J613 runs only on its qualified firmware, J615 only on its 14.x image. */
CHECK(pmp_floor_uuid_ok(PMP_FLOOR_J613_UUID, false) && !pmp_floor_uuid_ok(PMP_FLOOR_J613_UUID, true));
CHECK(!pmp_floor_uuid_ok(PMP_FLOOR_J615_UUID, false) && pmp_floor_uuid_ok(PMP_FLOOR_J615_UUID, true));
CHECK(!pmp_floor_uuid_ok("3b18c886-4c70-349b-b1c4-70f35de2c5cd", true));
CHECK(!pmp_floor_uuid_ok("", false) && !pmp_floor_uuid_ok("", true));
/* Measured on J615 with the 14.x image: 0x24 held (DCS4 SOC2), 0x0 released. */
CHECK(pmp_floor_raise_confirmed(0x24, 4, 2) && pmp_floor_drop_confirmed(0x0, 0x24));
return 0;
}

Expand Down Expand Up @@ -377,6 +409,35 @@ def static_checks():
assert 'pmp_floor_enabled(of_machine_is_compatible("apple,j613"),' in probe
assert 'rep->offsets->j613_floor_default, j613_floor)' in probe
assert 'module_param(j613_floor, bool, 0444);' in floor
# J615: its own board check behind the same parameter veto, admitted only
# on the generic T8122 report of a legacy tree and never on the native
# J613 report of the experimental J615 25G83 tree. J613's gate, link and
# fatal identity refusal are unchanged.
assert '&& !j615)' in probe
j615 = ' '.join(block(floor, 'static bool j615_floor_eligible(').split())
assert ('return pmp_floor_j615_enabled(of_machine_is_compatible("apple,j615"), '
'rep->offsets->j613_floor_default, of_device_is_compatible(rep->dev->of_node, '
'"apple,t8122-pmp-v2-report"), j613_floor, j615_floor);') in j615
# J615 stays opt-in: its parameter defaults to off.
assert re.search(r'^static bool j615_floor;$', floor, re.M)
assert 'module_param(j615_floor, bool, 0444);' in floor
assert floor.count('of_machine_is_compatible("apple,j615")') == 1
assert src.count('pmp_floor_j615_enabled(') == 1
# J613 takes the PMP that names its report, J615 only the PMP its report names.
link = block(floor, 'static bool j613_floor_linked(')
j615_link, j613_link = link[link.index('if (j615) {'):].split('} else {')
assert 'of_parse_phandle(report, "apple,pmp", 0);' in j615_link and 'linked = link == pmp;' in j615_link
assert 'apple,pmp-report' not in j615_link
assert 'of_parse_phandle(pmp, "apple,pmp-report", 0);' in j613_link and 'linked = link == report;' in j613_link
assert 'j613_floor_linked(pmp, dev->of_node, j615)' in probe
# Only a J615 report that starts its own PMP may take it while it is still
# disabled at probe (the legacy tree); every other PMP must be available.
assert 'if (!of_device_is_available(pmp) && !(j615 && rep->offsets->starts_pmp))' in probe
assert probe.count('of_device_is_available(pmp)') == 1
assert '!pmp_floor_uuid_ok(uuid, j615)) {' in probe
refusal = probe[probe.index('!pmp_floor_uuid_ok(uuid, j615)) {'):]
assert refusal.index('if (j615) {') < refusal.index('return 0;') < \
refusal.index('return dev_err_probe(dev, -EINVAL, "J613 floor PMP identity refused\\n");')
print('pmp-j613-floor: static source checks passed')


Expand Down
4 changes: 3 additions & 1 deletion tools/asahi/run-host-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ def mutations(flag, names, base, expect=KILL):
'finish-without-physical', 'poll-after-callback', 'poll-unsupported',
'stale-observation', 'drain-two', 'post-send-wake-refusal'), out()),
'pmp-agx-vote-tests.py': [(out('--output'), PASS), (out('--output') + ['--mutations'], PASS)],
'pmp-j613-floor-tests.py': [([], PASS)] + mutations('--mutant', ['no-hold', 'no-rate', 'no-streak', 'bad-word', 'foreign-ok', 'no-names', 'no-sum', 'no-board', 'no-default', 'no-disable'], []),
'pmp-j613-floor-tests.py': [([], PASS)] + mutations('--mutant', ['no-hold', 'no-rate', 'no-streak', 'bad-word', 'foreign-ok', 'no-names', 'no-sum', 'no-board', 'no-default', 'no-disable',
'j613-takes-j615-uuid', 'j615-any-uuid', 'j615-takes-j613-uuid', 'j615-native',
'j615-no-disable', 'j615-no-optin'], []),
'pmp-j613-hwmon-tests.py': [([], PASS)],
'pmu-rtc-tests.py': [(out(), PASS)]
+ mutations('--mutation', ('ack-clobber', 'arm-ack', 'offset-seconds',
Expand Down