blob: 4d2e9a0123202d57c20d4fa9b39ab1f839e44950 [file] [log] [blame]
Deepa Dinamani1c2748d2015-01-12 11:57:09 -08001/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <arch/cache.h>
14#include <symbols.h>
15#include "mmu.h"
16
17/* convenient shorthand (in MB) */
18#define RPM_START ((uintptr_t)_rpm / KiB)
19#define RPM_END ((uintptr_t)_erpm / KiB)
20#define RPM_SIZE (RPM_END - RPM_START)
21#define SRAM_START ((uintptr_t)_sram / KiB)
22#define SRAM_END ((uintptr_t)_esram / KiB)
23#define DRAM_START ((uintptr_t)_dram / MiB)
24#define DRAM_SIZE (CONFIG_DRAM_SIZE_MB)
25#define DRAM_END (DRAM_START + DRAM_SIZE)
26
27/* DMA memory for drivers */
28#define DMA_START ((uintptr_t)_dma_coherent / MiB)
29#define DMA_SIZE (_dma_coherent_size / MiB)
30
31void setup_dram_mappings(enum dram_state dram)
32{
33 if (dram == DRAM_INITIALIZED) {
34 mmu_config_range(DRAM_START, DRAM_SIZE, DCACHE_WRITEBACK);
35 /* Map DMA memory */
36 mmu_config_range(DMA_START, DMA_SIZE, DCACHE_OFF);
37 } else {
38 mmu_disable_range(DRAM_START, DRAM_SIZE);
39 /* Map DMA memory */
40 mmu_disable_range(DMA_START, DMA_SIZE);
41 }
42}
43
44void setup_mmu(enum dram_state dram)
45{
46 dcache_mmu_disable();
47
48 /* start with mapping everything as strongly ordered. */
49 mmu_config_range(0, 4096, DCACHE_OFF);
50
51 /* Map Device memory. */
52 mmu_config_range_kb(RPM_START, RPM_SIZE, DCACHE_OFF);
53
Deepa Dinamani1c2748d2015-01-12 11:57:09 -080054 mmu_config_range_kb(SRAM_START, SRAM_END - SRAM_START,
55 DCACHE_WRITEBACK);
56
57 /* Map DRAM memory */
58 setup_dram_mappings(dram);
59
60 mmu_disable_range(DRAM_END, 4096 - DRAM_END);
61
Deepa Dinamania386bf72015-02-18 15:48:44 -080062 /* disable Page 0 for trapping NULL pointer references. */
63 mmu_disable_range_kb(0, 1);
64
Deepa Dinamani1c2748d2015-01-12 11:57:09 -080065 mmu_init();
66
67 dcache_mmu_enable();
68}