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>
25 #include <linux/soc/qcom/mdt_loader.h>
27 #include "remoteproc_internal.h"
28 #include "qcom_common.h"
30 #define to_glink_subdev(d) container_of(d, struct qcom_rproc_glink, subdev)
31 #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev)
32 #define to_ssr_subdev(d) container_of(d, struct qcom_rproc_ssr, subdev)
34 static BLOCKING_NOTIFIER_HEAD(ssr_notifiers
);
36 static int glink_subdev_start(struct rproc_subdev
*subdev
)
38 struct qcom_rproc_glink
*glink
= to_glink_subdev(subdev
);
40 glink
->edge
= qcom_glink_smem_register(glink
->dev
, glink
->node
);
42 return PTR_ERR_OR_ZERO(glink
->edge
);
45 static void glink_subdev_stop(struct rproc_subdev
*subdev
, bool crashed
)
47 struct qcom_rproc_glink
*glink
= to_glink_subdev(subdev
);
49 qcom_glink_smem_unregister(glink
->edge
);
54 * qcom_add_glink_subdev() - try to add a GLINK subdevice to rproc
55 * @rproc: rproc handle to parent the subdevice
56 * @glink: reference to a GLINK subdev context
58 void qcom_add_glink_subdev(struct rproc
*rproc
, struct qcom_rproc_glink
*glink
)
60 struct device
*dev
= &rproc
->dev
;
62 glink
->node
= of_get_child_by_name(dev
->parent
->of_node
, "glink-edge");
67 glink
->subdev
.start
= glink_subdev_start
;
68 glink
->subdev
.stop
= glink_subdev_stop
;
70 rproc_add_subdev(rproc
, &glink
->subdev
);
72 EXPORT_SYMBOL_GPL(qcom_add_glink_subdev
);
75 * qcom_remove_glink_subdev() - remove a GLINK subdevice from rproc
76 * @rproc: rproc handle
77 * @glink: reference to a GLINK subdev context
79 void qcom_remove_glink_subdev(struct rproc
*rproc
, struct qcom_rproc_glink
*glink
)
84 rproc_remove_subdev(rproc
, &glink
->subdev
);
85 of_node_put(glink
->node
);
87 EXPORT_SYMBOL_GPL(qcom_remove_glink_subdev
);
90 * qcom_register_dump_segments() - register segments for coredump
91 * @rproc: remoteproc handle
92 * @fw: firmware header
94 * Register all segments of the ELF in the remoteproc coredump segment list
96 * Return: 0 on success, negative errno on failure.
98 int qcom_register_dump_segments(struct rproc
*rproc
,
99 const struct firmware
*fw
)
101 const struct elf32_phdr
*phdrs
;
102 const struct elf32_phdr
*phdr
;
103 const struct elf32_hdr
*ehdr
;
107 ehdr
= (struct elf32_hdr
*)fw
->data
;
108 phdrs
= (struct elf32_phdr
*)(ehdr
+ 1);
110 for (i
= 0; i
< ehdr
->e_phnum
; i
++) {
113 if (phdr
->p_type
!= PT_LOAD
)
116 if ((phdr
->p_flags
& QCOM_MDT_TYPE_MASK
) == QCOM_MDT_TYPE_HASH
)
122 ret
= rproc_coredump_add_segment(rproc
, phdr
->p_paddr
,
130 EXPORT_SYMBOL_GPL(qcom_register_dump_segments
);
132 static int smd_subdev_start(struct rproc_subdev
*subdev
)
134 struct qcom_rproc_subdev
*smd
= to_smd_subdev(subdev
);
136 smd
->edge
= qcom_smd_register_edge(smd
->dev
, smd
->node
);
138 return PTR_ERR_OR_ZERO(smd
->edge
);
141 static void smd_subdev_stop(struct rproc_subdev
*subdev
, bool crashed
)
143 struct qcom_rproc_subdev
*smd
= to_smd_subdev(subdev
);
145 qcom_smd_unregister_edge(smd
->edge
);
150 * qcom_add_smd_subdev() - try to add a SMD subdevice to rproc
151 * @rproc: rproc handle to parent the subdevice
152 * @smd: reference to a Qualcomm subdev context
154 void qcom_add_smd_subdev(struct rproc
*rproc
, struct qcom_rproc_subdev
*smd
)
156 struct device
*dev
= &rproc
->dev
;
158 smd
->node
= of_get_child_by_name(dev
->parent
->of_node
, "smd-edge");
163 smd
->subdev
.start
= smd_subdev_start
;
164 smd
->subdev
.stop
= smd_subdev_stop
;
166 rproc_add_subdev(rproc
, &smd
->subdev
);
168 EXPORT_SYMBOL_GPL(qcom_add_smd_subdev
);
171 * qcom_remove_smd_subdev() - remove the smd subdevice from rproc
172 * @rproc: rproc handle
173 * @smd: the SMD subdevice to remove
175 void qcom_remove_smd_subdev(struct rproc
*rproc
, struct qcom_rproc_subdev
*smd
)
180 rproc_remove_subdev(rproc
, &smd
->subdev
);
181 of_node_put(smd
->node
);
183 EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev
);
186 * qcom_register_ssr_notifier() - register SSR notification handler
187 * @nb: notifier_block to notify for restart notifications
189 * Returns 0 on success, negative errno on failure.
191 * This register the @notify function as handler for restart notifications. As
192 * remote processors are stopped this function will be called, with the SSR
193 * name passed as a parameter.
195 int qcom_register_ssr_notifier(struct notifier_block
*nb
)
197 return blocking_notifier_chain_register(&ssr_notifiers
, nb
);
199 EXPORT_SYMBOL_GPL(qcom_register_ssr_notifier
);
202 * qcom_unregister_ssr_notifier() - unregister SSR notification handler
203 * @nb: notifier_block to unregister
205 void qcom_unregister_ssr_notifier(struct notifier_block
*nb
)
207 blocking_notifier_chain_unregister(&ssr_notifiers
, nb
);
209 EXPORT_SYMBOL_GPL(qcom_unregister_ssr_notifier
);
211 static void ssr_notify_stop(struct rproc_subdev
*subdev
, bool crashed
)
213 struct qcom_rproc_ssr
*ssr
= to_ssr_subdev(subdev
);
215 blocking_notifier_call_chain(&ssr_notifiers
, 0, (void *)ssr
->name
);
219 * qcom_add_ssr_subdev() - register subdevice as restart notification source
220 * @rproc: rproc handle
221 * @ssr: SSR subdevice handle
222 * @ssr_name: identifier to use for notifications originating from @rproc
224 * As the @ssr is registered with the @rproc SSR events will be sent to all
225 * registered listeners in the system as the remoteproc is shut down.
227 void qcom_add_ssr_subdev(struct rproc
*rproc
, struct qcom_rproc_ssr
*ssr
,
228 const char *ssr_name
)
230 ssr
->name
= ssr_name
;
231 ssr
->subdev
.stop
= ssr_notify_stop
;
233 rproc_add_subdev(rproc
, &ssr
->subdev
);
235 EXPORT_SYMBOL_GPL(qcom_add_ssr_subdev
);
238 * qcom_remove_ssr_subdev() - remove subdevice as restart notification source
239 * @rproc: rproc handle
240 * @ssr: SSR subdevice handle
242 void qcom_remove_ssr_subdev(struct rproc
*rproc
, struct qcom_rproc_ssr
*ssr
)
244 rproc_remove_subdev(rproc
, &ssr
->subdev
);
246 EXPORT_SYMBOL_GPL(qcom_remove_ssr_subdev
);
248 MODULE_DESCRIPTION("Qualcomm Remoteproc helper driver");
249 MODULE_LICENSE("GPL v2");