platform/surface: aggregator: Extend user-space interface for events
Subsystems (4)
Maximilian Luz
maintainerv2 cover platform/surface: aggregator: Extend user-space interface for events
Extend the user-space debug interface so that it can be used to receive SSAM events in user-space.
Version 1 and rationale:
https://lore.kernel.org/platform-driver-x86/[email protected]/
Changes in version 2:
- PATCH 2/7: Avoid code duplication, remove unused variable
- PATCH 4/7: Add missing mutex_destroy() calls
Maximilian Luz (7):
platform/surface: aggregator: Allow registering notifiers without
enabling events
platform/surface: aggregator: Allow enabling of events without
notifiers
platform/surface: aggregator: Update copyright platform/surface: aggregator_cdev: Add support for forwarding events
to user-space
platform/surface: aggregator_cdev: Allow enabling of events from
user-space
platform/surface: aggregator_cdev: Add lockdep support
docs: driver-api: Update Surface Aggregator user-space interface
documentation
.../surface_aggregator/clients/cdev.rst | 127 ++++- .../userspace-api/ioctl/ioctl-number.rst | 2 +- drivers/platform/surface/aggregator/Kconfig | 2 +- drivers/platform/surface/aggregator/Makefile | 2 +- drivers/platform/surface/aggregator/bus.c | 2 +- drivers/platform/surface/aggregator/bus.h | 2 +- .../platform/surface/aggregator/controller.c | 332 +++++++++-- .../platform/surface/aggregator/controller.h | 2 +- drivers/platform/surface/aggregator/core.c | 2 +- .../platform/surface/aggregator/ssh_msgb.h | 2 +- .../surface/aggregator/ssh_packet_layer.c | 2 +- .../surface/aggregator/ssh_packet_layer.h | 2 +- .../platform/surface/aggregator/ssh_parser.c | 2 +- .../platform/surface/aggregator/ssh_parser.h | 2 +- .../surface/aggregator/ssh_request_layer.c | 2 +- .../surface/aggregator/ssh_request_layer.h | 2 +- drivers/platform/surface/aggregator/trace.h | 2 +- .../surface/surface_aggregator_cdev.c | 534 +++++++++++++++++- include/linux/surface_aggregator/controller.h | 27 +- include/linux/surface_aggregator/device.h | 2 +- include/linux/surface_aggregator/serial_hub.h | 2 +- include/uapi/linux/surface_aggregator/cdev.h | 73 ++- 22 files changed, 1018 insertions(+), 109 deletions(-)
Signature · 1 line
2.31.1
Maximilian Luz
maintainerPATCH v2 1/7 platform/surface: aggregator: Allow registering notifiers without enabling events
Currently, each SSAM event notifier is directly tied to one group of events. This makes sense as registering a notifier will automatically take care of enabling the corresponding event group and normally drivers only need notifications for a very limited number of events, associated with different callbacks for each group.
However, there are rare cases, especially for debugging, when we want to get notifications for a whole event target category instead of just a single group of events in that category. Registering multiple notifiers, i.e. one per group, may be infeasible due to two issues: a) we might not know every event enable/disable specification as some events are auto-enabled by the EC and b) forwarding this to the same callback will lead to duplicate events as we might not know the full event specification to perform the appropriate filtering.
This commit introduces observer-notifiers, which are notifiers that are not tied to a specific event group and do not attempt to manage any events. In other words, they can be registered without enabling any event group or incrementing the corresponding reference count and just act as silent observers, listening to all currently/previously enabled events based on their match-specification.
Essentially, this allows us to register one single notifier for a full event target category, meaning that we can process all events of that target category in a single callback without duplication. Specifically, this will be used in the cdev debug interface to forward events to user-space via a device file from which the events can be read.
---
Changes in v2:
- None
--- .../platform/surface/aggregator/controller.c | 69 +++++++++++-------- include/linux/surface_aggregator/controller.h | 17 +++++ 2 files changed, 58 insertions(+), 28 deletions(-)
drivers/platform/surface/aggregator/controller.c +41 -28
@@ -2127,9 +2127,15 @@ int ssam_ctrl_notif_d0_entry(struct ssam_controller *ctrl)* @ctrl: The controller to register the notifier on. * @n: The event notifier to register. * -* Register an event notifier and increment the usage counter of the -* associated SAM event. If the event was previously not enabled, it will be -* enabled during this call. +* Register an event notifier. Increment the usage counter of the associated +* SAM event if the notifier is not marked as an observer. If the event is not +* marked as an observer and is currently not enabled, it will be enabled +* during this call. If the notifier is marked as an observer, no attempt will +* be made at enabling any event and no reference count will be modified. +* +* Notifiers marked as observers do not need to be associated with one specific +* event, i.e. as long as no event matching is performed, only the event target +* category needs to be set. * * Return: Returns zero on success, %-ENOSPC if there have already been * %INT_MAX notifiers for the event ID/type associated with the notifier block
@@ -2138,11 +2144,10 @@ int ssam_ctrl_notif_d0_entry(struct ssam_controller *ctrl)* for the specific associated event, returns the status of the event-enable * EC-command. */ -int ssam_notifier_register (struct ssam_controller *ctrl, -struct ssam_event_notifier *n) +int ssam_notifier_register (struct ssam_controller *ctrl,struct ssam_event_notifier *n) {u16 rqid =ssh_tc_to_rqid (n->event.id.target_category); -struct ssam_nf_refcount_entry *entry; +struct ssam_nf_refcount_entry *entry =NULL ;struct ssam_nf_head *nf_head;struct ssam_nf *nf;int status;
@@ -2155,29 +2160,32 @@ int ssam_notifier_register(struct ssam_controller *ctrl,mutex_lock (&nf->lock); - entry =ssam_nf_refcount_inc (nf, n->event.reg, n->event.id); -if (IS_ERR (entry)) { -mutex_unlock (&nf->lock); -return PTR_ERR (entry); - } +if (!(n->flags &SSAM_EVENT_NOTIFIER_OBSERVER )) { + entry =ssam_nf_refcount_inc (nf, n->event.reg, n->event.id); +if (IS_ERR (entry)) { +mutex_unlock (&nf->lock); +return PTR_ERR (entry); + } -ssam_dbg (ctrl,"enabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , - n->event.reg.target_category, n->event.id.target_category, - n->event.id.instance, entry->refcount); +ssam_dbg (ctrl,"enabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , + n->event.reg.target_category, n->event.id.target_category, + n->event.id.instance, entry->refcount); + } status =ssam_nfblk_insert (nf_head, &n->base);if (status) { - entry =ssam_nf_refcount_dec (nf, n->event.reg, n->event.id); -if (entry->refcount ==0 ) -kfree (entry); +if (entry) { + entry =ssam_nf_refcount_dec (nf, n->event.reg, n->event.id); +if (entry->refcount ==0 ) +kfree (entry); + }mutex_unlock (&nf->lock);return status; } -if (entry->refcount ==1 ) { - status =ssam_ssh_event_enable (ctrl, n->event.reg, n->event.id, - n->event.flags); +if (entry && entry->refcount ==1 ) { + status =ssam_ssh_event_enable (ctrl, n->event.reg, n->event.id, n->event.flags);if (status) {ssam_nfblk_remove (&n->base);kfree (ssam_nf_refcount_dec (nf, n->event.reg, n->event.id));
@@ -2188,7 +2196,7 @@ int ssam_notifier_register(struct ssam_controller *ctrl, entry->flags = n->event.flags; - }else if (entry->flags != n->event.flags) { + }else if (entry && entry->flags != n->event.flags) { ssam_warn(ctrl, "inconsistent flags when enabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n", n->event.flags, entry->flags, n->event.reg.target_category,
@@ -2205,17 +2213,16 @@ EXPORT_SYMBOL_GPL(ssam_notifier_register);* @ctrl: The controller the notifier has been registered on. * @n: The event notifier to unregister. * -* Unregister an event notifier and decrement the usage counter of the -* associated SAM event. If the usage counter reaches zero, the event will be -* disabled. +* Unregister an event notifier. Decrement the usage counter of the associated +* SAM event if the notifier is not marked as an observer. If the usage counter +* reaches zero, the event will be disabled. * * Return: Returns zero on success, %-ENOENT if the given notifier block has * not been registered on the controller. If the given notifier block was the * last one associated with its specific event, returns the status of the * event-disable EC-command. */ -int ssam_notifier_unregister (struct ssam_controller *ctrl, -struct ssam_event_notifier *n) +int ssam_notifier_unregister (struct ssam_controller *ctrl,struct ssam_event_notifier *n) {u16 rqid =ssh_tc_to_rqid (n->event.id.target_category);struct ssam_nf_refcount_entry *entry;
@@ -2236,6 +2243,13 @@ int ssam_notifier_unregister(struct ssam_controller *ctrl,return -ENOENT ; } +/* +* If this is an observer notifier, do not attempt to disable the +* event, just remove it. +*/ +if (n->flags &SSAM_EVENT_NOTIFIER_OBSERVER ) + goto remove; + entry =ssam_nf_refcount_dec (nf, n->event.reg, n->event.id);if (WARN_ON (!entry)) {/*
@@ -2260,8 +2274,7 @@ int ssam_notifier_unregister(struct ssam_controller *ctrl, }if (entry->refcount ==0 ) { - status =ssam_ssh_event_disable (ctrl, n->event.reg, n->event.id, - n->event.flags); + status =ssam_ssh_event_disable (ctrl, n->event.reg, n->event.id, n->event.flags);kfree (entry); }
include/linux/surface_aggregator/controller.h +17 -0
@@ -795,6 +795,20 @@ enum ssam_event_mask {#define SSAM_EVENT_REGISTRY_REG \ SSAM_EVENT_REGISTRY(SSAM_SSH_TC_REG, 0x02, 0x01, 0x02) +/** +* enum ssam_event_notifier_flags - Flags for event notifiers. +* @SSAM_EVENT_NOTIFIER_OBSERVER: +* The corresponding notifier acts as observer. Registering a notifier +* with this flag set will not attempt to enable any event. Equally, +* unregistering will not attempt to disable any event. Note that a +* notifier with this flag may not even correspond to a certain event at +* all, only to a specific event target category. Event matching will not +* be influenced by this flag. +*/ +enum ssam_event_notifier_flags { +SSAM_EVENT_NOTIFIER_OBSERVER =BIT (0 ), +}; +/** * struct ssam_event_notifier - Notifier block for SSAM events. * @base: The base notifier block with callback function and priority.
@@ -803,6 +817,7 @@ enum ssam_event_mask {* @event.id: ID specifying the event. * @event.mask: Flags determining how events are matched to the notifier. * @event.flags: Flags used for enabling the event. +* @flags: Notifier flags (see &enum ssam_event_notifier_flags). */ struct ssam_event_notifier {struct ssam_notifier_block base;
@@ -813,6 +828,8 @@ struct ssam_event_notifier {enum ssam_event_mask mask;u8 flags; } event; + +unsigned long flags; }; int ssam_notifier_register(struct ssam_controller *ctrl,
Signature · 1 line
2.31.1
Maximilian Luz
maintainerPATCH v2 2/7 platform/surface: aggregator: Allow enabling of events without notifiers
In reply to Maximilian LuzWe can already enable and disable SAM events via one of two ways: either via a (non-observer) notifier tied to a specific event group, or a generic event enable/disable request. In some instances, however, neither method may be desirable.
The first method will tie the event enable request to a specific notifier, however, when we want to receive notifications for multiple event groups of the same target category and forward this to the same notifier callback, we may receive duplicate events, i.e. one event per registered notifier. The second method will bypass the internal reference counting mechanism, meaning that a disable request will disable the event regardless of any other client driver using it, which may break the functionality of that driver.
To address this problem, add new functions that allow enabling and disabling of events via the event reference counting mechanism built into the controller, without needing to register a notifier.
This can then be used in combination with observer notifiers to process multiple events of the same target category without duplication in the same callback function.
---
Changes in v2:
- Remove unused variable
- Avoid code duplication
--- .../platform/surface/aggregator/controller.c | 293 +++++++++++++++--- include/linux/surface_aggregator/controller.h | 8 + 2 files changed, 253 insertions(+), 48 deletions(-)
drivers/platform/surface/aggregator/controller.c +245 -48
@@ -407,6 +407,31 @@ ssam_nf_refcount_dec(struct ssam_nf *nf, struct ssam_event_registry reg,return NULL ; } +/** +* ssam_nf_refcount_dec_free() - Decrement reference-/activation-count of the +* given event and free its entry if the reference count reaches zero. +* @nf: The notifier system reference. +* @reg: The registry used to enable/disable the event. +* @id: The event ID. +* +* Decrements the reference-/activation-count of the specified event, freeing +* its entry if it reaches zero. +* +* Note: ``nf->lock`` must be held when calling this function. +*/ +static void ssam_nf_refcount_dec_free (struct ssam_nf *nf, +struct ssam_event_registry reg, +struct ssam_event_id id) +{ +struct ssam_nf_refcount_entry *entry; + +lockdep_assert_held (&nf->lock); + + entry =ssam_nf_refcount_dec (nf, reg, id); +if (entry && entry->refcount ==0 ) +kfree (entry); +} +/** * ssam_nf_refcount_empty() - Test if the notification system has any * enabled/active events.
@@ -2122,6 +2147,109 @@ int ssam_ctrl_notif_d0_entry(struct ssam_controller *ctrl)/* -- Top-level event registry interface. ----------------------------------- */ +/** +* ssam_nf_refcount_enable() - Enable event for reference count entry if it has +* not already been enabled. +* @ctrl: The controller to enable the event on. +* @entry: The reference count entry for the event to be enabled. +* @flags: The flags used for enabling the event on the EC. +* +* Enable the event associated with the given reference count entry if the +* reference count equals one, i.e. the event has not previously been enabled. +* If the event has already been enabled (i.e. reference count not equal to +* one), check that the flags used for enabling match and warn about this if +* they do not. +* +* This does not modify the reference count itself, which is done with +* ssam_nf_refcount_inc() / ssam_nf_refcount_dec(). +* +* Note: ``nf->lock`` must be held when calling this function. +* +* Return: Returns zero on success. If the event is enabled by this call, +* returns the status of the event-enable EC command. +*/ +static int ssam_nf_refcount_enable (struct ssam_controller *ctrl, +struct ssam_nf_refcount_entry *entry,u8 flags) +{ +const struct ssam_event_registry reg = entry->key.reg; +const struct ssam_event_id id = entry->key.id; +struct ssam_nf *nf = &ctrl->cplt.event.notif; +int status; + +lockdep_assert_held (&nf->lock); + +ssam_dbg (ctrl,"enabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , + reg.target_category, id.target_category, id.instance, entry->refcount); + +if (entry->refcount ==1 ) { + status =ssam_ssh_event_enable (ctrl, reg, id, flags); +if (status) +return status; + + entry->flags = flags; + + }else if (entry->flags != flags) { +ssam_warn (ctrl, +"inconsistent flags when enabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n" , + flags, entry->flags, reg.target_category, id.target_category, + id.instance); + } + +return 0 ; +} + +/** +* ssam_nf_refcount_enable() - Disable event for reference count entry if it is +* no longer in use and free the corresponding entry. +* @ctrl: The controller to disable the event on. +* @entry: The reference count entry for the event to be disabled. +* @flags: The flags used for enabling the event on the EC. +* +* If the reference count equals zero, i.e. the event is no longer requested by +* any client, the event will be disabled and the corresponding reference count +* entry freed. The reference count entry must not be used any more after a +* call to this function. +* +* Also checks if the flags used for disabling the event match the flags used +* for enabling the event and warns if they do not (regardless of reference +* count). +* +* This does not modify the reference count itself, which is done with +* ssam_nf_refcount_inc() / ssam_nf_refcount_dec(). +* +* Note: ``nf->lock`` must be held when calling this function. +* +* Return: Returns zero on success. If the event is disabled by this call, +* returns the status of the event-enable EC command. +*/ +static int ssam_nf_refcount_disable_free (struct ssam_controller *ctrl, +struct ssam_nf_refcount_entry *entry,u8 flags) +{ +const struct ssam_event_registry reg = entry->key.reg; +const struct ssam_event_id id = entry->key.id; +struct ssam_nf *nf = &ctrl->cplt.event.notif; +int status; + +lockdep_assert_held (&nf->lock); + +ssam_dbg (ctrl,"disabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , + reg.target_category, id.target_category, id.instance, entry->refcount); + +if (entry->flags != flags) { +ssam_warn (ctrl, +"inconsistent flags when disabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n" , + flags, entry->flags, reg.target_category, id.target_category, + id.instance); + } + +if (entry->refcount ==0 ) { + status =ssam_ssh_event_disable (ctrl, reg, id, flags); +kfree (entry); + } + +return status; +} +/** * ssam_notifier_register() - Register an event notifier. * @ctrl: The controller to register the notifier on.
@@ -2166,41 +2294,26 @@ int ssam_notifier_register(struct ssam_controller *ctrl, struct ssam_event_notifmutex_unlock (&nf->lock);return PTR_ERR (entry); } - -ssam_dbg (ctrl,"enabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , - n->event.reg.target_category, n->event.id.target_category, - n->event.id.instance, entry->refcount); } status =ssam_nfblk_insert (nf_head, &n->base);if (status) { -if (entry) { - entry =ssam_nf_refcount_dec (nf, n->event.reg, n->event.id); -if (entry->refcount ==0 ) -kfree (entry); - } +if (entry) +ssam_nf_refcount_dec_free (nf, n->event.reg, n->event.id);mutex_unlock (&nf->lock);return status; } -if (entry && entry->refcount ==1 ) { - status =ssam_ssh_event_enable (ctrl, n->event.reg, n->event.id, n->event.flags); +if (entry) { + status =ssam_nf_refcount_enable (ctrl, entry, n->event.flags);if (status) {ssam_nfblk_remove (&n->base); -kfree (ssam_nf_refcount_dec (nf, n->event.reg, n->event.id)); +ssam_nf_refcount_dec_free (nf, n->event.reg, n->event.id);mutex_unlock (&nf->lock);synchronize_srcu (&nf_head->srcu);return status; } - - entry->flags = n->event.flags; - - }else if (entry && entry->flags != n->event.flags) { -ssam_warn (ctrl, -"inconsistent flags when enabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n" , - n->event.flags, entry->flags, n->event.reg.target_category, - n->event.id.target_category, n->event.id.instance); }mutex_unlock (&nf->lock);
@@ -2247,35 +2360,20 @@ int ssam_notifier_unregister(struct ssam_controller *ctrl, struct ssam_event_not* If this is an observer notifier, do not attempt to disable the * event, just remove it. */ -if (n->flags &SSAM_EVENT_NOTIFIER_OBSERVER ) - goto remove; - - entry =ssam_nf_refcount_dec (nf, n->event.reg, n->event.id); -if (WARN_ON (!entry)) { -/* -* If this does not return an entry, there's a logic error -* somewhere: The notifier block is registered, but the event -* refcount entry is not there. Remove the notifier block -* anyways. -*/ - status = -ENOENT ; - goto remove; - } - -ssam_dbg (ctrl,"disabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , - n->event.reg.target_category, n->event.id.target_category, - n->event.id.instance, entry->refcount); - -if (entry->flags != n->event.flags) { -ssam_warn (ctrl, -"inconsistent flags when disabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n" , - n->event.flags, entry->flags, n->event.reg.target_category, - n->event.id.target_category, n->event.id.instance); - } +if (!(n->flags &SSAM_EVENT_NOTIFIER_OBSERVER )) { + entry =ssam_nf_refcount_dec (nf, n->event.reg, n->event.id); +if (WARN_ON (!entry)) { +/* +* If this does not return an entry, there's a logic +* error somewhere: The notifier block is registered, +* but the event refcount entry is not there. Remove +* the notifier block anyways. +*/ + status = -ENOENT ; + goto remove; + } -if (entry->refcount ==0 ) { - status =ssam_ssh_event_disable (ctrl, n->event.reg, n->event.id, n->event.flags); -kfree (entry); + status =ssam_nf_refcount_disable_free (ctrl, entry, n->event.flags); } remove:
@@ -2287,6 +2385,105 @@ int ssam_notifier_unregister(struct ssam_controller *ctrl, struct ssam_event_not }EXPORT_SYMBOL_GPL (ssam_notifier_unregister); +/** +* ssam_controller_event_enable() - Enable the specified event. +* @ctrl: The controller to enable the event for. +* @reg: The event registry to use for enabling the event. +* @id: The event ID specifying the event to be enabled. +* @flags: The SAM event flags used for enabling the event. +* +* Increment the event reference count of the specified event. If the event has +* not been enabled previously, it will be enabled by this call. +* +* Note: In general, ssam_notifier_register() with a non-observer notifier +* should be preferred for enabling/disabling events, as this will guarantee +* proper ordering and event forwarding in case of errors during event +* enabling/disabling. +* +* Return: Returns zero on success, %-ENOSPC if the reference count for the +* specified event has reached its maximum, %-ENOMEM if the corresponding event +* entry could not be allocated. If this is the first time that this event has +* been enabled (i.e. the reference count was incremented from zero to one by +* this call), returns the status of the event-enable EC-command. +*/ +int ssam_controller_event_enable (struct ssam_controller *ctrl, +struct ssam_event_registry reg, +struct ssam_event_id id,u8 flags) +{ +u16 rqid =ssh_tc_to_rqid (id.target_category); +struct ssam_nf *nf = &ctrl->cplt.event.notif; +struct ssam_nf_refcount_entry *entry; +int status; + +if (!ssh_rqid_is_event (rqid)) +return -EINVAL ; + +mutex_lock (&nf->lock); + + entry =ssam_nf_refcount_inc (nf, reg, id); +if (IS_ERR (entry)) { +mutex_unlock (&nf->lock); +return PTR_ERR (entry); + } + + status =ssam_nf_refcount_enable (ctrl, entry, flags); +if (status) { +ssam_nf_refcount_dec_free (nf, reg, id); +mutex_unlock (&nf->lock); +return status; + } + +mutex_unlock (&nf->lock); +return 0 ; +} +EXPORT_SYMBOL_GPL (ssam_controller_event_enable); + +/** +* ssam_controller_event_disable() - Disable the specified event. +* @ctrl: The controller to disable the event for. +* @reg: The event registry to use for disabling the event. +* @id: The event ID specifying the event to be disabled. +* @flags: The flags used when enabling the event. +* +* Decrement the reference count of the specified event. If the reference count +* reaches zero, the event will be disabled. +* +* Note: In general, ssam_notifier_register()/ssam_notifier_unregister() with a +* non-observer notifier should be preferred for enabling/disabling events, as +* this will guarantee proper ordering and event forwarding in case of errors +* during event enabling/disabling. +* +* Return: Returns zero on success, %-ENOENT if the given event has not been +* enabled on the controller. If the reference count of the event reaches zero +* during this call, returns the status of the event-disable EC-command. +*/ +int ssam_controller_event_disable (struct ssam_controller *ctrl, +struct ssam_event_registry reg, +struct ssam_event_id id,u8 flags) +{ +u16 rqid =ssh_tc_to_rqid (id.target_category); +struct ssam_nf *nf = &ctrl->cplt.event.notif; +struct ssam_nf_refcount_entry *entry; +int status =0 ; + +if (!ssh_rqid_is_event (rqid)) +return -EINVAL ; + +mutex_lock (&nf->lock); + + entry =ssam_nf_refcount_dec (nf, reg, id); +if (!entry) { +mutex_unlock (&nf->lock); +return -ENOENT ; + } + + status =ssam_nf_refcount_disable_free (ctrl, entry, flags); + +mutex_unlock (&nf->lock); +return status; +} +EXPORT_SYMBOL_GPL (ssam_controller_event_disable); +/** * ssam_notifier_disable_registered() - Disable events for all registered * notifiers.
include/linux/surface_aggregator/controller.h +8 -0
@@ -838,4 +838,12 @@ int ssam_notifier_register(struct ssam_controller *ctrl,int ssam_notifier_unregister (struct ssam_controller *ctrl,struct ssam_event_notifier *n); +int ssam_controller_event_enable (struct ssam_controller *ctrl, +struct ssam_event_registry reg, +struct ssam_event_id id,u8 flags); + +int ssam_controller_event_disable (struct ssam_controller *ctrl, +struct ssam_event_registry reg, +struct ssam_event_id id,u8 flags); +#endif /* _LINUX_SURFACE_AGGREGATOR_CONTROLLER_H */
Signature · 1 line
2.31.1
Re: [PATCH v2 2/7] platform/surface: aggregator: Allow enabling of events without notifiers
Hi,
Quoted 117 lines · Maximilian Luz
We can already enable and disable SAM events via one of two ways: either via a (non-observer) notifier tied to a specific event group, or a generic event enable/disable request. In some instances, however, neither method may be desirable.
The first method will tie the event enable request to a specific notifier, however, when we want to receive notifications for multiple event groups of the same target category and forward this to the same notifier callback, we may receive duplicate events, i.e. one event per registered notifier. The second method will bypass the internal reference counting mechanism, meaning that a disable request will disable the event regardless of any other client driver using it, which may break the functionality of that driver.
To address this problem, add new functions that allow enabling and disabling of events via the event reference counting mechanism built into the controller, without needing to register a notifier.
This can then be used in combination with observer notifiers to process multiple events of the same target category without duplication in the same callback function.
Signed-off-by Maximilian Luz <[email protected]>---
Changes in v2:
- Remove unused variable
- Avoid code duplication--- .../platform/surface/aggregator/controller.c | 293 +++++++++++++++--- include/linux/surface_aggregator/controller.h | 8 + 2 files changed, 253 insertions(+), 48 deletions(-)drivers/platform/surface/aggregator/controller.c +68
-0@@ -407,6 +407,31 @@ ssam_nf_refcount_dec(struct ssam_nf *nf, struct ssam_event_registry reg,return NULL ; } +/** +* ssam_nf_refcount_dec_free() - Decrement reference-/activation-count of the +* given event and free its entry if the reference count reaches zero. +* @nf: The notifier system reference. +* @reg: The registry used to enable/disable the event. +* @id: The event ID. +* +* Decrements the reference-/activation-count of the specified event, freeing +* its entry if it reaches zero. +* +* Note: ``nf->lock`` must be held when calling this function. +*/ +static void ssam_nf_refcount_dec_free (struct ssam_nf *nf, +struct ssam_event_registry reg, +struct ssam_event_id id) +{ +struct ssam_nf_refcount_entry *entry; + +lockdep_assert_held (&nf->lock); + + entry =ssam_nf_refcount_dec (nf, reg, id); +if (entry && entry->refcount ==0 ) +kfree (entry); +} +/** * ssam_nf_refcount_empty() - Test if the notification system has any * enabled/active events. @@ -2122,6 +2147,109 @@ int ssam_ctrl_notif_d0_entry(struct ssam_controller *ctrl)/* -- Top-level event registry interface. ----------------------------------- */ +/** +* ssam_nf_refcount_enable() - Enable event for reference count entry if it has +* not already been enabled. +* @ctrl: The controller to enable the event on. +* @entry: The reference count entry for the event to be enabled. +* @flags: The flags used for enabling the event on the EC. +* +* Enable the event associated with the given reference count entry if the +* reference count equals one, i.e. the event has not previously been enabled. +* If the event has already been enabled (i.e. reference count not equal to +* one), check that the flags used for enabling match and warn about this if +* they do not. +* +* This does not modify the reference count itself, which is done with +* ssam_nf_refcount_inc() / ssam_nf_refcount_dec(). +* +* Note: ``nf->lock`` must be held when calling this function. +* +* Return: Returns zero on success. If the event is enabled by this call, +* returns the status of the event-enable EC command. +*/ +static int ssam_nf_refcount_enable (struct ssam_controller *ctrl, +struct ssam_nf_refcount_entry *entry,u8 flags) +{ +const struct ssam_event_registry reg = entry->key.reg; +const struct ssam_event_id id = entry->key.id; +struct ssam_nf *nf = &ctrl->cplt.event.notif; +int status; + +lockdep_assert_held (&nf->lock); + +ssam_dbg (ctrl,"enabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , + reg.target_category, id.target_category, id.instance, entry->refcount); + +if (entry->refcount ==1 ) { + status =ssam_ssh_event_enable (ctrl, reg, id, flags); +if (status) +return status; + + entry->flags = flags; + + }else if (entry->flags != flags) { + ssam_warn(ctrl,
drivers/platform/surface/aggregator/controller.c int ssam_ctrl_notif_d0_entry(struct ssam_controller *ctrl) · line 2202
Quoted 10 lines
drivers/platform/surface/aggregator/controller.c +10
-0+"inconsistent flags when enabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n" , + flags, entry->flags, reg.target_category, id.target_category, + id.instance); + } + +return 0 ; +} + +/** +* ssam_nf_refcount_enable() - Disable event for reference count entry if it is
s/ssam_nf_refcount_enable/ssam_nf_refcount_disable_free/
No need to resend, I'll fix this up when merging this series.
Regards,
Hans
Quoted 273 lines
drivers/platform/surface/aggregator/controller.c +167
-48+* no longer in use and free the corresponding entry. +* @ctrl: The controller to disable the event on. +* @entry: The reference count entry for the event to be disabled. +* @flags: The flags used for enabling the event on the EC. +* +* If the reference count equals zero, i.e. the event is no longer requested by +* any client, the event will be disabled and the corresponding reference count +* entry freed. The reference count entry must not be used any more after a +* call to this function. +* +* Also checks if the flags used for disabling the event match the flags used +* for enabling the event and warns if they do not (regardless of reference +* count). +* +* This does not modify the reference count itself, which is done with +* ssam_nf_refcount_inc() / ssam_nf_refcount_dec(). +* +* Note: ``nf->lock`` must be held when calling this function. +* +* Return: Returns zero on success. If the event is disabled by this call, +* returns the status of the event-enable EC command. +*/ +static int ssam_nf_refcount_disable_free (struct ssam_controller *ctrl, +struct ssam_nf_refcount_entry *entry,u8 flags) +{ +const struct ssam_event_registry reg = entry->key.reg; +const struct ssam_event_id id = entry->key.id; +struct ssam_nf *nf = &ctrl->cplt.event.notif; +int status; + +lockdep_assert_held (&nf->lock); + +ssam_dbg (ctrl,"disabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , + reg.target_category, id.target_category, id.instance, entry->refcount); + +if (entry->flags != flags) { +ssam_warn (ctrl, +"inconsistent flags when disabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n" , + flags, entry->flags, reg.target_category, id.target_category, + id.instance); + } + +if (entry->refcount ==0 ) { + status =ssam_ssh_event_disable (ctrl, reg, id, flags); +kfree (entry); + } + +return status; +} +/** * ssam_notifier_register() - Register an event notifier. * @ctrl: The controller to register the notifier on. @@ -2166,41 +2294,26 @@ int ssam_notifier_register(struct ssam_controller *ctrl, struct ssam_event_notifmutex_unlock (&nf->lock);return PTR_ERR (entry); } - -ssam_dbg (ctrl,"enabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , - n->event.reg.target_category, n->event.id.target_category, - n->event.id.instance, entry->refcount); } status =ssam_nfblk_insert (nf_head, &n->base);if (status) { -if (entry) { - entry =ssam_nf_refcount_dec (nf, n->event.reg, n->event.id); -if (entry->refcount ==0 ) -kfree (entry); - } +if (entry) +ssam_nf_refcount_dec_free (nf, n->event.reg, n->event.id);mutex_unlock (&nf->lock);return status; } -if (entry && entry->refcount ==1 ) { - status =ssam_ssh_event_enable (ctrl, n->event.reg, n->event.id, n->event.flags); +if (entry) { + status =ssam_nf_refcount_enable (ctrl, entry, n->event.flags);if (status) {ssam_nfblk_remove (&n->base); -kfree (ssam_nf_refcount_dec (nf, n->event.reg, n->event.id)); +ssam_nf_refcount_dec_free (nf, n->event.reg, n->event.id);mutex_unlock (&nf->lock);synchronize_srcu (&nf_head->srcu);return status; } - - entry->flags = n->event.flags; - - }else if (entry && entry->flags != n->event.flags) { -ssam_warn (ctrl, -"inconsistent flags when enabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n" , - n->event.flags, entry->flags, n->event.reg.target_category, - n->event.id.target_category, n->event.id.instance); }mutex_unlock (&nf->lock);@@ -2247,35 +2360,20 @@ int ssam_notifier_unregister(struct ssam_controller *ctrl, struct ssam_event_not* If this is an observer notifier, do not attempt to disable the * event, just remove it. */ -if (n->flags &SSAM_EVENT_NOTIFIER_OBSERVER ) - goto remove; - - entry =ssam_nf_refcount_dec (nf, n->event.reg, n->event.id); -if (WARN_ON (!entry)) { -/* -* If this does not return an entry, there's a logic error -* somewhere: The notifier block is registered, but the event -* refcount entry is not there. Remove the notifier block -* anyways. -*/ - status = -ENOENT ; - goto remove; - } - -ssam_dbg (ctrl,"disabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , - n->event.reg.target_category, n->event.id.target_category, - n->event.id.instance, entry->refcount); - -if (entry->flags != n->event.flags) { -ssam_warn (ctrl, -"inconsistent flags when disabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n" , - n->event.flags, entry->flags, n->event.reg.target_category, - n->event.id.target_category, n->event.id.instance); - } +if (!(n->flags &SSAM_EVENT_NOTIFIER_OBSERVER )) { + entry =ssam_nf_refcount_dec (nf, n->event.reg, n->event.id); +if (WARN_ON (!entry)) { +/* +* If this does not return an entry, there's a logic +* error somewhere: The notifier block is registered, +* but the event refcount entry is not there. Remove +* the notifier block anyways. +*/ + status = -ENOENT ; + goto remove; + } -if (entry->refcount ==0 ) { - status =ssam_ssh_event_disable (ctrl, n->event.reg, n->event.id, n->event.flags); -kfree (entry); + status =ssam_nf_refcount_disable_free (ctrl, entry, n->event.flags); } remove:@@ -2287,6 +2385,105 @@ int ssam_notifier_unregister(struct ssam_controller *ctrl, struct ssam_event_not }EXPORT_SYMBOL_GPL (ssam_notifier_unregister); +/** +* ssam_controller_event_enable() - Enable the specified event. +* @ctrl: The controller to enable the event for. +* @reg: The event registry to use for enabling the event. +* @id: The event ID specifying the event to be enabled. +* @flags: The SAM event flags used for enabling the event. +* +* Increment the event reference count of the specified event. If the event has +* not been enabled previously, it will be enabled by this call. +* +* Note: In general, ssam_notifier_register() with a non-observer notifier +* should be preferred for enabling/disabling events, as this will guarantee +* proper ordering and event forwarding in case of errors during event +* enabling/disabling. +* +* Return: Returns zero on success, %-ENOSPC if the reference count for the +* specified event has reached its maximum, %-ENOMEM if the corresponding event +* entry could not be allocated. If this is the first time that this event has +* been enabled (i.e. the reference count was incremented from zero to one by +* this call), returns the status of the event-enable EC-command. +*/ +int ssam_controller_event_enable (struct ssam_controller *ctrl, +struct ssam_event_registry reg, +struct ssam_event_id id,u8 flags) +{ +u16 rqid =ssh_tc_to_rqid (id.target_category); +struct ssam_nf *nf = &ctrl->cplt.event.notif; +struct ssam_nf_refcount_entry *entry; +int status; + +if (!ssh_rqid_is_event (rqid)) +return -EINVAL ; + +mutex_lock (&nf->lock); + + entry =ssam_nf_refcount_inc (nf, reg, id); +if (IS_ERR (entry)) { +mutex_unlock (&nf->lock); +return PTR_ERR (entry); + } + + status =ssam_nf_refcount_enable (ctrl, entry, flags); +if (status) { +ssam_nf_refcount_dec_free (nf, reg, id); +mutex_unlock (&nf->lock); +return status; + } + +mutex_unlock (&nf->lock); +return 0 ; +} +EXPORT_SYMBOL_GPL (ssam_controller_event_enable); + +/** +* ssam_controller_event_disable() - Disable the specified event. +* @ctrl: The controller to disable the event for. +* @reg: The event registry to use for disabling the event. +* @id: The event ID specifying the event to be disabled. +* @flags: The flags used when enabling the event. +* +* Decrement the reference count of the specified event. If the reference count +* reaches zero, the event will be disabled. +* +* Note: In general, ssam_notifier_register()/ssam_notifier_unregister() with a +* non-observer notifier should be preferred for enabling/disabling events, as +* this will guarantee proper ordering and event forwarding in case of errors +* during event enabling/disabling. +* +* Return: Returns zero on success, %-ENOENT if the given event has not been +* enabled on the controller. If the reference count of the event reaches zero +* during this call, returns the status of the event-disable EC-command. +*/ +int ssam_controller_event_disable (struct ssam_controller *ctrl, +struct ssam_event_registry reg, +struct ssam_event_id id,u8 flags) +{ +u16 rqid =ssh_tc_to_rqid (id.target_category); +struct ssam_nf *nf = &ctrl->cplt.event.notif; +struct ssam_nf_refcount_entry *entry; +int status =0 ; + +if (!ssh_rqid_is_event (rqid)) +return -EINVAL ; + +mutex_lock (&nf->lock); + + entry =ssam_nf_refcount_dec (nf, reg, id); +if (!entry) { +mutex_unlock (&nf->lock); +return -ENOENT ; + } + + status =ssam_nf_refcount_disable_free (ctrl, entry, flags); + +mutex_unlock (&nf->lock); +return status; +} +EXPORT_SYMBOL_GPL (ssam_controller_event_disable); +/** * ssam_notifier_disable_registered() - Disable events for all registered * notifiers. include/linux/surface_aggregator/controller.h +8
-0@@ -838,4 +838,12 @@ int ssam_notifier_register(struct ssam_controller *ctrl,int ssam_notifier_unregister (struct ssam_controller *ctrl,struct ssam_event_notifier *n); +int ssam_controller_event_enable (struct ssam_controller *ctrl, +struct ssam_event_registry reg, +struct ssam_event_id id,u8 flags); + +int ssam_controller_event_disable (struct ssam_controller *ctrl, +struct ssam_event_registry reg, +struct ssam_event_id id,u8 flags); +#endif /* _LINUX_SURFACE_AGGREGATOR_CONTROLLER_H */
Maximilian Luz
maintainerRe: [PATCH v2 2/7] platform/surface: aggregator: Allow enabling of events without notifiers
Quoted 3 lines · Hans de Goede
Hi,
On 6/4/21 3:47 PM, Maximilian Luz wrote:
[...]
Quoted 35 lines
Quoted 22 lines
drivers/platform/surface/aggregator/controller.c +22
-0+static int ssam_nf_refcount_enable (struct ssam_controller *ctrl, +struct ssam_nf_refcount_entry *entry,u8 flags) +{ +const struct ssam_event_registry reg = entry->key.reg; +const struct ssam_event_id id = entry->key.id; +struct ssam_nf *nf = &ctrl->cplt.event.notif; +int status; + +lockdep_assert_held (&nf->lock); + +ssam_dbg (ctrl,"enabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n" , + reg.target_category, id.target_category, id.instance, entry->refcount); + +if (entry->refcount ==1 ) { + status =ssam_ssh_event_enable (ctrl, reg, id, flags); +if (status) +return status; + + entry->flags = flags; + + }else if (entry->flags != flags) { + ssam_warn(ctrl,drivers/platform/surface/aggregator/controller.c int ssam_ctrl_notif_d0_entry(struct ssam_controller *ctrl) · line 2202
Quoted 10 lines
drivers/platform/surface/aggregator/controller.c +10
-0+"inconsistent flags when enabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n" , + flags, entry->flags, reg.target_category, id.target_category, + id.instance); + } + +return 0 ; +} + +/** +* ssam_nf_refcount_enable() - Disable event for reference count entry if it is s/ssam_nf_refcount_enable/ssam_nf_refcount_disable_free/
Quoted 1 line
No need to resend, I'll fix this up when merging this series.
Oh right, thanks!
Regards,
Max
kernel test robot
build botRe: [PATCH v2 2/7] platform/surface: aggregator: Allow enabling of events without notifiers
In reply to Maximilian LuzI love your patch! Perhaps something to improve:
Hi Maximilian,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.13-rc4 next-20210604]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Maximilian-Luz/platform-surface-aggregator-Extend-user-space-interface-for-events/20210604-215134 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git f88cd3fb9df228e5ce4e13ec3dbad671ddb2146e config: x86_64-randconfig-r016-20210604 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 5c0d1b2f902aa6a9cf47cc7e42c5b83bb2217cf9)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/1d43dd8c1ca610c171da9a73c4122752f7cfd81d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Maximilian-Luz/platform-surface-aggregator-Extend-user-space-interface-for-events/20210604-215134 git checkout 1d43dd8c1ca610c171da9a73c4122752f7cfd81d
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/platform/surface/aggregator/controller.c:2245:6: warning: variable 'status' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
if (entry->refcount == 0) {
^~~~~~~~~~~~~~~~~~~~
drivers/platform/surface/aggregator/controller.c:2250:9: note: uninitialized use occurs here
return status;
^~~~~~
drivers/platform/surface/aggregator/controller.c:2245:2: note: remove the 'if' if its condition is always true
if (entry->refcount == 0) {
^~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/platform/surface/aggregator/controller.c:2231:12: note: initialize the variable 'status' to silence this warning
int status;
^
= 0
1 warning generated.
--
>> drivers/platform/surface/aggregator/controller.c:2227: warning: expecting prototype for ssam_nf_refcount_enable(). Prototype was for ssam_nf_refcount_disable_free() insteadvim +2245 drivers/platform/surface/aggregator/controller.c
2200
2201 /**
2202 * ssam_nf_refcount_enable() - Disable event for reference count entry if it is
2203 * no longer in use and free the corresponding entry.
2204 * @ctrl: The controller to disable the event on.
2205 * @entry: The reference count entry for the event to be disabled.
2206 * @flags: The flags used for enabling the event on the EC.
2207 *
2208 * If the reference count equals zero, i.e. the event is no longer requested by
2209 * any client, the event will be disabled and the corresponding reference count
2210 * entry freed. The reference count entry must not be used any more after a
2211 * call to this function.
2212 *
2213 * Also checks if the flags used for disabling the event match the flags used
2214 * for enabling the event and warns if they do not (regardless of reference
2215 * count).
2216 *
2217 * This does not modify the reference count itself, which is done with
2218 * ssam_nf_refcount_inc() / ssam_nf_refcount_dec().
2219 *
2220 * Note: ``nf->lock`` must be held when calling this function.
2221 *
2222 * Return: Returns zero on success. If the event is disabled by this call,
2223 * returns the status of the event-enable EC command.
2224 */
2225 static int ssam_nf_refcount_disable_free(struct ssam_controller *ctrl,
2226 struct ssam_nf_refcount_entry *entry, u8 flags)
> 2227 {
2228 const struct ssam_event_registry reg = entry->key.reg;
2229 const struct ssam_event_id id = entry->key.id;
2230 struct ssam_nf *nf = &ctrl->cplt.event.notif;
2231 int status;
2232
2233 lockdep_assert_held(&nf->lock);
2234
2235 ssam_dbg(ctrl, "disabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n",
2236 reg.target_category, id.target_category, id.instance, entry->refcount);
2237
2238 if (entry->flags != flags) {
2239 ssam_warn(ctrl,
2240 "inconsistent flags when disabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n",
2241 flags, entry->flags, reg.target_category, id.target_category,
2242 id.instance);
2243 }
2244
> 2245 if (entry->refcount == 0) { 2246 status = ssam_ssh_event_disable(ctrl, reg, id, flags);
2247 kfree(entry);
2248 }
2249
2250 return status;
2251 }
2252
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v2 2/7] platform/surface: aggregator: Allow enabling of events without notifiers
In reply to Maximilian LuzI love your patch! Perhaps something to improve:
Hi Maximilian,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.13-rc4 next-20210604]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Maximilian-Luz/platform-surface-aggregator-Extend-user-space-interface-for-events/20210604-215134 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git f88cd3fb9df228e5ce4e13ec3dbad671ddb2146e config: x86_64-randconfig-c022-20210604 (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/1d43dd8c1ca610c171da9a73c4122752f7cfd81d git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Maximilian-Luz/platform-surface-aggregator-Extend-user-space-interface-for-events/20210604-215134 git checkout 1d43dd8c1ca610c171da9a73c4122752f7cfd81d # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/platform/surface/aggregator/controller.c:2227: warning: expecting prototype for ssam_nf_refcount_enable(). Prototype was for ssam_nf_refcount_disable_free() instead
vim +2227 drivers/platform/surface/aggregator/controller.c
2200
2201 /**
2202 * ssam_nf_refcount_enable() - Disable event for reference count entry if it is
2203 * no longer in use and free the corresponding entry.
2204 * @ctrl: The controller to disable the event on.
2205 * @entry: The reference count entry for the event to be disabled.
2206 * @flags: The flags used for enabling the event on the EC.
2207 *
2208 * If the reference count equals zero, i.e. the event is no longer requested by
2209 * any client, the event will be disabled and the corresponding reference count
2210 * entry freed. The reference count entry must not be used any more after a
2211 * call to this function.
2212 *
2213 * Also checks if the flags used for disabling the event match the flags used
2214 * for enabling the event and warns if they do not (regardless of reference
2215 * count).
2216 *
2217 * This does not modify the reference count itself, which is done with
2218 * ssam_nf_refcount_inc() / ssam_nf_refcount_dec().
2219 *
2220 * Note: ``nf->lock`` must be held when calling this function.
2221 *
2222 * Return: Returns zero on success. If the event is disabled by this call,
2223 * returns the status of the event-enable EC command.
2224 */
2225 static int ssam_nf_refcount_disable_free(struct ssam_controller *ctrl,
2226 struct ssam_nf_refcount_entry *entry, u8 flags)
> 2227 {
2228 const struct ssam_event_registry reg = entry->key.reg;
2229 const struct ssam_event_id id = entry->key.id;
2230 struct ssam_nf *nf = &ctrl->cplt.event.notif;
2231 int status;
2232
2233 lockdep_assert_held(&nf->lock);
2234
2235 ssam_dbg(ctrl, "disabling event (reg: %#04x, tc: %#04x, iid: %#04x, rc: %d)\n",
2236 reg.target_category, id.target_category, id.instance, entry->refcount);
2237
2238 if (entry->flags != flags) {
2239 ssam_warn(ctrl,
2240 "inconsistent flags when disabling event: got %#04x, expected %#04x (reg: %#04x, tc: %#04x, iid: %#04x)\n",
2241 flags, entry->flags, reg.target_category, id.target_category,
2242 id.instance); 2243 }
2244
2245 if (entry->refcount == 0) {
2246 status = ssam_ssh_event_disable(ctrl, reg, id, flags);
2247 kfree(entry);
2248 }
2249
2250 return status;
2251 }
2252
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Maximilian Luz
maintainerPATCH v2 3/7 platform/surface: aggregator: Update copyright
In reply to Maximilian LuzIt's 2021, update the copyright accordingly.
---
Changes in v2:
- None
--- drivers/platform/surface/aggregator/Kconfig | 2 +- drivers/platform/surface/aggregator/Makefile | 2 +- drivers/platform/surface/aggregator/bus.c | 2 +- drivers/platform/surface/aggregator/bus.h | 2 +- drivers/platform/surface/aggregator/controller.c | 2 +- drivers/platform/surface/aggregator/controller.h | 2 +- drivers/platform/surface/aggregator/core.c | 2 +- drivers/platform/surface/aggregator/ssh_msgb.h | 2 +- drivers/platform/surface/aggregator/ssh_packet_layer.c | 2 +- drivers/platform/surface/aggregator/ssh_packet_layer.h | 2 +- drivers/platform/surface/aggregator/ssh_parser.c | 2 +- drivers/platform/surface/aggregator/ssh_parser.h | 2 +- drivers/platform/surface/aggregator/ssh_request_layer.c | 2 +- drivers/platform/surface/aggregator/ssh_request_layer.h | 2 +- drivers/platform/surface/aggregator/trace.h | 2 +- include/linux/surface_aggregator/controller.h | 2 +- include/linux/surface_aggregator/device.h | 2 +- include/linux/surface_aggregator/serial_hub.h | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-)
drivers/platform/surface/aggregator/Kconfig +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ -# Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +# Copyright (C) 2019-2021 Maximilian Luz <[email protected]> menuconfig SURFACE_AGGREGATOR tristate "Microsoft Surface System Aggregator Module Subsystem and Drivers"
drivers/platform/surface/aggregator/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ -# Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +# Copyright (C) 2019-2021 Maximilian Luz <[email protected]> # For include/trace/define_trace.h to include trace.h CFLAGS_core.o = -I$(src)
drivers/platform/surface/aggregator/bus.c +1 -1
@@ -2,7 +2,7 @@/* * Surface System Aggregator Module bus and device integration. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #include <linux/device.h>
drivers/platform/surface/aggregator/bus.h +1 -1
@@ -2,7 +2,7 @@/* * Surface System Aggregator Module bus and device integration. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #ifndef _SURFACE_AGGREGATOR_BUS_H
drivers/platform/surface/aggregator/controller.c +1 -1
@@ -2,7 +2,7 @@/* * Main SSAM/SSH controller structure and functionality. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #include <linux/acpi.h>
drivers/platform/surface/aggregator/controller.h +1 -1
@@ -2,7 +2,7 @@/* * Main SSAM/SSH controller structure and functionality. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #ifndef _SURFACE_AGGREGATOR_CONTROLLER_H
drivers/platform/surface/aggregator/core.c +1 -1
@@ -7,7 +7,7 @@* Handles communication via requests as well as enabling, disabling, and * relaying of events. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #include <linux/acpi.h>
drivers/platform/surface/aggregator/ssh_msgb.h +1 -1
@@ -2,7 +2,7 @@/* * SSH message builder functions. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #ifndef _SURFACE_AGGREGATOR_SSH_MSGB_H
drivers/platform/surface/aggregator/ssh_packet_layer.c +1 -1
@@ -2,7 +2,7 @@/* * SSH packet transport layer. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #include <asm/unaligned.h>
drivers/platform/surface/aggregator/ssh_packet_layer.h +1 -1
@@ -2,7 +2,7 @@/* * SSH packet transport layer. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #ifndef _SURFACE_AGGREGATOR_SSH_PACKET_LAYER_H
drivers/platform/surface/aggregator/ssh_parser.c +1 -1
@@ -2,7 +2,7 @@/* * SSH message parser. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #include <asm/unaligned.h>
drivers/platform/surface/aggregator/ssh_parser.h +1 -1
@@ -2,7 +2,7 @@/* * SSH message parser. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #ifndef _SURFACE_AGGREGATOR_SSH_PARSER_H
drivers/platform/surface/aggregator/ssh_request_layer.c +1 -1
@@ -2,7 +2,7 @@/* * SSH request transport layer. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #include <asm/unaligned.h>
drivers/platform/surface/aggregator/ssh_request_layer.h +1 -1
@@ -2,7 +2,7 @@/* * SSH request transport layer. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #ifndef _SURFACE_AGGREGATOR_SSH_REQUEST_LAYER_H
drivers/platform/surface/aggregator/trace.h +1 -1
@@ -2,7 +2,7 @@/* * Trace points for SSAM/SSH. * -* Copyright (C) 2020 Maximilian Luz <[email protected]> +* Copyright (C) 2020-2021 Maximilian Luz <[email protected]> */ #undef TRACE_SYSTEM
include/linux/surface_aggregator/controller.h +1 -1
@@ -6,7 +6,7 @@* managing access and communication to and from the SSAM EC, as well as main * communication structures and definitions. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #ifndef _LINUX_SURFACE_AGGREGATOR_CONTROLLER_H
include/linux/surface_aggregator/device.h +1 -1
@@ -7,7 +7,7 @@* Provides support for non-platform/non-ACPI SSAM clients via dedicated * subsystem. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #ifndef _LINUX_SURFACE_AGGREGATOR_DEVICE_H
include/linux/surface_aggregator/serial_hub.h +1 -1
@@ -6,7 +6,7 @@* Surface System Aggregator Module (SSAM). Provides the interface for basic * packet- and request-based communication with the SSAM EC via SSH. * -* Copyright (C) 2019-2020 Maximilian Luz <[email protected]> +* Copyright (C) 2019-2021 Maximilian Luz <[email protected]> */ #ifndef _LINUX_SURFACE_AGGREGATOR_SERIAL_HUB_H
Signature · 1 line
2.31.1
Maximilian Luz
maintainerPATCH v2 4/7 platform/surface: aggregator_cdev: Add support for forwarding events to user-space
In reply to Maximilian LuzCurrently, debugging unknown events requires writing a custom driver. This is somewhat difficult, slow to adapt, and not entirely user-friendly for quickly trying to figure out things on devices of some third-party user. We can do better. We already have a user-space interface intended for debugging SAM EC requests, so let's add support for receiving events to that.
This commit provides support for receiving events by reading from the controller file. It additionally introduces two new IOCTLs to control which event categories will be forwarded. Specifically, a user-space client can specify which target categories it wants to receive events from by registering the corresponding notifier(s) via the IOCTLs and after that, read the received events by reading from the controller device.
---
Changes in v2:
- Add missing mutex_destroy() calls in open() failure path
--- .../userspace-api/ioctl/ioctl-number.rst | 2 +- .../surface/surface_aggregator_cdev.c | 460 +++++++++++++++++- include/uapi/linux/surface_aggregator/cdev.h | 41 +- 3 files changed, 477 insertions(+), 26 deletions(-)
Documentation/userspace-api/ioctl/ioctl-number.rst +1 -1
@@ -325,7 +325,7 @@ Code Seq# Include File Comments 0xA3 90-9F linux/dtlk.h 0xA4 00-1F uapi/linux/tee.h Generic TEE subsystem 0xA4 00-1F uapi/asm/sgx.h <mailto:[email protected]> -0xA5 01 linux/surface_aggregator/cdev.h Microsoft Surface Platform System Aggregator +0xA5 01-05 linux/surface_aggregator/cdev.h Microsoft Surface Platform System Aggregator <mailto:[email protected]> 0xA5 20-2F linux/surface_aggregator/dtx.h Microsoft Surface DTX driver <mailto:[email protected]>
drivers/platform/surface/surface_aggregator_cdev.c +437 -23
580 lines not on this page · raw message
include/uapi/linux/surface_aggregator/cdev.h +39 -2
52 lines not on this page · raw message
Signature · 1 line
2.31.1
Maximilian Luz
maintainerPATCH v2 5/7 platform/surface: aggregator_cdev: Allow enabling of events from user-space
In reply to Maximilian LuzWhile events can already be enabled and disabled via the generic request IOCTL, this bypasses the internal reference counting mechanism of the controller. Due to that, disabling an event will turn it off regardless of any other client having requested said event, which may break functionality of that client.
To solve this, add IOCTLs wrapping the ssam_controller_event_enable() and ssam_controller_event_disable() functions, which have been previously introduced for this specific purpose.
---
Changes in v2:
- None
--- .../surface/surface_aggregator_cdev.c | 58 +++++++++++++++++++ include/uapi/linux/surface_aggregator/cdev.h | 32 ++++++++++ 2 files changed, 90 insertions(+)
drivers/platform/surface/surface_aggregator_cdev.c +58 -0
@@ -387,6 +387,58 @@ static long ssam_cdev_notif_unregister(struct ssam_cdev_client *client,return ssam_cdev_notifier_unregister (client, desc.target_category); } +static long ssam_cdev_event_enable (struct ssam_cdev_client *client, +const struct ssam_cdev_event_desc __user *d) +{ +struct ssam_cdev_event_desc desc; +struct ssam_event_registry reg; +struct ssam_event_id id; +long ret; + +/* Read descriptor from user-space. */ + ret =copy_struct_from_user (&desc,sizeof (desc), d,sizeof (*d)); +if (ret) +return ret; + +/* Translate descriptor. */ + reg.target_category = desc.reg.target_category; + reg.target_id = desc.reg.target_id; + reg.cid_enable = desc.reg.cid_enable; + reg.cid_disable = desc.reg.cid_disable; + + id.target_category = desc.id.target_category; + id.instance = desc.id.instance; + +/* Disable event. */ +return ssam_controller_event_enable (client->cdev->ctrl, reg, id, desc.flags); +} + +static long ssam_cdev_event_disable (struct ssam_cdev_client *client, +const struct ssam_cdev_event_desc __user *d) +{ +struct ssam_cdev_event_desc desc; +struct ssam_event_registry reg; +struct ssam_event_id id; +long ret; + +/* Read descriptor from user-space. */ + ret =copy_struct_from_user (&desc,sizeof (desc), d,sizeof (*d)); +if (ret) +return ret; + +/* Translate descriptor. */ + reg.target_category = desc.reg.target_category; + reg.target_id = desc.reg.target_id; + reg.cid_enable = desc.reg.cid_enable; + reg.cid_disable = desc.reg.cid_disable; + + id.target_category = desc.id.target_category; + id.instance = desc.id.instance; + +/* Disable event. */ +return ssam_controller_event_disable (client->cdev->ctrl, reg, id, desc.flags); +} +/* -- File operations. ------------------------------------------------------ */
@@ -473,6 +525,12 @@ static long __ssam_cdev_device_ioctl(struct ssam_cdev_client *client, unsigned ireturn ssam_cdev_notif_unregister (client, (struct ssam_cdev_notifier_desc __user *)arg); +case SSAM_CDEV_EVENT_ENABLE : +return ssam_cdev_event_enable (client, (struct ssam_cdev_event_desc __user *)arg); + +case SSAM_CDEV_EVENT_DISABLE : +return ssam_cdev_event_disable (client, (struct ssam_cdev_event_desc __user *)arg); +default :return -ENOTTY ; }
include/uapi/linux/surface_aggregator/cdev.h +32 -0
@@ -90,6 +90,36 @@ struct ssam_cdev_notifier_desc {__u8 target_category; } __attribute__((__packed__)); +/** +* struct ssam_cdev_event_desc - Event descriptor. +* @reg: Registry via which the event will be enabled/disabled. +* @reg.target_category: Target category for the event registry requests. +* @reg.target_id: Target ID for the event registry requests. +* @reg.cid_enable: Command ID for the event-enable request. +* @reg.cid_disable: Command ID for the event-disable request. +* @id: ID specifying the event. +* @id.target_category: Target category of the event source. +* @id.instance: Instance ID of the event source. +* @flags: Flags used for enabling the event. +* +* Specifies which event should be enabled/disabled and how to do that. +*/ +struct ssam_cdev_event_desc { +struct { +__u8 target_category; +__u8 target_id; +__u8 cid_enable; +__u8 cid_disable; + } reg; + +struct { +__u8 target_category; +__u8 instance; + } id; + +__u8 flags; +} __attribute__((__packed__ )); +/** * struct ssam_cdev_event - SSAM event sent by the EC. * @target_category: Target category of the event source. See &enum ssam_ssh_tc.
@@ -111,5 +141,7 @@ struct ssam_cdev_event {#define SSAM_CDEV_REQUEST _IOWR(0xA5, 1, struct ssam_cdev_request)#define SSAM_CDEV_NOTIF_REGISTER _IOW(0xA5, 2, struct ssam_cdev_notifier_desc)#define SSAM_CDEV_NOTIF_UNREGISTER _IOW(0xA5, 3, struct ssam_cdev_notifier_desc) +#define SSAM_CDEV_EVENT_ENABLE _IOW(0xA5, 4, struct ssam_cdev_event_desc) +#define SSAM_CDEV_EVENT_DISABLE _IOW(0xA5, 5, struct ssam_cdev_event_desc)#endif /* _UAPI_LINUX_SURFACE_AGGREGATOR_CDEV_H */
Signature · 1 line
2.31.1
Maximilian Luz
maintainerPATCH v2 6/7 platform/surface: aggregator_cdev: Add lockdep support
In reply to Maximilian LuzMark functions with locking requirements via the corresponding lockdep calls for debugging and documentary purposes.
---
Changes in v2:
- None
--- .../platform/surface/surface_aggregator_cdev.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/platform/surface/surface_aggregator_cdev.c +16 -0
@@ -139,6 +139,8 @@ static int ssam_cdev_notifier_register(struct ssam_cdev_client *client, u8 tc, istruct ssam_cdev_notifier *nf;int status; +lockdep_assert_held_read (&client->cdev->lock); +/* Validate notifier target category. */ if (!ssh_rqid_is_event (rqid))return -EINVAL ;
@@ -188,6 +190,8 @@ static int ssam_cdev_notifier_unregister(struct ssam_cdev_client *client, u8 tc)const u16 event =ssh_rqid_to_event (rqid);int status; +lockdep_assert_held_read (&client->cdev->lock); +/* Validate notifier target category. */ if (!ssh_rqid_is_event (rqid))return -EINVAL ;
@@ -257,6 +261,8 @@ static long ssam_cdev_request(struct ssam_cdev_client *client, struct ssam_cdev_void __user *rspdata;int status =0 , ret =0 , tmp; +lockdep_assert_held_read (&client->cdev->lock); + ret =copy_struct_from_user (&rqst,sizeof (rqst), r,sizeof (*r));if (ret) goto out;
@@ -367,6 +373,8 @@ static long ssam_cdev_notif_register(struct ssam_cdev_client *client,struct ssam_cdev_notifier_desc desc;long ret; +lockdep_assert_held_read (&client->cdev->lock); + ret =copy_struct_from_user (&desc,sizeof (desc), d,sizeof (*d));if (ret)return ret;
@@ -380,6 +388,8 @@ static long ssam_cdev_notif_unregister(struct ssam_cdev_client *client,struct ssam_cdev_notifier_desc desc;long ret; +lockdep_assert_held_read (&client->cdev->lock); + ret =copy_struct_from_user (&desc,sizeof (desc), d,sizeof (*d));if (ret)return ret;
@@ -395,6 +405,8 @@ static long ssam_cdev_event_enable(struct ssam_cdev_client *client,struct ssam_event_id id;long ret; +lockdep_assert_held_read (&client->cdev->lock); +/* Read descriptor from user-space. */ ret =copy_struct_from_user (&desc,sizeof (desc), d,sizeof (*d));if (ret)
@@ -421,6 +433,8 @@ static long ssam_cdev_event_disable(struct ssam_cdev_client *client,struct ssam_event_id id;long ret; +lockdep_assert_held_read (&client->cdev->lock); +/* Read descriptor from user-space. */ ret =copy_struct_from_user (&desc,sizeof (desc), d,sizeof (*d));if (ret)
@@ -513,6 +527,8 @@ static int ssam_cdev_device_release(struct inode *inode, struct file *filp)static long __ssam_cdev_device_ioctl (struct ssam_cdev_client *client,unsigned int cmd,unsigned long arg) { +lockdep_assert_held_read (&client->cdev->lock); +switch (cmd) {case SSAM_CDEV_REQUEST :return ssam_cdev_request (client, (struct ssam_cdev_request __user *)arg);
Signature · 1 line
2.31.1
Maximilian Luz
maintainerPATCH v2 7/7 docs: driver-api: Update Surface Aggregator user-space interface documentation
In reply to Maximilian LuzUpdate the controller-device user-space interface (cdev) documentation for the newly introduced IOCTLs and event interface.
---
Changes in v2:
- None
--- .../surface_aggregator/clients/cdev.rst | 127 +++++++++++++++++- 1 file changed, 122 insertions(+), 5 deletions(-)
Documentation/driver-api/surface_aggregator/clients/cdev.rst +122 -5
@@ -1,9 +1,8 @@ .. SPDX-License-Identifier: GPL-2.0+ -.. |u8| replace:: :c:type:`u8 <u8>` -.. |u16| replace:: :c:type:`u16 <u16>` .. |ssam_cdev_request| replace:: :c:type:`struct ssam_cdev_request <ssam_cdev_request>` .. |ssam_cdev_request_flags| replace:: :c:type:`enum ssam_cdev_request_flags <ssam_cdev_request_flags>` +.. |ssam_cdev_event| replace:: :c:type:`struct ssam_cdev_event <ssam_cdev_event>` ============================== User-Space EC Interface (cdev)
@@ -23,6 +22,40 @@ These IOCTLs and their respective input/output parameter structs are defined in A small python library and scripts for accessing this interface can be found at https://github.com/linux-surface/surface-aggregator-module/tree/master/scripts/ssam. +.. contents:: + + +Receiving Events +================ + +Events can be received by reading from the device-file. The are represented by +the |ssam_cdev_event| datatype. + +Before events are available to be read, however, the desired notifiers must be +registered via the ``SSAM_CDEV_NOTIF_REGISTER`` IOCTL. Notifiers are, in +essence, callbacks, called when the EC sends an event. They are, in this +interface, associated with a specific target category and device-file-instance. +They forward any event of this category to the buffer of the corresponding +instance, from which it can then be read. + +Notifiers themselves do not enable events on the EC. Thus, it may additionally +be necessary to enable events via the ``SSAM_CDEV_EVENT_ENABLE`` IOCTL. While +notifiers work per-client (i.e. per-device-file-instance), events are enabled +globally, for the EC and all of its clients (regardless of userspace or +non-userspace). The ``SSAM_CDEV_EVENT_ENABLE`` and ``SSAM_CDEV_EVENT_DISABLE`` +IOCTLs take care of reference counting the events, such that an event is +enabled as long as there is a client that has requested it. + +Note that enabled events are not automatically disabled once the client +instance is closed. Therefore any client process (or group of processes) should +balance their event enable calls with the corresponding event disable calls. It +is, however, perfectly valid to enable and disable events on different client +instances. For example, it is valid to set up notifiers and read events on +client instance ``A``, enable those events on instance ``B`` (note that these +will also be received by A since events are enabled/disabled globally), and +after no more events are desired, disable the previously enabled events via +instance ``C``. + Controller IOCTLs =================
@@ -45,9 +78,33 @@ The following IOCTLs are provided: - ``REQUEST`` - Perform synchronous SAM request. + * - ``0xA5`` + - ``2`` + - ``W`` + - ``NOTIF_REGISTER`` + - Register event notifier. -``REQUEST`` ------------ + * - ``0xA5`` + - ``3`` + - ``W`` + - ``NOTIF_UNREGISTER`` + - Unregister event notifier. + + * - ``0xA5`` + - ``4`` + - ``W`` + - ``EVENT_ENABLE`` + - Enable event source. + + * - ``0xA5`` + - ``5`` + - ``W`` + - ``EVENT_DISABLE`` + - Disable event source. + + +``SSAM_CDEV_REQUEST`` +--------------------- Defined as ``_IOWR(0xA5, 1, struct ssam_cdev_request)``.
@@ -82,6 +139,66 @@ submitted, and completed (i.e. handed back to user-space) successfully from inside the IOCTL, but the request ``status`` member may still be negative in case the actual execution of the request failed after it has been submitted. -A full definition of the argument struct is provided below: +A full definition of the argument struct is provided below. + +``SSAM_CDEV_NOTIF_REGISTER`` +---------------------------- + +Defined as ``_IOW(0xA5, 2, struct ssam_cdev_notifier_desc)``. + +Register a notifier for the event target category specified in the given +notifier description with the specified priority. Notifiers registration is +required to receive events, but does not enable events themselves. After a +notifier for a specific target category has been registered, all events of that +category will be forwarded to the userspace client and can then be read from +the device file instance. Note that events may have to be enabled, e.g. via the +``SSAM_CDEV_EVENT_ENABLE`` IOCTL, before the EC will send them. + +Only one notifier can be registered per target category and client instance. If +a notifier has already been registered, this IOCTL will fail with ``-EEXIST``. + +Notifiers will automatically be removed when the device file instance is +closed. + +``SSAM_CDEV_NOTIF_UNREGISTER`` +------------------------------ + +Defined as ``_IOW(0xA5, 3, struct ssam_cdev_notifier_desc)``. + +Unregisters the notifier associated with the specified target category. The +priority field will be ignored by this IOCTL. If no notifier has been +registered for this client instance and the given category, this IOCTL will +fail with ``-ENOENT``. + +``SSAM_CDEV_EVENT_ENABLE`` +-------------------------- + +Defined as ``_IOW(0xA5, 4, struct ssam_cdev_event_desc)``. + +Enable the event associated with the given event descriptor. + +Note that this call will not register a notifier itself, it will only enable +events on the controller. If you want to receive events by reading from the +device file, you will need to register the corresponding notifier(s) on that +instance. + +Events are not automatically disabled when the device file is closed. This must +be done manually, via a call to the ``SSAM_CDEV_EVENT_DISABLE`` IOCTL. + +``SSAM_CDEV_EVENT_DISABLE`` +--------------------------- + +Defined as ``_IOW(0xA5, 5, struct ssam_cdev_event_desc)``. + +Disable the event associated with the given event descriptor. + +Note that this will not unregister any notifiers. Events may still be received +and forwarded to user-space after this call. The only safe way of stopping +events from being received is unregistering all previously registered +notifiers. + + +Structures and Enums +==================== .. kernel-doc:: include/uapi/linux/surface_aggregator/cdev.h
Signature · 1 line
2.31.1
Hi,
Quoted 10 lines · Maximilian Luz
Extend the user-space debug interface so that it can be used to receive SSAM events in user-space.
Version 1 and rationale:
https://lore.kernel.org/platform-driver-x86/[email protected]/Changes in version 2:
- PATCH 2/7: Avoid code duplication, remove unused variable
- PATCH 4/7: Add missingmutex_destroy()calls
Quoted 13 lines
Maximilian Luz (7):
platform/surface: aggregator: Allow registering notifiers without
enabling events
platform/surface: aggregator: Allow enabling of events without
notifiers
platform/surface: aggregator: Update copyright platform/surface:aggregator_cdev: Add support for forwarding events
to user-space
platform/surface:aggregator_cdev: Allow enabling of events from
user-space
platform/surface:aggregator_cdev: Add lockdep support
docs: driver-api: Update Surface Aggregator user-space interface
documentation
Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
I've done one small fixup to patch 2/7, see my reply to that patch.
Once the builders have had some time to test this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.
Regards,
Hans
Quoted 25 lines
.../surface_aggregator/clients/cdev.rst | 127 ++++- .../userspace-api/ioctl/ioctl-number.rst | 2 +- drivers/platform/surface/aggregator/Kconfig | 2 +- drivers/platform/surface/aggregator/Makefile | 2 +- drivers/platform/surface/aggregator/bus.c | 2 +- drivers/platform/surface/aggregator/bus.h | 2 +- .../platform/surface/aggregator/controller.c | 332 +++++++++-- .../platform/surface/aggregator/controller.h | 2 +- drivers/platform/surface/aggregator/core.c | 2 +- .../platform/surface/aggregator/ssh_msgb.h | 2 +- .../surface/aggregator/ssh_packet_layer.c | 2 +- .../surface/aggregator/ssh_packet_layer.h | 2 +- .../platform/surface/aggregator/ssh_parser.c | 2 +- .../platform/surface/aggregator/ssh_parser.h | 2 +- .../surface/aggregator/ssh_request_layer.c | 2 +- .../surface/aggregator/ssh_request_layer.h | 2 +- drivers/platform/surface/aggregator/trace.h | 2 +- .../surface/surface_aggregator_cdev.c | 534 +++++++++++++++++- include/linux/surface_aggregator/controller.h | 27 +- include/linux/surface_aggregator/device.h | 2 +- include/linux/surface_aggregator/serial_hub.h | 2 +- include/uapi/linux/surface_aggregator/cdev.h | 73 ++- 22 files changed, 1018 insertions(+), 109 deletions(-)