blob: 13ff0e186b47fb43a2f86deeecff637cb3a4ee1e [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>
Antonio Nino Diaz09d58762019-01-23 19:06:55 +00009#include <drivers/arm/css/sds.h>
Soby Mathewf6f2b7e2017-06-12 12:13:04 +010010#include <platform_def.h>
Antonio Nino Diaz09d58762019-01-23 19:06:55 +000011
Soby Mathewf6f2b7e2017-06-12 12:13:04 +010012#include "../sds_private.h"
13
14 .globl sds_get_primary_cpu_id
15
16 /*
17 * int sds_get_primary_cpu_id(void);
18 * Return the primary CPU ID from SDS Structure
19 * Returns CPUID on success or -1 on failure
20 */
21func sds_get_primary_cpu_id
22 ldr r0, =PLAT_ARM_SDS_MEM_BASE
23 ldr r2, =SDS_REGION_SIGNATURE
24 ldr r1, [r0]
25 ubfx r3, r1, #0, #16
26
27 /* Check if the SDS region signature found */
28 cmp r2, r3
29 bne 2f
30
31 /* Get the structure count from region descriptor in r1 */
32 ubfx r1, r1, #SDS_REGION_STRUCT_COUNT_SHIFT, #SDS_REGION_STRUCT_COUNT_WIDTH
33 cmp r1, #0
34 beq 2f
35 add r0, r0, #SDS_REGION_DESC_SIZE
36
37 /* Initialize the loop iterator count in r3 */
38 mov r3, #0
39loop_begin:
40 ldrh r2, [r0]
41 cmp r2, #SDS_AP_CPU_INFO_STRUCT_ID
42 bne continue_loop
43
44 /* We have found the required structure */
45 ldr r0, [r0,#(SDS_HEADER_SIZE + SDS_AP_CPU_INFO_PRIMARY_CPUID_OFFSET)]
46 bx lr
47continue_loop:
48 /* Increment the loop counter and exit loop if counter == structure count */
49 add r3, r3, #0x1
50 cmp r1, r3
51 beq 2f
52
53 /* Read the 2nd word in header */
54 ldr r2, [r0,#4]
55 /* Get the structure size from header */
56 ubfx r2, r2, #SDS_HEADER_STRUCT_SIZE_SHIFT, #SDS_HEADER_STRUCT_SIZE_WIDTH
57 /* Add the structure size and SDS HEADER SIZE to point to next header */
58 add r2, r2, #SDS_HEADER_SIZE
59 add r0, r0, r2
60 b loop_begin
612:
62 mov r0, #0xffffffff
63 bx lr
64endfunc sds_get_primary_cpu_id