Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <arch.h> |
| 32 | #include <asm_macros.S> |
| 33 | #include <assert_macros.S> |
| 34 | #include <platform_def.h> |
| 35 | |
| 36 | .globl plat_my_core_pos |
| 37 | .globl plat_get_my_entrypoint |
| 38 | .globl platform_mem_init |
| 39 | .globl plat_qemu_calc_core_pos |
| 40 | .globl plat_crash_console_init |
| 41 | .globl plat_crash_console_putc |
| 42 | .globl plat_secondary_cold_boot_setup |
| 43 | .globl plat_get_my_entrypoint |
| 44 | .globl plat_is_my_cpu_primary |
| 45 | |
| 46 | |
| 47 | func plat_my_core_pos |
| 48 | mrs x0, mpidr_el1 |
| 49 | b plat_qemu_calc_core_pos |
| 50 | endfunc plat_my_core_pos |
| 51 | |
| 52 | /* |
| 53 | * unsigned int plat_qemu_calc_core_pos(u_register_t mpidr); |
| 54 | * With this function: CorePos = (ClusterId * 4) + CoreId |
| 55 | */ |
| 56 | func plat_qemu_calc_core_pos |
| 57 | and x1, x0, #MPIDR_CPU_MASK |
| 58 | and x0, x0, #MPIDR_CLUSTER_MASK |
| 59 | add x0, x1, x0, LSR #6 |
| 60 | ret |
| 61 | endfunc plat_qemu_calc_core_pos |
| 62 | |
| 63 | /* ----------------------------------------------------- |
| 64 | * unsigned int plat_is_my_cpu_primary (void); |
| 65 | * |
| 66 | * Find out whether the current cpu is the primary |
| 67 | * cpu. |
| 68 | * ----------------------------------------------------- |
| 69 | */ |
| 70 | func plat_is_my_cpu_primary |
| 71 | mrs x0, mpidr_el1 |
| 72 | and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK) |
| 73 | cmp x0, #QEMU_PRIMARY_CPU |
| 74 | cset w0, eq |
| 75 | ret |
| 76 | endfunc plat_is_my_cpu_primary |
| 77 | |
| 78 | /* ----------------------------------------------------- |
| 79 | * void plat_secondary_cold_boot_setup (void); |
| 80 | * |
| 81 | * This function performs any platform specific actions |
| 82 | * needed for a secondary cpu after a cold reset e.g |
| 83 | * mark the cpu's presence, mechanism to place it in a |
| 84 | * holding pen etc. |
| 85 | * ----------------------------------------------------- |
| 86 | */ |
| 87 | func plat_secondary_cold_boot_setup |
| 88 | /* Calculate address of our hold entry */ |
| 89 | bl plat_my_core_pos |
| 90 | mov_imm x2, PLAT_QEMU_HOLD_BASE |
| 91 | |
| 92 | /* Wait until we have a go */ |
| 93 | poll_mailbox: |
| 94 | ldr x1, [x2, x0] |
| 95 | cbz x1, 1f |
| 96 | mov_imm x0, PLAT_QEMU_TRUSTED_MAILBOX_BASE |
| 97 | ldr x1, [x0] |
| 98 | br x1 |
| 99 | 1: |
| 100 | wfe |
| 101 | b poll_mailbox |
| 102 | endfunc plat_secondary_cold_boot_setup |
| 103 | |
| 104 | func plat_get_my_entrypoint |
| 105 | /* TODO support warm boot */ |
| 106 | mov x0, #0 |
| 107 | ret |
| 108 | endfunc plat_get_my_entrypoint |
| 109 | |
| 110 | func platform_mem_init |
| 111 | ret |
| 112 | endfunc platform_mem_init |
| 113 | |
| 114 | /* --------------------------------------------- |
| 115 | * int plat_crash_console_init(void) |
| 116 | * Function to initialize the crash console |
| 117 | * without a C Runtime to print crash report. |
| 118 | * Clobber list : x0, x1, x2 |
| 119 | * --------------------------------------------- |
| 120 | */ |
| 121 | func plat_crash_console_init |
| 122 | mov_imm x0, PLAT_QEMU_CRASH_UART_BASE |
| 123 | mov_imm x1, PLAT_QEMU_CRASH_UART_CLK_IN_HZ |
| 124 | mov_imm x2, PLAT_QEMU_CONSOLE_BAUDRATE |
| 125 | b console_core_init |
| 126 | endfunc plat_crash_console_init |
| 127 | |
| 128 | /* --------------------------------------------- |
| 129 | * int plat_crash_console_putc(int c) |
| 130 | * Function to print a character on the crash |
| 131 | * console without a C Runtime. |
| 132 | * Clobber list : x1, x2 |
| 133 | * --------------------------------------------- |
| 134 | */ |
| 135 | func plat_crash_console_putc |
| 136 | mov_imm x1, PLAT_QEMU_CRASH_UART_BASE |
| 137 | b console_core_putc |
| 138 | endfunc plat_crash_console_putc |
| 139 | |
| 140 | |