diff --git a/Documentation/devicetree/bindings/power/apple,pmc.yaml b/Documentation/devicetree/bindings/power/apple,pmc.yaml index fe47291dff0dc..4053aa0167d4d 100644 --- a/Documentation/devicetree/bindings/power/apple,pmc.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmc.yaml @@ -266,7 +266,15 @@ patternProperties: $ref: /schemas/types.yaml#/definitions/phandle description: The SMC, whose package power reading the low-power platform profile - holds the CPU clusters to. + holds the CPU clusters to, and which the performance profile tells + about High Power mode on Macs that have it. + + apple,high-power-mode: + type: boolean + description: + The machine has High Power mode, the fan and power headroom macOS + offers on some MacBook Pros. The performance platform profile then + tells the SMC (apple,smc) that it is on. required: - compatible diff --git a/arch/arm64/boot/dts/apple/t6040-j616s.dts b/arch/arm64/boot/dts/apple/t6040-j616s.dts index e81fb8b6b5d0d..1d9e600d6ffdb 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j616s.dts @@ -40,6 +40,11 @@ }; }; +/* The 16-inch chassis has High Power mode */ +&clpc { + apple,high-power-mode; +}; + /* * ADT /arm-io/aon-ptd ptd_data_table: the battery record ("IFtb", layout 1, * slots 0x12-0x15). Only its peek aperture is read. diff --git a/arch/arm64/boot/dts/apple/t604x.dtsi b/arch/arm64/boot/dts/apple/t604x.dtsi index 3484262fa7a43..dc9cd3dbd7a1b 100644 --- a/arch/arm64/boot/dts/apple/t604x.dtsi +++ b/arch/arm64/boot/dts/apple/t604x.dtsi @@ -1089,6 +1089,8 @@ clpc: performance-controller@1 { compatible = "apple,t6041-clpc"; reg = <1>; + /* High Power mode goes to the SMC (the 16-inch M4 Pro) */ + apple,smc = <&smc>; }; }; diff --git a/arch/arm64/boot/dts/apple/t6050-j714s.dts b/arch/arm64/boot/dts/apple/t6050-j714s.dts index 064e758b07a00..fb10530121001 100644 --- a/arch/arm64/boot/dts/apple/t6050-j714s.dts +++ b/arch/arm64/boot/dts/apple/t6050-j714s.dts @@ -515,6 +515,11 @@ apple,pmp = <&pmp0>; }; +/* The 14-inch M5 Pro has High Power mode */ +&clpc { + apple,high-power-mode; +}; + &sgx { power-domains = <&pmp0_gfx>; }; diff --git a/drivers/soc/apple/clpc.c b/drivers/soc/apple/clpc.c index e257fefa310fa..f00f35181aa68 100644 --- a/drivers/soc/apple/clpc.c +++ b/drivers/soc/apple/clpc.c @@ -110,9 +110,6 @@ enum apple_clpc_rail { * sharing this CLPC without it get no low-power profile. NULL for any * @low_power_mw: package power (the SMC's PHPC key) the low-power profile * holds the CPU clusters to; 0 for none - * @high_power_machine: the machine compatible on which the performance - * profile tells the SMC that macOS's High Power mode is on (the zETM - * record below); NULL for none */ struct apple_clpc_hw { unsigned int rail[APPLE_CLPC_RAILS]; @@ -133,7 +130,6 @@ struct apple_clpc_hw { unsigned int low_power_khz; const char *low_power_machine; unsigned int low_power_mw; - const char *high_power_machine; }; struct apple_clpc_cluster { @@ -992,9 +988,15 @@ static void apple_clpc_sample(struct apple_clpc *clpc) apple_clpc_profile_limit(clpc); - /* Sample on time while graphics is powered, to see it power off, and in low power. */ + /* + * Sample on time while graphics is powered, to see it power off, and in + * low power where it has a ceiling to keep. A profile with no low-power + * ceiling (High Power only) has nothing to do there, so it stays + * deferrable. + */ apple_clpc_queue(clpc, !apple_clpc_floor(clpc, state) && !clpc->gpu_on && - !clpc->ane_qos_khz && !READ_ONCE(clpc->low_power)); + !clpc->ane_qos_khz && + !(clpc->low_power_khz && READ_ONCE(clpc->low_power))); } static void apple_clpc_run(struct apple_clpc *clpc) @@ -1066,10 +1068,10 @@ static int apple_clpc_status_show(struct seq_file *s, void *unused) seq_printf(s, " cpu%u %u", clpc->clusters[i].policy_cpu, clpc->clusters[i].max_khz); seq_puts(s, "\n"); - if (clpc->high_power) - seq_printf(s, "smc high power: %s (%u records sent)\n", - clpc->high_power_sent ? "on" : "off", clpc->high_power_seq); } + if (clpc->high_power) + seq_printf(s, "smc high power: %s (%u records sent)\n", + clpc->high_power_sent ? "on" : "off", clpc->high_power_seq); if (clpc->gpu_pmgr) { seq_printf(s, "gpu: powered %u for %u ms, pmp limited ", clpc->gpu_on, clpc->gpu_on ? jiffies_to_msecs(jiffies - clpc->gpu_on_since) : 0); @@ -1362,6 +1364,7 @@ static int apple_clpc_probe(struct platform_device *pdev) struct device_node *gpu = NULL; struct apple_clpc *clpc; unsigned int rail, i; + bool high_power; int ret; clpc = devm_kzalloc(dev, sizeof(*clpc), GFP_KERNEL); @@ -1501,20 +1504,34 @@ static int apple_clpc_probe(struct platform_device *pdev) clpc->power_next = jiffies; if (!clpc->hw->low_power_machine || of_machine_is_compatible(clpc->hw->low_power_machine)) clpc->low_power_khz = clpc->hw->low_power_khz; - if (clpc->low_power_khz && IS_REACHABLE(CONFIG_ACPI_PLATFORM_PROFILE)) { - struct device *ppdev; - + /* + * The board DT says whether the machine has High Power mode: then the + * performance profile tells the SMC that it is on (the zETM record). + * A machine with High Power mode and no low-power ceiling still gets + * the platform profile, named "apple-smc" so that userspace keeps its + * own low-power CPU budget. + */ + high_power = of_property_read_bool(dev->of_node, "apple,high-power-mode"); + if ((clpc->low_power_khz || high_power) && IS_REACHABLE(CONFIG_ACPI_PLATFORM_PROFILE)) { /* The SMC is optional: without it the low-power profile has only its ceiling. */ clpc->smc_np = of_parse_phandle(dev->of_node, "apple,smc", 0); - clpc->high_power = clpc->smc_np && clpc->hw->high_power_machine && - of_machine_is_compatible(clpc->hw->high_power_machine); - if (!clpc->policy_nb_added) { + clpc->high_power = clpc->smc_np && high_power; + } + /* High Power mode alone needs the SMC; without it there is no profile. */ + if ((clpc->low_power_khz || clpc->high_power) && IS_REACHABLE(CONFIG_ACPI_PLATFORM_PROFILE)) { + struct device *ppdev; + + if (clpc->low_power_khz && !clpc->policy_nb_added) { clpc->policy_nb.notifier_call = apple_clpc_policy_notify; clpc->policy_nb_added = !cpufreq_register_notifier(&clpc->policy_nb, CPUFREQ_POLICY_NOTIFIER); } - ppdev = devm_platform_profile_register(dev, "apple-clpc", clpc, - &apple_clpc_profile_ops); + /* + * "apple-clpc" budgets the low-power profile itself; "apple-smc" + * only carries High Power mode, and userspace keeps the CPU budget. + */ + ppdev = devm_platform_profile_register(dev, clpc->low_power_khz ? "apple-clpc" : + "apple-smc", clpc, &apple_clpc_profile_ops); if (IS_ERR(ppdev)) dev_warn(dev, "no platform profile: %pe\n", ppdev); } @@ -2041,8 +2058,6 @@ static const struct apple_clpc_hw apple_clpc_hw_t6050 = { .idle_on_time = true, .low_power_khz = 2808000, .low_power_mw = 15000, - /* High Power mode's record, as macOS 27.0 writes it on the 14-inch M5 Pro */ - .high_power_machine = "apple,j714s", }; static const struct of_device_id apple_clpc_of_match[] = { diff --git a/tools/asahi/clpc-gpu-demand-tests.py b/tools/asahi/clpc-gpu-demand-tests.py index 2e852e6f91643..43ad90e32b42d 100644 --- a/tools/asahi/clpc-gpu-demand-tests.py +++ b/tools/asahi/clpc-gpu-demand-tests.py @@ -111,6 +111,7 @@ def main(): unsigned int ane_qos_khz; unsigned long ane_until; bool low_power; + unsigned int low_power_khz; }; static unsigned long jiffies; static u64 ktime_get_mono_fast_ns(void) { return jiffies * 1000000ull; } @@ -245,6 +246,19 @@ def main(): assert(c.last_reason==16); } +// Low power samples on time only where it has a CPU ceiling to keep +// (low_power_khz); a High Power-only profile stays deferrable when idle. +static void check_low_power(void) { + struct apple_clpc_gpu gpu={0}; + struct apple_clpc c={.hw=&apple_clpc_hw_t6040,.agent=1,.mask=3,.gpu=&gpu,.low_power=true}; + read_error=vote_error=0; pmgr_status=0xf0; published=~0u; + jiffies=3000; apple_clpc_sample(&c); assert(published==0 && queued_idle); + c.low_power_khz=2808000; + jiffies=3004; apple_clpc_sample(&c); assert(published==0 && !queued_idle); + c.low_power=false; + jiffies=3008; apple_clpc_sample(&c); assert(published==0 && queued_idle); +} + int main(void) { // T6040's supplier is always powered: it must NEVER substitute for work. struct apple_clpc_gpu gpu={0}; @@ -273,6 +287,7 @@ def main(): check_t8140(); check_t8140_dense(); check_t8140_ane(); + check_low_power(); check_t6040_ane(); puts("PASS: T6040 and T8132 host demand; T8140 ANE, streaming, dense work, read errors and PMP backoff; idle release"); } diff --git a/tools/asahi/clpc-high-power-cleanup-tests.py b/tools/asahi/clpc-high-power-cleanup-tests.py index 806d309a4c1bc..709aed09ecf4f 100755 --- a/tools/asahi/clpc-high-power-cleanup-tests.py +++ b/tools/asahi/clpc-high-power-cleanup-tests.py @@ -231,7 +231,7 @@ def main(): cwd=ROOT, text=True) if args.old_ref else (ROOT / DRIVER).read_text()) # This is the action whose callback runs after devres removes the profile. assert source.index('devm_add_action_or_reset(dev, apple_clpc_stop, clpc)') < source.index( - 'devm_platform_profile_register(dev, "apple-clpc"') + 'devm_platform_profile_register(dev,') defines = '\n'.join(re.findall(r'^#define APPLE_CLPC_(?:ZETM_\w+|FLOAT_ONE)\s+[^\n]+', source, re.M)) body = '\n\n'.join(function(source, n) for n in ( 'apple_clpc_send_high_power', 'apple_clpc_profile_set', 'apple_clpc_halt', 'apple_clpc_stop'))