blob: b90d08bbdd4eacdb72c1a2f1040da6b0fd87f2f9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek04b7e622015-01-15 10:01:51 +01002/*
3 * (C) Copyright 2014 - 2015 Xilinx, Inc.
4 * Michal Simek <michal.simek@xilinx.com>
Michal Simek04b7e622015-01-15 10:01:51 +01005 */
6
7#include <common.h>
8#include <asm/arch/hardware.h>
9#include <asm/arch/sys_proto.h>
Alexander Graf0e2088c2016-03-04 01:09:49 +010010#include <asm/armv8/mmu.h>
Michal Simek04b7e622015-01-15 10:01:51 +010011#include <asm/io.h>
Ibai Erkiagac8a3efa2019-09-27 11:37:01 +010012#include <zynqmp_firmware.h>
Michal Simek04b7e622015-01-15 10:01:51 +010013
14#define ZYNQ_SILICON_VER_MASK 0xF000
15#define ZYNQ_SILICON_VER_SHIFT 12
16
17DECLARE_GLOBAL_DATA_PTR;
18
Nitin Jain9bcc76f2018-04-20 12:30:40 +053019/*
20 * Number of filled static entries and also the first empty
21 * slot in zynqmp_mem_map.
22 */
23#define ZYNQMP_MEM_MAP_USED 4
24
Siva Durga Prasad Paladugucafb6312018-01-12 15:35:46 +053025#if !defined(CONFIG_ZYNQMP_NO_DDR)
Nitin Jain9bcc76f2018-04-20 12:30:40 +053026#define DRAM_BANKS CONFIG_NR_DRAM_BANKS
27#else
28#define DRAM_BANKS 0
29#endif
30
31#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
32#define TCM_MAP 1
33#else
34#define TCM_MAP 0
Siva Durga Prasad Paladugucafb6312018-01-12 15:35:46 +053035#endif
Nitin Jain9bcc76f2018-04-20 12:30:40 +053036
37/* +1 is end of list which needs to be empty */
38#define ZYNQMP_MEM_MAP_MAX (ZYNQMP_MEM_MAP_USED + DRAM_BANKS + TCM_MAP + 1)
39
40static struct mm_region zynqmp_mem_map[ZYNQMP_MEM_MAP_MAX] = {
Siva Durga Prasad Paladugucafb6312018-01-12 15:35:46 +053041 {
York Sunc7104e52016-06-24 16:46:22 -070042 .virt = 0x80000000UL,
43 .phys = 0x80000000UL,
Alexander Graf0e2088c2016-03-04 01:09:49 +010044 .size = 0x70000000UL,
45 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
46 PTE_BLOCK_NON_SHARE |
47 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Nitin Jain9bcc76f2018-04-20 12:30:40 +053048 }, {
York Sunc7104e52016-06-24 16:46:22 -070049 .virt = 0xf8000000UL,
50 .phys = 0xf8000000UL,
Alexander Graf0e2088c2016-03-04 01:09:49 +010051 .size = 0x07e00000UL,
52 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
53 PTE_BLOCK_NON_SHARE |
54 PTE_BLOCK_PXN | PTE_BLOCK_UXN
55 }, {
York Sunc7104e52016-06-24 16:46:22 -070056 .virt = 0x400000000UL,
57 .phys = 0x400000000UL,
Anders Hedlundfcc09922017-12-19 17:24:41 +010058 .size = 0x400000000UL,
Alexander Graf0e2088c2016-03-04 01:09:49 +010059 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
60 PTE_BLOCK_NON_SHARE |
61 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Nitin Jain9bcc76f2018-04-20 12:30:40 +053062 }, {
Anders Hedlundfcc09922017-12-19 17:24:41 +010063 .virt = 0x1000000000UL,
64 .phys = 0x1000000000UL,
65 .size = 0xf000000000UL,
Alexander Graf0e2088c2016-03-04 01:09:49 +010066 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
67 PTE_BLOCK_NON_SHARE |
68 PTE_BLOCK_PXN | PTE_BLOCK_UXN
Alexander Graf0e2088c2016-03-04 01:09:49 +010069 }
70};
Nitin Jain9bcc76f2018-04-20 12:30:40 +053071
72void mem_map_fill(void)
73{
74 int banks = ZYNQMP_MEM_MAP_USED;
75
76#if defined(CONFIG_DEFINE_TCM_OCM_MMAP)
77 zynqmp_mem_map[banks].virt = 0xffe00000UL;
78 zynqmp_mem_map[banks].phys = 0xffe00000UL;
79 zynqmp_mem_map[banks].size = 0x00200000UL;
80 zynqmp_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
81 PTE_BLOCK_INNER_SHARE;
82 banks = banks + 1;
83#endif
84
85#if !defined(CONFIG_ZYNQMP_NO_DDR)
86 for (int i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
87 /* Zero size means no more DDR that's this is end */
88 if (!gd->bd->bi_dram[i].size)
89 break;
90
91 zynqmp_mem_map[banks].virt = gd->bd->bi_dram[i].start;
92 zynqmp_mem_map[banks].phys = gd->bd->bi_dram[i].start;
93 zynqmp_mem_map[banks].size = gd->bd->bi_dram[i].size;
94 zynqmp_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
95 PTE_BLOCK_INNER_SHARE;
96 banks = banks + 1;
97 }
98#endif
99}
100
Alexander Graf0e2088c2016-03-04 01:09:49 +0100101struct mm_region *mem_map = zynqmp_mem_map;
102
Michal Simek1a2d5e22016-05-30 10:41:26 +0200103u64 get_page_table_size(void)
104{
105 return 0x14000;
106}
107
Siva Durga Prasad Paladugu48eaa0c2018-10-05 15:09:05 +0530108#if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU) || defined(CONFIG_DEFINE_TCM_OCM_MMAP)
109void tcm_init(u8 mode)
Siva Durga Prasad Paladugu4628c502017-07-13 19:01:11 +0530110{
Siva Durga Prasad Paladugua1ad8782018-10-05 15:09:04 +0530111 puts("WARNING: Initializing TCM overwrites TCM content\n");
112 initialize_tcm(mode);
Siva Durga Prasad Paladugu4628c502017-07-13 19:01:11 +0530113 memset((void *)ZYNQMP_TCM_BASE_ADDR, 0, ZYNQMP_TCM_SIZE);
Siva Durga Prasad Paladugua1ad8782018-10-05 15:09:04 +0530114}
Siva Durga Prasad Paladugu48eaa0c2018-10-05 15:09:05 +0530115#endif
Siva Durga Prasad Paladugua1ad8782018-10-05 15:09:04 +0530116
Siva Durga Prasad Paladugu48eaa0c2018-10-05 15:09:05 +0530117#ifdef CONFIG_SYS_MEM_RSVD_FOR_MMU
Siva Durga Prasad Paladugua1ad8782018-10-05 15:09:04 +0530118int reserve_mmu(void)
119{
120 tcm_init(TCM_LOCK);
Siva Durga Prasad Paladugu4628c502017-07-13 19:01:11 +0530121 gd->arch.tlb_size = PGTABLE_SIZE;
122 gd->arch.tlb_addr = ZYNQMP_TCM_BASE_ADDR;
123
124 return 0;
125}
126#endif
127
Michal Simekc23d3f82015-11-05 08:34:35 +0100128static unsigned int zynqmp_get_silicon_version_secure(void)
129{
130 u32 ver;
131
132 ver = readl(&csu_base->version);
133 ver &= ZYNQMP_SILICON_VER_MASK;
134 ver >>= ZYNQMP_SILICON_VER_SHIFT;
135
136 return ver;
137}
138
Michal Simek04b7e622015-01-15 10:01:51 +0100139unsigned int zynqmp_get_silicon_version(void)
140{
Michal Simekc23d3f82015-11-05 08:34:35 +0100141 if (current_el() == 3)
142 return zynqmp_get_silicon_version_secure();
143
Michal Simek04b7e622015-01-15 10:01:51 +0100144 gd->cpu_clk = get_tbclk();
145
146 switch (gd->cpu_clk) {
147 case 50000000:
148 return ZYNQMP_CSU_VERSION_QEMU;
149 }
150
Michal Simek8d2c02d2015-08-20 14:01:39 +0200151 return ZYNQMP_CSU_VERSION_SILICON;
Michal Simek04b7e622015-01-15 10:01:51 +0100152}
Siva Durga Prasad Paladugu0e39bd72017-02-02 01:10:46 +0530153
Siva Durga Prasad Paladugu668fdd42017-07-13 19:01:12 +0530154static int zynqmp_mmio_rawwrite(const u32 address,
Siva Durga Prasad Paladugu0e39bd72017-02-02 01:10:46 +0530155 const u32 mask,
156 const u32 value)
157{
158 u32 data;
159 u32 value_local = value;
Michal Simekfaac0ce2018-06-13 10:38:33 +0200160 int ret;
161
162 ret = zynqmp_mmio_read(address, &data);
163 if (ret)
164 return ret;
Siva Durga Prasad Paladugu0e39bd72017-02-02 01:10:46 +0530165
Siva Durga Prasad Paladugu0e39bd72017-02-02 01:10:46 +0530166 data &= ~mask;
167 value_local &= mask;
168 value_local |= data;
169 writel(value_local, (ulong)address);
170 return 0;
171}
172
Siva Durga Prasad Paladugu668fdd42017-07-13 19:01:12 +0530173static int zynqmp_mmio_rawread(const u32 address, u32 *value)
Siva Durga Prasad Paladugu0e39bd72017-02-02 01:10:46 +0530174{
175 *value = readl((ulong)address);
176 return 0;
177}
Siva Durga Prasad Paladugu668fdd42017-07-13 19:01:12 +0530178
179int zynqmp_mmio_write(const u32 address,
180 const u32 mask,
181 const u32 value)
182{
183 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3)
184 return zynqmp_mmio_rawwrite(address, mask, value);
Michal Simek81efd2a2019-10-04 15:45:29 +0200185#if defined(CONFIG_ZYNQMP_FIRMWARE)
Heinrich Schuchardt9f92f792017-10-13 01:14:27 +0200186 else
Michal Simek4c3de372019-10-04 15:35:45 +0200187 return xilinx_pm_request(PM_MMIO_WRITE, address, mask,
188 value, 0, NULL);
Michal Simek81efd2a2019-10-04 15:45:29 +0200189#endif
Siva Durga Prasad Paladugu668fdd42017-07-13 19:01:12 +0530190
191 return -EINVAL;
192}
193
194int zynqmp_mmio_read(const u32 address, u32 *value)
195{
Michal Simek81efd2a2019-10-04 15:45:29 +0200196 u32 ret = -EINVAL;
Siva Durga Prasad Paladugu668fdd42017-07-13 19:01:12 +0530197
198 if (!value)
Michal Simek81efd2a2019-10-04 15:45:29 +0200199 return ret;
Siva Durga Prasad Paladugu668fdd42017-07-13 19:01:12 +0530200
201 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) {
202 ret = zynqmp_mmio_rawread(address, value);
Michal Simek81efd2a2019-10-04 15:45:29 +0200203 }
204#if defined(CONFIG_ZYNQMP_FIRMWARE)
205 else {
206 u32 ret_payload[PAYLOAD_ARG_CNT];
207
Michal Simek4c3de372019-10-04 15:35:45 +0200208 ret = xilinx_pm_request(PM_MMIO_READ, address, 0, 0,
209 0, ret_payload);
Siva Durga Prasad Paladugu668fdd42017-07-13 19:01:12 +0530210 *value = ret_payload[1];
211 }
Michal Simek81efd2a2019-10-04 15:45:29 +0200212#endif
Siva Durga Prasad Paladugu668fdd42017-07-13 19:01:12 +0530213
214 return ret;
215}