Home | History | Annotate | Download | only in Arm
      1 /** @file
      2 *
      3 *  Copyright (c) 2013-2014, ARM Limited. All rights reserved.
      4 *
      5 *  This program and the accompanying materials
      6 *  are licensed and made available under the terms and conditions of the BSD License
      7 *  which accompanies this distribution.  The full text of the license may be found at
      8 *  http://opensource.org/licenses/bsd-license.php
      9 *
     10 *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11 *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 *
     13 **/
     14 
     15 #include <AsmMacroIoLibV8.h>
     16 #include <Library/ArmLib.h>
     17 
     18 .text
     19 .align 3
     20 
     21 GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
     22 GCC_ASM_EXPORT(ArmPlatformGetCorePosition)
     23 GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId)
     24 GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore)
     25 
     26 GCC_ASM_IMPORT(_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask)
     27 
     28 
     29 PrimaryCoreMpid:  .word    0x0
     30 
     31 //
     32 // Return the core position from the value of its MpId register
     33 //
     34 // This function returns the core position from the position 0 in the processor.
     35 // This function might be called from assembler before any stack is set.
     36 //
     37 // @return   Return the core position
     38 //
     39 //UINTN
     40 //ArmPlatformGetCorePosition (
     41 //  IN UINTN MpId
     42 //  );
     43 // With this function: CorePos = (ClusterId * 2) + CoreId
     44 ASM_PFX(ArmPlatformGetCorePosition):
     45   and   r1, r0, #ARM_CORE_MASK
     46   and   r0, r0, #ARM_CLUSTER_MASK
     47   add   r0, r1, r0, LSR #7
     48   bx    lr
     49 
     50 //
     51 // Return the MpId of the primary core
     52 //
     53 // This function returns the MpId of the primary core.
     54 // This function might be called from assembler before any stack is set.
     55 //
     56 // @return   Return the MpId of the primary core
     57 //
     58 //UINTN
     59 //ArmPlatformGetPrimaryCoreMpId (
     60 //  VOID
     61 //  );
     62 ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
     63   ldr   r0, =PrimaryCoreMpid
     64   ldr   r0, [r0]
     65   bx    lr
     66 
     67 //
     68 // Return a non-zero value if the callee is the primary core
     69 //
     70 // This function returns a non-zero value if the callee is the primary core.
     71 // The primary core is the core responsible to initialize the hardware and run UEFI.
     72 // This function might be called from assembler before any stack is set.
     73 //
     74 //  @return   Return a non-zero value if the callee is the primary core.
     75 //
     76 //UINTN
     77 //ArmPlatformIsPrimaryCore (
     78 //  IN UINTN MpId
     79 //  );
     80 ASM_PFX(ArmPlatformIsPrimaryCore):
     81   LoadConstantToReg (_gPcd_FixedAtBuild_PcdArmPrimaryCoreMask, r1)
     82   ldr   r1, [r1]
     83   and   r0, r0, r1
     84 
     85   ldr   r1, =PrimaryCoreMpid
     86   ldr   r1, [r1]
     87 
     88   cmp   r0, r1
     89   moveq r0, #1
     90   movne r0, #0
     91   bx    lr
     92 
     93 //
     94 // First platform specific function to be called in the PEI phase
     95 //
     96 // This function is actually the first function called by the PrePi
     97 // or PrePeiCore modules. It allows to retrieve arguments passed to
     98 // the UEFI firmware through the CPU registers.
     99 //
    100 ASM_PFX(ArmPlatformPeiBootAction):
    101   // The trusted firmware passes the primary CPU MPID through r0 register.
    102   // Save it in a variable.
    103   ldr  r1, =PrimaryCoreMpid
    104   str  r0, [r1]
    105   bx   lr
    106