From: Alexander Stein <alexander.stein@ew.tq-group.com>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
"Peng Fan (OSS)" <peng.fan@oss.nxp.com>,
Peng Fan <peng.fan@nxp.com>
Cc: "devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"imx@lists.linux.dev" <imx@lists.linux.dev>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v6 2/2] nvmem: imx-ocotp-ele: Support accessing controller for i.MX9
Date: Wed, 22 Jan 2025 07:26:16 +0100 [thread overview]
Message-ID: <3890686.kQq0lBPeGt@steina-w> (raw)
In-Reply-To: <PAXPR04MB8459845E7D949680044E203188E12@PAXPR04MB8459.eurprd04.prod.outlook.com>
Am Mittwoch, 22. Januar 2025, 04:36:33 CET schrieb Peng Fan:
> > Subject: Re: [PATCH v6 2/2] nvmem: imx-ocotp-ele: Support accessing
> > controller for i.MX9
> >
> > Hi,
> >
> > Am Dienstag, 21. Januar 2025, 16:05:32 CET schrieb Peng Fan (OSS):
> > > From: Peng Fan <peng.fan@nxp.com>
> > >
> > > i.MX9 OCOTP supports a specific peripheral or function being fused
> > > which means disabled, so
> > > - Introduce ocotp_access_gates to be container of efuse gate info
> > > - Iterate all nodes to check accessing permission. If not
> > > allowed to be accessed, detach the node
> > >
> > > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > > ---
> > > drivers/nvmem/Kconfig | 3 +
> > > drivers/nvmem/imx-ocotp-ele.c | 172
> > > +++++++++++++++++++++++++++++++++++++++++-
> > > 2 files changed, 174 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index
> > >
> > 8671b7c974b933e147154bb40b5d41b5730518d2..77cc496fd5e0e1af
> > d753534b56fe
> > > 1f5ef3e3ec55 100644
> > > --- a/drivers/nvmem/Kconfig
> > > +++ b/drivers/nvmem/Kconfig
> > > @@ -93,6 +93,9 @@ config NVMEM_IMX_OCOTP_ELE
> > > This is a driver for the On-Chip OTP Controller (OCOTP)
> > > available on i.MX SoCs which has ELE.
> > >
> > > + If built as modules, any other driver relying on this working
> > > + as access controller also needs to be a module as well.
> > > +
> > > config NVMEM_IMX_OCOTP_SCU
> > > tristate "i.MX8 SCU On-Chip OTP Controller support"
> > > depends on IMX_SCU
> > > diff --git a/drivers/nvmem/imx-ocotp-ele.c
> > > b/drivers/nvmem/imx-ocotp-ele.c index
> > >
> > ca6dd71d8a2e29888c6e556aaea116c1a967cb5f..5ea6d959ce38760ee
> > ed44a989992
> > > fb35c462c0b4 100644
> > > --- a/drivers/nvmem/imx-ocotp-ele.c
> > > +++ b/drivers/nvmem/imx-ocotp-ele.c
> > > @@ -5,6 +5,8 @@
> > > * Copyright 2023 NXP
> > > */
> > >
> > > +#include <dt-bindings/nvmem/fsl,imx93-ocotp.h>
> > > +#include <dt-bindings/nvmem/fsl,imx95-ocotp.h>
> > > #include <linux/device.h>
> > > #include <linux/io.h>
> > > #include <linux/module.h>
> > > @@ -27,6 +29,7 @@ struct ocotp_map_entry { };
> > >
> > > struct ocotp_devtype_data {
> > > + const struct ocotp_access_gates *access_gates;
> > > u32 reg_off;
> > > char *name;
> > > u32 size;
> > > @@ -36,6 +39,20 @@ struct ocotp_devtype_data {
> > > struct ocotp_map_entry entry[];
> > > };
> > >
> > > +#define OCOTP_MAX_NUM_GATE_WORDS 4
> > > +
> > > +struct access_gate {
> > > + u32 word;
> > > + u32 mask;
> > > +};
> > > +
> > > +struct ocotp_access_gates {
> > > + u32 num_words;
> > > + u32 words[OCOTP_MAX_NUM_GATE_WORDS];
> > > + u32 num_gates;
> > > + struct access_gate *gates;
> > > +};
> > > +
> > > struct imx_ocotp_priv {
> > > struct device *dev;
> > > void __iomem *base;
> > > @@ -131,6 +148,82 @@ static void
> > imx_ocotp_fixup_dt_cell_info(struct nvmem_device *nvmem,
> > > cell->read_post_process = imx_ocotp_cell_pp; }
> > >
> > > +static int imx_ele_ocotp_check_access(struct imx_ocotp_priv *priv,
> > > +u32 id) {
> > > + const struct ocotp_access_gates *access_gates = priv->data-
> > >access_gates;
> > > + void __iomem *reg = priv->base + priv->data->reg_off;
> > > + u32 word, mask, val;
> > > +
> > > + if (id >= access_gates->num_gates) {
> > > + dev_err(priv->config.dev, "Index %d too large\n", id);
> > > + return -EACCES;
> > > + }
> > > +
> > > + word = access_gates->gates[id].word;
> > > + mask = access_gates->gates[id].mask;
> > > +
> > > + reg = priv->base + priv->data->reg_off + (word << 2);
> > > + val = readl(reg);
> > > +
> > > + dev_dbg(priv->config.dev, "id:%d word:%d mask:0x%08x\n",
> > id, word, mask);
> > > + /* true means not allow access */
> > > + if (val & mask)
> > > + return -EACCES;
> > > +
> > > + return 0;
> > > +}
> > > +
> > > +static int imx_ele_ocotp_grant_access(struct imx_ocotp_priv *priv,
> > > +struct device_node *parent) {
> > > + struct device *dev = priv->config.dev;
> > > +
> > > + for_each_available_child_of_node_scoped(parent, child) {
> > > + struct of_phandle_args args;
> > > + u32 id, idx = 0;
> > > +
> > > + while (!of_parse_phandle_with_args(child, "access-
> > controllers",
> > > + "#access-
> > controller-cells",
> > > + idx++, &args)) {
> > > + of_node_put(args.np);
> > > + if (args.np != dev->of_node)
> > > + continue;
> > > +
> > > + /* Only support one cell */
> > > + if (args.args_count != 1) {
> > > + dev_err(dev, "wrong args count\n");
> > > + continue;
> > > + }
> > > +
> > > + id = args.args[0];
> > > +
> > > + dev_dbg(dev, "Checking node: %pOF
> > gate: %d\n", child, id);
> > > +
> > > + if (imx_ele_ocotp_check_access(priv, id)) {
> > > + of_detach_node(child);
> > > + dev_info(dev, "%pOF: Not granted,
> > device driver will not be probed\n",
> > > + child);
> > > + }
> > > + }
> > > +
> > > + imx_ele_ocotp_grant_access(priv, child);
> > > + }
> > > +
> > > + return 0;
> > > +}
> > > +
> > > +static int imx_ele_ocotp_access_control(struct imx_ocotp_priv *priv)
> > > +{
> > > + struct device_node *root __free(device_node) =
> > > +of_find_node_by_path("/");
> > > +
> > > + if (!priv->data->access_gates)
> > > + return 0;
> > > +
> > > + /* This should never happen */
> > > + WARN_ON(!root);
> >
> > Even if you warning something is wrong, aka root == NULL, you are still
> > using it on imx_ele_ocotp_grant_access(). Just return early.
> >
> > if (WARN_ON(!))
> > return -EINVAL;
>
> Hmm, If this really happens, return early or not does not make much sense.
> Does it really matter here?
Why does it not make much sense? You already know something is wrong, aka
you have a NULL pointer, so it makes even less sense to continue.
I've skipped through the sources and looked for 'WARN_ON(!<pointer>)',
most of the times it is actually checked for early returns.
Best regards,
Alexander
--
TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/
next prev parent reply other threads:[~2025-01-22 6:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-21 15:05 [PATCH v6 0/2] Make i.MX9 OCOTP work as accessing controller Peng Fan (OSS)
2025-01-21 15:05 ` [PATCH v6 1/2] dt-bindings: nvmem: imx-ocotp: Introduce #access-controller-cells Peng Fan (OSS)
2025-01-30 9:49 ` Alexander Stein
2025-01-21 15:05 ` [PATCH v6 2/2] nvmem: imx-ocotp-ele: Support accessing controller for i.MX9 Peng Fan (OSS)
2025-01-21 15:21 ` Alexander Stein
2025-01-22 3:36 ` Peng Fan
2025-01-22 6:26 ` Alexander Stein [this message]
2025-01-22 12:43 ` Peng Fan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3890686.kQq0lBPeGt@steina-w \
--to=alexander.stein@ew.tq-group.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peng.fan@nxp.com \
--cc=peng.fan@oss.nxp.com \
--cc=robh@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox