/******************************************************************************/
/* Component Name   Memory information definition                             */
/******************************************************************************/
/* Product      : ICU-M Firmware                                              */
/******************************************************************************/
/* Copyright(C) 2021-2023 Renesas Electronics Corporation.                    */
/******************************************************************************/

/*******************************************************************************/
/* Definition                                                                  */
/*******************************************************************************/
#if defined(TARGET_DEVICE_S4X) || defined(TARGET_DEVICE_V4H)
#define ICUM_MEMORY_CONFIG_NUM  (41)
#else /* if defined(TARGET_DEVICE_S4H) */
#define ICUM_MEMORY_CONFIG_NUM  (17)
#endif
/*********************************************************/
/* User configurable area start                          */
/*********************************************************/
/* The user can change only the value of defined macro.  */
#if defined(TARGET_DEVICE_V4H)
#define ICUM_SERVICEQUEUE_1_ADDR    (0x41C00000u)
#define ICUM_SERVICEQUEUE_1_SIZE    (1152u)
#define ICUM_SHAREDMEMORY_1_ADDR    (0x41C00480u)
#define ICUM_SHAREDMEMORY_1_SIZE    (2097152u -1152u)
#define ICUM_SHAREDMEMORY_2_ADDR    (0x41E00000u)
#define ICUM_SHAREDMEMORY_2_SIZE    (2097152u)
#define ICUM_SHAREDMEMORY_3_ADDR    (0xEB231000u)
#define ICUM_SHAREDMEMORY_3_SIZE    (0xD000u)
#define ICUM_EXPORT_DATA_ADDR       (0x41C20000u)
#define ICUM_EXPORT_DATA_SIZE       (114688u)
#define ICUM_DATA_WORKAREA_ADDR     (0xEB2E0000u)
#define ICUM_DATA_WORKAREA_SIZE     (ICUM_EXPORT_DATA_SIZE)
#define ICUM_RTOS_IMAGE_ADDR        (0xE2100000u)
#define ICUM_RTOS_IMAGE_SIZE        (1048576u)
#define ICUM_CA_PROGRAM_1_ADDR      (0x46400000u)
#define ICUM_CA_PROGRAM_1_SIZE      (65536u)
#define ICUM_CA_PROGRAM_2_ADDR      (0u)
#define ICUM_CA_PROGRAM_2_SIZE      (0u)
#define ICUM_CA_PROGRAM_3_ADDR      (0u)
#define ICUM_CA_PROGRAM_3_SIZE      (0u)
#define ICUM_CA_PROGRAM_4_ADDR      (0u)
#define ICUM_CA_PROGRAM_4_SIZE      (0u)
#define ICUM_CA_PROGRAM_5_ADDR      (0u)
#define ICUM_CA_PROGRAM_5_SIZE      (0u)
#define ICUM_CA_PROGRAM_6_ADDR      (0u)
#define ICUM_CA_PROGRAM_6_SIZE      (0u)
#define ICUM_CA_PROGRAM_7_ADDR      (0u)
#define ICUM_CA_PROGRAM_7_SIZE      (0u)
#define ICUM_CA_PROGRAM_8_ADDR      (0u)
#define ICUM_CA_PROGRAM_8_SIZE      (0u)
#define ICUM_SECUREMOD              (0x000001FFu)      /*( 1:secure mode   0:non-secure mode   bit0:unused,bit1:PE1,,,bit8:PE8 )*/
#define ICUM_PE0_REGION_ID          (0x00130000u)      /* PE0 */
#define ICUM_PE1_REGION_ID          (0x00130000u)      /* PE1 */
#define ICUM_PE2_REGION_ID          (0x00130000u)      /* PE2 */
#define ICUM_PE3_REGION_ID          (0x00130000u)      /* PE3 */
#define ICUM_PE4_REGION_ID          (0x00130000u)      /* PE4 */
#define ICUM_PE5_REGION_ID          (0x00130000u)      /* PE5 */
#define ICUM_PE6_REGION_ID          (0x00130000u)      /* PE6 */
#define ICUM_PE7_REGION_ID          (0x00130000u)      /* PE7 */
#define ICUM_PE8_REGION_ID          (0x00130000u)      /* PE8 */
#define ICUM_PES_REGION_ID          (0x00130000u)      /* PEs */
                                    /*  b20    : SECMASK     = 1:AUTHSEC is invalid   0:AUTHSEC is valid  */
                                    /*  b19-16 : IDMASK[3:0] = invalid bit of AUTHID                      */
                                    /*  b4     : AUTHSEC     = 1:secure mode   0:non-secure mode          */
                                    /*  b3-0   : AUTHID[3:0] = region ID                                  */
#elif defined(TARGET_DEVICE_S4X)
#define ICUM_SERVICEQUEUE_1_ADDR    (0x41C00000u)
#define ICUM_SERVICEQUEUE_1_SIZE    (1152u)
#define ICUM_SHAREDMEMORY_1_ADDR    (0x41C00480u)
#define ICUM_SHAREDMEMORY_1_SIZE    (2097152u -1152u)
#define ICUM_SHAREDMEMORY_2_ADDR    (0x41E00000u)
#define ICUM_SHAREDMEMORY_2_SIZE    (2097152u)
#define ICUM_SHAREDMEMORY_3_ADDR    (0xE2100000u)
#define ICUM_SHAREDMEMORY_3_SIZE    (1048576u)
#define ICUM_EXPORT_DATA_ADDR       (0x41C20000u)
#define ICUM_EXPORT_DATA_SIZE       (114688u)
#define ICUM_DATA_WORKAREA_ADDR     (0xEB2E0000u)
#define ICUM_DATA_WORKAREA_SIZE     (ICUM_EXPORT_DATA_SIZE)
#define ICUM_RTOS_IMAGE_ADDR        (0xE2100000u)
#define ICUM_RTOS_IMAGE_SIZE        (1048576u)
#define ICUM_CA_PROGRAM_1_ADDR      (0x46400000u)
#define ICUM_CA_PROGRAM_1_SIZE      (65536u)
#define ICUM_CA_PROGRAM_2_ADDR      (0u)
#define ICUM_CA_PROGRAM_2_SIZE      (0u)
#define ICUM_CA_PROGRAM_3_ADDR      (0u)
#define ICUM_CA_PROGRAM_3_SIZE      (0u)
#define ICUM_CA_PROGRAM_4_ADDR      (0u)
#define ICUM_CA_PROGRAM_4_SIZE      (0u)
#define ICUM_CA_PROGRAM_5_ADDR      (0u)
#define ICUM_CA_PROGRAM_5_SIZE      (0u)
#define ICUM_CA_PROGRAM_6_ADDR      (0u)
#define ICUM_CA_PROGRAM_6_SIZE      (0u)
#define ICUM_CA_PROGRAM_7_ADDR      (0u)
#define ICUM_CA_PROGRAM_7_SIZE      (0u)
#define ICUM_CA_PROGRAM_8_ADDR      (0u)
#define ICUM_CA_PROGRAM_8_SIZE      (0u)
#define ICUM_SECUREMOD              (0x000001FFu)      /*( 1:secure mode   0:non-secure mode   bit0:unused,bit1:PE1,,,bit8:PE8 )*/
#define ICUM_PE0_REGION_ID          (0x00100000u)      /* PE0 */
#define ICUM_PE1_REGION_ID          (0x00100000u)      /* PE1 */
#define ICUM_PE2_REGION_ID          (0x00100000u)      /* PE2 */
#define ICUM_PE3_REGION_ID          (0x00100000u)      /* PE3 */
#define ICUM_PE4_REGION_ID          (0x00100000u)      /* PE4 */
#define ICUM_PE5_REGION_ID          (0x00100000u)      /* PE5 */
#define ICUM_PE6_REGION_ID          (0x00100000u)      /* PE6 */
#define ICUM_PE7_REGION_ID          (0x00100000u)      /* PE7 */
#define ICUM_PE8_REGION_ID          (0x00100000u)      /* PE8 */
#define ICUM_PES_REGION_ID          (0x00100000u)      /* PEs */
                                    /*  b20    : SECMASK     = 1:AUTHSEC is invalid   0:AUTHSEC is valid  */
                                    /*  b19-16 : IDMASK[3:0] = invalid bit of AUTHID                      */
                                    /*  b4     : AUTHSEC     = 1:secure mode   0:non-secure mode          */
                                    /*  b3-0   : AUTHID[3:0] = region ID                                  */
#elif defined(TARGET_DEVICE_S4H)
#define ICUM_SERVICEQUEUE_1_ADDR    (0xFE020000u)
#define ICUM_SERVICEQUEUE_1_SIZE    (256u)
#define ICUM_SHAREDMEMORY_1_ADDR    (0xFE000000u)
#define ICUM_SHAREDMEMORY_1_SIZE    (524288u)
#define ICUM_SHAREDMEMORY_2_ADDR    (0xFE400000u)
#define ICUM_SHAREDMEMORY_2_SIZE    (524288u)
#define ICUM_SHAREDMEMORY_3_ADDR    (0xFE800000u)  /* RRAM */
#define ICUM_SHAREDMEMORY_3_SIZE    (131072u)
#define ICUM_EXPORT_DATA_ADDR       (0xFE464000u)
#define ICUM_EXPORT_DATA_SIZE       (114688u)
#define ICUM_DATA_WORKAREA_ADDR     (0xFF200000u)
#define ICUM_DATA_WORKAREA_SIZE     (ICUM_EXPORT_DATA_SIZE)
#define ICUM_HOST_IMAGE_ADDR        (0x00000000u)
#define ICUM_HOST_IMAGE_SIZE        (5242880u)
#define ICUM_PE0_SPID               (0x00000000u)      /* PE0 */
#define ICUM_PE1_SPID               (0x00000001u)      /* PE1 */
#define ICUM_PES_SPID               (0x001F0000u)      /* PEs */
                                    /*  b20-16 : IDMASK[4:0] = invalid bit of AUTHID   */
                                    /*  b4-0   : AUTHID[4:0] = SPID                    */
#endif
/*********************************************************/
/* User configurable area end                            */
/*********************************************************/

/*******************************************************************************/
/* Headers                                                                     */
/*******************************************************************************/

#include "renesas_types.h"
#include "shared.h"

/*******************************************************************************/
/* Global data                                                                 */
/*******************************************************************************/
#if defined(TARGET_DEVICE_S4X) || defined(TARGET_DEVICE_V4H)
const uint32_t memory_information[ICUM_MEMORY_CONFIG_NUM] __attribute__((aligned(8), section(".constdata.CONFIG_DATA"))) = 
{
    ICUM_SERVICEQUEUE_1_ADDR,
    ICUM_SERVICEQUEUE_1_SIZE,
    ICUM_SHAREDMEMORY_1_ADDR,
    ICUM_SHAREDMEMORY_1_SIZE,
    ICUM_SHAREDMEMORY_2_ADDR,
    ICUM_SHAREDMEMORY_2_SIZE,
    ICUM_SHAREDMEMORY_3_ADDR,
    ICUM_SHAREDMEMORY_3_SIZE,
    ICUM_EXPORT_DATA_ADDR,
    ICUM_EXPORT_DATA_SIZE,
    ICUM_DATA_WORKAREA_ADDR,
    ICUM_DATA_WORKAREA_SIZE,
    ICUM_RTOS_IMAGE_ADDR,
    ICUM_RTOS_IMAGE_SIZE,
    ICUM_CA_PROGRAM_1_ADDR,
    ICUM_CA_PROGRAM_1_SIZE,
    ICUM_CA_PROGRAM_2_ADDR,
    ICUM_CA_PROGRAM_2_SIZE,
    ICUM_CA_PROGRAM_3_ADDR,
    ICUM_CA_PROGRAM_3_SIZE,
    ICUM_CA_PROGRAM_4_ADDR,
    ICUM_CA_PROGRAM_4_SIZE,
    ICUM_CA_PROGRAM_5_ADDR,
    ICUM_CA_PROGRAM_5_SIZE,
    ICUM_CA_PROGRAM_6_ADDR,
    ICUM_CA_PROGRAM_6_SIZE,
    ICUM_CA_PROGRAM_7_ADDR,
    ICUM_CA_PROGRAM_7_SIZE,
    ICUM_CA_PROGRAM_8_ADDR,
    ICUM_CA_PROGRAM_8_SIZE,
    ICUM_SECUREMOD,
    ICUM_PE0_REGION_ID,
    ICUM_PE1_REGION_ID,
    ICUM_PE2_REGION_ID,
    ICUM_PE3_REGION_ID,
    ICUM_PE4_REGION_ID,
    ICUM_PE5_REGION_ID,
    ICUM_PE6_REGION_ID,
    ICUM_PE7_REGION_ID,
    ICUM_PE8_REGION_ID,
    ICUM_PES_REGION_ID
};
#elif defined(TARGET_DEVICE_S4H)
const uint32_t memory_information[ICUM_MEMORY_CONFIG_NUM] __attribute__((aligned(8), section(".constdata.CONFIG_DATA"))) = 
{
    ICUM_SERVICEQUEUE_1_ADDR,
    ICUM_SERVICEQUEUE_1_SIZE,
    ICUM_SHAREDMEMORY_1_ADDR,
    ICUM_SHAREDMEMORY_1_SIZE,
    ICUM_SHAREDMEMORY_2_ADDR,
    ICUM_SHAREDMEMORY_2_SIZE,
    ICUM_SHAREDMEMORY_3_ADDR,
    ICUM_SHAREDMEMORY_3_SIZE,
    ICUM_EXPORT_DATA_ADDR,
    ICUM_EXPORT_DATA_SIZE,
    ICUM_DATA_WORKAREA_ADDR,
    ICUM_DATA_WORKAREA_SIZE,
    ICUM_HOST_IMAGE_ADDR,
    ICUM_HOST_IMAGE_SIZE,
    ICUM_PE0_SPID,
    ICUM_PE1_SPID,
    ICUM_PES_SPID
};
#endif

/*******************************************************************************/
/* Below shared variables are moved in memory via the linker directive file    */
/*******************************************************************************/

/*******************************************************************************/
/* Communication buffer between host and ICU-M */
/*******************************************************************************/
uint8_t ISD_BUFFER[SIZE_OF_ISD_BUFFER]    __attribute__((aligned(64), section(".bss.SHARED_TOP")));
uint8_t LCS_BUFFER[SIZE_OF_LCS_BUFFER]    __attribute__((aligned(64), section(".bss.SHARED_LCS")));
uint8_t CMAC_BUFFER[SIZE_OF_CMAC_BUFFER]  __attribute__((aligned(64), section(".bss.SHARED_CMAC")));
uint8_t HASH_BUFFER[SIZE_OF_HASH_BUFFER]  __attribute__((aligned(64), section(".bss.SHARED_HASH")));
