scmi_sys_pwr_proto.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 system power state
  13. */
  14. int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state)
  15. {
  16. mailbox_mem_t *mbx_mem;
  17. unsigned int token = 0;
  18. int ret;
  19. scmi_channel_t *ch = (scmi_channel_t *)p;
  20. validate_scmi_channel(ch);
  21. scmi_get_channel(ch);
  22. mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
  23. mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_PWR_PROTO_ID,
  24. SCMI_SYS_PWR_STATE_SET_MSG, token);
  25. mbx_mem->len = SCMI_SYS_PWR_STATE_SET_MSG_LEN;
  26. mbx_mem->flags = SCMI_FLAG_RESP_POLL;
  27. SCMI_PAYLOAD_ARG2(mbx_mem->payload, flags, system_state);
  28. scmi_send_sync_command(ch);
  29. /* Get the return values */
  30. SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
  31. assert(mbx_mem->len == SCMI_SYS_PWR_STATE_SET_RESP_LEN);
  32. assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
  33. scmi_put_channel(ch);
  34. return ret;
  35. }
  36. /*
  37. * API to get the SCMI system power state
  38. */
  39. int scmi_sys_pwr_state_get(void *p, uint32_t *system_state)
  40. {
  41. mailbox_mem_t *mbx_mem;
  42. unsigned int token = 0;
  43. int ret;
  44. scmi_channel_t *ch = (scmi_channel_t *)p;
  45. validate_scmi_channel(ch);
  46. scmi_get_channel(ch);
  47. mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
  48. mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_PWR_PROTO_ID,
  49. SCMI_SYS_PWR_STATE_GET_MSG, token);
  50. mbx_mem->len = SCMI_SYS_PWR_STATE_GET_MSG_LEN;
  51. mbx_mem->flags = SCMI_FLAG_RESP_POLL;
  52. scmi_send_sync_command(ch);
  53. /* Get the return values */
  54. SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *system_state);
  55. assert(mbx_mem->len == SCMI_SYS_PWR_STATE_GET_RESP_LEN);
  56. assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
  57. scmi_put_channel(ch);
  58. return ret;
  59. }