Soby Mathew | f6f2b7e | 2017-06-12 12:13:04 +0100 | [diff] [blame] | 1 | /* |
| 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 Diaz | 09d5876 | 2019-01-23 19:06:55 +0000 | [diff] [blame] | 9 | #include <drivers/arm/css/sds.h> |
Soby Mathew | f6f2b7e | 2017-06-12 12:13:04 +0100 | [diff] [blame] | 10 | #include <platform_def.h> |
Antonio Nino Diaz | 09d5876 | 2019-01-23 19:06:55 +0000 | [diff] [blame] | 11 | |
Soby Mathew | f6f2b7e | 2017-06-12 12:13:04 +0100 | [diff] [blame] | 12 | #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 | */ |
| 21 | func 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 |
| 39 | loop_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 |
| 47 | continue_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 |
| 61 | 2: |
| 62 | mov r0, #0xffffffff |
| 63 | bx lr |
| 64 | endfunc sds_get_primary_cpu_id |