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