Lines Matching refs:sysmon
81 static void sysmon_send_event(struct qcom_sysmon *sysmon, in sysmon_send_event() argument
93 mutex_lock(&sysmon->lock); in sysmon_send_event()
94 reinit_completion(&sysmon->comp); in sysmon_send_event()
95 sysmon->ssr_ack = false; in sysmon_send_event()
97 ret = rpmsg_send(sysmon->ept, req, len); in sysmon_send_event()
99 dev_err(sysmon->dev, "failed to send sysmon event\n"); in sysmon_send_event()
103 ret = wait_for_completion_timeout(&sysmon->comp, in sysmon_send_event()
106 dev_err(sysmon->dev, "timeout waiting for sysmon ack\n"); in sysmon_send_event()
110 if (!sysmon->ssr_ack) in sysmon_send_event()
111 dev_err(sysmon->dev, "unexpected response to sysmon event\n"); in sysmon_send_event()
114 mutex_unlock(&sysmon->lock); in sysmon_send_event()
123 static bool sysmon_request_shutdown(struct qcom_sysmon *sysmon) in sysmon_request_shutdown() argument
129 mutex_lock(&sysmon->lock); in sysmon_request_shutdown()
130 reinit_completion(&sysmon->comp); in sysmon_request_shutdown()
131 sysmon->ssr_ack = false; in sysmon_request_shutdown()
133 ret = rpmsg_send(sysmon->ept, req, strlen(req) + 1); in sysmon_request_shutdown()
135 dev_err(sysmon->dev, "send sysmon shutdown request failed\n"); in sysmon_request_shutdown()
139 ret = wait_for_completion_timeout(&sysmon->comp, in sysmon_request_shutdown()
142 dev_err(sysmon->dev, "timeout waiting for sysmon ack\n"); in sysmon_request_shutdown()
146 if (!sysmon->ssr_ack) in sysmon_request_shutdown()
147 dev_err(sysmon->dev, in sysmon_request_shutdown()
153 mutex_unlock(&sysmon->lock); in sysmon_request_shutdown()
161 struct qcom_sysmon *sysmon = priv; in sysmon_callback() local
165 if (!sysmon) in sysmon_callback()
169 sysmon->ssr_ack = true; in sysmon_callback()
171 complete(&sysmon->comp); in sysmon_callback()
293 struct qcom_sysmon *sysmon = container_of(qmi, struct qcom_sysmon, qmi); in sysmon_ind_cb() local
295 complete(&sysmon->ind_comp); in sysmon_ind_cb()
309 static bool ssctl_request_shutdown_wait(struct qcom_sysmon *sysmon) in ssctl_request_shutdown_wait() argument
313 ret = wait_for_completion_timeout(&sysmon->shutdown_comp, 10 * HZ); in ssctl_request_shutdown_wait()
317 ret = try_wait_for_completion(&sysmon->ind_comp); in ssctl_request_shutdown_wait()
321 dev_err(sysmon->dev, "timeout waiting for shutdown ack\n"); in ssctl_request_shutdown_wait()
331 static bool ssctl_request_shutdown(struct qcom_sysmon *sysmon) in ssctl_request_shutdown() argument
338 reinit_completion(&sysmon->ind_comp); in ssctl_request_shutdown()
339 reinit_completion(&sysmon->shutdown_comp); in ssctl_request_shutdown()
340 ret = qmi_txn_init(&sysmon->qmi, &txn, ssctl_shutdown_resp_ei, &resp); in ssctl_request_shutdown()
342 dev_err(sysmon->dev, "failed to allocate QMI txn\n"); in ssctl_request_shutdown()
346 ret = qmi_send_request(&sysmon->qmi, &sysmon->ssctl, &txn, in ssctl_request_shutdown()
349 dev_err(sysmon->dev, "failed to send shutdown request\n"); in ssctl_request_shutdown()
356 dev_err(sysmon->dev, "timeout waiting for shutdown response\n"); in ssctl_request_shutdown()
358 dev_err(sysmon->dev, "shutdown request rejected\n"); in ssctl_request_shutdown()
360 dev_dbg(sysmon->dev, "shutdown request completed\n"); in ssctl_request_shutdown()
364 if (sysmon->shutdown_irq > 0) in ssctl_request_shutdown()
365 return ssctl_request_shutdown_wait(sysmon); in ssctl_request_shutdown()
375 static void ssctl_send_event(struct qcom_sysmon *sysmon, in ssctl_send_event() argument
384 ret = qmi_txn_init(&sysmon->qmi, &txn, ssctl_subsys_event_resp_ei, &resp); in ssctl_send_event()
386 dev_err(sysmon->dev, "failed to allocate QMI txn\n"); in ssctl_send_event()
397 ret = qmi_send_request(&sysmon->qmi, &sysmon->ssctl, &txn, in ssctl_send_event()
401 dev_err(sysmon->dev, "failed to send subsystem event\n"); in ssctl_send_event()
408 dev_err(sysmon->dev, "timeout waiting for subsystem event response\n"); in ssctl_send_event()
410 dev_err(sysmon->dev, "subsystem event rejected\n"); in ssctl_send_event()
412 dev_dbg(sysmon->dev, "subsystem event accepted\n"); in ssctl_send_event()
424 struct qcom_sysmon *sysmon = container_of(qmi, struct qcom_sysmon, qmi); in ssctl_new_server() local
430 if (strcmp(sysmon->name, "modem")) in ssctl_new_server()
434 if (svc->instance != sysmon->ssctl_instance) in ssctl_new_server()
441 sysmon->ssctl_version = svc->version; in ssctl_new_server()
443 sysmon->ssctl.sq_family = AF_QIPCRTR; in ssctl_new_server()
444 sysmon->ssctl.sq_node = svc->node; in ssctl_new_server()
445 sysmon->ssctl.sq_port = svc->port; in ssctl_new_server()
447 svc->priv = sysmon; in ssctl_new_server()
449 complete(&sysmon->ssctl_comp); in ssctl_new_server()
461 struct qcom_sysmon *sysmon = svc->priv; in ssctl_del_server() local
463 sysmon->ssctl_version = 0; in ssctl_del_server()
473 struct qcom_sysmon *sysmon = container_of(subdev, struct qcom_sysmon, in sysmon_prepare() local
476 .subsys_name = sysmon->name, in sysmon_prepare()
480 mutex_lock(&sysmon->state_lock); in sysmon_prepare()
481 sysmon->state = SSCTL_SSR_EVENT_BEFORE_POWERUP; in sysmon_prepare()
483 mutex_unlock(&sysmon->state_lock); in sysmon_prepare()
499 struct qcom_sysmon *sysmon = container_of(subdev, struct qcom_sysmon, in sysmon_start() local
503 .subsys_name = sysmon->name, in sysmon_start()
507 reinit_completion(&sysmon->ssctl_comp); in sysmon_start()
508 mutex_lock(&sysmon->state_lock); in sysmon_start()
509 sysmon->state = SSCTL_SSR_EVENT_AFTER_POWERUP; in sysmon_start()
511 mutex_unlock(&sysmon->state_lock); in sysmon_start()
516 if (target == sysmon || target->state != SSCTL_SSR_EVENT_AFTER_POWERUP) { in sysmon_start()
524 if (sysmon->ssctl_version == 2) in sysmon_start()
525 ssctl_send_event(sysmon, &event); in sysmon_start()
526 else if (sysmon->ept) in sysmon_start()
527 sysmon_send_event(sysmon, &event); in sysmon_start()
537 struct qcom_sysmon *sysmon = container_of(subdev, struct qcom_sysmon, subdev); in sysmon_stop() local
539 .subsys_name = sysmon->name, in sysmon_stop()
543 sysmon->shutdown_acked = false; in sysmon_stop()
545 mutex_lock(&sysmon->state_lock); in sysmon_stop()
546 sysmon->state = SSCTL_SSR_EVENT_BEFORE_SHUTDOWN; in sysmon_stop()
548 mutex_unlock(&sysmon->state_lock); in sysmon_stop()
554 if (sysmon->ssctl_instance) { in sysmon_stop()
555 if (!wait_for_completion_timeout(&sysmon->ssctl_comp, HZ / 2)) in sysmon_stop()
556 dev_err(sysmon->dev, "timeout waiting for ssctl service\n"); in sysmon_stop()
559 if (sysmon->ssctl_version) in sysmon_stop()
560 sysmon->shutdown_acked = ssctl_request_shutdown(sysmon); in sysmon_stop()
561 else if (sysmon->ept) in sysmon_stop()
562 sysmon->shutdown_acked = sysmon_request_shutdown(sysmon); in sysmon_stop()
567 struct qcom_sysmon *sysmon = container_of(subdev, struct qcom_sysmon, in sysmon_unprepare() local
570 .subsys_name = sysmon->name, in sysmon_unprepare()
574 mutex_lock(&sysmon->state_lock); in sysmon_unprepare()
575 sysmon->state = SSCTL_SSR_EVENT_AFTER_SHUTDOWN; in sysmon_unprepare()
577 mutex_unlock(&sysmon->state_lock); in sysmon_unprepare()
589 struct qcom_sysmon *sysmon = container_of(nb, struct qcom_sysmon, nb); in sysmon_notify() local
593 if (sysmon->state != SSCTL_SSR_EVENT_AFTER_POWERUP || in sysmon_notify()
594 !strcmp(sysmon_event->subsys_name, sysmon->name)) { in sysmon_notify()
595 dev_dbg(sysmon->dev, "not notifying %s\n", sysmon->name); in sysmon_notify()
600 if (sysmon->ssctl_version == 2) in sysmon_notify()
601 ssctl_send_event(sysmon, sysmon_event); in sysmon_notify()
602 else if (sysmon->ept) in sysmon_notify()
603 sysmon_send_event(sysmon, sysmon_event); in sysmon_notify()
610 struct qcom_sysmon *sysmon = data; in sysmon_shutdown_interrupt() local
612 complete(&sysmon->shutdown_comp); in sysmon_shutdown_interrupt()
629 struct qcom_sysmon *sysmon; in qcom_add_sysmon_subdev() local
632 sysmon = kzalloc(sizeof(*sysmon), GFP_KERNEL); in qcom_add_sysmon_subdev()
633 if (!sysmon) in qcom_add_sysmon_subdev()
636 sysmon->dev = rproc->dev.parent; in qcom_add_sysmon_subdev()
637 sysmon->rproc = rproc; in qcom_add_sysmon_subdev()
639 sysmon->name = name; in qcom_add_sysmon_subdev()
640 sysmon->ssctl_instance = ssctl_instance; in qcom_add_sysmon_subdev()
642 init_completion(&sysmon->comp); in qcom_add_sysmon_subdev()
643 init_completion(&sysmon->ind_comp); in qcom_add_sysmon_subdev()
644 init_completion(&sysmon->shutdown_comp); in qcom_add_sysmon_subdev()
645 init_completion(&sysmon->ssctl_comp); in qcom_add_sysmon_subdev()
646 mutex_init(&sysmon->lock); in qcom_add_sysmon_subdev()
647 mutex_init(&sysmon->state_lock); in qcom_add_sysmon_subdev()
649 sysmon->shutdown_irq = of_irq_get_byname(sysmon->dev->of_node, in qcom_add_sysmon_subdev()
651 if (sysmon->shutdown_irq < 0) { in qcom_add_sysmon_subdev()
652 if (sysmon->shutdown_irq != -ENODATA) { in qcom_add_sysmon_subdev()
653 dev_err(sysmon->dev, in qcom_add_sysmon_subdev()
655 ret = sysmon->shutdown_irq; in qcom_add_sysmon_subdev()
656 kfree(sysmon); in qcom_add_sysmon_subdev()
660 ret = devm_request_threaded_irq(sysmon->dev, in qcom_add_sysmon_subdev()
661 sysmon->shutdown_irq, in qcom_add_sysmon_subdev()
664 "q6v5 shutdown-ack", sysmon); in qcom_add_sysmon_subdev()
666 dev_err(sysmon->dev, in qcom_add_sysmon_subdev()
668 kfree(sysmon); in qcom_add_sysmon_subdev()
673 ret = qmi_handle_init(&sysmon->qmi, SSCTL_MAX_MSG_LEN, &ssctl_ops, in qcom_add_sysmon_subdev()
676 dev_err(sysmon->dev, "failed to initialize qmi handle\n"); in qcom_add_sysmon_subdev()
677 kfree(sysmon); in qcom_add_sysmon_subdev()
681 qmi_add_lookup(&sysmon->qmi, 43, 0, 0); in qcom_add_sysmon_subdev()
683 sysmon->subdev.prepare = sysmon_prepare; in qcom_add_sysmon_subdev()
684 sysmon->subdev.start = sysmon_start; in qcom_add_sysmon_subdev()
685 sysmon->subdev.stop = sysmon_stop; in qcom_add_sysmon_subdev()
686 sysmon->subdev.unprepare = sysmon_unprepare; in qcom_add_sysmon_subdev()
688 rproc_add_subdev(rproc, &sysmon->subdev); in qcom_add_sysmon_subdev()
690 sysmon->nb.notifier_call = sysmon_notify; in qcom_add_sysmon_subdev()
691 blocking_notifier_chain_register(&sysmon_notifiers, &sysmon->nb); in qcom_add_sysmon_subdev()
694 list_add(&sysmon->node, &sysmon_list); in qcom_add_sysmon_subdev()
697 return sysmon; in qcom_add_sysmon_subdev()
705 void qcom_remove_sysmon_subdev(struct qcom_sysmon *sysmon) in qcom_remove_sysmon_subdev() argument
707 if (!sysmon) in qcom_remove_sysmon_subdev()
711 list_del(&sysmon->node); in qcom_remove_sysmon_subdev()
714 blocking_notifier_chain_unregister(&sysmon_notifiers, &sysmon->nb); in qcom_remove_sysmon_subdev()
716 rproc_remove_subdev(sysmon->rproc, &sysmon->subdev); in qcom_remove_sysmon_subdev()
718 qmi_handle_release(&sysmon->qmi); in qcom_remove_sysmon_subdev()
720 kfree(sysmon); in qcom_remove_sysmon_subdev()
734 bool qcom_sysmon_shutdown_acked(struct qcom_sysmon *sysmon) in qcom_sysmon_shutdown_acked() argument
736 return sysmon && sysmon->shutdown_acked; in qcom_sysmon_shutdown_acked()
751 struct qcom_sysmon *sysmon; in sysmon_probe() local
761 list_for_each_entry(sysmon, &sysmon_list, node) { in sysmon_probe()
762 if (sysmon->rproc == rproc) in sysmon_probe()
774 rpdev->ept->priv = sysmon; in sysmon_probe()
775 sysmon->ept = rpdev->ept; in sysmon_probe()
788 struct qcom_sysmon *sysmon = rpdev->ept->priv; in sysmon_remove() local
790 sysmon->ept = NULL; in sysmon_remove()