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