blob: 942f1fff571720f15a90647b082a5535c9f513c5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +03002/*
3 * Copyright (c) 2017 Tuomas Tynkkynen
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +03004 */
Bin Mengb9b59562018-10-15 02:21:19 -07005
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +03006#include <common.h>
Ard Biesheuvel3fa914a2020-07-07 12:07:09 +02007#include <cpu_func.h>
Bin Mengb9b59562018-10-15 02:21:19 -07008#include <dm.h>
Sughosh Ganu741ef862022-04-15 11:29:34 +05309#include <efi.h>
10#include <efi_loader.h>
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +030011#include <fdtdec.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Alper Nebi Yasak05e2fa72023-08-14 20:39:43 +030014#include <usb.h>
Bin Mengb9b59562018-10-15 02:21:19 -070015#include <virtio_types.h>
16#include <virtio.h>
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +030017
Sughosh Ganu741ef862022-04-15 11:29:34 +053018#include <linux/kernel.h>
Simon Glass662cfa02023-01-28 15:00:28 -070019#include <linux/sizes.h>
20
21/* GUIDs for capsule updatable firmware images */
22#define QEMU_ARM_UBOOT_IMAGE_GUID \
23 EFI_GUID(0xf885b085, 0x99f8, 0x45af, 0x84, 0x7d, \
24 0xd5, 0x14, 0x10, 0x7a, 0x4a, 0x2c)
25
26#define QEMU_ARM64_UBOOT_IMAGE_GUID \
27 EFI_GUID(0x058b7d83, 0x50d5, 0x4c47, 0xa1, 0x95, \
28 0x60, 0xd8, 0x6a, 0xd3, 0x41, 0xc4)
Sughosh Ganu741ef862022-04-15 11:29:34 +053029
Tuomas Tynkkynenddcca732018-01-11 16:11:23 +020030#ifdef CONFIG_ARM64
31#include <asm/armv8/mmu.h>
32
Simon Glass71aa8062023-02-05 15:39:42 -070033#if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
Sughosh Ganu741ef862022-04-15 11:29:34 +053034struct efi_fw_image fw_images[] = {
35#if defined(CONFIG_TARGET_QEMU_ARM_32BIT)
36 {
37 .image_type_id = QEMU_ARM_UBOOT_IMAGE_GUID,
38 .fw_name = u"Qemu-Arm-UBOOT",
39 .image_index = 1,
40 },
41#elif defined(CONFIG_TARGET_QEMU_ARM_64BIT)
42 {
43 .image_type_id = QEMU_ARM64_UBOOT_IMAGE_GUID,
44 .fw_name = u"Qemu-Arm-UBOOT",
45 .image_index = 1,
46 },
47#endif
48};
49
50struct efi_capsule_update_info update_info = {
Masahisa Kojimacccea182023-06-07 14:41:51 +090051 .num_images = ARRAY_SIZE(fw_images)
Sughosh Ganu741ef862022-04-15 11:29:34 +053052 .images = fw_images,
53};
54
Sughosh Ganu741ef862022-04-15 11:29:34 +053055#endif /* EFI_HAVE_CAPSULE_SUPPORT */
56
Tuomas Tynkkynenddcca732018-01-11 16:11:23 +020057static struct mm_region qemu_arm64_mem_map[] = {
58 {
59 /* Flash */
60 .virt = 0x00000000UL,
61 .phys = 0x00000000UL,
62 .size = 0x08000000UL,
63 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
64 PTE_BLOCK_INNER_SHARE
65 }, {
Tuomas Tynkkynen861b85c2018-09-04 18:16:52 +030066 /* Lowmem peripherals */
Tuomas Tynkkynenddcca732018-01-11 16:11:23 +020067 .virt = 0x08000000UL,
68 .phys = 0x08000000UL,
69 .size = 0x38000000,
70 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
71 PTE_BLOCK_NON_SHARE |
72 PTE_BLOCK_PXN | PTE_BLOCK_UXN
73 }, {
74 /* RAM */
75 .virt = 0x40000000UL,
76 .phys = 0x40000000UL,
Tuomas Tynkkynenf37770c2018-05-14 18:47:51 +030077 .size = 255UL * SZ_1G,
Tuomas Tynkkynenddcca732018-01-11 16:11:23 +020078 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
79 PTE_BLOCK_INNER_SHARE
80 }, {
Tuomas Tynkkynen861b85c2018-09-04 18:16:52 +030081 /* Highmem PCI-E ECAM memory area */
82 .virt = 0x4010000000ULL,
83 .phys = 0x4010000000ULL,
84 .size = 0x10000000,
85 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
86 PTE_BLOCK_NON_SHARE |
87 PTE_BLOCK_PXN | PTE_BLOCK_UXN
88 }, {
89 /* Highmem PCI-E MMIO memory area */
90 .virt = 0x8000000000ULL,
91 .phys = 0x8000000000ULL,
92 .size = 0x8000000000ULL,
93 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
94 PTE_BLOCK_NON_SHARE |
95 PTE_BLOCK_PXN | PTE_BLOCK_UXN
96 }, {
Tuomas Tynkkynenddcca732018-01-11 16:11:23 +020097 /* List terminator */
98 0,
99 }
100};
101
102struct mm_region *mem_map = qemu_arm64_mem_map;
103#endif
104
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +0300105int board_init(void)
106{
Sughosh Ganue1ee06d2020-12-30 19:27:00 +0530107 return 0;
108}
109
110int board_late_init(void)
111{
Bin Mengb9b59562018-10-15 02:21:19 -0700112 /*
113 * Make sure virtio bus is enumerated so that peripherals
114 * on the virtio bus can be discovered by their drivers
115 */
116 virtio_init();
117
Alper Nebi Yasak05e2fa72023-08-14 20:39:43 +0300118 /* start usb so that usb keyboard can be used as input device */
119 if (CONFIG_IS_ENABLED(USB_KEYBOARD))
120 usb_init();
121
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +0300122 return 0;
123}
124
125int dram_init(void)
126{
Siva Durga Prasad Paladugu12308b12018-07-16 15:56:11 +0530127 if (fdtdec_setup_mem_size_base() != 0)
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +0300128 return -EINVAL;
129
130 return 0;
131}
132
133int dram_init_banksize(void)
134{
135 fdtdec_setup_memory_banksize();
136
137 return 0;
138}
139
Ilias Apalodimase7fb7892021-10-26 09:12:33 +0300140void *board_fdt_blob_setup(int *err)
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +0300141{
Ilias Apalodimase7fb7892021-10-26 09:12:33 +0300142 *err = 0;
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +0300143 /* QEMU loads a generated DTB for us at the start of RAM. */
Tom Riniaa6e94d2022-11-16 13:10:37 -0500144 return (void *)CFG_SYS_SDRAM_BASE;
Tuomas Tynkkynen32f11822017-09-19 23:18:07 +0300145}
Sughosh Ganuf552fa42019-12-29 00:01:05 +0530146
Ard Biesheuvel3fa914a2020-07-07 12:07:09 +0200147void enable_caches(void)
148{
149 icache_enable();
150 dcache_enable();
151}
152
Ard Biesheuvel2e2c2a52020-07-07 12:07:11 +0200153#ifdef CONFIG_ARM64
154#define __W "w"
155#else
156#define __W
157#endif
158
159u8 flash_read8(void *addr)
160{
161 u8 ret;
162
163 asm("ldrb %" __W "0, %1" : "=r"(ret) : "m"(*(u8 *)addr));
164 return ret;
165}
166
167u16 flash_read16(void *addr)
168{
169 u16 ret;
170
171 asm("ldrh %" __W "0, %1" : "=r"(ret) : "m"(*(u16 *)addr));
172 return ret;
173}
174
175u32 flash_read32(void *addr)
176{
177 u32 ret;
178
179 asm("ldr %" __W "0, %1" : "=r"(ret) : "m"(*(u32 *)addr));
180 return ret;
181}
182
183void flash_write8(u8 value, void *addr)
184{
185 asm("strb %" __W "1, %0" : "=m"(*(u8 *)addr) : "r"(value));
186}
187
188void flash_write16(u16 value, void *addr)
189{
190 asm("strh %" __W "1, %0" : "=m"(*(u16 *)addr) : "r"(value));
191}
192
193void flash_write32(u32 value, void *addr)
194{
195 asm("str %" __W "1, %0" : "=m"(*(u32 *)addr) : "r"(value));
196}