blob: 829a6c1b3e5354dc7bbcdf2dd836faa6ffe3e15e [file] [log] [blame]
Michal Simek4b066a12018-08-22 14:55:27 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2016 - 2018 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
5 */
6
7#include <common.h>
8#include <asm/armv8/mmu.h>
9#include <asm/io.h>
Siva Durga Prasad Paladugu775aa952019-01-08 21:47:26 +053010#include <asm/arch/hardware.h>
11#include <asm/arch/sys_proto.h>
12
13DECLARE_GLOBAL_DATA_PTR;
Michal Simek4b066a12018-08-22 14:55:27 +020014
Michal Simekfe2eb112019-09-11 09:39:59 +020015#define VERSAL_MEM_MAP_USED 5
Michal Simek21eb5cc2019-04-29 09:39:09 -070016
17#define DRAM_BANKS CONFIG_NR_DRAM_BANKS
18
Michal Simekfe2eb112019-09-11 09:39:59 +020019#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
20#define TCM_MAP 1
21#else
22#define TCM_MAP 0
23#endif
24
Michal Simek21eb5cc2019-04-29 09:39:09 -070025/* +1 is end of list which needs to be empty */
Michal Simekfe2eb112019-09-11 09:39:59 +020026#define VERSAL_MEM_MAP_MAX (VERSAL_MEM_MAP_USED + DRAM_BANKS + TCM_MAP + 1)
Michal Simek21eb5cc2019-04-29 09:39:09 -070027
28static struct mm_region versal_mem_map[VERSAL_MEM_MAP_MAX] = {
Michal Simek4b066a12018-08-22 14:55:27 +020029 {
Michal Simek4b066a12018-08-22 14:55:27 +020030 .virt = 0x80000000UL,
31 .phys = 0x80000000UL,
32 .size = 0x70000000UL,
33 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
34 PTE_BLOCK_NON_SHARE |
35 PTE_BLOCK_PXN | PTE_BLOCK_UXN
36 }, {
37 .virt = 0xf0000000UL,
38 .phys = 0xf0000000UL,
39 .size = 0x0fe00000UL,
40 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
41 PTE_BLOCK_NON_SHARE |
42 PTE_BLOCK_PXN | PTE_BLOCK_UXN
43 }, {
Michal Simek4b066a12018-08-22 14:55:27 +020044 .virt = 0x400000000UL,
45 .phys = 0x400000000UL,
46 .size = 0x200000000UL,
47 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
48 PTE_BLOCK_NON_SHARE |
49 PTE_BLOCK_PXN | PTE_BLOCK_UXN
50 }, {
51 .virt = 0x600000000UL,
52 .phys = 0x600000000UL,
53 .size = 0x800000000UL,
54 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
55 PTE_BLOCK_INNER_SHARE
56 }, {
57 .virt = 0xe00000000UL,
58 .phys = 0xe00000000UL,
59 .size = 0xf200000000UL,
60 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
61 PTE_BLOCK_NON_SHARE |
62 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Michal Simek4b066a12018-08-22 14:55:27 +020063 }
64};
65
Michal Simek21eb5cc2019-04-29 09:39:09 -070066void mem_map_fill(void)
67{
68 int banks = VERSAL_MEM_MAP_USED;
69
Michal Simekfe2eb112019-09-11 09:39:59 +020070#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
71 versal_mem_map[banks].virt = 0xffe00000UL;
72 versal_mem_map[banks].phys = 0xffe00000UL;
73 versal_mem_map[banks].size = 0x00200000UL;
74 versal_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
75 PTE_BLOCK_INNER_SHARE;
76 banks = banks + 1;
77#endif
78
Michal Simek21eb5cc2019-04-29 09:39:09 -070079 for (int i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
80 /* Zero size means no more DDR that's this is end */
81 if (!gd->bd->bi_dram[i].size)
82 break;
83
Michal Simekdfcd21d2020-03-18 13:45:21 +010084#if defined(CONFIG_VERSAL_NO_DDR)
85 if (gd->bd->bi_dram[i].start < 0x80000000UL ||
86 gd->bd->bi_dram[i].start > 0x100000000UL) {
87 printf("Ignore caches over %llx/%llx\n",
88 gd->bd->bi_dram[i].start,
89 gd->bd->bi_dram[i].size);
90 continue;
91 }
92#endif
Michal Simek21eb5cc2019-04-29 09:39:09 -070093 versal_mem_map[banks].virt = gd->bd->bi_dram[i].start;
94 versal_mem_map[banks].phys = gd->bd->bi_dram[i].start;
95 versal_mem_map[banks].size = gd->bd->bi_dram[i].size;
96 versal_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
97 PTE_BLOCK_INNER_SHARE;
98 banks = banks + 1;
99 }
100}
101
Michal Simek4b066a12018-08-22 14:55:27 +0200102struct mm_region *mem_map = versal_mem_map;
103
104u64 get_page_table_size(void)
105{
106 return 0x14000;
107}
Siva Durga Prasad Paladugu775aa952019-01-08 21:47:26 +0530108
109#if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU)
110int reserve_mmu(void)
111{
112 tcm_init(TCM_LOCK);
113 gd->arch.tlb_size = PGTABLE_SIZE;
114 gd->arch.tlb_addr = VERSAL_TCM_BASE_ADDR;
115
116 return 0;
117}
118#endif