[PATCH v1 6/6] xen/riscv: relocating and unflattening host device tree

Oleksii Kurochko posted 6 patches 4 weeks, 1 day ago
There is a newer version of this series
[PATCH v1 6/6] xen/riscv: relocating and unflattening host device tree
Posted by Oleksii Kurochko 4 weeks, 1 day ago
Relocate FDT to Xen heap instead of using early mapping as it is
expected that discard_initial_modules() ( is supposed to call in
the future ) discards the FDT boot module and remove_early_mappings()
destroys the early mapping.

Unflatten a device tree, creating the tree of struct device_node.
It also fills the "name" and "type" pointers of the nodes so the normal
device-tree walking functions can be used.

Set device_tree_flattened to NULL in the case when acpi_disabled is
equal to false.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
 xen/arch/riscv/setup.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c
index ff667260ec..41826f77fb 100644
--- a/xen/arch/riscv/setup.c
+++ b/xen/arch/riscv/setup.c
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 
+#include <xen/acpi.h>
 #include <xen/bug.h>
 #include <xen/bootfdt.h>
 #include <xen/compile.h>
@@ -71,6 +72,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
                                paddr_t dtb_addr)
 {
     const char *cmdline;
+    size_t fdt_size;
 
     remove_identity_mapping();
 
@@ -95,7 +97,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
                           _end - _start, false) )
         panic("Failed to add BOOTMOD_XEN\n");
 
-    if ( !boot_fdt_info(device_tree_flattened, dtb_addr) )
+    if ( !(fdt_size = boot_fdt_info(device_tree_flattened, dtb_addr)) )
         BUG();
 
     cmdline = boot_fdt_cmdline(device_tree_flattened);
@@ -114,6 +116,18 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
      */
     system_state = SYS_STATE_boot;
 
+    if ( acpi_disabled )
+    {
+        printk("Booting using Device Tree\n");
+        device_tree_flattened = relocate_fdt(dtb_addr, fdt_size);
+        dt_unflatten_host_device_tree();
+    }
+    else
+    {
+        device_tree_flattened = NULL;
+        panic("Booting using ACPI isn't supported\n");
+    }
+
     printk("All set up\n");
 
     machine_halt();
-- 
2.47.0
Re: [PATCH v1 6/6] xen/riscv: relocating and unflattening host device tree
Posted by Jan Beulich 2 weeks, 3 days ago
On 27.11.2024 13:50, Oleksii Kurochko wrote:
> Relocate FDT to Xen heap instead of using early mapping as it is
> expected that discard_initial_modules() ( is supposed to call in
> the future ) discards the FDT boot module and remove_early_mappings()
> destroys the early mapping.
> 
> Unflatten a device tree, creating the tree of struct device_node.
> It also fills the "name" and "type" pointers of the nodes so the normal
> device-tree walking functions can be used.
> 
> Set device_tree_flattened to NULL in the case when acpi_disabled is
> equal to false.
> 
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

Acked-by: Jan Beulich <jbeulich@suse.com>

Albeit ...

> @@ -71,6 +72,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
>                                 paddr_t dtb_addr)
>  {
>      const char *cmdline;
> +    size_t fdt_size;
>  
>      remove_identity_mapping();
>  
> @@ -95,7 +97,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
>                            _end - _start, false) )
>          panic("Failed to add BOOTMOD_XEN\n");
>  
> -    if ( !boot_fdt_info(device_tree_flattened, dtb_addr) )
> +    if ( !(fdt_size = boot_fdt_info(device_tree_flattened, dtb_addr)) )
>          BUG();

... perhaps better

    fdt_size = boot_fdt_info(device_tree_flattened, dtb_addr);
    BUG_ON(!fdt_size);

?

Jan
Re: [PATCH v1 6/6] xen/riscv: relocating and unflattening host device tree
Posted by Jan Beulich 2 weeks, 3 days ago
On 09.12.2024 16:56, Jan Beulich wrote:
> On 27.11.2024 13:50, Oleksii Kurochko wrote:
>> Relocate FDT to Xen heap instead of using early mapping as it is
>> expected that discard_initial_modules() ( is supposed to call in
>> the future ) discards the FDT boot module and remove_early_mappings()
>> destroys the early mapping.
>>
>> Unflatten a device tree, creating the tree of struct device_node.
>> It also fills the "name" and "type" pointers of the nodes so the normal
>> device-tree walking functions can be used.
>>
>> Set device_tree_flattened to NULL in the case when acpi_disabled is
>> equal to false.
>>
>> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> 
> Acked-by: Jan Beulich <jbeulich@suse.com>
> 
> Albeit ...
> 
>> @@ -71,6 +72,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
>>                                 paddr_t dtb_addr)
>>  {
>>      const char *cmdline;
>> +    size_t fdt_size;
>>  
>>      remove_identity_mapping();
>>  
>> @@ -95,7 +97,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
>>                            _end - _start, false) )
>>          panic("Failed to add BOOTMOD_XEN\n");
>>  
>> -    if ( !boot_fdt_info(device_tree_flattened, dtb_addr) )
>> +    if ( !(fdt_size = boot_fdt_info(device_tree_flattened, dtb_addr)) )
>>          BUG();
> 
> ... perhaps better
> 
>     fdt_size = boot_fdt_info(device_tree_flattened, dtb_addr);
>     BUG_ON(!fdt_size);
> 
> ?

And then I notice that Arm has no such check at all. Better stay in sync?

Jan
Re: [PATCH v1 6/6] xen/riscv: relocating and unflattening host device tree
Posted by Oleksii Kurochko 2 weeks, 2 days ago
On 12/9/24 4:57 PM, Jan Beulich wrote:
> On 09.12.2024 16:56, Jan Beulich wrote:
>> On 27.11.2024 13:50, Oleksii Kurochko wrote:
>>> Relocate FDT to Xen heap instead of using early mapping as it is
>>> expected that discard_initial_modules() ( is supposed to call in
>>> the future ) discards the FDT boot module and remove_early_mappings()
>>> destroys the early mapping.
>>>
>>> Unflatten a device tree, creating the tree of struct device_node.
>>> It also fills the "name" and "type" pointers of the nodes so the normal
>>> device-tree walking functions can be used.
>>>
>>> Set device_tree_flattened to NULL in the case when acpi_disabled is
>>> equal to false.
>>>
>>> Signed-off-by: Oleksii Kurochko<oleksii.kurochko@gmail.com>
>> Acked-by: Jan Beulich<jbeulich@suse.com>
>>
>> Albeit ...
>>
>>> @@ -71,6 +72,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
>>>                                  paddr_t dtb_addr)
>>>   {
>>>       const char *cmdline;
>>> +    size_t fdt_size;
>>>   
>>>       remove_identity_mapping();
>>>   
>>> @@ -95,7 +97,7 @@ void __init noreturn start_xen(unsigned long bootcpu_id,
>>>                             _end - _start, false) )
>>>           panic("Failed to add BOOTMOD_XEN\n");
>>>   
>>> -    if ( !boot_fdt_info(device_tree_flattened, dtb_addr) )
>>> +    if ( !(fdt_size = boot_fdt_info(device_tree_flattened, dtb_addr)) )
>>>           BUG();
>> ... perhaps better
>>
>>      fdt_size = boot_fdt_info(device_tree_flattened, dtb_addr);
>>      BUG_ON(!fdt_size);
>>
>> ?
> And then I notice that Arm has no such check at all. Better stay in sync?

Agree, it is better to be in sync. I will drop the BUG_ON().

Thanks.

~ Oleksii