public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 03/23] fdt: Add resource parsing functions
Date: Tue, 19 Aug 2014 13:35:50 +0200	[thread overview]
Message-ID: <20140819113549.GC19515@ulmo> (raw)
In-Reply-To: <CAPnjgZ2X6q29ZwjpsohXoNVvu71YOg_PEPpciHLg87jK58s3nQ@mail.gmail.com>

On Mon, Aug 18, 2014 at 12:06:26PM -0600, Simon Glass wrote:
> Hi Thierry,
> 
> On 18 August 2014 01:16, Thierry Reding <thierry.reding@gmail.com> wrote:
> > From: Thierry Reding <treding@nvidia.com>
> >
> > Add the fdt_get_resource() and fdt_get_named_resource() functions which
> > can be used to parse resources (memory regions) from an FDT. A helper to
> > compute the size of a region is also provided.
> >
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> > ---
> >  include/fdtdec.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  lib/fdtdec.c     | 43 +++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 91 insertions(+)
> >
> > diff --git a/include/fdtdec.h b/include/fdtdec.h
> > index 856e6cf766de..e9091eee6bae 100644
> > --- a/include/fdtdec.h
> > +++ b/include/fdtdec.h
> > @@ -40,6 +40,23 @@ struct fdt_memory {
> >         fdt_addr_t end;
> >  };
> >
> > +/* information about a resource */
> 
> Please add comments, e.g. that end is inclusive.

I've added this comment:

/*
 * Information about a resource. start is the first address of the resource
 * and end is the last address (inclusive). The length of the resource will
 * be equal to: end - start + 1.
 */

Is that enough or do you want me to be more verbose?

> > +/**
> > + * Obtain a named resource from a device property.
> > + *
> > + * Look up the index of the name in a list of strings and return the resource
> > + * at that index.
> > + *
> > + * @param fdt          FDT blob
> > + * @param node         node to examine
> > + * @param property     name of the property to parse
> > + * @param names                name of the property to obtain the match the name to
> > + * @param name         the name of the entry to look up
> 
> These two parameters are confusing. Perhaps rename names to something better?

How about "prop_names" so that it indicates it is the name of a
property? I've also adjusted the comment a bit:

 * @param prop_names name of the property containing the list of names

Hopefully that will make it more obvious.

> > +int fdt_get_resource(const void *fdt, int node, const char *property,
> > +                    unsigned int index, struct fdt_resource *res)
> 
> s/index/find_index/

In my opinion the find_ prefix is redundant. After all the function name
already indicates that we're looking for a resource inside a property.
And index would be the offset in that property.

> > +       if (!ptr)
> > +               return len;
> > +
> > +       end = ptr + len / 4;
> 
> sizeof(*ptr) might be better than 4.

Device tree explicitly specifies that cells are 32-bit, so this can't
ever be anything other than 4. But I'll change it anyway if you prefer.

> > +
> > +       while (ptr + na + ns <= end) {
> > +               if (i == index) {
> > +                       res->start = fdt_addr_to_cpu(*ptr);
> 
> This doesn't deal with 64-bit addresses. There is a half-hearted
> attempt with fdt_addr_t, but I wonder if we need a helper function
> like fdt_get_addr(ptr, num_cells)?

The Linux kernel handles this by wrapping it in an of_read_number()
helper and always returning u64, like this:

	static inline u64 of_read_number(const __be32 *cell, int size)
	{
		u64 r = 0;

		while (size--)
			r = (r << 32) | be32_to_cpu(*(cell++));

		return r;
	}

It obviously only works for size in { 0, 1, 2 }, but I can add a helper
like that if you want.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140819/92553822/attachment.pgp>

  reply	other threads:[~2014-08-19 11:35 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-18  7:16 [U-Boot] [PATCH 00/23] ARM: tegra: Add PCIe support Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 01/23] fdt: Add functions to query a node's #address- and #size-cells Thierry Reding
2014-08-18 17:52   ` Simon Glass
2014-08-19 10:59     ` Thierry Reding
2014-08-19 12:52       ` Simon Glass
2014-08-19 13:06         ` Thierry Reding
2014-08-23  3:03           ` Simon Glass
2014-08-23 11:26             ` Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 02/23] fdt: Add a function to get the index of a string Thierry Reding
2014-08-18 17:58   ` Simon Glass
2014-08-19 11:13     ` Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 03/23] fdt: Add resource parsing functions Thierry Reding
2014-08-18 18:06   ` Simon Glass
2014-08-19 11:35     ` Thierry Reding [this message]
2014-08-19 12:55       ` Simon Glass
2014-08-19 13:12         ` Thierry Reding
2014-08-19 21:28           ` Simon Glass
2014-08-20  6:36             ` Thierry Reding
2014-08-20 14:05               ` Simon Glass
2014-08-18  7:16 ` [U-Boot] [PATCH 04/23] fdt: Add a function to return PCI BDF triplet Thierry Reding
2014-08-18 18:20   ` Simon Glass
2014-08-18  7:16 ` [U-Boot] [PATCH 05/23] fdt: Add a subnodes iterator macro Thierry Reding
2014-08-18 18:11   ` Simon Glass
2014-08-19 12:22     ` Thierry Reding
2014-08-19 12:57       ` Simon Glass
2014-08-19 13:12         ` Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 06/23] pci: Abort early if bus does not exist Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 07/23] pci: Honour pci_skip_dev() Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 08/23] Add pr_fmt() macro Thierry Reding
2014-08-18 18:24   ` Simon Glass
2014-08-19 12:27     ` Thierry Reding
2014-08-19 12:58       ` Simon Glass
2014-08-18  7:16 ` [U-Boot] [PATCH 09/23] ARM: tegra: Implement tegra_plle_enable() Thierry Reding
2014-08-20 18:12   ` Stephen Warren
2014-08-18  7:16 ` [U-Boot] [PATCH 10/23] ARM: tegra: Provide PCIEXCLK reset ID Thierry Reding
2014-08-20 18:20   ` Stephen Warren
2014-08-22 12:38     ` Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 11/23] ARM: tegra: Implement powergate support Thierry Reding
2014-08-20 18:24   ` Stephen Warren
2014-08-22 13:54     ` Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 12/23] ARM: tegra: Implement XUSB pad controller Thierry Reding
2014-08-20 18:32   ` Stephen Warren
2014-08-22 14:11     ` Thierry Reding
2014-08-22 14:38     ` Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 13/23] ARM: tegra: Add XUSB pad controller on Tegra124 Thierry Reding
2014-08-20 18:33   ` Stephen Warren
2014-08-18  7:16 ` [U-Boot] [PATCH 14/23] ARM: tegra: Enable XUSB pad controller on Jetson TK1 Thierry Reding
2014-08-20 18:34   ` Stephen Warren
2014-08-18  7:16 ` [U-Boot] [PATCH 15/23] pci: tegra: Add Tegra PCIe driver Thierry Reding
2014-08-20 19:04   ` Stephen Warren
2014-08-22 15:24     ` Thierry Reding
2014-08-22 17:33     ` Stephen Warren
2014-08-22 19:41       ` Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 16/23] ARM: tegra: Add Tegra20 PCIe device tree node Thierry Reding
2014-08-20 18:37   ` Stephen Warren
2014-08-18  7:16 ` [U-Boot] [PATCH 17/23] ARM: tegra: Enable PCIe on TrimSlice Thierry Reding
2014-08-20 18:38   ` Stephen Warren
2014-08-22 14:44     ` Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 18/23] ARM: tegra: Add Tegra30 PCIe device tree node Thierry Reding
2014-08-20 18:39   ` Stephen Warren
2014-08-22 14:51     ` Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 19/23] ARM: tegra: Enable PCIe on Beaver Thierry Reding
2014-08-19 13:48   ` Marcel Ziswiler
2014-08-20  6:38     ` Thierry Reding
2014-08-20  8:56       ` Marcel Ziswiler
2014-08-20  9:46         ` Thierry Reding
2014-08-20 13:13           ` Marcel Ziswiler
2014-08-20 18:43   ` Stephen Warren
2014-08-22 12:33     ` Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 20/23] ARM: tegra: Enable PCIe on Cardhu Thierry Reding
2014-08-18  7:16 ` [U-Boot] [PATCH 21/23] ARM: tegra: Add GIC for Tegra124 Thierry Reding
2014-08-20 18:45   ` Stephen Warren
2014-08-18  7:16 ` [U-Boot] [PATCH 22/23] ARM: tegra: Add Tegra124 PCIe device tree node Thierry Reding
2014-08-20 18:46   ` Stephen Warren
2014-08-18  7:16 ` [U-Boot] [PATCH 23/23] ARM: tegra: Enable PCIe on Jetson TK1 Thierry Reding
2014-08-18 18:37   ` Simon Glass
2014-08-19 12:29     ` Thierry Reding
2014-08-19 13:07       ` Simon Glass
2014-08-20 18:51   ` Stephen Warren
2014-08-22 12:09     ` Thierry Reding
2014-08-22 18:50       ` Stephen Warren
2014-08-22 19:27       ` Simon Glass
2014-08-22 19:40         ` Thierry Reding
2014-08-22 20:12           ` Simon Glass
2014-08-22 22:03             ` Thierry Reding
2014-08-23  1:47               ` Simon Glass
2014-08-23 11:33                 ` Thierry Reding
2014-08-20 18:54   ` Stephen Warren
2014-08-26 12:54   ` Tuomas Tynkkynen
2014-08-27 13:28     ` Thierry Reding
2014-08-27 14:34       ` Thierry Reding
2014-08-27 16:52         ` Tuomas Tynkkynen

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=20140819113549.GC19515@ulmo \
    --to=thierry.reding@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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