Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1167113ybl; Fri, 10 Jan 2020 13:20:26 -0800 (PST) X-Google-Smtp-Source: APXvYqxtpFts+r5cgGIzfqU0y5J5BouODS50Ad7gVLtlraS5xow3z3nNrSzL8qaxFm5eRTbcJD0+ X-Received: by 2002:aca:c08b:: with SMTP id q133mr3700059oif.46.1578691226528; Fri, 10 Jan 2020 13:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578691226; cv=none; d=google.com; s=arc-20160816; b=hqpOO6shvohWGQ114rMOiRW4EJEeVtLgWEooED9dpd4n6jG0pvVXcDA1X7gd9eDHyJ Ca/HMbrE2LlfuCTAvKkCf+l1QekOYfIS1QKcKWScZQmE6UerCbpHXgW7tWzxGQ/yUxKL 6mMBYPoesdU32vTPYzqEKM2njc3gvZbDChgGAJEy6dNEEvjCP0t8TILLzehp8ojtoFYd OkEBCKBVtosoPNraH+CaLOaP5pvfSfTuFR3r3wxiVvHrCUdBUEH6ZBvZO0n7trCNl+lb eMqnpZoiQ4pJfN0YZpYI5SuzrLEC/hT5Utq0heOy4069ZFSgdvVT7dFtKx5C1z+phDqQ 8/uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OsFwSWP/xRcH1cmWjjdOujlzZsNfP9UNbHn7pdTBcQ8=; b=dAhxdoB8Lj+JkwxO9x3FI+8fpLTfi9dWsGbLJXnQQvPTM8WFQCmh47xBHnAAfnflsZ V1otNJAtWPbVvJQqagJyZmzDU1Rw9eWnDDUHMgI7nKBoRYYBWLhfXo1KDDUWYJKNZndA BB+p/EmyzN2VWyn3fvMexmmharxAIB5/ZsV8wb0zpn4Yb8OJ9N0a2BJUfZp2M6kht1sm AyOH9SQOjsg+EmjgG+Er6FxSTTRJiEWajPQ2OCCSW7P7/E8m+w6giWlH7RO5bZHQCu5e nxDQOYvyz/lh3a+YboNhRuk0lIhWvj1SIE/IONkUACjJ5DCeu/ASM6Be3RZ9ePD1dhe9 wM9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CLh5YwP6; 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 d192si1761893oig.21.2020.01.10.13.20.14; Fri, 10 Jan 2020 13:20:26 -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=CLh5YwP6; 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 S1727165AbgAJVSu (ORCPT + 99 others); Fri, 10 Jan 2020 16:18:50 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:51591 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726788AbgAJVSu (ORCPT ); Fri, 10 Jan 2020 16:18:50 -0500 Received: by mail-pj1-f67.google.com with SMTP id d15so105182pjw.1 for ; Fri, 10 Jan 2020 13:18:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=OsFwSWP/xRcH1cmWjjdOujlzZsNfP9UNbHn7pdTBcQ8=; b=CLh5YwP6LHsUQIyC9mN3P/Pg6C/S9QYnJlr15b9bT9RP+Kp9FIHfpxVng5kKNRMvc9 ml078eP3iGkhrrYHUX2IcROXMuWrGDGyJ/JrEcvvSKnVM11SbdFl6qYyKjzWCWvgtS3r XHA4I0+/qe5Ne71x/ra9yKEZGpWsd5/I7Pce8eyEf3xTxL7T4bI81leeuE+8upkMJAbX N6myHqYe5mi7ZJNtkU8u33N6Ad1k567Qat7fIACFtxTbpD/vgrgRjZEDoJL40QbdGyLk WLg4Gnel81hnCp/7QyA5V8lKrvRSN0+GyZun5sY14gkkBo/ARul8hzRbtD8i7im6NpJU qSNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=OsFwSWP/xRcH1cmWjjdOujlzZsNfP9UNbHn7pdTBcQ8=; b=ufI0hqlFX+dKNfcrmLqww7PwYTLw7+oMJrLyY0rQ8cLSCAPrUNLViwTdJn8MZ1fCUY WZM/De30O7No8bP94ZnYx/NYkSsQoMCpLsjKrCf5lHyCoqqW/pgTSE/dsKS2tSF9N7O5 2YpFfsgUBbqCy7gylbsb1Cjtch6DIuOCs1Jv08fpR5DbxfIAmPoXuG3IKM8QMtCbnUKT lKwV/mXMiyQdBqY8HrQMm7b1JRCB7Ws2GSWI/y39zvzjrO/aiYYq9XhVVeWUQ0sL57XA 9jE0syPyEO/sx4LoMmD8azdkJIB2ZXvJmEmR9d3/pSSNWb+zMzv6tmBLDFrJsYynaUts Z+og== X-Gm-Message-State: APjAAAVEOqOepAYPPgpjxkVBhlaVs7tWghMKVdm3UsPH6eIiXuHs6B8/ BOROXXBIHEBS9FfyiR4DJMPHjQ== X-Received: by 2002:a17:90a:9d8a:: with SMTP id k10mr7230861pjp.91.1578691128908; Fri, 10 Jan 2020 13:18:48 -0800 (PST) Received: from xps15 (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b8sm4148927pfr.64.2020.01.10.13.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2020 13:18:47 -0800 (PST) Date: Fri, 10 Jan 2020 14:18:46 -0700 From: Mathieu Poirier To: Bjorn Andersson Cc: Rob Herring , Mark Rutland , Ohad Ben-Cohen , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org, Sibi Sankar , Rishabh Bhatnagar Subject: Re: [PATCH v2 2/8] remoteproc: qcom: Introduce driver to store pil info in IMEM Message-ID: <20200110211846.GA11555@xps15> References: <20191227053215.423811-1-bjorn.andersson@linaro.org> <20191227053215.423811-3-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191227053215.423811-3-bjorn.andersson@linaro.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Bjorn, On Thu, Dec 26, 2019 at 09:32:09PM -0800, Bjorn Andersson wrote: > 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 v1: > - Added helper to probe defer clients > - Fixed logical bug in slot scan > - Added SPDX header in header file > > drivers/remoteproc/Kconfig | 3 + > drivers/remoteproc/Makefile | 1 + > drivers/remoteproc/qcom_pil_info.c | 150 +++++++++++++++++++++++++++++ > drivers/remoteproc/qcom_pil_info.h | 8 ++ > 4 files changed, 162 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 94afdde4bc9f..0798602e355a 100644 > --- a/drivers/remoteproc/Kconfig > +++ b/drivers/remoteproc/Kconfig > @@ -85,6 +85,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 00f09e658cb3..c1b46e9033cb 100644 > --- a/drivers/remoteproc/Makefile > +++ b/drivers/remoteproc/Makefile > @@ -14,6 +14,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..b0897ae9eae5 > --- /dev/null > +++ b/drivers/remoteproc/qcom_pil_info.c > @@ -0,0 +1,150 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (c) 2019 Linaro Ltd. > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include These should be in alphabetical order if there is no depencencies between them, something checkpatch complains about. > + > +struct pil_reloc_entry { > + char name[8]; Please add a #define for the name length and reuse it in qcom_pil_info_store() > + __le64 base; > + __le32 size; > +} __packed; > + > +#define PIL_INFO_SIZE 200 > +#define PIL_INFO_ENTRIES (PIL_INFO_SIZE / sizeof(struct pil_reloc_entry)) > + > +struct pil_reloc { > + struct device *dev; > + struct regmap *map; > + u32 offset; > + int val_bytes; > + > + struct pil_reloc_entry entries[PIL_INFO_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 > + */ > +void qcom_pil_info_store(const char *image, phys_addr_t base, size_t size) > +{ > + struct pil_reloc_entry *entry; > + int idx = -1; > + int i; > + > + mutex_lock(&reloc_mutex); > + if (!_reloc) Since it is available, I would use function qcom_pil_info_available(). Also checkpatch complains about indentation problems related to the 'if' condition but I can't see what makes it angry. > + goto unlock; > + > + for (i = 0; i < PIL_INFO_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"); > + goto unlock; Given how this function is used in the next patch I think an error should be reported to the caller. > + } > + > +found: > + entry = &_reloc->entries[idx]; > + stracpy(entry->name, image); Function stracpy() isn't around in mainline. > + entry->base = base; > + entry->size = size; > + > + regmap_bulk_write(_reloc->map, _reloc->offset + idx * sizeof(*entry), > + entry, sizeof(*entry) / _reloc->val_bytes); Same here - the error code should be handled and reported to the caller. > + > +unlock: > + mutex_unlock(&reloc_mutex); > +} > +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) > +{ > + struct pil_reloc *reloc; > + > + reloc = devm_kzalloc(&pdev->dev, sizeof(*reloc), 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); > + > + if (of_property_read_u32(pdev->dev.of_node, "offset", &reloc->offset)) > + return -EINVAL; > + > + reloc->val_bytes = regmap_get_val_bytes(reloc->map); > + if (reloc->val_bytes < 0) > + return -EINVAL; > + > + regmap_bulk_write(reloc->map, reloc->offset, reloc->entries, > + sizeof(reloc->entries) / reloc->val_bytes); Error code handling. Thanks, Mathieu > + > + 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..0372602fae1d > --- /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__ > + > +void qcom_pil_info_store(const char *image, phys_addr_t base, size_t size); > +bool qcom_pil_info_available(void); > + > +#endif > -- > 2.24.0 >