1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2017-2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "clock_devices.h"
9 #include "sgm776_mmap.h"
10 #include "sgm776_sds.h"
11 #include "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 feature_flags = SGM776_SDS_FEATURE_FIRMWARE_MASK;
26 static const uint32_t version_packed = FWK_BUILD_VERSION;
27 
28 static const struct mod_sds_region_desc sds_module_regions[] = {
29     [SGM776_SDS_REGION_SECURE] = {
30         .base = (void*)SDS_SECURE_BASE,
31         .size = SDS_SECURE_SIZE,
32     },
33 #ifdef BUILD_MODE_DEBUG
34     [SGM776_SDS_REGION_NONSECURE] = {
35         .base = (void *)SDS_NONSECURE_BASE,
36         .size = SDS_NONSECURE_SIZE,
37     },
38 #endif
39 };
40 
41 static_assert(FWK_ARRAY_SIZE(sds_module_regions) == SGM776_SDS_REGION_COUNT,
42               "Mismatch between number of SDS regions and number of regions "
43               "provided by the SDS configuration.");
44 
45 const struct mod_sds_config sds_module_config = {
46     .regions =  sds_module_regions,
47     .region_count = SGM776_SDS_REGION_COUNT,
48     .clock_id = FWK_ID_ELEMENT_INIT(
49                     FWK_MODULE_IDX_CLOCK,
50                     CLOCK_DEV_IDX_INTERCONNECT),
51 };
52 
53 static const struct fwk_element sds_element_table[] = {
54     {
55         .name = "RAM Version",
56         .data = &((struct mod_sds_structure_desc) {
57             .id = SGM776_SDS_RAM_VERSION,
58             .size = SGM776_SDS_RAM_VERSION_SIZE,
59             .payload = &version_packed,
60             .region_id = SGM776_SDS_REGION_SECURE,
61             .finalize = true,
62         }),
63     },
64     {
65         .name = "Feature Availability",
66         .data = &((struct mod_sds_structure_desc) {
67             .id = SGM776_SDS_FEATURE_AVAILABILITY,
68             .size = sizeof(feature_flags),
69             .payload = &feature_flags,
70             .region_id = SGM776_SDS_REGION_SECURE,
71             .finalize = true,
72         }),
73     },
74     { 0 }, /* Termination description. */
75 };
76 
77 static_assert(SDS_SECURE_SIZE >
78                     SGM776_SDS_RAM_VERSION_SIZE +
79                     sizeof(feature_flags),
80             "SDS structures too large for SDS S-RAM.\n");
81 
sds_get_element_table(fwk_id_t module_id)82 static const struct fwk_element *sds_get_element_table(fwk_id_t module_id)
83 {
84     return sds_element_table;
85 }
86 
87 const struct fwk_module_config config_sds = {
88     .data = &sds_module_config,
89     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(sds_get_element_table),
90 };
91