blob: f68cb35f1ef882672eeb3176205f10f6b9fab7de [file] [log] [blame]
Soby Mathewf6f2b7e2017-06-12 12:13:04 +01001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <platform_def.h>
10#include "../sds.h"
11#include "../sds_private.h"
12
13 .globl sds_get_primary_cpu_id
14
15 /*
16 * int sds_get_primary_cpu_id(void);
17 * Return the primary CPU ID from SDS Structure
18 * Returns CPUID on success or -1 on failure
19 */
20func sds_get_primary_cpu_id
21 ldr r0, =PLAT_ARM_SDS_MEM_BASE
22 ldr r2, =SDS_REGION_SIGNATURE
23 ldr r1, [r0]
24 ubfx r3, r1, #0, #16
25
26 /* Check if the SDS region signature found */
27 cmp r2, r3
28 bne 2f
29
30 /* Get the structure count from region descriptor in r1 */
31 ubfx r1, r1, #SDS_REGION_STRUCT_COUNT_SHIFT, #SDS_REGION_STRUCT_COUNT_WIDTH
32 cmp r1, #0
33 beq 2f
34 add r0, r0, #SDS_REGION_DESC_SIZE
35
36 /* Initialize the loop iterator count in r3 */
37 mov r3, #0
38loop_begin:
39 ldrh r2, [r0]
40 cmp r2, #SDS_AP_CPU_INFO_STRUCT_ID
41 bne continue_loop
42
43 /* We have found the required structure */
44 ldr r0, [r0,#(SDS_HEADER_SIZE + SDS_AP_CPU_INFO_PRIMARY_CPUID_OFFSET)]
45 bx lr
46continue_loop:
47 /* Increment the loop counter and exit loop if counter == structure count */
48 add r3, r3, #0x1
49 cmp r1, r3
50 beq 2f
51
52 /* Read the 2nd word in header */
53 ldr r2, [r0,#4]
54 /* Get the structure size from header */
55 ubfx r2, r2, #SDS_HEADER_STRUCT_SIZE_SHIFT, #SDS_HEADER_STRUCT_SIZE_WIDTH
56 /* Add the structure size and SDS HEADER SIZE to point to next header */
57 add r2, r2, #SDS_HEADER_SIZE
58 add r0, r0, r2
59 b loop_begin
602:
61 mov r0, #0xffffffff
62 bx lr
63endfunc sds_get_primary_cpu_id