This is my operation on RPi 4B, the firmware is RPi4_UEFI_Firmware_v1.33:
primary core boot -> PSCI cpu_on(called by primary boot) -> secondary core boot(affinity_state is AFF_STATE_ON) -> PSCI cpu off (called by secondary core) -> secondary core powerdown(affinity_state is AFF_STATE_OFF) -> PSCI cpu_on(called by primary boot twice) -> secondary core boot(affinity_state is AFF_STATE_ON_PENDING)
PSCI cpu_on operation:
struct arm_smccc_res res;
cpuid = 3;
secondary_entry = 0x7a000000;
arm_smccc_smc(0xC4000003, cpuid, secondary_entry, 0, 0, 0, 0, 0, &res);
PSCI cpu_off operation:
arm_smccc_smc(0x84000002, 0, 0, 0, 0, 0, 0, 0, &res);
When I boot the secondary core at second time, it returns success(res.a0 returns 0). But the affinity_state is AFF_STATE_ON_PENDING instead of AFF_STATE_ON.
In my prediction, the last affinity_state of secondary core should be AFF_STATE_ON. I tried to figure out what problem it is, do I miss some steps?
In arm-trusted-firmware\plat\rpi\common\rpi3_pm.c, I find the hook pwr_domain_pwr_down_wfi is covered by rpi3_pwr_down_wfi directly, which previously is rpi3_pwr_domain_pwr_down_wfi.
The modification is in this commit: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/commit/plat/rpi?h=v2.3&id=2e5f84432dabd74cbcd045e5007e02c7d3b25a91
Previously(without the commit):
pwr_domain_pwr_down_wfi->rpi3_pwr_domain_pwr_down_wfi->plat_secondary_cold_boot_setup->plat_wait_for_warm_boot
It will bring secondary core to wfe, waiting for mailbox, come into bl31_warm_entrypoint when the mailbox value is PLAT_RPI3_TM_HOLD_STATE_GO, and finally the affinity_state will be set to AFF_STATE_ON in bl31_warm_entrypoint.
Now(within the commit):
pwr_domain_pwr_down_wfi->rpi3_pwr_down_wfi->write_rmr_el3(RMR_EL3_RR_BIT | RMR_EL3_AA64_BIT)
It resets the secondary core via RMR, waiting for a "warm boot" request. But I don't know how to receive the "warm boot" request and come into bl31_warm_entrypoint. It seems it's not workable in this way. In this case, the last affinity_state is still AFF_STATE_ON_PENDING.