blob: 0b08919f420f5b34030d2969faca558273614757 [file] [log] [blame]
Boyan Karatoteve7d7c272023-01-25 16:55:18 +00001/*
Arvind Ram Prakashe82f7592024-09-16 16:57:33 -05002 * Copyright (c) 2023-2025, Arm Limited and Contributors. All rights reserved.
Boyan Karatoteve7d7c272023-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
Boyan Karatoteve7d7c272023-01-25 16:55:18 +000024
25#if __aarch64__
26#define CPU_NO_EXTRA1_FUNC 0
27#define CPU_NO_EXTRA2_FUNC 0
28#define CPU_NO_EXTRA3_FUNC 0
Arvind Ram Prakashe82f7592024-09-16 16:57:33 -050029#define CPU_NO_EXTRA4_FUNC 0
Boyan Karatoteve7d7c272023-01-25 16:55:18 +000030#endif /* __aarch64__ */
31
32
33/*
34 * Define the sizes of the fields in the cpu_ops structure. Word size is set per
35 * Aarch so keep these definitions the same and each can include whatever it
36 * needs.
37 */
38#define CPU_MIDR_SIZE CPU_WORD_SIZE
39#ifdef IMAGE_AT_EL3
40#define CPU_RESET_FUNC_SIZE CPU_WORD_SIZE
41#else
42#define CPU_RESET_FUNC_SIZE 0
43#endif /* IMAGE_AT_EL3 */
44#define CPU_EXTRA1_FUNC_SIZE CPU_WORD_SIZE
45#define CPU_EXTRA2_FUNC_SIZE CPU_WORD_SIZE
46#define CPU_EXTRA3_FUNC_SIZE CPU_WORD_SIZE
Arvind Ram Prakashe82f7592024-09-16 16:57:33 -050047#define CPU_EXTRA4_FUNC_SIZE CPU_WORD_SIZE
Boyan Karatoteve7d7c272023-01-25 16:55:18 +000048#define CPU_E_HANDLER_FUNC_SIZE CPU_WORD_SIZE
49/* The power down core and cluster is needed only in BL31 and BL32 */
50#if defined(IMAGE_BL31) || defined(IMAGE_BL32)
51#define CPU_PWR_DWN_OPS_SIZE CPU_WORD_SIZE * CPU_MAX_PWR_DWN_OPS
52#else
53#define CPU_PWR_DWN_OPS_SIZE 0
54#endif /* defined(IMAGE_BL31) || defined(IMAGE_BL32) */
55
Boyan Karatotev821364e2023-01-27 09:35:10 +000056#define CPU_ERRATA_LIST_START_SIZE CPU_WORD_SIZE
57#define CPU_ERRATA_LIST_END_SIZE CPU_WORD_SIZE
Boyan Karatoteve7d7c272023-01-25 16:55:18 +000058/* Fields required to print errata status */
59#if REPORT_ERRATA
Boyan Karatotev821364e2023-01-27 09:35:10 +000060#define CPU_CPU_STR_SIZE CPU_WORD_SIZE
Boyan Karatoteve7d7c272023-01-25 16:55:18 +000061/* BL1 doesn't require mutual exclusion and printed flag. */
62#if defined(IMAGE_BL31) || defined(IMAGE_BL32)
63#define CPU_ERRATA_LOCK_SIZE CPU_WORD_SIZE
64#define CPU_ERRATA_PRINTED_SIZE CPU_WORD_SIZE
65#else
66#define CPU_ERRATA_LOCK_SIZE 0
67#define CPU_ERRATA_PRINTED_SIZE 0
68#endif /* defined(IMAGE_BL31) || defined(IMAGE_BL32) */
69#else
Boyan Karatotev821364e2023-01-27 09:35:10 +000070#define CPU_CPU_STR_SIZE 0
Boyan Karatoteve7d7c272023-01-25 16:55:18 +000071#define CPU_ERRATA_LOCK_SIZE 0
72#define CPU_ERRATA_PRINTED_SIZE 0
73#endif /* REPORT_ERRATA */
74
75#if defined(IMAGE_BL31) && CRASH_REPORTING
76#define CPU_REG_DUMP_SIZE CPU_WORD_SIZE
77#else
78#define CPU_REG_DUMP_SIZE 0
79#endif /* defined(IMAGE_BL31) && CRASH_REPORTING */
80
81
82/*
83 * Define the offsets to the fields in cpu_ops structure. Every offset is
84 * defined based on the offset and size of the previous field.
85 */
86#define CPU_MIDR 0
87#define CPU_RESET_FUNC CPU_MIDR + CPU_MIDR_SIZE
88#if __aarch64__
89#define CPU_EXTRA1_FUNC CPU_RESET_FUNC + CPU_RESET_FUNC_SIZE
90#define CPU_EXTRA2_FUNC CPU_EXTRA1_FUNC + CPU_EXTRA1_FUNC_SIZE
91#define CPU_EXTRA3_FUNC CPU_EXTRA2_FUNC + CPU_EXTRA2_FUNC_SIZE
Arvind Ram Prakashe82f7592024-09-16 16:57:33 -050092#define CPU_EXTRA4_FUNC CPU_EXTRA3_FUNC + CPU_EXTRA3_FUNC_SIZE
93#define CPU_E_HANDLER_FUNC CPU_EXTRA4_FUNC + CPU_EXTRA4_FUNC_SIZE
Boyan Karatoteve7d7c272023-01-25 16:55:18 +000094#define CPU_PWR_DWN_OPS CPU_E_HANDLER_FUNC + CPU_E_HANDLER_FUNC_SIZE
95#else
96#define CPU_PWR_DWN_OPS CPU_RESET_FUNC + CPU_RESET_FUNC_SIZE
97#endif /* __aarch64__ */
Boyan Karatotev821364e2023-01-27 09:35:10 +000098#define CPU_ERRATA_LIST_START CPU_PWR_DWN_OPS + CPU_PWR_DWN_OPS_SIZE
99#define CPU_ERRATA_LIST_END CPU_ERRATA_LIST_START + CPU_ERRATA_LIST_START_SIZE
Ryan Everett3f588c42024-05-14 14:47:09 +0100100#define CPU_CPU_STR CPU_ERRATA_LIST_END + CPU_ERRATA_LIST_END_SIZE
Boyan Karatotev821364e2023-01-27 09:35:10 +0000101#define CPU_ERRATA_LOCK CPU_CPU_STR + CPU_CPU_STR_SIZE
Boyan Karatoteve7d7c272023-01-25 16:55:18 +0000102#define CPU_ERRATA_PRINTED CPU_ERRATA_LOCK + CPU_ERRATA_LOCK_SIZE
103#if __aarch64__
104#define CPU_REG_DUMP CPU_ERRATA_PRINTED + CPU_ERRATA_PRINTED_SIZE
105#define CPU_OPS_SIZE CPU_REG_DUMP + CPU_REG_DUMP_SIZE
106#else
107#define CPU_OPS_SIZE CPU_ERRATA_PRINTED + CPU_ERRATA_PRINTED_SIZE
108#endif /* __aarch64__ */
109
Boyan Karatotev06236c92023-01-25 18:50:10 +0000110#ifndef __ASSEMBLER__
111#include <lib/cassert.h>
112#include <lib/spinlock.h>
113
114struct cpu_ops {
115 unsigned long midr;
116#ifdef IMAGE_AT_EL3
117 void (*reset_func)(void);
118#endif /* IMAGE_AT_EL3 */
119#if __aarch64__
120 void (*extra1_func)(void);
121 void (*extra2_func)(void);
122 void (*extra3_func)(void);
Arvind Ram Prakashe82f7592024-09-16 16:57:33 -0500123 void (*extra4_func)(void);
Boyan Karatotev06236c92023-01-25 18:50:10 +0000124 void (*e_handler_func)(long es);
125#endif /* __aarch64__ */
126#if (defined(IMAGE_BL31) || defined(IMAGE_BL32)) && CPU_MAX_PWR_DWN_OPS
127 void (*pwr_dwn_ops[CPU_MAX_PWR_DWN_OPS])(void);
128#endif /* (defined(IMAGE_BL31) || defined(IMAGE_BL32)) && CPU_MAX_PWR_DWN_OPS */
Boyan Karatotev821364e2023-01-27 09:35:10 +0000129 void *errata_list_start;
130 void *errata_list_end;
Boyan Karatotev06236c92023-01-25 18:50:10 +0000131#if REPORT_ERRATA
Boyan Karatotev821364e2023-01-27 09:35:10 +0000132 char *cpu_str;
Boyan Karatotev06236c92023-01-25 18:50:10 +0000133#if defined(IMAGE_BL31) || defined(IMAGE_BL32)
134 spinlock_t *errata_lock;
135 unsigned int *errata_reported;
136#endif /* defined(IMAGE_BL31) || defined(IMAGE_BL32) */
137#endif /* REPORT_ERRATA */
138#if defined(IMAGE_BL31) && CRASH_REPORTING
139 void (*reg_dump)(void);
140#endif /* defined(IMAGE_BL31) && CRASH_REPORTING */
141} __packed;
142
143CASSERT(sizeof(struct cpu_ops) == CPU_OPS_SIZE,
144 assert_cpu_ops_asm_c_different_sizes);
145
146long cpu_get_rev_var(void);
147void *get_cpu_ops_ptr(void);
148
149#endif /* __ASSEMBLER__ */
Boyan Karatoteve7d7c272023-01-25 16:55:18 +0000150#endif /* CPU_OPS_H */