sgi_helper.S 2.44 KB
Newer Older
1
/*
2
 * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
9
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arch.h>
#include <asm_macros.S>
#include <platform_def.h>
10
#include <cortex_a75.h>
11
#include <neoverse_n1.h>
12
#include <cpu_macros.S>
13
14

	.globl	plat_arm_calc_core_pos
15
	.globl	plat_reset_handler
16
17

	/* -----------------------------------------------------
18
19
20
	 * unsigned int plat_arm_calc_core_pos(u_register_t mpidr)
	 *
	 * Helper function to calculate the core position.
21
22
	 * (ChipId * PLAT_ARM_CLUSTER_COUNT *
	 *  CSS_SGI_MAX_CPUS_PER_CLUSTER * CSS_SGI_MAX_PE_PER_CPU) +
23
24
25
26
27
28
	 * (ClusterId * CSS_SGI_MAX_CPUS_PER_CLUSTER * CSS_SGI_MAX_PE_PER_CPU) +
	 * (CPUId * CSS_SGI_MAX_PE_PER_CPU) +
	 * ThreadId
	 *
	 * which can be simplified as:
	 *
29
30
31
	 * ((((ChipId * PLAT_ARM_CLUSTER_COUNT) + ClusterId) *
	 *   CSS_SGI_MAX_CPUS_PER_CLUSTER) + CPUId) * CSS_SGI_MAX_PE_PER_CPU +
	 * ThreadId
32
33
34
	 * ------------------------------------------------------
	 */

35
func plat_arm_calc_core_pos
36
	mov	x4, x0
37
38
39
40
41
42
43

	/*
	 * The MT bit in MPIDR is always set for SGI platforms
	 * and the affinity level 0 corresponds to thread affinity level.
	 */

	/* Extract individual affinity fields from MPIDR */
44
45
46
47
	ubfx    x0, x4, #MPIDR_AFF0_SHIFT, #MPIDR_AFFINITY_BITS
	ubfx    x1, x4, #MPIDR_AFF1_SHIFT, #MPIDR_AFFINITY_BITS
	ubfx    x2, x4, #MPIDR_AFF2_SHIFT, #MPIDR_AFFINITY_BITS
	ubfx    x3, x4, #MPIDR_AFF3_SHIFT, #MPIDR_AFFINITY_BITS
48
49

	/* Compute linear position */
50
51
	mov     x4, #PLAT_ARM_CLUSTER_COUNT
	madd    x2, x3, x4, x2
52
53
	mov     x4, #CSS_SGI_MAX_CPUS_PER_CLUSTER
	madd    x1, x2, x4, x1
54
55
	mov     x4, #CSS_SGI_MAX_PE_PER_CPU
	madd    x0, x1, x4, x0
56
57
	ret
endfunc plat_arm_calc_core_pos
58
59
60
61
62
63
64
65
66
67

	/* -----------------------------------------------------
	 * void plat_reset_handler(void);
	 *
	 * Determine the CPU MIDR and disable power down bit for
	 * that CPU.
	 * -----------------------------------------------------
	 */
func plat_reset_handler
	jump_if_cpu_midr CORTEX_A75_MIDR, A75
68
	jump_if_cpu_midr NEOVERSE_N1_MIDR, N1
69
70
71
72
73
74
75
76
77
78
79
80
	ret

	/* -----------------------------------------------------
	 * Disable CPU power down bit in power control register
	 * -----------------------------------------------------
	 */
A75:
	mrs	x0, CORTEX_A75_CPUPWRCTLR_EL1
	bic	x0, x0, #CORTEX_A75_CORE_PWRDN_EN_MASK
	msr	CORTEX_A75_CPUPWRCTLR_EL1, x0
	isb
	ret
81

82
83
84
85
N1:
	mrs	x0, NEOVERSE_N1_CPUPWRCTLR_EL1
	bic	x0, x0, #NEOVERSE_N1_CORE_PWRDN_EN_MASK
	msr	NEOVERSE_N1_CPUPWRCTLR_EL1, x0
86
87
	isb
	ret
88
endfunc plat_reset_handler