Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1226472ybv; Thu, 13 Feb 2020 18:36:19 -0800 (PST) X-Google-Smtp-Source: APXvYqwlflS6/fuR8vWylcOSGF4jOjFGL0j10r9Q/AwzIdtoyrWKTuntuBzSUkZhv4Q+P3Hvj3GP X-Received: by 2002:aca:5083:: with SMTP id e125mr462622oib.96.1581647778924; Thu, 13 Feb 2020 18:36:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581647778; cv=none; d=google.com; s=arc-20160816; b=Ae/SjD5R0EMWiHN+X6UwvlRwFAL0kMYqJi05KL16HnqMHzaqfXHXFJ9L3froXNfm/m UTzqNW3lG9/BD2Xy4lGEWbggHMK61feYWiNkgfVbYP4trdbpuvjKix0eXqogPsDUmU/0 vJBii68SuY8TJBFP6ssvh+6MQexTPqA7pItAQPg/RpIkh7Jqg2eJi9lhI1oGNqzDGrd0 WU8EjQ9t2c2i1Ncnb9Ti4J329RkSwISNa/oCzMG0IK7wNKS4TCVLiKG7rGeCtccsWNYN aU4UmRRwDBdX+1aKnM2krEHTWnO+Po5OvugdolIciICUU3SCaroEbfYUtpq/15MTLzb9 Picw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:date:to:cc:from :subject:references:in-reply-to:content-transfer-encoding :mime-version:dkim-signature; bh=YkjZqM2zPCFdKSMVqrMU4uiZIPgukgPkLcBqtvrPxVw=; b=ykwj+M8KDXgEp4JzLFUdx1vcjYLau+Om4+sS4E3JJNaY3VleAPXyZiopaYVAes4fG+ dxI8r3IExE2mRcFO1vh2Zp7R8l6oLbsXAzn4k1PbyMU4gRbLTm7SA34Y39mWu5GzsWcX LxvCuQq8jJAf35iinjpYv9F9xAajo3iAm7dUTY27A7dwelHIdQW3hUiYi3/Qk6dFeS/R hCcEh5XwtqG+kAd8NdKVRsGFFPDAjbmU4IsHUO5IrtmB7d91Me98UI8fuZtdQgsn98ls 16zrPROqUlz793ieZN7AZqnjZ9Lqz6920+YdZMai4+JO94hjXDCex9o7+8OuYr4pmiLc hdoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FTUtexd2; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w18si2173011otp.48.2020.02.13.18.36.05; Thu, 13 Feb 2020 18:36:18 -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=@chromium.org header.s=google header.b=FTUtexd2; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728337AbgBNCfr (ORCPT + 99 others); Thu, 13 Feb 2020 21:35:47 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39886 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727988AbgBNCfq (ORCPT ); Thu, 13 Feb 2020 21:35:46 -0500 Received: by mail-pl1-f196.google.com with SMTP id g6so3135306plp.6 for ; Thu, 13 Feb 2020 18:35:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:content-transfer-encoding:in-reply-to:references :subject:from:cc:to:date:message-id:user-agent; bh=YkjZqM2zPCFdKSMVqrMU4uiZIPgukgPkLcBqtvrPxVw=; b=FTUtexd2G2VHH/wGsAlNuLW1UMTCHwjwtEcGyCzSAIdwYUx0MwYQQh7YEfLp6mz5TO G6+m7V3uJfynCvaujIsP79TJiVeOiOBrHdDLYBjzL/QMS9ILnbk3bf+NIfug96yWIb1u Ax872eNX8BTmhKr+43c+Ni6DHyQYLLjoZ3ThA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding :in-reply-to:references:subject:from:cc:to:date:message-id :user-agent; bh=YkjZqM2zPCFdKSMVqrMU4uiZIPgukgPkLcBqtvrPxVw=; b=q73c2AQjCnl6Pm4sqQgYZEFfc/NdUPlUsLWrIE+eXcx2VWJoixypb0AqqG6rXFNscZ W3ebwY4R1BqZ6MlSNvu70B2LIP9pE49TSyQDhSiMiHUcd8JOsWy8cGbrLREZGQA8RQrj TmOqOHArkgxPH+qpzYWcFeDznV/5A5iD9wgPwg2lLaOfyFsnqaURNmSXnn4dqEZV3Jc+ 8hM3e+tS6RJcTEZv7XAdu+OvyTUv9UECKbqMYV81TV+MN0QM3NoaI7E7j4OCBJZZb42p naJeuao4sjcuUHI1yI9HIRCuxEpzsyAK4LKeiYj95In5NFvmwn3LyXOyBJyVn+4GVat0 n8Gg== X-Gm-Message-State: APjAAAWeNw1QkkXJa1pqC1whJF+kRdnqrq7wFQFq0YgExG43qagX9HAO tsk4+N2i29XY5GcFUXieMlbBPg== X-Received: by 2002:a17:902:d216:: with SMTP id t22mr1019808ply.150.1581647745421; Thu, 13 Feb 2020 18:35:45 -0800 (PST) Received: from chromium.org ([2620:15c:202:1:fa53:7765:582b:82b9]) by smtp.gmail.com with ESMTPSA id y10sm4612216pfq.110.2020.02.13.18.35.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 18:35:45 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20200211005059.1377279-3-bjorn.andersson@linaro.org> References: <20200211005059.1377279-1-bjorn.andersson@linaro.org> <20200211005059.1377279-3-bjorn.andersson@linaro.org> Subject: Re: [PATCH v3 2/8] remoteproc: qcom: Introduce driver to store pil info in IMEM From: Stephen Boyd 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 To: Bjorn Andersson , Ohad Ben-Cohen Date: Thu, 13 Feb 2020 18:35:44 -0800 Message-ID: <158164774404.184098.8855626264878132058@swboyd.mtv.corp.google.com> User-Agent: alot/0.9 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Bjorn Andersson (2020-02-10 16:50:53) > 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; Does this need __packed? Isn't it naturally aligned? > + > +struct pil_reloc { > + struct device *dev; > + struct regmap *map; > + size_t offset; > + size_t num_entries; > + int val_bytes; unsigned int? > + > + struct pil_reloc_entry entries[]; > +}; > + > +static struct pil_reloc *_reloc; Can this be const? Or marked __read_mostly? > +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 =3D -1; > + int ret; > + int i; > + > + mutex_lock(&reloc_mutex); > + for (i =3D 0; i < _reloc->num_entries; i++) { > + if (!_reloc->entries[i].name[0]) { > + if (idx =3D=3D -1) > + idx =3D i; > + continue; > + } > + > + if (!strncmp(_reloc->entries[i].name, image, 8)) { > + idx =3D i; > + goto found; > + } > + } > + > + if (idx =3D=3D -1) { Maybe it would be better to use a pointer and set it to NULL when it isn't found. Then do some pointer math on the 'entry' to find the address to regmap_bulk_write() below. > + dev_warn(_reloc->dev, "insufficient PIL info slots\n"); > + ret =3D -ENOMEM; > + goto unlock; > + } > + > +found: > + entry =3D &_reloc->entries[idx]; > + strscpy(entry->name, image, ARRAY_SIZE(entry->name)); > + entry->base =3D base; > + entry->size =3D size; > + > + ret =3D regmap_bulk_write(_reloc->map, > + _reloc->offset + idx * sizeof(*entry), > + entry, sizeof(*entry) / _reloc->val_bytes= ); > +unlock: > + mutex_unlock(&reloc_mutex); Does the mutex need to be held until here? Why can't we release it once we find the entry? > + > + 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 =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); > + if (!res) > + return -EINVAL; > + > + num_entries =3D resource_size(res) / sizeof(struct pil_reloc_entr= y); > + > + reloc =3D devm_kzalloc(&pdev->dev, > + struct_size(reloc, entries, num_entries), > + GFP_KERNEL); > + if (!reloc) > + return -ENOMEM; > + > + reloc->dev =3D &pdev->dev; > + reloc->map =3D syscon_node_to_regmap(pdev->dev.parent->of_node); > + if (IS_ERR(reloc->map)) > + return PTR_ERR(reloc->map); > + > + reloc->offset =3D res->start; > + reloc->num_entries =3D num_entries; > + > + reloc->val_bytes =3D regmap_get_val_bytes(reloc->map); > + if (reloc->val_bytes < 0) > + return -EINVAL; > + > + ret =3D regmap_bulk_write(reloc->map, reloc->offset, reloc->entri= es, > + reloc->num_entries * > + sizeof(struct pil_reloc_entry) / > + reloc->val_bytes); > + if (ret < 0) > + return ret; > + > + mutex_lock(&reloc_mutex); > + _reloc =3D reloc; > + mutex_unlock(&reloc_mutex); Ah ok, I see that mutex is protecting the pointer used for everything. Ignore the comment above. But also, why not have every remoteproc device point at some imem and then search through the imem for the name? Then we don't need this driver or a lock that synchronizes these things. Ideally we could dedicate a place in imem for each remoteproc and not even have to search it for the string to update. Is that possible? Then it becomes even simpler because the DT binding can point directly at the address to write. It's not like the various images are changing that much to the point where this location in imem is actually changing, right? > + > + return 0; > +}