Lines Matching +full:protocol +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0
10 * SCMI Protocol specification allows the platform to signal events to
18 * Each SCMI Protocol implementation, during its initialization, registers with
28 * of the SCMI Protocol itself, the underlying notification chains are created
36 * All users provided callbacks and allocated notification-chains are stored in
44 * hash-keys.
47 * as described in the SCMI Protocol specification, while src_id represents an
48 * optional, protocol dependent, source identifier (like domain_id, perf_id
54 * pushes the event-data itself on a protocol-dedicated kfifo queue for further
57 * Each protocol has it own dedicated work_struct and worker which, once kicked
59 * queued items into the proper notification-chain: notifications processing can
61 * different protocols while delivery of events within the same protocol is
65 * conveyed, converted into a custom per-event report struct, as the void *data
73 #define dev_fmt(fmt) "SCMI Notifications - " fmt
74 #define pr_fmt(fmt) "SCMI Notifications - " fmt
115 * Assumes that the stored obj includes its own hash-key in a field named 'key':
131 if (obj_->key == k_) \
152 __pd = READ_ONCE(ni_->registered_protocols[(__pid)]); \
162 if (pd_ && eid_ < pd_->num_events) \
163 __revt = READ_ONCE(pd_->registered_events[eid_]); \
181 r->proto->ops->set_notify_enabled(r->proto->ph, \
194 r->proto->ops->fill_custom_report(r->proto->ph, \
204 * struct scmi_notify_instance - Represents an instance of the notification
212 * all the registered protocol-level specific information
232 * struct events_queue - Describes a queue and its associated worker
238 * Each protocol has its own dedicated events_queue descriptor.
248 * struct scmi_event_header - A utility header
252 * @evt_id: Event ID (corresponds to the Event MsgID for this Protocol)
268 * struct scmi_registered_events_desc - Protocol Specific information
269 * @id: Protocol ID
270 * @ops: Protocol specific and event-related operations
271 * @equeue: The embedded per-protocol events_queue
273 * @eh: A reference to pre-allocated buffer to be used as a scratch area by the
275 * @eh_sz: Size of the pre-allocated buffer @eh
279 * events' descriptors, whose fixed-size is determined at
282 * @ph: SCMI protocol handle reference
284 * descriptors registered for this protocol
286 * All protocols that register at least one event have their protocol-specific
288 * These descriptors are stored in the @registered_protocols array at protocol
293 * we safely grab a NON-NULL reference from the array we can keep it and use it.
296 u8 id; member
312 * struct scmi_registered_event - Event Specific Information
313 * @proto: A reference to the associated protocol descriptor
316 * @report: A pre-allocated buffer used by the deferred worker to fill a
325 * stored in the @registered_events array at protocol registration time.
329 * safely grab a NON-NULL reference from the table we can keep it and use it.
342 * struct scmi_event_handler - Event handler information
348 * known nor registered by any protocol at that point in time
356 * These descriptors are stored in a per-protocol @registered_events_handlers
368 #define IS_HNDL_PENDING(hndl) (!(hndl)->r_evt)
378 * scmi_lookup_and_call_event_chain() - Lookup the proper chain and call it
381 * @report: The customized event-specific report to pass down to the callbacks
401 ret = blocking_notifier_call_chain(&hndl->chain, in scmi_lookup_and_call_event_chain()
411 * scmi_process_event_header() - Dequeue and process an event header
413 * @pd: The protocol descriptor to use
415 * Read an event header from the protocol queue into the dedicated scratch
421 * * ERR_PTR(-EINVAL) when NO registered event could be found
431 outs = kfifo_out(&eq->kfifo, pd->eh, in scmi_process_event_header()
436 dev_err(pd->ni->handle->dev, "corrupted EVT header. Flush.\n"); in scmi_process_event_header()
437 kfifo_reset_out(&eq->kfifo); in scmi_process_event_header()
441 r_evt = SCMI_GET_REVT_FROM_PD(pd, pd->eh->evt_id); in scmi_process_event_header()
443 r_evt = ERR_PTR(-EINVAL); in scmi_process_event_header()
449 * scmi_process_event_payload() - Dequeue and process an event payload
451 * @pd: The protocol descriptor to use
454 * Read an event payload from the protocol queue into the dedicated scratch
470 outs = kfifo_out(&eq->kfifo, pd->eh->payld, pd->eh->payld_sz); in scmi_process_event_payload()
474 /* Any in-flight event has now been officially processed */ in scmi_process_event_payload()
475 pd->in_flight = NULL; in scmi_process_event_payload()
477 if (outs != pd->eh->payld_sz) { in scmi_process_event_payload()
478 dev_err(pd->ni->handle->dev, "corrupted EVT Payload. Flush.\n"); in scmi_process_event_payload()
479 kfifo_reset_out(&eq->kfifo); in scmi_process_event_payload()
484 dev_warn(pd->ni->handle->dev, in scmi_process_event_payload()
485 "SKIP UNKNOWN EVT - proto:%X evt:%d\n", in scmi_process_event_payload()
486 pd->id, pd->eh->evt_id); in scmi_process_event_payload()
490 report = REVT_FILL_REPORT(r_evt, pd->eh->evt_id, pd->eh->timestamp, in scmi_process_event_payload()
491 pd->eh->payld, pd->eh->payld_sz, in scmi_process_event_payload()
492 r_evt->report, &src_id); in scmi_process_event_payload()
494 dev_err(pd->ni->handle->dev, in scmi_process_event_payload()
495 "report not available - proto:%X evt:%d\n", in scmi_process_event_payload()
496 pd->id, pd->eh->evt_id); in scmi_process_event_payload()
501 key = MAKE_ALL_SRCS_KEY(pd->id, pd->eh->evt_id); in scmi_process_event_payload()
502 scmi_lookup_and_call_event_chain(pd->ni, key, report); in scmi_process_event_payload()
505 key = MAKE_HASH_KEY(pd->id, pd->eh->evt_id, src_id); in scmi_process_event_payload()
506 scmi_lookup_and_call_event_chain(pd->ni, key, report); in scmi_process_event_payload()
512 * scmi_events_dispatcher() - Common worker logic for all work items.
519 * - > call the related notification chain passing in the report
521 * - > call the related notification chain passing in the report
524 * * a dedicated per-protocol kfifo queue is used: in this way an anomalous
526 * * each per-protocol queue is associated to a distinct work_item, which
532 * reader/writer on the associated kfifo, so that we can use it lock-less
545 * In order to keep the queue lock-less and the number of memcopies in scmi_events_dispatcher()
547 * possibility of per-protocol in-flight events: i.e. an event whose in scmi_events_dispatcher()
552 if (!pd->in_flight) { in scmi_events_dispatcher()
556 pd->in_flight = r_evt; in scmi_events_dispatcher()
558 r_evt = pd->in_flight; in scmi_events_dispatcher()
564 * scmi_notify() - Queues a notification for further deferred processing
567 * @proto_id: Protocol ID
568 * @evt_id: Event ID (msgID)
591 return -EINVAL; in scmi_notify()
593 if (len > r_evt->evt->max_payld_sz) { in scmi_notify()
594 dev_err(handle->dev, "discard badly sized message\n"); in scmi_notify()
595 return -EINVAL; in scmi_notify()
597 if (kfifo_avail(&r_evt->proto->equeue.kfifo) < sizeof(eh) + len) { in scmi_notify()
598 dev_warn(handle->dev, in scmi_notify()
601 return -ENOMEM; in scmi_notify()
610 * with in-flight events tracking. in scmi_notify()
612 kfifo_in(&r_evt->proto->equeue.kfifo, &eh, sizeof(eh)); in scmi_notify()
613 kfifo_in(&r_evt->proto->equeue.kfifo, buf, len); in scmi_notify()
618 * - if work was already queued it will simply fail to queue a new one in scmi_notify()
620 * - if work was not queued already it will be now, even in case work in scmi_notify()
626 queue_work(r_evt->proto->equeue.wq, in scmi_notify()
627 &r_evt->proto->equeue.notify_work); in scmi_notify()
633 * scmi_kfifo_free() - Devres action helper to free the kfifo
642 * scmi_initialize_events_queue() - Allocate/Initialize a kfifo buffer
656 if (kfifo_alloc(&equeue->kfifo, sz, GFP_KERNEL)) in scmi_initialize_events_queue()
657 return -ENOMEM; in scmi_initialize_events_queue()
658 /* Size could have been roundup to power-of-two */ in scmi_initialize_events_queue()
659 equeue->sz = kfifo_size(&equeue->kfifo); in scmi_initialize_events_queue()
661 ret = devm_add_action_or_reset(ni->handle->dev, scmi_kfifo_free, in scmi_initialize_events_queue()
662 &equeue->kfifo); in scmi_initialize_events_queue()
666 INIT_WORK(&equeue->notify_work, scmi_events_dispatcher); in scmi_initialize_events_queue()
667 equeue->wq = ni->notify_wq; in scmi_initialize_events_queue()
673 * scmi_allocate_registered_events_desc() - Allocate a registered events'
677 * @proto_id: Protocol ID
679 * @eh_sz: Size of the event header scratch area to pre-allocate
681 * @ops: Pointer to a struct holding references to protocol specific helpers
684 * It is supposed to be called only once for each protocol at protocol
685 * initialization time, so it warns if the requested protocol is found already
701 if (WARN_ON(ni->registered_protocols[proto_id])) in scmi_allocate_registered_events_desc()
702 return ERR_PTR(-EINVAL); in scmi_allocate_registered_events_desc()
704 pd = devm_kzalloc(ni->handle->dev, sizeof(*pd), GFP_KERNEL); in scmi_allocate_registered_events_desc()
706 return ERR_PTR(-ENOMEM); in scmi_allocate_registered_events_desc()
707 pd->id = proto_id; in scmi_allocate_registered_events_desc()
708 pd->ops = ops; in scmi_allocate_registered_events_desc()
709 pd->ni = ni; in scmi_allocate_registered_events_desc()
711 ret = scmi_initialize_events_queue(ni, &pd->equeue, queue_sz); in scmi_allocate_registered_events_desc()
715 pd->eh = devm_kzalloc(ni->handle->dev, eh_sz, GFP_KERNEL); in scmi_allocate_registered_events_desc()
716 if (!pd->eh) in scmi_allocate_registered_events_desc()
717 return ERR_PTR(-ENOMEM); in scmi_allocate_registered_events_desc()
718 pd->eh_sz = eh_sz; in scmi_allocate_registered_events_desc()
720 pd->registered_events = devm_kcalloc(ni->handle->dev, num_events, in scmi_allocate_registered_events_desc()
722 if (!pd->registered_events) in scmi_allocate_registered_events_desc()
723 return ERR_PTR(-ENOMEM); in scmi_allocate_registered_events_desc()
724 pd->num_events = num_events; in scmi_allocate_registered_events_desc()
726 /* Initialize per protocol handlers table */ in scmi_allocate_registered_events_desc()
727 mutex_init(&pd->registered_mtx); in scmi_allocate_registered_events_desc()
728 hash_init(pd->registered_events_handlers); in scmi_allocate_registered_events_desc()
734 * scmi_register_protocol_events() - Register Protocol Events with the core
736 * protocol's events are registered
737 * @proto_id: Protocol ID
738 * @ph: SCMI protocol handle.
739 * @ee: A structure describing the events supported by this protocol.
743 * pre-allocate and store all needed descriptors, scratch buffers and event
759 if (!ee || !ee->ops || !ee->evts || !ph || in scmi_register_protocol_events()
760 (!ee->num_sources && !ee->ops->get_num_sources)) in scmi_register_protocol_events()
761 return -EINVAL; in scmi_register_protocol_events()
765 return -ENOMEM; in scmi_register_protocol_events()
768 if (ee->num_sources) { in scmi_register_protocol_events()
769 num_sources = ee->num_sources; in scmi_register_protocol_events()
771 int nsrc = ee->ops->get_num_sources(ph); in scmi_register_protocol_events()
774 return -EINVAL; in scmi_register_protocol_events()
778 evt = ee->evts; in scmi_register_protocol_events()
779 for (i = 0; i < ee->num_events; i++) in scmi_register_protocol_events()
783 pd = scmi_allocate_registered_events_desc(ni, proto_id, ee->queue_sz, in scmi_register_protocol_events()
784 payld_sz, ee->num_events, in scmi_register_protocol_events()
785 ee->ops); in scmi_register_protocol_events()
789 pd->ph = ph; in scmi_register_protocol_events()
790 for (i = 0; i < ee->num_events; i++, evt++) { in scmi_register_protocol_events()
793 r_evt = devm_kzalloc(ni->handle->dev, sizeof(*r_evt), in scmi_register_protocol_events()
797 r_evt->proto = pd; in scmi_register_protocol_events()
798 r_evt->evt = evt; in scmi_register_protocol_events()
800 r_evt->sources = devm_kcalloc(ni->handle->dev, num_sources, in scmi_register_protocol_events()
802 if (!r_evt->sources) in scmi_register_protocol_events()
804 r_evt->num_sources = num_sources; in scmi_register_protocol_events()
805 mutex_init(&r_evt->sources_mtx); in scmi_register_protocol_events()
807 r_evt->report = devm_kzalloc(ni->handle->dev, in scmi_register_protocol_events()
808 evt->max_report_sz, GFP_KERNEL); in scmi_register_protocol_events()
809 if (!r_evt->report) in scmi_register_protocol_events()
812 pd->registered_events[i] = r_evt; in scmi_register_protocol_events()
815 dev_dbg(handle->dev, "registered event - %lX\n", in scmi_register_protocol_events()
816 MAKE_ALL_SRCS_KEY(r_evt->proto->id, r_evt->evt->id)); in scmi_register_protocol_events()
819 /* Register protocol and events...it will never be removed */ in scmi_register_protocol_events()
820 ni->registered_protocols[proto_id] = pd; in scmi_register_protocol_events()
826 * for this protocol's events registration. in scmi_register_protocol_events()
828 schedule_work(&ni->init_work); in scmi_register_protocol_events()
833 dev_warn(handle->dev, "Proto:%X - Registration Failed !\n", proto_id); in scmi_register_protocol_events()
835 return -ENOMEM; in scmi_register_protocol_events()
839 * scmi_deregister_protocol_events - Deregister protocol events with the core
841 * protocol's events are registered
842 * @proto_id: Protocol ID
854 pd = ni->registered_protocols[proto_id]; in scmi_deregister_protocol_events()
858 ni->registered_protocols[proto_id] = NULL; in scmi_deregister_protocol_events()
862 cancel_work_sync(&pd->equeue.notify_work); in scmi_deregister_protocol_events()
866 * scmi_allocate_event_handler() - Allocate Event handler
874 * associated to this handler descriptor (hndl->r_evt == NULL), so the handler
888 hndl->key = evt_key; in scmi_allocate_event_handler()
889 BLOCKING_INIT_NOTIFIER_HEAD(&hndl->chain); in scmi_allocate_event_handler()
890 refcount_set(&hndl->users, 1); in scmi_allocate_event_handler()
892 hash_add(ni->pending_events_handlers, &hndl->hash, hndl->key); in scmi_allocate_event_handler()
898 * scmi_free_event_handler() - Free the provided Event handler
906 hash_del(&hndl->hash); in scmi_free_event_handler()
911 * scmi_bind_event_handler() - Helper to attempt binding an handler to an event
927 r_evt = SCMI_GET_REVT(ni, KEY_XTRACT_PROTO_ID(hndl->key), in scmi_bind_event_handler()
928 KEY_XTRACT_EVT_ID(hndl->key)); in scmi_bind_event_handler()
930 return -EINVAL; in scmi_bind_event_handler()
934 * of protocol instance. in scmi_bind_event_handler()
936 hash_del(&hndl->hash); in scmi_bind_event_handler()
939 * protocol initialization when a notifier is registered against a still in scmi_bind_event_handler()
940 * not registered protocol, since it would make little sense to force init in scmi_bind_event_handler()
944 scmi_acquire_protocol(ni->handle, KEY_XTRACT_PROTO_ID(hndl->key)); in scmi_bind_event_handler()
945 hndl->r_evt = r_evt; in scmi_bind_event_handler()
947 mutex_lock(&r_evt->proto->registered_mtx); in scmi_bind_event_handler()
948 hash_add(r_evt->proto->registered_events_handlers, in scmi_bind_event_handler()
949 &hndl->hash, hndl->key); in scmi_bind_event_handler()
950 mutex_unlock(&r_evt->proto->registered_mtx); in scmi_bind_event_handler()
956 * scmi_valid_pending_handler() - Helper to check pending status of handlers
965 * initialized and registered protocol.
975 return -EINVAL; in scmi_valid_pending_handler()
977 pd = SCMI_GET_PROTO(ni, KEY_XTRACT_PROTO_ID(hndl->key)); in scmi_valid_pending_handler()
979 return -EINVAL; in scmi_valid_pending_handler()
985 * scmi_register_event_handler() - Register whenever possible an Event handler
994 * worker which is kicked each time a new protocol completes its own
1008 dev_dbg(ni->handle->dev, "registered NEW handler - key:%X\n", in scmi_register_event_handler()
1009 hndl->key); in scmi_register_event_handler()
1013 dev_dbg(ni->handle->dev, in scmi_register_event_handler()
1014 "registered PENDING handler - key:%X\n", in scmi_register_event_handler()
1015 hndl->key); in scmi_register_event_handler()
1022 * __scmi_event_handler_get_ops() - Utility to get or create an event handler
1028 * Search for the desired handler matching the key in both the per-protocol
1061 mutex_lock(&ni->pending_mtx); in __scmi_event_handler_get_ops()
1064 mutex_lock(&r_evt->proto->registered_mtx); in __scmi_event_handler_get_ops()
1065 hndl = KEY_FIND(r_evt->proto->registered_events_handlers, in __scmi_event_handler_get_ops()
1068 refcount_inc(&hndl->users); in __scmi_event_handler_get_ops()
1069 mutex_unlock(&r_evt->proto->registered_mtx); in __scmi_event_handler_get_ops()
1074 hndl = KEY_FIND(ni->pending_events_handlers, hndl, evt_key); in __scmi_event_handler_get_ops()
1076 refcount_inc(&hndl->users); in __scmi_event_handler_get_ops()
1083 dev_dbg(ni->handle->dev, in __scmi_event_handler_get_ops()
1084 "purging UNKNOWN handler - key:%X\n", in __scmi_event_handler_get_ops()
1085 hndl->key); in __scmi_event_handler_get_ops()
1091 mutex_unlock(&ni->pending_mtx); in __scmi_event_handler_get_ops()
1109 * scmi_get_active_handler() - Helper to get active handlers only
1113 * Search for the desired handler matching the key only in the per-protocol
1128 mutex_lock(&r_evt->proto->registered_mtx); in scmi_get_active_handler()
1129 hndl = KEY_FIND(r_evt->proto->registered_events_handlers, in scmi_get_active_handler()
1132 refcount_inc(&hndl->users); in scmi_get_active_handler()
1133 mutex_unlock(&r_evt->proto->registered_mtx); in scmi_get_active_handler()
1140 * __scmi_enable_evt() - Enable/disable events generation
1143 * @enable: The action to perform: true->Enable, false->Disable
1161 num_sources = r_evt->num_sources; in __scmi_enable_evt()
1162 } else if (src_id < r_evt->num_sources) { in __scmi_enable_evt()
1165 return -EINVAL; in __scmi_enable_evt()
1168 mutex_lock(&r_evt->sources_mtx); in __scmi_enable_evt()
1170 for (; num_sources; src_id++, num_sources--) { in __scmi_enable_evt()
1173 sid = &r_evt->sources[src_id]; in __scmi_enable_evt()
1175 ret = REVT_NOTIFY_ENABLE(r_evt, r_evt->evt->id, in __scmi_enable_evt()
1185 for (; num_sources; src_id++, num_sources--) { in __scmi_enable_evt()
1186 sid = &r_evt->sources[src_id]; in __scmi_enable_evt()
1189 r_evt->evt->id, src_id); in __scmi_enable_evt()
1193 mutex_unlock(&r_evt->sources_mtx); in __scmi_enable_evt()
1195 return retvals ? 0 : -EINVAL; in __scmi_enable_evt()
1202 if (!hndl->enabled) { in scmi_enable_events()
1203 ret = __scmi_enable_evt(hndl->r_evt, in scmi_enable_events()
1204 KEY_XTRACT_SRC_ID(hndl->key), true); in scmi_enable_events()
1206 hndl->enabled = true; in scmi_enable_events()
1216 if (hndl->enabled) { in scmi_disable_events()
1217 ret = __scmi_enable_evt(hndl->r_evt, in scmi_disable_events()
1218 KEY_XTRACT_SRC_ID(hndl->key), false); in scmi_disable_events()
1220 hndl->enabled = false; in scmi_disable_events()
1227 * scmi_put_handler_unlocked() - Put an event handler
1245 if (refcount_dec_and_test(&hndl->users)) { in scmi_put_handler_unlocked()
1260 struct scmi_registered_event *r_evt = hndl->r_evt; in scmi_put_handler()
1262 mutex_lock(&ni->pending_mtx); in scmi_put_handler()
1264 protocol_id = r_evt->proto->id; in scmi_put_handler()
1265 mutex_lock(&r_evt->proto->registered_mtx); in scmi_put_handler()
1271 mutex_unlock(&r_evt->proto->registered_mtx); in scmi_put_handler()
1273 * Only registered handler acquired protocol; must be here in scmi_put_handler()
1275 * releasing a protocol can trigger its de-initialization in scmi_put_handler()
1279 scmi_release_protocol(ni->handle, protocol_id); in scmi_put_handler()
1281 mutex_unlock(&ni->pending_mtx); in scmi_put_handler()
1288 struct scmi_registered_event *r_evt = hndl->r_evt; in scmi_put_active_handler()
1289 u8 protocol_id = r_evt->proto->id; in scmi_put_active_handler()
1291 mutex_lock(&r_evt->proto->registered_mtx); in scmi_put_active_handler()
1293 mutex_unlock(&r_evt->proto->registered_mtx); in scmi_put_active_handler()
1295 scmi_release_protocol(ni->handle, protocol_id); in scmi_put_active_handler()
1299 * scmi_event_handler_enable_events() - Enable events associated to an handler
1307 pr_err("Failed to ENABLE events for key:%X !\n", hndl->key); in scmi_event_handler_enable_events()
1308 return -EINVAL; in scmi_event_handler_enable_events()
1315 * scmi_register_notifier() - Register a notifier_block for an event
1318 * @proto_id: Protocol ID
1319 * @evt_id: Event ID
1320 * @src_id: Source ID, when NULL register for events coming form ALL possible
1324 * Generic helper to register a notifier_block against a protocol event.
1330 * (proto_X, evt_Y, src_Z) --> chain_X_Y_Z
1332 * @src_id meaning is protocol specific and identifies the origin of the event
1336 * notifications from ALL the available sources for that protocol OR simply that
1337 * the protocol does not support distinct sources.
1342 * protocol is still to be initialized and the handler has just been registered
1358 return -ENODEV; in scmi_register_notifier()
1364 return -EINVAL; in scmi_register_notifier()
1366 blocking_notifier_chain_register(&hndl->chain, nb); in scmi_register_notifier()
1379 * scmi_unregister_notifier() - Unregister a notifier_block for an event
1382 * @proto_id: Protocol ID
1383 * @evt_id: Event ID
1384 * @src_id: Source ID
1404 return -ENODEV; in scmi_unregister_notifier()
1410 return -EINVAL; in scmi_unregister_notifier()
1416 blocking_notifier_chain_unregister(&hndl->chain, nb); in scmi_unregister_notifier()
1448 scmi_unregister_notifier(dres->handle, dres->proto_id, dres->evt_id, in scmi_devm_release_notifier()
1449 dres->src_id, dres->nb); in scmi_devm_release_notifier()
1453 * scmi_devm_register_notifier() - Managed registration of a notifier_block
1457 * @proto_id: Protocol ID
1458 * @evt_id: Event ID
1459 * @src_id: Source ID, when NULL register for events coming form ALL possible
1464 * protocol event.
1476 return -ENOMEM; in scmi_devm_register_notifier()
1478 ret = scmi_register_notifier(sdev->handle, proto_id, in scmi_devm_register_notifier()
1485 dres->handle = sdev->handle; in scmi_devm_register_notifier()
1486 dres->proto_id = proto_id; in scmi_devm_register_notifier()
1487 dres->evt_id = evt_id; in scmi_devm_register_notifier()
1488 dres->nb = nb; in scmi_devm_register_notifier()
1490 dres->__src_id = *src_id; in scmi_devm_register_notifier()
1491 dres->src_id = &dres->__src_id; in scmi_devm_register_notifier()
1493 dres->src_id = NULL; in scmi_devm_register_notifier()
1495 devres_add(&sdev->dev, dres); in scmi_devm_register_notifier()
1508 return dres->proto_id == xres->proto_id && in scmi_devm_notifier_match()
1509 dres->evt_id == xres->evt_id && in scmi_devm_notifier_match()
1510 dres->nb == xres->nb && in scmi_devm_notifier_match()
1511 ((!dres->src_id && !xres->src_id) || in scmi_devm_notifier_match()
1512 (dres->src_id && xres->src_id && in scmi_devm_notifier_match()
1513 dres->__src_id == xres->__src_id)); in scmi_devm_notifier_match()
1517 * scmi_devm_unregister_notifier() - Managed un-registration of a
1521 * @proto_id: Protocol ID
1522 * @evt_id: Event ID
1523 * @src_id: Source ID, when NULL register for events coming form ALL possible
1527 * Generic devres managed helper to explicitly un-register a notifier_block
1528 * against a protocol event, which was previously registered using the above
1538 dres.handle = sdev->handle; in scmi_devm_unregister_notifier()
1548 ret = devres_release(&sdev->dev, scmi_devm_release_notifier, in scmi_devm_unregister_notifier()
1557 * scmi_protocols_late_init() - Worker for late initialization
1560 * This kicks in whenever a new protocol has completed its own registration via
1562 * pending handlers (registered by users while the related protocol was still
1578 mutex_lock(&ni->pending_mtx); in scmi_protocols_late_init()
1579 hash_for_each_safe(ni->pending_events_handlers, bkt, tmp, hndl, hash) { in scmi_protocols_late_init()
1584 dev_dbg(ni->handle->dev, in scmi_protocols_late_init()
1585 "finalized PENDING handler - key:%X\n", in scmi_protocols_late_init()
1586 hndl->key); in scmi_protocols_late_init()
1589 dev_dbg(ni->handle->dev, in scmi_protocols_late_init()
1590 "purging INVALID handler - key:%X\n", in scmi_protocols_late_init()
1591 hndl->key); in scmi_protocols_late_init()
1597 dev_dbg(ni->handle->dev, in scmi_protocols_late_init()
1598 "purging PENDING handler - key:%X\n", in scmi_protocols_late_init()
1599 hndl->key); in scmi_protocols_late_init()
1605 mutex_unlock(&ni->pending_mtx); in scmi_protocols_late_init()
1620 * scmi_notification_init() - Initializes Notification Core Support
1635 * further per-protocol allocations
1650 gid = devres_open_group(handle->dev, NULL, GFP_KERNEL); in scmi_notification_init()
1652 return -ENOMEM; in scmi_notification_init()
1654 ni = devm_kzalloc(handle->dev, sizeof(*ni), GFP_KERNEL); in scmi_notification_init()
1658 ni->gid = gid; in scmi_notification_init()
1659 ni->handle = handle; in scmi_notification_init()
1661 ni->registered_protocols = devm_kcalloc(handle->dev, SCMI_MAX_PROTO, in scmi_notification_init()
1663 if (!ni->registered_protocols) in scmi_notification_init()
1666 ni->notify_wq = alloc_workqueue(dev_name(handle->dev), in scmi_notification_init()
1669 if (!ni->notify_wq) in scmi_notification_init()
1672 mutex_init(&ni->pending_mtx); in scmi_notification_init()
1673 hash_init(ni->pending_events_handlers); in scmi_notification_init()
1675 INIT_WORK(&ni->init_work, scmi_protocols_late_init); in scmi_notification_init()
1678 handle->notify_ops = &notify_ops; in scmi_notification_init()
1682 dev_info(handle->dev, "Core Enabled.\n"); in scmi_notification_init()
1684 devres_close_group(handle->dev, ni->gid); in scmi_notification_init()
1689 dev_warn(handle->dev, "Initialization Failed.\n"); in scmi_notification_init()
1690 devres_release_group(handle->dev, gid); in scmi_notification_init()
1691 return -ENOMEM; in scmi_notification_init()
1695 * scmi_notification_exit() - Shutdown and clean Notification core
1708 destroy_workqueue(ni->notify_wq); in scmi_notification_exit()
1710 devres_release_group(ni->handle->dev, ni->gid); in scmi_notification_exit()