.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Qualcomm Peripheral Image Loader helpers |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2016 Linaro Ltd |
---|
5 | 6 | * Copyright (C) 2015 Sony Mobile Communications Inc |
---|
6 | 7 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
---|
7 | | - * |
---|
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. |
---|
11 | | - * |
---|
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. |
---|
16 | 8 | */ |
---|
17 | 9 | |
---|
18 | 10 | #include <linux/firmware.h> |
---|
.. | .. |
---|
20 | 12 | #include <linux/module.h> |
---|
21 | 13 | #include <linux/notifier.h> |
---|
22 | 14 | #include <linux/remoteproc.h> |
---|
| 15 | +#include <linux/remoteproc/qcom_rproc.h> |
---|
23 | 16 | #include <linux/rpmsg/qcom_glink.h> |
---|
24 | 17 | #include <linux/rpmsg/qcom_smd.h> |
---|
| 18 | +#include <linux/slab.h> |
---|
25 | 19 | #include <linux/soc/qcom/mdt_loader.h> |
---|
26 | 20 | |
---|
27 | 21 | #include "remoteproc_internal.h" |
---|
.. | .. |
---|
31 | 25 | #define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev) |
---|
32 | 26 | #define to_ssr_subdev(d) container_of(d, struct qcom_rproc_ssr, subdev) |
---|
33 | 27 | |
---|
34 | | -static BLOCKING_NOTIFIER_HEAD(ssr_notifiers); |
---|
| 28 | +struct qcom_ssr_subsystem { |
---|
| 29 | + const char *name; |
---|
| 30 | + struct srcu_notifier_head notifier_list; |
---|
| 31 | + struct list_head list; |
---|
| 32 | +}; |
---|
| 33 | + |
---|
| 34 | +static LIST_HEAD(qcom_ssr_subsystem_list); |
---|
| 35 | +static DEFINE_MUTEX(qcom_ssr_subsys_lock); |
---|
35 | 36 | |
---|
36 | 37 | static int glink_subdev_start(struct rproc_subdev *subdev) |
---|
37 | 38 | { |
---|
.. | .. |
---|
50 | 51 | glink->edge = NULL; |
---|
51 | 52 | } |
---|
52 | 53 | |
---|
| 54 | +static void glink_subdev_unprepare(struct rproc_subdev *subdev) |
---|
| 55 | +{ |
---|
| 56 | + struct qcom_rproc_glink *glink = to_glink_subdev(subdev); |
---|
| 57 | + |
---|
| 58 | + qcom_glink_ssr_notify(glink->ssr_name); |
---|
| 59 | +} |
---|
| 60 | + |
---|
53 | 61 | /** |
---|
54 | 62 | * qcom_add_glink_subdev() - try to add a GLINK subdevice to rproc |
---|
55 | 63 | * @rproc: rproc handle to parent the subdevice |
---|
56 | 64 | * @glink: reference to a GLINK subdev context |
---|
| 65 | + * @ssr_name: identifier of the associated remoteproc for ssr notifications |
---|
57 | 66 | */ |
---|
58 | | -void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink) |
---|
| 67 | +void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink, |
---|
| 68 | + const char *ssr_name) |
---|
59 | 69 | { |
---|
60 | 70 | struct device *dev = &rproc->dev; |
---|
61 | 71 | |
---|
.. | .. |
---|
63 | 73 | if (!glink->node) |
---|
64 | 74 | return; |
---|
65 | 75 | |
---|
| 76 | + glink->ssr_name = kstrdup_const(ssr_name, GFP_KERNEL); |
---|
| 77 | + if (!glink->ssr_name) |
---|
| 78 | + return; |
---|
| 79 | + |
---|
66 | 80 | glink->dev = dev; |
---|
67 | 81 | glink->subdev.start = glink_subdev_start; |
---|
68 | 82 | glink->subdev.stop = glink_subdev_stop; |
---|
| 83 | + glink->subdev.unprepare = glink_subdev_unprepare; |
---|
69 | 84 | |
---|
70 | 85 | rproc_add_subdev(rproc, &glink->subdev); |
---|
71 | 86 | } |
---|
.. | .. |
---|
82 | 97 | return; |
---|
83 | 98 | |
---|
84 | 99 | rproc_remove_subdev(rproc, &glink->subdev); |
---|
| 100 | + kfree_const(glink->ssr_name); |
---|
85 | 101 | of_node_put(glink->node); |
---|
86 | 102 | } |
---|
87 | 103 | EXPORT_SYMBOL_GPL(qcom_remove_glink_subdev); |
---|
.. | .. |
---|
182 | 198 | } |
---|
183 | 199 | EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev); |
---|
184 | 200 | |
---|
| 201 | +static struct qcom_ssr_subsystem *qcom_ssr_get_subsys(const char *name) |
---|
| 202 | +{ |
---|
| 203 | + struct qcom_ssr_subsystem *info; |
---|
| 204 | + |
---|
| 205 | + mutex_lock(&qcom_ssr_subsys_lock); |
---|
| 206 | + /* Match in the global qcom_ssr_subsystem_list with name */ |
---|
| 207 | + list_for_each_entry(info, &qcom_ssr_subsystem_list, list) |
---|
| 208 | + if (!strcmp(info->name, name)) |
---|
| 209 | + goto out; |
---|
| 210 | + |
---|
| 211 | + info = kzalloc(sizeof(*info), GFP_KERNEL); |
---|
| 212 | + if (!info) { |
---|
| 213 | + info = ERR_PTR(-ENOMEM); |
---|
| 214 | + goto out; |
---|
| 215 | + } |
---|
| 216 | + info->name = kstrdup_const(name, GFP_KERNEL); |
---|
| 217 | + srcu_init_notifier_head(&info->notifier_list); |
---|
| 218 | + |
---|
| 219 | + /* Add to global notification list */ |
---|
| 220 | + list_add_tail(&info->list, &qcom_ssr_subsystem_list); |
---|
| 221 | + |
---|
| 222 | +out: |
---|
| 223 | + mutex_unlock(&qcom_ssr_subsys_lock); |
---|
| 224 | + return info; |
---|
| 225 | +} |
---|
| 226 | + |
---|
185 | 227 | /** |
---|
186 | 228 | * qcom_register_ssr_notifier() - register SSR notification handler |
---|
187 | | - * @nb: notifier_block to notify for restart notifications |
---|
| 229 | + * @name: Subsystem's SSR name |
---|
| 230 | + * @nb: notifier_block to be invoked upon subsystem's state change |
---|
188 | 231 | * |
---|
189 | | - * Returns 0 on success, negative errno on failure. |
---|
| 232 | + * This registers the @nb notifier block as part the notifier chain for a |
---|
| 233 | + * remoteproc associated with @name. The notifier block's callback |
---|
| 234 | + * will be invoked when the remote processor's SSR events occur |
---|
| 235 | + * (pre/post startup and pre/post shutdown). |
---|
190 | 236 | * |
---|
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. |
---|
| 237 | + * Return: a subsystem cookie on success, ERR_PTR on failure. |
---|
194 | 238 | */ |
---|
195 | | -int qcom_register_ssr_notifier(struct notifier_block *nb) |
---|
| 239 | +void *qcom_register_ssr_notifier(const char *name, struct notifier_block *nb) |
---|
196 | 240 | { |
---|
197 | | - return blocking_notifier_chain_register(&ssr_notifiers, nb); |
---|
| 241 | + struct qcom_ssr_subsystem *info; |
---|
| 242 | + |
---|
| 243 | + info = qcom_ssr_get_subsys(name); |
---|
| 244 | + if (IS_ERR(info)) |
---|
| 245 | + return info; |
---|
| 246 | + |
---|
| 247 | + srcu_notifier_chain_register(&info->notifier_list, nb); |
---|
| 248 | + |
---|
| 249 | + return &info->notifier_list; |
---|
198 | 250 | } |
---|
199 | 251 | EXPORT_SYMBOL_GPL(qcom_register_ssr_notifier); |
---|
200 | 252 | |
---|
201 | 253 | /** |
---|
202 | 254 | * qcom_unregister_ssr_notifier() - unregister SSR notification handler |
---|
| 255 | + * @notify: subsystem cookie returned from qcom_register_ssr_notifier |
---|
203 | 256 | * @nb: notifier_block to unregister |
---|
| 257 | + * |
---|
| 258 | + * This function will unregister the notifier from the particular notifier |
---|
| 259 | + * chain. |
---|
| 260 | + * |
---|
| 261 | + * Return: 0 on success, %ENOENT otherwise. |
---|
204 | 262 | */ |
---|
205 | | -void qcom_unregister_ssr_notifier(struct notifier_block *nb) |
---|
| 263 | +int qcom_unregister_ssr_notifier(void *notify, struct notifier_block *nb) |
---|
206 | 264 | { |
---|
207 | | - blocking_notifier_chain_unregister(&ssr_notifiers, nb); |
---|
| 265 | + return srcu_notifier_chain_unregister(notify, nb); |
---|
208 | 266 | } |
---|
209 | 267 | EXPORT_SYMBOL_GPL(qcom_unregister_ssr_notifier); |
---|
| 268 | + |
---|
| 269 | +static int ssr_notify_prepare(struct rproc_subdev *subdev) |
---|
| 270 | +{ |
---|
| 271 | + struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev); |
---|
| 272 | + struct qcom_ssr_notify_data data = { |
---|
| 273 | + .name = ssr->info->name, |
---|
| 274 | + .crashed = false, |
---|
| 275 | + }; |
---|
| 276 | + |
---|
| 277 | + srcu_notifier_call_chain(&ssr->info->notifier_list, |
---|
| 278 | + QCOM_SSR_BEFORE_POWERUP, &data); |
---|
| 279 | + return 0; |
---|
| 280 | +} |
---|
| 281 | + |
---|
| 282 | +static int ssr_notify_start(struct rproc_subdev *subdev) |
---|
| 283 | +{ |
---|
| 284 | + struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev); |
---|
| 285 | + struct qcom_ssr_notify_data data = { |
---|
| 286 | + .name = ssr->info->name, |
---|
| 287 | + .crashed = false, |
---|
| 288 | + }; |
---|
| 289 | + |
---|
| 290 | + srcu_notifier_call_chain(&ssr->info->notifier_list, |
---|
| 291 | + QCOM_SSR_AFTER_POWERUP, &data); |
---|
| 292 | + return 0; |
---|
| 293 | +} |
---|
210 | 294 | |
---|
211 | 295 | static void ssr_notify_stop(struct rproc_subdev *subdev, bool crashed) |
---|
212 | 296 | { |
---|
213 | 297 | struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev); |
---|
| 298 | + struct qcom_ssr_notify_data data = { |
---|
| 299 | + .name = ssr->info->name, |
---|
| 300 | + .crashed = crashed, |
---|
| 301 | + }; |
---|
214 | 302 | |
---|
215 | | - blocking_notifier_call_chain(&ssr_notifiers, 0, (void *)ssr->name); |
---|
| 303 | + srcu_notifier_call_chain(&ssr->info->notifier_list, |
---|
| 304 | + QCOM_SSR_BEFORE_SHUTDOWN, &data); |
---|
| 305 | +} |
---|
| 306 | + |
---|
| 307 | +static void ssr_notify_unprepare(struct rproc_subdev *subdev) |
---|
| 308 | +{ |
---|
| 309 | + struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev); |
---|
| 310 | + struct qcom_ssr_notify_data data = { |
---|
| 311 | + .name = ssr->info->name, |
---|
| 312 | + .crashed = false, |
---|
| 313 | + }; |
---|
| 314 | + |
---|
| 315 | + srcu_notifier_call_chain(&ssr->info->notifier_list, |
---|
| 316 | + QCOM_SSR_AFTER_SHUTDOWN, &data); |
---|
216 | 317 | } |
---|
217 | 318 | |
---|
218 | 319 | /** |
---|
.. | .. |
---|
222 | 323 | * @ssr_name: identifier to use for notifications originating from @rproc |
---|
223 | 324 | * |
---|
224 | 325 | * 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. |
---|
| 326 | + * registered listeners for the remoteproc when it's SSR events occur |
---|
| 327 | + * (pre/post startup and pre/post shutdown). |
---|
226 | 328 | */ |
---|
227 | 329 | void qcom_add_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr, |
---|
228 | 330 | const char *ssr_name) |
---|
229 | 331 | { |
---|
230 | | - ssr->name = ssr_name; |
---|
| 332 | + struct qcom_ssr_subsystem *info; |
---|
| 333 | + |
---|
| 334 | + info = qcom_ssr_get_subsys(ssr_name); |
---|
| 335 | + if (IS_ERR(info)) { |
---|
| 336 | + dev_err(&rproc->dev, "Failed to add ssr subdevice\n"); |
---|
| 337 | + return; |
---|
| 338 | + } |
---|
| 339 | + |
---|
| 340 | + ssr->info = info; |
---|
| 341 | + ssr->subdev.prepare = ssr_notify_prepare; |
---|
| 342 | + ssr->subdev.start = ssr_notify_start; |
---|
231 | 343 | ssr->subdev.stop = ssr_notify_stop; |
---|
| 344 | + ssr->subdev.unprepare = ssr_notify_unprepare; |
---|
232 | 345 | |
---|
233 | 346 | rproc_add_subdev(rproc, &ssr->subdev); |
---|
234 | 347 | } |
---|
.. | .. |
---|
242 | 355 | void qcom_remove_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr) |
---|
243 | 356 | { |
---|
244 | 357 | rproc_remove_subdev(rproc, &ssr->subdev); |
---|
| 358 | + ssr->info = NULL; |
---|
245 | 359 | } |
---|
246 | 360 | EXPORT_SYMBOL_GPL(qcom_remove_ssr_subdev); |
---|
247 | 361 | |
---|