2020-04-04 18:51:11 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2018-07-04 07:37:39 +02:00
|
|
|
|
|
|
|
#include <arch/mmu.h>
|
|
|
|
#include <symbols.h>
|
|
|
|
#include <soc/emi.h>
|
|
|
|
#include <soc/mmu_operations.h>
|
|
|
|
|
|
|
|
__weak void mtk_soc_after_dram(void) { /* do nothing */ }
|
|
|
|
|
|
|
|
void mtk_mmu_init(void)
|
|
|
|
{
|
|
|
|
mmu_init();
|
|
|
|
|
2018-08-09 09:14:15 +02:00
|
|
|
/*
|
2020-07-23 07:44:17 +02:00
|
|
|
* Set 0x0 to 8GB address as device memory. We want to config IO_PHYS
|
2018-08-09 09:14:15 +02:00
|
|
|
* address to DEV_MEM, and map a proper range of dram for the memory
|
|
|
|
* test during calibration.
|
|
|
|
*/
|
2020-07-23 07:44:17 +02:00
|
|
|
mmu_config_range((void *)0, (uintptr_t)8U * GiB, DEV_MEM);
|
2018-07-04 07:37:39 +02:00
|
|
|
|
|
|
|
/* SRAM is cached */
|
2019-02-21 03:39:22 +01:00
|
|
|
mmu_config_range(_sram, REGION_SIZE(sram), SECURE_CACHED_MEM);
|
2018-07-04 07:37:39 +02:00
|
|
|
|
|
|
|
/* L2C SRAM is cached */
|
2019-02-21 03:39:22 +01:00
|
|
|
mmu_config_range(_sram_l2c, REGION_SIZE(sram_l2c), SECURE_CACHED_MEM);
|
2018-07-04 07:37:39 +02:00
|
|
|
|
|
|
|
/* DMA is non-cached and is reserved for TPM & da9212 I2C DMA */
|
2019-02-21 03:39:22 +01:00
|
|
|
mmu_config_range(_dma_coherent, REGION_SIZE(dma_coherent),
|
2018-08-09 09:14:15 +02:00
|
|
|
SECURE_UNCACHED_MEM);
|
2018-07-04 07:37:39 +02:00
|
|
|
|
|
|
|
mmu_enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void mtk_mmu_after_dram(void)
|
|
|
|
{
|
|
|
|
/* Map DRAM as cached now that it's up and running */
|
2018-08-09 09:14:15 +02:00
|
|
|
mmu_config_range(_dram, (uintptr_t)sdram_size(), NONSECURE_CACHED_MEM);
|
2018-07-04 07:37:39 +02:00
|
|
|
|
|
|
|
mtk_soc_after_dram();
|
|
|
|
}
|
|
|
|
|
|
|
|
void mtk_mmu_disable_l2c_sram(void)
|
|
|
|
{
|
|
|
|
/* Unmap L2C SRAM so it can be reclaimed by L2 cache */
|
|
|
|
/* TODO: Implement true unmapping, and also use it for the zero-page! */
|
2019-02-21 03:39:22 +01:00
|
|
|
mmu_config_range(_sram_l2c, REGION_SIZE(sram_l2c), DEV_MEM);
|
2018-07-04 07:37:39 +02:00
|
|
|
|
|
|
|
/* Careful: changing cache geometry while it's active is a bad idea! */
|
|
|
|
mmu_disable();
|
|
|
|
|
|
|
|
mtk_soc_disable_l2c_sram();
|
|
|
|
|
|
|
|
/* Reenable MMU with now enlarged L2 cache. Page tables still valid. */
|
|
|
|
mmu_enable();
|
|
|
|
}
|