1 /*
2 * Arm SCP/MCP Software
3 * Copyright (c) 2018-2021, Arm Limited and Contributors. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #include "config_clock.h"
9 #include "morello_pik_scp.h"
10 #include "morello_scp_pik.h"
11 #include "morello_scp_software_mmap.h"
12 #include "morello_sds.h"
13
14 #include <mod_sds.h>
15
16 #include <fwk_assert.h>
17 #include <fwk_element.h>
18 #include <fwk_id.h>
19 #include <fwk_macros.h>
20 #include <fwk_module.h>
21 #include <fwk_module_idx.h>
22
23 #include <stdbool.h>
24 #include <stdint.h>
25
26 static const uint32_t version_packed = FWK_BUILD_VERSION;
27 static const uint32_t feature_flags = 0x00000000;
28
29 static const struct mod_sds_region_desc sds_module_regions[] = {
30 [MORELLO_SDS_REGION_SECURE] =
31 {
32 .base = (void *)SCP_SDS_SECURE_BASE,
33 .size = SCP_SDS_SECURE_SIZE,
34 },
35 #ifdef BUILD_MODE_DEBUG
36 [MORELLO_SDS_REGION_NONSECURE] =
37 {
38 .base = (void *)SCP_SDS_NONSECURE_BASE,
39 .size = SCP_SDS_NONSECURE_SIZE,
40 },
41 #endif
42 };
43
44 static_assert(
45 FWK_ARRAY_SIZE(sds_module_regions) == MORELLO_SDS_REGION_COUNT,
46 "Mismatch between number of SDS regions and number of regions "
47 "provided by the SDS configuration.");
48
49 static const struct mod_sds_config sds_module_config = {
50 .regions = sds_module_regions,
51 .region_count = MORELLO_SDS_REGION_COUNT,
52 .clock_id =
53 FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_CLOCK, CLOCK_IDX_INTERCONNECT)
54 };
55
56 static struct fwk_element sds_element_table[] = {
57 {
58 .name = "CPU Info",
59 .data = &((struct mod_sds_structure_desc){
60 .id = MORELLO_SDS_CPU_INFO,
61 .size = MORELLO_SDS_CPU_INFO_SIZE,
62 .region_id = MORELLO_SDS_REGION_SECURE,
63 .finalize = true,
64 }),
65 },
66 {
67 .name = "Firmware version",
68 .data = &((struct mod_sds_structure_desc){
69 .id = MORELLO_SDS_FIRMWARE_VERSION,
70 .size = MORELLO_SDS_FIRMWARE_VERSION_SIZE,
71 .region_id = MORELLO_SDS_REGION_SECURE,
72 .payload = &version_packed,
73 .finalize = true,
74 }),
75 },
76 {
77 .name = "Reset Syndrome",
78 .data = &((struct mod_sds_structure_desc){
79 .id = MORELLO_SDS_RESET_SYNDROME,
80 .size = MORELLO_SDS_RESET_SYNDROME_SIZE,
81 .region_id = MORELLO_SDS_REGION_SECURE,
82 .payload = (void *)(&PIK_SCP->RESET_SYNDROME),
83 .finalize = true,
84 }),
85 },
86 {
87 .name = "Feature Availability",
88 .data = &((struct mod_sds_structure_desc){
89 .id = MORELLO_SDS_FEATURE_AVAILABILITY,
90 .size = MORELLO_SDS_FEATURE_AVAILABILITY_SIZE,
91 .region_id = MORELLO_SDS_REGION_SECURE,
92 .payload = &feature_flags,
93 .finalize = true,
94 }),
95 },
96 {
97 .name = "Platform Info",
98 .data = &((struct mod_sds_structure_desc){
99 .id = MORELLO_SDS_PLATFORM_INFO,
100 .size = MORELLO_SDS_PLATFORM_INFO_SIZE,
101 .region_id = MORELLO_SDS_REGION_SECURE,
102 .finalize = true,
103 }),
104 },
105 #ifdef BUILD_MODE_DEBUG
106 {
107 .name = "Boot Counters",
108 .data = &((struct mod_sds_structure_desc){
109 .id = MORELLO_SDS_CPU_BOOTCTR,
110 .size = MORELLO_SDS_CPU_BOOTCTR_SIZE,
111 .region_id = MORELLO_SDS_REGION_NONSECURE,
112 .finalize = true,
113 }),
114 },
115 {
116 .name = "CPU Flags",
117 .data = &((struct mod_sds_structure_desc){
118 .id = MORELLO_SDS_CPU_FLAGS,
119 .size = MORELLO_SDS_CPU_FLAGS_SIZE,
120 .region_id = MORELLO_SDS_REGION_NONSECURE,
121 .finalize = true,
122 }),
123 },
124 #endif
125 { 0 }, /* Termination description. */
126 };
127
128 static_assert(
129 SCP_SDS_SECURE_SIZE > MORELLO_SDS_CPU_INFO_SIZE +
130 MORELLO_SDS_FIRMWARE_VERSION_SIZE +
131 MORELLO_SDS_RESET_SYNDROME_SIZE +
132 MORELLO_SDS_FEATURE_AVAILABILITY_SIZE,
133 "SDS structures too large for SDS S-RAM.\n");
134
135 #ifdef BUILD_MODE_DEBUG
136 static_assert(
137 SCP_SDS_NONSECURE_SIZE >
138 MORELLO_SDS_CPU_BOOTCTR_SIZE + MORELLO_SDS_CPU_FLAGS_SIZE,
139 "SDS structures too large for SDS NS-RAM.\n");
140 #endif
141
sds_get_element_table(fwk_id_t module_id)142 static const struct fwk_element *sds_get_element_table(fwk_id_t module_id)
143 {
144 static_assert(BUILD_VERSION_MAJOR < UINT8_MAX, "Invalid version size");
145 static_assert(BUILD_VERSION_MINOR < UINT8_MAX, "Invalid version size");
146 static_assert(BUILD_VERSION_PATCH < UINT16_MAX, "Invalid version size");
147
148 return sds_element_table;
149 }
150
151 struct fwk_module_config config_sds = {
152 .elements = FWK_MODULE_DYNAMIC_ELEMENTS(sds_get_element_table),
153 .data = &sds_module_config,
154 };
155