1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "scp_css_mmap.h"
9 #include "scp_software_mmap.h"
10 #include "tc0_core.h"
11 #include "tc0_dvfs.h"
12 #include "tc0_timer.h"
13 
14 #include <mod_traffic_cop.h>
15 
16 #include <fwk_macros.h>
17 #include <fwk_module.h>
18 #include <fwk_module_idx.h>
19 
20 enum core_pd_idx {
21     CORE0_PD_IDX,
22     CORE1_PD_IDX,
23     CORE2_PD_IDX,
24     CORE3_PD_IDX,
25     CORE4_PD_IDX,
26     CORE5_PD_IDX,
27     CORE6_PD_IDX,
28     CORE7_PD_IDX
29 };
30 
31 static struct mod_tcop_pct_table k_pct[] = {
32     {
33         /*
34          * Perf limit for 3 or 4 cores online.
35          * The first entry must be the maximum number of cores in this domain.
36          */
37         .cores_online = 4,
38         .perf_limit = 1153 * 1000000UL,
39     },
40     {
41         /* Perf limit for 1 or 2 cores online. */
42         .cores_online = 2,
43         .perf_limit = 1844 * 1000000UL,
44     },
45 };
46 
47 static struct mod_tcop_pct_table m_pct[] = {
48     {
49         /*
50          * Perf limit for 3 cores online.
51          * The first entry must be the maximum number of cores in this domain.
52          */
53         .cores_online = 3,
54         .perf_limit = 1893 * 1000000UL,
55     },
56     {
57         /* Perf limit for 2 cores online. */
58         .cores_online = 2,
59         .perf_limit = 2271 * 1000000UL,
60     },
61     {
62         /* Perf limit for 1 core online. */
63         .cores_online = 1,
64         .perf_limit = 2650 * 1000000UL,
65     },
66 };
67 
68 static const struct mod_tcop_core_config k_core_config[] = {
69     [0] = {
70         .pd_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_POWER_DOMAIN, CORE0_PD_IDX),
71         .core_starts_online = true,
72         },
73     [1] = {
74         .pd_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_POWER_DOMAIN, CORE1_PD_IDX),
75         .core_starts_online = false,
76         },
77     [2] = {
78         .pd_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_POWER_DOMAIN, CORE2_PD_IDX),
79         .core_starts_online = false,
80         },
81     [3] = {
82         .pd_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_POWER_DOMAIN, CORE3_PD_IDX),
83         .core_starts_online = false,
84         },
85 };
86 
87 static const struct mod_tcop_core_config m_core_config[] = {
88     [0] = {
89         .pd_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_POWER_DOMAIN, CORE4_PD_IDX),
90         .core_starts_online = false,
91         },
92     [1] = {
93         .pd_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_POWER_DOMAIN, CORE5_PD_IDX),
94         .core_starts_online = false,
95         },
96     [2] = {
97         .pd_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_POWER_DOMAIN, CORE6_PD_IDX),
98         .core_starts_online = false,
99         },
100 };
101 
102 static const struct mod_tcop_domain_config k_domain_conf[] = {
103     [0] = {
104         .perf_id = FWK_ID_ELEMENT_INIT(
105             FWK_MODULE_IDX_DVFS,
106             DVFS_ELEMENT_IDX_KLEIN),
107         .pct = k_pct,
108         .pct_size = FWK_ARRAY_SIZE(k_pct),
109         .core_config = k_core_config,
110     },
111     [1] = { { 0 } },
112 };
113 
114 static const struct mod_tcop_domain_config m_domain_conf[] = {
115     [0] = {
116         .perf_id = FWK_ID_ELEMENT_INIT(
117             FWK_MODULE_IDX_DVFS,
118             DVFS_ELEMENT_IDX_MATTERHORN),
119         .pct = m_pct,
120         .pct_size = FWK_ARRAY_SIZE(m_pct),
121         .core_config = m_core_config,
122     },
123     [1] = { { 0 } },
124 };
125 
126 static const struct fwk_element element_table[] = {
127     [0] = {
128         .name = "TCOP_KLEIN_ELEM",
129         .sub_element_count = 4,
130         .data = k_domain_conf,
131     },
132     [1] = {
133         .name = "TCOP_MATTERHORN_ELEM",
134         .sub_element_count = 3,
135         .data = m_domain_conf,
136     },
137     [2] = { 0 },
138 };
139 
tcop_get_element_table(fwk_id_t module_id)140 static const struct fwk_element *tcop_get_element_table(fwk_id_t module_id)
141 {
142     return element_table;
143 }
144 const struct fwk_module_config config_traffic_cop = {
145     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(tcop_get_element_table),
146 };
147