scmi_pwr_dmn_proto.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <arch_helpers.h>
  8. #include <common/debug.h>
  9. #include <drivers/arm/css/scmi.h>
  10. #include "scmi_private.h"
  11. /*
  12. * API to set the SCMI power domain power state.
  13. */
  14. int scmi_pwr_state_set(void *p, uint32_t domain_id,
  15. uint32_t scmi_pwr_state)
  16. {
  17. mailbox_mem_t *mbx_mem;
  18. unsigned int token = 0;
  19. int ret;
  20. /*
  21. * Only asynchronous mode of `set power state` command is allowed on
  22. * application processors.
  23. */
  24. uint32_t pwr_state_set_msg_flag = SCMI_PWR_STATE_SET_FLAG_ASYNC;
  25. scmi_channel_t *ch = (scmi_channel_t *)p;
  26. validate_scmi_channel(ch);
  27. scmi_get_channel(ch);
  28. mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
  29. mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID,
  30. SCMI_PWR_STATE_SET_MSG, token);
  31. mbx_mem->len = SCMI_PWR_STATE_SET_MSG_LEN;
  32. mbx_mem->flags = SCMI_FLAG_RESP_POLL;
  33. SCMI_PAYLOAD_ARG3(mbx_mem->payload, pwr_state_set_msg_flag,
  34. domain_id, scmi_pwr_state);
  35. scmi_send_sync_command(ch);
  36. /* Get the return values */
  37. SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
  38. assert(mbx_mem->len == SCMI_PWR_STATE_SET_RESP_LEN);
  39. assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
  40. scmi_put_channel(ch);
  41. return ret;
  42. }
  43. /*
  44. * API to get the SCMI power domain power state.
  45. */
  46. int scmi_pwr_state_get(void *p, uint32_t domain_id,
  47. uint32_t *scmi_pwr_state)
  48. {
  49. mailbox_mem_t *mbx_mem;
  50. unsigned int token = 0;
  51. int ret;
  52. scmi_channel_t *ch = (scmi_channel_t *)p;
  53. validate_scmi_channel(ch);
  54. scmi_get_channel(ch);
  55. mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
  56. mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID,
  57. SCMI_PWR_STATE_GET_MSG, token);
  58. mbx_mem->len = SCMI_PWR_STATE_GET_MSG_LEN;
  59. mbx_mem->flags = SCMI_FLAG_RESP_POLL;
  60. SCMI_PAYLOAD_ARG1(mbx_mem->payload, domain_id);
  61. scmi_send_sync_command(ch);
  62. /* Get the return values */
  63. SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *scmi_pwr_state);
  64. assert(mbx_mem->len == SCMI_PWR_STATE_GET_RESP_LEN);
  65. assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
  66. scmi_put_channel(ch);
  67. return ret;
  68. }