Debian Codegraph @

src/soc/mediatek/common/mmu_operations.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <arch/mmu.h>
4 #include <symbols.h>
5 #include <soc/emi.h>
6 #include <soc/mmu_operations.h>
7 #include <soc/symbols.h>
8
9 __weak void mtk_soc_after_dram(void) { /* do nothing */ }
10
11 void mtk_mmu_init(void)
12 {
13 static bool mmu_inited;
14
15 if (mmu_inited)
16 return;
17
18 mmu_inited = true;
19
20 mmu_init();
21
22 /*
23 * Set 0x0 to 16GB address as device memory. We want to config IO_PHYS
24 * address to DEV_MEM, and map a proper range of dram for the memory
25 * test during calibration.
26 */
27 mmu_config_range((void *)0, (uintptr_t)16U * GiB, DEV_MEM);
28
29 /* SRAM is cached */
30 mmu_config_range(_sram, REGION_SIZE(sram), SECURE_CACHED_MEM);
31
32 /* L2C SRAM is cached */
33 mmu_config_range(_sram_l2c, REGION_SIZE(sram_l2c), SECURE_CACHED_MEM);
34
35 /* DMA is non-cached and is reserved for TPM & da9212 I2C DMA */
36 mmu_config_range(_dma_coherent, REGION_SIZE(dma_coherent),
37 SECURE_UNCACHED_MEM);
38
39 /* Set mcufw_reserved to non-cacheable */
40 if (REGION_SIZE(mcufw_reserved) != 0)
41 mmu_config_range(_mcufw_reserved, REGION_SIZE(mcufw_reserved),
42 SECURE_UNCACHED_MEM);
43
44 mmu_enable();
45 }
46
47 void mtk_mmu_after_dram(void)
48 {
49 /* Map DRAM as cached now that it's up and running */
50 mmu_config_range(_dram, (uintptr_t)sdram_size(), NONSECURE_CACHED_MEM);
51
52 mtk_soc_after_dram();
53 }
54
55 void mtk_mmu_disable_l2c_sram(void)
56 {
57 /* Unmap L2C SRAM so it can be reclaimed by L2 cache */
58 /* TODO: Implement true unmapping, and also use it for the zero-page! */
59 mmu_config_range(_sram_l2c, REGION_SIZE(sram_l2c), DEV_MEM);
60
61 /* Careful: changing cache geometry while it's active is a bad idea! */
62 mmu_disable();
63
64 mtk_soc_disable_l2c_sram();
65
66 /* Re-enable MMU with now enlarged L2 cache. Page tables still valid. */
67 mmu_enable();
68 }