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