blob: 16237e29e4673e1995d37a93aef0e599652cec8a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +03002/*
3 * Copyright (c) 2017 Tuomas Tynkkynen
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +03004 */
Bin Menga94f6a02018-10-15 02:21:19 -07005
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +03006#include <common.h>
Ard Biesheuvel58f0bb92020-07-07 12:07:09 +02007#include <cpu_func.h>
Bin Menga94f6a02018-10-15 02:21:19 -07008#include <dm.h>
Sughosh Ganuccb36462022-04-15 11:29:34 +05309#include <efi.h>
10#include <efi_loader.h>
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030011#include <fdtdec.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Bin Menga94f6a02018-10-15 02:21:19 -070014#include <virtio_types.h>
15#include <virtio.h>
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030016
Sughosh Ganuccb36462022-04-15 11:29:34 +053017#include <linux/kernel.h>
18
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020019#ifdef CONFIG_ARM64
20#include <asm/armv8/mmu.h>
21
Sughosh Ganuccb36462022-04-15 11:29:34 +053022#if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
23struct efi_fw_image fw_images[] = {
24#if defined(CONFIG_TARGET_QEMU_ARM_32BIT)
25 {
26 .image_type_id = QEMU_ARM_UBOOT_IMAGE_GUID,
27 .fw_name = u"Qemu-Arm-UBOOT",
28 .image_index = 1,
29 },
30#elif defined(CONFIG_TARGET_QEMU_ARM_64BIT)
31 {
32 .image_type_id = QEMU_ARM64_UBOOT_IMAGE_GUID,
33 .fw_name = u"Qemu-Arm-UBOOT",
34 .image_index = 1,
35 },
36#endif
37};
38
39struct efi_capsule_update_info update_info = {
40 .images = fw_images,
41};
42
43u8 num_image_type_guids = ARRAY_SIZE(fw_images);
44#endif /* EFI_HAVE_CAPSULE_SUPPORT */
45
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020046static struct mm_region qemu_arm64_mem_map[] = {
47 {
48 /* Flash */
49 .virt = 0x00000000UL,
50 .phys = 0x00000000UL,
51 .size = 0x08000000UL,
52 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
53 PTE_BLOCK_INNER_SHARE
54 }, {
Tuomas Tynkkynene09ca642018-09-04 18:16:52 +030055 /* Lowmem peripherals */
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020056 .virt = 0x08000000UL,
57 .phys = 0x08000000UL,
58 .size = 0x38000000,
59 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
60 PTE_BLOCK_NON_SHARE |
61 PTE_BLOCK_PXN | PTE_BLOCK_UXN
62 }, {
63 /* RAM */
64 .virt = 0x40000000UL,
65 .phys = 0x40000000UL,
Tuomas Tynkkynenac927392018-05-14 18:47:51 +030066 .size = 255UL * SZ_1G,
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020067 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
68 PTE_BLOCK_INNER_SHARE
69 }, {
Tuomas Tynkkynene09ca642018-09-04 18:16:52 +030070 /* Highmem PCI-E ECAM memory area */
71 .virt = 0x4010000000ULL,
72 .phys = 0x4010000000ULL,
73 .size = 0x10000000,
74 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
75 PTE_BLOCK_NON_SHARE |
76 PTE_BLOCK_PXN | PTE_BLOCK_UXN
77 }, {
78 /* Highmem PCI-E MMIO memory area */
79 .virt = 0x8000000000ULL,
80 .phys = 0x8000000000ULL,
81 .size = 0x8000000000ULL,
82 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
83 PTE_BLOCK_NON_SHARE |
84 PTE_BLOCK_PXN | PTE_BLOCK_UXN
85 }, {
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020086 /* List terminator */
87 0,
88 }
89};
90
91struct mm_region *mem_map = qemu_arm64_mem_map;
92#endif
93
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030094int board_init(void)
95{
Sughosh Ganu1316a702020-12-30 19:27:00 +053096 return 0;
97}
98
99int board_late_init(void)
100{
Bin Menga94f6a02018-10-15 02:21:19 -0700101 /*
102 * Make sure virtio bus is enumerated so that peripherals
103 * on the virtio bus can be discovered by their drivers
104 */
105 virtio_init();
106
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +0300107 return 0;
108}
109
110int dram_init(void)
111{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +0530112 if (fdtdec_setup_mem_size_base() != 0)
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +0300113 return -EINVAL;
114
115 return 0;
116}
117
118int dram_init_banksize(void)
119{
120 fdtdec_setup_memory_banksize();
121
122 return 0;
123}
124
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300125void *board_fdt_blob_setup(int *err)
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +0300126{
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300127 *err = 0;
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +0300128 /* QEMU loads a generated DTB for us at the start of RAM. */
129 return (void *)CONFIG_SYS_SDRAM_BASE;
130}
Sughosh Ganu7064a5d2019-12-29 00:01:05 +0530131
Ard Biesheuvel58f0bb92020-07-07 12:07:09 +0200132void enable_caches(void)
133{
134 icache_enable();
135 dcache_enable();
136}
137
Ard Biesheuvelcd360da2020-07-07 12:07:11 +0200138#ifdef CONFIG_ARM64
139#define __W "w"
140#else
141#define __W
142#endif
143
144u8 flash_read8(void *addr)
145{
146 u8 ret;
147
148 asm("ldrb %" __W "0, %1" : "=r"(ret) : "m"(*(u8 *)addr));
149 return ret;
150}
151
152u16 flash_read16(void *addr)
153{
154 u16 ret;
155
156 asm("ldrh %" __W "0, %1" : "=r"(ret) : "m"(*(u16 *)addr));
157 return ret;
158}
159
160u32 flash_read32(void *addr)
161{
162 u32 ret;
163
164 asm("ldr %" __W "0, %1" : "=r"(ret) : "m"(*(u32 *)addr));
165 return ret;
166}
167
168void flash_write8(u8 value, void *addr)
169{
170 asm("strb %" __W "1, %0" : "=m"(*(u8 *)addr) : "r"(value));
171}
172
173void flash_write16(u16 value, void *addr)
174{
175 asm("strh %" __W "1, %0" : "=m"(*(u16 *)addr) : "r"(value));
176}
177
178void flash_write32(u32 value, void *addr)
179{
180 asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value));
181}