diff mbox

[Xen-devel,RFC,08/19] xen/dts: Provide an helper to get a DT node from a path provided by a guest

Message ID 1402935486-29136-9-git-send-email-julien.grall@linaro.org
State Superseded, archived
Headers show

Commit Message

Julien Grall June 16, 2014, 4:17 p.m. UTC
Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/common/device_tree.c      |   19 +++++++++++++++++++
 xen/include/xen/device_tree.h |   17 +++++++++++++++++
 2 files changed, 36 insertions(+)

Comments

Ian Campbell July 3, 2014, 11:30 a.m. UTC | #1
On Mon, 2014-06-16 at 17:17 +0100, Julien Grall wrote:
> Signed-off-by: Julien Grall <julien.grall@linaro.org>
> ---
>  xen/common/device_tree.c      |   19 +++++++++++++++++++
>  xen/include/xen/device_tree.h |   17 +++++++++++++++++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
> index 4736e0d..fd95307 100644
> --- a/xen/common/device_tree.c
> +++ b/xen/common/device_tree.c
> @@ -13,6 +13,7 @@
>  #include <xen/config.h>
>  #include <xen/types.h>
>  #include <xen/init.h>
> +#include <xen/guest_access.h>
>  #include <xen/device_tree.h>
>  #include <xen/kernel.h>
>  #include <xen/lib.h>
> @@ -661,6 +662,24 @@ struct dt_device_node *dt_find_node_by_path(const char *path)
>      return np;
>  }
>  
> +int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
> +                          struct dt_device_node **node)

My initial feeling is that this should be a static helper in whichever
file is using this rather than part of the "dt library" interface.

Ian.
Julien Grall July 3, 2014, 11:49 a.m. UTC | #2
Hi Ian,

On 07/03/2014 12:30 PM, Ian Campbell wrote:
> On Mon, 2014-06-16 at 17:17 +0100, Julien Grall wrote:
>> Signed-off-by: Julien Grall <julien.grall@linaro.org>
>> ---
>>  xen/common/device_tree.c      |   19 +++++++++++++++++++
>>  xen/include/xen/device_tree.h |   17 +++++++++++++++++
>>  2 files changed, 36 insertions(+)
>>
>> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
>> index 4736e0d..fd95307 100644
>> --- a/xen/common/device_tree.c
>> +++ b/xen/common/device_tree.c
>> @@ -13,6 +13,7 @@
>>  #include <xen/config.h>
>>  #include <xen/types.h>
>>  #include <xen/init.h>
>> +#include <xen/guest_access.h>
>>  #include <xen/device_tree.h>
>>  #include <xen/kernel.h>
>>  #include <xen/lib.h>
>> @@ -661,6 +662,24 @@ struct dt_device_node *dt_find_node_by_path(const char *path)
>>      return np;
>>  }
>>  
>> +int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
>> +                          struct dt_device_node **node)
> 
> My initial feeling is that this should be a static helper in whichever
> file is using this rather than part of the "dt library" interface.

It's used in 2 different place (see patch #9 and #12).

Regards,
Ian Campbell July 3, 2014, 12:13 p.m. UTC | #3
On Thu, 2014-07-03 at 12:49 +0100, Julien Grall wrote:
> Hi Ian,
> 
> On 07/03/2014 12:30 PM, Ian Campbell wrote:
> > On Mon, 2014-06-16 at 17:17 +0100, Julien Grall wrote:
> >> Signed-off-by: Julien Grall <julien.grall@linaro.org>
> >> ---
> >>  xen/common/device_tree.c      |   19 +++++++++++++++++++
> >>  xen/include/xen/device_tree.h |   17 +++++++++++++++++
> >>  2 files changed, 36 insertions(+)
> >>
> >> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
> >> index 4736e0d..fd95307 100644
> >> --- a/xen/common/device_tree.c
> >> +++ b/xen/common/device_tree.c
> >> @@ -13,6 +13,7 @@
> >>  #include <xen/config.h>
> >>  #include <xen/types.h>
> >>  #include <xen/init.h>
> >> +#include <xen/guest_access.h>
> >>  #include <xen/device_tree.h>
> >>  #include <xen/kernel.h>
> >>  #include <xen/lib.h>
> >> @@ -661,6 +662,24 @@ struct dt_device_node *dt_find_node_by_path(const char *path)
> >>      return np;
> >>  }
> >>  
> >> +int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
> >> +                          struct dt_device_node **node)
> > 
> > My initial feeling is that this should be a static helper in whichever
> > file is using this rather than part of the "dt library" interface.
> 
> It's used in 2 different place (see patch #9 and #12).

domtctl and physdev op I think?

I suppose device_tree.c isn't so bad, I just felt odd putting guest
specific stuff in there.

Ian.
Julien Grall July 3, 2014, 12:22 p.m. UTC | #4
On 07/03/2014 01:13 PM, Ian Campbell wrote:
> On Thu, 2014-07-03 at 12:49 +0100, Julien Grall wrote:
>> Hi Ian,
>>
>> On 07/03/2014 12:30 PM, Ian Campbell wrote:
>>> On Mon, 2014-06-16 at 17:17 +0100, Julien Grall wrote:
>>>> Signed-off-by: Julien Grall <julien.grall@linaro.org>
>>>> ---
>>>>  xen/common/device_tree.c      |   19 +++++++++++++++++++
>>>>  xen/include/xen/device_tree.h |   17 +++++++++++++++++
>>>>  2 files changed, 36 insertions(+)
>>>>
>>>> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
>>>> index 4736e0d..fd95307 100644
>>>> --- a/xen/common/device_tree.c
>>>> +++ b/xen/common/device_tree.c
>>>> @@ -13,6 +13,7 @@
>>>>  #include <xen/config.h>
>>>>  #include <xen/types.h>
>>>>  #include <xen/init.h>
>>>> +#include <xen/guest_access.h>
>>>>  #include <xen/device_tree.h>
>>>>  #include <xen/kernel.h>
>>>>  #include <xen/lib.h>
>>>> @@ -661,6 +662,24 @@ struct dt_device_node *dt_find_node_by_path(const char *path)
>>>>      return np;
>>>>  }
>>>>  
>>>> +int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
>>>> +                          struct dt_device_node **node)
>>>
>>> My initial feeling is that this should be a static helper in whichever
>>> file is using this rather than part of the "dt library" interface.
>>
>> It's used in 2 different place (see patch #9 and #12).
> 
> domtctl and physdev op I think?

Yes.

> I suppose device_tree.c isn't so bad, I just felt odd putting guest
> specific stuff in there.

I can move in arch/arm/guestcopy.c. Even though for me it's not arch
specific but device tree specific.

Regards,
diff mbox

Patch

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 4736e0d..fd95307 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -13,6 +13,7 @@ 
 #include <xen/config.h>
 #include <xen/types.h>
 #include <xen/init.h>
+#include <xen/guest_access.h>
 #include <xen/device_tree.h>
 #include <xen/kernel.h>
 #include <xen/lib.h>
@@ -661,6 +662,24 @@  struct dt_device_node *dt_find_node_by_path(const char *path)
     return np;
 }
 
+int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
+                          struct dt_device_node **node)
+{
+    char *path;
+    int ret;
+
+    ret = copy_string_from_guest(u_path, &path, u_plen,
+                                 DEVICE_TREE_MAX_PATHLEN);
+    if ( ret )
+        return ret;
+
+    *node = dt_find_node_by_path(path);
+
+    xfree(path);
+
+    return (*node == NULL) ? -ESRCH : 0;
+}
+
 struct dt_device_node *dt_find_node_by_alias(const char *alias)
 {
     const struct dt_alias_prop *app;
diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index e413447..bb33e54 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -20,6 +20,9 @@ 
 
 #define DEVICE_TREE_MAX_DEPTH 16
 
+/* This limit is used by the hypercalls to restrict the size of the path */
+#define DEVICE_TREE_MAX_PATHLEN 1024
+
 #define NR_MEM_BANKS 8
 
 #define MOD_XEN    0
@@ -484,6 +487,20 @@  struct dt_device_node *dt_find_node_by_alias(const char *alias);
  */
 struct dt_device_node *dt_find_node_by_path(const char *path);
 
+
+/**
+ * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the
+ * path from the guest
+ *
+ * @u_path: Xen Guest handle to the buffer containing the path
+ * @u_plen: Length of the buffer
+ * @node: TODO
+ *
+ * Return 0 if succeed otherwise -errno
+ */
+int dt_find_node_by_gpath(XEN_GUEST_HANDLE(char) u_path, uint32_t u_plen,
+                          struct dt_device_node **node);
+
 /**
  * dt_get_parent - Get a node's parent if any
  * @node: Node to get parent