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 "tc0_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 MOD_RES_PERMS_SCMI_VOLTAGE_DOMAIN_PROTOCOL_DENIED, 40 }, 41 }; 42 43 /* 44 * Messages have an index offset from 0x3 as all agents can access 45 * the VERSION/ATTRIBUTES/MSG_ATTRIBUTES messages for all 46 * protocols, hence message 0x3 maps to bit[0], message 0x4 maps 47 * to bit[1], etc. 48 */ 49 static struct mod_res_agent_msg_permissions 50 agent_msg_permissions[] = 51 { 52 [AGENT_IDX(SCP_SCMI_AGENT_ID_OSPM)] = 53 { 54 .messages = { 55 [MOD_RES_PERMS_SCMI_BASE_MESSAGE_IDX] = 0x0, 56 [MOD_RES_PERMS_SCMI_POWER_DOMAIN_MESSAGE_IDX] = 57 0x0, 58 [MOD_RES_PERMS_SCMI_SYS_POWER_MESSAGE_IDX] = 0x0, 59 [MOD_RES_PERMS_SCMI_PERF_MESSAGE_IDX] = 0x0, 60 [MOD_RES_PERMS_SCMI_CLOCK_MESSAGE_IDX] = 0x0, 61 [MOD_RES_PERMS_SCMI_SENSOR_MESSAGE_IDX] = 0x0, 62 [MOD_RES_PERMS_SCMI_RESET_DOMAIN_MESSAGE_IDX] = 63 0x0, 64 [MOD_RES_PERMS_SCMI_VOLTAGE_DOMAIN_MESSAGE_IDX] = 65 0x0, 66 }, 67 }, 68 [AGENT_IDX(SCP_SCMI_AGENT_ID_PSCI)] = 69 { 70 .messages = { 71 [MOD_RES_PERMS_SCMI_BASE_MESSAGE_IDX] = 0x0, 72 [MOD_RES_PERMS_SCMI_POWER_DOMAIN_MESSAGE_IDX] = 73 0x0, 74 [MOD_RES_PERMS_SCMI_SYS_POWER_MESSAGE_IDX] = 0x0, 75 [MOD_RES_PERMS_SCMI_PERF_MESSAGE_IDX] = 76 ((1 77 << (MOD_SCMI_PERF_DOMAIN_ATTRIBUTES - 78 MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) | 79 /* DESCRIBE_LEVELS is required for some reason */ 80 (0 81 << (MOD_SCMI_PERF_DESCRIBE_LEVELS - 82 MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) | 83 (1 84 << (MOD_SCMI_PERF_LIMITS_SET - 85 MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) | 86 (1 87 << (MOD_SCMI_PERF_LIMITS_GET - 88 MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) | 89 (1 90 << (MOD_SCMI_PERF_LEVEL_SET - 91 MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) | 92 (1 93 << (MOD_SCMI_PERF_LEVEL_GET - 94 MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) | 95 (1 96 << (MOD_SCMI_PERF_NOTIFY_LIMITS - 97 MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) | 98 (1 99 << (MOD_SCMI_PERF_NOTIFY_LEVEL - 100 MOD_SCMI_PERF_DOMAIN_ATTRIBUTES)) | 101 (1 102 << (MOD_SCMI_PERF_DESCRIBE_FAST_CHANNEL - 103 MOD_SCMI_PERF_DOMAIN_ATTRIBUTES))), 104 /* Clocks, no access */ 105 [MOD_RES_PERMS_SCMI_CLOCK_MESSAGE_IDX] = 0xff, 106 [MOD_RES_PERMS_SCMI_SENSOR_MESSAGE_IDX] = 0x0, 107 [MOD_RES_PERMS_SCMI_RESET_DOMAIN_MESSAGE_IDX] = 108 0x0, 109 [MOD_RES_PERMS_SCMI_VOLTAGE_DOMAIN_MESSAGE_IDX] = 110 0x0, 111 }, 112 }, 113 }; 114 115 static struct mod_res_agent_permission agent_permissions = { 116 .agent_protocol_permissions = agent_protocol_permissions, 117 .agent_msg_permissions = agent_msg_permissions, 118 }; 119 120 struct fwk_module_config config_resource_perms = { 121 .data = 122 &(struct mod_res_resource_perms_config){ 123 .agent_permissions = (uintptr_t)&agent_permissions, 124 .agent_count = SCP_SCMI_AGENT_ID_COUNT, 125 .protocol_count = 8, 126 }, 127 }; 128