Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Qualcomm Peripheral Image Loader helpers
  4 *
  5 * Copyright (C) 2016 Linaro Ltd
  6 * Copyright (C) 2015 Sony Mobile Communications Inc
  7 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
 
 
 
 
 
 
 
 
 
  8 */
  9
 10#include <linux/firmware.h>
 11#include <linux/kernel.h>
 12#include <linux/module.h>
 13#include <linux/notifier.h>
 14#include <linux/remoteproc.h>
 15#include <linux/remoteproc/qcom_rproc.h>
 16#include <linux/rpmsg/qcom_glink.h>
 17#include <linux/rpmsg/qcom_smd.h>
 18#include <linux/slab.h>
 19#include <linux/soc/qcom/mdt_loader.h>
 20#include <linux/soc/qcom/smem.h>
 21
 22#include "remoteproc_internal.h"
 23#include "qcom_common.h"
 24
 25#define to_glink_subdev(d) container_of(d, struct qcom_rproc_glink, subdev)
 26#define to_smd_subdev(d) container_of(d, struct qcom_rproc_subdev, subdev)
 27#define to_ssr_subdev(d) container_of(d, struct qcom_rproc_ssr, subdev)
 28
 29#define MAX_NUM_OF_SS           10
 30#define MAX_REGION_NAME_LENGTH  16
 31#define SBL_MINIDUMP_SMEM_ID	602
 32#define MINIDUMP_REGION_VALID		('V' << 24 | 'A' << 16 | 'L' << 8 | 'I' << 0)
 33#define MINIDUMP_SS_ENCR_DONE		('D' << 24 | 'O' << 16 | 'N' << 8 | 'E' << 0)
 34#define MINIDUMP_SS_ENABLED		('E' << 24 | 'N' << 16 | 'B' << 8 | 'L' << 0)
 35
 36/**
 37 * struct minidump_region - Minidump region
 38 * @name		: Name of the region to be dumped
 39 * @seq_num:		: Use to differentiate regions with same name.
 40 * @valid		: This entry to be dumped (if set to 1)
 41 * @address		: Physical address of region to be dumped
 42 * @size		: Size of the region
 43 */
 44struct minidump_region {
 45	char	name[MAX_REGION_NAME_LENGTH];
 46	__le32	seq_num;
 47	__le32	valid;
 48	__le64	address;
 49	__le64	size;
 50};
 51
 52/**
 53 * struct minidump_subsystem - Subsystem's SMEM Table of content
 54 * @status : Subsystem toc init status
 55 * @enabled : if set to 1, this region would be copied during coredump
 56 * @encryption_status: Encryption status for this subsystem
 57 * @encryption_required : Decides to encrypt the subsystem regions or not
 58 * @region_count : Number of regions added in this subsystem toc
 59 * @regions_baseptr : regions base pointer of the subsystem
 60 */
 61struct minidump_subsystem {
 62	__le32	status;
 63	__le32	enabled;
 64	__le32	encryption_status;
 65	__le32	encryption_required;
 66	__le32	region_count;
 67	__le64	regions_baseptr;
 68};
 69
 70/**
 71 * struct minidump_global_toc - Global Table of Content
 72 * @status : Global Minidump init status
 73 * @md_revision : Minidump revision
 74 * @enabled : Minidump enable status
 75 * @subsystems : Array of subsystems toc
 76 */
 77struct minidump_global_toc {
 78	__le32				status;
 79	__le32				md_revision;
 80	__le32				enabled;
 81	struct minidump_subsystem	subsystems[MAX_NUM_OF_SS];
 82};
 83
 84struct qcom_ssr_subsystem {
 85	const char *name;
 86	struct srcu_notifier_head notifier_list;
 87	struct list_head list;
 88};
 89
 90static LIST_HEAD(qcom_ssr_subsystem_list);
 91static DEFINE_MUTEX(qcom_ssr_subsys_lock);
 92
 93static void qcom_minidump_cleanup(struct rproc *rproc)
 94{
 95	struct rproc_dump_segment *entry, *tmp;
 96
 97	list_for_each_entry_safe(entry, tmp, &rproc->dump_segments, node) {
 98		list_del(&entry->node);
 99		kfree(entry->priv);
100		kfree(entry);
101	}
102}
103
104static int qcom_add_minidump_segments(struct rproc *rproc, struct minidump_subsystem *subsystem,
105			void (*rproc_dumpfn_t)(struct rproc *rproc, struct rproc_dump_segment *segment,
106				void *dest, size_t offset, size_t size))
107{
108	struct minidump_region __iomem *ptr;
109	struct minidump_region region;
110	int seg_cnt, i;
111	dma_addr_t da;
112	size_t size;
113	char *name;
114
115	if (WARN_ON(!list_empty(&rproc->dump_segments))) {
116		dev_err(&rproc->dev, "dump segment list already populated\n");
117		return -EUCLEAN;
118	}
119
120	seg_cnt = le32_to_cpu(subsystem->region_count);
121	ptr = ioremap((unsigned long)le64_to_cpu(subsystem->regions_baseptr),
122		      seg_cnt * sizeof(struct minidump_region));
123	if (!ptr)
124		return -EFAULT;
125
126	for (i = 0; i < seg_cnt; i++) {
127		memcpy_fromio(&region, ptr + i, sizeof(region));
128		if (le32_to_cpu(region.valid) == MINIDUMP_REGION_VALID) {
129			name = kstrndup(region.name, MAX_REGION_NAME_LENGTH - 1, GFP_KERNEL);
130			if (!name) {
131				iounmap(ptr);
132				return -ENOMEM;
133			}
134			da = le64_to_cpu(region.address);
135			size = le64_to_cpu(region.size);
136			rproc_coredump_add_custom_segment(rproc, da, size, rproc_dumpfn_t, name);
137		}
138	}
139
140	iounmap(ptr);
141	return 0;
142}
143
144void qcom_minidump(struct rproc *rproc, unsigned int minidump_id,
145		void (*rproc_dumpfn_t)(struct rproc *rproc,
146		struct rproc_dump_segment *segment, void *dest, size_t offset,
147		size_t size))
148{
149	int ret;
150	struct minidump_subsystem *subsystem;
151	struct minidump_global_toc *toc;
152
153	/* Get Global minidump ToC*/
154	toc = qcom_smem_get(QCOM_SMEM_HOST_ANY, SBL_MINIDUMP_SMEM_ID, NULL);
155
156	/* check if global table pointer exists and init is set */
157	if (IS_ERR(toc) || !toc->status) {
158		dev_err(&rproc->dev, "Minidump TOC not found in SMEM\n");
159		return;
160	}
161
162	/* Get subsystem table of contents using the minidump id */
163	subsystem = &toc->subsystems[minidump_id];
164
165	/**
166	 * Collect minidump if SS ToC is valid and segment table
167	 * is initialized in memory and encryption status is set.
168	 */
169	if (subsystem->regions_baseptr == 0 ||
170	    le32_to_cpu(subsystem->status) != 1 ||
171	    le32_to_cpu(subsystem->enabled) != MINIDUMP_SS_ENABLED) {
172		return rproc_coredump(rproc);
173	}
174
175	if (le32_to_cpu(subsystem->encryption_status) != MINIDUMP_SS_ENCR_DONE) {
176		dev_err(&rproc->dev, "Minidump not ready, skipping\n");
177		return;
178	}
179
180	/**
181	 * Clear out the dump segments populated by parse_fw before
182	 * re-populating them with minidump segments.
183	 */
184	rproc_coredump_cleanup(rproc);
185
186	ret = qcom_add_minidump_segments(rproc, subsystem, rproc_dumpfn_t);
187	if (ret) {
188		dev_err(&rproc->dev, "Failed with error: %d while adding minidump entries\n", ret);
189		goto clean_minidump;
190	}
191	rproc_coredump_using_sections(rproc);
192clean_minidump:
193	qcom_minidump_cleanup(rproc);
194}
195EXPORT_SYMBOL_GPL(qcom_minidump);
196
197static int glink_subdev_start(struct rproc_subdev *subdev)
198{
199	struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
200
201	glink->edge = qcom_glink_smem_register(glink->dev, glink->node);
202
203	return PTR_ERR_OR_ZERO(glink->edge);
204}
205
206static void glink_subdev_stop(struct rproc_subdev *subdev, bool crashed)
207{
208	struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
209
210	qcom_glink_smem_unregister(glink->edge);
211	glink->edge = NULL;
212}
213
214static void glink_subdev_unprepare(struct rproc_subdev *subdev)
215{
216	struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
217
218	qcom_glink_ssr_notify(glink->ssr_name);
219}
220
221/**
222 * qcom_add_glink_subdev() - try to add a GLINK subdevice to rproc
223 * @rproc:	rproc handle to parent the subdevice
224 * @glink:	reference to a GLINK subdev context
225 * @ssr_name:	identifier of the associated remoteproc for ssr notifications
226 */
227void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink,
228			   const char *ssr_name)
229{
230	struct device *dev = &rproc->dev;
231
232	glink->node = of_get_child_by_name(dev->parent->of_node, "glink-edge");
233	if (!glink->node)
234		return;
235
236	glink->ssr_name = kstrdup_const(ssr_name, GFP_KERNEL);
237	if (!glink->ssr_name)
238		return;
239
240	glink->dev = dev;
241	glink->subdev.start = glink_subdev_start;
242	glink->subdev.stop = glink_subdev_stop;
243	glink->subdev.unprepare = glink_subdev_unprepare;
244
245	rproc_add_subdev(rproc, &glink->subdev);
246}
247EXPORT_SYMBOL_GPL(qcom_add_glink_subdev);
248
249/**
250 * qcom_remove_glink_subdev() - remove a GLINK subdevice from rproc
251 * @rproc:	rproc handle
252 * @glink:	reference to a GLINK subdev context
253 */
254void qcom_remove_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink)
255{
256	if (!glink->node)
257		return;
258
259	rproc_remove_subdev(rproc, &glink->subdev);
260	kfree_const(glink->ssr_name);
261	of_node_put(glink->node);
262}
263EXPORT_SYMBOL_GPL(qcom_remove_glink_subdev);
264
265/**
266 * qcom_register_dump_segments() - register segments for coredump
267 * @rproc:	remoteproc handle
268 * @fw:		firmware header
269 *
270 * Register all segments of the ELF in the remoteproc coredump segment list
271 *
272 * Return: 0 on success, negative errno on failure.
273 */
274int qcom_register_dump_segments(struct rproc *rproc,
275				const struct firmware *fw)
276{
277	const struct elf32_phdr *phdrs;
278	const struct elf32_phdr *phdr;
279	const struct elf32_hdr *ehdr;
280	int ret;
281	int i;
282
283	ehdr = (struct elf32_hdr *)fw->data;
284	phdrs = (struct elf32_phdr *)(ehdr + 1);
285
286	for (i = 0; i < ehdr->e_phnum; i++) {
287		phdr = &phdrs[i];
288
289		if (phdr->p_type != PT_LOAD)
290			continue;
291
292		if ((phdr->p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH)
293			continue;
294
295		if (!phdr->p_memsz)
296			continue;
297
298		ret = rproc_coredump_add_segment(rproc, phdr->p_paddr,
299						 phdr->p_memsz);
300		if (ret)
301			return ret;
302	}
303
304	return 0;
305}
306EXPORT_SYMBOL_GPL(qcom_register_dump_segments);
307
308static int smd_subdev_start(struct rproc_subdev *subdev)
309{
310	struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
311
312	smd->edge = qcom_smd_register_edge(smd->dev, smd->node);
313
314	return PTR_ERR_OR_ZERO(smd->edge);
315}
316
317static void smd_subdev_stop(struct rproc_subdev *subdev, bool crashed)
318{
319	struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
320
321	qcom_smd_unregister_edge(smd->edge);
322	smd->edge = NULL;
323}
324
325/**
326 * qcom_add_smd_subdev() - try to add a SMD subdevice to rproc
327 * @rproc:	rproc handle to parent the subdevice
328 * @smd:	reference to a Qualcomm subdev context
329 */
330void qcom_add_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
331{
332	struct device *dev = &rproc->dev;
333
334	smd->node = of_get_child_by_name(dev->parent->of_node, "smd-edge");
335	if (!smd->node)
336		return;
337
338	smd->dev = dev;
339	smd->subdev.start = smd_subdev_start;
340	smd->subdev.stop = smd_subdev_stop;
341
342	rproc_add_subdev(rproc, &smd->subdev);
343}
344EXPORT_SYMBOL_GPL(qcom_add_smd_subdev);
345
346/**
347 * qcom_remove_smd_subdev() - remove the smd subdevice from rproc
348 * @rproc:	rproc handle
349 * @smd:	the SMD subdevice to remove
350 */
351void qcom_remove_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
352{
353	if (!smd->node)
354		return;
355
356	rproc_remove_subdev(rproc, &smd->subdev);
357	of_node_put(smd->node);
358}
359EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev);
360
361static struct qcom_ssr_subsystem *qcom_ssr_get_subsys(const char *name)
362{
363	struct qcom_ssr_subsystem *info;
364
365	mutex_lock(&qcom_ssr_subsys_lock);
366	/* Match in the global qcom_ssr_subsystem_list with name */
367	list_for_each_entry(info, &qcom_ssr_subsystem_list, list)
368		if (!strcmp(info->name, name))
369			goto out;
370
371	info = kzalloc(sizeof(*info), GFP_KERNEL);
372	if (!info) {
373		info = ERR_PTR(-ENOMEM);
374		goto out;
375	}
376	info->name = kstrdup_const(name, GFP_KERNEL);
377	srcu_init_notifier_head(&info->notifier_list);
378
379	/* Add to global notification list */
380	list_add_tail(&info->list, &qcom_ssr_subsystem_list);
381
382out:
383	mutex_unlock(&qcom_ssr_subsys_lock);
384	return info;
385}
386
387/**
388 * qcom_register_ssr_notifier() - register SSR notification handler
389 * @name:	Subsystem's SSR name
390 * @nb:		notifier_block to be invoked upon subsystem's state change
391 *
392 * This registers the @nb notifier block as part the notifier chain for a
393 * remoteproc associated with @name. The notifier block's callback
394 * will be invoked when the remote processor's SSR events occur
395 * (pre/post startup and pre/post shutdown).
396 *
397 * Return: a subsystem cookie on success, ERR_PTR on failure.
 
 
398 */
399void *qcom_register_ssr_notifier(const char *name, struct notifier_block *nb)
400{
401	struct qcom_ssr_subsystem *info;
402
403	info = qcom_ssr_get_subsys(name);
404	if (IS_ERR(info))
405		return info;
406
407	srcu_notifier_chain_register(&info->notifier_list, nb);
408
409	return &info->notifier_list;
410}
411EXPORT_SYMBOL_GPL(qcom_register_ssr_notifier);
412
413/**
414 * qcom_unregister_ssr_notifier() - unregister SSR notification handler
415 * @notify:	subsystem cookie returned from qcom_register_ssr_notifier
416 * @nb:		notifier_block to unregister
417 *
418 * This function will unregister the notifier from the particular notifier
419 * chain.
420 *
421 * Return: 0 on success, %ENOENT otherwise.
422 */
423int qcom_unregister_ssr_notifier(void *notify, struct notifier_block *nb)
424{
425	return srcu_notifier_chain_unregister(notify, nb);
426}
427EXPORT_SYMBOL_GPL(qcom_unregister_ssr_notifier);
428
429static int ssr_notify_prepare(struct rproc_subdev *subdev)
430{
431	struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev);
432	struct qcom_ssr_notify_data data = {
433		.name = ssr->info->name,
434		.crashed = false,
435	};
436
437	srcu_notifier_call_chain(&ssr->info->notifier_list,
438				 QCOM_SSR_BEFORE_POWERUP, &data);
439	return 0;
440}
441
442static int ssr_notify_start(struct rproc_subdev *subdev)
443{
444	struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev);
445	struct qcom_ssr_notify_data data = {
446		.name = ssr->info->name,
447		.crashed = false,
448	};
449
450	srcu_notifier_call_chain(&ssr->info->notifier_list,
451				 QCOM_SSR_AFTER_POWERUP, &data);
452	return 0;
453}
454
455static void ssr_notify_stop(struct rproc_subdev *subdev, bool crashed)
456{
457	struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev);
458	struct qcom_ssr_notify_data data = {
459		.name = ssr->info->name,
460		.crashed = crashed,
461	};
462
463	srcu_notifier_call_chain(&ssr->info->notifier_list,
464				 QCOM_SSR_BEFORE_SHUTDOWN, &data);
465}
466
467static void ssr_notify_unprepare(struct rproc_subdev *subdev)
468{
469	struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev);
470	struct qcom_ssr_notify_data data = {
471		.name = ssr->info->name,
472		.crashed = false,
473	};
474
475	srcu_notifier_call_chain(&ssr->info->notifier_list,
476				 QCOM_SSR_AFTER_SHUTDOWN, &data);
477}
478
479/**
480 * qcom_add_ssr_subdev() - register subdevice as restart notification source
481 * @rproc:	rproc handle
482 * @ssr:	SSR subdevice handle
483 * @ssr_name:	identifier to use for notifications originating from @rproc
484 *
485 * As the @ssr is registered with the @rproc SSR events will be sent to all
486 * registered listeners for the remoteproc when it's SSR events occur
487 * (pre/post startup and pre/post shutdown).
488 */
489void qcom_add_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr,
490			 const char *ssr_name)
491{
492	struct qcom_ssr_subsystem *info;
493
494	info = qcom_ssr_get_subsys(ssr_name);
495	if (IS_ERR(info)) {
496		dev_err(&rproc->dev, "Failed to add ssr subdevice\n");
497		return;
498	}
499
500	ssr->info = info;
501	ssr->subdev.prepare = ssr_notify_prepare;
502	ssr->subdev.start = ssr_notify_start;
503	ssr->subdev.stop = ssr_notify_stop;
504	ssr->subdev.unprepare = ssr_notify_unprepare;
505
506	rproc_add_subdev(rproc, &ssr->subdev);
507}
508EXPORT_SYMBOL_GPL(qcom_add_ssr_subdev);
509
510/**
511 * qcom_remove_ssr_subdev() - remove subdevice as restart notification source
512 * @rproc:	rproc handle
513 * @ssr:	SSR subdevice handle
514 */
515void qcom_remove_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr)
516{
517	rproc_remove_subdev(rproc, &ssr->subdev);
518	ssr->info = NULL;
519}
520EXPORT_SYMBOL_GPL(qcom_remove_ssr_subdev);
521
522MODULE_DESCRIPTION("Qualcomm Remoteproc helper driver");
523MODULE_LICENSE("GPL v2");
v4.17
 
  1/*
  2 * Qualcomm Peripheral Image Loader helpers
  3 *
  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.
  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 */
 17
 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>
 
 26
 27#include "remoteproc_internal.h"
 28#include "qcom_common.h"
 29
 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)
 33
 34static BLOCKING_NOTIFIER_HEAD(ssr_notifiers);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 35
 36static int glink_subdev_probe(struct rproc_subdev *subdev)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 37{
 38	struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
 39
 40	glink->edge = qcom_glink_smem_register(glink->dev, glink->node);
 41
 42	return PTR_ERR_OR_ZERO(glink->edge);
 43}
 44
 45static void glink_subdev_remove(struct rproc_subdev *subdev, bool crashed)
 46{
 47	struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
 48
 49	qcom_glink_smem_unregister(glink->edge);
 50	glink->edge = NULL;
 51}
 52
 
 
 
 
 
 
 
 53/**
 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
 
 57 */
 58void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink)
 
 59{
 60	struct device *dev = &rproc->dev;
 61
 62	glink->node = of_get_child_by_name(dev->parent->of_node, "glink-edge");
 63	if (!glink->node)
 64		return;
 65
 
 
 
 
 66	glink->dev = dev;
 67	rproc_add_subdev(rproc, &glink->subdev, glink_subdev_probe, glink_subdev_remove);
 
 
 
 
 68}
 69EXPORT_SYMBOL_GPL(qcom_add_glink_subdev);
 70
 71/**
 72 * qcom_remove_glink_subdev() - remove a GLINK subdevice from rproc
 73 * @rproc:	rproc handle
 74 * @glink:	reference to a GLINK subdev context
 75 */
 76void qcom_remove_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink)
 77{
 78	if (!glink->node)
 79		return;
 80
 81	rproc_remove_subdev(rproc, &glink->subdev);
 
 82	of_node_put(glink->node);
 83}
 84EXPORT_SYMBOL_GPL(qcom_remove_glink_subdev);
 85
 86/**
 87 * qcom_register_dump_segments() - register segments for coredump
 88 * @rproc:	remoteproc handle
 89 * @fw:		firmware header
 90 *
 91 * Register all segments of the ELF in the remoteproc coredump segment list
 92 *
 93 * Return: 0 on success, negative errno on failure.
 94 */
 95int qcom_register_dump_segments(struct rproc *rproc,
 96				const struct firmware *fw)
 97{
 98	const struct elf32_phdr *phdrs;
 99	const struct elf32_phdr *phdr;
100	const struct elf32_hdr *ehdr;
101	int ret;
102	int i;
103
104	ehdr = (struct elf32_hdr *)fw->data;
105	phdrs = (struct elf32_phdr *)(ehdr + 1);
106
107	for (i = 0; i < ehdr->e_phnum; i++) {
108		phdr = &phdrs[i];
109
110		if (phdr->p_type != PT_LOAD)
111			continue;
112
113		if ((phdr->p_flags & QCOM_MDT_TYPE_MASK) == QCOM_MDT_TYPE_HASH)
114			continue;
115
116		if (!phdr->p_memsz)
117			continue;
118
119		ret = rproc_coredump_add_segment(rproc, phdr->p_paddr,
120						 phdr->p_memsz);
121		if (ret)
122			return ret;
123	}
124
125	return 0;
126}
127EXPORT_SYMBOL_GPL(qcom_register_dump_segments);
128
129static int smd_subdev_probe(struct rproc_subdev *subdev)
130{
131	struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
132
133	smd->edge = qcom_smd_register_edge(smd->dev, smd->node);
134
135	return PTR_ERR_OR_ZERO(smd->edge);
136}
137
138static void smd_subdev_remove(struct rproc_subdev *subdev, bool crashed)
139{
140	struct qcom_rproc_subdev *smd = to_smd_subdev(subdev);
141
142	qcom_smd_unregister_edge(smd->edge);
143	smd->edge = NULL;
144}
145
146/**
147 * qcom_add_smd_subdev() - try to add a SMD subdevice to rproc
148 * @rproc:	rproc handle to parent the subdevice
149 * @smd:	reference to a Qualcomm subdev context
150 */
151void qcom_add_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
152{
153	struct device *dev = &rproc->dev;
154
155	smd->node = of_get_child_by_name(dev->parent->of_node, "smd-edge");
156	if (!smd->node)
157		return;
158
159	smd->dev = dev;
160	rproc_add_subdev(rproc, &smd->subdev, smd_subdev_probe, smd_subdev_remove);
 
 
 
161}
162EXPORT_SYMBOL_GPL(qcom_add_smd_subdev);
163
164/**
165 * qcom_remove_smd_subdev() - remove the smd subdevice from rproc
166 * @rproc:	rproc handle
167 * @smd:	the SMD subdevice to remove
168 */
169void qcom_remove_smd_subdev(struct rproc *rproc, struct qcom_rproc_subdev *smd)
170{
171	if (!smd->node)
172		return;
173
174	rproc_remove_subdev(rproc, &smd->subdev);
175	of_node_put(smd->node);
176}
177EXPORT_SYMBOL_GPL(qcom_remove_smd_subdev);
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179/**
180 * qcom_register_ssr_notifier() - register SSR notification handler
181 * @nb:		notifier_block to notify for restart notifications
 
182 *
183 * Returns 0 on success, negative errno on failure.
 
 
 
184 *
185 * This register the @notify function as handler for restart notifications. As
186 * remote processors are stopped this function will be called, with the SSR
187 * name passed as a parameter.
188 */
189int qcom_register_ssr_notifier(struct notifier_block *nb)
190{
191	return blocking_notifier_chain_register(&ssr_notifiers, nb);
 
 
 
 
 
 
 
 
192}
193EXPORT_SYMBOL_GPL(qcom_register_ssr_notifier);
194
195/**
196 * qcom_unregister_ssr_notifier() - unregister SSR notification handler
 
197 * @nb:		notifier_block to unregister
 
 
 
 
 
198 */
199void qcom_unregister_ssr_notifier(struct notifier_block *nb)
200{
201	blocking_notifier_chain_unregister(&ssr_notifiers, nb);
202}
203EXPORT_SYMBOL_GPL(qcom_unregister_ssr_notifier);
204
 
 
 
 
 
 
 
 
 
 
 
 
 
205static int ssr_notify_start(struct rproc_subdev *subdev)
206{
207	return  0;
 
 
 
 
 
 
 
 
208}
209
210static void ssr_notify_stop(struct rproc_subdev *subdev, bool crashed)
211{
212	struct qcom_rproc_ssr *ssr = to_ssr_subdev(subdev);
 
 
 
 
213
214	blocking_notifier_call_chain(&ssr_notifiers, 0, (void *)ssr->name);
 
 
 
 
 
 
 
 
 
 
 
 
 
215}
216
217/**
218 * qcom_add_ssr_subdev() - register subdevice as restart notification source
219 * @rproc:	rproc handle
220 * @ssr:	SSR subdevice handle
221 * @ssr_name:	identifier to use for notifications originating from @rproc
222 *
223 * As the @ssr is registered with the @rproc SSR events will be sent to all
224 * registered listeners in the system as the remoteproc is shut down.
 
225 */
226void qcom_add_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr,
227			 const char *ssr_name)
228{
229	ssr->name = ssr_name;
 
 
 
 
 
 
 
 
 
 
 
 
230
231	rproc_add_subdev(rproc, &ssr->subdev, ssr_notify_start, ssr_notify_stop);
232}
233EXPORT_SYMBOL_GPL(qcom_add_ssr_subdev);
234
235/**
236 * qcom_remove_ssr_subdev() - remove subdevice as restart notification source
237 * @rproc:	rproc handle
238 * @ssr:	SSR subdevice handle
239 */
240void qcom_remove_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr)
241{
242	rproc_remove_subdev(rproc, &ssr->subdev);
 
243}
244EXPORT_SYMBOL_GPL(qcom_remove_ssr_subdev);
245
246MODULE_DESCRIPTION("Qualcomm Remoteproc helper driver");
247MODULE_LICENSE("GPL v2");