1 // SPDX-License-Identifier: GPL-2.0
3 * System Control and Management Interface (SCMI) Notification support
5 * Copyright (C) 2020 ARM Ltd.
8 * DOC: Theory of operation
10 * SCMI Protocol specification allows the platform to signal events to
11 * interested agents via notification messages: this is an implementation
12 * of the dispatch and delivery of such notifications to the interested users
13 * inside the Linux kernel.
15 * An SCMI Notification core instance is initialized for each active platform
16 * instance identified by the means of the usual &struct scmi_handle.
18 * Each SCMI Protocol implementation, during its initialization, registers with
19 * this core its set of supported events using scmi_register_protocol_events():
20 * all the needed descriptors are stored in the &struct registered_protocols and
21 * &struct registered_events arrays.
23 * Kernel users interested in some specific event can register their callbacks
24 * providing the usual notifier_block descriptor, since this core implements
25 * events' delivery using the standard Kernel notification chains machinery.
27 * Given the number of possible events defined by SCMI and the extensibility
28 * of the SCMI Protocol itself, the underlying notification chains are created
29 * and destroyed dynamically on demand depending on the number of users
30 * effectively registered for an event, so that no support structures or chains
31 * are allocated until at least one user has registered a notifier_block for
32 * such event. Similarly, events' generation itself is enabled at the platform
33 * level only after at least one user has registered, and it is shutdown after
34 * the last user for that event has gone.
36 * All users provided callbacks and allocated notification-chains are stored in
37 * the @registered_events_handlers hashtable. Callbacks' registration requests
38 * for still to be registered events are instead kept in the dedicated common
39 * hashtable @pending_events_handlers.
41 * An event is identified univocally by the tuple (proto_id, evt_id, src_id)
42 * and is served by its own dedicated notification chain; information contained
43 * in such tuples is used, in a few different ways, to generate the needed
46 * Here proto_id and evt_id are simply the protocol_id and message_id numbers
47 * as described in the SCMI Protocol specification, while src_id represents an
48 * optional, protocol dependent, source identifier (like domain_id, perf_id
49 * or sensor_id and so forth).
51 * Upon reception of a notification message from the platform the SCMI RX ISR
52 * passes the received message payload and some ancillary information (including
53 * an arrival timestamp in nanoseconds) to the core via @scmi_notify() which
54 * pushes the event-data itself on a protocol-dedicated kfifo queue for further
55 * deferred processing as specified in @scmi_events_dispatcher().
57 * Each protocol has it own dedicated work_struct and worker which, once kicked
58 * by the ISR, takes care to empty its own dedicated queue, deliverying the
59 * queued items into the proper notification-chain: notifications processing can
60 * proceed concurrently on distinct workers only between events belonging to
61 * different protocols while delivery of events within the same protocol is
62 * still strictly sequentially ordered by time of arrival.
64 * Events' information is then extracted from the SCMI Notification messages and
65 * conveyed, converted into a custom per-event report struct, as the void *data
66 * param to the user callback provided by the registered notifier_block, so that
67 * from the user perspective his callback will look invoked like:
69 * int user_cb(struct notifier_block *nb, unsigned long event_id, void *report)
73 #define dev_fmt(fmt) "SCMI Notifications - " fmt
74 #define pr_fmt(fmt) "SCMI Notifications - " fmt
76 #include <linux/bitfield.h>
77 #include <linux/bug.h>
78 #include <linux/compiler.h>
79 #include <linux/device.h>
80 #include <linux/err.h>
81 #include <linux/hashtable.h>
82 #include <linux/kernel.h>
83 #include <linux/ktime.h>
84 #include <linux/kfifo.h>
85 #include <linux/list.h>
86 #include <linux/mutex.h>
87 #include <linux/notifier.h>
88 #include <linux/refcount.h>
89 #include <linux/scmi_protocol.h>
90 #include <linux/slab.h>
91 #include <linux/types.h>
92 #include <linux/workqueue.h>
96 #define SCMI_MAX_PROTO 256
98 #define PROTO_ID_MASK GENMASK(31, 24)
99 #define EVT_ID_MASK GENMASK(23, 16)
100 #define SRC_ID_MASK GENMASK(15, 0)
103 * Builds an unsigned 32bit key from the given input tuple to be used
104 * as a key in hashtables.
106 #define MAKE_HASH_KEY(p, e, s) \
107 (FIELD_PREP(PROTO_ID_MASK, (p)) | \
108 FIELD_PREP(EVT_ID_MASK, (e)) | \
109 FIELD_PREP(SRC_ID_MASK, (s)))
111 #define MAKE_ALL_SRCS_KEY(p, e) MAKE_HASH_KEY((p), (e), SRC_ID_MASK)
114 * Assumes that the stored obj includes its own hash-key in a field named 'key':
115 * with this simplification this macro can be equally used for all the objects'
116 * types hashed by this implementation.
118 * @__ht: The hashtable name
119 * @__obj: A pointer to the object type to be retrieved from the hashtable;
120 * it will be used as a cursor while scanning the hastable and it will
121 * be possibly left as NULL when @__k is not found
122 * @__k: The key to search for
124 #define KEY_FIND(__ht, __obj, __k) \
126 typeof(__k) k_ = __k; \
127 typeof(__obj) obj_; \
129 hash_for_each_possible((__ht), obj_, hash, k_) \
130 if (obj_->key == k_) \
135 #define KEY_XTRACT_PROTO_ID(key) FIELD_GET(PROTO_ID_MASK, (key))
136 #define KEY_XTRACT_EVT_ID(key) FIELD_GET(EVT_ID_MASK, (key))
137 #define KEY_XTRACT_SRC_ID(key) FIELD_GET(SRC_ID_MASK, (key))
140 * A set of macros used to access safely @registered_protocols and
141 * @registered_events arrays; these are fixed in size and each entry is possibly
142 * populated at protocols' registration time and then only read but NEVER
143 * modified or removed.
145 #define SCMI_GET_PROTO(__ni, __pid) \
147 typeof(__ni) ni_ = __ni; \
148 struct scmi_registered_events_desc *__pd = NULL; \
151 __pd = READ_ONCE(ni_->registered_protocols[(__pid)]); \
155 #define SCMI_GET_REVT_FROM_PD(__pd, __eid) \
157 typeof(__pd) pd_ = __pd; \
158 typeof(__eid) eid_ = __eid; \
159 struct scmi_registered_event *__revt = NULL; \
161 if (pd_ && eid_ < pd_->num_events) \
162 __revt = READ_ONCE(pd_->registered_events[eid_]); \
166 #define SCMI_GET_REVT(__ni, __pid, __eid) \
168 struct scmi_registered_event *__revt; \
169 struct scmi_registered_events_desc *__pd; \
171 __pd = SCMI_GET_PROTO((__ni), (__pid)); \
172 __revt = SCMI_GET_REVT_FROM_PD(__pd, (__eid)); \
176 /* A couple of utility macros to limit cruft when calling protocols' helpers */
177 #define REVT_NOTIFY_SET_STATUS(revt, eid, sid, state) \
179 typeof(revt) r = revt; \
180 r->proto->ops->set_notify_enabled(r->proto->ni->handle, \
181 (eid), (sid), (state)); \
184 #define REVT_NOTIFY_ENABLE(revt, eid, sid) \
185 REVT_NOTIFY_SET_STATUS((revt), (eid), (sid), true)
187 #define REVT_NOTIFY_DISABLE(revt, eid, sid) \
188 REVT_NOTIFY_SET_STATUS((revt), (eid), (sid), false)
190 #define REVT_FILL_REPORT(revt, ...) \
192 typeof(revt) r = revt; \
193 r->proto->ops->fill_custom_report(r->proto->ni->handle, \
197 #define SCMI_PENDING_HASH_SZ 4
198 #define SCMI_REGISTERED_HASH_SZ 6
200 struct scmi_registered_events_desc
;
203 * struct scmi_notify_instance - Represents an instance of the notification
205 * @gid: GroupID used for devres
206 * @handle: A reference to the platform instance
207 * @init_work: A work item to perform final initializations of pending handlers
208 * @notify_wq: A reference to the allocated Kernel cmwq
209 * @pending_mtx: A mutex to protect @pending_events_handlers
210 * @registered_protocols: A statically allocated array containing pointers to
211 * all the registered protocol-level specific information
212 * related to events' handling
213 * @pending_events_handlers: An hashtable containing all pending events'
214 * handlers descriptors
216 * Each platform instance, represented by a handle, has its own instance of
217 * the notification subsystem represented by this structure.
219 struct scmi_notify_instance
{
221 struct scmi_handle
*handle
;
222 struct work_struct init_work
;
223 struct workqueue_struct
*notify_wq
;
224 /* lock to protect pending_events_handlers */
225 struct mutex pending_mtx
;
226 struct scmi_registered_events_desc
**registered_protocols
;
227 DECLARE_HASHTABLE(pending_events_handlers
, SCMI_PENDING_HASH_SZ
);
231 * struct events_queue - Describes a queue and its associated worker
232 * @sz: Size in bytes of the related kfifo
233 * @kfifo: A dedicated Kernel kfifo descriptor
234 * @notify_work: A custom work item bound to this queue
235 * @wq: A reference to the associated workqueue
237 * Each protocol has its own dedicated events_queue descriptor.
239 struct events_queue
{
242 struct work_struct notify_work
;
243 struct workqueue_struct
*wq
;
247 * struct scmi_event_header - A utility header
248 * @timestamp: The timestamp, in nanoseconds (boottime), which was associated
249 * to this event as soon as it entered the SCMI RX ISR
250 * @payld_sz: Effective size of the embedded message payload which follows
251 * @evt_id: Event ID (corresponds to the Event MsgID for this Protocol)
252 * @payld: A reference to the embedded event payload
254 * This header is prepended to each received event message payload before
255 * queueing it on the related &struct events_queue.
257 struct scmi_event_header
{
260 unsigned char evt_id
;
261 unsigned char payld
[];
264 struct scmi_registered_event
;
267 * struct scmi_registered_events_desc - Protocol Specific information
269 * @ops: Protocol specific and event-related operations
270 * @equeue: The embedded per-protocol events_queue
271 * @ni: A reference to the initialized instance descriptor
272 * @eh: A reference to pre-allocated buffer to be used as a scratch area by the
273 * deferred worker when fetching data from the kfifo
274 * @eh_sz: Size of the pre-allocated buffer @eh
275 * @in_flight: A reference to an in flight &struct scmi_registered_event
276 * @num_events: Number of events in @registered_events
277 * @registered_events: A dynamically allocated array holding all the registered
278 * events' descriptors, whose fixed-size is determined at
280 * @registered_mtx: A mutex to protect @registered_events_handlers
281 * @registered_events_handlers: An hashtable containing all events' handlers
282 * descriptors registered for this protocol
284 * All protocols that register at least one event have their protocol-specific
285 * information stored here, together with the embedded allocated events_queue.
286 * These descriptors are stored in the @registered_protocols array at protocol
289 * Once these descriptors are successfully registered, they are NEVER again
290 * removed or modified since protocols do not unregister ever, so that, once
291 * we safely grab a NON-NULL reference from the array we can keep it and use it.
293 struct scmi_registered_events_desc
{
295 const struct scmi_event_ops
*ops
;
296 struct events_queue equeue
;
297 struct scmi_notify_instance
*ni
;
298 struct scmi_event_header
*eh
;
302 struct scmi_registered_event
**registered_events
;
303 /* mutex to protect registered_events_handlers */
304 struct mutex registered_mtx
;
305 DECLARE_HASHTABLE(registered_events_handlers
, SCMI_REGISTERED_HASH_SZ
);
309 * struct scmi_registered_event - Event Specific Information
310 * @proto: A reference to the associated protocol descriptor
311 * @evt: A reference to the associated event descriptor (as provided at
313 * @report: A pre-allocated buffer used by the deferred worker to fill a
314 * customized event report
315 * @num_sources: The number of possible sources for this event as stated at
316 * events' registration time
317 * @sources: A reference to a dynamically allocated array used to refcount the
318 * events' enable requests for all the existing sources
319 * @sources_mtx: A mutex to serialize the access to @sources
321 * All registered events are represented by one of these structures that are
322 * stored in the @registered_events array at protocol registration time.
324 * Once these descriptors are successfully registered, they are NEVER again
325 * removed or modified since protocols do not unregister ever, so that once we
326 * safely grab a NON-NULL reference from the table we can keep it and use it.
328 struct scmi_registered_event
{
329 struct scmi_registered_events_desc
*proto
;
330 const struct scmi_event
*evt
;
334 /* locking to serialize the access to sources */
335 struct mutex sources_mtx
;
339 * struct scmi_event_handler - Event handler information
340 * @key: The used hashkey
341 * @users: A reference count for number of active users for this handler
342 * @r_evt: A reference to the associated registered event; when this is NULL
343 * this handler is pending, which means that identifies a set of
344 * callbacks intended to be attached to an event which is still not
345 * known nor registered by any protocol at that point in time
346 * @chain: The notification chain dedicated to this specific event tuple
347 * @hash: The hlist_node used for collision handling
348 * @enabled: A boolean which records if event's generation has been already
349 * enabled for this handler as a whole
351 * This structure collects all the information needed to process a received
352 * event identified by the tuple (proto_id, evt_id, src_id).
353 * These descriptors are stored in a per-protocol @registered_events_handlers
354 * table using as a key a value derived from that tuple.
356 struct scmi_event_handler
{
359 struct scmi_registered_event
*r_evt
;
360 struct blocking_notifier_head chain
;
361 struct hlist_node hash
;
365 #define IS_HNDL_PENDING(hndl) (!(hndl)->r_evt)
367 static struct scmi_event_handler
*
368 scmi_get_active_handler(struct scmi_notify_instance
*ni
, u32 evt_key
);
369 static void scmi_put_active_handler(struct scmi_notify_instance
*ni
,
370 struct scmi_event_handler
*hndl
);
371 static void scmi_put_handler_unlocked(struct scmi_notify_instance
*ni
,
372 struct scmi_event_handler
*hndl
);
375 * scmi_lookup_and_call_event_chain() - Lookup the proper chain and call it
376 * @ni: A reference to the notification instance to use
377 * @evt_key: The key to use to lookup the related notification chain
378 * @report: The customized event-specific report to pass down to the callbacks
379 * as their *data parameter.
382 scmi_lookup_and_call_event_chain(struct scmi_notify_instance
*ni
,
383 u32 evt_key
, void *report
)
386 struct scmi_event_handler
*hndl
;
389 * Here ensure the event handler cannot vanish while using it.
390 * It is legitimate, though, for an handler not to be found at all here,
391 * e.g. when it has been unregistered by the user after some events had
392 * already been queued.
394 hndl
= scmi_get_active_handler(ni
, evt_key
);
398 ret
= blocking_notifier_call_chain(&hndl
->chain
,
399 KEY_XTRACT_EVT_ID(evt_key
),
401 /* Notifiers are NOT supposed to cut the chain ... */
402 WARN_ON_ONCE(ret
& NOTIFY_STOP_MASK
);
404 scmi_put_active_handler(ni
, hndl
);
408 * scmi_process_event_header() - Dequeue and process an event header
409 * @eq: The queue to use
410 * @pd: The protocol descriptor to use
412 * Read an event header from the protocol queue into the dedicated scratch
413 * buffer and looks for a matching registered event; in case an anomalously
414 * sized read is detected just flush the queue.
417 * * a reference to the matching registered event when found
418 * * ERR_PTR(-EINVAL) when NO registered event could be found
419 * * NULL when the queue is empty
421 static inline struct scmi_registered_event
*
422 scmi_process_event_header(struct events_queue
*eq
,
423 struct scmi_registered_events_desc
*pd
)
426 struct scmi_registered_event
*r_evt
;
428 outs
= kfifo_out(&eq
->kfifo
, pd
->eh
,
429 sizeof(struct scmi_event_header
));
432 if (outs
!= sizeof(struct scmi_event_header
)) {
433 dev_err(pd
->ni
->handle
->dev
, "corrupted EVT header. Flush.\n");
434 kfifo_reset_out(&eq
->kfifo
);
438 r_evt
= SCMI_GET_REVT_FROM_PD(pd
, pd
->eh
->evt_id
);
440 r_evt
= ERR_PTR(-EINVAL
);
446 * scmi_process_event_payload() - Dequeue and process an event payload
447 * @eq: The queue to use
448 * @pd: The protocol descriptor to use
449 * @r_evt: The registered event descriptor to use
451 * Read an event payload from the protocol queue into the dedicated scratch
452 * buffer, fills a custom report and then look for matching event handlers and
453 * call them; skip any unknown event (as marked by scmi_process_event_header())
454 * and in case an anomalously sized read is detected just flush the queue.
456 * Return: False when the queue is empty
459 scmi_process_event_payload(struct events_queue
*eq
,
460 struct scmi_registered_events_desc
*pd
,
461 struct scmi_registered_event
*r_evt
)
467 outs
= kfifo_out(&eq
->kfifo
, pd
->eh
->payld
, pd
->eh
->payld_sz
);
471 /* Any in-flight event has now been officially processed */
472 pd
->in_flight
= NULL
;
474 if (outs
!= pd
->eh
->payld_sz
) {
475 dev_err(pd
->ni
->handle
->dev
, "corrupted EVT Payload. Flush.\n");
476 kfifo_reset_out(&eq
->kfifo
);
481 dev_warn(pd
->ni
->handle
->dev
,
482 "SKIP UNKNOWN EVT - proto:%X evt:%d\n",
483 pd
->id
, pd
->eh
->evt_id
);
487 report
= REVT_FILL_REPORT(r_evt
, pd
->eh
->evt_id
, pd
->eh
->timestamp
,
488 pd
->eh
->payld
, pd
->eh
->payld_sz
,
489 r_evt
->report
, &src_id
);
491 dev_err(pd
->ni
->handle
->dev
,
492 "report not available - proto:%X evt:%d\n",
493 pd
->id
, pd
->eh
->evt_id
);
497 /* At first search for a generic ALL src_ids handler... */
498 key
= MAKE_ALL_SRCS_KEY(pd
->id
, pd
->eh
->evt_id
);
499 scmi_lookup_and_call_event_chain(pd
->ni
, key
, report
);
501 /* ...then search for any specific src_id */
502 key
= MAKE_HASH_KEY(pd
->id
, pd
->eh
->evt_id
, src_id
);
503 scmi_lookup_and_call_event_chain(pd
->ni
, key
, report
);
509 * scmi_events_dispatcher() - Common worker logic for all work items.
510 * @work: The work item to use, which is associated to a dedicated events_queue
513 * 1. dequeue one pending RX notification (queued in SCMI RX ISR context)
514 * 2. generate a custom event report from the received event message
515 * 3. lookup for any registered ALL_SRC_IDs handler:
516 * - > call the related notification chain passing in the report
517 * 4. lookup for any registered specific SRC_ID handler:
518 * - > call the related notification chain passing in the report
521 * * a dedicated per-protocol kfifo queue is used: in this way an anomalous
522 * flood of events cannot saturate other protocols' queues.
523 * * each per-protocol queue is associated to a distinct work_item, which
524 * means, in turn, that:
525 * + all protocols can process their dedicated queues concurrently
526 * (since notify_wq:max_active != 1)
527 * + anyway at most one worker instance is allowed to run on the same queue
528 * concurrently: this ensures that we can have only one concurrent
529 * reader/writer on the associated kfifo, so that we can use it lock-less
531 * Context: Process context.
533 static void scmi_events_dispatcher(struct work_struct
*work
)
535 struct events_queue
*eq
;
536 struct scmi_registered_events_desc
*pd
;
537 struct scmi_registered_event
*r_evt
;
539 eq
= container_of(work
, struct events_queue
, notify_work
);
540 pd
= container_of(eq
, struct scmi_registered_events_desc
, equeue
);
542 * In order to keep the queue lock-less and the number of memcopies
543 * to the bare minimum needed, the dispatcher accounts for the
544 * possibility of per-protocol in-flight events: i.e. an event whose
545 * reception could end up being split across two subsequent runs of this
546 * worker, first the header, then the payload.
549 if (!pd
->in_flight
) {
550 r_evt
= scmi_process_event_header(eq
, pd
);
553 pd
->in_flight
= r_evt
;
555 r_evt
= pd
->in_flight
;
557 } while (scmi_process_event_payload(eq
, pd
, r_evt
));
561 * scmi_notify() - Queues a notification for further deferred processing
562 * @handle: The handle identifying the platform instance from which the
563 * dispatched event is generated
564 * @proto_id: Protocol ID
565 * @evt_id: Event ID (msgID)
566 * @buf: Event Message Payload (without the header)
567 * @len: Event Message Payload size
568 * @ts: RX Timestamp in nanoseconds (boottime)
570 * Context: Called in interrupt context to queue a received event for
571 * deferred processing.
573 * Return: 0 on Success
575 int scmi_notify(const struct scmi_handle
*handle
, u8 proto_id
, u8 evt_id
,
576 const void *buf
, size_t len
, ktime_t ts
)
578 struct scmi_registered_event
*r_evt
;
579 struct scmi_event_header eh
;
580 struct scmi_notify_instance
*ni
;
582 /* Ensure notify_priv is updated */
584 if (!handle
->notify_priv
)
586 ni
= handle
->notify_priv
;
588 r_evt
= SCMI_GET_REVT(ni
, proto_id
, evt_id
);
592 if (len
> r_evt
->evt
->max_payld_sz
) {
593 dev_err(handle
->dev
, "discard badly sized message\n");
596 if (kfifo_avail(&r_evt
->proto
->equeue
.kfifo
) < sizeof(eh
) + len
) {
597 dev_warn(handle
->dev
,
598 "queue full, dropping proto_id:%d evt_id:%d ts:%lld\n",
599 proto_id
, evt_id
, ktime_to_ns(ts
));
607 * Header and payload are enqueued with two distinct kfifo_in() (so non
608 * atomic), but this situation is handled properly on the consumer side
609 * with in-flight events tracking.
611 kfifo_in(&r_evt
->proto
->equeue
.kfifo
, &eh
, sizeof(eh
));
612 kfifo_in(&r_evt
->proto
->equeue
.kfifo
, buf
, len
);
614 * Don't care about return value here since we just want to ensure that
615 * a work is queued all the times whenever some items have been pushed
617 * - if work was already queued it will simply fail to queue a new one
618 * since it is not needed
619 * - if work was not queued already it will be now, even in case work
620 * was in fact already running: this behavior avoids any possible race
621 * when this function pushes new items onto the kfifos after the
622 * related executing worker had already determined the kfifo to be
623 * empty and it was terminating.
625 queue_work(r_evt
->proto
->equeue
.wq
,
626 &r_evt
->proto
->equeue
.notify_work
);
632 * scmi_kfifo_free() - Devres action helper to free the kfifo
633 * @kfifo: The kfifo to free
635 static void scmi_kfifo_free(void *kfifo
)
637 kfifo_free((struct kfifo
*)kfifo
);
641 * scmi_initialize_events_queue() - Allocate/Initialize a kfifo buffer
642 * @ni: A reference to the notification instance to use
643 * @equeue: The events_queue to initialize
644 * @sz: Size of the kfifo buffer to allocate
646 * Allocate a buffer for the kfifo and initialize it.
648 * Return: 0 on Success
650 static int scmi_initialize_events_queue(struct scmi_notify_instance
*ni
,
651 struct events_queue
*equeue
, size_t sz
)
655 if (kfifo_alloc(&equeue
->kfifo
, sz
, GFP_KERNEL
))
657 /* Size could have been roundup to power-of-two */
658 equeue
->sz
= kfifo_size(&equeue
->kfifo
);
660 ret
= devm_add_action_or_reset(ni
->handle
->dev
, scmi_kfifo_free
,
665 INIT_WORK(&equeue
->notify_work
, scmi_events_dispatcher
);
666 equeue
->wq
= ni
->notify_wq
;
672 * scmi_allocate_registered_events_desc() - Allocate a registered events'
674 * @ni: A reference to the &struct scmi_notify_instance notification instance
676 * @proto_id: Protocol ID
677 * @queue_sz: Size of the associated queue to allocate
678 * @eh_sz: Size of the event header scratch area to pre-allocate
679 * @num_events: Number of events to support (size of @registered_events)
680 * @ops: Pointer to a struct holding references to protocol specific helpers
681 * needed during events handling
683 * It is supposed to be called only once for each protocol at protocol
684 * initialization time, so it warns if the requested protocol is found already
687 * Return: The allocated and registered descriptor on Success
689 static struct scmi_registered_events_desc
*
690 scmi_allocate_registered_events_desc(struct scmi_notify_instance
*ni
,
691 u8 proto_id
, size_t queue_sz
, size_t eh_sz
,
693 const struct scmi_event_ops
*ops
)
696 struct scmi_registered_events_desc
*pd
;
698 /* Ensure protocols are up to date */
700 if (WARN_ON(ni
->registered_protocols
[proto_id
]))
701 return ERR_PTR(-EINVAL
);
703 pd
= devm_kzalloc(ni
->handle
->dev
, sizeof(*pd
), GFP_KERNEL
);
705 return ERR_PTR(-ENOMEM
);
710 ret
= scmi_initialize_events_queue(ni
, &pd
->equeue
, queue_sz
);
714 pd
->eh
= devm_kzalloc(ni
->handle
->dev
, eh_sz
, GFP_KERNEL
);
716 return ERR_PTR(-ENOMEM
);
719 pd
->registered_events
= devm_kcalloc(ni
->handle
->dev
, num_events
,
720 sizeof(char *), GFP_KERNEL
);
721 if (!pd
->registered_events
)
722 return ERR_PTR(-ENOMEM
);
723 pd
->num_events
= num_events
;
725 /* Initialize per protocol handlers table */
726 mutex_init(&pd
->registered_mtx
);
727 hash_init(pd
->registered_events_handlers
);
733 * scmi_register_protocol_events() - Register Protocol Events with the core
734 * @handle: The handle identifying the platform instance against which the
735 * the protocol's events are registered
736 * @proto_id: Protocol ID
737 * @queue_sz: Size in bytes of the associated queue to be allocated
738 * @ops: Protocol specific event-related operations
739 * @evt: Event descriptor array
740 * @num_events: Number of events in @evt array
741 * @num_sources: Number of possible sources for this protocol on this
744 * Used by SCMI Protocols initialization code to register with the notification
745 * core the list of supported events and their descriptors: takes care to
746 * pre-allocate and store all needed descriptors, scratch buffers and event
749 * Return: 0 on Success
751 int scmi_register_protocol_events(const struct scmi_handle
*handle
,
752 u8 proto_id
, size_t queue_sz
,
753 const struct scmi_event_ops
*ops
,
754 const struct scmi_event
*evt
, int num_events
,
759 struct scmi_registered_events_desc
*pd
;
760 struct scmi_notify_instance
*ni
;
765 /* Ensure notify_priv is updated */
767 if (!handle
->notify_priv
)
769 ni
= handle
->notify_priv
;
771 /* Attach to the notification main devres group */
772 if (!devres_open_group(ni
->handle
->dev
, ni
->gid
, GFP_KERNEL
))
775 for (i
= 0; i
< num_events
; i
++)
776 payld_sz
= max_t(size_t, payld_sz
, evt
[i
].max_payld_sz
);
777 payld_sz
+= sizeof(struct scmi_event_header
);
779 pd
= scmi_allocate_registered_events_desc(ni
, proto_id
, queue_sz
,
780 payld_sz
, num_events
, ops
);
784 for (i
= 0; i
< num_events
; i
++, evt
++) {
785 struct scmi_registered_event
*r_evt
;
787 r_evt
= devm_kzalloc(ni
->handle
->dev
, sizeof(*r_evt
),
794 r_evt
->sources
= devm_kcalloc(ni
->handle
->dev
, num_sources
,
795 sizeof(refcount_t
), GFP_KERNEL
);
798 r_evt
->num_sources
= num_sources
;
799 mutex_init(&r_evt
->sources_mtx
);
801 r_evt
->report
= devm_kzalloc(ni
->handle
->dev
,
802 evt
->max_report_sz
, GFP_KERNEL
);
806 pd
->registered_events
[i
] = r_evt
;
807 /* Ensure events are updated */
809 dev_dbg(handle
->dev
, "registered event - %lX\n",
810 MAKE_ALL_SRCS_KEY(r_evt
->proto
->id
, r_evt
->evt
->id
));
813 /* Register protocol and events...it will never be removed */
814 ni
->registered_protocols
[proto_id
] = pd
;
815 /* Ensure protocols are updated */
818 devres_close_group(ni
->handle
->dev
, ni
->gid
);
821 * Finalize any pending events' handler which could have been waiting
822 * for this protocol's events registration.
824 schedule_work(&ni
->init_work
);
829 dev_warn(handle
->dev
, "Proto:%X - Registration Failed !\n", proto_id
);
830 /* A failing protocol registration does not trigger full failure */
831 devres_close_group(ni
->handle
->dev
, ni
->gid
);
837 * scmi_allocate_event_handler() - Allocate Event handler
838 * @ni: A reference to the notification instance to use
839 * @evt_key: 32bit key uniquely bind to the event identified by the tuple
840 * (proto_id, evt_id, src_id)
842 * Allocate an event handler and related notification chain associated with
843 * the provided event handler key.
844 * Note that, at this point, a related registered_event is still to be
845 * associated to this handler descriptor (hndl->r_evt == NULL), so the handler
846 * is initialized as pending.
848 * Context: Assumes to be called with @pending_mtx already acquired.
849 * Return: the freshly allocated structure on Success
851 static struct scmi_event_handler
*
852 scmi_allocate_event_handler(struct scmi_notify_instance
*ni
, u32 evt_key
)
854 struct scmi_event_handler
*hndl
;
856 hndl
= kzalloc(sizeof(*hndl
), GFP_KERNEL
);
860 BLOCKING_INIT_NOTIFIER_HEAD(&hndl
->chain
);
861 refcount_set(&hndl
->users
, 1);
862 /* New handlers are created pending */
863 hash_add(ni
->pending_events_handlers
, &hndl
->hash
, hndl
->key
);
869 * scmi_free_event_handler() - Free the provided Event handler
870 * @hndl: The event handler structure to free
872 * Context: Assumes to be called with proper locking acquired depending
875 static void scmi_free_event_handler(struct scmi_event_handler
*hndl
)
877 hash_del(&hndl
->hash
);
882 * scmi_bind_event_handler() - Helper to attempt binding an handler to an event
883 * @ni: A reference to the notification instance to use
884 * @hndl: The event handler to bind
886 * If an associated registered event is found, move the handler from the pending
887 * into the registered table.
889 * Context: Assumes to be called with @pending_mtx already acquired.
891 * Return: 0 on Success
893 static inline int scmi_bind_event_handler(struct scmi_notify_instance
*ni
,
894 struct scmi_event_handler
*hndl
)
896 struct scmi_registered_event
*r_evt
;
898 r_evt
= SCMI_GET_REVT(ni
, KEY_XTRACT_PROTO_ID(hndl
->key
),
899 KEY_XTRACT_EVT_ID(hndl
->key
));
903 /* Remove from pending and insert into registered */
904 hash_del(&hndl
->hash
);
906 mutex_lock(&r_evt
->proto
->registered_mtx
);
907 hash_add(r_evt
->proto
->registered_events_handlers
,
908 &hndl
->hash
, hndl
->key
);
909 mutex_unlock(&r_evt
->proto
->registered_mtx
);
915 * scmi_valid_pending_handler() - Helper to check pending status of handlers
916 * @ni: A reference to the notification instance to use
917 * @hndl: The event handler to check
919 * An handler is considered pending when its r_evt == NULL, because the related
920 * event was still unknown at handler's registration time; anyway, since all
921 * protocols register their supported events once for all at protocols'
922 * initialization time, a pending handler cannot be considered valid anymore if
923 * the underlying event (which it is waiting for), belongs to an already
924 * initialized and registered protocol.
926 * Return: 0 on Success
928 static inline int scmi_valid_pending_handler(struct scmi_notify_instance
*ni
,
929 struct scmi_event_handler
*hndl
)
931 struct scmi_registered_events_desc
*pd
;
933 if (!IS_HNDL_PENDING(hndl
))
936 pd
= SCMI_GET_PROTO(ni
, KEY_XTRACT_PROTO_ID(hndl
->key
));
944 * scmi_register_event_handler() - Register whenever possible an Event handler
945 * @ni: A reference to the notification instance to use
946 * @hndl: The event handler to register
948 * At first try to bind an event handler to its associated event, then check if
949 * it was at least a valid pending handler: if it was not bound nor valid return
952 * Valid pending incomplete bindings will be periodically retried by a dedicated
953 * worker which is kicked each time a new protocol completes its own
954 * registration phase.
956 * Context: Assumes to be called with @pending_mtx acquired.
958 * Return: 0 on Success
960 static int scmi_register_event_handler(struct scmi_notify_instance
*ni
,
961 struct scmi_event_handler
*hndl
)
965 ret
= scmi_bind_event_handler(ni
, hndl
);
967 dev_dbg(ni
->handle
->dev
, "registered NEW handler - key:%X\n",
970 ret
= scmi_valid_pending_handler(ni
, hndl
);
972 dev_dbg(ni
->handle
->dev
,
973 "registered PENDING handler - key:%X\n",
981 * __scmi_event_handler_get_ops() - Utility to get or create an event handler
982 * @ni: A reference to the notification instance to use
983 * @evt_key: The event key to use
984 * @create: A boolean flag to specify if a handler must be created when
985 * not already existent
987 * Search for the desired handler matching the key in both the per-protocol
988 * registered table and the common pending table:
989 * * if found adjust users refcount
990 * * if not found and @create is true, create and register the new handler:
991 * handler could end up being registered as pending if no matching event
994 * An handler is guaranteed to reside in one and only one of the tables at
995 * any one time; to ensure this the whole search and create is performed
996 * holding the @pending_mtx lock, with @registered_mtx additionally acquired
999 * Note that when a nested acquisition of these mutexes is needed the locking
1000 * order is always (same as in @init_work):
1004 * Events generation is NOT enabled right after creation within this routine
1005 * since at creation time we usually want to have all setup and ready before
1006 * events really start flowing.
1008 * Return: A properly refcounted handler on Success, NULL on Failure
1010 static inline struct scmi_event_handler
*
1011 __scmi_event_handler_get_ops(struct scmi_notify_instance
*ni
,
1012 u32 evt_key
, bool create
)
1014 struct scmi_registered_event
*r_evt
;
1015 struct scmi_event_handler
*hndl
= NULL
;
1017 r_evt
= SCMI_GET_REVT(ni
, KEY_XTRACT_PROTO_ID(evt_key
),
1018 KEY_XTRACT_EVT_ID(evt_key
));
1020 mutex_lock(&ni
->pending_mtx
);
1021 /* Search registered events at first ... if possible at all */
1023 mutex_lock(&r_evt
->proto
->registered_mtx
);
1024 hndl
= KEY_FIND(r_evt
->proto
->registered_events_handlers
,
1027 refcount_inc(&hndl
->users
);
1028 mutex_unlock(&r_evt
->proto
->registered_mtx
);
1031 /* ...then amongst pending. */
1033 hndl
= KEY_FIND(ni
->pending_events_handlers
, hndl
, evt_key
);
1035 refcount_inc(&hndl
->users
);
1038 /* Create if still not found and required */
1039 if (!hndl
&& create
) {
1040 hndl
= scmi_allocate_event_handler(ni
, evt_key
);
1041 if (hndl
&& scmi_register_event_handler(ni
, hndl
)) {
1042 dev_dbg(ni
->handle
->dev
,
1043 "purging UNKNOWN handler - key:%X\n",
1045 /* this hndl can be only a pending one */
1046 scmi_put_handler_unlocked(ni
, hndl
);
1050 mutex_unlock(&ni
->pending_mtx
);
1055 static struct scmi_event_handler
*
1056 scmi_get_handler(struct scmi_notify_instance
*ni
, u32 evt_key
)
1058 return __scmi_event_handler_get_ops(ni
, evt_key
, false);
1061 static struct scmi_event_handler
*
1062 scmi_get_or_create_handler(struct scmi_notify_instance
*ni
, u32 evt_key
)
1064 return __scmi_event_handler_get_ops(ni
, evt_key
, true);
1068 * scmi_get_active_handler() - Helper to get active handlers only
1069 * @ni: A reference to the notification instance to use
1070 * @evt_key: The event key to use
1072 * Search for the desired handler matching the key only in the per-protocol
1073 * table of registered handlers: this is called only from the dispatching path
1074 * so want to be as quick as possible and do not care about pending.
1076 * Return: A properly refcounted active handler
1078 static struct scmi_event_handler
*
1079 scmi_get_active_handler(struct scmi_notify_instance
*ni
, u32 evt_key
)
1081 struct scmi_registered_event
*r_evt
;
1082 struct scmi_event_handler
*hndl
= NULL
;
1084 r_evt
= SCMI_GET_REVT(ni
, KEY_XTRACT_PROTO_ID(evt_key
),
1085 KEY_XTRACT_EVT_ID(evt_key
));
1087 mutex_lock(&r_evt
->proto
->registered_mtx
);
1088 hndl
= KEY_FIND(r_evt
->proto
->registered_events_handlers
,
1091 refcount_inc(&hndl
->users
);
1092 mutex_unlock(&r_evt
->proto
->registered_mtx
);
1099 * __scmi_enable_evt() - Enable/disable events generation
1100 * @r_evt: The registered event to act upon
1101 * @src_id: The src_id to act upon
1102 * @enable: The action to perform: true->Enable, false->Disable
1104 * Takes care of proper refcounting while performing enable/disable: handles
1105 * the special case of ALL sources requests by itself.
1106 * Returns successfully if at least one of the required src_id has been
1107 * successfully enabled/disabled.
1109 * Return: 0 on Success
1111 static inline int __scmi_enable_evt(struct scmi_registered_event
*r_evt
,
1112 u32 src_id
, bool enable
)
1118 if (src_id
== SRC_ID_MASK
) {
1120 num_sources
= r_evt
->num_sources
;
1121 } else if (src_id
< r_evt
->num_sources
) {
1127 mutex_lock(&r_evt
->sources_mtx
);
1129 for (; num_sources
; src_id
++, num_sources
--) {
1132 sid
= &r_evt
->sources
[src_id
];
1133 if (refcount_read(sid
) == 0) {
1134 ret
= REVT_NOTIFY_ENABLE(r_evt
, r_evt
->evt
->id
,
1137 refcount_set(sid
, 1);
1144 for (; num_sources
; src_id
++, num_sources
--) {
1145 sid
= &r_evt
->sources
[src_id
];
1146 if (refcount_dec_and_test(sid
))
1147 REVT_NOTIFY_DISABLE(r_evt
,
1148 r_evt
->evt
->id
, src_id
);
1152 mutex_unlock(&r_evt
->sources_mtx
);
1154 return retvals
? 0 : -EINVAL
;
1157 static int scmi_enable_events(struct scmi_event_handler
*hndl
)
1161 if (!hndl
->enabled
) {
1162 ret
= __scmi_enable_evt(hndl
->r_evt
,
1163 KEY_XTRACT_SRC_ID(hndl
->key
), true);
1165 hndl
->enabled
= true;
1171 static int scmi_disable_events(struct scmi_event_handler
*hndl
)
1175 if (hndl
->enabled
) {
1176 ret
= __scmi_enable_evt(hndl
->r_evt
,
1177 KEY_XTRACT_SRC_ID(hndl
->key
), false);
1179 hndl
->enabled
= false;
1186 * scmi_put_handler_unlocked() - Put an event handler
1187 * @ni: A reference to the notification instance to use
1188 * @hndl: The event handler to act upon
1190 * After having got exclusive access to the registered handlers hashtable,
1191 * update the refcount and if @hndl is no more in use by anyone:
1192 * * ask for events' generation disabling
1193 * * unregister and free the handler itself
1195 * Context: Assumes all the proper locking has been managed by the caller.
1197 static void scmi_put_handler_unlocked(struct scmi_notify_instance
*ni
,
1198 struct scmi_event_handler
*hndl
)
1200 if (refcount_dec_and_test(&hndl
->users
)) {
1201 if (!IS_HNDL_PENDING(hndl
))
1202 scmi_disable_events(hndl
);
1203 scmi_free_event_handler(hndl
);
1207 static void scmi_put_handler(struct scmi_notify_instance
*ni
,
1208 struct scmi_event_handler
*hndl
)
1210 struct scmi_registered_event
*r_evt
= hndl
->r_evt
;
1212 mutex_lock(&ni
->pending_mtx
);
1214 mutex_lock(&r_evt
->proto
->registered_mtx
);
1216 scmi_put_handler_unlocked(ni
, hndl
);
1219 mutex_unlock(&r_evt
->proto
->registered_mtx
);
1220 mutex_unlock(&ni
->pending_mtx
);
1223 static void scmi_put_active_handler(struct scmi_notify_instance
*ni
,
1224 struct scmi_event_handler
*hndl
)
1226 struct scmi_registered_event
*r_evt
= hndl
->r_evt
;
1228 mutex_lock(&r_evt
->proto
->registered_mtx
);
1229 scmi_put_handler_unlocked(ni
, hndl
);
1230 mutex_unlock(&r_evt
->proto
->registered_mtx
);
1234 * scmi_event_handler_enable_events() - Enable events associated to an handler
1235 * @hndl: The Event handler to act upon
1237 * Return: 0 on Success
1239 static int scmi_event_handler_enable_events(struct scmi_event_handler
*hndl
)
1241 if (scmi_enable_events(hndl
)) {
1242 pr_err("Failed to ENABLE events for key:%X !\n", hndl
->key
);
1250 * scmi_register_notifier() - Register a notifier_block for an event
1251 * @handle: The handle identifying the platform instance against which the
1252 * callback is registered
1253 * @proto_id: Protocol ID
1255 * @src_id: Source ID, when NULL register for events coming form ALL possible
1257 * @nb: A standard notifier block to register for the specified event
1259 * Generic helper to register a notifier_block against a protocol event.
1261 * A notifier_block @nb will be registered for each distinct event identified
1262 * by the tuple (proto_id, evt_id, src_id) on a dedicated notification chain
1265 * (proto_X, evt_Y, src_Z) --> chain_X_Y_Z
1267 * @src_id meaning is protocol specific and identifies the origin of the event
1268 * (like domain_id, sensor_id and so forth).
1270 * @src_id can be NULL to signify that the caller is interested in receiving
1271 * notifications from ALL the available sources for that protocol OR simply that
1272 * the protocol does not support distinct sources.
1274 * As soon as one user for the specified tuple appears, an handler is created,
1275 * and that specific event's generation is enabled at the platform level, unless
1276 * an associated registered event is found missing, meaning that the needed
1277 * protocol is still to be initialized and the handler has just been registered
1280 * Return: 0 on Success
1282 static int scmi_register_notifier(const struct scmi_handle
*handle
,
1283 u8 proto_id
, u8 evt_id
, u32
*src_id
,
1284 struct notifier_block
*nb
)
1288 struct scmi_event_handler
*hndl
;
1289 struct scmi_notify_instance
*ni
;
1291 /* Ensure notify_priv is updated */
1293 if (!handle
->notify_priv
)
1295 ni
= handle
->notify_priv
;
1297 evt_key
= MAKE_HASH_KEY(proto_id
, evt_id
,
1298 src_id
? *src_id
: SRC_ID_MASK
);
1299 hndl
= scmi_get_or_create_handler(ni
, evt_key
);
1303 blocking_notifier_chain_register(&hndl
->chain
, nb
);
1305 /* Enable events for not pending handlers */
1306 if (!IS_HNDL_PENDING(hndl
)) {
1307 ret
= scmi_event_handler_enable_events(hndl
);
1309 scmi_put_handler(ni
, hndl
);
1316 * scmi_unregister_notifier() - Unregister a notifier_block for an event
1317 * @handle: The handle identifying the platform instance against which the
1318 * callback is unregistered
1319 * @proto_id: Protocol ID
1321 * @src_id: Source ID
1322 * @nb: The notifier_block to unregister
1324 * Takes care to unregister the provided @nb from the notification chain
1325 * associated to the specified event and, if there are no more users for the
1326 * event handler, frees also the associated event handler structures.
1327 * (this could possibly cause disabling of event's generation at platform level)
1329 * Return: 0 on Success
1331 static int scmi_unregister_notifier(const struct scmi_handle
*handle
,
1332 u8 proto_id
, u8 evt_id
, u32
*src_id
,
1333 struct notifier_block
*nb
)
1336 struct scmi_event_handler
*hndl
;
1337 struct scmi_notify_instance
*ni
;
1339 /* Ensure notify_priv is updated */
1341 if (!handle
->notify_priv
)
1343 ni
= handle
->notify_priv
;
1345 evt_key
= MAKE_HASH_KEY(proto_id
, evt_id
,
1346 src_id
? *src_id
: SRC_ID_MASK
);
1347 hndl
= scmi_get_handler(ni
, evt_key
);
1352 * Note that this chain unregistration call is safe on its own
1353 * being internally protected by an rwsem.
1355 blocking_notifier_chain_unregister(&hndl
->chain
, nb
);
1356 scmi_put_handler(ni
, hndl
);
1359 * This balances the initial get issued in @scmi_register_notifier.
1360 * If this notifier_block happened to be the last known user callback
1361 * for this event, the handler is here freed and the event's generation
1364 * Note that, an ongoing concurrent lookup on the delivery workqueue
1365 * path could still hold the refcount to 1 even after this routine
1366 * completes: in such a case it will be the final put on the delivery
1367 * path which will finally free this unused handler.
1369 scmi_put_handler(ni
, hndl
);
1375 * scmi_protocols_late_init() - Worker for late initialization
1376 * @work: The work item to use associated to the proper SCMI instance
1378 * This kicks in whenever a new protocol has completed its own registration via
1379 * scmi_register_protocol_events(): it is in charge of scanning the table of
1380 * pending handlers (registered by users while the related protocol was still
1381 * not initialized) and finalizing their initialization whenever possible;
1382 * invalid pending handlers are purged at this point in time.
1384 static void scmi_protocols_late_init(struct work_struct
*work
)
1387 struct scmi_event_handler
*hndl
;
1388 struct scmi_notify_instance
*ni
;
1389 struct hlist_node
*tmp
;
1391 ni
= container_of(work
, struct scmi_notify_instance
, init_work
);
1393 /* Ensure protocols and events are up to date */
1396 mutex_lock(&ni
->pending_mtx
);
1397 hash_for_each_safe(ni
->pending_events_handlers
, bkt
, tmp
, hndl
, hash
) {
1400 ret
= scmi_bind_event_handler(ni
, hndl
);
1402 dev_dbg(ni
->handle
->dev
,
1403 "finalized PENDING handler - key:%X\n",
1405 ret
= scmi_event_handler_enable_events(hndl
);
1407 dev_dbg(ni
->handle
->dev
,
1408 "purging INVALID handler - key:%X\n",
1410 scmi_put_active_handler(ni
, hndl
);
1413 ret
= scmi_valid_pending_handler(ni
, hndl
);
1415 dev_dbg(ni
->handle
->dev
,
1416 "purging PENDING handler - key:%X\n",
1418 /* this hndl can be only a pending one */
1419 scmi_put_handler_unlocked(ni
, hndl
);
1423 mutex_unlock(&ni
->pending_mtx
);
1427 * notify_ops are attached to the handle so that can be accessed
1428 * directly from an scmi_driver to register its own notifiers.
1430 static const struct scmi_notify_ops notify_ops
= {
1431 .register_event_notifier
= scmi_register_notifier
,
1432 .unregister_event_notifier
= scmi_unregister_notifier
,
1436 * scmi_notification_init() - Initializes Notification Core Support
1437 * @handle: The handle identifying the platform instance to initialize
1439 * This function lays out all the basic resources needed by the notification
1440 * core instance identified by the provided handle: once done, all of the
1441 * SCMI Protocols can register their events with the core during their own
1444 * Note that failing to initialize the core notifications support does not
1445 * cause the whole SCMI Protocols stack to fail its initialization.
1447 * SCMI Notification Initialization happens in 2 steps:
1448 * * initialization: basic common allocations (this function)
1449 * * registration: protocols asynchronously come into life and registers their
1450 * own supported list of events with the core; this causes
1451 * further per-protocol allocations
1453 * Any user's callback registration attempt, referring a still not registered
1454 * event, will be registered as pending and finalized later (if possible)
1455 * by scmi_protocols_late_init() work.
1456 * This allows for lazy initialization of SCMI Protocols due to late (or
1457 * missing) SCMI drivers' modules loading.
1459 * Return: 0 on Success
1461 int scmi_notification_init(struct scmi_handle
*handle
)
1464 struct scmi_notify_instance
*ni
;
1466 gid
= devres_open_group(handle
->dev
, NULL
, GFP_KERNEL
);
1470 ni
= devm_kzalloc(handle
->dev
, sizeof(*ni
), GFP_KERNEL
);
1475 ni
->handle
= handle
;
1477 ni
->registered_protocols
= devm_kcalloc(handle
->dev
, SCMI_MAX_PROTO
,
1478 sizeof(char *), GFP_KERNEL
);
1479 if (!ni
->registered_protocols
)
1482 ni
->notify_wq
= alloc_workqueue(dev_name(handle
->dev
),
1483 WQ_UNBOUND
| WQ_FREEZABLE
| WQ_SYSFS
,
1488 mutex_init(&ni
->pending_mtx
);
1489 hash_init(ni
->pending_events_handlers
);
1491 INIT_WORK(&ni
->init_work
, scmi_protocols_late_init
);
1493 handle
->notify_ops
= ¬ify_ops
;
1494 handle
->notify_priv
= ni
;
1495 /* Ensure handle is up to date */
1498 dev_info(handle
->dev
, "Core Enabled.\n");
1500 devres_close_group(handle
->dev
, ni
->gid
);
1505 dev_warn(handle
->dev
, "Initialization Failed.\n");
1506 devres_release_group(handle
->dev
, NULL
);
1511 * scmi_notification_exit() - Shutdown and clean Notification core
1512 * @handle: The handle identifying the platform instance to shutdown
1514 void scmi_notification_exit(struct scmi_handle
*handle
)
1516 struct scmi_notify_instance
*ni
;
1518 /* Ensure notify_priv is updated */
1520 if (!handle
->notify_priv
)
1522 ni
= handle
->notify_priv
;
1524 handle
->notify_priv
= NULL
;
1525 /* Ensure handle is up to date */
1528 /* Destroy while letting pending work complete */
1529 destroy_workqueue(ni
->notify_wq
);
1531 devres_release_group(ni
->handle
->dev
, ni
->gid
);