2 * Qualcomm Peripheral Image Loader helpers
4 * Copyright (C) 2016 Linaro Ltd
5 * Copyright (C) 2015 Sony Mobile Communications Inc
6 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/firmware.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/notifier.h>
22 #include <linux/remoteproc.h>
23 #include <linux/rpmsg/qcom_smd.h>
25 #include "remoteproc_internal.h"
26 #include "qcom_common.h"
28 #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev)
29 #define to_ssr_subdev(d) container_of(d, struct qcom_rproc_ssr, subdev)
31 static BLOCKING_NOTIFIER_HEAD(ssr_notifiers);
34 * qcom_mdt_find_rsc_table() - provide dummy resource table for remoteproc
35 * @rproc: remoteproc handle
36 * @fw: firmware header
37 * @tablesz: outgoing size of the table
39 * Returns a dummy table.
41 struct resource_table *qcom_mdt_find_rsc_table(struct rproc *rproc,
42 const struct firmware *fw,
45 static struct resource_table table = { .ver = 1, };
47 *tablesz = sizeof(table);
50 EXPORT_SYMBOL_GPL(qcom_mdt_find_rsc_table);
52 static int smd_subdev_probe(struct rproc_subdev *subdev)
54 struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
56 smd->edge = qcom_smd_register_edge(smd->dev, smd->node);
58 return PTR_ERR_OR_ZERO(smd->edge);
61 static void smd_subdev_remove(struct rproc_subdev *subdev)
63 struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
65 qcom_smd_unregister_edge(smd->edge);
70 * qcom_add_smd_subdev() - try to add a SMD subdevice to rproc
71 * @rproc: rproc handle to parent the subdevice
72 * @smd: reference to a Qualcomm subdev context
74 void qcom_add_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
76 struct device *dev = &rproc->dev;
78 smd->node = of_get_child_by_name(dev->parent->of_node, "smd-edge");
83 rproc_add_subdev(rproc, &smd->subdev, smd_subdev_probe, smd_subdev_remove);
85 EXPORT_SYMBOL_GPL(qcom_add_smd_subdev);
88 * qcom_remove_smd_subdev() - remove the smd subdevice from rproc
89 * @rproc: rproc handle
90 * @smd: the SMD subdevice to remove
92 void qcom_remove_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
94 rproc_remove_subdev(rproc, &smd->subdev);
95 of_node_put(smd->node);
97 EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev);
100 * qcom_register_ssr_notifier() - register SSR notification handler
101 * @nb: notifier_block to notify for restart notifications
103 * Returns 0 on success, negative errno on failure.
105 * This register the @notify function as handler for restart notifications. As
106 * remote processors are stopped this function will be called, with the SSR
107 * name passed as a parameter.
109 int qcom_register_ssr_notifier(struct notifier_block *nb)
111 return blocking_notifier_chain_register(&ssr_notifiers, nb);
113 EXPORT_SYMBOL_GPL(qcom_register_ssr_notifier);
116 * qcom_unregister_ssr_notifier() - unregister SSR notification handler
117 * @nb: notifier_block to unregister
119 void qcom_unregister_ssr_notifier(struct notifier_block *nb)
121 blocking_notifier_chain_unregister(&ssr_notifiers, nb);
123 EXPORT_SYMBOL_GPL(qcom_unregister_ssr_notifier);
125 static int ssr_notify_start(struct rproc_subdev *subdev)
130 static void ssr_notify_stop(struct rproc_subdev *subdev)
132 struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev);
134 blocking_notifier_call_chain(&ssr_notifiers, 0, (void *)ssr->name);
138 * qcom_add_ssr_subdev() - register subdevice as restart notification source
139 * @rproc: rproc handle
140 * @ssr: SSR subdevice handle
141 * @ssr_name: identifier to use for notifications originating from @rproc
143 * As the @ssr is registered with the @rproc SSR events will be sent to all
144 * registered listeners in the system as the remoteproc is shut down.
146 void qcom_add_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr,
147 const char *ssr_name)
149 ssr->name = ssr_name;
151 rproc_add_subdev(rproc, &ssr->subdev, ssr_notify_start, ssr_notify_stop);
153 EXPORT_SYMBOL_GPL(qcom_add_ssr_subdev);
156 * qcom_remove_ssr_subdev() - remove subdevice as restart notification source
157 * @rproc: rproc handle
158 * @ssr: SSR subdevice handle
160 void qcom_remove_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr)
162 rproc_remove_subdev(rproc, &ssr->subdev);
164 EXPORT_SYMBOL_GPL(qcom_remove_ssr_subdev);
166 MODULE_DESCRIPTION("Qualcomm Remoteproc helper driver");
167 MODULE_LICENSE("GPL v2");