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 "morello_scp_scmi.h"
9 
10 #include <mod_resource_perms.h>
11 #include <mod_scmi_std.h>
12 
13 #include <fwk_element.h>
14 #include <fwk_id.h>
15 #include <fwk_macros.h>
16 #include <fwk_module.h>
17 #include <fwk_module_idx.h>
18 
19 /*!
20  * If the agent wants to modify permissions at run-time these tables
21  * must be allocated in writable memory.
22  */
23 
24 #define AGENT_IDX(agent_id) (agent_id - 1)
25 
26 static struct mod_res_agent_protocol_permissions agent_protocol_permissions[2] =
27     {
28         [AGENT_IDX(SCP_SCMI_AGENT_ID_OSPM)] =
29             {
30                 .protocols = MOD_RES_PERMS_SCMI_ALL_PROTOCOLS_ALLOWED,
31             },
32 
33         /* PSCI agent has no access to clock, perf and sensor protocol */
34         [AGENT_IDX(SCP_SCMI_AGENT_ID_PSCI)] =
35             {
36                 .protocols = MOD_RES_PERMS_SCMI_CLOCK_PROTOCOL_DENIED |
37                     MOD_RES_PERMS_SCMI_PERF_PROTOCOL_DENIED |
38                     MOD_RES_PERMS_SCMI_SENSOR_PROTOCOL_DENIED,
39             },
40     };
41 
42 /*
43  * Messages have an index offset from 0x3 as all agents can access
44  * the VERSION/ATTRIBUTES/MSG_ATTRIBUTES messages for all
45  * protocols, hence message 0x3 maps to bit[0], message 0x4 maps
46  * to bit[1], etc.
47  */
48 static struct mod_res_agent_msg_permissions
49     agent_msg_permissions[2] =
50         {
51             [AGENT_IDX(SCP_SCMI_AGENT_ID_OSPM)] =
52                 {
53                     /* Example, Base, disable unused msg 12 */
54                     .messages[MOD_RES_PERMS_SCMI_BASE_MESSAGE_IDX] = 0x0,
55                     /* Power Domain */
56                     .messages[MOD_RES_PERMS_SCMI_POWER_DOMAIN_MESSAGE_IDX] =
57                         0x0,
58                     /* System Power Domain */
59                     .messages[MOD_RES_PERMS_SCMI_SYS_POWER_MESSAGE_IDX] = 0x0,
60                     /* Performance */
61                     .messages[MOD_RES_PERMS_SCMI_PERF_MESSAGE_IDX] = 0x0,
62                     /* Clock management */
63                     .messages[MOD_RES_PERMS_SCMI_CLOCK_MESSAGE_IDX] = 0x0,
64                     /* Sensors */
65                     .messages[MOD_RES_PERMS_SCMI_SENSOR_MESSAGE_IDX] = 0x0,
66                     /* Reset Domains */
67                     .messages[MOD_RES_PERMS_SCMI_RESET_DOMAIN_MESSAGE_IDX] =
68                         0x0,
69                 },
70             [AGENT_IDX(SCP_SCMI_AGENT_ID_PSCI)] =
71                 {
72                     .messages[0] = 0x0, /* Base */
73                     .messages[1] = 0x0, /* Power Domain */
74                     .messages[2] = 0x0, /* System Power Domain */
75                     .messages[3] =
76                         ((1
77                           << (MOD_SCMI_PERF_DOMAIN_ATTRIBUTES -
78                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
79                          (0
80                           << (MOD_SCMI_PERF_DESCRIBE_LEVELS -
81                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
82                          (1
83                           << (MOD_SCMI_PERF_LIMITS_SET -
84                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
85                          (1
86                           << (MOD_SCMI_PERF_LIMITS_GET -
87                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
88                          (1
89                           << (MOD_SCMI_PERF_LEVEL_SET -
90                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
91                          (1
92                           << (MOD_SCMI_PERF_LEVEL_GET -
93                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
94                          (1
95                           << (MOD_SCMI_PERF_NOTIFY_LIMITS -
96                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
97                          (1
98                           << (MOD_SCMI_PERF_NOTIFY_LEVEL -
99                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
100                          (1
101                           << (MOD_SCMI_PERF_DESCRIBE_FAST_CHANNEL -
102                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES))),
103                     .messages[4] =
104                         (1
105                          << (MOD_SCMI_CLOCK_CONFIG_SET -
106                              MOD_SCMI_CLOCK_ATTRIBUTES)), /* Clock management */
107                     .messages[5] = 0x0, /* Sensors */
108                 },
109         };
110 
111 static struct mod_res_agent_permission agent_permissions = {
112     .agent_protocol_permissions = agent_protocol_permissions,
113     .agent_msg_permissions = agent_msg_permissions,
114 };
115 
116 struct fwk_module_config config_resource_perms = {
117     .data =
118         &(struct mod_res_resource_perms_config){
119             .agent_permissions = (uintptr_t)&agent_permissions,
120             .agent_count = SCP_SCMI_AGENT_ID_COUNT,
121             .protocol_count = 6,
122         },
123 };
124