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_glink.h>
24 #include <linux/rpmsg/qcom_smd.h>
26 #include "remoteproc_internal.h"
27 #include "qcom_common.h"
29 #define to_glink_subdev(d) container_of(d, struct qcom_rproc_glink, subdev)
30 #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev)
31 #define to_ssr_subdev(d) container_of(d, struct qcom_rproc_ssr, subdev)
33 static BLOCKING_NOTIFIER_HEAD(ssr_notifiers
);
36 * qcom_mdt_find_rsc_table() - provide dummy resource table for remoteproc
37 * @rproc: remoteproc handle
38 * @fw: firmware header
39 * @tablesz: outgoing size of the table
41 * Returns a dummy table.
43 struct resource_table
*qcom_mdt_find_rsc_table(struct rproc
*rproc
,
44 const struct firmware
*fw
,
47 static struct resource_table table
= { .ver
= 1, };
49 *tablesz
= sizeof(table
);
52 EXPORT_SYMBOL_GPL(qcom_mdt_find_rsc_table
);
54 static int glink_subdev_probe(struct rproc_subdev
*subdev
)
56 struct qcom_rproc_glink
*glink
= to_glink_subdev(subdev
);
58 glink
->edge
= qcom_glink_smem_register(glink
->dev
, glink
->node
);
60 return IS_ERR(glink
->edge
) ? PTR_ERR(glink
->edge
) : 0;
63 static void glink_subdev_remove(struct rproc_subdev
*subdev
)
65 struct qcom_rproc_glink
*glink
= to_glink_subdev(subdev
);
67 qcom_glink_smem_unregister(glink
->edge
);
72 * qcom_add_glink_subdev() - try to add a GLINK subdevice to rproc
73 * @rproc: rproc handle to parent the subdevice
74 * @glink: reference to a GLINK subdev context
76 void qcom_add_glink_subdev(struct rproc
*rproc
, struct qcom_rproc_glink
*glink
)
78 struct device
*dev
= &rproc
->dev
;
80 glink
->node
= of_get_child_by_name(dev
->parent
->of_node
, "glink-edge");
85 rproc_add_subdev(rproc
, &glink
->subdev
, glink_subdev_probe
, glink_subdev_remove
);
87 EXPORT_SYMBOL_GPL(qcom_add_glink_subdev
);
90 * qcom_remove_glink_subdev() - remove a GLINK subdevice from rproc
91 * @rproc: rproc handle
92 * @glink: reference to a GLINK subdev context
94 void qcom_remove_glink_subdev(struct rproc
*rproc
, struct qcom_rproc_glink
*glink
)
96 rproc_remove_subdev(rproc
, &glink
->subdev
);
97 of_node_put(glink
->node
);
99 EXPORT_SYMBOL_GPL(qcom_remove_glink_subdev
);
101 static int smd_subdev_probe(struct rproc_subdev
*subdev
)
103 struct qcom_rproc_subdev
*smd
= to_smd_subdev(subdev
);
105 smd
->edge
= qcom_smd_register_edge(smd
->dev
, smd
->node
);
107 return PTR_ERR_OR_ZERO(smd
->edge
);
110 static void smd_subdev_remove(struct rproc_subdev
*subdev
)
112 struct qcom_rproc_subdev
*smd
= to_smd_subdev(subdev
);
114 qcom_smd_unregister_edge(smd
->edge
);
119 * qcom_add_smd_subdev() - try to add a SMD subdevice to rproc
120 * @rproc: rproc handle to parent the subdevice
121 * @smd: reference to a Qualcomm subdev context
123 void qcom_add_smd_subdev(struct rproc
*rproc
, struct qcom_rproc_subdev
*smd
)
125 struct device
*dev
= &rproc
->dev
;
127 smd
->node
= of_get_child_by_name(dev
->parent
->of_node
, "smd-edge");
132 rproc_add_subdev(rproc
, &smd
->subdev
, smd_subdev_probe
, smd_subdev_remove
);
134 EXPORT_SYMBOL_GPL(qcom_add_smd_subdev
);
137 * qcom_remove_smd_subdev() - remove the smd subdevice from rproc
138 * @rproc: rproc handle
139 * @smd: the SMD subdevice to remove
141 void qcom_remove_smd_subdev(struct rproc
*rproc
, struct qcom_rproc_subdev
*smd
)
143 rproc_remove_subdev(rproc
, &smd
->subdev
);
144 of_node_put(smd
->node
);
146 EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev
);
149 * qcom_register_ssr_notifier() - register SSR notification handler
150 * @nb: notifier_block to notify for restart notifications
152 * Returns 0 on success, negative errno on failure.
154 * This register the @notify function as handler for restart notifications. As
155 * remote processors are stopped this function will be called, with the SSR
156 * name passed as a parameter.
158 int qcom_register_ssr_notifier(struct notifier_block
*nb
)
160 return blocking_notifier_chain_register(&ssr_notifiers
, nb
);
162 EXPORT_SYMBOL_GPL(qcom_register_ssr_notifier
);
165 * qcom_unregister_ssr_notifier() - unregister SSR notification handler
166 * @nb: notifier_block to unregister
168 void qcom_unregister_ssr_notifier(struct notifier_block
*nb
)
170 blocking_notifier_chain_unregister(&ssr_notifiers
, nb
);
172 EXPORT_SYMBOL_GPL(qcom_unregister_ssr_notifier
);
174 static int ssr_notify_start(struct rproc_subdev
*subdev
)
179 static void ssr_notify_stop(struct rproc_subdev
*subdev
)
181 struct qcom_rproc_ssr
*ssr
= to_ssr_subdev(subdev
);
183 blocking_notifier_call_chain(&ssr_notifiers
, 0, (void *)ssr
->name
);
187 * qcom_add_ssr_subdev() - register subdevice as restart notification source
188 * @rproc: rproc handle
189 * @ssr: SSR subdevice handle
190 * @ssr_name: identifier to use for notifications originating from @rproc
192 * As the @ssr is registered with the @rproc SSR events will be sent to all
193 * registered listeners in the system as the remoteproc is shut down.
195 void qcom_add_ssr_subdev(struct rproc
*rproc
, struct qcom_rproc_ssr
*ssr
,
196 const char *ssr_name
)
198 ssr
->name
= ssr_name
;
200 rproc_add_subdev(rproc
, &ssr
->subdev
, ssr_notify_start
, ssr_notify_stop
);
202 EXPORT_SYMBOL_GPL(qcom_add_ssr_subdev
);
205 * qcom_remove_ssr_subdev() - remove subdevice as restart notification source
206 * @rproc: rproc handle
207 * @ssr: SSR subdevice handle
209 void qcom_remove_ssr_subdev(struct rproc
*rproc
, struct qcom_rproc_ssr
*ssr
)
211 rproc_remove_subdev(rproc
, &ssr
->subdev
);
213 EXPORT_SYMBOL_GPL(qcom_remove_ssr_subdev
);
215 MODULE_DESCRIPTION("Qualcomm Remoteproc helper driver");
216 MODULE_LICENSE("GPL v2");