Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 1 | // 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 Paladugu | 775aa95 | 2019-01-08 21:47:26 +0530 | [diff] [blame] | 10 | #include <asm/arch/hardware.h> |
| 11 | #include <asm/arch/sys_proto.h> |
| 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 14 | |
Michal Simek | fe2eb11 | 2019-09-11 09:39:59 +0200 | [diff] [blame] | 15 | #define VERSAL_MEM_MAP_USED 5 |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 16 | |
| 17 | #define DRAM_BANKS CONFIG_NR_DRAM_BANKS |
| 18 | |
Michal Simek | fe2eb11 | 2019-09-11 09:39:59 +0200 | [diff] [blame] | 19 | #if defined(CONFIG_DEFINE_TCM_OCM_MMAP) |
| 20 | #define TCM_MAP 1 |
| 21 | #else |
| 22 | #define TCM_MAP 0 |
| 23 | #endif |
| 24 | |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 25 | /* +1 is end of list which needs to be empty */ |
Michal Simek | fe2eb11 | 2019-09-11 09:39:59 +0200 | [diff] [blame] | 26 | #define VERSAL_MEM_MAP_MAX (VERSAL_MEM_MAP_USED + DRAM_BANKS + TCM_MAP + 1) |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 27 | |
| 28 | static struct mm_region versal_mem_map[VERSAL_MEM_MAP_MAX] = { |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 29 | { |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 30 | .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 Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 44 | .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 Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 63 | } |
| 64 | }; |
| 65 | |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 66 | void mem_map_fill(void) |
| 67 | { |
| 68 | int banks = VERSAL_MEM_MAP_USED; |
| 69 | |
Michal Simek | fe2eb11 | 2019-09-11 09:39:59 +0200 | [diff] [blame] | 70 | #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 Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 79 | 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 Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 93 | struct mm_region *mem_map = versal_mem_map; |
| 94 | |
| 95 | u64 get_page_table_size(void) |
| 96 | { |
| 97 | return 0x14000; |
| 98 | } |
Siva Durga Prasad Paladugu | 775aa95 | 2019-01-08 21:47:26 +0530 | [diff] [blame] | 99 | |
| 100 | #if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU) |
| 101 | int 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 Simek | c3c3106 | 2018-09-18 14:58:16 +0200 | [diff] [blame] | 110 | |
| 111 | #if defined(CONFIG_OF_BOARD) |
| 112 | void *board_fdt_blob_setup(void) |
| 113 | { |
| 114 | static void *fw_dtb = (void *)CONFIG_VERSAL_OF_BOARD_DTB_ADDR; |
| 115 | |
| 116 | if (fdt_magic(fw_dtb) != FDT_MAGIC) { |
| 117 | printf("DTB is not passed via %llx\n", (u64)fw_dtb); |
| 118 | return NULL; |
| 119 | } |
| 120 | |
| 121 | return fw_dtb; |
| 122 | } |
| 123 | #endif |
Siva Durga Prasad Paladugu | f7a7120 | 2019-06-23 12:24:57 +0530 | [diff] [blame^] | 124 | |
| 125 | int versal_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2, |
| 126 | u32 arg3, u32 *ret_payload) |
| 127 | { |
| 128 | struct pt_regs regs; |
| 129 | |
| 130 | if (current_el() == 3) |
| 131 | return 0; |
| 132 | |
| 133 | regs.regs[0] = PM_SIP_SVC | api_id; |
| 134 | regs.regs[1] = ((u64)arg1 << 32) | arg0; |
| 135 | regs.regs[2] = ((u64)arg3 << 32) | arg2; |
| 136 | |
| 137 | smc_call(®s); |
| 138 | |
| 139 | if (ret_payload) { |
| 140 | ret_payload[0] = (u32)regs.regs[0]; |
| 141 | ret_payload[1] = upper_32_bits(regs.regs[0]); |
| 142 | ret_payload[2] = (u32)regs.regs[1]; |
| 143 | ret_payload[3] = upper_32_bits(regs.regs[1]); |
| 144 | ret_payload[4] = (u32)regs.regs[2]; |
| 145 | } |
| 146 | |
| 147 | return regs.regs[0]; |
| 148 | } |