Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ properties:
- const: apple,t7000-cluster-cpufreq
- const: apple,s5l8960x-cluster-cpufreq
- const: apple,s5l8960x-cluster-cpufreq
- const: apple,t8140-cluster-cpufreq
- items:
- const: apple,t6020-cluster-cpufreq
- const: apple,t8112-cluster-cpufreq
Expand Down
8 changes: 8 additions & 0 deletions Documentation/devicetree/bindings/hwmon/apple,smc-hwmon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ properties:
compatible:
const: apple,smc-hwmon

apple,cpu-thermal-policy:
type: boolean
description:
Enable the J700 CPU thermal provider over the first six temperature
channels, which must contain Te05, Te0S, Tp01, Tp05, Tp09 and Tp0D.
Further temperature channels are reporting-only. The provider holds
CPU frequency constraints while these readings are unavailable.

patternProperties:
"^current-[A-Za-z0-9]{4}$":
$ref: "#/$defs/sensor"
Expand Down
1 change: 1 addition & 0 deletions Documentation/devicetree/bindings/mfd/apple,smc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ properties:
- enum:
- apple,t6020-smc
- apple,t8122-smc
- apple,t8140-smc
- const: apple,t8103-smc
- items:
- enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ properties:
compatible:
items:
- enum:
- apple,baku-pmic
- apple,maverick-pmic
- apple,sera-pmic
- apple,stowe-pmic
Expand Down
1 change: 1 addition & 0 deletions Documentation/devicetree/bindings/spmi/apple,spmi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ properties:
- apple,t8012-spmi
- apple,t8015-spmi
- apple,t8122-spmi
- apple,t8140-spmi
- const: apple,t8103-spmi
- items:
- enum:
Expand Down
4 changes: 4 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,11 @@ F: Documentation/devicetree/bindings/serial/apple,dockchannel-uart.yaml
F: Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml
F: Documentation/devicetree/bindings/sound/apple,t8140-aop-audio.yaml
F: arch/arm64/boot/dts/apple/t8140*
F: arch/arm64/include/asm/apple-idle.h
F: arch/arm64/kernel/idle-apple.S
F: drivers/thermal/apple-smc-cpu-thermal.c
F: drivers/tty/serial/apple_dockchannel*
F: include/linux/soc/apple/smc-thermal.h

APPLETALK NETWORK LAYER
L: netdev@vger.kernel.org
Expand Down
8 changes: 8 additions & 0 deletions arch/arm64/include/asm/apple-idle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef __ASM_APPLE_IDLE_H
#define __ASM_APPLE_IDLE_H

/* WFI that preserves x18-x30 on cores that lose them (Apple T8140). */
void apple_cpu_wfi(void);

#endif
4 changes: 4 additions & 0 deletions arch/arm64/include/asm/cputype.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
#define APPLE_CPU_PART_M2_AVALANCHE_PRO 0x035
#define APPLE_CPU_PART_M2_BLIZZARD_MAX 0x038
#define APPLE_CPU_PART_M2_AVALANCHE_MAX 0x039
#define APPLE_CPU_PART_TAHITI_E 0x060
#define APPLE_CPU_PART_TAHITI_P 0x061

#define AMPERE_CPU_PART_AMPERE1 0xAC3
#define AMPERE_CPU_PART_AMPERE1A 0xAC4
Expand Down Expand Up @@ -246,6 +248,8 @@
#define MIDR_APPLE_M2_AVALANCHE_PRO MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_AVALANCHE_PRO)
#define MIDR_APPLE_M2_BLIZZARD_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_BLIZZARD_MAX)
#define MIDR_APPLE_M2_AVALANCHE_MAX MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_M2_AVALANCHE_MAX)
#define MIDR_APPLE_TAHITI_E MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_TAHITI_E)
#define MIDR_APPLE_TAHITI_P MIDR_CPU_MODEL(ARM_CPU_IMP_APPLE, APPLE_CPU_PART_TAHITI_P)
#define MIDR_AMPERE1 MIDR_CPU_MODEL(ARM_CPU_IMP_AMPERE, AMPERE_CPU_PART_AMPERE1)
#define MIDR_AMPERE1A MIDR_CPU_MODEL(ARM_CPU_IMP_AMPERE, AMPERE_CPU_PART_AMPERE1A)
#define MIDR_MICROSOFT_AZURE_COBALT_100 MIDR_CPU_MODEL(ARM_CPU_IMP_MICROSOFT, MICROSOFT_CPU_PART_AZURE_COBALT_100)
Expand Down
2 changes: 2 additions & 0 deletions arch/arm64/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ obj-y := debug-monitors.o entry.o irq.o fpsimd.o \
cpufeature_impdef.o \
rsi.o jump_label.o

obj-$(CONFIG_ARCH_APPLE) += idle-apple.o

obj-$(CONFIG_COMPAT) += sys32.o signal32.o \
sys_compat.o
obj-$(CONFIG_COMPAT) += sigreturn32.o
Expand Down
45 changes: 45 additions & 0 deletions arch/arm64/kernel/idle-apple.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <linux/linkage.h>
#include <asm/assembler.h>

/*
* T8140 secondaries can resume from WFI with cleared general registers.
* SP and stack memory survive. Preserve the AAPCS64 callee-saved registers
* and x18 (which may hold the shadow call stack), including the return PC.
* This follows the stateless-wait approach used during m1n1 M5 Windows
* bring-up. It does not configure an Apple deep-sleep state or DVFS policy.
*
* IRQ masking/context management remains with cpu_do_idle(). The direct
* function call tells its compiler that x0-x17 and flags are clobbered.
*/
.macro apple_wait_save
stp x29, x30, [sp, #-112]!
mov x29, sp
stp x19, x20, [sp, #16]
stp x21, x22, [sp, #32]
stp x23, x24, [sp, #48]
stp x25, x26, [sp, #64]
stp x27, x28, [sp, #80]
str x18, [sp, #96]
dsb sy
.endm

.macro apple_wait_restore
isb
ldr x18, [sp, #96]
ldp x19, x20, [sp, #16]
ldp x21, x22, [sp, #32]
ldp x23, x24, [sp, #48]
ldp x25, x26, [sp, #64]
ldp x27, x28, [sp, #80]
ldp x29, x30, [sp], #112
ret
.endm

.pushsection .cpuidle.text, "ax"
SYM_FUNC_START(apple_cpu_wfi)
apple_wait_save
wfi
apple_wait_restore
SYM_FUNC_END(apple_cpu_wfi)
.popsection
54 changes: 52 additions & 2 deletions arch/arm64/kernel/idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
*/

#include <linux/cpu.h>
#include <linux/init.h>
#include <linux/irqflags.h>
#include <linux/jump_label.h>

#include <asm/apple-idle.h>
#include <asm/barrier.h>
#include <asm/cpuidle.h>
#include <asm/cpufeature.h>
#include <asm/cputype.h>
#include <asm/fpsimd.h>
#include <asm/sysreg.h>

enum {
Expand All @@ -34,6 +39,41 @@ static int __init setup_idle(char *arg)
}
early_param("idle", setup_idle);

#ifdef CONFIG_ARCH_APPLE
/*
* Apple T8140 (A18 Pro) secondary CPUs can return from WFI with their
* general-purpose and FP/SIMD registers cleared. The key is enabled once
* at boot on those parts; everywhere else the check is a patched-out branch.
*/
static DEFINE_STATIC_KEY_FALSE(apple_wfi_loses_regs);

static const struct midr_range apple_wfi_loses_regs_cpus[] __initconst = {
MIDR_ALL_VERSIONS(MIDR_APPLE_TAHITI_E),
MIDR_ALL_VERSIONS(MIDR_APPLE_TAHITI_P),
{}
};

static int __init apple_wfi_quirk_init(void)
{
if (is_midr_in_range_list(apple_wfi_loses_regs_cpus)) {
static_branch_enable(&apple_wfi_loses_regs);
pr_info("Apple T8140: preserving registers across WFI\n");
}
return 0;
}
early_initcall(apple_wfi_quirk_init);

static __always_inline bool apple_wfi_needs_save(void)
{
return static_branch_unlikely(&apple_wfi_loses_regs);
}
#else
static __always_inline bool apple_wfi_needs_save(void)
{
return false;
}
#endif

/*
* cpu_do_idle()
*
Expand All @@ -50,8 +90,18 @@ void __cpuidle cpu_do_idle(void)
arm_cpuidle_save_irq_context(&context);

if (likely(idle == ARM64_IDLE_WFI)) {
dsb(sy);
wfi();
if (apple_wfi_needs_save()) {
/*
* The FP/SIMD registers do not survive either: drop the
* lazy ownership so the next return to userspace reloads
* them, even when the same task resumes on this CPU.
*/
fpsimd_save_and_flush_cpu_state();
apple_cpu_wfi();
} else {
dsb(sy);
wfi();
}
} else if (idle == ARM64_IDLE_YIELD) {
dsb(sy);
asm volatile("yield" ::: "memory");
Expand Down
Loading