1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2018-2022, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "config_clock.h"
9 #include "n1sdp_pik_scp.h"
10 #include "n1sdp_scp_pik.h"
11 #include "n1sdp_scp_software_mmap.h"
12 #include "n1sdp_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     [N1SDP_SDS_REGION_SECURE] = {
31         .base = (void*)SCP_SDS_SECURE_BASE,
32         .size = SCP_SDS_SECURE_SIZE,
33     },
34 #ifdef BUILD_MODE_DEBUG
35     [N1SDP_SDS_REGION_NONSECURE] = {
36         .base = (void *)SCP_SDS_NONSECURE_BASE,
37         .size = SCP_SDS_NONSECURE_SIZE,
38     },
39 #endif
40 };
41 
42 static_assert(FWK_ARRAY_SIZE(sds_module_regions) == N1SDP_SDS_REGION_COUNT,
43               "Mismatch between number of SDS regions and number of regions "
44               "provided by the SDS configuration.");
45 
46 static const struct mod_sds_config sds_module_config = {
47     .regions = sds_module_regions,
48     .region_count = N1SDP_SDS_REGION_COUNT,
49     .clock_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_CLOCK,
50                                     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 = N1SDP_SDS_CPU_INFO,
58             .size = N1SDP_SDS_CPU_INFO_SIZE,
59             .region_id = N1SDP_SDS_REGION_SECURE,
60             .finalize = true,
61         }),
62     },
63     {
64         .name = "Firmware version",
65         .data = &((struct mod_sds_structure_desc) {
66             .id = N1SDP_SDS_FIRMWARE_VERSION,
67             .size = N1SDP_SDS_FIRMWARE_VERSION_SIZE,
68             .region_id = N1SDP_SDS_REGION_SECURE,
69             .payload = &version_packed,
70             .finalize = true,
71         }),
72     },
73     {
74         .name = "Reset Syndrome",
75         .data = &((struct mod_sds_structure_desc) {
76             .id = N1SDP_SDS_RESET_SYNDROME,
77             .size = N1SDP_SDS_RESET_SYNDROME_SIZE,
78             .region_id = N1SDP_SDS_REGION_SECURE,
79             .payload = (void *)(&PIK_SCP->RESET_SYNDROME),
80             .finalize = true,
81         }),
82     },
83     {
84         .name = "Feature Availability",
85         .data = &((struct mod_sds_structure_desc) {
86             .id = N1SDP_SDS_FEATURE_AVAILABILITY,
87             .size = N1SDP_SDS_FEATURE_AVAILABILITY_SIZE,
88             .region_id = N1SDP_SDS_REGION_SECURE,
89             .payload = &feature_flags,
90             .finalize = true,
91         }),
92     },
93     {
94         .name = "Platform Info",
95         .data = &((struct mod_sds_structure_desc) {
96             .id = N1SDP_SDS_PLATFORM_INFO,
97             .size = N1SDP_SDS_PLATFORM_INFO_SIZE,
98             .region_id = N1SDP_SDS_REGION_SECURE,
99             .finalize = true,
100         }),
101     },
102 #ifdef BUILD_MODE_DEBUG
103     {
104         .name = "Boot Counters",
105         .data = &((struct mod_sds_structure_desc) {
106             .id = N1SDP_SDS_CPU_BOOTCTR,
107             .size = N1SDP_SDS_CPU_BOOTCTR_SIZE,
108             .region_id = N1SDP_SDS_REGION_NONSECURE,
109             .finalize = true,
110         }),
111     },
112     {
113         .name = "CPU Flags",
114         .data = &((struct mod_sds_structure_desc) {
115             .id = N1SDP_SDS_CPU_FLAGS,
116             .size = N1SDP_SDS_CPU_FLAGS_SIZE,
117             .region_id = N1SDP_SDS_REGION_NONSECURE,
118             .finalize = true,
119         }),
120     },
121 #endif
122     { 0 }, /* Termination description. */
123 };
124 
125 static_assert(SCP_SDS_SECURE_SIZE >
126                     N1SDP_SDS_CPU_INFO_SIZE +
127                     N1SDP_SDS_FIRMWARE_VERSION_SIZE +
128                     N1SDP_SDS_RESET_SYNDROME_SIZE +
129                     N1SDP_SDS_FEATURE_AVAILABILITY_SIZE,
130             "SDS structures too large for SDS S-RAM.\n");
131 
132 #ifdef BUILD_MODE_DEBUG
133     static_assert(SCP_SDS_NONSECURE_SIZE >
134                         N1SDP_SDS_CPU_BOOTCTR_SIZE +
135                         N1SDP_SDS_CPU_FLAGS_SIZE,
136                 "SDS structures too large for SDS NS-RAM.\n");
137 #endif
138 
sds_get_element_table(fwk_id_t module_id)139 static const struct fwk_element *sds_get_element_table(fwk_id_t module_id)
140 {
141     static_assert(BUILD_VERSION_MAJOR < UINT8_MAX, "Invalid version size");
142     static_assert(BUILD_VERSION_MINOR < UINT8_MAX, "Invalid version size");
143     static_assert(BUILD_VERSION_PATCH < UINT16_MAX, "Invalid version size");
144 
145     return sds_element_table;
146 }
147 
148 struct fwk_module_config config_sds = {
149     .data = &sds_module_config,
150     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(sds_get_element_table),
151 };
152