From 2f3055170dc6e643b7351d5ec9b6525ca4c30890 Mon Sep 17 00:00:00 2001 From: Allan Clempe Date: Wed, 2 Dec 2026 23:35:54 +1000 Subject: [PATCH] fix(oms-58): carry PR #2549 CLPC platform-profile fix for no-ACPI kernels Distribution linux-aurora kernels build with # CONFIG_ACPI is not set. Because ACPI_PLATFORM_PROFILE sat inside `if ACPI` in drivers/acpi/Kconfig, drivers/Makefile entered acpi/ only with CONFIG_ACPI, and APPLE_CLPC used `select ACPI_PLATFORM_PROFILE if ACPI`, Kconfig dropped ACPI_PLATFORM_PROFILE and apple_clpc_probe() skipped devm_platform_profile_register(). On the J616c (2.3), apple-clpc binds with apple,high-power-mode and apple,low-power-frequency-max-mhz=2808 in DT, yet /sys/class/platform-profile never registers and powerprofilesctl falls back to PlatformDriver: placeholder. - Add patches/linux-pr2549-clpc-platform-profile-no-acpi.patch rebased with zero fuzz onto aurora-silicon/linux db6da7821954 from open upstream PR aurora-silicon/linux#2549 (4dfa5b665833, Diljit Singh) with human-only sign-off; verified clean with git apply --check and git am, and compiled into linux-aurora 7.3.0.aurora1-3.1. - Document the patch, base commit, and verification in patches/README.md. - Add read-only tools/clpc-platform-profile-check.sh and 40 host tests in tools/tests/clpc-platform-profile-check-test.sh covering kernel config, /sys/class/platform-profile, powerprofilesctl, and CLPC DT properties. - Record root cause, live 2.3 baseline, 3.1 vmlinux verification, and upstream PR #2549 status in JOURNEY.md section 9.103. --- JOURNEY.md | 59 +++ patches/README.md | 1 + ...pr2549-clpc-platform-profile-no-acpi.patch | 168 +++++++ tools/clpc-platform-profile-check.sh | 442 ++++++++++++++++++ .../tests/clpc-platform-profile-check-test.sh | 422 +++++++++++++++++ 5 files changed, 1092 insertions(+) create mode 100644 patches/linux-pr2549-clpc-platform-profile-no-acpi.patch create mode 100755 tools/clpc-platform-profile-check.sh create mode 100755 tools/tests/clpc-platform-profile-check-test.sh diff --git a/JOURNEY.md b/JOURNEY.md index d918805..9619c09 100644 --- a/JOURNEY.md +++ b/JOURNEY.md @@ -2484,3 +2484,62 @@ Built on the Mac's macOS 27.2 side, outputs in `build/oms30/` (`*2` folders and - **Check helper and host test:** added read-only `tools/gpu-stats-ring-check.sh` and `tools/tests/gpu-stats-ring-check-test.sh` (all suites in `tools/tests/*.sh` pass). +### 9.103 Apple CLPC platform profiles disabled without ACPI (OMS-58, 2026-12-02) +- **Live baseline on `2.3` (`7.3.0-1-2.3-ARCH`, J616c):** `apple-clpc` binds to + `5048aa000.power-management:performance-controller@1` (`compatible` `apple,t6041-max-clpc`, + `apple,t6041-clpc`), and its live device-tree node exposes `apple,high-power-mode` (from + `arch/arm64/boot/dts/apple/t6041-j616c.dts`), `apple,low-power-frequency-max-mhz = 2808` + (`0x00000af8`, matching `apple_clpc_hw_t6041.low_power_khz = 2808000` in + `drivers/soc/apple/clpc.c`), and the `apple,smc` phandle. Yet `/sys/class/platform-profile` + does not exist, `/proc/config.gz` has `# CONFIG_ACPI is not set` and `CONFIG_APPLE_CLPC=y` + with `CONFIG_ACPI_PLATFORM_PROFILE` absent, and `powerprofilesctl` (`power-profiles-daemon 0.30`) + falls back to `PlatformDriver: placeholder` on `balanced` and `power-saver` (with only + `CpuDriver: cpufreq` on `performance`). Apple SMC High Power mode (`zETM` record) and Low Power + mode's 2808 MHz CPU ceiling are therefore unreachable from userspace. +- **Root cause (verified in kernel source):** `apple_clpc_probe()` in `drivers/soc/apple/clpc.c` + gates profile registration (`has_profile` and `devm_platform_profile_register()`) on + `IS_REACHABLE(CONFIG_ACPI_PLATFORM_PROFILE)`. In `aurora-silicon/linux` `main` (`db6da7821954`) + and `omacom/linux-aurora` edge (`ea21b9af9a4c`), `drivers/soc/apple/Kconfig` has + `select ACPI_PLATFORM_PROFILE if ACPI`, `drivers/acpi/Kconfig` defines `config ACPI_PLATFORM_PROFILE` + inside `if ACPI`, and `drivers/Makefile` only enters `acpi/` under `CONFIG_ACPI`. Because + distribution `linux-aurora` kernels build with `# CONFIG_ACPI is not set`, Kconfig drops + `ACPI_PLATFORM_PROFILE`, `drivers/acpi/platform_profile.o` is never built, and `apple-clpc` + silently skips registering its `low-power balanced performance` class device. +- **Upstream PR status (`aurora-silicon/linux#2549`, checked 2026-12-02):** + [aurora-silicon/linux#2549](https://github.com/aurora-silicon/linux/pull/2549) (`"soc: apple: + clpc: offer platform profiles in kernels without ACPI"`, Diljit Singh / `DjDeveloperr`, head + `4dfa5b6658331ccd3a8ea03fd04fff06b07ea2e9`, opened 2026-11-20) is still **open** (ready for + review, 9/9 CI checks passing, no conflicts on `main`, hardware rows passing on J714s and + K114s with `# CONFIG_ACPI is not set`). It is waiting on one approving review from Core or + Omarchy Mac and cleanup of a commit trailer flagged in review. The 5-file change moves + `config ACPI_PLATFORM_PROFILE` outside `if ACPI` in `drivers/acpi/Kconfig`, builds + `acpi/platform_profile.o` under `ifndef CONFIG_ACPI` in `drivers/Makefile`, wraps legacy + `acpi_kobj` calls in `drivers/acpi/platform_profile.c` behind `#ifdef CONFIG_ACPI` via + `platform_profile_legacy_kobj()`, changes `APPLE_CLPC` to `select ACPI_PLATFORM_PROFILE` + unconditionally in `drivers/soc/apple/Kconfig`, and adds `CONFIG_ACPI_PLATFORM_PROFILE=y` to + `arch/arm64/configs/asahi.config`. +- **Rebased patch and `linux-aurora 7.3.0.aurora1-3.1` build check:** stored as + `patches/linux-pr2549-clpc-platform-profile-no-acpi.patch` (rebased with zero fuzz onto + `aurora-silicon/linux` `db6da7821954` with only the author's human `Signed-off-by`; verified + clean with both `git apply --check` and `git am` against pristine `db6da7821954`). Already + compiled into the staged `linux-aurora 7.3.0.aurora1-3.1` package + (`~/build/oms57/k-audit/linux-aurora-7.3.0.aurora1-3.1-aarch64.pkg.tar.xz`, sha256 + `1fe7c524…c1afc`; headers `be771605…ea3f`): + - Resolved `.config`: `# CONFIG_ACPI is not set`, `CONFIG_ACPI_PLATFORM_PROFILE=y`, + `CONFIG_APPLE_CLPC=y`. + - Build log confirms `CC drivers/acpi/platform_profile.o`. + - `vmlinux` and `System.map` carry `platform_profile_class`, `platform_profile_init`, + `platform_profile_register`, `devm_platform_profile_register`, `apple_clpc_profile_probe`, + `apple_clpc_profile_get`, and `apple_clpc_profile_set`. + - Live boot testing of `3.1` on the J616c (verifying `/sys/class/platform-profile/platform-profile-0` + registers `apple-clpc` with `low-power balanced performance` and `powerprofilesctl` switches + from `placeholder` to `platform_profile`) belongs to OMS-57; promoting the derivation's kernel + pin stays in OMS-51. +- **Check helper and host tests:** added read-only `tools/clpc-platform-profile-check.sh` and + `tools/tests/clpc-platform-profile-check-test.sh` (40 host tests covering patched `3.1` mocks, + large/gzipped configs without SIGPIPE, unpatched `2.3` diagnostics, `powerprofilesctl` driver + checks, J616c DT decoding, exit codes, and patch verification). On the live `2.3` J616c, + `bash tools/clpc-platform-profile-check.sh --require-dt` exits `1` and reports + `CONFIG_ACPI=n CONFIG_ACPI_PLATFORM_PROFILE=absent CONFIG_APPLE_CLPC=y`, missing + `/sys/class/platform-profile`, `PlatformDriver: placeholder`, and the intact J616c DT + (`high_power_mode=present low_power_max_mhz=2808 smc=present`). diff --git a/patches/README.md b/patches/README.md index d3f5be0..f88af71 100644 --- a/patches/README.md +++ b/patches/README.md @@ -12,6 +12,7 @@ Changes to other projects' repositories, kept here as plain `git diff` output so | `linux-t6041-pmp-sram-data.patch` | aurora-silicon/linux | `07ab25e06e00f16f56282d65181e21241d7da103` | The T6041 PMP keeps its firmware's data segment from the SRAM header's offset (`sram_backup_data`), which moved from `0x61000` (26.6.2) to `0x62000` (27.2), as the T8132 does; without it the PMP doesn't restart after a deep sleep (`-62`) (OMS-53, JOURNEY 9.98). Sent as [aurora-silicon/linux#3688](https://github.com/aurora-silicon/linux/pull/3688) (JOURNEY 9.99) | | `linux-t6041-26b123-32core-ane.patch` | aurora-silicon/linux | `42169a04154695428ae092e981bf88c936c7fe2c` (main, 2026-11-30, "Merge pull request #3498") | Admits the 32-core J616C's macOS 27.2 (26B123) Neural Engine preload as its own H16 profile, so the ANE starts on this Mac's 27.2 stub, plus the KUnit check that ties the 26B123 DART rule to both 26B123 rules (OMS-47, JOURNEY 9.100). A `git format-patch` commit with Allan's `Signed-off-by`; apply it with `git am`. Sent as a draft, [aurora-silicon/linux#3690](https://github.com/aurora-silicon/linux/pull/3690) (allanclempe/linux `1e0e243a`) | | `linux-t6041-26b123-gpu-stats-tag32.patch` | aurora-silicon/linux | `d5e9949314fd89fd59a233b5707139aea0a3bf43` (also applies cleanly to `37a19f92` and `omacom/linux-aurora` `ea21b9af9a4c` / `4a42f3105002`) | Returns `fw::m5::STATISTICS_TYPES` (`0x1_5fff_0000`, which includes tag 32 / `0x20`) in `InitData::statistics_types()` when `self.v26b123` is set, matching `InitData::scheduler_release()`, plus the `v26b123_admits_statistics_tag_32_without_quarantine` host test in `tools/asahi/g17-telemetry-integration-tests.py`. Prevents `G17 Primary Statistics ring stopped: EIO` and permanent statistics-ring quarantine on T6041 macOS 27.2 (`26B123`). Already merged upstream on `aurora-silicon/linux` `main` as [aurora-silicon/linux#3767](https://github.com/aurora-silicon/linux/pull/3767) (`a06c56629436`, commit `8d6847dc55c5`); kept here for backporting onto pre-`a06c5662` trees such as `37a19f92` (`2.3`) or `omacom/linux-aurora` `carry/aurora-7.3.0-4` (`ea21b9af9a4c`). Follow-up [aurora-silicon/linux#3775](https://github.com/aurora-silicon/linux/pull/3775) (`b98bf00b32a7`) builds on it to enable `Protocol::PSTATE_8MS` telemetry on `V26B123` (OMS-50, JOURNEY 9.102) | +| `linux-pr2549-clpc-platform-profile-no-acpi.patch` | aurora-silicon/linux | `db6da7821954eb92abce57b2ade4e2e31f4d3af5` (main, 2026-12-02, "Merge pull request #3814") | Enables `/sys/class/platform-profile` on kernels built without `CONFIG_ACPI` so `apple-clpc` registers its `low-power balanced performance` platform profile on distro kernels instead of letting `powerprofilesctl` fall back to `PlatformDriver: placeholder`: moves `config ACPI_PLATFORM_PROFILE` outside `if ACPI` in `drivers/acpi/Kconfig`, compiles `acpi/platform_profile.o` in `drivers/Makefile` under `ifndef CONFIG_ACPI`, guards legacy `acpi_kobj` calls behind `#ifdef CONFIG_ACPI` via `platform_profile_legacy_kobj()` in `drivers/acpi/platform_profile.c`, makes `APPLE_CLPC` select `ACPI_PLATFORM_PROFILE` unconditionally in `drivers/soc/apple/Kconfig`, and requests `CONFIG_ACPI_PLATFORM_PROFILE=y` in `arch/arm64/configs/asahi.config`. Rebased with zero fuzz onto `db6da7821954` from open upstream PR [aurora-silicon/linux#2549](https://github.com/aurora-silicon/linux/pull/2549) (`4dfa5b665833`, Diljit Singh); apply with `git apply` or `git am`. Compiled into `linux-aurora 7.3.0.aurora1-3.1` (`CONFIG_ACPI_PLATFORM_PROFILE=y` with `# CONFIG_ACPI is not set`, `platform_profile_class`/`devm_platform_profile_register`/`apple_clpc_profile_set` in `vmlinux`). Verify on a running Mac with `bash tools/clpc-platform-profile-check.sh --require-dt` and host tests `bash tools/tests/clpc-platform-profile-check-test.sh` (OMS-58, JOURNEY 9.103) | | `omarchy-lock-fingerprint-scanning.patch` | omacom/omarchy | `b20d7876f5ec6a45d18b9e4383dc4b6d9e8492ab` (quattro, 2026-11-19, "Keep colors in terminal windows an agent opens (#19507)") | The lock screen shows the fingerprint reader matching a finger: the icon pulses and the field says "Checking…" while fprintd reports a finger on the reader, the icon turns red for a finger it rejects, and a finger on the reader holds the idle blank (OMS-36, JOURNEY 9.48 to 9.50); sent upstream as [omacom/omarchy#19537](https://github.com/omacom/omarchy/pull/19537) | ## omarchy-mac-boot-aurora.patch diff --git a/patches/linux-pr2549-clpc-platform-profile-no-acpi.patch b/patches/linux-pr2549-clpc-platform-profile-no-acpi.patch new file mode 100644 index 0000000..367e051 --- /dev/null +++ b/patches/linux-pr2549-clpc-platform-profile-no-acpi.patch @@ -0,0 +1,168 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Diljit Singh +Date: Fri, 20 Nov 2026 06:31:31 -0500 +Subject: [PATCH] soc: apple: clpc: offer platform profiles in kernels without + ACPI + +Distribution kernels build without ACPI. ACPI_PLATFORM_PROFILE sat under +`if ACPI` and was built only inside drivers/acpi/, so APPLE_CLPC's +`select ACPI_PLATFORM_PROFILE if ACPI` did nothing there and the driver +skipped devm_platform_profile_register(): no /sys/class/platform-profile +on the M5 Pro. + +The class needs nothing from ACPI. Define the symbol outside `if ACPI`, +build platform_profile.o without ACPI too, select it unconditionally, +and request it in asahi.config so a distribution build fails loudly if +it is ever dropped again. + +Signed-off-by: Diljit Singh +--- + arch/arm64/configs/asahi.config | 2 ++ + drivers/Makefile | 4 ++++ + drivers/acpi/Kconfig | 8 +++++--- + drivers/acpi/platform_profile.c | 35 +++++++++++++++++++++++++-------- + drivers/soc/apple/Kconfig | 2 +- + 5 files changed, 39 insertions(+), 12 deletions(-) + +diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config +index 2c19008..dc1d7c1 100644 +--- a/arch/arm64/configs/asahi.config ++++ b/arch/arm64/configs/asahi.config +@@ -173,6 +173,8 @@ CONFIG_APPLE_T6041_CIO_RECONFIG=y + CONFIG_APPLE_PMC=y + CONFIG_APPLE_CLUSTER_PWRGATE=y + CONFIG_APPLE_CLPC=y ++# Its power modes as platform profiles (/sys/class/platform-profile). ++CONFIG_ACPI_PLATFORM_PROFILE=y + CONFIG_APPLE_MCC=y + CONFIG_APPLE_DISPLAY_GATE=y + CONFIG_APPLE_PMP=m +diff --git a/drivers/Makefile b/drivers/Makefile +index 0841ea8..9cde182 100644 +--- a/drivers/Makefile ++++ b/drivers/Makefile +@@ -31,6 +31,10 @@ obj-y += idle/ + obj-y += char/ipmi/ + + obj-$(CONFIG_ACPI) += acpi/ ++# Without ACPI, of drivers/acpi/ only the platform profile class is built. ++ifndef CONFIG_ACPI ++obj-$(CONFIG_ACPI_PLATFORM_PROFILE) += acpi/platform_profile.o ++endif + + # PnP must come after ACPI since it will eventually need to check if acpi + # was used and do nothing if so +diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig +index f165d14..0d842f5 100644 +--- a/drivers/acpi/Kconfig ++++ b/drivers/acpi/Kconfig +@@ -351,9 +351,6 @@ config ACPI_THERMAL + To compile this driver as a module, choose M here: + the module will be called thermal. + +-config ACPI_PLATFORM_PROFILE +- tristate +- + config ACPI_CUSTOM_DSDT_FILE + string "Custom DSDT Table file to include" + default "" +@@ -609,6 +606,11 @@ config ACPI_PRMT + + endif # ACPI + ++# The class interface (/sys/class/platform-profile) needs nothing from ACPI, ++# so device tree platforms without ACPI can select it too. ++config ACPI_PLATFORM_PROFILE ++ tristate ++ + config X86_PM_TIMER + bool "Power Management Timer Support" if EXPERT + depends on X86 && (ACPI || JAILHOUSE_GUEST) +diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c +index f5453b0..98475a3 100644 +--- a/drivers/acpi/platform_profile.c ++++ b/drivers/acpi/platform_profile.c +@@ -193,16 +193,32 @@ static ssize_t profile_show(struct device *dev, + + static const struct attribute_group platform_profile_group; + +-/* The legacy /sys/firmware/acpi files exist only where ACPI firmware runs. */ ++/* ++ * The legacy /sys/firmware/acpi files exist only where ACPI firmware runs, ++ * and never in a kernel built without ACPI. ++ */ ++static struct kobject *platform_profile_legacy_kobj(void) ++{ ++#ifdef CONFIG_ACPI ++ return acpi_kobj; ++#else ++ return NULL; ++#endif ++} ++ + static void platform_profile_legacy_notify(void) + { +- if (acpi_kobj) +- sysfs_notify(acpi_kobj, NULL, "platform_profile"); ++ struct kobject *kobj = platform_profile_legacy_kobj(); ++ ++ if (kobj) ++ sysfs_notify(kobj, NULL, "platform_profile"); + } + + static int platform_profile_legacy_update(void) + { +- return acpi_kobj ? sysfs_update_group(acpi_kobj, &platform_profile_group) : 0; ++ struct kobject *kobj = platform_profile_legacy_kobj(); ++ ++ return kobj ? sysfs_update_group(kobj, &platform_profile_group) : 0; + } + + /** +@@ -702,6 +718,7 @@ EXPORT_SYMBOL_GPL(devm_platform_profile_register); + + static int __init platform_profile_init(void) + { ++ struct kobject *kobj = platform_profile_legacy_kobj(); + int err; + + err = class_register(&platform_profile_class); +@@ -709,10 +726,10 @@ static int __init platform_profile_init(void) + return err; + + /* Without ACPI firmware (a device tree boot) only the class interface exists. */ +- if (!acpi_kobj) ++ if (!kobj) + return 0; + +- err = sysfs_create_group(acpi_kobj, &platform_profile_group); ++ err = sysfs_create_group(kobj, &platform_profile_group); + if (err) + class_unregister(&platform_profile_class); + +@@ -721,8 +738,10 @@ static int __init platform_profile_init(void) + + static void __exit platform_profile_exit(void) + { +- if (acpi_kobj) +- sysfs_remove_group(acpi_kobj, &platform_profile_group); ++ struct kobject *kobj = platform_profile_legacy_kobj(); ++ ++ if (kobj) ++ sysfs_remove_group(kobj, &platform_profile_group); + class_unregister(&platform_profile_class); + } + module_init(platform_profile_init); +diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig +index ab20d7f..f76ae34 100644 +--- a/drivers/soc/apple/Kconfig ++++ b/drivers/soc/apple/Kconfig +@@ -481,7 +481,7 @@ config APPLE_CLPC + depends on ARCH_APPLE || COMPILE_TEST + depends on (APPLE_PMC || !APPLE_PMC) && CPU_FREQ + depends on MFD_MACSMC || !MFD_MACSMC +- select ACPI_PLATFORM_PROFILE if ACPI ++ select ACPI_PLATFORM_PROFILE + default ARCH_APPLE + help + Raises the DRAM controller and SoC fabric performance floors of the diff --git a/tools/clpc-platform-profile-check.sh b/tools/clpc-platform-profile-check.sh new file mode 100755 index 0000000..16acb56 --- /dev/null +++ b/tools/clpc-platform-profile-check.sh @@ -0,0 +1,442 @@ +#!/bin/bash +# Read-only check for Apple CLPC platform-profile registration on kernels built +# without ACPI (OMS-58, JOURNEY 9.103). Detects missing CONFIG_ACPI_PLATFORM_PROFILE +# / absent /sys/class/platform-profile and powerprofilesctl placeholder fallback +# addressed upstream in aurora-silicon/linux#2549. +# +# Usage: +# bash tools/clpc-platform-profile-check.sh [--require-dt] \ +# [--config PATH] [--class-dir PATH] [--clpc-of-node PATH] \ +# [--clpc-driver-dir PATH] [--ppd-output PATH] [--ppd-cmd CMD] +# +# Environment overrides (also accepted for host tests): +# KCONFIG_PATH path to kernel .config or config.gz (optional; +# default /proc/config.gz when readable; "none" to skip) +# PLATFORM_PROFILE_DIR path to platform-profile class dir +# (default /sys/class/platform-profile; missing -> exit 1) +# CLPC_OF_NODE path to apple-clpc of_node directory (optional) +# CLPC_DRIVER_DIR path to apple-clpc platform driver dir +# (default /sys/bus/platform/drivers/apple-clpc) +# PPD_OUTPUT_FILE path to captured powerprofilesctl output (optional) +# PPD_CMD command to query power-profiles-daemon +# (default powerprofilesctl; "none" to skip) +# +# Exit codes: +# 0 apple-clpc platform-profile class healthy (low-power, balanced, +# performance), readable kernel config enables APPLE_CLPC and +# ACPI_PLATFORM_PROFILE, and powerprofilesctl (if available) uses +# PlatformDriver: platform_profile +# 1 platform-profile class missing or incomplete, kernel config missing +# ACPI_PLATFORM_PROFILE/APPLE_CLPC, powerprofilesctl on placeholder, +# malformed DT property, or missing J616c DT properties with --require-dt +# 2 usage error or explicit --config / --clpc-of-node / --ppd-output +# input unreadable +set -euo pipefail + +require_dt=0 +kconfig=${KCONFIG_PATH:-} +kconfig_explicit=0 +if [[ -n $kconfig ]]; then kconfig_explicit=1; fi +class_dir=${PLATFORM_PROFILE_DIR:-/sys/class/platform-profile} +clpc_of_node=${CLPC_OF_NODE:-} +clpc_of_node_explicit=0 +if [[ -n $clpc_of_node ]]; then clpc_of_node_explicit=1; fi +clpc_driver_dir=${CLPC_DRIVER_DIR:-/sys/bus/platform/drivers/apple-clpc} +ppd_output=${PPD_OUTPUT_FILE:-} +ppd_output_explicit=0 +if [[ -n $ppd_output ]]; then ppd_output_explicit=1; fi +ppd_cmd=${PPD_CMD:-powerprofilesctl} + +usage() { + cat >&2 <<'EOF' +usage: clpc-platform-profile-check.sh [--require-dt] [--config PATH] + [--class-dir PATH] [--clpc-of-node PATH] [--clpc-driver-dir PATH] + [--ppd-output PATH] [--ppd-cmd CMD] +EOF + exit 2 +} + +while (($#)); do + case $1 in + --require-dt) require_dt=1 ;; + --config) + (($# >= 2)) || usage + kconfig=$2 + kconfig_explicit=1 + shift + ;; + --class-dir) + (($# >= 2)) || usage + class_dir=$2 + shift + ;; + --clpc-of-node) + (($# >= 2)) || usage + clpc_of_node=$2 + clpc_of_node_explicit=1 + shift + ;; + --clpc-driver-dir) + (($# >= 2)) || usage + clpc_driver_dir=$2 + shift + ;; + --ppd-output) + (($# >= 2)) || usage + ppd_output=$2 + ppd_output_explicit=1 + shift + ;; + --ppd-cmd) + (($# >= 2)) || usage + ppd_cmd=$2 + shift + ;; + -h|--help) usage ;; + *) usage ;; + esac + shift +done + +if ((kconfig_explicit)) && [[ $kconfig != none ]]; then + if [[ ! -f $kconfig || ! -r $kconfig ]]; then + echo "clpc-platform-profile-check: config file unreadable ($kconfig)" >&2 + exit 2 + fi +elif ((!kconfig_explicit)) && [[ -r /proc/config.gz ]]; then + kconfig=/proc/config.gz +fi + +if ((clpc_of_node_explicit)); then + if [[ ! -d $clpc_of_node || ! -r $clpc_of_node ]]; then + echo "clpc-platform-profile-check: CLPC of_node directory unreadable ($clpc_of_node)" >&2 + exit 2 + fi +else + shopt -s nullglob + for candidate in "$clpc_driver_dir"/*/of_node; do + if [[ -d $candidate && -r $candidate ]]; then + clpc_of_node=$candidate + break + fi + done + shopt -u nullglob +fi + +if ((ppd_output_explicit)); then + if [[ ! -f $ppd_output || ! -r $ppd_output ]]; then + echo "clpc-platform-profile-check: powerprofilesctl output file unreadable ($ppd_output)" >&2 + exit 2 + fi +fi + +failures=() + +# Read a plain or gzipped kernel config fully to EOF (avoiding SIGPIPE on pipes) +# and print "acpi= profile= clpc=". +parse_kconfig() { + local path=$1 + local is_gz=0 + local magic="" + magic=$(od -An -N2 -tx1 "$path" 2>/dev/null | tr -d ' \n' || true) + if [[ $magic == 1f8b ]]; then + is_gz=1 + fi + + local awk_prog=' + BEGIN { acpi="absent"; profile="absent"; clpc="absent" } + /^# CONFIG_ACPI is not set$/ { acpi="n" } + /^CONFIG_ACPI=/ { sub(/^CONFIG_ACPI=/, ""); acpi=$0 } + /^# CONFIG_ACPI_PLATFORM_PROFILE is not set$/ { profile="n" } + /^CONFIG_ACPI_PLATFORM_PROFILE=/ { sub(/^CONFIG_ACPI_PLATFORM_PROFILE=/, ""); profile=$0 } + /^# CONFIG_APPLE_CLPC is not set$/ { clpc="n" } + /^CONFIG_APPLE_CLPC=/ { sub(/^CONFIG_APPLE_CLPC=/, ""); clpc=$0 } + END { printf "%s %s %s\n", acpi, profile, clpc } + ' + if ((is_gz)); then + gzip -dc "$path" | awk "$awk_prog" + else + awk "$awk_prog" "$path" + fi +} + +cfg_acpi="unavail" +cfg_profile="unavail" +cfg_clpc="unavail" +if [[ -n $kconfig && $kconfig != none && -r $kconfig ]]; then + if ! kcfg_line=$(parse_kconfig "$kconfig"); then + echo "clpc-platform-profile-check: failed to read kernel config ($kconfig)" >&2 + exit 2 + fi + read -r cfg_acpi cfg_profile cfg_clpc <<<"$kcfg_line" + if [[ $cfg_clpc != y && $cfg_clpc != m ]]; then + failures+=("kernel config does not enable CONFIG_APPLE_CLPC (got: $cfg_clpc)") + fi + if [[ $cfg_profile != y && $cfg_profile != m ]]; then + if [[ $cfg_acpi == n || $cfg_acpi == absent ]]; then + failures+=("kernel config lacks CONFIG_ACPI_PLATFORM_PROFILE with CONFIG_ACPI=$cfg_acpi (needs aurora-silicon/linux#2549)") + else + failures+=("kernel config does not enable CONFIG_ACPI_PLATFORM_PROFILE (got: $cfg_profile)") + fi + fi +fi + +# Inspect /sys/class/platform-profile. +read_trimmed() { + local file=$1 + if [[ -r $file ]]; then + awk '{ + for (i = 1; i <= NF; i++) { + out = (out == "" ? $i : out " " $i) + } + } END { print out }' "$file" + fi +} + +has_word() { + local list=$1 word=$2 + [[ " $list " == *" $word "* ]] +} + +pp_summary="" +if [[ ! -d $class_dir ]]; then + pp_summary="class_dir=missing ($class_dir)" + if [[ $cfg_profile != y && $cfg_profile != m && $cfg_acpi == n ]]; then + failures+=("platform-profile sysfs class missing ($class_dir); kernel built without ACPI and without CONFIG_ACPI_PLATFORM_PROFILE") + else + failures+=("platform-profile sysfs class missing ($class_dir)") + fi +else + shopt -s nullglob + entries=("$class_dir"/*) + shopt -u nullglob + found_handlers=() + clpc_dev="" + clpc_choices="" + clpc_profile="" + for entry in "${entries[@]}"; do + [[ -d $entry ]] || continue + h_name=$(read_trimmed "$entry/name") + h_choices=$(read_trimmed "$entry/choices") + h_profile=$(read_trimmed "$entry/profile") + bname=$(basename "$entry") + found_handlers+=("${bname}:${h_name:-unknown}") + if [[ $h_name == apple-clpc && -z $clpc_dev ]]; then + clpc_dev=$bname + clpc_choices=$h_choices + clpc_profile=$h_profile + fi + done + + if ((${#found_handlers[@]} == 0)); then + pp_summary="handlers=none" + failures+=("no platform-profile handlers registered under $class_dir") + elif [[ -z $clpc_dev ]]; then + joined=$(IFS=,; echo "${found_handlers[*]}") + pp_summary="handlers=$joined" + failures+=("apple-clpc platform-profile handler not registered under $class_dir (found: $joined)") + else + pp_summary="device=$clpc_dev name=apple-clpc profile=${clpc_profile:-missing} choices=${clpc_choices:-missing}" + for req in low-power balanced performance; do + if ! has_word "$clpc_choices" "$req"; then + failures+=("apple-clpc platform-profile choices missing '$req' (got: '${clpc_choices:-empty}')") + fi + done + if [[ -z $clpc_profile ]]; then + failures+=("apple-clpc platform-profile active profile is empty or unreadable") + elif ! has_word "$clpc_choices" "$clpc_profile"; then + failures+=("apple-clpc active profile '$clpc_profile' is not in choices ('$clpc_choices')") + fi + fi +fi + +# Inspect powerprofilesctl output if supplied or available. +ppd_text="" +ppd_avail=0 +if [[ -n $ppd_output ]]; then + ppd_text=$(cat "$ppd_output") + ppd_avail=1 +elif [[ $ppd_cmd != none ]] && command -v "$ppd_cmd" >/dev/null 2>&1; then + if ppd_text=$("$ppd_cmd" list 2>/dev/null); then + ppd_avail=1 + fi +fi + +ppd_summary="unavail" +if ((ppd_avail)); then + ppd_parsed=$(awk ' + BEGIN { + cur = "" + active = "none" + n = 0 + } + /^(\*[[:space:]]+|[[:space:]]?[[:space:]]?)[a-zA-Z0-9_-]+:[[:space:]]*$/ { + line = $0 + is_active = (line ~ /^[[:space:]]*\*/) + sub(/^[[:space:]]*[*]?[[:space:]]*/, "", line) + sub(/:[[:space:]]*$/, "", line) + cur = line + if (!(cur in seen)) { + seen[cur] = 1 + order[++n] = cur + pdrv[cur] = "none" + } + if (is_active) active = cur + next + } + /^[[:space:]]*(PlatformDriver|Driver):[[:space:]]*/ { + if (cur != "") { + val = $0 + sub(/^[[:space:]]*(PlatformDriver|Driver):[[:space:]]*/, "", val) + sub(/[[:space:]]+$/, "", val) + pdrv[cur] = val + } + next + } + END { + if (n == 0) { + print "EMPTY" + exit 0 + } + drivers = "" + for (i = 1; i <= n; i++) { + p = order[i] + pair = p ":" pdrv[p] + drivers = (drivers == "" ? pair : drivers "," pair) + } + printf "OK\t%s\t%s\n", active, drivers + } + ' <<<"$ppd_text") + + if [[ $ppd_parsed == EMPTY || -z $ppd_parsed ]]; then + ppd_summary="empty" + failures+=("powerprofilesctl output contained no profiles") + else + IFS=$'\t' read -r _ ppd_active ppd_drivers <<<"$ppd_parsed" + ppd_summary="active=$ppd_active drivers=$ppd_drivers" + saw_placeholder=0 + saw_platform_profile=0 + saw_perf=0 + saw_bal=0 + saw_ps=0 + missing_profile_drv=() + IFS=',' read -r -a pairs <<<"$ppd_drivers" + for pair in "${pairs[@]}"; do + prof=${pair%%:*} + drv=${pair#*:} + if [[ $drv == placeholder ]]; then + saw_placeholder=1 + elif [[ $drv == platform_profile ]]; then + saw_platform_profile=1 + fi + case $prof in + performance) + saw_perf=1 + if [[ $drv != platform_profile ]]; then + missing_profile_drv+=("${prof}:${drv}") + fi + ;; + balanced) + saw_bal=1 + if [[ $drv != platform_profile ]]; then + missing_profile_drv+=("${prof}:${drv}") + fi + ;; + power-saver) + saw_ps=1 + if [[ $drv != platform_profile ]]; then + missing_profile_drv+=("${prof}:${drv}") + fi + ;; + esac + done + ((saw_perf)) || missing_profile_drv+=("performance:absent") + ((saw_bal)) || missing_profile_drv+=("balanced:absent") + ((saw_ps)) || missing_profile_drv+=("power-saver:absent") + if ((saw_placeholder)); then + failures+=("powerprofilesctl fell back to PlatformDriver: placeholder ($ppd_drivers)") + elif ((!saw_platform_profile)); then + failures+=("powerprofilesctl does not report PlatformDriver: platform_profile ($ppd_drivers)") + elif ((${#missing_profile_drv[@]} > 0)); then + bad=$(IFS=,; echo "${missing_profile_drv[*]}") + failures+=("powerprofilesctl profiles missing PlatformDriver: platform_profile ($bad)") + fi + fi +fi + +# Inspect apple-clpc device-tree properties if present or explicitly provided. +read_be32_file() { + local file=$1 + local size + size=$(wc -c <"$file") + if [[ $size -ne 4 ]]; then + echo "invalid" + return 0 + fi + local b0 b1 b2 b3 + read -r b0 b1 b2 b3 < <(od -An -v -t u1 "$file" | tr '\n' ' ') + if [[ -z ${b3:-} ]]; then + echo "invalid" + return 0 + fi + echo $(( (b0 << 24) | (b1 << 16) | (b2 << 8) | b3 )) +} + +dt_summary="unavail" +if [[ -n $clpc_of_node && -d $clpc_of_node ]]; then + dt_compat="absent" + if [[ -r $clpc_of_node/compatible ]]; then + dt_compat=$(tr '\0' ',' <"$clpc_of_node/compatible" | sed 's/,$//') + if [[ -z $dt_compat ]]; then dt_compat="empty"; fi + fi + dt_high_power="absent" + if [[ -e $clpc_of_node/apple,high-power-mode ]]; then + dt_high_power="present" + fi + dt_low_mhz="absent" + if [[ -e $clpc_of_node/apple,low-power-frequency-max-mhz ]]; then + if [[ -r $clpc_of_node/apple,low-power-frequency-max-mhz ]]; then + dt_low_mhz=$(read_be32_file "$clpc_of_node/apple,low-power-frequency-max-mhz") + else + dt_low_mhz="unreadable" + fi + fi + dt_smc="absent" + if [[ -e $clpc_of_node/apple,smc ]]; then + dt_smc="present" + fi + + dt_summary="compatible=$dt_compat high_power_mode=$dt_high_power low_power_max_mhz=$dt_low_mhz smc=$dt_smc" + + if [[ $dt_low_mhz == invalid || $dt_low_mhz == unreadable || $dt_low_mhz == 0 ]]; then + failures+=("apple-clpc DT apple,low-power-frequency-max-mhz is invalid ($dt_low_mhz)") + fi + if ((require_dt)); then + if [[ $dt_high_power != present ]]; then + failures+=("apple-clpc DT missing apple,high-power-mode (--require-dt)") + fi + if [[ ! $dt_low_mhz =~ ^[0-9]+$ ]] || ((dt_low_mhz == 0)); then + failures+=("apple-clpc DT missing valid apple,low-power-frequency-max-mhz (--require-dt; got: $dt_low_mhz)") + fi + if [[ $dt_smc != present ]]; then + failures+=("apple-clpc DT missing apple,smc phandle (--require-dt)") + fi + fi +elif ((require_dt)); then + failures+=("apple-clpc device-tree node not found (--require-dt)") +fi + +printf 'kconfig: CONFIG_ACPI=%s CONFIG_ACPI_PLATFORM_PROFILE=%s CONFIG_APPLE_CLPC=%s\n' \ + "$cfg_acpi" "$cfg_profile" "$cfg_clpc" +printf 'platform_profile: %s\n' "$pp_summary" +printf 'powerprofilesctl: %s\n' "$ppd_summary" +printf 'clpc_dt: %s\n' "$dt_summary" + +if ((${#failures[@]} > 0)); then + for msg in "${failures[@]}"; do + printf 'FAIL: %s\n' "$msg" >&2 + done + exit 1 +fi + +echo "PASS: apple-clpc platform profiles active" diff --git a/tools/tests/clpc-platform-profile-check-test.sh b/tools/tests/clpc-platform-profile-check-test.sh new file mode 100755 index 0000000..23d94dd --- /dev/null +++ b/tools/tests/clpc-platform-profile-check-test.sh @@ -0,0 +1,422 @@ +#!/bin/bash +# Host tests for tools/clpc-platform-profile-check.sh and +# patches/linux-pr2549-clpc-platform-profile-no-acpi.patch (OMS-58). +# Runs as a normal user on any Linux: +# bash tools/tests/clpc-platform-profile-check-test.sh +set -euo pipefail + +here=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +repo=$(cd -- "$here/../.." && pwd) +checker=$repo/tools/clpc-platform-profile-check.sh +patch=$repo/patches/linux-pr2549-clpc-platform-profile-no-acpi.patch + +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT + +fails=0 +n=0 + +pass() { + n=$((n + 1)) + echo "ok: $1" +} + +fail() { + n=$((n + 1)) + fails=$((fails + 1)) + echo "FAIL: $1" >&2 +} + +expect_rc() { + local name=$1 want_rc=$2 + shift 2 + local rc=0 + "$@" >"$tmp/out" 2>"$tmp/err" || rc=$? + if [[ $rc == "$want_rc" ]]; then + pass "$name" + else + fail "$name (exit $rc, want $want_rc; out=$(tr '\n' ' ' <"$tmp/out") err=$(tr '\n' ' ' <"$tmp/err"))" + fi +} + +expect_stderr_contains() { + local name=$1 needle=$2 + if grep -qF "$needle" "$tmp/err"; then + pass "$name" + else + fail "$name (stderr missing '$needle'; got: $(tr '\n' ' ' <"$tmp/err"))" + fi +} + +expect_stdout_contains() { + local name=$1 needle=$2 + if grep -qF "$needle" "$tmp/out"; then + pass "$name" + else + fail "$name (stdout missing '$needle'; got: $(tr '\n' ' ' <"$tmp/out"))" + fi +} + +# --- Kernel config fixtures --- +cat >"$tmp/config-patched" <<'EOF' +# CONFIG_ACPI is not set +CONFIG_ACPI_PLATFORM_PROFILE=y +CONFIG_APPLE_CLPC=y +EOF + +cat >"$tmp/config-patched-mod" <<'EOF' +# CONFIG_ACPI is not set +CONFIG_ACPI_PLATFORM_PROFILE=m +CONFIG_APPLE_CLPC=m +EOF + +cat >"$tmp/config-unpatched" <<'EOF' +# CONFIG_ACPI is not set +CONFIG_APPLE_CLPC=y +EOF + +cat >"$tmp/config-no-clpc" <<'EOF' +# CONFIG_ACPI is not set +CONFIG_ACPI_PLATFORM_PROFILE=y +# CONFIG_APPLE_CLPC is not set +EOF + +cat >"$tmp/config-acpi-no-profile" <<'EOF' +CONFIG_ACPI=y +# CONFIG_ACPI_PLATFORM_PROFILE is not set +CONFIG_APPLE_CLPC=y +EOF + +# Large (>128 KiB) plain and gzipped configs with target symbols near the top +# to guard against SIGPIPE under pipefail. +cp "$tmp/config-patched" "$tmp/config-large" +for i in $(seq 1 3500); do + printf 'CONFIG_DUMMY_PADDING_OPTION_%04d=y\n' "$i" >>"$tmp/config-large" +done +gzip -c "$tmp/config-large" >"$tmp/config-large.gz" + +# Corrupt gzip file (valid magic bytes, truncated garbage payload). +printf '\x1f\x8b\x08\x00not-a-valid-gzip-stream' >"$tmp/config-corrupt.gz" + +# --- /sys/class/platform-profile fixtures --- +mkdir -p "$tmp/class-ok/platform-profile-0" +printf 'apple-clpc\n' >"$tmp/class-ok/platform-profile-0/name" +printf 'low-power balanced performance\n' >"$tmp/class-ok/platform-profile-0/choices" +printf 'balanced\n' >"$tmp/class-ok/platform-profile-0/profile" + +mkdir -p "$tmp/class-empty" + +mkdir -p "$tmp/class-wrong-handler/platform-profile-0" +printf 'apple-smc\n' >"$tmp/class-wrong-handler/platform-profile-0/name" +printf 'low-power balanced performance\n' >"$tmp/class-wrong-handler/platform-profile-0/choices" +printf 'balanced\n' >"$tmp/class-wrong-handler/platform-profile-0/profile" + +mkdir -p "$tmp/class-multi/platform-profile-0" "$tmp/class-multi/platform-profile-1" +printf 'other-driver\n' >"$tmp/class-multi/platform-profile-0/name" +printf 'balanced\n' >"$tmp/class-multi/platform-profile-0/choices" +printf 'balanced\n' >"$tmp/class-multi/platform-profile-0/profile" +printf 'apple-clpc\n' >"$tmp/class-multi/platform-profile-1/name" +printf 'performance balanced low-power\n' >"$tmp/class-multi/platform-profile-1/choices" +printf 'performance\n' >"$tmp/class-multi/platform-profile-1/profile" + +mkdir -p "$tmp/class-partial-choices/platform-profile-0" +printf 'apple-clpc\n' >"$tmp/class-partial-choices/platform-profile-0/name" +printf 'low-power balanced\n' >"$tmp/class-partial-choices/platform-profile-0/choices" +printf 'balanced\n' >"$tmp/class-partial-choices/platform-profile-0/profile" + +mkdir -p "$tmp/class-bad-profile/platform-profile-0" +printf 'apple-clpc\n' >"$tmp/class-bad-profile/platform-profile-0/name" +printf 'low-power balanced performance\n' >"$tmp/class-bad-profile/platform-profile-0/choices" +printf 'custom\n' >"$tmp/class-bad-profile/platform-profile-0/profile" + +# --- powerprofilesctl fixtures --- +cat >"$tmp/ppd-ok" <<'EOF' + performance: + CpuDriver: cpufreq + PlatformDriver: platform_profile + Degraded: no + +* balanced: + CpuDriver: cpufreq + PlatformDriver: platform_profile + + power-saver: + CpuDriver: cpufreq + PlatformDriver: platform_profile +EOF + +cat >"$tmp/ppd-placeholder" <<'EOF' +* performance: + CpuDriver: cpufreq + Degraded: no + + balanced: + CpuDriver: cpufreq + PlatformDriver: placeholder + + power-saver: + CpuDriver: cpufreq + PlatformDriver: placeholder +EOF + +cat >"$tmp/ppd-perf-missing-drv" <<'EOF' + performance: + CpuDriver: cpufreq + Degraded: no + +* balanced: + CpuDriver: cpufreq + PlatformDriver: platform_profile + + power-saver: + CpuDriver: cpufreq + PlatformDriver: platform_profile +EOF + +cat >"$tmp/ppd-no-performance" <<'EOF' +* balanced: + CpuDriver: cpufreq + PlatformDriver: platform_profile + + power-saver: + CpuDriver: cpufreq + PlatformDriver: platform_profile +EOF + +: >"$tmp/ppd-empty" + +# --- Device-tree of_node fixtures --- +make_dt_ok() { + local dir=$1 + mkdir -p "$dir" + printf 'apple,t6041-max-clpc\0apple,t6041-clpc\0' >"$dir/compatible" + : >"$dir/apple,high-power-mode" + # 2808 MHz = 0x00000af8 big-endian u32 + printf '\x00\x00\x0a\xf8' >"$dir/apple,low-power-frequency-max-mhz" + printf '\x00\x00\x00\x42' >"$dir/apple,smc" +} + +make_dt_ok "$tmp/dt-ok" + +make_dt_ok "$tmp/dt-no-hp" +rm -f "$tmp/dt-no-hp/apple,high-power-mode" + +make_dt_ok "$tmp/dt-no-lp" +rm -f "$tmp/dt-no-lp/apple,low-power-frequency-max-mhz" + +make_dt_ok "$tmp/dt-no-smc" +rm -f "$tmp/dt-no-smc/apple,smc" + +make_dt_ok "$tmp/dt-bad-lp-len" +printf '\x0a\xf8' >"$tmp/dt-bad-lp-len/apple,low-power-frequency-max-mhz" + +make_dt_ok "$tmp/dt-zero-lp" +printf '\x00\x00\x00\x00' >"$tmp/dt-zero-lp/apple,low-power-frequency-max-mhz" + +mkdir -p "$tmp/drv-auto/5048aa000.power-management:performance-controller@1" +ln -s "$tmp/dt-ok" "$tmp/drv-auto/5048aa000.power-management:performance-controller@1/of_node" +mkdir -p "$tmp/drv-empty" + +# --- Functional test cases --- +expect_rc "patched 3.1 mock state passes default check" 0 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" +expect_stdout_contains "patched 3.1 stdout reports decoded DT MHz" "low_power_max_mhz=2808" + +expect_rc "patched 3.1 mock state passes --require-dt" 0 \ + bash "$checker" --require-dt --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "patched 3.1 state passes with large (>128 KiB) gzipped config without SIGPIPE" 0 \ + bash "$checker" --config "$tmp/config-large.gz" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "patched 3.1 state passes with large (>128 KiB) plain config" 0 \ + bash "$checker" --config "$tmp/config-large" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "modular CONFIG_ACPI_PLATFORM_PROFILE=m and CONFIG_APPLE_CLPC=m passes" 0 \ + bash "$checker" --config "$tmp/config-patched-mod" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "auto-discovered CLPC driver of_node symlink passes --require-dt" 0 \ + bash "$checker" --require-dt --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-driver-dir "$tmp/drv-auto" --ppd-output "$tmp/ppd-ok" + +expect_rc "unpatched 2.3 state (no ACPI_PLATFORM_PROFILE, missing class dir, placeholder) fails" 1 \ + bash "$checker" --config "$tmp/config-unpatched" --class-dir "$tmp/does-not-exist-class" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-placeholder" +expect_stderr_contains "unpatched 2.3 stderr mentions PR #2549" "aurora-silicon/linux#2549" +expect_stderr_contains "unpatched 2.3 stderr flags placeholder" "PlatformDriver: placeholder" + +expect_rc "empty platform-profile class directory fails" 1 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-empty" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "wrong handler (apple-smc instead of apple-clpc) fails" 1 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-wrong-handler" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "multiple handlers with apple-clpc at platform-profile-1 passes" 0 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-multi" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "apple-clpc missing performance choice fails" 1 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-partial-choices" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "apple-clpc active profile not in choices fails" 1 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-bad-profile" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "powerprofilesctl placeholder fails even when sysfs and kconfig pass" 1 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-placeholder" + +expect_rc "powerprofilesctl performance missing platform_profile driver fails" 1 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-perf-missing-drv" + +expect_rc "powerprofilesctl missing performance profile entry fails" 1 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-no-performance" + +expect_rc "powerprofilesctl skipped (--ppd-cmd none) passes when kernel checks pass" 0 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-cmd none +expect_stdout_contains "skipped ppd reports unavail" "powerprofilesctl: unavail" + +expect_rc "empty powerprofilesctl output fails" 1 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-empty" + +expect_rc "skipped kernel config (--config none) passes when sysfs and ppd pass" 0 \ + bash "$checker" --config none --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "kernel config without CONFIG_APPLE_CLPC fails" 1 \ + bash "$checker" --config "$tmp/config-no-clpc" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "kernel config with ACPI=y but ACPI_PLATFORM_PROFILE=n fails" 1 \ + bash "$checker" --config "$tmp/config-acpi-no-profile" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "missing CLPC DT node passes default check" 0 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-driver-dir "$tmp/drv-empty" --ppd-output "$tmp/ppd-ok" +expect_stdout_contains "missing DT reports unavail" "clpc_dt: unavail" + +expect_rc "missing CLPC DT node fails --require-dt" 1 \ + bash "$checker" --require-dt --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-driver-dir "$tmp/drv-empty" --ppd-output "$tmp/ppd-ok" + +expect_rc "DT missing apple,high-power-mode passes default check" 0 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-no-hp" --ppd-output "$tmp/ppd-ok" + +expect_rc "DT missing apple,high-power-mode fails --require-dt" 1 \ + bash "$checker" --require-dt --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-no-hp" --ppd-output "$tmp/ppd-ok" + +expect_rc "DT missing apple,low-power-frequency-max-mhz fails --require-dt" 1 \ + bash "$checker" --require-dt --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-no-lp" --ppd-output "$tmp/ppd-ok" + +expect_rc "DT missing apple,smc phandle fails --require-dt" 1 \ + bash "$checker" --require-dt --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-no-smc" --ppd-output "$tmp/ppd-ok" + +expect_rc "DT malformed apple,low-power-frequency-max-mhz length fails" 1 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-bad-lp-len" --ppd-output "$tmp/ppd-ok" + +expect_rc "DT zero apple,low-power-frequency-max-mhz fails" 1 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-zero-lp" --ppd-output "$tmp/ppd-ok" + +# --- Exit-2 input / usage error cases --- +expect_rc "unknown option exits 2" 2 \ + bash "$checker" --unknown-flag + +expect_rc "explicit missing --config exits 2" 2 \ + bash "$checker" --config "$tmp/no-such-config" --class-dir "$tmp/class-ok" + +expect_rc "corrupt gzip --config exits 2" 2 \ + bash "$checker" --config "$tmp/config-corrupt.gz" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/ppd-ok" + +expect_rc "explicit missing --clpc-of-node exits 2" 2 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/no-such-dt" --ppd-output "$tmp/ppd-ok" + +expect_rc "explicit missing --ppd-output exits 2" 2 \ + bash "$checker" --config "$tmp/config-patched" --class-dir "$tmp/class-ok" \ + --clpc-of-node "$tmp/dt-ok" --ppd-output "$tmp/no-such-ppd" + +# --- Verify patches/linux-pr2549-clpc-platform-profile-no-acpi.patch --- +if [[ -f $patch ]] && + git apply --stat "$patch" >"$tmp/stat" 2>"$tmp/stat-err" && + grep -qF 'arch/arm64/configs/asahi.config' "$tmp/stat" && + grep -qF 'drivers/Makefile' "$tmp/stat" && + grep -qF 'drivers/acpi/Kconfig' "$tmp/stat" && + grep -qF 'drivers/acpi/platform_profile.c' "$tmp/stat" && + grep -qF 'drivers/soc/apple/Kconfig' "$tmp/stat" && + grep -qF '+CONFIG_ACPI_PLATFORM_PROFILE=y' "$patch" && + grep -qF '+obj-$(CONFIG_ACPI_PLATFORM_PROFILE)' "$patch" && + grep -qF '+ select ACPI_PLATFORM_PROFILE' "$patch" && + grep -qF 'Signed-off-by: Diljit Singh ' "$patch" && + awk '/^---$/ { exit 0 } /^[A-Za-z-]+-[Bb]y:/ && $0 != "Signed-off-by: Diljit Singh " { exit 1 }' "$patch"; then + pass "PR #2549 patch parses cleanly with all 5 files and human-only sign-off" +else + fail "PR #2549 patch missing expected files, hunks, or clean attribution" +fi + +# Apply non-platform_profile.c hunks to minimal pre-PR#2549 fixtures. +mkdir -p "$tmp/tree/arch/arm64/configs" "$tmp/tree/drivers/soc/apple" +cat >"$tmp/tree/arch/arm64/configs/asahi.config" <<'EOF' +CONFIG_APPLE_T6041_CIO_RECONFIG=y +CONFIG_APPLE_PMC=y +CONFIG_APPLE_CLUSTER_PWRGATE=y +CONFIG_APPLE_CLPC=y +CONFIG_APPLE_MCC=y +CONFIG_APPLE_DISPLAY_GATE=y +CONFIG_APPLE_PMP=m +EOF + +cat >"$tmp/tree/drivers/Makefile" <<'EOF' +obj-y += idle/ +obj-y += char/ipmi/ + +obj-$(CONFIG_ACPI) += acpi/ + +# PnP must come after ACPI since it will eventually need to check if acpi +# was used and do nothing if so +EOF + +cat >"$tmp/tree/drivers/soc/apple/Kconfig" <<'EOF' +config APPLE_CLPC + depends on ARCH_APPLE || COMPILE_TEST + depends on (APPLE_PMC || !APPLE_PMC) && CPU_FREQ + depends on MFD_MACSMC || !MFD_MACSMC + select ACPI_PLATFORM_PROFILE if ACPI + default ARCH_APPLE + help + Raises the DRAM controller and SoC fabric performance floors of the +EOF + +if git -C "$tmp/tree" apply --check \ + --include=arch/arm64/configs/asahi.config \ + --include=drivers/Makefile \ + --include=drivers/soc/apple/Kconfig \ + "$patch" 2>"$tmp/apply-err"; then + pass "PR #2549 Kconfig/Makefile/asahi.config hunks apply cleanly to pre-PR#2549 fixtures" +else + fail "PR #2549 fixture apply failed: $(cat "$tmp/apply-err")" +fi + +if ((fails)); then + echo "clpc-platform-profile-check tests: $fails of $n failed" >&2 + exit 1 +fi +echo "clpc-platform-profile-check tests: $n passed"