Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 1 | /* |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 2 | * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved. |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 5 | */ |
Antonio Nino Diaz | a320ecd | 2019-01-15 14:19:50 +0000 | [diff] [blame] | 6 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 7 | #include <arch.h> |
| 8 | #include <asm_macros.S> |
| 9 | #include <cpu_macros.S> |
Antonio Nino Diaz | a320ecd | 2019-01-15 14:19:50 +0000 | [diff] [blame] | 10 | #include <platform_def.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 11 | |
| 12 | .weak plat_secondary_cold_boot_setup |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 13 | .weak plat_get_my_entrypoint |
David Wang | 323ebe8 | 2015-10-22 13:30:50 +0800 | [diff] [blame] | 14 | .globl css_calc_core_pos_swap_cluster |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 15 | .weak plat_is_my_cpu_primary |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 16 | |
Sandrine Bailleux | 4c79d20 | 2015-04-29 16:28:52 +0100 | [diff] [blame] | 17 | /* --------------------------------------------------------------------- |
| 18 | * void plat_secondary_cold_boot_setup(void); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 19 | * |
Sandrine Bailleux | 4c79d20 | 2015-04-29 16:28:52 +0100 | [diff] [blame] | 20 | * 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 Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 29 | */ |
| 30 | func plat_secondary_cold_boot_setup |
Sandrine Bailleux | 4c79d20 | 2015-04-29 16:28:52 +0100 | [diff] [blame] | 31 | #ifndef EL3_PAYLOAD_BASE |
| 32 | /* TODO: Implement secondary CPU cold boot setup on CSS platforms */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 33 | cb_panic: |
| 34 | b cb_panic |
Sandrine Bailleux | 4c79d20 | 2015-04-29 16:28:52 +0100 | [diff] [blame] | 35 | #else |
| 36 | mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE |
| 37 | |
| 38 | /* Wait until the mailbox gets populated */ |
| 39 | poll_mailbox: |
| 40 | ldr x1, [x0] |
| 41 | cbz x1, 1f |
| 42 | br x1 |
| 43 | 1: |
| 44 | wfe |
| 45 | b poll_mailbox |
| 46 | #endif /* EL3_PAYLOAD_BASE */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 47 | endfunc plat_secondary_cold_boot_setup |
| 48 | |
Sandrine Bailleux | daf9a9d | 2015-07-10 16:49:31 +0100 | [diff] [blame] | 49 | /* --------------------------------------------------------------------- |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 50 | * uintptr_t plat_get_my_entrypoint (void); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 51 | * |
Sandrine Bailleux | daf9a9d | 2015-07-10 16:49:31 +0100 | [diff] [blame] | 52 | * 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 Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 57 | * |
Sandrine Bailleux | daf9a9d | 2015-07-10 16:49:31 +0100 | [diff] [blame] | 58 | * 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 Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 62 | */ |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 63 | func plat_get_my_entrypoint |
Soby Mathew | feac8fc | 2015-09-29 15:47:16 +0100 | [diff] [blame] | 64 | mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE |
Sandrine Bailleux | daf9a9d | 2015-07-10 16:49:31 +0100 | [diff] [blame] | 65 | ldr x0, [x0] |
| 66 | ret |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 67 | endfunc plat_get_my_entrypoint |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 68 | |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 69 | /* ----------------------------------------------------------- |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 70 | * unsigned int css_calc_core_pos_swap_cluster(u_register_t mpidr) |
David Wang | 323ebe8 | 2015-10-22 13:30:50 +0800 | [diff] [blame] | 71 | * Utility function to calculate the core position by |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 72 | * swapping the cluster order. This is necessary in order to |
| 73 | * match the format of the boot information passed by the SCP |
Soby Mathew | eb3bbf1 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 74 | * and read in plat_is_my_cpu_primary below. |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 75 | * ----------------------------------------------------------- |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 76 | */ |
David Wang | 323ebe8 | 2015-10-22 13:30:50 +0800 | [diff] [blame] | 77 | func css_calc_core_pos_swap_cluster |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 78 | 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 Wang | 323ebe8 | 2015-10-22 13:30:50 +0800 | [diff] [blame] | 83 | endfunc css_calc_core_pos_swap_cluster |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 84 | |
| 85 | /* ----------------------------------------------------- |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 86 | * unsigned int plat_is_my_cpu_primary (void); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 87 | * |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 88 | * Find out whether the current cpu is the primary |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 89 | * cpu (applicable ony after a cold boot) |
| 90 | * ----------------------------------------------------- |
| 91 | */ |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 92 | #if CSS_USE_SCMI_SDS_DRIVER |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 93 | func plat_is_my_cpu_primary |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 94 | mov x9, x30 |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 95 | bl plat_my_core_pos |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 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 |
| 105 | 1: |
| 106 | no_ret plat_panic_handler |
| 107 | endfunc plat_is_my_cpu_primary |
| 108 | #else |
| 109 | func plat_is_my_cpu_primary |
| 110 | mov x9, x30 |
| 111 | bl plat_my_core_pos |
Soby Mathew | ef81bc5 | 2018-10-12 17:08:28 +0100 | [diff] [blame] | 112 | mov_imm x1, SCP_BOOT_CFG_ADDR |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 113 | ldr x1, [x1] |
Vikram Kanigiri | 7208419 | 2016-02-08 16:29:30 +0000 | [diff] [blame] | 114 | ubfx x1, x1, #PLAT_CSS_PRIMARY_CPU_SHIFT, \ |
| 115 | #PLAT_CSS_PRIMARY_CPU_BIT_WIDTH |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 116 | cmp x0, x1 |
Soby Mathew | eb3bbf1 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 117 | cset w0, eq |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 118 | ret x9 |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 119 | endfunc plat_is_my_cpu_primary |
Soby Mathew | 1ced6b8 | 2017-06-12 12:37:10 +0100 | [diff] [blame] | 120 | #endif |