diff mbox

[edk2,v2,08/29] ArmVirtualizationPkg: add padding to FDT allocation

Message ID 1422299011-2409-9-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show

Commit Message

Ard Biesheuvel Jan. 26, 2015, 7:03 p.m. UTC
Our primary user QEMU/mach-virt presents us with a FDT blob padded
to 64 KB with plenty of room to set additional properties. However,
in the general case, we should only add properties after making sure
there is enough room available.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

Comments

Ard Biesheuvel Jan. 28, 2015, 4:18 p.m. UTC | #1
On 28 January 2015 at 15:13, Olivier Martin <olivier.martin@arm.com> wrote:
> Same question as last time, would it not be better to have a PCD instead of
> hardcoded value?

Ah yes, I remember reading that but failed to take it into account.

> Some platforms might want to have a larger FDT padding.
>

Agreed. Will add it to v3


>
>> -----Original Message-----
>> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
>> Sent: 26 January 2015 19:03
>> To: edk2-devel@lists.sourceforge.net; lersek@redhat.com; Olivier
>> Martin; roy.franz@linaro.org; leif.lindholm@linaro.org;
>> stefano.stabellini@eu.citrix.com; Ian.Campbell@citrix.com;
>> anthony.perard@citrix.com; christoffer.dall@linaro.org; xen-
>> devel@lists.xen.org; ilias.biris@linaro.org
>> Cc: Ard Biesheuvel
>> Subject: [PATCH v2 08/29] ArmVirtualizationPkg: add padding to FDT
>> allocation
>>
>> Our primary user QEMU/mach-virt presents us with a FDT blob padded
>> to 64 KB with plenty of room to set additional properties. However,
>> in the general case, we should only add properties after making sure
>> there is enough room available.
>>
>> Contributed-under: TianoCore Contribution Agreement 1.0
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> ---
>>
>> ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiL
>> ib.c | 17 ++++++++++++++---
>>  1 file changed, 14 insertions(+), 3 deletions(-)
>>
>> diff --git
>> a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe
>> iLib.c
>> b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe
>> iLib.c
>> index c500d5964b25..42a87309aebe 100644
>> ---
>> a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe
>> iLib.c
>> +++
>> b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPe
>> iLib.c
>> @@ -24,6 +24,15 @@
>>  #include <Guid/EarlyPL011BaseAddress.h>
>>  #include <Guid/FdtHob.h>
>>
>> +//
>> +// We may want to apply some changes to the device tree before passing
>> it
>> +// to the OS: for instance, if we find a PL031 RTC node and attach our
>> +// runtime driver to it, we should disable it in the device tree by
>> setting
>> +// its status property to "disabled". Add some padding to make sure
>> this is
>> +// possible.
>> +//
>> +#define FDT_PADDING   256
>> +
>>  EFI_STATUS
>>  EFIAPI
>>  PlatformPeim (
>> @@ -33,6 +42,7 @@ PlatformPeim (
>>    VOID               *Base;
>>    VOID               *NewBase;
>>    UINTN              FdtSize;
>> +  UINTN              FdtPages;
>>    UINT64             *FdtHobData;
>>    UINT64             *UartHobData;
>>    INT32              Node, Prev;
>> @@ -47,10 +57,11 @@ PlatformPeim (
>>    ASSERT (Base != NULL);
>>    ASSERT (fdt_check_header (Base) == 0);
>>
>> -  FdtSize = fdt_totalsize (Base);
>> -  NewBase = AllocatePages (EFI_SIZE_TO_PAGES (FdtSize));
>> +  FdtSize = fdt_totalsize (Base) + FDT_PADDING;
>> +  FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
>> +  NewBase = AllocatePages (FdtPages);
>>    ASSERT (NewBase != NULL);
>> -  CopyMem (NewBase, Base, FdtSize);
>> +  fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));
>>
>>    FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);
>>    ASSERT (FdtHobData != NULL);
>> --
>> 1.8.3.2
>>
>
>
>
>

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
diff mbox

Patch

diff --git a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c
index c500d5964b25..42a87309aebe 100644
--- a/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c
+++ b/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c
@@ -24,6 +24,15 @@ 
 #include <Guid/EarlyPL011BaseAddress.h>
 #include <Guid/FdtHob.h>
 
+//
+// We may want to apply some changes to the device tree before passing it
+// to the OS: for instance, if we find a PL031 RTC node and attach our
+// runtime driver to it, we should disable it in the device tree by setting
+// its status property to "disabled". Add some padding to make sure this is
+// possible.
+//
+#define FDT_PADDING   256
+
 EFI_STATUS
 EFIAPI
 PlatformPeim (
@@ -33,6 +42,7 @@  PlatformPeim (
   VOID               *Base;
   VOID               *NewBase;
   UINTN              FdtSize;
+  UINTN              FdtPages;
   UINT64             *FdtHobData;
   UINT64             *UartHobData;
   INT32              Node, Prev;
@@ -47,10 +57,11 @@  PlatformPeim (
   ASSERT (Base != NULL);
   ASSERT (fdt_check_header (Base) == 0);
 
-  FdtSize = fdt_totalsize (Base);
-  NewBase = AllocatePages (EFI_SIZE_TO_PAGES (FdtSize));
+  FdtSize = fdt_totalsize (Base) + FDT_PADDING;
+  FdtPages = EFI_SIZE_TO_PAGES (FdtSize);
+  NewBase = AllocatePages (FdtPages);
   ASSERT (NewBase != NULL);
-  CopyMem (NewBase, Base, FdtSize);
+  fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages));
 
   FdtHobData = BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData);
   ASSERT (FdtHobData != NULL);