]> git.sur5r.net Git - u-boot/blob - arch/arm/mach-meson/board.c
Merge git://git.denx.de/u-boot-mmc
[u-boot] / arch / arm / mach-meson / board.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
4  */
5
6 #include <common.h>
7 #include <linux/libfdt.h>
8 #include <linux/err.h>
9 #include <asm/arch/gx.h>
10 #include <asm/arch/sm.h>
11 #include <asm/armv8/mmu.h>
12 #include <asm/unaligned.h>
13 #include <linux/sizes.h>
14 #include <efi_loader.h>
15 #include <asm/io.h>
16
17 DECLARE_GLOBAL_DATA_PTR;
18
19 int dram_init(void)
20 {
21         const fdt64_t *val;
22         int offset;
23         int len;
24
25         offset = fdt_path_offset(gd->fdt_blob, "/memory");
26         if (offset < 0)
27                 return -EINVAL;
28
29         val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
30         if (len < sizeof(*val) * 2)
31                 return -EINVAL;
32
33         /* Use unaligned access since cache is still disabled */
34         gd->ram_size = get_unaligned_be64(&val[1]);
35
36         return 0;
37 }
38
39 phys_size_t get_effective_memsize(void)
40 {
41         /* Size is reported in MiB, convert it in bytes */
42         return ((readl(GX_AO_SEC_GP_CFG0) & GX_AO_MEM_SIZE_MASK)
43                         >> GX_AO_MEM_SIZE_SHIFT) * SZ_1M;
44 }
45
46 static void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
47 {
48         int ret;
49
50         ret = fdt_add_mem_rsv(fdt, start, size);
51         if (ret)
52                 printf("Could not reserve zone @ 0x%llx\n", start);
53
54         if (IS_ENABLED(CONFIG_EFI_LOADER)) {
55                 efi_add_memory_map(start,
56                                    ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT,
57                                    EFI_RESERVED_MEMORY_TYPE, false);
58         }
59 }
60
61 void meson_gx_init_reserved_memory(void *fdt)
62 {
63         u64 bl31_size, bl31_start;
64         u64 bl32_size, bl32_start;
65         u32 reg;
66
67         /*
68          * Get ARM Trusted Firmware reserved memory zones in :
69          * - AO_SEC_GP_CFG3: bl32 & bl31 size in KiB, can be 0
70          * - AO_SEC_GP_CFG5: bl31 physical start address, can be NULL
71          * - AO_SEC_GP_CFG4: bl32 physical start address, can be NULL
72          */
73
74         reg = readl(GX_AO_SEC_GP_CFG3);
75
76         bl31_size = ((reg & GX_AO_BL31_RSVMEM_SIZE_MASK)
77                         >> GX_AO_BL31_RSVMEM_SIZE_SHIFT) * SZ_1K;
78         bl32_size = (reg & GX_AO_BL32_RSVMEM_SIZE_MASK) * SZ_1K;
79
80         bl31_start = readl(GX_AO_SEC_GP_CFG5);
81         bl32_start = readl(GX_AO_SEC_GP_CFG4);
82
83         /*
84          * Early Meson GX Firmware revisions did not provide the reserved
85          * memory zones in the registers, keep fixed memory zone handling.
86          */
87         if (IS_ENABLED(CONFIG_MESON_GX) &&
88             !reg && !bl31_start && !bl32_start) {
89                 bl31_start = 0x10000000;
90                 bl31_size = 0x200000;
91         }
92
93         /* Add first 16MiB reserved zone */
94         meson_board_add_reserved_memory(fdt, 0, GX_FIRMWARE_MEM_SIZE);
95
96         /* Add BL31 reserved zone */
97         if (bl31_start && bl31_size)
98                 meson_board_add_reserved_memory(fdt, bl31_start, bl31_size);
99
100         /* Add BL32 reserved zone */
101         if (bl32_start && bl32_size)
102                 meson_board_add_reserved_memory(fdt, bl32_start, bl32_size);
103 }
104
105 void reset_cpu(ulong addr)
106 {
107         psci_system_reset();
108 }
109
110 static struct mm_region gx_mem_map[] = {
111         {
112                 .virt = 0x0UL,
113                 .phys = 0x0UL,
114                 .size = 0x80000000UL,
115                 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
116                          PTE_BLOCK_INNER_SHARE
117         }, {
118                 .virt = 0x80000000UL,
119                 .phys = 0x80000000UL,
120                 .size = 0x80000000UL,
121                 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
122                          PTE_BLOCK_NON_SHARE |
123                          PTE_BLOCK_PXN | PTE_BLOCK_UXN
124         }, {
125                 /* List terminator */
126                 0,
127         }
128 };
129
130 struct mm_region *mem_map = gx_mem_map;