1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2019-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[] =
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[] =
50         {
51             [AGENT_IDX(SCP_SCMI_AGENT_ID_OSPM)] =
52                 {
53                     /* Example, Base, disable unused msg 12 */
54                     .messages = {
55                     [MOD_RES_PERMS_SCMI_BASE_MESSAGE_IDX] = 0x0,
56                     /* Power Domain */
57                     [MOD_RES_PERMS_SCMI_POWER_DOMAIN_MESSAGE_IDX] =
58                         0x0,
59                     /* System Power Domain */
60                     [MOD_RES_PERMS_SCMI_SYS_POWER_MESSAGE_IDX] = 0x0,
61                     /* Performance */
62                     [MOD_RES_PERMS_SCMI_PERF_MESSAGE_IDX] = 0x0,
63                     /*
64                      * TODO: access to CONFIG_SET required?
65                      */
66                     [MOD_RES_PERMS_SCMI_CLOCK_MESSAGE_IDX] =
67                         MOD_RES_PERMS_ACCESS_DENIED
68                         << (MOD_SCMI_CLOCK_CONFIG_SET -
69                             MOD_SCMI_CLOCK_ATTRIBUTES),
70                     /* Sensors */
71                     [MOD_RES_PERMS_SCMI_SENSOR_MESSAGE_IDX] = 0x0,
72                     /* Reset Domains */
73                     [MOD_RES_PERMS_SCMI_RESET_DOMAIN_MESSAGE_IDX] =
74                         0x0,
75                     }
76                 },
77             [AGENT_IDX(SCP_SCMI_AGENT_ID_PSCI)] =
78                 {
79                     .messages = {
80                     [0] = 0x0, /* Base */
81                     [1] = 0x0, /* Power Domain */
82                     [2] = 0x0, /* System Power Domain */
83                     [3] =
84                         ((1
85                           << (MOD_SCMI_PERF_DOMAIN_ATTRIBUTES -
86                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
87                          /* DESCRIBE_LEVELS is required for some reason ... */
88                          (0
89                           << (MOD_SCMI_PERF_DESCRIBE_LEVELS -
90                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
91                          (1
92                           << (MOD_SCMI_PERF_LIMITS_SET -
93                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
94                          (1
95                           << (MOD_SCMI_PERF_LIMITS_GET -
96                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
97                          (1
98                           << (MOD_SCMI_PERF_LEVEL_SET -
99                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
100                          (1
101                           << (MOD_SCMI_PERF_LEVEL_GET -
102                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
103                          (1
104                           << (MOD_SCMI_PERF_NOTIFY_LIMITS -
105                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
106                          (1
107                           << (MOD_SCMI_PERF_NOTIFY_LEVEL -
108                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) |
109                          (1
110                           << (MOD_SCMI_PERF_DESCRIBE_FAST_CHANNEL -
111                               MOD_SCMI_PERF_DOMAIN_ATTRIBUTES))),
112                     /*
113                      * TODO: access to CONFIG_SET required?
114                      */
115                     [4] =
116                         (1
117                          << (MOD_SCMI_CLOCK_CONFIG_SET -
118                              MOD_SCMI_CLOCK_ATTRIBUTES)),
119                     [5] = 0x0, /* Sensors */
120                     }
121                 },
122         };
123 
124 static struct mod_res_agent_permission agent_permissions = {
125     .agent_protocol_permissions = agent_protocol_permissions,
126     .agent_msg_permissions = agent_msg_permissions,
127 };
128 
129 struct fwk_module_config config_resource_perms = {
130     .data =
131         &(struct mod_res_resource_perms_config){
132             .agent_permissions = (uintptr_t)&agent_permissions,
133             .agent_count = SCP_SCMI_AGENT_ID_COUNT,
134             .protocol_count = 6,
135         },
136 };
137