Lines Matching +full:protocol +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2020-2021 ARM Ltd.
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()
796 return -ENOMEM; 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()
803 return -ENOMEM; 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()
810 return -ENOMEM; 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()
834 * scmi_deregister_protocol_events - Deregister protocol events with the core
836 * protocol's events are registered
837 * @proto_id: Protocol ID
849 pd = ni->registered_protocols[proto_id]; in scmi_deregister_protocol_events()
853 ni->registered_protocols[proto_id] = NULL; in scmi_deregister_protocol_events()
857 cancel_work_sync(&pd->equeue.notify_work); in scmi_deregister_protocol_events()
861 * scmi_allocate_event_handler() - Allocate Event handler
869 * associated to this handler descriptor (hndl->r_evt == NULL), so the handler
883 hndl->key = evt_key; in scmi_allocate_event_handler()
884 BLOCKING_INIT_NOTIFIER_HEAD(&hndl->chain); in scmi_allocate_event_handler()
885 refcount_set(&hndl->users, 1); in scmi_allocate_event_handler()
887 hash_add(ni->pending_events_handlers, &hndl->hash, hndl->key); in scmi_allocate_event_handler()
893 * scmi_free_event_handler() - Free the provided Event handler
901 hash_del(&hndl->hash); in scmi_free_event_handler()
906 * scmi_bind_event_handler() - Helper to attempt binding an handler to an event
922 r_evt = SCMI_GET_REVT(ni, KEY_XTRACT_PROTO_ID(hndl->key), in scmi_bind_event_handler()
923 KEY_XTRACT_EVT_ID(hndl->key)); in scmi_bind_event_handler()
925 return -EINVAL; in scmi_bind_event_handler()
929 * of protocol instance. in scmi_bind_event_handler()
931 hash_del(&hndl->hash); in scmi_bind_event_handler()
934 * protocol initialization when a notifier is registered against a still in scmi_bind_event_handler()
935 * not registered protocol, since it would make little sense to force init in scmi_bind_event_handler()
939 scmi_protocol_acquire(ni->handle, KEY_XTRACT_PROTO_ID(hndl->key)); in scmi_bind_event_handler()
940 hndl->r_evt = r_evt; in scmi_bind_event_handler()
942 mutex_lock(&r_evt->proto->registered_mtx); in scmi_bind_event_handler()
943 hash_add(r_evt->proto->registered_events_handlers, in scmi_bind_event_handler()
944 &hndl->hash, hndl->key); in scmi_bind_event_handler()
945 mutex_unlock(&r_evt->proto->registered_mtx); in scmi_bind_event_handler()
951 * scmi_valid_pending_handler() - Helper to check pending status of handlers
960 * initialized and registered protocol.
970 return -EINVAL; in scmi_valid_pending_handler()
972 pd = SCMI_GET_PROTO(ni, KEY_XTRACT_PROTO_ID(hndl->key)); in scmi_valid_pending_handler()
974 return -EINVAL; in scmi_valid_pending_handler()
980 * scmi_register_event_handler() - Register whenever possible an Event handler
989 * worker which is kicked each time a new protocol completes its own
1003 dev_dbg(ni->handle->dev, "registered NEW handler - key:%X\n", in scmi_register_event_handler()
1004 hndl->key); in scmi_register_event_handler()
1008 dev_dbg(ni->handle->dev, in scmi_register_event_handler()
1009 "registered PENDING handler - key:%X\n", in scmi_register_event_handler()
1010 hndl->key); in scmi_register_event_handler()
1017 * __scmi_event_handler_get_ops() - Utility to get or create an event handler
1023 * Search for the desired handler matching the key in both the per-protocol
1056 mutex_lock(&ni->pending_mtx); in __scmi_event_handler_get_ops()
1059 mutex_lock(&r_evt->proto->registered_mtx); in __scmi_event_handler_get_ops()
1060 hndl = KEY_FIND(r_evt->proto->registered_events_handlers, in __scmi_event_handler_get_ops()
1063 refcount_inc(&hndl->users); in __scmi_event_handler_get_ops()
1064 mutex_unlock(&r_evt->proto->registered_mtx); in __scmi_event_handler_get_ops()
1069 hndl = KEY_FIND(ni->pending_events_handlers, hndl, evt_key); in __scmi_event_handler_get_ops()
1071 refcount_inc(&hndl->users); in __scmi_event_handler_get_ops()
1078 dev_dbg(ni->handle->dev, in __scmi_event_handler_get_ops()
1079 "purging UNKNOWN handler - key:%X\n", in __scmi_event_handler_get_ops()
1080 hndl->key); in __scmi_event_handler_get_ops()
1086 mutex_unlock(&ni->pending_mtx); in __scmi_event_handler_get_ops()
1104 * scmi_get_active_handler() - Helper to get active handlers only
1108 * Search for the desired handler matching the key only in the per-protocol
1123 mutex_lock(&r_evt->proto->registered_mtx); in scmi_get_active_handler()
1124 hndl = KEY_FIND(r_evt->proto->registered_events_handlers, in scmi_get_active_handler()
1127 refcount_inc(&hndl->users); in scmi_get_active_handler()
1128 mutex_unlock(&r_evt->proto->registered_mtx); in scmi_get_active_handler()
1135 * __scmi_enable_evt() - Enable/disable events generation
1138 * @enable: The action to perform: true->Enable, false->Disable
1156 num_sources = r_evt->num_sources; in __scmi_enable_evt()
1157 } else if (src_id < r_evt->num_sources) { in __scmi_enable_evt()
1160 return -EINVAL; in __scmi_enable_evt()
1163 mutex_lock(&r_evt->sources_mtx); in __scmi_enable_evt()
1165 for (; num_sources; src_id++, num_sources--) { in __scmi_enable_evt()
1168 sid = &r_evt->sources[src_id]; in __scmi_enable_evt()
1170 ret = REVT_NOTIFY_ENABLE(r_evt, r_evt->evt->id, in __scmi_enable_evt()
1180 for (; num_sources; src_id++, num_sources--) { in __scmi_enable_evt()
1181 sid = &r_evt->sources[src_id]; in __scmi_enable_evt()
1184 r_evt->evt->id, src_id); in __scmi_enable_evt()
1188 mutex_unlock(&r_evt->sources_mtx); in __scmi_enable_evt()
1190 return retvals ? 0 : -EINVAL; in __scmi_enable_evt()
1197 if (!hndl->enabled) { in scmi_enable_events()
1198 ret = __scmi_enable_evt(hndl->r_evt, in scmi_enable_events()
1199 KEY_XTRACT_SRC_ID(hndl->key), true); in scmi_enable_events()
1201 hndl->enabled = true; in scmi_enable_events()
1211 if (hndl->enabled) { in scmi_disable_events()
1212 ret = __scmi_enable_evt(hndl->r_evt, in scmi_disable_events()
1213 KEY_XTRACT_SRC_ID(hndl->key), false); in scmi_disable_events()
1215 hndl->enabled = false; in scmi_disable_events()
1222 * scmi_put_handler_unlocked() - Put an event handler
1240 if (refcount_dec_and_test(&hndl->users)) { in scmi_put_handler_unlocked()
1255 struct scmi_registered_event *r_evt = hndl->r_evt; in scmi_put_handler()
1257 mutex_lock(&ni->pending_mtx); in scmi_put_handler()
1259 protocol_id = r_evt->proto->id; in scmi_put_handler()
1260 mutex_lock(&r_evt->proto->registered_mtx); in scmi_put_handler()
1266 mutex_unlock(&r_evt->proto->registered_mtx); in scmi_put_handler()
1268 * Only registered handler acquired protocol; must be here in scmi_put_handler()
1270 * releasing a protocol can trigger its de-initialization in scmi_put_handler()
1274 scmi_protocol_release(ni->handle, protocol_id); in scmi_put_handler()
1276 mutex_unlock(&ni->pending_mtx); in scmi_put_handler()
1283 struct scmi_registered_event *r_evt = hndl->r_evt; in scmi_put_active_handler()
1284 u8 protocol_id = r_evt->proto->id; in scmi_put_active_handler()
1286 mutex_lock(&r_evt->proto->registered_mtx); in scmi_put_active_handler()
1288 mutex_unlock(&r_evt->proto->registered_mtx); in scmi_put_active_handler()
1290 scmi_protocol_release(ni->handle, protocol_id); in scmi_put_active_handler()
1294 * scmi_event_handler_enable_events() - Enable events associated to an handler
1302 pr_err("Failed to ENABLE events for key:%X !\n", hndl->key); in scmi_event_handler_enable_events()
1303 return -EINVAL; in scmi_event_handler_enable_events()
1310 * scmi_notifier_register() - Register a notifier_block for an event
1313 * @proto_id: Protocol ID
1314 * @evt_id: Event ID
1315 * @src_id: Source ID, when NULL register for events coming form ALL possible
1319 * Generic helper to register a notifier_block against a protocol event.
1325 * (proto_X, evt_Y, src_Z) --> chain_X_Y_Z
1327 * @src_id meaning is protocol specific and identifies the origin of the event
1331 * notifications from ALL the available sources for that protocol OR simply that
1332 * the protocol does not support distinct sources.
1337 * protocol is still to be initialized and the handler has just been registered
1353 return -ENODEV; in scmi_notifier_register()
1359 return -EINVAL; in scmi_notifier_register()
1361 blocking_notifier_chain_register(&hndl->chain, nb); in scmi_notifier_register()
1374 * scmi_notifier_unregister() - Unregister a notifier_block for an event
1377 * @proto_id: Protocol ID
1378 * @evt_id: Event ID
1379 * @src_id: Source ID
1399 return -ENODEV; in scmi_notifier_unregister()
1405 return -EINVAL; in scmi_notifier_unregister()
1411 blocking_notifier_chain_unregister(&hndl->chain, nb); in scmi_notifier_unregister()
1443 scmi_notifier_unregister(dres->handle, dres->proto_id, dres->evt_id, in scmi_devm_release_notifier()
1444 dres->src_id, dres->nb); in scmi_devm_release_notifier()
1448 * scmi_devm_notifier_register() - Managed registration of a notifier_block
1452 * @proto_id: Protocol ID
1453 * @evt_id: Event ID
1454 * @src_id: Source ID, when NULL register for events coming form ALL possible
1459 * protocol event.
1474 return -ENOMEM; in scmi_devm_notifier_register()
1476 ret = scmi_notifier_register(sdev->handle, proto_id, in scmi_devm_notifier_register()
1483 dres->handle = sdev->handle; in scmi_devm_notifier_register()
1484 dres->proto_id = proto_id; in scmi_devm_notifier_register()
1485 dres->evt_id = evt_id; in scmi_devm_notifier_register()
1486 dres->nb = nb; in scmi_devm_notifier_register()
1488 dres->__src_id = *src_id; in scmi_devm_notifier_register()
1489 dres->src_id = &dres->__src_id; in scmi_devm_notifier_register()
1491 dres->src_id = NULL; in scmi_devm_notifier_register()
1493 devres_add(&sdev->dev, dres); in scmi_devm_notifier_register()
1506 return dres->proto_id == xres->proto_id && in scmi_devm_notifier_match()
1507 dres->evt_id == xres->evt_id && in scmi_devm_notifier_match()
1508 dres->nb == xres->nb && in scmi_devm_notifier_match()
1509 ((!dres->src_id && !xres->src_id) || in scmi_devm_notifier_match()
1510 (dres->src_id && xres->src_id && in scmi_devm_notifier_match()
1511 dres->__src_id == xres->__src_id)); in scmi_devm_notifier_match()
1515 * scmi_devm_notifier_unregister() - Managed un-registration of a
1519 * @proto_id: Protocol ID
1520 * @evt_id: Event ID
1521 * @src_id: Source ID, when NULL register for events coming form ALL possible
1525 * Generic devres managed helper to explicitly un-register a notifier_block
1526 * against a protocol event, which was previously registered using the above
1539 dres.handle = sdev->handle; in scmi_devm_notifier_unregister()
1549 ret = devres_release(&sdev->dev, scmi_devm_release_notifier, in scmi_devm_notifier_unregister()
1558 * scmi_protocols_late_init() - Worker for late initialization
1561 * This kicks in whenever a new protocol has completed its own registration via
1563 * pending handlers (registered by users while the related protocol was still
1579 mutex_lock(&ni->pending_mtx); in scmi_protocols_late_init()
1580 hash_for_each_safe(ni->pending_events_handlers, bkt, tmp, hndl, hash) { in scmi_protocols_late_init()
1585 dev_dbg(ni->handle->dev, in scmi_protocols_late_init()
1586 "finalized PENDING handler - key:%X\n", in scmi_protocols_late_init()
1587 hndl->key); in scmi_protocols_late_init()
1590 dev_dbg(ni->handle->dev, in scmi_protocols_late_init()
1591 "purging INVALID handler - key:%X\n", in scmi_protocols_late_init()
1592 hndl->key); in scmi_protocols_late_init()
1598 dev_dbg(ni->handle->dev, in scmi_protocols_late_init()
1599 "purging PENDING handler - key:%X\n", in scmi_protocols_late_init()
1600 hndl->key); in scmi_protocols_late_init()
1606 mutex_unlock(&ni->pending_mtx); in scmi_protocols_late_init()
1621 * scmi_notification_init() - Initializes Notification Core Support
1636 * further per-protocol allocations
1651 gid = devres_open_group(handle->dev, NULL, GFP_KERNEL); in scmi_notification_init()
1653 return -ENOMEM; in scmi_notification_init()
1655 ni = devm_kzalloc(handle->dev, sizeof(*ni), GFP_KERNEL); in scmi_notification_init()
1659 ni->gid = gid; in scmi_notification_init()
1660 ni->handle = handle; in scmi_notification_init()
1662 ni->registered_protocols = devm_kcalloc(handle->dev, SCMI_MAX_PROTO, in scmi_notification_init()
1664 if (!ni->registered_protocols) in scmi_notification_init()
1667 ni->notify_wq = alloc_workqueue(dev_name(handle->dev), in scmi_notification_init()
1670 if (!ni->notify_wq) in scmi_notification_init()
1673 mutex_init(&ni->pending_mtx); in scmi_notification_init()
1674 hash_init(ni->pending_events_handlers); in scmi_notification_init()
1676 INIT_WORK(&ni->init_work, scmi_protocols_late_init); in scmi_notification_init()
1679 handle->notify_ops = ¬ify_ops; in scmi_notification_init()
1683 dev_info(handle->dev, "Core Enabled.\n"); in scmi_notification_init()
1685 devres_close_group(handle->dev, ni->gid); in scmi_notification_init()
1690 dev_warn(handle->dev, "Initialization Failed.\n"); in scmi_notification_init()
1691 devres_release_group(handle->dev, gid); in scmi_notification_init()
1692 return -ENOMEM; in scmi_notification_init()
1696 * scmi_notification_exit() - Shutdown and clean Notification core
1709 destroy_workqueue(ni->notify_wq); in scmi_notification_exit()
1711 devres_release_group(ni->handle->dev, ni->gid); in scmi_notification_exit()