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> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 9 | #include <asm/cache.h> |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 10 | #include <asm/io.h> |
Siva Durga Prasad Paladugu | 775aa95 | 2019-01-08 21:47:26 +0530 | [diff] [blame] | 11 | #include <asm/arch/hardware.h> |
| 12 | #include <asm/arch/sys_proto.h> |
Ovidiu Panait | 2b61847 | 2020-03-29 20:57:40 +0300 | [diff] [blame] | 13 | #include <asm/cache.h> |
Siva Durga Prasad Paladugu | 775aa95 | 2019-01-08 21:47:26 +0530 | [diff] [blame] | 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 16 | |
Michal Simek | fe2eb11 | 2019-09-11 09:39:59 +0200 | [diff] [blame] | 17 | #define VERSAL_MEM_MAP_USED 5 |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 18 | |
| 19 | #define DRAM_BANKS CONFIG_NR_DRAM_BANKS |
| 20 | |
Michal Simek | fe2eb11 | 2019-09-11 09:39:59 +0200 | [diff] [blame] | 21 | #if defined(CONFIG_DEFINE_TCM_OCM_MMAP) |
| 22 | #define TCM_MAP 1 |
| 23 | #else |
| 24 | #define TCM_MAP 0 |
| 25 | #endif |
| 26 | |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 27 | /* +1 is end of list which needs to be empty */ |
Michal Simek | fe2eb11 | 2019-09-11 09:39:59 +0200 | [diff] [blame] | 28 | #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] | 29 | |
| 30 | static struct mm_region versal_mem_map[VERSAL_MEM_MAP_MAX] = { |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 31 | { |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 32 | .virt = 0x80000000UL, |
| 33 | .phys = 0x80000000UL, |
| 34 | .size = 0x70000000UL, |
| 35 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 36 | PTE_BLOCK_NON_SHARE | |
| 37 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 38 | }, { |
| 39 | .virt = 0xf0000000UL, |
| 40 | .phys = 0xf0000000UL, |
| 41 | .size = 0x0fe00000UL, |
| 42 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 43 | PTE_BLOCK_NON_SHARE | |
| 44 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 45 | }, { |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 46 | .virt = 0x400000000UL, |
| 47 | .phys = 0x400000000UL, |
| 48 | .size = 0x200000000UL, |
| 49 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 50 | PTE_BLOCK_NON_SHARE | |
| 51 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 52 | }, { |
| 53 | .virt = 0x600000000UL, |
| 54 | .phys = 0x600000000UL, |
| 55 | .size = 0x800000000UL, |
| 56 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 57 | PTE_BLOCK_INNER_SHARE |
| 58 | }, { |
| 59 | .virt = 0xe00000000UL, |
| 60 | .phys = 0xe00000000UL, |
| 61 | .size = 0xf200000000UL, |
| 62 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 63 | PTE_BLOCK_NON_SHARE | |
| 64 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 65 | } |
| 66 | }; |
| 67 | |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 68 | void mem_map_fill(void) |
| 69 | { |
| 70 | int banks = VERSAL_MEM_MAP_USED; |
| 71 | |
Michal Simek | fe2eb11 | 2019-09-11 09:39:59 +0200 | [diff] [blame] | 72 | #if defined(CONFIG_DEFINE_TCM_OCM_MMAP) |
| 73 | versal_mem_map[banks].virt = 0xffe00000UL; |
| 74 | versal_mem_map[banks].phys = 0xffe00000UL; |
| 75 | versal_mem_map[banks].size = 0x00200000UL; |
| 76 | versal_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 77 | PTE_BLOCK_INNER_SHARE; |
| 78 | banks = banks + 1; |
| 79 | #endif |
| 80 | |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 81 | for (int i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 82 | /* Zero size means no more DDR that's this is end */ |
| 83 | if (!gd->bd->bi_dram[i].size) |
| 84 | break; |
| 85 | |
Michal Simek | dfcd21d | 2020-03-18 13:45:21 +0100 | [diff] [blame] | 86 | #if defined(CONFIG_VERSAL_NO_DDR) |
| 87 | if (gd->bd->bi_dram[i].start < 0x80000000UL || |
| 88 | gd->bd->bi_dram[i].start > 0x100000000UL) { |
| 89 | printf("Ignore caches over %llx/%llx\n", |
| 90 | gd->bd->bi_dram[i].start, |
| 91 | gd->bd->bi_dram[i].size); |
| 92 | continue; |
| 93 | } |
| 94 | #endif |
Michal Simek | 21eb5cc | 2019-04-29 09:39:09 -0700 | [diff] [blame] | 95 | versal_mem_map[banks].virt = gd->bd->bi_dram[i].start; |
| 96 | versal_mem_map[banks].phys = gd->bd->bi_dram[i].start; |
| 97 | versal_mem_map[banks].size = gd->bd->bi_dram[i].size; |
| 98 | versal_mem_map[banks].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 99 | PTE_BLOCK_INNER_SHARE; |
| 100 | banks = banks + 1; |
| 101 | } |
| 102 | } |
| 103 | |
Michal Simek | 4b066a1 | 2018-08-22 14:55:27 +0200 | [diff] [blame] | 104 | struct mm_region *mem_map = versal_mem_map; |
| 105 | |
| 106 | u64 get_page_table_size(void) |
| 107 | { |
| 108 | return 0x14000; |
| 109 | } |
Siva Durga Prasad Paladugu | 775aa95 | 2019-01-08 21:47:26 +0530 | [diff] [blame] | 110 | |
| 111 | #if defined(CONFIG_SYS_MEM_RSVD_FOR_MMU) |
Ovidiu Panait | 2b61847 | 2020-03-29 20:57:40 +0300 | [diff] [blame] | 112 | int arm_reserve_mmu(void) |
Siva Durga Prasad Paladugu | 775aa95 | 2019-01-08 21:47:26 +0530 | [diff] [blame] | 113 | { |
| 114 | tcm_init(TCM_LOCK); |
| 115 | gd->arch.tlb_size = PGTABLE_SIZE; |
| 116 | gd->arch.tlb_addr = VERSAL_TCM_BASE_ADDR; |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | #endif |