lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+V-a8u_oMxG8QmmK=_y8z6O_H-22SyCkje-VrQVqHn4H=5oow@mail.gmail.com>
Date: Mon, 15 Jul 2024 09:43:10 +0100
From: "Lad, Prabhakar" <prabhakar.csengg@...il.com>
To: Geert Uytterhoeven <geert@...ux-m68k.org>
Cc: Michael Turquette <mturquette@...libre.com>, Stephen Boyd <sboyd@...nel.org>, 
	Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley <conor+dt@...nel.org>, 
	Philipp Zabel <p.zabel@...gutronix.de>, Magnus Damm <magnus.damm@...il.com>, 
	linux-clk@...r.kernel.org, devicetree@...r.kernel.org, 
	linux-kernel@...r.kernel.org, linux-renesas-soc@...r.kernel.org, 
	Biju Das <biju.das.jz@...renesas.com>, 
	Fabrizio Castro <fabrizio.castro.jz@...esas.com>, 
	Lad Prabhakar <prabhakar.mahadev-lad.rj@...renesas.com>
Subject: Re: [PATCH v3 2/3] clk: renesas: Add family-specific clock driver for RZ/V2H(P)

Hi Geert,

On Fri, Jul 12, 2024 at 6:11 PM Geert Uytterhoeven <geert@...ux-m68k.org> wrote:
>
> Hi Prabhakar,
>
> On Fri, Jul 12, 2024 at 5:29 PM Lad, Prabhakar
> <prabhakar.csengg@...il.com> wrote:
> > On Fri, Jul 12, 2024 at 4:23 PM Geert Uytterhoeven <geert@...ux-m68k.org> wrote:
> > > On Fri, Jul 12, 2024 at 5:14 PM Lad, Prabhakar
> > > <prabhakar.csengg@...il.com> wrote:
> > > > On Fri, Jul 12, 2024 at 12:59 PM Geert Uytterhoeven
> > > > > On Thu, Jun 27, 2024 at 6:14 PM Prabhakar <prabhakar.csengg@...il.com> wrote:
> > > > > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@...renesas.com>
> > > > > >
> > > > > > Add family-specific clock driver for RZ/V2H(P) SoCs.
> > > > > >
> > > > > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@...renesas.com>
> > > > > > ---
> > > > > > v2->v3
> > > > > > - Dropped num_hw_resets from struct rzv2h_cpg_priv
> > > > > > - Dropped range_check for module clocks
> > > > > > - Made mon_index to s8 instead of u8 in struct rzv2h_mod_clk
> > > > > > - Added support for critical module clocks with DEF_MOD_CRITICAL
> > > > > > - Added check for mon_index in rzv2h_mod_clock_endisable and
> > > > > >   rzv2h_mod_clock_is_enabled()
> > >
> > > > > > --- /dev/null
> > > > > > +++ b/drivers/clk/renesas/rzv2h-cpg.h
> > >
> > > > > > +/**
> > > > > > + * struct rzv2h_reset - Reset definitions
> > > > > > + *
> > > > > > + * @reset_index: reset register index
> > > > > > + * @reset_bit: reset bit
> > > > > > + * @mon_index: monitor register index
> > > > > > + * @mon_bit: monitor bit
> > > > > > + */
> > > > > > +struct rzv2h_reset {
> > > > > > +       u8 reset_index;
> > > > > > +       u8 reset_bit;
> > > > > > +       u8 mon_index;
> > > > > > +       u8 mon_bit;
> > > > > > +};
> > > > > > +
> > > > > > +#define RST_ID(x, y)   ((((x) * 16)) + (y))
> > > > > > +
> > > > > > +#define DEF_RST_BASE(_id, _resindex, _resbit, _monindex, _monbit)      \
> > > > > > +       [_id] = { \
> > > > >
> > > > > Indexing by _id means the reset array will be very sparse.  E.g. the
> > > > > innocent-looking r9a09g057_resets[] with only a single entry takes
> > > > > 600 bytes.
> > > > >
> > > > > If you do need the full array for indexing, please allocate and
> > > > > populate it at runtime.
> > > > >
> > > > OK, I will use the radix tree for resets (is that OK)?
> > >
> > > You mean XArray? include/linux/radix-tree.h has:
> > >
> > >     /* Keep unconverted code working */
> > >     #define radix_tree_root         xarray
> > >     #define radix_tree_node         xa_node
> > >
> > Yes, I meant the above.
> >
> > > Given a single xa_node is already 576 bytes, just allocating the full
> > > linear reset array at runtime is probably better.
> > >
> > Agreed, I will create a linear reset array and loop through the array
> > based on reset index and reset bit to match with id whenever required.
>
> With a full allocated linear reset array you do not need to loop,
> but you can just index it by the reset ID??
>
Instead of having a sparse array, to save memory I was thinking
something like below:

/**
 * struct rzv2h_reset - Reset definitions
 *
 * @reset_index: reset register index
 * @reset_bit: reset bit
 * @mon_index: monitor register index
 * @mon_bit: monitor bit
 */
struct rzv2h_reset {
    u8 reset_index;
    u8 reset_bit;
    u8 mon_index;
    u8 mon_bit;
};

#define DEF_RST_BASE(_resindex, _resbit, _monindex, _monbit)    \
    { \
        .reset_index = (_resindex), \
        .reset_bit = (_resbit), \
        .mon_index = (_monindex), \
        .mon_bit = (_monbit), \
    }

#define DEF_RST(_resindex, _resbit, _monindex, _monbit)    \
    DEF_RST_BASE(_resindex, _resbit, _monindex, _monbit)


in rzv2h_cpg_probe() (.num_resets = ARRAY_SIZE(r9a09g057_resets))

    resets = devm_kmalloc_array(dev, info->num_resets, sizeof(struct
rzv2h_reset), GFP_KERNEL);
    if (!resets)
        return -ENOMEM;

    for (i = 0; i < priv->num_resets; i++)
        memcpy(&resets[i], &info->resets[i], sizeof(struct rzv2h_reset));

And have the below xlate function that will convert id into index ie
index into rests array.

static int rzv2h_get_reset_index(struct rzv2h_cpg_priv *priv,
                 unsigned long id)
{
    u8 reset_index = id / 16;
    u8 reset_bit = id % 16;
    unsigned int i;

    for (i = 0; i < priv->num_resets; i++) {
        if (priv->resets[i].reset_index == reset_index &&
            priv->resets[i].reset_bit == reset_bit)
            return i;
    }

    return -EINVAL;
}

static int rzv2h_cpg_reset_xlate(struct reset_controller_dev *rcdev,
                 const struct of_phandle_args *reset_spec)
{
    struct rzv2h_cpg_priv *priv = rcdev_to_priv(rcdev);
    unsigned int id = reset_spec->args[0];
    int index = rzv2h_get_reset_index(priv, id);

    if (index < 0) {
        dev_err(rcdev->dev, "Invalid reset index %u\n", id);
        return -EINVAL;
    }

    return index;
}


rzv2h_cpg_assert() and rzv2h_cpg_deassert() which will use an id that
can directly index into resets[] array.

Please let me know if this is OK.

Cheers,
Prabhakar

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ