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 | |
Michal Simek | dfcd21d | 2020-03-18 13:45:21 +0100 | [diff] [blame^] | 84 | #if defined(CONFIG_VERSAL_NO_DDR) |
| 85 | if (gd->bd->bi_dram[i].start < 0x80000000UL || |
| 86 | gd->bd->bi_dram[i].start > 0x100000000UL) { |
| 87 | printf("Ignore caches over %llx/%llx\n", |
| 88 | gd->bd->bi_dram[i].start, |
| 89 | gd->bd->bi_dram[i].size); |
| 90 | continue; |
| 91 | } |
| 92 | #endif |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 93 | versal_mem_map[banks].virt = gd->bd->bi_dram[i].start; |
| 94 | versal_mem_map[banks].phys = gd->bd->bi_dram[i].start; |
| 95 | versal_mem_map[banks].size = gd->bd->bi_dram[i].size; |
| 96 | versal_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 97 | PTE_BLOCK_INNER_SHARE; |
| 98 | banks = banks + 1; |
| 99 | } |
| 100 | } |
| 101 | |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 102 | struct mm_region *mem_map = versal_mem_map; |
| 103 | |
| 104 | u64 get_page_table_size(void) |
| 105 | { |
| 106 | return 0x14000; |
| 107 | } |
Siva Durga Prasad Paladugu | 775aa95 | 2019-01-08 21:47:26 +0530 | [diff] [blame] | 108 | |
| 109 | #if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU) |
| 110 | int reserve_mmu(void) |
| 111 | { |
| 112 | tcm_init(TCM_LOCK); |
| 113 | gd->arch.tlb_size = PGTABLE_SIZE; |
| 114 | gd->arch.tlb_addr = VERSAL_TCM_BASE_ADDR; |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | #endif |