IPMMU Configuration Guide
---------------------------

1. Overview
-----------
The R-Car series (except R-Car H2) has IPMMU-GP to access 40-bit physical 
address range. The IPMMU-GP setting contains configurable parameters and
it depends on memory configuration of target system.

This document describes IPMMU-GP setting for SGX.

 +-----+                +--------+                
 | SGX |--------------->|IPMMU-GP|---------------> memory
 +-----+ 32-bit access  +--------+ 40-bit access

Note:
  - IPMMU-GP is enabled when CONFIG_ARM_LPAE is enabled in Linux BSP.

  - Due to IPMMU-GP specification, this driver supports 4GB address space
    as maximum.

2. Physical memory map
----------------------
If IPMMU-GP is disabled, SGX driver is able to access only 32bit address range.
When enabling IPMMU-GP, SGX driver is able to access 40bit address range also.

For example, KOELSCH board (R-Car M2W) has 2GB DRAM which is located as follows;
- 1GB is located at 0x01_00000000 and other 1GB is located at 0x02_00000000
- 1st 1GB (located at 0x01_00000000) is mirrored to legacy memory area 
  (0x00_40000000).

To enable to use these 2GB areas, SGX driver needs to set page table to IPMMU-GP. If you use difference system with different memory configuration, you have to configure IPMMU-GP setting. See "3. Configurable parameters for address space extension" for detail.

                  physical area layout
 0x00_00000000   +--------------------+
                 |                    |
 kernal area top +--------------------+
 0x00_40000000   |Kernel Area         |
                 |                    |
                 +--------------------+
                 |                    |
 section0        +--------------------+
 0x01_00000000   |mirrored from kernel|
                 |                    |
 section1        +--------------------+
 0x02_00000000   |highmem             |
                 |                    |
 section2        +--------------------+
                 |highmem             |
                 |                    |
 section3        +--------------------+
                 |highmem             |
                 |                    |
                 +--------------------+
                 |                    |
                 +--------------------+


3. Configurable parameters for address space extension
------------------------------------------------------
In this driver, each sections are defined as following symbols.

                              physical area layout
                             +--------------------+
                             |                    |
       IPMMU_KERNEL_PHY_ADDR +--------------------+
                             |Kernel Area         |
                             |                    |
                             +--------------------+
                             |                    |
IPMMU_KERNEL_PHY_MIRROR_ADDR +--------------------+
      & IPMMU_ADDR_SECTION_0 |mirrored from kernel|
                             |                    |
        IPMMU_ADDR_SECTION_1 +--------------------+
                             |highmem             |
                             |                    |
        IPMMU_ADDR_SECTION_2 +--------------------+
                             |highmem             |
                             |                    |
        IPMMU_ADDR_SECTION_3 +--------------------+
                             |highmem             |
                             |                    |
                             +--------------------+
                             |                    |
                             +--------------------+

The following list shows details of IPMMU definition.

 - IPMMUGP_BASE_ADDR:
   Top physical address of the IPMMU-GP register

 - SUPPORT_RCAR_IPMMU:
   Enable IPMMU address translation
   It is enabled automatically if CONFIG_ARM_LPAE is 'y'

 - IPMMU_KERNEL_PHY_ADDR:
   Top physical address of the Kernel Area

 - IPMMU_KERNEL_PHY_MIRROR_ADDR:
   Mirror address of the Kenel on the IPMMU

 - IPMMU_KERNEL_LEGACY_MEM_SIZE:
   Kernel Area size

 - IPMMU_ADDR_SECTION_NUM:
   The number of IPMMU sections(max 4 sections)

 - IPMMU_ADDR_SECTION_0:
 - IPMMU_ADDR_SECTION_1:
 - IPMMU_ADDR_SECTION_2:
 - IPMMU_ADDR_SECTION_3:
   Top physical address of each section.
   If some section are not used in the system, the section must be
   defined as "0x0".

Configurable parameters:
-----------------------------+--------------+--------------+-------------+
 Define                      | M2W(R8A7791) | M2N(R8A7793) | E2(R8A7794) |
-----------------------------+--------------+--------------+-------------+
 IPMMUGP_BASE_ADDR           |             0xe62a0000 + 0x800            |
 IPMMU_KERNEL_PHY_ADDR       |               0x0040000000                |
 IPMMU_KERNEL_PHY_MIRROR_ADDR|               0x0100000000                |
 IPMMU_KERNEL_LEGACY_MEM_SIZE|               0x0040000000UL              |
 IPMMU_ADDR_SECTION_0        |               0x0100000000                |
 IPMMU_ADDR_SECTION_1        | 0x0200000000 |           0x0              |
 IPMMU_ADDR_SECTION_2        |                    0x0                    |
 IPMMU_ADDR_SECTION_3        |                    0x0                    |
 IPMMU_ADDR_SECTION_NUM      | 2            |             1              |
-----------------------------+--------------+--------------+-------------+

If you want to change these parameters, modify Makefile of your build target.
--
