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 "config_power_domain.h"
9 #include "platform_core.h"
10 #include "scp_css_mmap.h"
11
12 #include <mod_power_domain.h>
13 #include <mod_ppu_v1.h>
14
15 #include <fwk_element.h>
16 #include <fwk_id.h>
17 #include <fwk_interrupt.h>
18 #include <fwk_macros.h>
19 #include <fwk_mm.h>
20 #include <fwk_module.h>
21 #include <fwk_module_idx.h>
22
23 #include <stdio.h>
24 #include <string.h>
25
26 /* Maximum PPU core name size including the null terminator */
27 #define PPU_CORE_NAME_SIZE 12
28
29 /* Maximum PPU cluster name size including the null terminator */
30 #define PPU_CLUS_NAME_SIZE 7
31
32 /* Module configuration data */
33 static struct mod_ppu_v1_config ppu_v1_config_data = {
34 .pd_notification_id = FWK_ID_NOTIFICATION_INIT(
35 FWK_MODULE_IDX_POWER_DOMAIN,
36 MOD_PD_NOTIFICATION_IDX_POWER_STATE_TRANSITION),
37 };
38
39 static struct fwk_element ppu_v1_system_element_table[] = {
40 [0] = {
41 .name = "SYS0",
42 .data = &((struct mod_ppu_v1_pd_config) {
43 .pd_type = MOD_PD_TYPE_SYSTEM,
44 .ppu.reg_base = SCP_PPU_SYS0_BASE,
45 .observer_id = FWK_ID_NONE_INIT,
46 }),
47 },
48 };
49
ppu_v1_get_element_table(fwk_id_t module_id)50 static const struct fwk_element *ppu_v1_get_element_table(fwk_id_t module_id)
51 {
52 struct fwk_element *element_table, *element;
53 struct mod_ppu_v1_pd_config *pd_config_table, *pd_config;
54 unsigned int core_idx;
55 unsigned int cluster_idx;
56 unsigned int core_count;
57 unsigned int cluster_count;
58 unsigned int core_element_count = 0;
59
60 core_count = platform_get_core_count();
61 cluster_count = platform_get_cluster_count();
62
63 /*
64 * Allocate element descriptors based on:
65 * Number of cores
66 * + Number of cluster descriptors
67 * + Number of system power domain descriptors
68 * + 1 terminator descriptor
69 */
70 element_table = fwk_mm_calloc(
71 core_count + cluster_count +
72 FWK_ARRAY_SIZE(ppu_v1_system_element_table) + 1,
73 sizeof(struct fwk_element));
74
75 pd_config_table = fwk_mm_calloc(
76 core_count + cluster_count, sizeof(struct mod_ppu_v1_pd_config));
77
78 for (cluster_idx = 0; cluster_idx < cluster_count; cluster_idx++) {
79 for (core_idx = 0;
80 core_idx < platform_get_core_per_cluster_count(cluster_idx);
81 core_idx++) {
82 element = &element_table[core_element_count];
83 pd_config = &pd_config_table[core_element_count];
84
85 element->name = fwk_mm_alloc(PPU_CORE_NAME_SIZE, 1);
86
87 snprintf(
88 (char *)element->name,
89 PPU_CORE_NAME_SIZE,
90 "CLUS%uCORE%u",
91 cluster_idx,
92 core_idx);
93
94 element->data = pd_config;
95
96 pd_config->pd_type = MOD_PD_TYPE_CORE;
97 pd_config->ppu.reg_base = SCP_CORE_PPU_BASE(cluster_idx);
98 pd_config->ppu.irq = FWK_INTERRUPT_NONE;
99 pd_config->cluster_id = FWK_ID_ELEMENT(
100 FWK_MODULE_IDX_PPU_V1, (core_count + cluster_idx));
101 pd_config->observer_id = FWK_ID_NONE;
102 core_element_count++;
103 }
104
105 element = &element_table[core_count + cluster_idx];
106 pd_config = &pd_config_table[core_count + cluster_idx];
107
108 element->name = fwk_mm_alloc(PPU_CLUS_NAME_SIZE, 1);
109
110 snprintf(
111 (char *)element->name, PPU_CLUS_NAME_SIZE, "CLUS%u", cluster_idx);
112
113 element->data = pd_config;
114
115 pd_config->pd_type = MOD_PD_TYPE_CLUSTER;
116 pd_config->ppu.reg_base = SCP_CLUSTER_PPU_BASE(cluster_idx);
117 pd_config->ppu.irq = FWK_INTERRUPT_NONE;
118 pd_config->observer_id = FWK_ID_NONE;
119 pd_config->observer_api = FWK_ID_NONE;
120 }
121
122 memcpy(
123 &element_table[core_count + cluster_count],
124 ppu_v1_system_element_table,
125 sizeof(ppu_v1_system_element_table));
126
127 /*
128 * Configure pd_source_id with the SYSTOP identifier from the power domain
129 * module which is dynamically defined based on the number of cores.
130 */
131 ppu_v1_config_data.pd_source_id = fwk_id_build_element_id(
132 fwk_module_id_power_domain,
133 core_count + cluster_count + PD_STATIC_DEV_IDX_SYSTOP);
134
135 return element_table;
136 }
137
138 /*
139 * Power module configuration data
140 */
141 const struct fwk_module_config config_ppu_v1 = {
142 .data = &ppu_v1_config_data,
143 .elements = FWK_MODULE_DYNAMIC_ELEMENTS(ppu_v1_get_element_table),
144 };
145