xref: /arm-trusted-firmware/drivers/arm/css/sds/aarch64/sds_helpers.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu *
4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu */
6*91f16700Schasinglulu
7*91f16700Schasinglulu#include <arch.h>
8*91f16700Schasinglulu#include <asm_macros.S>
9*91f16700Schasinglulu#include <drivers/arm/css/sds.h>
10*91f16700Schasinglulu#include <platform_def.h>
11*91f16700Schasinglulu
12*91f16700Schasinglulu#include "../sds_private.h"
13*91f16700Schasinglulu
14*91f16700Schasinglulu	.globl	sds_get_primary_cpu_id
15*91f16700Schasinglulu
16*91f16700Schasinglulu	/*
17*91f16700Schasinglulu	 * int sds_get_primary_cpu_id(void);
18*91f16700Schasinglulu	 * Return the primary CPI ID from SDS Structure
19*91f16700Schasinglulu	 * Returns CPUID on success or -1 on failure
20*91f16700Schasinglulu	 */
21*91f16700Schasinglulufunc sds_get_primary_cpu_id
22*91f16700Schasinglulu	mov_imm	x0, PLAT_ARM_SDS_MEM_BASE
23*91f16700Schasinglulu	mov	w2, #SDS_REGION_SIGNATURE
24*91f16700Schasinglulu	ldr	w1, [x0]
25*91f16700Schasinglulu
26*91f16700Schasinglulu	/* Check if the SDS region signature found */
27*91f16700Schasinglulu	cmp	w2, w1, uxth
28*91f16700Schasinglulu	b.ne	2f
29*91f16700Schasinglulu
30*91f16700Schasinglulu	/* Get the structure count from region descriptor in `w1 */
31*91f16700Schasinglulu	ubfx	w1, w1, #SDS_REGION_STRUCT_COUNT_SHIFT, #SDS_REGION_STRUCT_COUNT_WIDTH
32*91f16700Schasinglulu	cbz	w1, 2f
33*91f16700Schasinglulu	add	x0, x0, #SDS_REGION_DESC_SIZE
34*91f16700Schasinglulu
35*91f16700Schasinglulu	/* Initialize the loop iterator count in w3 */
36*91f16700Schasinglulu	mov	w3, #0
37*91f16700Schasinglululoop_begin:
38*91f16700Schasinglulu	ldrh	w2, [x0]
39*91f16700Schasinglulu	cmp	w2, #SDS_AP_CPU_INFO_STRUCT_ID
40*91f16700Schasinglulu	b.ne	continue_loop
41*91f16700Schasinglulu
42*91f16700Schasinglulu	/* We have found the required structure */
43*91f16700Schasinglulu	ldr	w0, [x0,#(SDS_HEADER_SIZE + SDS_AP_CPU_INFO_PRIMARY_CPUID_OFFSET)]
44*91f16700Schasinglulu	ret
45*91f16700Schasinglulucontinue_loop:
46*91f16700Schasinglulu	/* Increment the loop counter and exit loop if counter == structure count */
47*91f16700Schasinglulu	add	w3, w3, #0x1
48*91f16700Schasinglulu	cmp	w1, w3
49*91f16700Schasinglulu	b.eq	2f
50*91f16700Schasinglulu
51*91f16700Schasinglulu	/* Read the 2nd word in header */
52*91f16700Schasinglulu	ldr	w2, [x0,#4]
53*91f16700Schasinglulu	/* Get the structure size from header */
54*91f16700Schasinglulu	ubfx	x2, x2, #SDS_HEADER_STRUCT_SIZE_SHIFT, #SDS_HEADER_STRUCT_SIZE_WIDTH
55*91f16700Schasinglulu	/* Add the structure size and SDS HEADER SIZE to point to next header */
56*91f16700Schasinglulu	add	x2, x2, #SDS_HEADER_SIZE
57*91f16700Schasinglulu	add	x0, x0, x2
58*91f16700Schasinglulu	b	loop_begin
59*91f16700Schasinglulu2:
60*91f16700Schasinglulu	mov	w0, #0xffffffff
61*91f16700Schasinglulu	ret
62*91f16700Schasingluluendfunc sds_get_primary_cpu_id
63