blob: 49f1e51c8ea52c38857d7fb6fd8f364712da955a [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
84 versal_mem_map[banks].virt = gd->bd->bi_dram[i].start;
85 versal_mem_map[banks].phys = gd->bd->bi_dram[i].start;
86 versal_mem_map[banks].size = gd->bd->bi_dram[i].size;
87 versal_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
88 PTE_BLOCK_INNER_SHARE;
89 banks = banks + 1;
90 }
91}
92
Michal Simek4b066a12018-08-22 14:55:27 +020093struct mm_region *mem_map = versal_mem_map;
94
95u64 get_page_table_size(void)
96{
97 return 0x14000;
98}
Siva Durga Prasad Paladugu775aa952019-01-08 21:47:26 +053099
100#if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU)
101int reserve_mmu(void)
102{
103 tcm_init(TCM_LOCK);
104 gd->arch.tlb_size = PGTABLE_SIZE;
105 gd->arch.tlb_addr = VERSAL_TCM_BASE_ADDR;
106
107 return 0;
108}
109#endif
Michal Simekc3c31062018-09-18 14:58:16 +0200110
Siva Durga Prasad Paladuguf7a71202019-06-23 12:24:57 +0530111int versal_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2,
112 u32 arg3, u32 *ret_payload)
113{
114 struct pt_regs regs;
115
116 if (current_el() == 3)
117 return 0;
118
119 regs.regs[0] = PM_SIP_SVC | api_id;
120 regs.regs[1] = ((u64)arg1 << 32) | arg0;
121 regs.regs[2] = ((u64)arg3 << 32) | arg2;
122
123 smc_call(&regs);
124
125 if (ret_payload) {
126 ret_payload[0] = (u32)regs.regs[0];
127 ret_payload[1] = upper_32_bits(regs.regs[0]);
128 ret_payload[2] = (u32)regs.regs[1];
129 ret_payload[3] = upper_32_bits(regs.regs[1]);
130 ret_payload[4] = (u32)regs.regs[2];
131 }
132
133 return regs.regs[0];
134}