blob: 29743cae5aabfcac38a639979841dfb7330b43fc [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek84c72042015-01-15 10:01:51 +01002/*
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
Michal Simek84c72042015-01-15 10:01:51 +01005 */
6
7#include <common.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Simon Glass049f8d62019-12-28 10:44:59 -07009#include <time.h>
Michal Simek84c72042015-01-15 10:01:51 +010010#include <asm/arch/hardware.h>
11#include <asm/arch/sys_proto.h>
Alexander Graf96519f32016-03-04 01:09:49 +010012#include <asm/armv8/mmu.h>
Simon Glass90526e92020-05-10 11:39:56 -060013#include <asm/cache.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Michal Simek84c72042015-01-15 10:01:51 +010015#include <asm/io.h>
Ibai Erkiaga009ab7b2019-09-27 11:37:01 +010016#include <zynqmp_firmware.h>
Ovidiu Panait61848582020-03-29 20:57:40 +030017#include <asm/cache.h>
Michal Simek84c72042015-01-15 10:01:51 +010018
19#define ZYNQ_SILICON_VER_MASK 0xF000
20#define ZYNQ_SILICON_VER_SHIFT 12
21
22DECLARE_GLOBAL_DATA_PTR;
23
Nitin Jain06789412018-04-20 12:30:40 +053024/*
25 * Number of filled static entries and also the first empty
26 * slot in zynqmp_mem_map.
27 */
28#define ZYNQMP_MEM_MAP_USED 4
29
Siva Durga Prasad Paladugu3b644a32018-01-12 15:35:46 +053030#if !defined(CONFIG_ZYNQMP_NO_DDR)
Nitin Jain06789412018-04-20 12:30:40 +053031#define DRAM_BANKS CONFIG_NR_DRAM_BANKS
32#else
33#define DRAM_BANKS 0
Siva Durga Prasad Paladugu3b644a32018-01-12 15:35:46 +053034#endif
Nitin Jain06789412018-04-20 12:30:40 +053035
36#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
37#define TCM_MAP 1
38#else
39#define TCM_MAP 0
40#endif
41
42/* +1 is end of list which needs to be empty */
43#define ZYNQMP_MEM_MAP_MAX (ZYNQMP_MEM_MAP_USED + DRAM_BANKS + TCM_MAP + 1)
44
45static struct mm_region zynqmp_mem_map[ZYNQMP_MEM_MAP_MAX] = {
Siva Durga Prasad Paladugu3b644a32018-01-12 15:35:46 +053046 {
York Suncd4b0c52016-06-24 16:46:22 -070047 .virt = 0x80000000UL,
48 .phys = 0x80000000UL,
Alexander Graf96519f32016-03-04 01:09:49 +010049 .size = 0x70000000UL,
50 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
51 PTE_BLOCK_NON_SHARE |
52 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Nitin Jain06789412018-04-20 12:30:40 +053053 }, {
York Suncd4b0c52016-06-24 16:46:22 -070054 .virt = 0xf8000000UL,
55 .phys = 0xf8000000UL,
Alexander Graf96519f32016-03-04 01:09:49 +010056 .size = 0x07e00000UL,
57 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
58 PTE_BLOCK_NON_SHARE |
59 PTE_BLOCK_PXN | PTE_BLOCK_UXN
60 }, {
York Suncd4b0c52016-06-24 16:46:22 -070061 .virt = 0x400000000UL,
62 .phys = 0x400000000UL,
Anders Hedlund501fbc62017-12-19 17:24:41 +010063 .size = 0x400000000UL,
Alexander Graf96519f32016-03-04 01:09:49 +010064 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
65 PTE_BLOCK_NON_SHARE |
66 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Nitin Jain06789412018-04-20 12:30:40 +053067 }, {
Anders Hedlund501fbc62017-12-19 17:24:41 +010068 .virt = 0x1000000000UL,
69 .phys = 0x1000000000UL,
70 .size = 0xf000000000UL,
Alexander Graf96519f32016-03-04 01:09:49 +010071 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
72 PTE_BLOCK_NON_SHARE |
73 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Alexander Graf96519f32016-03-04 01:09:49 +010074 }
75};
Nitin Jain06789412018-04-20 12:30:40 +053076
77void mem_map_fill(void)
78{
79 int banks = ZYNQMP_MEM_MAP_USED;
80
81#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
82 zynqmp_mem_map[banks].virt = 0xffe00000UL;
83 zynqmp_mem_map[banks].phys = 0xffe00000UL;
84 zynqmp_mem_map[banks].size = 0x00200000UL;
85 zynqmp_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
86 PTE_BLOCK_INNER_SHARE;
87 banks = banks + 1;
88#endif
89
90#if !defined(CONFIG_ZYNQMP_NO_DDR)
91 for (int i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
92 /* Zero size means no more DDR that's this is end */
93 if (!gd->bd->bi_dram[i].size)
94 break;
95
96 zynqmp_mem_map[banks].virt = gd->bd->bi_dram[i].start;
97 zynqmp_mem_map[banks].phys = gd->bd->bi_dram[i].start;
98 zynqmp_mem_map[banks].size = gd->bd->bi_dram[i].size;
99 zynqmp_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
100 PTE_BLOCK_INNER_SHARE;
101 banks = banks + 1;
102 }
103#endif
104}
105
Alexander Graf96519f32016-03-04 01:09:49 +0100106struct mm_region *mem_map = zynqmp_mem_map;
107
Michal Simek9c152ed2016-05-30 10:41:26 +0200108u64 get_page_table_size(void)
109{
110 return 0x14000;
111}
112
Siva Durga Prasad Paladugu5860bc12018-10-05 15:09:05 +0530113#if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU) || defined(CONFIG_DEFINE_TCM_OCM_MMAP)
114void tcm_init(u8 mode)
Siva Durga Prasad Paladugu12ad2992018-10-05 15:09:04 +0530115{
116 puts("WARNING: Initializing TCM overwrites TCM content\n");
117 initialize_tcm(mode);
118 memset((void *)ZYNQMP_TCM_BASE_ADDR, 0, ZYNQMP_TCM_SIZE);
119}
Siva Durga Prasad Paladugu5860bc12018-10-05 15:09:05 +0530120#endif
Siva Durga Prasad Paladugu12ad2992018-10-05 15:09:04 +0530121
Siva Durga Prasad Paladugu5860bc12018-10-05 15:09:05 +0530122#ifdef CONFIG_SYS_MEM_RSVD_FOR_MMU
Ovidiu Panait61848582020-03-29 20:57:40 +0300123int arm_reserve_mmu(void)
Siva Durga Prasad Paladugue042d362017-07-13 19:01:11 +0530124{
Siva Durga Prasad Paladugu12ad2992018-10-05 15:09:04 +0530125 tcm_init(TCM_LOCK);
Siva Durga Prasad Paladugue042d362017-07-13 19:01:11 +0530126 gd->arch.tlb_size = PGTABLE_SIZE;
127 gd->arch.tlb_addr = ZYNQMP_TCM_BASE_ADDR;
128
129 return 0;
130}
131#endif
132
Michal Simek0785dfd2015-11-05 08:34:35 +0100133static unsigned int zynqmp_get_silicon_version_secure(void)
134{
135 u32 ver;
136
137 ver = readl(&csu_base->version);
138 ver &= ZYNQMP_SILICON_VER_MASK;
139 ver >>= ZYNQMP_SILICON_VER_SHIFT;
140
141 return ver;
142}
143
Michal Simek84c72042015-01-15 10:01:51 +0100144unsigned int zynqmp_get_silicon_version(void)
145{
Michal Simek0785dfd2015-11-05 08:34:35 +0100146 if (current_el() == 3)
147 return zynqmp_get_silicon_version_secure();
148
Michal Simek84c72042015-01-15 10:01:51 +0100149 gd->cpu_clk = get_tbclk();
150
151 switch (gd->cpu_clk) {
152 case 50000000:
153 return ZYNQMP_CSU_VERSION_QEMU;
154 }
155
Michal Simekbe6f6af2015-08-20 14:01:39 +0200156 return ZYNQMP_CSU_VERSION_SILICON;
Michal Simek84c72042015-01-15 10:01:51 +0100157}
Siva Durga Prasad Paladugue0752bc2017-02-02 01:10:46 +0530158
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530159static int zynqmp_mmio_rawwrite(const u32 address,
Siva Durga Prasad Paladugue0752bc2017-02-02 01:10:46 +0530160 const u32 mask,
161 const u32 value)
162{
163 u32 data;
164 u32 value_local = value;
Michal Simeke3c26b82018-06-13 10:38:33 +0200165 int ret;
Siva Durga Prasad Paladugue0752bc2017-02-02 01:10:46 +0530166
Michal Simeke3c26b82018-06-13 10:38:33 +0200167 ret = zynqmp_mmio_read(address, &data);
168 if (ret)
169 return ret;
170
Siva Durga Prasad Paladugue0752bc2017-02-02 01:10:46 +0530171 data &= ~mask;
172 value_local &= mask;
173 value_local |= data;
174 writel(value_local, (ulong)address);
175 return 0;
176}
177
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530178static int zynqmp_mmio_rawread(const u32 address, u32 *value)
Siva Durga Prasad Paladugue0752bc2017-02-02 01:10:46 +0530179{
180 *value = readl((ulong)address);
181 return 0;
182}
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530183
184int zynqmp_mmio_write(const u32 address,
185 const u32 mask,
186 const u32 value)
187{
188 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3)
189 return zynqmp_mmio_rawwrite(address, mask, value);
Michal Simek866225f2019-10-04 15:45:29 +0200190#if defined(CONFIG_ZYNQMP_FIRMWARE)
Heinrich Schuchardt549d6842017-10-13 01:14:27 +0200191 else
Michal Simek40361952019-10-04 15:35:45 +0200192 return xilinx_pm_request(PM_MMIO_WRITE, address, mask,
193 value, 0, NULL);
Michal Simek866225f2019-10-04 15:45:29 +0200194#endif
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530195
196 return -EINVAL;
197}
198
199int zynqmp_mmio_read(const u32 address, u32 *value)
200{
Michal Simek866225f2019-10-04 15:45:29 +0200201 u32 ret = -EINVAL;
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530202
203 if (!value)
Michal Simek866225f2019-10-04 15:45:29 +0200204 return ret;
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530205
206 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) {
207 ret = zynqmp_mmio_rawread(address, value);
Michal Simek866225f2019-10-04 15:45:29 +0200208 }
209#if defined(CONFIG_ZYNQMP_FIRMWARE)
210 else {
211 u32 ret_payload[PAYLOAD_ARG_CNT];
212
Michal Simek40361952019-10-04 15:35:45 +0200213 ret = xilinx_pm_request(PM_MMIO_READ, address, 0, 0,
214 0, ret_payload);
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530215 *value = ret_payload[1];
216 }
Michal Simek866225f2019-10-04 15:45:29 +0200217#endif
Siva Durga Prasad Paladugucb186e72017-07-13 19:01:12 +0530218
219 return ret;
220}