blob: 01669be6ebcac2e36785f7d5fb22d7f1e4c7c7db [file] [log] [blame]
Dan Handleyb4315302015-03-19 18:58:55 +00001/*
Soby Mathew18e279e2017-06-12 12:37:10 +01002 * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
Dan Handleyb4315302015-03-19 18:58:55 +00003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handleyb4315302015-03-19 18:58:55 +00005 */
Antonio Nino Diaz234bc7f2019-01-15 14:19:50 +00006
Dan Handleyb4315302015-03-19 18:58:55 +00007#include <arch.h>
8#include <asm_macros.S>
9#include <cpu_macros.S>
Antonio Nino Diaz234bc7f2019-01-15 14:19:50 +000010#include <platform_def.h>
Dan Handleyb4315302015-03-19 18:58:55 +000011
12 .weak plat_secondary_cold_boot_setup
Soby Mathew38dce702015-07-01 16:16:20 +010013 .weak plat_get_my_entrypoint
David Wang371d4392015-10-22 13:30:50 +080014 .globl css_calc_core_pos_swap_cluster
Soby Mathew38dce702015-07-01 16:16:20 +010015 .weak plat_is_my_cpu_primary
Dan Handleyb4315302015-03-19 18:58:55 +000016
Sandrine Bailleux2bc42062015-04-29 16:28:52 +010017 /* ---------------------------------------------------------------------
18 * void plat_secondary_cold_boot_setup(void);
Dan Handleyb4315302015-03-19 18:58:55 +000019 *
Sandrine Bailleux2bc42062015-04-29 16:28:52 +010020 * In the normal boot flow, cold-booting secondary CPUs is not yet
21 * implemented and they panic.
22 *
23 * When booting an EL3 payload, secondary CPUs are placed in a holding
24 * pen, waiting for their mailbox to be populated. Note that all CPUs
25 * share the same mailbox ; therefore, populating it will release all
26 * CPUs from their holding pen. If finer-grained control is needed then
27 * this should be handled in the code that secondary CPUs jump to.
28 * ---------------------------------------------------------------------
Dan Handleyb4315302015-03-19 18:58:55 +000029 */
30func plat_secondary_cold_boot_setup
Sandrine Bailleux2bc42062015-04-29 16:28:52 +010031#ifndef EL3_PAYLOAD_BASE
32 /* TODO: Implement secondary CPU cold boot setup on CSS platforms */
Dan Handleyb4315302015-03-19 18:58:55 +000033cb_panic:
34 b cb_panic
Sandrine Bailleux2bc42062015-04-29 16:28:52 +010035#else
36 mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE
37
38 /* Wait until the mailbox gets populated */
39poll_mailbox:
40 ldr x1, [x0]
41 cbz x1, 1f
42 br x1
431:
44 wfe
45 b poll_mailbox
46#endif /* EL3_PAYLOAD_BASE */
Dan Handleyb4315302015-03-19 18:58:55 +000047endfunc plat_secondary_cold_boot_setup
48
Sandrine Bailleux804040d2015-07-10 16:49:31 +010049 /* ---------------------------------------------------------------------
Soby Mathew4c0d0392016-06-16 14:52:04 +010050 * uintptr_t plat_get_my_entrypoint (void);
Dan Handleyb4315302015-03-19 18:58:55 +000051 *
Sandrine Bailleux804040d2015-07-10 16:49:31 +010052 * Main job of this routine is to distinguish between a cold and a warm
53 * boot. On CSS platforms, this distinction is based on the contents of
54 * the Trusted Mailbox. It is initialised to zero by the SCP before the
55 * AP cores are released from reset. Therefore, a zero mailbox means
56 * it's a cold reset.
Dan Handleyb4315302015-03-19 18:58:55 +000057 *
Sandrine Bailleux804040d2015-07-10 16:49:31 +010058 * This functions returns the contents of the mailbox, i.e.:
59 * - 0 for a cold boot;
60 * - the warm boot entrypoint for a warm boot.
61 * ---------------------------------------------------------------------
Dan Handleyb4315302015-03-19 18:58:55 +000062 */
Soby Mathew38dce702015-07-01 16:16:20 +010063func plat_get_my_entrypoint
Soby Mathew785fb922015-09-29 15:47:16 +010064 mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE
Sandrine Bailleux804040d2015-07-10 16:49:31 +010065 ldr x0, [x0]
66 ret
Soby Mathew38dce702015-07-01 16:16:20 +010067endfunc plat_get_my_entrypoint
Dan Handleyb4315302015-03-19 18:58:55 +000068
Soby Mathew38dce702015-07-01 16:16:20 +010069 /* -----------------------------------------------------------
Soby Mathew4c0d0392016-06-16 14:52:04 +010070 * unsigned int css_calc_core_pos_swap_cluster(u_register_t mpidr)
David Wang371d4392015-10-22 13:30:50 +080071 * Utility function to calculate the core position by
Soby Mathew38dce702015-07-01 16:16:20 +010072 * swapping the cluster order. This is necessary in order to
73 * match the format of the boot information passed by the SCP
Soby Mathew58523c02015-06-08 12:32:50 +010074 * and read in plat_is_my_cpu_primary below.
Soby Mathew38dce702015-07-01 16:16:20 +010075 * -----------------------------------------------------------
Dan Handleyb4315302015-03-19 18:58:55 +000076 */
David Wang371d4392015-10-22 13:30:50 +080077func css_calc_core_pos_swap_cluster
Dan Handleyb4315302015-03-19 18:58:55 +000078 and x1, x0, #MPIDR_CPU_MASK
79 and x0, x0, #MPIDR_CLUSTER_MASK
80 eor x0, x0, #(1 << MPIDR_AFFINITY_BITS) // swap cluster order
81 add x0, x1, x0, LSR #6
82 ret
David Wang371d4392015-10-22 13:30:50 +080083endfunc css_calc_core_pos_swap_cluster
Dan Handleyb4315302015-03-19 18:58:55 +000084
85 /* -----------------------------------------------------
Soby Mathew38dce702015-07-01 16:16:20 +010086 * unsigned int plat_is_my_cpu_primary (void);
Dan Handleyb4315302015-03-19 18:58:55 +000087 *
Soby Mathew38dce702015-07-01 16:16:20 +010088 * Find out whether the current cpu is the primary
Dan Handleyb4315302015-03-19 18:58:55 +000089 * cpu (applicable ony after a cold boot)
90 * -----------------------------------------------------
91 */
Soby Mathew18e279e2017-06-12 12:37:10 +010092#if CSS_USE_SCMI_SDS_DRIVER
93func plat_is_my_cpu_primary
94 mov x9, x30
95 bl plat_my_core_pos
96 mov x4, x0
97 bl sds_get_primary_cpu_id
98 /* Check for error */
99 mov x1, #0xffffffff
100 cmp x0, x1
101 b.eq 1f
102 cmp x0, x4
103 cset w0, eq
104 ret x9
1051:
106 no_ret plat_panic_handler
107endfunc plat_is_my_cpu_primary
108#else
Soby Mathew38dce702015-07-01 16:16:20 +0100109func plat_is_my_cpu_primary
Dan Handleyb4315302015-03-19 18:58:55 +0000110 mov x9, x30
Soby Mathew38dce702015-07-01 16:16:20 +0100111 bl plat_my_core_pos
Soby Mathewbd83b392018-10-12 17:08:28 +0100112 mov_imm x1, SCP_BOOT_CFG_ADDR
Dan Handleyb4315302015-03-19 18:58:55 +0000113 ldr x1, [x1]
Vikram Kanigiri8e083ec2016-02-08 16:29:30 +0000114 ubfx x1, x1, #PLAT_CSS_PRIMARY_CPU_SHIFT, \
115 #PLAT_CSS_PRIMARY_CPU_BIT_WIDTH
Dan Handleyb4315302015-03-19 18:58:55 +0000116 cmp x0, x1
Soby Mathew58523c02015-06-08 12:32:50 +0100117 cset w0, eq
Dan Handleyb4315302015-03-19 18:58:55 +0000118 ret x9
Soby Mathew38dce702015-07-01 16:16:20 +0100119endfunc plat_is_my_cpu_primary
Soby Mathew18e279e2017-06-12 12:37:10 +0100120#endif