diff mbox series

[v3,4/6] xen/arm: handle "multiboot, device-tree" compatible nodes

Message ID 20190808231242.26424-4-sstabellini@kernel.org (mailing list archive)
State New, archived
Headers show
Series [v3,1/6] xen/arm: introduce handle_interrupts | expand

Commit Message

Stefano Stabellini Aug. 8, 2019, 11:12 p.m. UTC
Detect "multiboot,device-tree" compatible nodes. Add them to the bootmod
array as BOOTMOD_GUEST_DTB.  In kernel_probe, find the right
BOOTMOD_GUEST_DTB and store a pointer to it in dtb_bootmodule.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>

---
Changes in v2:
- rename BOOTMOD_DTB to BOOTMOD_GUEST_DTB
- rename multiboot,dtb to multiboot,device-tree
---
 xen/arch/arm/bootfdt.c      |  2 ++
 xen/arch/arm/kernel.c       | 12 +++++++++++-
 xen/arch/arm/setup.c        |  1 +
 xen/include/asm-arm/setup.h |  1 +
 4 files changed, 15 insertions(+), 1 deletion(-)

Comments

Volodymyr Babchuk Aug. 9, 2019, 6:32 p.m. UTC | #1
Stefano Stabellini writes:

> Detect "multiboot,device-tree" compatible nodes. Add them to the bootmod
> array as BOOTMOD_GUEST_DTB.  In kernel_probe, find the right
> BOOTMOD_GUEST_DTB and store a pointer to it in dtb_bootmodule.
>
> Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
>
> ---
> Changes in v2:
> - rename BOOTMOD_DTB to BOOTMOD_GUEST_DTB
> - rename multiboot,dtb to multiboot,device-tree
> ---
>  xen/arch/arm/bootfdt.c      |  2 ++
>  xen/arch/arm/kernel.c       | 12 +++++++++++-
>  xen/arch/arm/setup.c        |  1 +
>  xen/include/asm-arm/setup.h |  1 +
>  4 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c
> index 891b4b66ff..4ee1bc314e 100644
> --- a/xen/arch/arm/bootfdt.c
> +++ b/xen/arch/arm/bootfdt.c
> @@ -205,6 +205,8 @@ static void __init process_multiboot_node(const void *fdt, int node,
>          kind = BOOTMOD_RAMDISK;
>      else if ( fdt_node_check_compatible(fdt, node, "xen,xsm-policy") == 0 )
>          kind = BOOTMOD_XSM;
> +    else if ( fdt_node_check_compatible(fdt, node, "multiboot,device-tree") == 0 )
> +        kind = BOOTMOD_GUEST_DTB;
>      else
>          kind = BOOTMOD_UNKNOWN;
>  
> diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
> index 389bef2afa..997a871f62 100644
> --- a/xen/arch/arm/kernel.c
> +++ b/xen/arch/arm/kernel.c
> @@ -425,7 +425,7 @@ int __init kernel_probe(struct kernel_info *info,
>      struct bootmodule *mod = NULL;
>      struct bootcmdline *cmd = NULL;
>      struct dt_device_node *node;
> -    u64 kernel_addr, initrd_addr, size;
> +    u64 kernel_addr = 0, initrd_addr = 0, dtb_addr = 0, size;
It is unclear for my why are you initialize those variables with 0

>      int rc;
>  
>      /* domain is NULL only for the hardware domain */
> @@ -469,6 +469,16 @@ int __init kernel_probe(struct kernel_info *info,
>                  info->initrd_bootmodule = boot_module_find_by_addr_and_kind(
>                          BOOTMOD_RAMDISK, initrd_addr);
>              }
> +            else if ( dt_device_is_compatible(node, "multiboot,device-tree") )
> +            {
> +                u32 len;
> +                const __be32 *val;
> +
> +                val = dt_get_property(node, "reg", &len);
Do you need to check return value there?

> +                dt_get_range(&val, node, &dtb_addr, &size);
> +                info->dtb_bootmodule = boot_module_find_by_addr_and_kind(
> +                        BOOTMOD_GUEST_DTB, dtb_addr);
> +            }
>              else
>                  continue;
>          }
> diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> index 215746a5c3..f93a8bed04 100644
> --- a/xen/arch/arm/setup.c
> +++ b/xen/arch/arm/setup.c
> @@ -347,6 +347,7 @@ const char * __init boot_module_kind_as_string(bootmodule_kind kind)
>      case BOOTMOD_KERNEL:  return "Kernel";
>      case BOOTMOD_RAMDISK: return "Ramdisk";
>      case BOOTMOD_XSM:     return "XSM";
> +    case BOOTMOD_GUEST_DTB:     return "DTB";
>      case BOOTMOD_UNKNOWN: return "Unknown";
>      default: BUG();
>      }
> diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h
> index 8bf3d5910a..5aaf07bf97 100644
> --- a/xen/include/asm-arm/setup.h
> +++ b/xen/include/asm-arm/setup.h
> @@ -16,6 +16,7 @@ typedef enum {
>      BOOTMOD_KERNEL,
>      BOOTMOD_RAMDISK,
>      BOOTMOD_XSM,
> +    BOOTMOD_GUEST_DTB,
>      BOOTMOD_UNKNOWN
>  }  bootmodule_kind;
Julien Grall Aug. 9, 2019, 8:14 p.m. UTC | #2
Hi Stefano,

On 8/9/19 12:12 AM, Stefano Stabellini wrote:
> Detect "multiboot,device-tree" compatible nodes. Add them to the bootmod
> array as BOOTMOD_GUEST_DTB.  In kernel_probe, find the right
> BOOTMOD_GUEST_DTB and store a pointer to it in dtb_bootmodule.
> 
> Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> 
> ---
> Changes in v2:
> - rename BOOTMOD_DTB to BOOTMOD_GUEST_DTB
> - rename multiboot,dtb to multiboot,device-tree
> ---
>   xen/arch/arm/bootfdt.c      |  2 ++
>   xen/arch/arm/kernel.c       | 12 +++++++++++-
>   xen/arch/arm/setup.c        |  1 +
>   xen/include/asm-arm/setup.h |  1 +
>   4 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c
> index 891b4b66ff..4ee1bc314e 100644
> --- a/xen/arch/arm/bootfdt.c
> +++ b/xen/arch/arm/bootfdt.c
> @@ -205,6 +205,8 @@ static void __init process_multiboot_node(const void *fdt, int node,
>           kind = BOOTMOD_RAMDISK;
>       else if ( fdt_node_check_compatible(fdt, node, "xen,xsm-policy") == 0 )
>           kind = BOOTMOD_XSM;
> +    else if ( fdt_node_check_compatible(fdt, node, "multiboot,device-tree") == 0 )
> +        kind = BOOTMOD_GUEST_DTB;

AFAICT, this function will only be executed if the compatible 
multiboot,module or xen,multiboot-module is also present. But this is 
not documented in booting.txt.

>       else
>           kind = BOOTMOD_UNKNOWN;
>   
> diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
> index 389bef2afa..997a871f62 100644
> --- a/xen/arch/arm/kernel.c
> +++ b/xen/arch/arm/kernel.c
> @@ -425,7 +425,7 @@ int __init kernel_probe(struct kernel_info *info,
>       struct bootmodule *mod = NULL;
>       struct bootcmdline *cmd = NULL;
>       struct dt_device_node *node;
> -    u64 kernel_addr, initrd_addr, size;
> +    u64 kernel_addr = 0, initrd_addr = 0, dtb_addr = 0, size;
>       int rc;
>   
>       /* domain is NULL only for the hardware domain */
> @@ -469,6 +469,16 @@ int __init kernel_probe(struct kernel_info *info,
>                   info->initrd_bootmodule = boot_module_find_by_addr_and_kind(
>                           BOOTMOD_RAMDISK, initrd_addr);
>               }
> +            else if ( dt_device_is_compatible(node, "multiboot,device-tree") )
> +            {
> +                u32 len;

No more u32. Please use uint32_t instead.

> +                const __be32 *val;
> +
> +                val = dt_get_property(node, "reg", &len);
> +                dt_get_range(&val, node, &dtb_addr, &size);
> +                info->dtb_bootmodule = boot_module_find_by_addr_and_kind(
> +                        BOOTMOD_GUEST_DTB, dtb_addr);
> +            }
>               else
>                   continue;
>           }
> diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> index 215746a5c3..f93a8bed04 100644
> --- a/xen/arch/arm/setup.c
> +++ b/xen/arch/arm/setup.c
> @@ -347,6 +347,7 @@ const char * __init boot_module_kind_as_string(bootmodule_kind kind)
>       case BOOTMOD_KERNEL:  return "Kernel";
>       case BOOTMOD_RAMDISK: return "Ramdisk";
>       case BOOTMOD_XSM:     return "XSM";
> +    case BOOTMOD_GUEST_DTB:     return "DTB";
>       case BOOTMOD_UNKNOWN: return "Unknown";
>       default: BUG();
>       }
> diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h
> index 8bf3d5910a..5aaf07bf97 100644
> --- a/xen/include/asm-arm/setup.h
> +++ b/xen/include/asm-arm/setup.h
> @@ -16,6 +16,7 @@ typedef enum {
>       BOOTMOD_KERNEL,
>       BOOTMOD_RAMDISK,
>       BOOTMOD_XSM,
> +    BOOTMOD_GUEST_DTB,
>       BOOTMOD_UNKNOWN
>   }  bootmodule_kind;
>   
> 

Cheers,
Stefano Stabellini Aug. 20, 2019, 12:23 a.m. UTC | #3
On Fri, 9 Aug 2019, Volodymyr Babchuk wrote:
> Stefano Stabellini writes:
> 
> > Detect "multiboot,device-tree" compatible nodes. Add them to the bootmod
> > array as BOOTMOD_GUEST_DTB.  In kernel_probe, find the right
> > BOOTMOD_GUEST_DTB and store a pointer to it in dtb_bootmodule.
> >
> > Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> >
> > ---
> > Changes in v2:
> > - rename BOOTMOD_DTB to BOOTMOD_GUEST_DTB
> > - rename multiboot,dtb to multiboot,device-tree
> > ---
> >  xen/arch/arm/bootfdt.c      |  2 ++
> >  xen/arch/arm/kernel.c       | 12 +++++++++++-
> >  xen/arch/arm/setup.c        |  1 +
> >  xen/include/asm-arm/setup.h |  1 +
> >  4 files changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c
> > index 891b4b66ff..4ee1bc314e 100644
> > --- a/xen/arch/arm/bootfdt.c
> > +++ b/xen/arch/arm/bootfdt.c
> > @@ -205,6 +205,8 @@ static void __init process_multiboot_node(const void *fdt, int node,
> >          kind = BOOTMOD_RAMDISK;
> >      else if ( fdt_node_check_compatible(fdt, node, "xen,xsm-policy") == 0 )
> >          kind = BOOTMOD_XSM;
> > +    else if ( fdt_node_check_compatible(fdt, node, "multiboot,device-tree") == 0 )
> > +        kind = BOOTMOD_GUEST_DTB;
> >      else
> >          kind = BOOTMOD_UNKNOWN;
> >  
> > diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
> > index 389bef2afa..997a871f62 100644
> > --- a/xen/arch/arm/kernel.c
> > +++ b/xen/arch/arm/kernel.c
> > @@ -425,7 +425,7 @@ int __init kernel_probe(struct kernel_info *info,
> >      struct bootmodule *mod = NULL;
> >      struct bootcmdline *cmd = NULL;
> >      struct dt_device_node *node;
> > -    u64 kernel_addr, initrd_addr, size;
> > +    u64 kernel_addr = 0, initrd_addr = 0, dtb_addr = 0, size;
> It is unclear for my why are you initialize those variables with 0

Good point, they are unnecessary


> >      int rc;
> >  
> >      /* domain is NULL only for the hardware domain */
> > @@ -469,6 +469,16 @@ int __init kernel_probe(struct kernel_info *info,
> >                  info->initrd_bootmodule = boot_module_find_by_addr_and_kind(
> >                          BOOTMOD_RAMDISK, initrd_addr);
> >              }
> > +            else if ( dt_device_is_compatible(node, "multiboot,device-tree") )
> > +            {
> > +                u32 len;
> > +                const __be32 *val;
> > +
> > +                val = dt_get_property(node, "reg", &len);
> Do you need to check return value there?

I'll add a check


> > +                dt_get_range(&val, node, &dtb_addr, &size);
> > +                info->dtb_bootmodule = boot_module_find_by_addr_and_kind(
> > +                        BOOTMOD_GUEST_DTB, dtb_addr);
> > +            }
> >              else
> >                  continue;
> >          }
> > diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> > index 215746a5c3..f93a8bed04 100644
> > --- a/xen/arch/arm/setup.c
> > +++ b/xen/arch/arm/setup.c
> > @@ -347,6 +347,7 @@ const char * __init boot_module_kind_as_string(bootmodule_kind kind)
> >      case BOOTMOD_KERNEL:  return "Kernel";
> >      case BOOTMOD_RAMDISK: return "Ramdisk";
> >      case BOOTMOD_XSM:     return "XSM";
> > +    case BOOTMOD_GUEST_DTB:     return "DTB";
> >      case BOOTMOD_UNKNOWN: return "Unknown";
> >      default: BUG();
> >      }
> > diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h
> > index 8bf3d5910a..5aaf07bf97 100644
> > --- a/xen/include/asm-arm/setup.h
> > +++ b/xen/include/asm-arm/setup.h
> > @@ -16,6 +16,7 @@ typedef enum {
> >      BOOTMOD_KERNEL,
> >      BOOTMOD_RAMDISK,
> >      BOOTMOD_XSM,
> > +    BOOTMOD_GUEST_DTB,
> >      BOOTMOD_UNKNOWN
> >  }  bootmodule_kind;
> 
> 
> -- 
> Volodymyr Babchuk at EPAM
Stefano Stabellini Aug. 20, 2019, 12:45 a.m. UTC | #4
On Fri, 9 Aug 2019, Julien Grall wrote:
> Hi Stefano,
> 
> On 8/9/19 12:12 AM, Stefano Stabellini wrote:
> > Detect "multiboot,device-tree" compatible nodes. Add them to the bootmod
> > array as BOOTMOD_GUEST_DTB.  In kernel_probe, find the right
> > BOOTMOD_GUEST_DTB and store a pointer to it in dtb_bootmodule.
> > 
> > Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> > 
> > ---
> > Changes in v2:
> > - rename BOOTMOD_DTB to BOOTMOD_GUEST_DTB
> > - rename multiboot,dtb to multiboot,device-tree
> > ---
> >   xen/arch/arm/bootfdt.c      |  2 ++
> >   xen/arch/arm/kernel.c       | 12 +++++++++++-
> >   xen/arch/arm/setup.c        |  1 +
> >   xen/include/asm-arm/setup.h |  1 +
> >   4 files changed, 15 insertions(+), 1 deletion(-)
> > 
> > diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c
> > index 891b4b66ff..4ee1bc314e 100644
> > --- a/xen/arch/arm/bootfdt.c
> > +++ b/xen/arch/arm/bootfdt.c
> > @@ -205,6 +205,8 @@ static void __init process_multiboot_node(const void
> > *fdt, int node,
> >           kind = BOOTMOD_RAMDISK;
> >       else if ( fdt_node_check_compatible(fdt, node, "xen,xsm-policy") == 0
> > )
> >           kind = BOOTMOD_XSM;
> > +    else if ( fdt_node_check_compatible(fdt, node, "multiboot,device-tree")
> > == 0 )
> > +        kind = BOOTMOD_GUEST_DTB;
> 
> AFAICT, this function will only be executed if the compatible multiboot,module
> or xen,multiboot-module is also present. But this is not documented in
> booting.txt.

That's a good point, I added it to the doc


> >       else
> >           kind = BOOTMOD_UNKNOWN;
> >   diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
> > index 389bef2afa..997a871f62 100644
> > --- a/xen/arch/arm/kernel.c
> > +++ b/xen/arch/arm/kernel.c
> > @@ -425,7 +425,7 @@ int __init kernel_probe(struct kernel_info *info,
> >       struct bootmodule *mod = NULL;
> >       struct bootcmdline *cmd = NULL;
> >       struct dt_device_node *node;
> > -    u64 kernel_addr, initrd_addr, size;
> > +    u64 kernel_addr = 0, initrd_addr = 0, dtb_addr = 0, size;
> >       int rc;
> >         /* domain is NULL only for the hardware domain */
> > @@ -469,6 +469,16 @@ int __init kernel_probe(struct kernel_info *info,
> >                   info->initrd_bootmodule =
> > boot_module_find_by_addr_and_kind(
> >                           BOOTMOD_RAMDISK, initrd_addr);
> >               }
> > +            else if ( dt_device_is_compatible(node,
> > "multiboot,device-tree") )
> > +            {
> > +                u32 len;
> 
> No more u32. Please use uint32_t instead.

Ok, got it


> > +                const __be32 *val;
> > +
> > +                val = dt_get_property(node, "reg", &len);
> > +                dt_get_range(&val, node, &dtb_addr, &size);
> > +                info->dtb_bootmodule = boot_module_find_by_addr_and_kind(
> > +                        BOOTMOD_GUEST_DTB, dtb_addr);
> > +            }
> >               else
> >                   continue;
> >           }
> > diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
> > index 215746a5c3..f93a8bed04 100644
> > --- a/xen/arch/arm/setup.c
> > +++ b/xen/arch/arm/setup.c
> > @@ -347,6 +347,7 @@ const char * __init
> > boot_module_kind_as_string(bootmodule_kind kind)
> >       case BOOTMOD_KERNEL:  return "Kernel";
> >       case BOOTMOD_RAMDISK: return "Ramdisk";
> >       case BOOTMOD_XSM:     return "XSM";
> > +    case BOOTMOD_GUEST_DTB:     return "DTB";
> >       case BOOTMOD_UNKNOWN: return "Unknown";
> >       default: BUG();
> >       }
> > diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h
> > index 8bf3d5910a..5aaf07bf97 100644
> > --- a/xen/include/asm-arm/setup.h
> > +++ b/xen/include/asm-arm/setup.h
> > @@ -16,6 +16,7 @@ typedef enum {
> >       BOOTMOD_KERNEL,
> >       BOOTMOD_RAMDISK,
> >       BOOTMOD_XSM,
> > +    BOOTMOD_GUEST_DTB,
> >       BOOTMOD_UNKNOWN
> >   }  bootmodule_kind;
> >   
> 
> Cheers,
> 
> -- 
> Julien Grall
>
diff mbox series

Patch

diff --git a/xen/arch/arm/bootfdt.c b/xen/arch/arm/bootfdt.c
index 891b4b66ff..4ee1bc314e 100644
--- a/xen/arch/arm/bootfdt.c
+++ b/xen/arch/arm/bootfdt.c
@@ -205,6 +205,8 @@  static void __init process_multiboot_node(const void *fdt, int node,
         kind = BOOTMOD_RAMDISK;
     else if ( fdt_node_check_compatible(fdt, node, "xen,xsm-policy") == 0 )
         kind = BOOTMOD_XSM;
+    else if ( fdt_node_check_compatible(fdt, node, "multiboot,device-tree") == 0 )
+        kind = BOOTMOD_GUEST_DTB;
     else
         kind = BOOTMOD_UNKNOWN;
 
diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c
index 389bef2afa..997a871f62 100644
--- a/xen/arch/arm/kernel.c
+++ b/xen/arch/arm/kernel.c
@@ -425,7 +425,7 @@  int __init kernel_probe(struct kernel_info *info,
     struct bootmodule *mod = NULL;
     struct bootcmdline *cmd = NULL;
     struct dt_device_node *node;
-    u64 kernel_addr, initrd_addr, size;
+    u64 kernel_addr = 0, initrd_addr = 0, dtb_addr = 0, size;
     int rc;
 
     /* domain is NULL only for the hardware domain */
@@ -469,6 +469,16 @@  int __init kernel_probe(struct kernel_info *info,
                 info->initrd_bootmodule = boot_module_find_by_addr_and_kind(
                         BOOTMOD_RAMDISK, initrd_addr);
             }
+            else if ( dt_device_is_compatible(node, "multiboot,device-tree") )
+            {
+                u32 len;
+                const __be32 *val;
+
+                val = dt_get_property(node, "reg", &len);
+                dt_get_range(&val, node, &dtb_addr, &size);
+                info->dtb_bootmodule = boot_module_find_by_addr_and_kind(
+                        BOOTMOD_GUEST_DTB, dtb_addr);
+            }
             else
                 continue;
         }
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 215746a5c3..f93a8bed04 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -347,6 +347,7 @@  const char * __init boot_module_kind_as_string(bootmodule_kind kind)
     case BOOTMOD_KERNEL:  return "Kernel";
     case BOOTMOD_RAMDISK: return "Ramdisk";
     case BOOTMOD_XSM:     return "XSM";
+    case BOOTMOD_GUEST_DTB:     return "DTB";
     case BOOTMOD_UNKNOWN: return "Unknown";
     default: BUG();
     }
diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h
index 8bf3d5910a..5aaf07bf97 100644
--- a/xen/include/asm-arm/setup.h
+++ b/xen/include/asm-arm/setup.h
@@ -16,6 +16,7 @@  typedef enum {
     BOOTMOD_KERNEL,
     BOOTMOD_RAMDISK,
     BOOTMOD_XSM,
+    BOOTMOD_GUEST_DTB,
     BOOTMOD_UNKNOWN
 }  bootmodule_kind;