Re: [U-Boot] [PATCH 4/9] armv8: layerscape: Rewrite memory reservation

2017-02-15 Thread Alexander Graf



On 15/02/2017 19:52, york sun wrote:

Reduce CC list.

On 02/14/2017 11:56 AM, Alexander Graf wrote:



On 14/02/2017 18:38, york sun wrote:

On 02/14/2017 09:00 AM, york@nxp.com wrote:

On 02/14/2017 07:31 AM, Alexander Graf wrote:



On 14/02/2017 04:45, York Sun wrote:

For ARMv8 Layerscape SoCs, secure memory and MC memorey are reserved
at the end of DDR. DDR is spit into two or three banks. This patch
reverts commit aabd7ddb and simplifies the calculation of reserved
memory, and moves the code into common SoC file. Secure memory is
carved out first. DDR bank size is reduced. Reserved memory is then
allocated on the top of available memory. U-Boot still has access
to reserved memory as data transferring is needed. Device tree is
fixed with reduced memory size to hide the reserved memory from OS.


I haven't looked in detail, but could you please ensure that you also
reserve those regions in the efi_loader memory map?


I missed efi reserved memory map. Will add in v2 patch.



Alex,

Is the misc_init_r() the best place to add such reservation under your
code dealing with DP_DDR? It is per board code. As of now, we only have
ls2080ardb with efi boot.


Ideally I'd like to make sure efi boot works on all boards, not just
individual ones. So if you find a more generic place that gets called
after efi_memory_init(), that would be great.

Since you add a global kconfig define for reserved memory, you can even
do it inside efi_memory_init() directly for the top-of-ram region.



Alex,

I am thinking to add a weak function efi_add_known_memory() to do the
work you have at the beginning of efi_memory_init(). Then I will add
this function to arch/arm/cpu/armv8/fsl-layerscape/cpu.c. Since the SoC
file has the knowledge of DP-DDR and how memory is reserved, it can be
easily added without risking breaking anything else.


That's certainly a possibility, yes :).


By the way, I failed to run distro boot as I set up before. I am going
to re-download the DVD ISO file and deploy it again to my USB thumb
drive. Any tips on running it without installation, i.e. live CD mode? I
remember last time I did some trick to drop to the shell.


Grub should give you a rescue menu item which gets you into a shell, 
yes. Inside the installer you can also exit into a very minimalistic 
shell if you like, but it's not very powerful.



Alex
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 4/9] armv8: layerscape: Rewrite memory reservation

2017-02-15 Thread york sun
Reduce CC list.

On 02/14/2017 11:56 AM, Alexander Graf wrote:
>
>
> On 14/02/2017 18:38, york sun wrote:
>> On 02/14/2017 09:00 AM, york@nxp.com wrote:
>>> On 02/14/2017 07:31 AM, Alexander Graf wrote:


 On 14/02/2017 04:45, York Sun wrote:
> For ARMv8 Layerscape SoCs, secure memory and MC memorey are reserved
> at the end of DDR. DDR is spit into two or three banks. This patch
> reverts commit aabd7ddb and simplifies the calculation of reserved
> memory, and moves the code into common SoC file. Secure memory is
> carved out first. DDR bank size is reduced. Reserved memory is then
> allocated on the top of available memory. U-Boot still has access
> to reserved memory as data transferring is needed. Device tree is
> fixed with reduced memory size to hide the reserved memory from OS.

 I haven't looked in detail, but could you please ensure that you also
 reserve those regions in the efi_loader memory map?
>>>
>>> I missed efi reserved memory map. Will add in v2 patch.
>>>
>>
>> Alex,
>>
>> Is the misc_init_r() the best place to add such reservation under your
>> code dealing with DP_DDR? It is per board code. As of now, we only have
>> ls2080ardb with efi boot.
>
> Ideally I'd like to make sure efi boot works on all boards, not just
> individual ones. So if you find a more generic place that gets called
> after efi_memory_init(), that would be great.
>
> Since you add a global kconfig define for reserved memory, you can even
> do it inside efi_memory_init() directly for the top-of-ram region.
>

Alex,

I am thinking to add a weak function efi_add_known_memory() to do the 
work you have at the beginning of efi_memory_init(). Then I will add 
this function to arch/arm/cpu/armv8/fsl-layerscape/cpu.c. Since the SoC 
file has the knowledge of DP-DDR and how memory is reserved, it can be 
easily added without risking breaking anything else.

By the way, I failed to run distro boot as I set up before. I am going 
to re-download the DVD ISO file and deploy it again to my USB thumb 
drive. Any tips on running it without installation, i.e. live CD mode? I 
remember last time I did some trick to drop to the shell.

York

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 4/9] armv8: layerscape: Rewrite memory reservation

2017-02-14 Thread york sun
On 02/14/2017 11:56 AM, Alexander Graf wrote:
>
>
> On 14/02/2017 18:38, york sun wrote:
>> On 02/14/2017 09:00 AM, york@nxp.com wrote:
>>> On 02/14/2017 07:31 AM, Alexander Graf wrote:


 On 14/02/2017 04:45, York Sun wrote:
> For ARMv8 Layerscape SoCs, secure memory and MC memorey are reserved
> at the end of DDR. DDR is spit into two or three banks. This patch
> reverts commit aabd7ddb and simplifies the calculation of reserved
> memory, and moves the code into common SoC file. Secure memory is
> carved out first. DDR bank size is reduced. Reserved memory is then
> allocated on the top of available memory. U-Boot still has access
> to reserved memory as data transferring is needed. Device tree is
> fixed with reduced memory size to hide the reserved memory from OS.

 I haven't looked in detail, but could you please ensure that you also
 reserve those regions in the efi_loader memory map?
>>>
>>> I missed efi reserved memory map. Will add in v2 patch.
>>>
>>
>> Alex,
>>
>> Is the misc_init_r() the best place to add such reservation under your
>> code dealing with DP_DDR? It is per board code. As of now, we only have
>> ls2080ardb with efi boot.
>
> Ideally I'd like to make sure efi boot works on all boards, not just
> individual ones. So if you find a more generic place that gets called
> after efi_memory_init(), that would be great.
>
> Since you add a global kconfig define for reserved memory, you can even
> do it inside efi_memory_init() directly for the top-of-ram region.
>

I think it will be a good idea to put into efi_memory_init(), where the 
memory is added.

York

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 4/9] armv8: layerscape: Rewrite memory reservation

2017-02-14 Thread Alexander Graf



On 14/02/2017 18:38, york sun wrote:

On 02/14/2017 09:00 AM, york@nxp.com wrote:

On 02/14/2017 07:31 AM, Alexander Graf wrote:



On 14/02/2017 04:45, York Sun wrote:

For ARMv8 Layerscape SoCs, secure memory and MC memorey are reserved
at the end of DDR. DDR is spit into two or three banks. This patch
reverts commit aabd7ddb and simplifies the calculation of reserved
memory, and moves the code into common SoC file. Secure memory is
carved out first. DDR bank size is reduced. Reserved memory is then
allocated on the top of available memory. U-Boot still has access
to reserved memory as data transferring is needed. Device tree is
fixed with reduced memory size to hide the reserved memory from OS.


I haven't looked in detail, but could you please ensure that you also
reserve those regions in the efi_loader memory map?


I missed efi reserved memory map. Will add in v2 patch.



Alex,

Is the misc_init_r() the best place to add such reservation under your
code dealing with DP_DDR? It is per board code. As of now, we only have
ls2080ardb with efi boot.


Ideally I'd like to make sure efi boot works on all boards, not just 
individual ones. So if you find a more generic place that gets called 
after efi_memory_init(), that would be great.


Since you add a global kconfig define for reserved memory, you can even 
do it inside efi_memory_init() directly for the top-of-ram region.



Alex
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 4/9] armv8: layerscape: Rewrite memory reservation

2017-02-14 Thread york sun
On 02/14/2017 09:00 AM, york@nxp.com wrote:
> On 02/14/2017 07:31 AM, Alexander Graf wrote:
>>
>>
>> On 14/02/2017 04:45, York Sun wrote:
>>> For ARMv8 Layerscape SoCs, secure memory and MC memorey are reserved
>>> at the end of DDR. DDR is spit into two or three banks. This patch
>>> reverts commit aabd7ddb and simplifies the calculation of reserved
>>> memory, and moves the code into common SoC file. Secure memory is
>>> carved out first. DDR bank size is reduced. Reserved memory is then
>>> allocated on the top of available memory. U-Boot still has access
>>> to reserved memory as data transferring is needed. Device tree is
>>> fixed with reduced memory size to hide the reserved memory from OS.
>>
>> I haven't looked in detail, but could you please ensure that you also
>> reserve those regions in the efi_loader memory map?
>
> I missed efi reserved memory map. Will add in v2 patch.
>

Alex,

Is the misc_init_r() the best place to add such reservation under your 
code dealing with DP_DDR? It is per board code. As of now, we only have 
ls2080ardb with efi boot.

York

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 4/9] armv8: layerscape: Rewrite memory reservation

2017-02-14 Thread york sun
On 02/14/2017 07:31 AM, Alexander Graf wrote:
>
>
> On 14/02/2017 04:45, York Sun wrote:
>> For ARMv8 Layerscape SoCs, secure memory and MC memorey are reserved
>> at the end of DDR. DDR is spit into two or three banks. This patch
>> reverts commit aabd7ddb and simplifies the calculation of reserved
>> memory, and moves the code into common SoC file. Secure memory is
>> carved out first. DDR bank size is reduced. Reserved memory is then
>> allocated on the top of available memory. U-Boot still has access
>> to reserved memory as data transferring is needed. Device tree is
>> fixed with reduced memory size to hide the reserved memory from OS.
>
> I haven't looked in detail, but could you please ensure that you also
> reserve those regions in the efi_loader memory map?

I missed efi reserved memory map. Will add in v2 patch.

York

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 4/9] armv8: layerscape: Rewrite memory reservation

2017-02-14 Thread Alexander Graf



On 14/02/2017 04:45, York Sun wrote:

For ARMv8 Layerscape SoCs, secure memory and MC memorey are reserved
at the end of DDR. DDR is spit into two or three banks. This patch
reverts commit aabd7ddb and simplifies the calculation of reserved
memory, and moves the code into common SoC file. Secure memory is
carved out first. DDR bank size is reduced. Reserved memory is then
allocated on the top of available memory. U-Boot still has access
to reserved memory as data transferring is needed. Device tree is
fixed with reduced memory size to hide the reserved memory from OS.


I haven't looked in detail, but could you please ensure that you also 
reserve those regions in the efi_loader memory map?



Alex
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 4/9] armv8: layerscape: Rewrite memory reservation

2017-02-13 Thread York Sun
For ARMv8 Layerscape SoCs, secure memory and MC memorey are reserved
at the end of DDR. DDR is spit into two or three banks. This patch
reverts commit aabd7ddb and simplifies the calculation of reserved
memory, and moves the code into common SoC file. Secure memory is
carved out first. DDR bank size is reduced. Reserved memory is then
allocated on the top of available memory. U-Boot still has access
to reserved memory as data transferring is needed. Device tree is
fixed with reduced memory size to hide the reserved memory from OS.

Signed-off-by: York Sun 
---

 arch/arm/cpu/armv8/fsl-layerscape/cpu.c   | 165 +-
 arch/arm/include/asm/arch-fsl-layerscape/config.h |   4 +-
 board/freescale/ls1012afrdm/ls1012afrdm.c |  29 
 board/freescale/ls1012aqds/ls1012aqds.c   |  29 
 board/freescale/ls1012ardb/ls1012ardb.c   |  29 
 board/freescale/ls1043aqds/ddr.c  |  29 
 board/freescale/ls1043ardb/ddr.c  |  29 
 board/freescale/ls1046aqds/ddr.c  |  29 
 board/freescale/ls1046ardb/ddr.c  |  29 
 board/freescale/ls2080a/ddr.c |  55 
 board/freescale/ls2080a/ls2080a.c |  10 ++
 board/freescale/ls2080aqds/ddr.c  |  55 
 board/freescale/ls2080aqds/ls2080aqds.c   |  10 ++
 board/freescale/ls2080ardb/ddr.c  |  55 
 board/freescale/ls2080ardb/ls2080ardb.c   |  10 ++
 common/board_f.c  |  32 ++---
 drivers/net/fsl-mc/mc.c   |  16 +--
 17 files changed, 200 insertions(+), 415 deletions(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c 
b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
index 335f225..6e68cd3 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/cpu.c
@@ -524,15 +524,168 @@ phys_size_t board_reserve_ram_top(phys_size_t ram_size)
 {
phys_size_t ram_top = ram_size;
 
-#ifdef CONFIG_SYS_MEM_TOP_HIDE
-#error CONFIG_SYS_MEM_TOP_HIDE not to be used together with this function
-#endif
-
-/* Carve the MC private DRAM block from the end of DRAM */
 #ifdef CONFIG_FSL_MC_ENET
+   /* The start address of MC reserved memory needs to be aligned. */
ram_top -= mc_get_dram_block_size();
ram_top &= ~(CONFIG_SYS_MC_RSV_MEM_ALIGN - 1);
 #endif
 
-   return ram_top;
+   return ram_size - ram_top;
+}
+
+phys_size_t get_effective_memsize(void)
+{
+   phys_size_t ea_size, rem = 0;
+
+   /*
+* For ARMv8 SoCs, DDR memory is split into two or three regions. The
+* first region is 2GB space at 0x8000_. If the memory extends to
+* the second region (or the third region if applicable), the secure
+* memory and Management Complex (MC) memory should be put into the
+* highest region, i.e. the end of DDR memory. CONFIG_MAX_MEM_MAPPED
+* is set to the size of first region so U-Boot doesn't relocate itself
+* into higher address. Should DDR be configured to skip the first
+* region, this function needs to be adjusted.
+*/
+   if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
+   ea_size = CONFIG_MAX_MEM_MAPPED;
+   rem = gd->ram_size - ea_size;
+   } else {
+   ea_size = gd->ram_size;
+   }
+
+#ifdef CONFIG_SYS_MEM_RESERVE_SECURE
+   /* Check if we have enough space for secure memory */
+   if (rem > CONFIG_SYS_MEM_RESERVE_SECURE) {
+   rem -= CONFIG_SYS_MEM_RESERVE_SECURE;
+   } else {
+   if (ea_size > CONFIG_SYS_MEM_RESERVE_SECURE) {
+   ea_size -= CONFIG_SYS_MEM_RESERVE_SECURE;
+   rem = 0;/* Presume MC requires more memory */
+   } else {
+   printf("Error: No enough space for secure memory.\n");
+   }
+   }
+#endif
+   /* Check if we have enough memory for MC */
+   if (rem < board_reserve_ram_top(rem)) {
+   /* Not enough memory in high region to reserve */
+   if (ea_size > board_reserve_ram_top(rem))
+   ea_size -= board_reserve_ram_top(rem);
+   else
+   printf("Error: No enough space for reserved memory.\n");
+   }
+
+   return ea_size;
+}
+
+void dram_init_banksize(void)
+{
+#ifdef CONFIG_SYS_DP_DDR_BASE_PHY
+   phys_size_t dp_ddr_size;
+#endif
+
+   /*
+* gd->ram_size has the total size of DDR memory, less reserved secure
+* memory. The DDR extends from low region to high region(s) presuming
+* no hole is created with DDR configuration. gd->arch.secure_ram tracks
+* the location of secure memory. gd->arch.resv_ram tracks the location
+* of reserved memory for Management Complex (MC).
+*/
+   gd->bd->bi_dram[0].start =