notify.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * System Control and Management Interface (SCMI) Message Protocol
  4. * notification header file containing some definitions, structures
  5. * and function prototypes related to SCMI Notification handling.
  6. *
  7. * Copyright (C) 2020-2021 ARM Ltd.
  8. */
  9. #ifndef _SCMI_NOTIFY_H
  10. #define _SCMI_NOTIFY_H
  11. #include <linux/device.h>
  12. #include <linux/ktime.h>
  13. #include <linux/types.h>
  14. #define SCMI_PROTO_QUEUE_SZ 4096
  15. /**
  16. * struct scmi_event - Describes an event to be supported
  17. * @id: Event ID
  18. * @max_payld_sz: Max possible size for the payload of a notification message
  19. * @max_report_sz: Max possible size for the report of a notification message
  20. *
  21. * Each SCMI protocol, during its initialization phase, can describe the events
  22. * it wishes to support in a few struct scmi_event and pass them to the core
  23. * using scmi_register_protocol_events().
  24. */
  25. struct scmi_event {
  26. u8 id;
  27. size_t max_payld_sz;
  28. size_t max_report_sz;
  29. };
  30. struct scmi_protocol_handle;
  31. /**
  32. * struct scmi_event_ops - Protocol helpers called by the notification core.
  33. * @is_notify_supported: Return 0 if the specified notification for the
  34. * specified resource (src_id) is supported.
  35. * @get_num_sources: Returns the number of possible events' sources for this
  36. * protocol
  37. * @set_notify_enabled: Enable/disable the required evt_id/src_id notifications
  38. * using the proper custom protocol commands.
  39. * Return 0 on Success
  40. * @fill_custom_report: fills a custom event report from the provided
  41. * event message payld identifying the event
  42. * specific src_id.
  43. * Return NULL on failure otherwise @report now fully
  44. * populated
  45. *
  46. * Context: Helpers described in &struct scmi_event_ops are called only in
  47. * process context.
  48. */
  49. struct scmi_event_ops {
  50. bool (*is_notify_supported)(const struct scmi_protocol_handle *ph,
  51. u8 evt_id, u32 src_id);
  52. int (*get_num_sources)(const struct scmi_protocol_handle *ph);
  53. int (*set_notify_enabled)(const struct scmi_protocol_handle *ph,
  54. u8 evt_id, u32 src_id, bool enabled);
  55. void *(*fill_custom_report)(const struct scmi_protocol_handle *ph,
  56. u8 evt_id, ktime_t timestamp,
  57. const void *payld, size_t payld_sz,
  58. void *report, u32 *src_id);
  59. };
  60. /**
  61. * struct scmi_protocol_events - Per-protocol description of available events
  62. * @queue_sz: Size in bytes of the per-protocol queue to use.
  63. * @ops: Array of protocol-specific events operations.
  64. * @evts: Array of supported protocol's events.
  65. * @num_events: Number of supported protocol's events described in @evts.
  66. * @num_sources: Number of protocol's sources, should be greater than 0; if not
  67. * available at compile time, it will be provided at run-time via
  68. * @get_num_sources.
  69. */
  70. struct scmi_protocol_events {
  71. size_t queue_sz;
  72. const struct scmi_event_ops *ops;
  73. const struct scmi_event *evts;
  74. unsigned int num_events;
  75. unsigned int num_sources;
  76. };
  77. int scmi_notification_init(struct scmi_handle *handle);
  78. void scmi_notification_exit(struct scmi_handle *handle);
  79. int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
  80. const struct scmi_protocol_handle *ph,
  81. const struct scmi_protocol_events *ee);
  82. void scmi_deregister_protocol_events(const struct scmi_handle *handle,
  83. u8 proto_id);
  84. int scmi_notify(const struct scmi_handle *handle, u8 proto_id, u8 evt_id,
  85. const void *buf, size_t len, ktime_t ts);
  86. #endif /* _SCMI_NOTIFY_H */