blob: 3fce66a896f22a915617c29e9852f483620825a8 [file] [log] [blame]
Boyan Karatotev49d12002023-01-25 16:55:18 +00001/*
Arvind Ram Prakash8fc0fa72024-09-16 16:57:33 -05002 * Copyright (c) 2023-2025, Arm Limited and Contributors. All rights reserved.
Boyan Karatotev49d12002023-01-25 16:55:18 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef CPU_OPS_H
8#define CPU_OPS_H
9
10#include <arch.h>
11
12#define CPU_IMPL_PN_MASK (MIDR_IMPL_MASK << MIDR_IMPL_SHIFT) | \
13 (MIDR_PN_MASK << MIDR_PN_SHIFT)
14
15/* Hardcode to keep compatible with assembly. sizeof(uintptr_t) */
16#if __aarch64__
17#define CPU_WORD_SIZE 8
18#else
19#define CPU_WORD_SIZE 4
20#endif /* __aarch64__ */
21
22/* The number of CPU operations allowed */
23#define CPU_MAX_PWR_DWN_OPS 2
24/* Special constant to specify that CPU has no reset function */
25#define CPU_NO_RESET_FUNC 0
26
27#if __aarch64__
28#define CPU_NO_EXTRA1_FUNC 0
29#define CPU_NO_EXTRA2_FUNC 0
30#define CPU_NO_EXTRA3_FUNC 0
Arvind Ram Prakash8fc0fa72024-09-16 16:57:33 -050031#define CPU_NO_EXTRA4_FUNC 0
Boyan Karatotev49d12002023-01-25 16:55:18 +000032#endif /* __aarch64__ */
33
34
35/*
36 * Define the sizes of the fields in the cpu_ops structure. Word size is set per
37 * Aarch so keep these definitions the same and each can include whatever it
38 * needs.
39 */
40#define CPU_MIDR_SIZE CPU_WORD_SIZE
41#ifdef IMAGE_AT_EL3
42#define CPU_RESET_FUNC_SIZE CPU_WORD_SIZE
43#else
44#define CPU_RESET_FUNC_SIZE 0
45#endif /* IMAGE_AT_EL3 */
46#define CPU_EXTRA1_FUNC_SIZE CPU_WORD_SIZE
47#define CPU_EXTRA2_FUNC_SIZE CPU_WORD_SIZE
48#define CPU_EXTRA3_FUNC_SIZE CPU_WORD_SIZE
Arvind Ram Prakash8fc0fa72024-09-16 16:57:33 -050049#define CPU_EXTRA4_FUNC_SIZE CPU_WORD_SIZE
Boyan Karatotev49d12002023-01-25 16:55:18 +000050#define CPU_E_HANDLER_FUNC_SIZE CPU_WORD_SIZE
51/* The power down core and cluster is needed only in BL31 and BL32 */
52#if defined(IMAGE_BL31) || defined(IMAGE_BL32)
53#define CPU_PWR_DWN_OPS_SIZE CPU_WORD_SIZE * CPU_MAX_PWR_DWN_OPS
54#else
55#define CPU_PWR_DWN_OPS_SIZE 0
56#endif /* defined(IMAGE_BL31) || defined(IMAGE_BL32) */
57
Boyan Karatotev0fe4e972023-01-27 09:35:10 +000058#define CPU_ERRATA_LIST_START_SIZE CPU_WORD_SIZE
59#define CPU_ERRATA_LIST_END_SIZE CPU_WORD_SIZE
Boyan Karatotev49d12002023-01-25 16:55:18 +000060/* Fields required to print errata status */
61#if REPORT_ERRATA
62#define CPU_ERRATA_FUNC_SIZE CPU_WORD_SIZE
Boyan Karatotev0fe4e972023-01-27 09:35:10 +000063#define CPU_CPU_STR_SIZE CPU_WORD_SIZE
Boyan Karatotev49d12002023-01-25 16:55:18 +000064/* BL1 doesn't require mutual exclusion and printed flag. */
65#if defined(IMAGE_BL31) || defined(IMAGE_BL32)
66#define CPU_ERRATA_LOCK_SIZE CPU_WORD_SIZE
67#define CPU_ERRATA_PRINTED_SIZE CPU_WORD_SIZE
68#else
69#define CPU_ERRATA_LOCK_SIZE 0
70#define CPU_ERRATA_PRINTED_SIZE 0
71#endif /* defined(IMAGE_BL31) || defined(IMAGE_BL32) */
72#else
73#define CPU_ERRATA_FUNC_SIZE 0
Boyan Karatotev0fe4e972023-01-27 09:35:10 +000074#define CPU_CPU_STR_SIZE 0
Boyan Karatotev49d12002023-01-25 16:55:18 +000075#define CPU_ERRATA_LOCK_SIZE 0
76#define CPU_ERRATA_PRINTED_SIZE 0
77#endif /* REPORT_ERRATA */
78
79#if defined(IMAGE_BL31) && CRASH_REPORTING
80#define CPU_REG_DUMP_SIZE CPU_WORD_SIZE
81#else
82#define CPU_REG_DUMP_SIZE 0
83#endif /* defined(IMAGE_BL31) && CRASH_REPORTING */
84
85
86/*
87 * Define the offsets to the fields in cpu_ops structure. Every offset is
88 * defined based on the offset and size of the previous field.
89 */
90#define CPU_MIDR 0
91#define CPU_RESET_FUNC CPU_MIDR + CPU_MIDR_SIZE
92#if __aarch64__
93#define CPU_EXTRA1_FUNC CPU_RESET_FUNC + CPU_RESET_FUNC_SIZE
94#define CPU_EXTRA2_FUNC CPU_EXTRA1_FUNC + CPU_EXTRA1_FUNC_SIZE
95#define CPU_EXTRA3_FUNC CPU_EXTRA2_FUNC + CPU_EXTRA2_FUNC_SIZE
Arvind Ram Prakash8fc0fa72024-09-16 16:57:33 -050096#define CPU_EXTRA4_FUNC CPU_EXTRA3_FUNC + CPU_EXTRA3_FUNC_SIZE
97#define CPU_E_HANDLER_FUNC CPU_EXTRA4_FUNC + CPU_EXTRA4_FUNC_SIZE
Boyan Karatotev49d12002023-01-25 16:55:18 +000098#define CPU_PWR_DWN_OPS CPU_E_HANDLER_FUNC + CPU_E_HANDLER_FUNC_SIZE
99#else
100#define CPU_PWR_DWN_OPS CPU_RESET_FUNC + CPU_RESET_FUNC_SIZE
101#endif /* __aarch64__ */
Boyan Karatotev0fe4e972023-01-27 09:35:10 +0000102#define CPU_ERRATA_LIST_START CPU_PWR_DWN_OPS + CPU_PWR_DWN_OPS_SIZE
103#define CPU_ERRATA_LIST_END CPU_ERRATA_LIST_START + CPU_ERRATA_LIST_START_SIZE
104#define CPU_ERRATA_FUNC CPU_ERRATA_LIST_END + CPU_ERRATA_LIST_END_SIZE
105#define CPU_CPU_STR CPU_ERRATA_FUNC + CPU_ERRATA_FUNC_SIZE
106#define CPU_ERRATA_LOCK CPU_CPU_STR + CPU_CPU_STR_SIZE
Boyan Karatotev49d12002023-01-25 16:55:18 +0000107#define CPU_ERRATA_PRINTED CPU_ERRATA_LOCK + CPU_ERRATA_LOCK_SIZE
108#if __aarch64__
109#define CPU_REG_DUMP CPU_ERRATA_PRINTED + CPU_ERRATA_PRINTED_SIZE
110#define CPU_OPS_SIZE CPU_REG_DUMP + CPU_REG_DUMP_SIZE
111#else
112#define CPU_OPS_SIZE CPU_ERRATA_PRINTED + CPU_ERRATA_PRINTED_SIZE
113#endif /* __aarch64__ */
114
Boyan Karatotev30abae02023-01-25 18:50:10 +0000115#ifndef __ASSEMBLER__
116#include <lib/cassert.h>
117#include <lib/spinlock.h>
118
119struct cpu_ops {
120 unsigned long midr;
121#ifdef IMAGE_AT_EL3
122 void (*reset_func)(void);
123#endif /* IMAGE_AT_EL3 */
124#if __aarch64__
125 void (*extra1_func)(void);
126 void (*extra2_func)(void);
127 void (*extra3_func)(void);
Arvind Ram Prakash8fc0fa72024-09-16 16:57:33 -0500128 void (*extra4_func)(void);
Boyan Karatotev30abae02023-01-25 18:50:10 +0000129 void (*e_handler_func)(long es);
130#endif /* __aarch64__ */
131#if (defined(IMAGE_BL31) || defined(IMAGE_BL32)) && CPU_MAX_PWR_DWN_OPS
132 void (*pwr_dwn_ops[CPU_MAX_PWR_DWN_OPS])(void);
133#endif /* (defined(IMAGE_BL31) || defined(IMAGE_BL32)) && CPU_MAX_PWR_DWN_OPS */
Boyan Karatotev0fe4e972023-01-27 09:35:10 +0000134 void *errata_list_start;
135 void *errata_list_end;
Boyan Karatotev30abae02023-01-25 18:50:10 +0000136#if REPORT_ERRATA
137 void (*errata_func)(void);
Boyan Karatotev0fe4e972023-01-27 09:35:10 +0000138 char *cpu_str;
Boyan Karatotev30abae02023-01-25 18:50:10 +0000139#if defined(IMAGE_BL31) || defined(IMAGE_BL32)
140 spinlock_t *errata_lock;
141 unsigned int *errata_reported;
142#endif /* defined(IMAGE_BL31) || defined(IMAGE_BL32) */
143#endif /* REPORT_ERRATA */
144#if defined(IMAGE_BL31) && CRASH_REPORTING
145 void (*reg_dump)(void);
146#endif /* defined(IMAGE_BL31) && CRASH_REPORTING */
147} __packed;
148
149CASSERT(sizeof(struct cpu_ops) == CPU_OPS_SIZE,
150 assert_cpu_ops_asm_c_different_sizes);
151
152long cpu_get_rev_var(void);
153void *get_cpu_ops_ptr(void);
154
155#endif /* __ASSEMBLER__ */
Boyan Karatotev49d12002023-01-25 16:55:18 +0000156#endif /* CPU_OPS_H */