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
9 changes: 8 additions & 1 deletion drivers/gpu/drm/apple/j613_dcp_activate.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ bool apple_t8122_25g83_board(void)
return ok;
}

/* Match the PMGR provider: automatic domains can be clock-gated while active. */
static bool j613_power_state_active(u32 state)
{
return FIELD_GET(GENMASK(7, 4), state) == 15 ||
((state & BIT(28)) && FIELD_GET(GENMASK(3, 0), state) == 15);
}

/* These are DT domain nodes, carrying the PMGR offsets, not copied registers. */
static int j613_power_ready(void)
{
Expand Down Expand Up @@ -82,7 +89,7 @@ static int j613_power_ready(void)
return -ENOMEM;
state = readl(pmgr + offset);
iounmap(pmgr);
if (FIELD_GET(GENMASK(7, 4), state) != 15)
if (!j613_power_state_active(state))
return -EBUSY;
}
return 0;
Expand Down
3 changes: 2 additions & 1 deletion tools/asahi/run-host-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def mutations(flag, names, base, expect=KILL):
# The old revision reports a DART fault that clears before the second latch read as success.
'ane-tm-transient-fault-tests.py': [([], PASS),
(['--old-ref', 'b50066848322c6799c1433ee3a358aab2e9faabb'], PASS)],
'test-j613-dcp-power.py': [([], PASS)],
'aop-als-channel-tests.py': [([], PASS)],
'aop-bootargs-tests.py': [([], PASS)],
'mtp-pm-tests.py': [(out(), PASS),
Expand Down Expand Up @@ -194,7 +195,7 @@ def jobs(work, conf, dtc):
if re.search(r'-tests\.(py|rs|sh)$', p.name) and p.name != Path(__file__).name}
known = set(ASAHI_TESTS) | set(ASAHI_RUST) | set(ASAHI_SHELL)
missing = sorted(found - known)
gone = sorted(known - found)
gone = sorted(name for name in known if not (ASAHI / name).is_file())
if missing or gone:
for name in missing:
print(f'not registered in {Path(__file__).name}: tools/asahi/{name}', file=sys.stderr)
Expand Down
57 changes: 57 additions & 0 deletions tools/asahi/test-j613-dcp-power.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only OR MIT
"""Compile the production J613 PMGR predicate and test PMGR fields and unrelated bits."""
from pathlib import Path
import os
import subprocess
import tempfile

root = Path(__file__).resolve().parents[2]
source = (root / "drivers/gpu/drm/apple/j613_dcp_activate.c").read_text()
start = source.index("static bool j613_power_state_active(")
end = source.index("\n}\n", start) + 3
stub = r"""
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
typedef uint32_t u32;
#define BIT(n) (1U << (n))
#define GENMASK(a,b) (((1U << ((a)-(b)+1))-1) << (b))
#define FIELD_GET(mask,v) (((v) & (mask)) >> __builtin_ctz(mask))
"""
main = r"""
int main(void) {
/* Only ACTUAL[7:4], TARGET[3:0] and AUTO_ENABLE[28] affect readiness. */
const u32 unrelated_mask = ~(GENMASK(7, 0) | BIT(28));
u32 unrelated[32] = {0, unrelated_mask,
0xaaaaaaaaU & unrelated_mask,
0x55555555U & unrelated_mask};
unsigned int count = 4;
for (unsigned int bit = 8; bit < 32; bit++)
if (bit != 28) unrelated[count++] = BIT(bit);
for (unsigned int i = 0; i < count; i++)
for (u32 actual = 0; actual < 16; actual++)
for (u32 target = 0; target < 16; target++)
for (u32 automatic = 0; automatic < 2; automatic++) {
u32 word = unrelated[i] | (actual << 4) | target | (automatic << 28);
bool expected = actual == 15 || (target == 15 && automatic);
if (j613_power_state_active(word) != expected) {
fprintf(stderr, "PMGR state 0x%08x: expected active=%d\n", word, expected);
return 1;
}
}
if (!j613_power_state_active(0x1404024f)) return 2;
if (j613_power_state_active(0x0404024f)) return 3;
if (j613_power_state_active(0x14040240)) return 4;
puts("PASS: 13824 PMGR combinations and captured-state regression controls");
return 0;
}
"""
with tempfile.TemporaryDirectory() as temporary:
path = Path(temporary) / "power.c"
path.write_text(stub + source[start:end] + main)
for flags in (["-O0"], ["-O2"]):
exe = str(path.with_suffix(""))
subprocess.run([os.environ.get("CC", "cc"), "-Wall", "-Wextra", "-Werror",
*flags, str(path), "-o", exe], check=True)
subprocess.run([exe], check=True)