@ -15,12 +15,16 @@
# include <common/bl_common.h>
# include <common/debug.h>
# include <common/desc_image_load.h>
# include <common/image_decompress.h>
# include <drivers/console.h>
# include <drivers/io/io_driver.h>
# include <drivers/io/io_storage.h>
# include <lib/mmio.h>
# include <lib/xlat_tables/xlat_tables_defs.h>
# include <plat/common/platform.h>
# if RCAR_GEN3_BL33_GZIP == 1
# include <tf_gunzip.h>
# endif
# include "avs_driver.h"
# include "boot_init_dram.h"
@ -357,16 +361,29 @@ static uint32_t is_ddr_backup_mode(void)
# endif
}
# if RCAR_GEN3_BL33_GZIP == 1
void bl2_plat_preload_setup ( void )
{
image_decompress_init ( BL33_COMP_BASE , BL33_COMP_SIZE , gunzip ) ;
}
# endif
int bl2_plat_handle_pre_image_load ( unsigned int image_id )
{
u_register_t * boot_kind = ( void * ) BOOT_KIND_BASE ;
bl_mem_params_node_t * bl_mem_params ;
bl_mem_params = get_bl_mem_params_node ( image_id ) ;
# if RCAR_GEN3_BL33_GZIP == 1
if ( image_id = = BL33_IMAGE_ID ) {
image_decompress_prepare ( & bl_mem_params - > image_info ) ;
}
# endif
if ( image_id ! = BL31_IMAGE_ID )
return 0 ;
bl_mem_params = get_bl_mem_params_node ( image_id ) ;
if ( is_ddr_backup_mode ( ) = = RCAR_COLD_BOOT )
goto cold_boot ;
@ -433,6 +450,19 @@ int bl2_plat_handle_post_image_load(unsigned int image_id)
sizeof ( entry_point_info_t ) ) ;
break ;
case BL33_IMAGE_ID :
# if RCAR_GEN3_BL33_GZIP == 1
if ( ( mmio_read_32 ( BL33_COMP_BASE ) & 0xffff ) = = 0x8b1f ) {
/* decompress gzip-compressed image */
ret = image_decompress ( & bl_mem_params - > image_info ) ;
if ( ret ! = 0 ) {
return ret ;
}
} else {
/* plain image, copy it in place */
memcpy ( ( void * ) BL33_BASE , ( void * ) BL33_COMP_BASE ,
bl_mem_params - > image_info . image_size ) ;
}
# endif
memcpy ( & params - > bl33_ep_info , & bl_mem_params - > ep_info ,
sizeof ( entry_point_info_t ) ) ;
break ;
@ -535,12 +565,75 @@ static void bl2_populate_compatible_string(void *dt)
}
}
static void bl2_advertise_dram_entries ( uint64_t dram_config [ 8 ] )
static void bl2_add_rpc_node ( void )
{
# if (RCAR_RPC_HYPERFLASH_LOCKED == 0)
int ret , node ;
node = ret = fdt_add_subnode ( fdt , 0 , " soc " ) ;
if ( ret < 0 ) {
goto err ;
}
node = ret = fdt_add_subnode ( fdt , node , " rpc@ee200000 " ) ;
if ( ret < 0 ) {
goto err ;
}
ret = fdt_setprop_string ( fdt , node , " status " , " okay " ) ;
if ( ret < 0 ) {
goto err ;
}
return ;
err :
NOTICE ( " BL2: Cannot add RPC node to FDT (ret=%i) \n " , ret ) ;
panic ( ) ;
# endif
}
static void bl2_add_dram_entry ( uint64_t start , uint64_t size )
{
char nodename [ 32 ] = { 0 } ;
uint64_t start , size ;
uint64_t fdtsize ;
int ret , node , chan ;
int ret , node ;
fdtsize = cpu_to_fdt64 ( size ) ;
snprintf ( nodename , sizeof ( nodename ) , " memory@ " ) ;
unsigned_num_print ( start , 16 , nodename + strlen ( nodename ) ) ;
node = ret = fdt_add_subnode ( fdt , 0 , nodename ) ;
if ( ret < 0 ) {
goto err ;
}
ret = fdt_setprop_string ( fdt , node , " device_type " , " memory " ) ;
if ( ret < 0 ) {
goto err ;
}
ret = fdt_setprop_u64 ( fdt , node , " reg " , start ) ;
if ( ret < 0 ) {
goto err ;
}
ret = fdt_appendprop ( fdt , node , " reg " , & fdtsize ,
sizeof ( fdtsize ) ) ;
if ( ret < 0 ) {
goto err ;
}
return ;
err :
NOTICE ( " BL2: Cannot add memory node [%llx - %llx] to FDT (ret=%i) \n " ,
start , start + size - 1 , ret ) ;
panic ( ) ;
}
static void bl2_advertise_dram_entries ( uint64_t dram_config [ 8 ] )
{
uint64_t start , size , size32 ;
int chan ;
for ( chan = 0 ; chan < 4 ; chan + + ) {
start = dram_config [ 2 * chan ] ;
@ -568,39 +661,43 @@ static void bl2_advertise_dram_entries(uint64_t dram_config[8])
/*
* Channel 0 is mapped in 32 bit space and the first
* 128 MiB are reserved
* 128 MiB are reserved and the maximum size is 2 GiB .
*/
if ( chan = = 0 ) {
start = 0x48000000 ;
size - = 0x8000000 ;
/* Limit the 32bit entry to 2 GiB - 128 MiB */
size32 = size - 0x8000000U ;
if ( size32 > = 0x78000000U ) {
size32 = 0x78000000U ;
}
/* Emit 32bit entry, up to 2 GiB - 128 MiB long. */
bl2_add_dram_entry ( 0x48000000 , size32 ) ;
/*
* If channel 0 is less than 2 GiB long , the
* entire memory fits into the 32 bit space entry ,
* so move on to the next channel .
*/
if ( size < = 0x80000000U ) {
continue ;
}
/*
* If channel 0 is more than 2 GiB long , emit
* another entry which covers the rest of the
* memory in channel 0 , in the 64 bit space .
*
* Start of this new entry is at 2 GiB offset
* from the beginning of the 64 bit channel 0
* address , size is 2 GiB shorter than total
* size of the channel .
*/
start + = 0x80000000U ;
size - = 0x80000000U ;
}
fdtsize = cpu_to_fdt64 ( size ) ;
snprintf ( nodename , sizeof ( nodename ) , " memory@ " ) ;
unsigned_num_print ( start , 16 , nodename + strlen ( nodename ) ) ;
node = ret = fdt_add_subnode ( fdt , 0 , nodename ) ;
if ( ret < 0 )
goto err ;
ret = fdt_setprop_string ( fdt , node , " device_type " , " memory " ) ;
if ( ret < 0 )
goto err ;
ret = fdt_setprop_u64 ( fdt , node , " reg " , start ) ;
if ( ret < 0 )
goto err ;
ret = fdt_appendprop ( fdt , node , " reg " , & fdtsize ,
sizeof ( fdtsize ) ) ;
if ( ret < 0 )
goto err ;
bl2_add_dram_entry ( start , size ) ;
}
return ;
err :
NOTICE ( " BL2: Cannot add memory node to FDT (ret=%i) \n " , ret ) ;
panic ( ) ;
}
static void bl2_advertise_dram_size ( uint32_t product )
@ -648,8 +745,13 @@ static void bl2_advertise_dram_size(uint32_t product)
break ;
case PRR_PRODUCT_M3N :
# if (RCAR_DRAM_LPDDR4_MEMCONF == 2)
/* 4GB(4GBx1) */
dram_config [ 1 ] = 0x100000000ULL ;
# elif (RCAR_DRAM_LPDDR4_MEMCONF == 1)
/* 2GB(1GBx2) */
dram_config [ 1 ] = 0x80000000ULL ;
# endif
break ;
case PRR_PRODUCT_V3M :
@ -935,6 +1037,9 @@ lcm_state:
/* Add platform compatible string */
bl2_populate_compatible_string ( fdt ) ;
/* Enable RPC if unlocked */
bl2_add_rpc_node ( ) ;
/* Print DRAM layout */
bl2_advertise_dram_size ( product ) ;