On 15.07.2024 16:58, Jan Beulich wrote:
> On 15.07.2024 15:58, Oleksii wrote:
>> On Mon, 2024-07-15 at 10:52 +0200, Jan Beulich wrote:
>>> On 12.07.2024 18:22, Oleksii Kurochko wrote:
>>>> +    rc = map_pages_to_xen(BOOT_FDT_VIRT_START,
>>>> maddr_to_mfn(base_paddr),
>>>> +                          SZ_2M >> PAGE_SHIFT,
>>>> +                          PAGE_HYPERVISOR_RO | _PAGE_BLOCK);
>>>> +    if ( rc )
>>>> +        panic("Unable to map the device-tree.\n");
>>>> +
>>>> +    offset = fdt_paddr % XEN_PT_LEVEL_SIZE(1);
>>>> +    fdt_virt = (void *)BOOT_FDT_VIRT_START + offset;
>>>> +
>>>> +    if ( fdt_magic(fdt_virt) != FDT_MAGIC )
>>>> +        return NULL;
>>>> +
>>>> +    size = fdt_totalsize(fdt_virt);
>>>> +    if ( size > BOOT_FDT_VIRT_SIZE )
>>>> +        return NULL;
>>>> +
>>>> +    if ( (offset + size) > SZ_2M )
>>>> +    {
>>>> +        rc = map_pages_to_xen(BOOT_FDT_VIRT_START + SZ_2M,
>>>> +                              maddr_to_mfn(base_paddr + SZ_2M),
>>>> +                              SZ_2M >> PAGE_SHIFT,
>>>> +                              PAGE_HYPERVISOR_RO | _PAGE_BLOCK);
>>>> +        if ( rc )
>>>> +            panic("Unable to map the device-tree\n");
>>>> +    }
>>>
>>> Why this two part mapping? And why are you mapping perhaps much more
>>> than "size"?
>> I wasn't able to find if RISC-V has a requirement for alignment of FDT
>> address so I decided to follow Arm where FDT is required to be placed
>> on a 8-byte boundary, so FDT can cross a 2MB boundary, so the second
>> 2MB page should be mapped if the FDT is crossing the 2MB boundary.
> 
> This explains why you may need to map more than 2Mb (which wasn't the
> question), but it doesn't explain why you need to do it in two steps.

Oh, wait - you know the full size only after having mapped the initial
part. I'm sorry, I didn't spot that early enough.

Jan

Reply via email to