/*******************************************************************************
 * DISCLAIMER
 * This software is supplied by Renesas Electronics Corporation and is only
 * intended for use with Renesas products. No other uses are authorized. This
 * software is owned by Renesas Electronics Corporation and is protected under
 * all applicable laws, including copyright laws.
 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * Renesas reserves the right, without notice, to make changes to this software
 * and to discontinue the availability of this software. By using this software,
 * you agree to the additional terms and conditions found by accessing the
 * following link:
 * http://www.renesas.com/disclaimer
 * Copyright 2018-2022 Renesas Electronics Corporation All rights reserved.
*******************************************************************************/


/*******************************************************************************
 * DESCRIPTION   : Definitions used by the MMU.
 ******************************************************************************/
/******************************************************************************
 * @file          loader_mmu_table.h
 * - Version      : 0.01
 * @brief         MMU define.
 * .
 *****************************************************************************/
/******************************************************************************
 * History : DD.MM.YYYY Version  Description
 *         : 14.12.2022 0.01     First Release
*****************************************************************************/

#ifndef MMU_TABLE_H_
#define MMU_TABLE_H_

#include <stdint.h>		/* for uint32_t */

/* b[1:0] Block and Table descriptors */
#define MMU_TBL_TYPE_TABLE		(3UL << 0)
#define MMU_TBL_TYPE_BLOCK		(1UL << 0)
#define MMU_TBL_TYPE_PAGE		(3UL << 0)

/* Lower attributes:SH[1:0] unused */
#define MMU_TBL_BLOCK_OUTER_SHARE	(2ULL << 8)
#define MMU_TBL_BLOCK_INNER_SHARE	(3ULL << 8)

/* Lower attributes:AF[10] */
#define MMU_TBL_BLOCK_AF		(1UL << 10)

/* Lower attributes:AP[2:1] access permissions model */
#define MMU_TBL_AP_APP_RW		(1UL << 6)
#define MMU_TBL_AP_APP_R		(3UL << 6)

/* Lower attributes:AttrIndx[2:0]  */
#define MMU_TBL_ATTRINDX0		(0UL << 2)	/* Device-nGnRnE memory */
#define MMU_TBL_ATTRINDX1		(1UL << 2)	/* Normal memory, Outer Non-cacheable, Inner Write-Through Non-transient */
#define MMU_TBL_ATTRINDX2		(2UL << 2)	/* Normal memory, Outer Non-cacheable, Inner Non-cacheable */

/* Upper attributes:Block descriptors */
#define MMU_TBL_BLOCK_XN		(1UL << 54)

#define MMU_TBL_BLOCK_NOEXEC_DEVICE	  (MMU_TBL_BLOCK_XN  | MMU_TBL_AP_APP_RW | MMU_TBL_ATTRINDX0 | MMU_TBL_BLOCK_AF | MMU_TBL_TYPE_BLOCK)
#define MMU_TBL_BLOCK_EXECREAD_MEMORY (                    MMU_TBL_AP_APP_R  | MMU_TBL_ATTRINDX1 | MMU_TBL_BLOCK_AF | MMU_TBL_TYPE_BLOCK)
#define MMU_TBL_BLOCK_NOEXEC_MEMORY   (MMU_TBL_BLOCK_XN  | MMU_TBL_AP_APP_RW | MMU_TBL_ATTRINDX2 | MMU_TBL_BLOCK_AF | MMU_TBL_TYPE_BLOCK)
/* Level 3 */
#define MMU_TBL_PAGE_NOEXEC_DEVICE	  (MMU_TBL_BLOCK_XN  | MMU_TBL_AP_APP_RW | MMU_TBL_ATTRINDX0 | MMU_TBL_BLOCK_AF | MMU_TBL_TYPE_PAGE)
#define MMU_TBL_PAGE_EXECREAD_MEMORY  (                    MMU_TBL_AP_APP_R  | MMU_TBL_ATTRINDX1 | MMU_TBL_BLOCK_AF | MMU_TBL_TYPE_PAGE)
#define MMU_TBL_PAGE_NOEXEC_MEMORY	  (MMU_TBL_BLOCK_XN  | MMU_TBL_AP_APP_RW | MMU_TBL_ATTRINDX2 | MMU_TBL_BLOCK_AF | MMU_TBL_TYPE_PAGE)

extern const uint64_t g_loader_level1_table[];
extern const uint64_t g_loader_level2_table[];
extern const uint64_t g_loader_level3_table[];

#endif	 /* MMU_TABLE_H_ */
