Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1702639 > unrolled thread

[PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem

Started byBjorn Andersson <bjorn.andersson@linaro.org>
First post2017-08-03 05:00 +0200
Last post2017-08-04 17:10 +0200
Articles 5 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem Bjorn Andersson <bjorn.andersson@linaro.org> - 2017-08-03 05:00 +0200
    Re: [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem Rob Herring <robh+dt@kernel.org> - 2017-08-03 19:50 +0200
      Re: [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring  reserved_mem Bjorn Andersson <bjorn.andersson@linaro.org> - 2017-08-04 01:40 +0200
        Re: [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem Rob Herring <robh+dt@kernel.org> - 2017-08-04 17:00 +0200
          Re: [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring  reserved_mem Bjorn Andersson <bjorn.andersson@linaro.org> - 2017-08-04 17:10 +0200

#1702639 — [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem

FromBjorn Andersson <bjorn.andersson@linaro.org>
Date2017-08-03 05:00 +0200
Subject[PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem
Message-ID<uaewG-224-17@gated-at.bofh.it>
In some cases drivers referencing a reserved-memory region might want to
remap the entire region, but when defining the reserved-memory by "size"
the client driver has no means to know the associated base address of
the reserved memory region.

This patch adds an accessor for such drivers to acquire a handle to
their associated reserved-memory for this purpose.

A complicating factor for the implementation is that the reserved_mem
objects are created from the flattened DeviceTree, as such we can't
use the device_node address for comparison. Fortunately the name of the
node will be used as "name" of the reserved_mem and will be used when
building the full_name, so we can compare the "name" with the basename
of the full_name to find the match.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---

Changes since v1:
- Previous patch provided interface to resolve memory-region reference, instead
  of direct lookup by device_node

 drivers/of/of_reserved_mem.c    | 26 ++++++++++++++++++++++++++
 include/linux/of_reserved_mem.h |  5 +++++
 2 files changed, 31 insertions(+)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index d507c3569a88..b40cfce68fd4 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -397,3 +397,29 @@ void of_reserved_mem_device_release(struct device *dev)
 	rmem->ops->device_release(rmem, dev);
 }
 EXPORT_SYMBOL_GPL(of_reserved_mem_device_release);
+
+/**
+ * of_reserved_mem_get() - acquire reserved_mem from a device node
+ * @np:		node pointer of the desired reserved-memory region
+ *
+ * This function allows drivers to acquire a reference to the reserved_mem
+ * struct based on a device node handle.
+ *
+ * Returns a reserved_mem reference, or NULL on error.
+ */
+struct reserved_mem *of_reserved_mem_get(struct device_node *np)
+{
+	const char *name;
+	int i;
+
+	if (!np->full_name)
+		return NULL;
+
+	name = kbasename(np->full_name);
+	for (i = 0; i < reserved_mem_count; i++)
+		if (!strcmp(reserved_mem[i].name, name))
+			return &reserved_mem[i];
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(of_reserved_mem_get);
diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h
index f8e1992d6423..91b1eb5076e4 100644
--- a/include/linux/of_reserved_mem.h
+++ b/include/linux/of_reserved_mem.h
@@ -44,6 +44,7 @@ int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,
 void fdt_init_reserved_mem(void);
 void fdt_reserved_mem_save_node(unsigned long node, const char *uname,
 			       phys_addr_t base, phys_addr_t size);
+struct reserved_mem *of_reserved_mem_get(struct device_node *np);
 #else
 static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
 					struct device_node *np, int idx)
@@ -55,6 +56,10 @@ static inline void of_reserved_mem_device_release(struct device *pdev) { }
 static inline void fdt_init_reserved_mem(void) { }
 static inline void fdt_reserved_mem_save_node(unsigned long node,
 		const char *uname, phys_addr_t base, phys_addr_t size) { }
+static inline struct reserved_mem *of_reserved_mem_get(struct device_node *np)
+{
+	return NULL;
+}
 #endif
 
 /**
-- 
2.12.0

[toc] | [next] | [standalone]


#1703309

FromRob Herring <robh+dt@kernel.org>
Date2017-08-03 19:50 +0200
Message-ID<uaspY-3iy-13@gated-at.bofh.it>
In reply to#1702639
On Wed, Aug 2, 2017 at 9:57 PM, Bjorn Andersson
<bjorn.andersson@linaro.org> wrote:
> In some cases drivers referencing a reserved-memory region might want to
> remap the entire region, but when defining the reserved-memory by "size"
> the client driver has no means to know the associated base address of
> the reserved memory region.
>
> This patch adds an accessor for such drivers to acquire a handle to
> their associated reserved-memory for this purpose.
>
> A complicating factor for the implementation is that the reserved_mem
> objects are created from the flattened DeviceTree, as such we can't
> use the device_node address for comparison. Fortunately the name of the
> node will be used as "name" of the reserved_mem and will be used when
> building the full_name, so we can compare the "name" with the basename
> of the full_name to find the match.

Maybe we should add the device_node pointer when we unflatten?

>
> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
>
> Changes since v1:
> - Previous patch provided interface to resolve memory-region reference, instead
>   of direct lookup by device_node
>
>  drivers/of/of_reserved_mem.c    | 26 ++++++++++++++++++++++++++
>  include/linux/of_reserved_mem.h |  5 +++++
>  2 files changed, 31 insertions(+)
>
> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index d507c3569a88..b40cfce68fd4 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c
> @@ -397,3 +397,29 @@ void of_reserved_mem_device_release(struct device *dev)
>         rmem->ops->device_release(rmem, dev);
>  }
>  EXPORT_SYMBOL_GPL(of_reserved_mem_device_release);
> +
> +/**
> + * of_reserved_mem_get() - acquire reserved_mem from a device node
> + * @np:                node pointer of the desired reserved-memory region
> + *
> + * This function allows drivers to acquire a reference to the reserved_mem
> + * struct based on a device node handle.
> + *
> + * Returns a reserved_mem reference, or NULL on error.
> + */
> +struct reserved_mem *of_reserved_mem_get(struct device_node *np)
> +{
> +       const char *name;
> +       int i;
> +
> +       if (!np->full_name)
> +               return NULL;
> +
> +       name = kbasename(np->full_name);
> +       for (i = 0; i < reserved_mem_count; i++)
> +               if (!strcmp(reserved_mem[i].name, name))
> +                       return &reserved_mem[i];
> +
> +       return NULL;
> +}
> +EXPORT_SYMBOL_GPL(of_reserved_mem_get);
> diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h
> index f8e1992d6423..91b1eb5076e4 100644
> --- a/include/linux/of_reserved_mem.h
> +++ b/include/linux/of_reserved_mem.h
> @@ -44,6 +44,7 @@ int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,
>  void fdt_init_reserved_mem(void);
>  void fdt_reserved_mem_save_node(unsigned long node, const char *uname,
>                                phys_addr_t base, phys_addr_t size);
> +struct reserved_mem *of_reserved_mem_get(struct device_node *np);
>  #else
>  static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
>                                         struct device_node *np, int idx)
> @@ -55,6 +56,10 @@ static inline void of_reserved_mem_device_release(struct device *pdev) { }
>  static inline void fdt_init_reserved_mem(void) { }
>  static inline void fdt_reserved_mem_save_node(unsigned long node,
>                 const char *uname, phys_addr_t base, phys_addr_t size) { }
> +static inline struct reserved_mem *of_reserved_mem_get(struct device_node *np)
> +{
> +       return NULL;
> +}
>  #endif
>
>  /**
> --
> 2.12.0
>

[toc] | [prev] | [next] | [standalone]


#1703540 — Re: [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem

FromBjorn Andersson <bjorn.andersson@linaro.org>
Date2017-08-04 01:40 +0200
SubjectRe: [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem
Message-ID<uaxSG-7aD-7@gated-at.bofh.it>
In reply to#1703309
On Thu 03 Aug 10:45 PDT 2017, Rob Herring wrote:

> On Wed, Aug 2, 2017 at 9:57 PM, Bjorn Andersson
> <bjorn.andersson@linaro.org> wrote:
> > In some cases drivers referencing a reserved-memory region might want to
> > remap the entire region, but when defining the reserved-memory by "size"
> > the client driver has no means to know the associated base address of
> > the reserved memory region.
> >
> > This patch adds an accessor for such drivers to acquire a handle to
> > their associated reserved-memory for this purpose.
> >
> > A complicating factor for the implementation is that the reserved_mem
> > objects are created from the flattened DeviceTree, as such we can't
> > use the device_node address for comparison. Fortunately the name of the
> > node will be used as "name" of the reserved_mem and will be used when
> > building the full_name, so we can compare the "name" with the basename
> > of the full_name to find the match.
> 
> Maybe we should add the device_node pointer when we unflatten?
> 

It did try to figure something sane out in that direction.

The solution I came up with was to amend populate_node() to in a !dryrun
block check if the "dad" full_name is /reserved-memory and if so
call call a new accessor in of_reserved_mem.c to add the "np" to the
reserved_mem object with fdt_node equal offset.

This code path is already cluttered due to the version differences when
it comes to building full_name and we would end up checking for each
node in the entire tree if the parent happens to be "/reserved-mem".

So I went for the less intrusive and more straight forward comparison
with basename(full_name) instead.


Do you have any alternative suggestion of how to do this?

Regards,
Bjorn

[toc] | [prev] | [next] | [standalone]


#1704059

FromRob Herring <robh+dt@kernel.org>
Date2017-08-04 17:00 +0200
Message-ID<uaMf1-8ke-35@gated-at.bofh.it>
In reply to#1703540
On Thu, Aug 3, 2017 at 6:31 PM, Bjorn Andersson
<bjorn.andersson@linaro.org> wrote:
> On Thu 03 Aug 10:45 PDT 2017, Rob Herring wrote:
>
>> On Wed, Aug 2, 2017 at 9:57 PM, Bjorn Andersson
>> <bjorn.andersson@linaro.org> wrote:
>> > In some cases drivers referencing a reserved-memory region might want to
>> > remap the entire region, but when defining the reserved-memory by "size"
>> > the client driver has no means to know the associated base address of
>> > the reserved memory region.
>> >
>> > This patch adds an accessor for such drivers to acquire a handle to
>> > their associated reserved-memory for this purpose.
>> >
>> > A complicating factor for the implementation is that the reserved_mem
>> > objects are created from the flattened DeviceTree, as such we can't
>> > use the device_node address for comparison. Fortunately the name of the
>> > node will be used as "name" of the reserved_mem and will be used when
>> > building the full_name, so we can compare the "name" with the basename
>> > of the full_name to find the match.
>>
>> Maybe we should add the device_node pointer when we unflatten?
>>
>
> It did try to figure something sane out in that direction.
>
> The solution I came up with was to amend populate_node() to in a !dryrun
> block check if the "dad" full_name is /reserved-memory and if so
> call call a new accessor in of_reserved_mem.c to add the "np" to the
> reserved_mem object with fdt_node equal offset.

I was thinking doing it with the unflattened tree just after it has
been unflattened rather than during unflattening.

> This code path is already cluttered due to the version differences when
> it comes to building full_name and we would end up checking for each
> node in the entire tree if the parent happens to be "/reserved-mem".
>
> So I went for the less intrusive and more straight forward comparison
> with basename(full_name) instead.

That's good, because full_name is about to become just the basename.

Rob

[toc] | [prev] | [next] | [standalone]


#1704063 — Re: [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem

FromBjorn Andersson <bjorn.andersson@linaro.org>
Date2017-08-04 17:10 +0200
SubjectRe: [PATCH v2 2/5] of: reserved_mem: Accessor for acquiring reserved_mem
Message-ID<uaMoG-br-19@gated-at.bofh.it>
In reply to#1704059
On Fri 04 Aug 07:50 PDT 2017, Rob Herring wrote:

> On Thu, Aug 3, 2017 at 6:31 PM, Bjorn Andersson
> <bjorn.andersson@linaro.org> wrote:
> > On Thu 03 Aug 10:45 PDT 2017, Rob Herring wrote:
> >
> >> On Wed, Aug 2, 2017 at 9:57 PM, Bjorn Andersson
> >> <bjorn.andersson@linaro.org> wrote:
> >> > In some cases drivers referencing a reserved-memory region might want to
> >> > remap the entire region, but when defining the reserved-memory by "size"
> >> > the client driver has no means to know the associated base address of
> >> > the reserved memory region.
> >> >
> >> > This patch adds an accessor for such drivers to acquire a handle to
> >> > their associated reserved-memory for this purpose.
> >> >
> >> > A complicating factor for the implementation is that the reserved_mem
> >> > objects are created from the flattened DeviceTree, as such we can't
> >> > use the device_node address for comparison. Fortunately the name of the
> >> > node will be used as "name" of the reserved_mem and will be used when
> >> > building the full_name, so we can compare the "name" with the basename
> >> > of the full_name to find the match.
> >>
> >> Maybe we should add the device_node pointer when we unflatten?
> >>
> >
> > It did try to figure something sane out in that direction.
> >
> > The solution I came up with was to amend populate_node() to in a !dryrun
> > block check if the "dad" full_name is /reserved-memory and if so
> > call call a new accessor in of_reserved_mem.c to add the "np" to the
> > reserved_mem object with fdt_node equal offset.
> 
> I was thinking doing it with the unflattened tree just after it has
> been unflattened rather than during unflattening.
> 

The problem is that the fdt_node of the reserved_mem is the offset in
the flat tree, but we don't carry this information with us when we
create the individual device_nodes.

So, AFAICT, to fill out this information at any point after returning
from the particular populate_node() call we will have to use some sort
of heuristics in matching the two nodes.

> > This code path is already cluttered due to the version differences when
> > it comes to building full_name and we would end up checking for each
> > node in the entire tree if the parent happens to be "/reserved-mem".
> >
> > So I went for the less intrusive and more straight forward comparison
> > with basename(full_name) instead.
> 
> That's good, because full_name is about to become just the basename.
> 

I'll update patch 1/5 and resend the series.

Thanks,
Bjorn

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web