Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4313731ybv; Mon, 10 Feb 2020 16:54:25 -0800 (PST) X-Google-Smtp-Source: APXvYqzAO/9miil8T+NzOabRCYA8vPyxqKIMH9HUH4ElCLuiaYLeyEdYvXawNN5aU+hxDmhY5XFd X-Received: by 2002:a05:6830:110a:: with SMTP id w10mr3316124otq.300.1581382465190; Mon, 10 Feb 2020 16:54:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581382465; cv=none; d=google.com; s=arc-20160816; b=M+M9yLVo/0ozNUk66Z9HnpD4y/zhCiwMps1laH2m8wUTkb0E401ZRMfWb6xCrhoOVH WnN7SVdWymSzN4tASBEA8+4c2PmPZlLhJzAaEe7V2GZLqnhXRWsS5jn3m/MXfNTFeeSg H648vDA8EW2De9dWJxB50ZglwHI+ZPTqzSkZVMVkhJCIpK5CnsQWXK3DLSsqEOsBbDvZ p6sgGFYhqqBN7ghCkne5tszGpSMBr5/TMeKB3NoijRiEtMQmRXVNNjGYd6JRb3u/2vt5 uUmz0rqO2xByu5q85LsjZBqyQUSAESaYMAztoFezr4nnkKVnLJttX9KPJTsLtuzQrUK3 UN0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ydVhHnWQ0HLgMTFUIhwtCaw9X4iLwegWCzrRdrC4PNM=; b=R6MjFnPIrDLXqM0b6FaTcs8CMf1jgV9oL2LJNDTJfUCj48WpmPlnlbTWe1V6/Xtb1M tGhIcS2QO9bTnUrfGdBgxhq5ApG7NRoyy4K21O73XQzYQmj9476ImVz4nKnfV04Jf69M TWAqsxWrW4A7Z3/KPCO7fIWjsvnPWpodrbpZQ63HRRpDVbqWgs5daSwATIP5S9r9OZfU 99/R17S8SRRoD7UDFxNSJIvYrrsVhD+c8y2PWaldqpNcw4IJQlsnSGXmvw1UJGWa1jAz wyAl2AYNN5hGTNm4hYERGxSwQ/xPv4QC6/EmNrnrBapwucmiOSD96E3W6jiEjdsgxekZ +Zvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PZDbyeYw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 q5si1075256otc.104.2020.02.10.16.54.11; Mon, 10 Feb 2020 16:54:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PZDbyeYw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727836AbgBKAwq (ORCPT + 99 others); Mon, 10 Feb 2020 19:52:46 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42669 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727599AbgBKAwM (ORCPT ); Mon, 10 Feb 2020 19:52:12 -0500 Received: by mail-pl1-f193.google.com with SMTP id e8so3519068plt.9 for ; Mon, 10 Feb 2020 16:52:12 -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 :mime-version:content-transfer-encoding; bh=ydVhHnWQ0HLgMTFUIhwtCaw9X4iLwegWCzrRdrC4PNM=; b=PZDbyeYwSRrVYyQgLk9W66oGcfWhJofwkWszGstL1FDQWe9K2WvtQxQZeNsaoTkS7i WwrjzIyFdnpbxs0XidqutKEGXBIDo+6h4LkGXVGgrOUiTs/3qhNEA7V/j5IpGmsjzQF2 iOd5uESII0B+orQiQToYaFkSU6a4UtelaUpp82xUCG27bQJaL0LpJ5slk/Tleg5+MyqU 9UEDYLQ8C5TcQG+k3Dr4EwZHXVfmy9nmLqjDKVhxsXMeh+7zE6rPj5CdB6QWqSirWwe2 faV0P8cOt+8qa22hTe8pai+iSR7hIrRURWEwRi2a66vPCYNmMg6tIXZTz2yu3V/1CF11 piqg== 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:mime-version:content-transfer-encoding; bh=ydVhHnWQ0HLgMTFUIhwtCaw9X4iLwegWCzrRdrC4PNM=; b=b9dzqcXPm14RlOLZKeUf3FbS/90LJ32w/h5jiCeZWqDaLprbQGqvIAyES2k11Fk/nX G7e7QZWorLNRj+BOJ67F1vfjWT27bcNDr/KiqnUURCyvW1wZznc1CoxQv37vq9RQSb/Z JKog4YJsvoYE0+c3AVuYLqXGlhlA/rwaHTmDvQVAqjDAgZ+2IrsTH8T4XSrdvo1otdoC OG3ACn7ZUxN7oK5lOkbYoR4KT5wA6Uj4hNDT4z7x6sxqAktpnDT15iHDnrk9bTkegZ9e AY7Cj200c1+n4FkbhwZ6yLnM3nFoB03ZhS/ow8s3vrKCgufKxg7ryqeWypHoBMi1kqs4 9AqA== X-Gm-Message-State: APjAAAW70ttAHcSw2jgQx48ALUaVIO2Z13jMb1LihmUeopAa1nIQyTRr Wb0eMnnpxJ5i2LLThlbBA33pXg== X-Received: by 2002:a17:902:b682:: with SMTP id c2mr625237pls.127.1581382331559; Mon, 10 Feb 2020 16:52:11 -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 q21sm1538480pff.105.2020.02.10.16.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 16:52:10 -0800 (PST) From: Bjorn Andersson To: Bjorn Andersson , Ohad Ben-Cohen Cc: Andy Gross , Rob Herring , Mark Rutland , linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sibi Sankar , Rishabh Bhatnagar Subject: [PATCH v3 2/8] remoteproc: qcom: Introduce driver to store pil info in IMEM Date: Mon, 10 Feb 2020 16:50:53 -0800 Message-Id: <20200211005059.1377279-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200211005059.1377279-1-bjorn.andersson@linaro.org> References: <20200211005059.1377279-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A region in IMEM is used to communicate load addresses of remoteproc to post mortem debug tools. Implement a driver that can be used to store this information in order to enable these tools to process collected ramdumps. Signed-off-by: Bjorn Andersson --- Changes since v2: - Sorted includes - Replace use of stracpy (still not landed upstream) - Fixed error handling in probe - Return error from store, to allow clients to decide action - Replace hard coded size with value read from reg property drivers/remoteproc/Kconfig | 3 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/qcom_pil_info.c | 168 +++++++++++++++++++++++++++++ drivers/remoteproc/qcom_pil_info.h | 8 ++ 4 files changed, 180 insertions(+) create mode 100644 drivers/remoteproc/qcom_pil_info.c create mode 100644 drivers/remoteproc/qcom_pil_info.h diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig index de3862c15fcc..20c8194e610e 100644 --- a/drivers/remoteproc/Kconfig +++ b/drivers/remoteproc/Kconfig @@ -95,6 +95,9 @@ config KEYSTONE_REMOTEPROC It's safe to say N here if you're not interested in the Keystone DSPs or just want to use a bare minimum kernel. +config QCOM_PIL_INFO + tristate + config QCOM_RPROC_COMMON tristate diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile index e30a1b15fbac..2ab32bd41b44 100644 --- a/drivers/remoteproc/Makefile +++ b/drivers/remoteproc/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o obj-$(CONFIG_WKUP_M3_RPROC) += wkup_m3_rproc.o obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.o obj-$(CONFIG_KEYSTONE_REMOTEPROC) += keystone_remoteproc.o +obj-$(CONFIG_QCOM_PIL_INFO) += qcom_pil_info.o obj-$(CONFIG_QCOM_RPROC_COMMON) += qcom_common.o obj-$(CONFIG_QCOM_Q6V5_COMMON) += qcom_q6v5.o obj-$(CONFIG_QCOM_Q6V5_ADSP) += qcom_q6v5_adsp.o diff --git a/drivers/remoteproc/qcom_pil_info.c b/drivers/remoteproc/qcom_pil_info.c new file mode 100644 index 000000000000..398aeb957f3c --- /dev/null +++ b/drivers/remoteproc/qcom_pil_info.c @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2019-2020 Linaro Ltd. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#define PIL_RELOC_NAME_LEN 8 + +struct pil_reloc_entry { + char name[PIL_RELOC_NAME_LEN]; + __le64 base; + __le32 size; +} __packed; + +struct pil_reloc { + struct device *dev; + struct regmap *map; + size_t offset; + size_t num_entries; + int val_bytes; + + struct pil_reloc_entry entries[]; +}; + +static struct pil_reloc *_reloc; +static DEFINE_MUTEX(reloc_mutex); + +/** + * qcom_pil_info_store() - store PIL information of image in IMEM + * @image: name of the image + * @base: base address of the loaded image + * @size: size of the loaded image + * + * Return: 0 on success, negative errno on failure + */ +int qcom_pil_info_store(const char *image, phys_addr_t base, size_t size) +{ + struct pil_reloc_entry *entry; + int idx = -1; + int ret; + int i; + + mutex_lock(&reloc_mutex); + for (i = 0; i < _reloc->num_entries; i++) { + if (!_reloc->entries[i].name[0]) { + if (idx == -1) + idx = i; + continue; + } + + if (!strncmp(_reloc->entries[i].name, image, 8)) { + idx = i; + goto found; + } + } + + if (idx == -1) { + dev_warn(_reloc->dev, "insufficient PIL info slots\n"); + ret = -ENOMEM; + goto unlock; + } + +found: + entry = &_reloc->entries[idx]; + strscpy(entry->name, image, ARRAY_SIZE(entry->name)); + entry->base = base; + entry->size = size; + + ret = regmap_bulk_write(_reloc->map, + _reloc->offset + idx * sizeof(*entry), + entry, sizeof(*entry) / _reloc->val_bytes); +unlock: + mutex_unlock(&reloc_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(qcom_pil_info_store); + +/** + * qcom_pil_info_available() - query if the pil info is probed + * + * Return: boolean indicating if the pil info device is probed + */ +bool qcom_pil_info_available(void) +{ + return !!_reloc; +} +EXPORT_SYMBOL_GPL(qcom_pil_info_available); + +static int pil_reloc_probe(struct platform_device *pdev) +{ + unsigned int num_entries; + struct pil_reloc *reloc; + struct resource *res; + int ret; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -EINVAL; + + num_entries = resource_size(res) / sizeof(struct pil_reloc_entry); + + reloc = devm_kzalloc(&pdev->dev, + struct_size(reloc, entries, num_entries), + GFP_KERNEL); + if (!reloc) + return -ENOMEM; + + reloc->dev = &pdev->dev; + reloc->map = syscon_node_to_regmap(pdev->dev.parent->of_node); + if (IS_ERR(reloc->map)) + return PTR_ERR(reloc->map); + + reloc->offset = res->start; + reloc->num_entries = num_entries; + + reloc->val_bytes = regmap_get_val_bytes(reloc->map); + if (reloc->val_bytes < 0) + return -EINVAL; + + ret = regmap_bulk_write(reloc->map, reloc->offset, reloc->entries, + reloc->num_entries * + sizeof(struct pil_reloc_entry) / + reloc->val_bytes); + if (ret < 0) + return ret; + + mutex_lock(&reloc_mutex); + _reloc = reloc; + mutex_unlock(&reloc_mutex); + + return 0; +} + +static int pil_reloc_remove(struct platform_device *pdev) +{ + mutex_lock(&reloc_mutex); + _reloc = NULL; + mutex_unlock(&reloc_mutex); + + return 0; +} + +static const struct of_device_id pil_reloc_of_match[] = { + { .compatible = "qcom,pil-reloc-info" }, + {} +}; +MODULE_DEVICE_TABLE(of, pil_reloc_of_match); + +static struct platform_driver pil_reloc_driver = { + .probe = pil_reloc_probe, + .remove = pil_reloc_remove, + .driver = { + .name = "qcom-pil-reloc-info", + .of_match_table = pil_reloc_of_match, + }, +}; +module_platform_driver(pil_reloc_driver); + +MODULE_DESCRIPTION("Qualcomm PIL relocation info"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/remoteproc/qcom_pil_info.h b/drivers/remoteproc/qcom_pil_info.h new file mode 100644 index 000000000000..93aaaca8aed2 --- /dev/null +++ b/drivers/remoteproc/qcom_pil_info.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __QCOM_PIL_INFO_H__ +#define __QCOM_PIL_INFO_H__ + +int qcom_pil_info_store(const char *image, phys_addr_t base, size_t size); +bool qcom_pil_info_available(void); + +#endif -- 2.24.0