From patchwork Tue Dec 26 20:38:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 122753 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1390272qgn; Tue, 26 Dec 2017 12:39:36 -0800 (PST) X-Google-Smtp-Source: ACJfBotbt7YYeTLAA5Q46VDpdKi03JptuXPnrkQ+5NbCDqC3jMjG1SWUQKPK/TZvArG6gB0IeNj5 X-Received: by 10.98.9.79 with SMTP id e76mr26459096pfd.70.1514320775957; Tue, 26 Dec 2017 12:39:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514320775; cv=none; d=google.com; s=arc-20160816; b=LiGtTeSNV/+/lAPBt/qFeYb2oJe15PjFA7Grk4lPmQ/wALKD2LjB/fc/qlRLdU1uy7 8gazDT6CBpDqzU045xW9mGt56KoHgl+w1s4pJNBsbsEBfkgE4432exrZzWd9H512BGDi HXUwHk9gzKZu6ZCPQ4RXqiC8QAXoovLrqqfInnqYLxVPn51JlOcp0iT401xOSKV0t7LM 9PS+ihTeO0JJv+yJnz5acfaWUcuC2N6aGv/9l9VIMs1BsGqFAXOLGMV2kqQ4lXeVImbW i0Nl1drtEc4abndm78q72CjR56UZt0O9Pgam+j8OHPuh5jVsW6ncSjPm4ngRTOE7kkd7 Ahmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=TkDhgV6/w8s3ue3AVSqokr6iOrammkAD8ZdGUI9XO+I=; b=fnFtnpI019tnJ5fC94w/laamNkIYJO3pn9gUcjr9XoTSOP6WlzCeJNEdee66/pTV3P pGTUt4vjr4loITgc1YsC3C3y5NJSt7NGrjQKlH1flidMQVAKSxLUPELVx9GOsOe1ghmi pKhNYoJsgucaDxxR0i5BmYr4O4qjtjxNif29NYkaDPf7sx2ZnUdXTqX7sk89vH/ab04r raXyarc9FTykbK67MvuGO6o2XSYgZ1JfPSt1tLcO9nXtjkMsObX6YYQctSxwh3I5WCZ/ H7OYn1Z9Cyo5XV3tyiyZEhJ5pAWwiFJziOeKxWIFXWtL2tFb5sX5BCDCh/l0VBdvlK7C 01Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dt8SiZs9; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si23686322pfl.63.2017.12.26.12.39.35; Tue, 26 Dec 2017 12:39:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dt8SiZs9; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751467AbdLZUje (ORCPT + 10 others); Tue, 26 Dec 2017 15:39:34 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:32848 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751220AbdLZUih (ORCPT ); Tue, 26 Dec 2017 15:38:37 -0500 Received: by mail-pf0-f193.google.com with SMTP id y89so19058076pfk.0 for ; Tue, 26 Dec 2017 12:38:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GID84wUKoSZY9877w/R3D7KzfNyr3j31muYokwcu6b0=; b=dt8SiZs9fbP3SbrglHcqwTYwDy9hylK0agmEVCMW439E6YuY0LBl2kFUkeowCcJm1o iSrIBYeM4WuUEYaqfyz7gzQ0gVT2MrCAGExPvfFHkEESJWHRcg8Ptp9OcCQh5c3W9j/X nYzh/fTu78FFIGHes3GoKHUQvdHW+rprGrliQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GID84wUKoSZY9877w/R3D7KzfNyr3j31muYokwcu6b0=; b=JfPGJ0BQLLeFZjFaH5loo3r5BCSG519vTpBfq1Fu3NaWHETeuDFa58L/Ymb7ypYiQ9 TjOuGhK2gb28c/HuQJRgLcPLEpkOBXWEIsvtrEbofVn3wx5Bpr14hF4jPpFvAIaHxqi0 O9AIpCU9dz1LGsrtNCIl9le+3uT15LikEgzp5LwHn1Juiu/38WBmqurJ6hPe7b528DWl r3ZJfFG+a0DyOzv8jPPlf0WcDQNiMMrdBv4qFWbGgyDYNgtS+4Hu9cqJtqiopz7RPX23 kkQJoQ7IQMvEeDY1Tjz963bsNB/BjdjVrdl9M5d6XxpkdrIjyk7BPuR1oUW9b60YdnMf 8AYA== X-Gm-Message-State: AKGB3mJE3LPTsile22JMdu8NZhryODqeLG7l0SiiCRGJDjFPyVHpH4NX IdGX4b8j7um0xGr579GlPtDjcA== X-Received: by 10.99.105.134 with SMTP id e128mr22944896pgc.152.1514320717075; Tue, 26 Dec 2017 12:38:37 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id 68sm58746339pfx.186.2017.12.26.12.38.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Dec 2017 12:38:36 -0800 (PST) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, Suman Anna , Avaneesh Kumar Dwivedi Subject: [PATCH v2 1/4] remoteproc: Add remote processor coredump support Date: Tue, 26 Dec 2017 12:38:29 -0800 Message-Id: <20171226203832.14928-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171226203832.14928-1-bjorn.andersson@linaro.org> References: <20171226203832.14928-1-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Sarangdhar Joshi As the remoteproc framework restarts the remote processor after a fatal event, it's useful to be able to acquire a coredump of the remote processor's state, for post mortem debugging. This patch introduces a mechanism for extracting the memory contents after the remote has stopped and before the restart sequence has begun in the recovery path. The remoteproc framework builds the core dump in memory and use devcoredump to expose this to user space. Signed-off-by: Sarangdhar Joshi [bjorn: Use vmalloc instead of composing the ELF on the fly] Signed-off-by: Bjorn Andersson --- Changes since v1: - vmalloc() memory to build ELF file before registering devcoredump - life cycle of segment list is from boot to shutdown (not start/shutdown) - add WANT_DEV_COREDUMP select - use dma_addr_t to denote device addresses drivers/remoteproc/Kconfig | 1 + drivers/remoteproc/remoteproc_core.c | 128 +++++++++++++++++++++++++++++++++++ include/linux/remoteproc.h | 18 +++++ 3 files changed, 147 insertions(+) -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig index b609e1d3654b..3e4bca77188d 100644 --- a/drivers/remoteproc/Kconfig +++ b/drivers/remoteproc/Kconfig @@ -6,6 +6,7 @@ config REMOTEPROC select CRC32 select FW_LOADER select VIRTIO + select WANT_DEV_COREDUMP help Support for remote processors (such as DSP coprocessors). These are mainly used on embedded systems. diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 4170dfbd93bd..5af7547b9d8d 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -801,6 +802,20 @@ static void rproc_remove_subdevices(struct rproc *rproc) subdev->remove(subdev); } +/** + * rproc_coredump_cleanup() - clean up dump_segments list + * @rproc: the remote processor handle + */ +static void rproc_coredump_cleanup(struct rproc *rproc) +{ + struct rproc_dump_segment *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, &rproc->dump_segments, node) { + list_del(&entry->node); + kfree(entry); + } +} + /** * rproc_resource_cleanup() - clean up and free all acquired resources * @rproc: rproc handle @@ -848,6 +863,8 @@ static void rproc_resource_cleanup(struct rproc *rproc) /* clean up remote vdev entries */ list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node) kref_put(&rvdev->refcount, rproc_vdev_release); + + rproc_coredump_cleanup(rproc); } static int rproc_start(struct rproc *rproc, const struct firmware *fw) @@ -1017,6 +1034,113 @@ static int rproc_stop(struct rproc *rproc) return 0; } +/** + * rproc_coredump_add_segment() - add segment of device memory to coredump + * @rproc: handle of a remote processor + * @da: device address + * @size: size of segment + * + * Add device memory to the list of segments to be included in a coredump for + * the remoteproc. + * + * Return: 0 on success, negative errno on error. + */ +int rproc_coredump_add_segment(struct rproc *rproc, dma_addr_t da, size_t size) +{ + struct rproc_dump_segment *segment; + + segment = kzalloc(sizeof(*segment), GFP_KERNEL); + if (!segment) + return -ENOMEM; + + segment->da = da; + segment->size = size; + + list_add_tail(&segment->node, &rproc->dump_segments); + + return 0; +} +EXPORT_SYMBOL(rproc_coredump_add_segment); + +/** + * rproc_coredump() - perform coredump + * @rproc: rproc handle + * + * This function will generate an ELF header for the registered segments + * and create a devcoredump device associated with rproc. + */ +static void rproc_coredump(struct rproc *rproc) +{ + struct rproc_dump_segment *segment; + struct elf32_phdr *phdr; + struct elf32_hdr *ehdr; + size_t data_size; + size_t offset; + void *data; + void *ptr; + int phnum = 0; + + if (list_empty(&rproc->dump_segments)) + return; + + data_size = sizeof(*ehdr); + list_for_each_entry(segment, &rproc->dump_segments, node) { + data_size += sizeof(*phdr) + segment->size; + + phnum++; + } + + data = vmalloc(data_size); + if (!data) + return; + + ehdr = data; + + memset(ehdr, 0, sizeof(*ehdr)); + memcpy(ehdr->e_ident, ELFMAG, SELFMAG); + ehdr->e_ident[EI_CLASS] = ELFCLASS32; + ehdr->e_ident[EI_DATA] = ELFDATA2LSB; + ehdr->e_ident[EI_VERSION] = EV_CURRENT; + ehdr->e_ident[EI_OSABI] = ELFOSABI_NONE; + ehdr->e_type = ET_CORE; + ehdr->e_machine = EM_NONE; + ehdr->e_version = EV_CURRENT; + ehdr->e_entry = rproc->bootaddr; + ehdr->e_phoff = sizeof(*ehdr); + ehdr->e_ehsize = sizeof(*ehdr); + ehdr->e_phentsize = sizeof(*phdr); + ehdr->e_phnum = phnum; + + phdr = data + ehdr->e_phoff; + offset = ehdr->e_phoff + sizeof(*phdr) * ehdr->e_phnum; + list_for_each_entry(segment, &rproc->dump_segments, node) { + memset(phdr, 0, sizeof(*phdr)); + phdr->p_type = PT_LOAD; + phdr->p_offset = offset; + phdr->p_vaddr = segment->da; + phdr->p_paddr = segment->da; + phdr->p_filesz = segment->size; + phdr->p_memsz = segment->size; + phdr->p_flags = PF_R | PF_W | PF_X; + phdr->p_align = 0; + + ptr = rproc_da_to_va(rproc, segment->da, segment->size); + if (!ptr) { + dev_err(&rproc->dev, + "invalid coredump segment (%pad, %zu)\n", + &segment->da, segment->size); + memset(data + offset, 0xff, segment->size); + } else { + memcpy(data + offset, ptr, segment->size); + } + + offset += phdr->p_filesz; + phdr++; + } + + dev_coredumpv(&rproc->dev, data, data_size, GFP_KERNEL); +} + /** * rproc_trigger_recovery() - recover a remoteproc * @rproc: the remote processor @@ -1043,6 +1167,9 @@ int rproc_trigger_recovery(struct rproc *rproc) if (ret) goto unlock_mutex; + /* generate coredump */ + rproc_coredump(rproc); + /* load firmware */ ret = request_firmware(&firmware_p, rproc->firmware, dev); if (ret < 0) { @@ -1443,6 +1570,7 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, INIT_LIST_HEAD(&rproc->traces); INIT_LIST_HEAD(&rproc->rvdevs); INIT_LIST_HEAD(&rproc->subdevs); + INIT_LIST_HEAD(&rproc->dump_segments); INIT_WORK(&rproc->crash_handler, rproc_crash_handler_work); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 32a3bf351919..de6e20a3f061 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -393,6 +393,21 @@ enum rproc_crash_type { RPROC_FATAL_ERROR, }; +/** + * struct rproc_dump_segment - segment info from ELF header + * @node: list node related to the rproc segment list + * @da: device address of the segment + * @size: size of the segment + */ +struct rproc_dump_segment { + struct list_head node; + + dma_addr_t da; + size_t size; + + loff_t offset; +}; + /** * struct rproc - represents a physical remote processor device * @node: list node of this rproc object @@ -423,6 +438,7 @@ enum rproc_crash_type { * @cached_table: copy of the resource table * @table_sz: size of @cached_table * @has_iommu: flag to indicate if remote processor is behind an MMU + * @dump_segments: list of segments in the firmware */ struct rproc { struct list_head node; @@ -454,6 +470,7 @@ struct rproc { size_t table_sz; bool has_iommu; bool auto_boot; + struct list_head dump_segments; }; /** @@ -533,6 +550,7 @@ void rproc_free(struct rproc *rproc); int rproc_boot(struct rproc *rproc); void rproc_shutdown(struct rproc *rproc); void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type); +int rproc_coredump_add_segment(struct rproc *rproc, dma_addr_t da, size_t size); static inline struct rproc_vdev *vdev_to_rvdev(struct virtio_device *vdev) { From patchwork Tue Dec 26 20:38:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 122750 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1389708qgn; Tue, 26 Dec 2017 12:38:49 -0800 (PST) X-Google-Smtp-Source: ACJfBou35Dknc391hpHw7bFTFm/qt2nQt4S3n43OHYVgxnGUnOFir1Wfuyn6NNY6P9YiZuTGeSoN X-Received: by 10.99.96.3 with SMTP id u3mr23496199pgb.121.1514320729177; Tue, 26 Dec 2017 12:38:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514320729; cv=none; d=google.com; s=arc-20160816; b=myUOn14FRESB9rZTlQKStvOJH4W5NvnIkaTXjoVyFFXRK9bO8h2+W8xoO/iB3JQ8Km GU6FZMtJF05CvcBUVr6jA30MHcbl9vbGg+xuvBV7MUmTGwEE/mziO80mxMyhWNvFi0fG N7vQQUihAF1/26gu7W0idmysSrvn7CL0WVTpTj9+1G+xgDySaTJGnlcgRZYlUclprwdQ E/oAVJZ3GPi8c2SQ8M/KQ+oqCFBblVkZbkIMMepw7xQ/XqjMRVjuaHKvq53r2OYBLOQT QlGu8EkhD3Itf8NIIMIqMTgtRDRqaF4iWHvBzFFm5p6JY9Ym3SbpzyB+3wachAQlW1vz rI7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=2a15B4EvdS3zBvJXwG6jmaqWjMVvTbmODcqIhP5q1JM=; b=ZiwVz8gpTkk/U7t48qPx4vCdJCC5DmRyWKJx9i8X/UxmE0kEs+tUnA2lcK53thPBWM 3ZJfWt1XrR/r1EShkxGx+qD/gTjsppz7tP0BEHH9lyp0KbpVATsfzRcYMpZtD5PSIppm ajwtlaUzRH/BG1rC1uvYXBMkH5ROwqLhUwOYZCa9UKMEGasjh9OTGKlCOPIM8RM0X/C+ k0zPao0paCJ7Dh1xPaIwwcj2uurR4/CAoo7E+kee4Yczs2jxCk/+Zu+qqvC0IYujvCBM k/JPeCDQ2Jgd1YF6sSuOCf0Oncpo1wpgE/kO2S0HP1LeiGTF/OvKGYQ3Qw+OGO5V+cD2 pBtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=aHhFoG2D; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3si21159528pgs.84.2017.12.26.12.38.48; Tue, 26 Dec 2017 12:38:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=aHhFoG2D; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751453AbdLZUim (ORCPT + 10 others); Tue, 26 Dec 2017 15:38:42 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:44664 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751143AbdLZUik (ORCPT ); Tue, 26 Dec 2017 15:38:40 -0500 Received: by mail-pl0-f67.google.com with SMTP id n13so18378358plp.11 for ; Tue, 26 Dec 2017 12:38:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GUnlnT0KUFrrdhSX74OBc/u369q62LIIdYojViR7Bq0=; b=aHhFoG2DXv4DnUByzjXwsdvN4vmIvfgO2iN2I1PAyhK/tUsAohTOKhEVu7TC4jZdFN oKnYa4t8VTHQLFIX3vudA4h1Nu/hwHqx42fAhxrUrTFEhi0JxWCvX69Lvy9Nms0+mwfh XnJJe6qe6iD7K10Ty7jVd3+qf32rq4HzYHZ1I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GUnlnT0KUFrrdhSX74OBc/u369q62LIIdYojViR7Bq0=; b=lMBJqh2xVD/joiPzRC5D3s/fcKMBK4Eic1qDlLrOWhcaE6VA71Ie2AyN5TlzhHf6ik ChboCvvLXSxGHJoqt9SF2JH2r8uFpV+YSPgqoidkRTf7I7JJgoUgBRFg7UnwI/H9xH+K sLYsWhnwRKcsd4MoGkfy4MkvvFEIFQUHlR02R7n+kzvFesntKuLLf5NyoFwGRzPWBUtE pkJTIIyY7VjNGkC9CQtmGRtK+QEe+u4sRQBPRAh3t2pTK4gXABAfGXbQfc6l2Wr/Lcmo v3SSmvrDY6pULRG0SIbMvZk1BDG6CuwWimhgfbgpECfePmLMj661KfJuOfCdiBuFKnPJ 3bjA== X-Gm-Message-State: AKGB3mKmzOMjQ/Z99yenQHv+GWl8sbZXCUhkXe1R0pWkVKpmQ/N4vKvr 2j5Op0KofDwymn/FBbmnxoUZ4w== X-Received: by 10.159.198.1 with SMTP id f1mr26258497plo.450.1514320719675; Tue, 26 Dec 2017 12:38:39 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id 68sm58746339pfx.186.2017.12.26.12.38.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Dec 2017 12:38:38 -0800 (PST) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson , Andy Gross Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Suman Anna , Avaneesh Kumar Dwivedi , Rob Clark , Stanimir Varbanov , linux-soc@vger.kernel.org Subject: [PATCH v2 3/4] soc: qcom: mdt-loader: Return relocation base Date: Tue, 26 Dec 2017 12:38:31 -0800 Message-Id: <20171226203832.14928-4-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171226203832.14928-1-bjorn.andersson@linaro.org> References: <20171226203832.14928-1-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org In order to implement support for grabbing core dumps in remoteproc it's necessary to know the relocated base of the image, as the offsets from the virtual memory base might not be based on the physical address. Return the adjusted physical base address to the caller. Signed-off-by: Bjorn Andersson --- Changes since v1: - New patch drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 4 ++-- drivers/media/platform/qcom/venus/firmware.c | 2 +- drivers/remoteproc/qcom_adsp_pil.c | 4 +++- drivers/remoteproc/qcom_wcnss.c | 3 ++- drivers/soc/qcom/mdt_loader.c | 7 ++++++- include/linux/soc/qcom/mdt_loader.h | 3 ++- 6 files changed, 16 insertions(+), 7 deletions(-) -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c index a1f4eeeb73e2..3cab1c74df84 100644 --- a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c @@ -87,14 +87,14 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname) */ if (to_adreno_gpu(gpu)->fwloc == FW_LOCATION_LEGACY) { ret = qcom_mdt_load(dev, fw, fwname, GPU_PAS_ID, - mem_region, mem_phys, mem_size); + mem_region, mem_phys, mem_size, NULL); } else { char newname[strlen("qcom/") + strlen(fwname) + 1]; sprintf(newname, "qcom/%s", fwname); ret = qcom_mdt_load(dev, fw, newname, GPU_PAS_ID, - mem_region, mem_phys, mem_size); + mem_region, mem_phys, mem_size, NULL); } if (ret) goto out; diff --git a/drivers/media/platform/qcom/venus/firmware.c b/drivers/media/platform/qcom/venus/firmware.c index 521d4b36c090..c4a577848dd7 100644 --- a/drivers/media/platform/qcom/venus/firmware.c +++ b/drivers/media/platform/qcom/venus/firmware.c @@ -76,7 +76,7 @@ int venus_boot(struct device *dev, const char *fwname) } ret = qcom_mdt_load(dev, mdt, fwname, VENUS_PAS_ID, mem_va, mem_phys, - mem_size); + mem_size, NULL); release_firmware(mdt); diff --git a/drivers/remoteproc/qcom_adsp_pil.c b/drivers/remoteproc/qcom_adsp_pil.c index 373c167892d7..833763aa3f2a 100644 --- a/drivers/remoteproc/qcom_adsp_pil.c +++ b/drivers/remoteproc/qcom_adsp_pil.c @@ -82,7 +82,9 @@ static int adsp_load(struct rproc *rproc, const struct firmware *fw) struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; return qcom_mdt_load(adsp->dev, fw, rproc->firmware, adsp->pas_id, - adsp->mem_region, adsp->mem_phys, adsp->mem_size); + adsp->mem_region, adsp->mem_phys, adsp->mem_size, + &adsp->mem_reloc); + } static int adsp_start(struct rproc *rproc) diff --git a/drivers/remoteproc/qcom_wcnss.c b/drivers/remoteproc/qcom_wcnss.c index 3f0609236a76..599c1aa73b7f 100644 --- a/drivers/remoteproc/qcom_wcnss.c +++ b/drivers/remoteproc/qcom_wcnss.c @@ -153,7 +153,8 @@ static int wcnss_load(struct rproc *rproc, const struct firmware *fw) struct qcom_wcnss *wcnss = (struct qcom_wcnss *)rproc->priv; return qcom_mdt_load(wcnss->dev, fw, rproc->firmware, WCNSS_PAS_ID, - wcnss->mem_region, wcnss->mem_phys, wcnss->mem_size); + wcnss->mem_region, wcnss->mem_phys, + wcnss->mem_size, &wcnss->mem_reloc); } static void wcnss_indicate_nv_download(struct qcom_wcnss *wcnss) diff --git a/drivers/soc/qcom/mdt_loader.c b/drivers/soc/qcom/mdt_loader.c index 08bd8549242a..17b314d9a148 100644 --- a/drivers/soc/qcom/mdt_loader.c +++ b/drivers/soc/qcom/mdt_loader.c @@ -83,12 +83,14 @@ EXPORT_SYMBOL_GPL(qcom_mdt_get_size); * @mem_region: allocated memory region to load firmware into * @mem_phys: physical address of allocated memory region * @mem_size: size of the allocated memory region + * @reloc_base: adjusted physical address after relocation * * Returns 0 on success, negative errno otherwise. */ int qcom_mdt_load(struct device *dev, const struct firmware *fw, const char *firmware, int pas_id, void *mem_region, - phys_addr_t mem_phys, size_t mem_size) + phys_addr_t mem_phys, size_t mem_size, + phys_addr_t *reloc_base) { const struct elf32_phdr *phdrs; const struct elf32_phdr *phdr; @@ -192,6 +194,9 @@ int qcom_mdt_load(struct device *dev, const struct firmware *fw, memset(ptr + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz); } + if (reloc_base) + *reloc_base = mem_reloc; + out: kfree(fw_name); diff --git a/include/linux/soc/qcom/mdt_loader.h b/include/linux/soc/qcom/mdt_loader.h index bd8e0864b059..5b98bbdabc25 100644 --- a/include/linux/soc/qcom/mdt_loader.h +++ b/include/linux/soc/qcom/mdt_loader.h @@ -14,6 +14,7 @@ struct firmware; ssize_t qcom_mdt_get_size(const struct firmware *fw); int qcom_mdt_load(struct device *dev, const struct firmware *fw, const char *fw_name, int pas_id, void *mem_region, - phys_addr_t mem_phys, size_t mem_size); + phys_addr_t mem_phys, size_t mem_size, + phys_addr_t *reloc_base); #endif