scmi_agent.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /*
  3. * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
  4. * Copyright (C) 2019-2020, Linaro Limited
  5. *
  6. * An SCMI agent device represent on communication path from a
  7. * device driver to the remote SCMI server which driver sends
  8. * messages to and receives response messages from.
  9. */
  10. #ifndef SCMI_AGENT_H
  11. #define SCMI_AGENT_H
  12. #include <asm/types.h>
  13. struct udevice;
  14. /*
  15. * struct scmi_msg - Context of a SCMI message sent and the response received
  16. *
  17. * @protocol_id: SCMI protocol ID
  18. * @message_id: SCMI message ID for a defined protocol ID
  19. * @in_msg: Pointer to the message payload sent by the driver
  20. * @in_msg_sz: Byte size of the message payload sent
  21. * @out_msg: Pointer to buffer to store response message payload
  22. * @out_msg_sz: Byte size of the response buffer and response payload
  23. */
  24. struct scmi_msg {
  25. unsigned int protocol_id;
  26. unsigned int message_id;
  27. u8 *in_msg;
  28. size_t in_msg_sz;
  29. u8 *out_msg;
  30. size_t out_msg_sz;
  31. };
  32. /* Helper macro to match a message on input/output array references */
  33. #define SCMI_MSG_IN(_protocol, _message, _in_array, _out_array) \
  34. (struct scmi_msg){ \
  35. .protocol_id = (_protocol), \
  36. .message_id = (_message), \
  37. .in_msg = (uint8_t *)&(_in_array), \
  38. .in_msg_sz = sizeof(_in_array), \
  39. .out_msg = (uint8_t *)&(_out_array), \
  40. .out_msg_sz = sizeof(_out_array), \
  41. }
  42. /**
  43. * scmi_send_and_process_msg() - send and process a SCMI message
  44. *
  45. * Send a message to a SCMI server through a target SCMI agent device.
  46. * Caller sets scmi_msg::out_msg_sz to the output message buffer size.
  47. * On return, scmi_msg::out_msg_sz stores the response payload size.
  48. *
  49. * @dev: SCMI agent device
  50. * @msg: Message structure reference
  51. * @return 0 on success and a negative errno on failure
  52. */
  53. int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg);
  54. /**
  55. * scmi_to_linux_errno() - Convert an SCMI error code into a Linux errno code
  56. *
  57. * @scmi_errno: SCMI error code value
  58. * @return 0 for successful status and a negative errno otherwise
  59. */
  60. int scmi_to_linux_errno(s32 scmi_errno);
  61. #endif /* SCMI_H */