blob: a35aac2c02c20f79ea9ccf28d133be18dd2a1d50 [file] [log] [blame]
Michal Simekec48b6c2018-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>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Michal Simekec48b6c2018-08-22 14:55:27 +02009#include <asm/armv8/mmu.h>
Simon Glass90526e92020-05-10 11:39:56 -060010#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Michal Simekec48b6c2018-08-22 14:55:27 +020012#include <asm/io.h>
Siva Durga Prasad Paladugu4244f2b2019-01-08 21:47:26 +053013#include <asm/arch/hardware.h>
14#include <asm/arch/sys_proto.h>
Ovidiu Panait61848582020-03-29 20:57:40 +030015#include <asm/cache.h>
Siva Durga Prasad Paladugu4244f2b2019-01-08 21:47:26 +053016
17DECLARE_GLOBAL_DATA_PTR;
Michal Simekec48b6c2018-08-22 14:55:27 +020018
Michal Simek3899ebd2019-09-11 09:39:59 +020019#define VERSAL_MEM_MAP_USED 5
Michal Simekaef149e2019-04-29 09:39:09 -070020
21#define DRAM_BANKS CONFIG_NR_DRAM_BANKS
22
Michal Simek3899ebd2019-09-11 09:39:59 +020023#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
24#define TCM_MAP 1
25#else
26#define TCM_MAP 0
27#endif
28
Michal Simekaef149e2019-04-29 09:39:09 -070029/* +1 is end of list which needs to be empty */
Michal Simek3899ebd2019-09-11 09:39:59 +020030#define VERSAL_MEM_MAP_MAX (VERSAL_MEM_MAP_USED + DRAM_BANKS + TCM_MAP + 1)
Michal Simekaef149e2019-04-29 09:39:09 -070031
32static struct mm_region versal_mem_map[VERSAL_MEM_MAP_MAX] = {
Michal Simekec48b6c2018-08-22 14:55:27 +020033 {
Michal Simekec48b6c2018-08-22 14:55:27 +020034 .virt = 0x80000000UL,
35 .phys = 0x80000000UL,
36 .size = 0x70000000UL,
37 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
38 PTE_BLOCK_NON_SHARE |
39 PTE_BLOCK_PXN | PTE_BLOCK_UXN
40 }, {
41 .virt = 0xf0000000UL,
42 .phys = 0xf0000000UL,
43 .size = 0x0fe00000UL,
44 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
45 PTE_BLOCK_NON_SHARE |
46 PTE_BLOCK_PXN | PTE_BLOCK_UXN
47 }, {
Michal Simekec48b6c2018-08-22 14:55:27 +020048 .virt = 0x400000000UL,
49 .phys = 0x400000000UL,
50 .size = 0x200000000UL,
51 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
52 PTE_BLOCK_NON_SHARE |
53 PTE_BLOCK_PXN | PTE_BLOCK_UXN
54 }, {
55 .virt = 0x600000000UL,
56 .phys = 0x600000000UL,
57 .size = 0x800000000UL,
58 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
59 PTE_BLOCK_INNER_SHARE
60 }, {
61 .virt = 0xe00000000UL,
62 .phys = 0xe00000000UL,
63 .size = 0xf200000000UL,
64 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
65 PTE_BLOCK_NON_SHARE |
66 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Michal Simekec48b6c2018-08-22 14:55:27 +020067 }
68};
69
Michal Simekaef149e2019-04-29 09:39:09 -070070void mem_map_fill(void)
71{
72 int banks = VERSAL_MEM_MAP_USED;
73
Michal Simek3899ebd2019-09-11 09:39:59 +020074#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
75 versal_mem_map[banks].virt = 0xffe00000UL;
76 versal_mem_map[banks].phys = 0xffe00000UL;
77 versal_mem_map[banks].size = 0x00200000UL;
78 versal_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
79 PTE_BLOCK_INNER_SHARE;
80 banks = banks + 1;
81#endif
82
Michal Simekaef149e2019-04-29 09:39:09 -070083 for (int i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
84 /* Zero size means no more DDR that's this is end */
85 if (!gd->bd->bi_dram[i].size)
86 break;
87
Michal Simek98da8662020-03-18 13:45:21 +010088#if defined(CONFIG_VERSAL_NO_DDR)
89 if (gd->bd->bi_dram[i].start < 0x80000000UL ||
90 gd->bd->bi_dram[i].start > 0x100000000UL) {
91 printf("Ignore caches over %llx/%llx\n",
92 gd->bd->bi_dram[i].start,
93 gd->bd->bi_dram[i].size);
94 continue;
95 }
96#endif
Michal Simekaef149e2019-04-29 09:39:09 -070097 versal_mem_map[banks].virt = gd->bd->bi_dram[i].start;
98 versal_mem_map[banks].phys = gd->bd->bi_dram[i].start;
99 versal_mem_map[banks].size = gd->bd->bi_dram[i].size;
100 versal_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
101 PTE_BLOCK_INNER_SHARE;
102 banks = banks + 1;
103 }
104}
105
Michal Simekec48b6c2018-08-22 14:55:27 +0200106struct mm_region *mem_map = versal_mem_map;
107
108u64 get_page_table_size(void)
109{
110 return 0x14000;
111}
Michal Simekddccf5e2018-09-18 14:58:16 +0200112
Siva Durga Prasad Paladugu4244f2b2019-01-08 21:47:26 +0530113#if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU)
Ovidiu Panait61848582020-03-29 20:57:40 +0300114int arm_reserve_mmu(void)
Siva Durga Prasad Paladugu4244f2b2019-01-08 21:47:26 +0530115{
116 tcm_init(TCM_LOCK);
117 gd->arch.tlb_size = PGTABLE_SIZE;
118 gd->arch.tlb_addr = VERSAL_TCM_BASE_ADDR;
119
120 return 0;
121}
122#endif