1//
2//  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
3//
4//  This program and the accompanying materials
5//  are licensed and made available under the terms and conditions of the BSD License
6//  which accompanies this distribution.  The full text of the license may be found at
7//  http://opensource.org/licenses/bsd-license.php
8//
9//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11//
12//
13
14
15/* Secondary core pens for AArch64 Linux booting.
16
17   This code it placed in Linux kernel memory and marked reserved. UEFI ensures
18   that the secondary cores get to this pen and the kernel can then start the
19   cores from here.
20   NOTE: This code must be self-contained.
21*/
22
23#include <Library/ArmLib.h>
24
25.text
26.align 3
27
28GCC_ASM_EXPORT(SecondariesPenStart)
29ASM_GLOBAL SecondariesPenEnd
30
31ASM_PFX(SecondariesPenStart):
32   // Registers x0-x3 are reserved for future use and should be set to zero.
33   mov x0, xzr
34   mov x1, xzr
35   mov x2, xzr
36   mov x3, xzr
37
38   // Get core position. Taken from ArmPlatformGetCorePosition().
39   // Assumes max 4 cores per cluster.
40   mrs x4, mpidr_el1             // Get MPCore register.
41   and x5, x4, #ARM_CORE_MASK    // Get core number.
42   and x4, x4, #ARM_CLUSTER_MASK // Get cluster number.
43   add x4, x5, x4, LSR #6        // Add scaled cluster number to core number.
44   lsl x4, x4, 3            // Get mailbox offset for this core.
45   ldr x5, AsmMailboxbase   // Get mailbox addr relative to pc (36 bytes ahead).
46   add x4, x4, x5           // Add core mailbox offset to base of mailbox.
471: ldr x5, [x4]             // Load value from mailbox.
48   cmp xzr, x5              // Has the mailbox been set?
49   b.ne 2f                  // If so break out of loop.
50   wfe                      // If not, wait a bit.
51   b 1b                     // Wait over, check if mailbox set again.
522: br x5                    // Jump to mailbox value.
53
54.align 3 // Make sure the variable below is 8 byte aligned.
55                .global     AsmMailboxbase
56AsmMailboxbase: .xword      0xdeaddeadbeefbeef
57
58SecondariesPenEnd:
59