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