blob: 01669be6ebcac2e36785f7d5fb22d7f1e4c7c7db [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Soby Mathew1ced6b82017-06-12 12:37:10 +01002 * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
Dan Handley9df48042015-03-19 18:58:55 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handley9df48042015-03-19 18:58:55 +00005 */
Antonio Nino Diaza320ecd2019-01-15 14:19:50 +00006
Dan Handley9df48042015-03-19 18:58:55 +00007#include <arch.h>
8#include <asm_macros.S>
9#include <cpu_macros.S>
Antonio Nino Diaza320ecd2019-01-15 14:19:50 +000010#include <platform_def.h>
Dan Handley9df48042015-03-19 18:58:55 +000011
12 .weak plat_secondary_cold_boot_setup
Soby Mathewfec4eb72015-07-01 16:16:20 +010013 .weak plat_get_my_entrypoint
David Wang323ebe82015-10-22 13:30:50 +080014 .globl css_calc_core_pos_swap_cluster
Soby Mathewfec4eb72015-07-01 16:16:20 +010015 .weak plat_is_my_cpu_primary
Dan Handley9df48042015-03-19 18:58:55 +000016
Sandrine Bailleux4c79d202015-04-29 16:28:52 +010017 /* ---------------------------------------------------------------------
18 * void plat_secondary_cold_boot_setup(void);
Dan Handley9df48042015-03-19 18:58:55 +000019 *
Sandrine Bailleux4c79d202015-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 Handley9df48042015-03-19 18:58:55 +000029 */
30func plat_secondary_cold_boot_setup
Sandrine Bailleux4c79d202015-04-29 16:28:52 +010031#ifndef EL3_PAYLOAD_BASE
32 /* TODO: Implement secondary CPU cold boot setup on CSS platforms */
Dan Handley9df48042015-03-19 18:58:55 +000033cb_panic:
34 b cb_panic
Sandrine Bailleux4c79d202015-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 Handley9df48042015-03-19 18:58:55 +000047endfunc plat_secondary_cold_boot_setup
48
Sandrine Bailleuxdaf9a9d2015-07-10 16:49:31 +010049 /* ---------------------------------------------------------------------
Soby Mathewa0fedc42016-06-16 14:52:04 +010050 * uintptr_t plat_get_my_entrypoint (void);
Dan Handley9df48042015-03-19 18:58:55 +000051 *
Sandrine Bailleuxdaf9a9d2015-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 Handley9df48042015-03-19 18:58:55 +000057 *
Sandrine Bailleuxdaf9a9d2015-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 Handley9df48042015-03-19 18:58:55 +000062 */
Soby Mathewfec4eb72015-07-01 16:16:20 +010063func plat_get_my_entrypoint
Soby Mathewfeac8fc2015-09-29 15:47:16 +010064 mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE
Sandrine Bailleuxdaf9a9d2015-07-10 16:49:31 +010065 ldr x0, [x0]
66 ret
Soby Mathewfec4eb72015-07-01 16:16:20 +010067endfunc plat_get_my_entrypoint
Dan Handley9df48042015-03-19 18:58:55 +000068
Soby Mathewfec4eb72015-07-01 16:16:20 +010069 /* -----------------------------------------------------------
Soby Mathewa0fedc42016-06-16 14:52:04 +010070 * unsigned int css_calc_core_pos_swap_cluster(u_register_t mpidr)
David Wang323ebe82015-10-22 13:30:50 +080071 * Utility function to calculate the core position by
Soby Mathewfec4eb72015-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 Matheweb3bbf12015-06-08 12:32:50 +010074 * and read in plat_is_my_cpu_primary below.
Soby Mathewfec4eb72015-07-01 16:16:20 +010075 * -----------------------------------------------------------
Dan Handley9df48042015-03-19 18:58:55 +000076 */
David Wang323ebe82015-10-22 13:30:50 +080077func css_calc_core_pos_swap_cluster
Dan Handley9df48042015-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 Wang323ebe82015-10-22 13:30:50 +080083endfunc css_calc_core_pos_swap_cluster
Dan Handley9df48042015-03-19 18:58:55 +000084
85 /* -----------------------------------------------------
Soby Mathewfec4eb72015-07-01 16:16:20 +010086 * unsigned int plat_is_my_cpu_primary (void);
Dan Handley9df48042015-03-19 18:58:55 +000087 *
Soby Mathewfec4eb72015-07-01 16:16:20 +010088 * Find out whether the current cpu is the primary
Dan Handley9df48042015-03-19 18:58:55 +000089 * cpu (applicable ony after a cold boot)
90 * -----------------------------------------------------
91 */
Soby Mathew1ced6b82017-06-12 12:37:10 +010092#if CSS_USE_SCMI_SDS_DRIVER
Soby Mathewfec4eb72015-07-01 16:16:20 +010093func plat_is_my_cpu_primary
Dan Handley9df48042015-03-19 18:58:55 +000094 mov x9, x30
Soby Mathewfec4eb72015-07-01 16:16:20 +010095 bl plat_my_core_pos
Soby Mathew1ced6b82017-06-12 12:37:10 +010096 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
109func plat_is_my_cpu_primary
110 mov x9, x30
111 bl plat_my_core_pos
Soby Mathewef81bc52018-10-12 17:08:28 +0100112 mov_imm x1, SCP_BOOT_CFG_ADDR
Dan Handley9df48042015-03-19 18:58:55 +0000113 ldr x1, [x1]
Vikram Kanigiri72084192016-02-08 16:29:30 +0000114 ubfx x1, x1, #PLAT_CSS_PRIMARY_CPU_SHIFT, \
115 #PLAT_CSS_PRIMARY_CPU_BIT_WIDTH
Dan Handley9df48042015-03-19 18:58:55 +0000116 cmp x0, x1
Soby Matheweb3bbf12015-06-08 12:32:50 +0100117 cset w0, eq
Dan Handley9df48042015-03-19 18:58:55 +0000118 ret x9
Soby Mathewfec4eb72015-07-01 16:16:20 +0100119endfunc plat_is_my_cpu_primary
Soby Mathew1ced6b82017-06-12 12:37:10 +0100120#endif