reset_domain.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // SPDX-License-Identifier: BSD-3-Clause
  2. /*
  3. * Copyright (c) 2015-2020, Arm Limited and Contributors. All rights reserved.
  4. * Copyright (c) 2019-2020, Linaro Limited
  5. */
  6. #include <cdefs.h>
  7. #include <string.h>
  8. #include <drivers/scmi-msg.h>
  9. #include <drivers/scmi.h>
  10. #include <lib/utils.h>
  11. #include <lib/utils_def.h>
  12. #include "common.h"
  13. static bool message_id_is_supported(unsigned int message_id);
  14. #pragma weak plat_scmi_rstd_count
  15. #pragma weak plat_scmi_rstd_get_name
  16. #pragma weak plat_scmi_rstd_autonomous
  17. #pragma weak plat_scmi_rstd_set_state
  18. size_t plat_scmi_rstd_count(unsigned int agent_id __unused)
  19. {
  20. return 0U;
  21. }
  22. const char *plat_scmi_rstd_get_name(unsigned int agent_id __unused,
  23. unsigned int scmi_id __unused)
  24. {
  25. return NULL;
  26. }
  27. int32_t plat_scmi_rstd_autonomous(unsigned int agent_id __unused,
  28. unsigned int scmi_id __unused,
  29. unsigned int state __unused)
  30. {
  31. return SCMI_NOT_SUPPORTED;
  32. }
  33. int32_t plat_scmi_rstd_set_state(unsigned int agent_id __unused,
  34. unsigned int scmi_id __unused,
  35. bool assert_not_deassert __unused)
  36. {
  37. return SCMI_NOT_SUPPORTED;
  38. }
  39. static void report_version(struct scmi_msg *msg)
  40. {
  41. struct scmi_protocol_version_p2a return_values = {
  42. .status = SCMI_SUCCESS,
  43. .version = SCMI_PROTOCOL_VERSION_RESET_DOMAIN,
  44. };
  45. if (msg->in_size != 0U) {
  46. scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
  47. return;
  48. }
  49. scmi_write_response(msg, &return_values, sizeof(return_values));
  50. }
  51. static void report_attributes(struct scmi_msg *msg)
  52. {
  53. struct scmi_protocol_attributes_p2a return_values = {
  54. .status = SCMI_SUCCESS,
  55. .attributes = plat_scmi_rstd_count(msg->agent_id),
  56. };
  57. if (msg->in_size != 0U) {
  58. scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
  59. return;
  60. }
  61. scmi_write_response(msg, &return_values, sizeof(return_values));
  62. }
  63. static void report_message_attributes(struct scmi_msg *msg)
  64. {
  65. struct scmi_protocol_message_attributes_a2p *in_args = (void *)msg->in;
  66. struct scmi_protocol_message_attributes_p2a return_values = {
  67. .status = SCMI_SUCCESS,
  68. /* For this protocol, attributes shall be zero */
  69. .attributes = 0U,
  70. };
  71. if (msg->in_size != sizeof(*in_args)) {
  72. scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
  73. return;
  74. }
  75. if (!message_id_is_supported(in_args->message_id)) {
  76. scmi_status_response(msg, SCMI_NOT_FOUND);
  77. return;
  78. }
  79. scmi_write_response(msg, &return_values, sizeof(return_values));
  80. }
  81. static void reset_domain_attributes(struct scmi_msg *msg)
  82. {
  83. struct scmi_reset_domain_attributes_a2p *in_args = (void *)msg->in;
  84. struct scmi_reset_domain_attributes_p2a return_values;
  85. const char *name = NULL;
  86. unsigned int domain_id = 0U;
  87. if (msg->in_size != sizeof(*in_args)) {
  88. scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
  89. return;
  90. }
  91. domain_id = SPECULATION_SAFE_VALUE(in_args->domain_id);
  92. if (domain_id >= plat_scmi_rstd_count(msg->agent_id)) {
  93. scmi_status_response(msg, SCMI_INVALID_PARAMETERS);
  94. return;
  95. }
  96. name = plat_scmi_rstd_get_name(msg->agent_id, domain_id);
  97. if (name == NULL) {
  98. scmi_status_response(msg, SCMI_NOT_FOUND);
  99. return;
  100. }
  101. zeromem(&return_values, sizeof(return_values));
  102. COPY_NAME_IDENTIFIER(return_values.name, name);
  103. return_values.status = SCMI_SUCCESS;
  104. return_values.flags = 0U; /* Async and Notif are not supported */
  105. return_values.latency = SCMI_RESET_DOMAIN_ATTR_UNK_LAT;
  106. scmi_write_response(msg, &return_values, sizeof(return_values));
  107. }
  108. static void reset_request(struct scmi_msg *msg)
  109. {
  110. struct scmi_reset_domain_request_a2p *in_args = (void *)msg->in;
  111. struct scmi_reset_domain_request_p2a out_args = {
  112. .status = SCMI_SUCCESS,
  113. };
  114. unsigned int domain_id = 0U;
  115. if (msg->in_size != sizeof(*in_args)) {
  116. scmi_status_response(msg, SCMI_PROTOCOL_ERROR);
  117. return;
  118. }
  119. domain_id = SPECULATION_SAFE_VALUE(in_args->domain_id);
  120. if (domain_id >= plat_scmi_rstd_count(msg->agent_id)) {
  121. scmi_status_response(msg, SCMI_NOT_FOUND);
  122. return;
  123. }
  124. if ((in_args->flags & SCMI_RESET_DOMAIN_AUTO) != 0U) {
  125. out_args.status = plat_scmi_rstd_autonomous(msg->agent_id,
  126. domain_id,
  127. in_args->reset_state);
  128. } else if ((in_args->flags & SCMI_RESET_DOMAIN_EXPLICIT) != 0U) {
  129. out_args.status = plat_scmi_rstd_set_state(msg->agent_id,
  130. domain_id, true);
  131. } else {
  132. out_args.status = plat_scmi_rstd_set_state(msg->agent_id,
  133. domain_id, false);
  134. }
  135. if (out_args.status != SCMI_SUCCESS) {
  136. scmi_status_response(msg, out_args.status);
  137. } else {
  138. scmi_write_response(msg, &out_args, sizeof(out_args));
  139. }
  140. }
  141. static const scmi_msg_handler_t scmi_rstd_handler_table[] = {
  142. [SCMI_PROTOCOL_VERSION] = report_version,
  143. [SCMI_PROTOCOL_ATTRIBUTES] = report_attributes,
  144. [SCMI_PROTOCOL_MESSAGE_ATTRIBUTES] = report_message_attributes,
  145. [SCMI_RESET_DOMAIN_ATTRIBUTES] = reset_domain_attributes,
  146. [SCMI_RESET_DOMAIN_REQUEST] = reset_request,
  147. };
  148. static bool message_id_is_supported(unsigned int message_id)
  149. {
  150. return (message_id < ARRAY_SIZE(scmi_rstd_handler_table)) &&
  151. (scmi_rstd_handler_table[message_id] != NULL);
  152. }
  153. scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg)
  154. {
  155. unsigned int message_id = SPECULATION_SAFE_VALUE(msg->message_id);
  156. if (message_id >= ARRAY_SIZE(scmi_rstd_handler_table)) {
  157. VERBOSE("Reset domain handle not found %u\n", msg->message_id);
  158. return NULL;
  159. }
  160. return scmi_rstd_handler_table[message_id];
  161. }