xref: /openbmc/linux/drivers/firmware/arm_scmi/notify.h (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
11fc2dd18SCristian Marussi /* SPDX-License-Identifier: GPL-2.0 */
21fc2dd18SCristian Marussi /*
31fc2dd18SCristian Marussi  * System Control and Management Interface (SCMI) Message Protocol
41fc2dd18SCristian Marussi  * notification header file containing some definitions, structures
51fc2dd18SCristian Marussi  * and function prototypes related to SCMI Notification handling.
61fc2dd18SCristian Marussi  *
7533c7095SCristian Marussi  * Copyright (C) 2020-2021 ARM Ltd.
81fc2dd18SCristian Marussi  */
91fc2dd18SCristian Marussi #ifndef _SCMI_NOTIFY_H
101fc2dd18SCristian Marussi #define _SCMI_NOTIFY_H
111fc2dd18SCristian Marussi 
121fc2dd18SCristian Marussi #include <linux/device.h>
1372a5eb9dSCristian Marussi #include <linux/ktime.h>
141fc2dd18SCristian Marussi #include <linux/types.h>
151fc2dd18SCristian Marussi 
161fc2dd18SCristian Marussi #define SCMI_PROTO_QUEUE_SZ	4096
171fc2dd18SCristian Marussi 
181fc2dd18SCristian Marussi /**
191fc2dd18SCristian Marussi  * struct scmi_event  - Describes an event to be supported
201fc2dd18SCristian Marussi  * @id: Event ID
211fc2dd18SCristian Marussi  * @max_payld_sz: Max possible size for the payload of a notification message
221fc2dd18SCristian Marussi  * @max_report_sz: Max possible size for the report of a notification message
231fc2dd18SCristian Marussi  *
241fc2dd18SCristian Marussi  * Each SCMI protocol, during its initialization phase, can describe the events
251fc2dd18SCristian Marussi  * it wishes to support in a few struct scmi_event and pass them to the core
261fc2dd18SCristian Marussi  * using scmi_register_protocol_events().
271fc2dd18SCristian Marussi  */
281fc2dd18SCristian Marussi struct scmi_event {
291fc2dd18SCristian Marussi 	u8	id;
301fc2dd18SCristian Marussi 	size_t	max_payld_sz;
311fc2dd18SCristian Marussi 	size_t	max_report_sz;
321fc2dd18SCristian Marussi };
331fc2dd18SCristian Marussi 
34533c7095SCristian Marussi struct scmi_protocol_handle;
35533c7095SCristian Marussi 
361fc2dd18SCristian Marussi /**
371fc2dd18SCristian Marussi  * struct scmi_event_ops  - Protocol helpers called by the notification core.
38533c7095SCristian Marussi  * @get_num_sources: Returns the number of possible events' sources for this
39533c7095SCristian Marussi  *		     protocol
401fc2dd18SCristian Marussi  * @set_notify_enabled: Enable/disable the required evt_id/src_id notifications
411fc2dd18SCristian Marussi  *			using the proper custom protocol commands.
421fc2dd18SCristian Marussi  *			Return 0 on Success
43bd31b249SCristian Marussi  * @fill_custom_report: fills a custom event report from the provided
44bd31b249SCristian Marussi  *			event message payld identifying the event
45bd31b249SCristian Marussi  *			specific src_id.
46bd31b249SCristian Marussi  *			Return NULL on failure otherwise @report now fully
47bd31b249SCristian Marussi  *			populated
481fc2dd18SCristian Marussi  *
491fc2dd18SCristian Marussi  * Context: Helpers described in &struct scmi_event_ops are called only in
501fc2dd18SCristian Marussi  *	    process context.
511fc2dd18SCristian Marussi  */
521fc2dd18SCristian Marussi struct scmi_event_ops {
53*3cb8c95fSCristian Marussi 	int (*get_num_sources)(const struct scmi_protocol_handle *ph);
54*3cb8c95fSCristian Marussi 	int (*set_notify_enabled)(const struct scmi_protocol_handle *ph,
551fc2dd18SCristian Marussi 				  u8 evt_id, u32 src_id, bool enabled);
56*3cb8c95fSCristian Marussi 	void *(*fill_custom_report)(const struct scmi_protocol_handle *ph,
5772a5eb9dSCristian Marussi 				    u8 evt_id, ktime_t timestamp,
5872a5eb9dSCristian Marussi 				    const void *payld, size_t payld_sz,
5972a5eb9dSCristian Marussi 				    void *report, u32 *src_id);
601fc2dd18SCristian Marussi };
611fc2dd18SCristian Marussi 
62533c7095SCristian Marussi /**
63533c7095SCristian Marussi  * struct scmi_protocol_events  - Per-protocol description of available events
64533c7095SCristian Marussi  * @queue_sz: Size in bytes of the per-protocol queue to use.
65533c7095SCristian Marussi  * @ops: Array of protocol-specific events operations.
66533c7095SCristian Marussi  * @evts: Array of supported protocol's events.
67533c7095SCristian Marussi  * @num_events: Number of supported protocol's events described in @evts.
68533c7095SCristian Marussi  * @num_sources: Number of protocol's sources, should be greater than 0; if not
69533c7095SCristian Marussi  *		 available at compile time, it will be provided at run-time via
70533c7095SCristian Marussi  *		 @get_num_sources.
71533c7095SCristian Marussi  */
72533c7095SCristian Marussi struct scmi_protocol_events {
73533c7095SCristian Marussi 	size_t				queue_sz;
74533c7095SCristian Marussi 	const struct scmi_event_ops	*ops;
75533c7095SCristian Marussi 	const struct scmi_event		*evts;
76533c7095SCristian Marussi 	unsigned int			num_events;
77533c7095SCristian Marussi 	unsigned int			num_sources;
78533c7095SCristian Marussi };
79533c7095SCristian Marussi 
801fc2dd18SCristian Marussi int scmi_notification_init(struct scmi_handle *handle);
811fc2dd18SCristian Marussi void scmi_notification_exit(struct scmi_handle *handle);
82533c7095SCristian Marussi int scmi_register_protocol_events(const struct scmi_handle *handle, u8 proto_id,
83b9f7fd90SCristian Marussi 				  const struct scmi_protocol_handle *ph,
84533c7095SCristian Marussi 				  const struct scmi_protocol_events *ee);
85533c7095SCristian Marussi void scmi_deregister_protocol_events(const struct scmi_handle *handle,
86533c7095SCristian Marussi 				     u8 proto_id);
87bd31b249SCristian Marussi int scmi_notify(const struct scmi_handle *handle, u8 proto_id, u8 evt_id,
8872a5eb9dSCristian Marussi 		const void *buf, size_t len, ktime_t ts);
891fc2dd18SCristian Marussi 
901fc2dd18SCristian Marussi #endif /* _SCMI_NOTIFY_H */
91