blob: 340f9ec9893a39afc800cd020c24d1dceb53e4d6 [file] [log] [blame]
Angel Ponse67ab182020-04-04 18:51:11 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Tristan Shiehc645a5a2018-07-04 13:37:39 +08002
3#include <arch/mmu.h>
Tristan Shiehc645a5a2018-07-04 13:37:39 +08004#include <symbols.h>
5#include <soc/emi.h>
6#include <soc/mmu_operations.h>
7
8__weak void mtk_soc_after_dram(void) { /* do nothing */ }
9
10void mtk_mmu_init(void)
11{
12 mmu_init();
13
Tristan Shieh1efe2572018-08-09 15:14:15 +080014 /*
Huayang Duan4bcb63b2020-07-23 13:44:17 +080015 * Set 0x0 to 8GB address as device memory. We want to config IO_PHYS
Tristan Shieh1efe2572018-08-09 15:14:15 +080016 * address to DEV_MEM, and map a proper range of dram for the memory
17 * test during calibration.
18 */
Huayang Duan4bcb63b2020-07-23 13:44:17 +080019 mmu_config_range((void *)0, (uintptr_t)8U * GiB, DEV_MEM);
Tristan Shiehc645a5a2018-07-04 13:37:39 +080020
21 /* SRAM is cached */
Julius Werner7e0dea62019-02-20 18:39:22 -080022 mmu_config_range(_sram, REGION_SIZE(sram), SECURE_CACHED_MEM);
Tristan Shiehc645a5a2018-07-04 13:37:39 +080023
24 /* L2C SRAM is cached */
Julius Werner7e0dea62019-02-20 18:39:22 -080025 mmu_config_range(_sram_l2c, REGION_SIZE(sram_l2c), SECURE_CACHED_MEM);
Tristan Shiehc645a5a2018-07-04 13:37:39 +080026
27 /* DMA is non-cached and is reserved for TPM & da9212 I2C DMA */
Julius Werner7e0dea62019-02-20 18:39:22 -080028 mmu_config_range(_dma_coherent, REGION_SIZE(dma_coherent),
Tristan Shieh1efe2572018-08-09 15:14:15 +080029 SECURE_UNCACHED_MEM);
Tristan Shiehc645a5a2018-07-04 13:37:39 +080030
31 mmu_enable();
32}
33
34void mtk_mmu_after_dram(void)
35{
36 /* Map DRAM as cached now that it's up and running */
Tristan Shieh1efe2572018-08-09 15:14:15 +080037 mmu_config_range(_dram, (uintptr_t)sdram_size(), NONSECURE_CACHED_MEM);
Tristan Shiehc645a5a2018-07-04 13:37:39 +080038
39 mtk_soc_after_dram();
40}
41
42void mtk_mmu_disable_l2c_sram(void)
43{
44 /* Unmap L2C SRAM so it can be reclaimed by L2 cache */
45 /* TODO: Implement true unmapping, and also use it for the zero-page! */
Julius Werner7e0dea62019-02-20 18:39:22 -080046 mmu_config_range(_sram_l2c, REGION_SIZE(sram_l2c), DEV_MEM);
Tristan Shiehc645a5a2018-07-04 13:37:39 +080047
48 /* Careful: changing cache geometry while it's active is a bad idea! */
49 mmu_disable();
50
51 mtk_soc_disable_l2c_sram();
52
Martin Roth26f97f92021-10-01 14:53:22 -060053 /* Re-enable MMU with now enlarged L2 cache. Page tables still valid. */
Tristan Shiehc645a5a2018-07-04 13:37:39 +080054 mmu_enable();
55}