blob: 3b9c562d0b211cb2254a49416035027177da20f4 [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 CPI ID from SDS Structure
18 * Returns CPUID on success or -1 on failure
19 */
20func sds_get_primary_cpu_id
21 mov_imm x0, PLAT_ARM_SDS_MEM_BASE
22 mov w2, #SDS_REGION_SIGNATURE
23 ldr w1, [x0]
24
25 /* Check if the SDS region signature found */
26 cmp w2, w1, uxth
27 b.ne 2f
28
29 /* Get the structure count from region descriptor in `w1 */
30 ubfx w1, w1, #SDS_REGION_STRUCT_COUNT_SHIFT, #SDS_REGION_STRUCT_COUNT_WIDTH
31 cbz w1, 2f
32 add x0, x0, #SDS_REGION_DESC_SIZE
33
34 /* Initialize the loop iterator count in w3 */
35 mov w3, #0
36loop_begin:
37 ldrh w2, [x0]
38 cmp w2, #SDS_AP_CPU_INFO_STRUCT_ID
39 b.ne continue_loop
40
41 /* We have found the required structure */
42 ldr w0, [x0,#(SDS_HEADER_SIZE + SDS_AP_CPU_INFO_PRIMARY_CPUID_OFFSET)]
43 ret
44continue_loop:
45 /* Increment the loop counter and exit loop if counter == structure count */
46 add w3, w3, #0x1
47 cmp w1, w3
48 b.eq 2f
49
50 /* Read the 2nd word in header */
51 ldr w2, [x0,#4]
52 /* Get the structure size from header */
53 ubfx x2, x2, #SDS_HEADER_STRUCT_SIZE_SHIFT, #SDS_HEADER_STRUCT_SIZE_WIDTH
54 /* Add the structure size and SDS HEADER SIZE to point to next header */
55 add x2, x2, #SDS_HEADER_SIZE
56 add x0, x0, x2
57 b loop_begin
582:
59 mov w0, #0xffffffff
60 ret
61endfunc sds_get_primary_cpu_id