blob: 61c0b663fcfe10dc7f50d00bbcc00e1eb4286faf [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>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Michal Simek4b066a12018-08-22 14:55:27 +02009#include <asm/armv8/mmu.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <asm/cache.h>
Michal Simek4b066a12018-08-22 14:55:27 +020011#include <asm/io.h>
Siva Durga Prasad Paladugu775aa952019-01-08 21:47:26 +053012#include <asm/arch/hardware.h>
13#include <asm/arch/sys_proto.h>
Ovidiu Panait2b618472020-03-29 20:57:40 +030014#include <asm/cache.h>
Siva Durga Prasad Paladugu775aa952019-01-08 21:47:26 +053015
16DECLARE_GLOBAL_DATA_PTR;
Michal Simek4b066a12018-08-22 14:55:27 +020017
Michal Simekfe2eb112019-09-11 09:39:59 +020018#define VERSAL_MEM_MAP_USED 5
Michal Simek21eb5cc2019-04-29 09:39:09 -070019
20#define DRAM_BANKS CONFIG_NR_DRAM_BANKS
21
Michal Simekfe2eb112019-09-11 09:39:59 +020022#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
23#define TCM_MAP 1
24#else
25#define TCM_MAP 0
26#endif
27
Michal Simek21eb5cc2019-04-29 09:39:09 -070028/* +1 is end of list which needs to be empty */
Michal Simekfe2eb112019-09-11 09:39:59 +020029#define VERSAL_MEM_MAP_MAX (VERSAL_MEM_MAP_USED + DRAM_BANKS + TCM_MAP + 1)
Michal Simek21eb5cc2019-04-29 09:39:09 -070030
31static struct mm_region versal_mem_map[VERSAL_MEM_MAP_MAX] = {
Michal Simek4b066a12018-08-22 14:55:27 +020032 {
Michal Simek4b066a12018-08-22 14:55:27 +020033 .virt = 0x80000000UL,
34 .phys = 0x80000000UL,
35 .size = 0x70000000UL,
36 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
37 PTE_BLOCK_NON_SHARE |
38 PTE_BLOCK_PXN | PTE_BLOCK_UXN
39 }, {
40 .virt = 0xf0000000UL,
41 .phys = 0xf0000000UL,
42 .size = 0x0fe00000UL,
43 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
44 PTE_BLOCK_NON_SHARE |
45 PTE_BLOCK_PXN | PTE_BLOCK_UXN
46 }, {
Michal Simek4b066a12018-08-22 14:55:27 +020047 .virt = 0x400000000UL,
48 .phys = 0x400000000UL,
49 .size = 0x200000000UL,
50 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
51 PTE_BLOCK_NON_SHARE |
52 PTE_BLOCK_PXN | PTE_BLOCK_UXN
53 }, {
54 .virt = 0x600000000UL,
55 .phys = 0x600000000UL,
56 .size = 0x800000000UL,
57 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
58 PTE_BLOCK_INNER_SHARE
59 }, {
60 .virt = 0xe00000000UL,
61 .phys = 0xe00000000UL,
62 .size = 0xf200000000UL,
63 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
64 PTE_BLOCK_NON_SHARE |
65 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Michal Simek4b066a12018-08-22 14:55:27 +020066 }
67};
68
Michal Simek21eb5cc2019-04-29 09:39:09 -070069void mem_map_fill(void)
70{
71 int banks = VERSAL_MEM_MAP_USED;
72
Michal Simekfe2eb112019-09-11 09:39:59 +020073#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
74 versal_mem_map[banks].virt = 0xffe00000UL;
75 versal_mem_map[banks].phys = 0xffe00000UL;
76 versal_mem_map[banks].size = 0x00200000UL;
77 versal_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
78 PTE_BLOCK_INNER_SHARE;
79 banks = banks + 1;
80#endif
81
Michal Simek21eb5cc2019-04-29 09:39:09 -070082 for (int i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
83 /* Zero size means no more DDR that's this is end */
84 if (!gd->bd->bi_dram[i].size)
85 break;
86
Michal Simekdfcd21d2020-03-18 13:45:21 +010087#if defined(CONFIG_VERSAL_NO_DDR)
88 if (gd->bd->bi_dram[i].start < 0x80000000UL ||
89 gd->bd->bi_dram[i].start > 0x100000000UL) {
90 printf("Ignore caches over %llx/%llx\n",
91 gd->bd->bi_dram[i].start,
92 gd->bd->bi_dram[i].size);
93 continue;
94 }
95#endif
Michal Simek21eb5cc2019-04-29 09:39:09 -070096 versal_mem_map[banks].virt = gd->bd->bi_dram[i].start;
97 versal_mem_map[banks].phys = gd->bd->bi_dram[i].start;
98 versal_mem_map[banks].size = gd->bd->bi_dram[i].size;
99 versal_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
100 PTE_BLOCK_INNER_SHARE;
101 banks = banks + 1;
102 }
103}
104
Michal Simek4b066a12018-08-22 14:55:27 +0200105struct mm_region *mem_map = versal_mem_map;
106
107u64 get_page_table_size(void)
108{
109 return 0x14000;
110}
Siva Durga Prasad Paladugu775aa952019-01-08 21:47:26 +0530111
112#if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU)
Ovidiu Panait2b618472020-03-29 20:57:40 +0300113int arm_reserve_mmu(void)
Siva Durga Prasad Paladugu775aa952019-01-08 21:47:26 +0530114{
115 tcm_init(TCM_LOCK);
116 gd->arch.tlb_size = PGTABLE_SIZE;
117 gd->arch.tlb_addr = VERSAL_TCM_BASE_ADDR;
118
119 return 0;
120}
121#endif