blob: 69e8ef46f1f5fba3e003abb833346e29a53daf87 [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>
Bin Menga94f6a02018-10-15 02:21:19 -07007#include <dm.h>
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +03008#include <fdtdec.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Bin Menga94f6a02018-10-15 02:21:19 -070011#include <virtio_types.h>
12#include <virtio.h>
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030013
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020014#ifdef CONFIG_ARM64
15#include <asm/armv8/mmu.h>
16
17static struct mm_region qemu_arm64_mem_map[] = {
18 {
19 /* Flash */
20 .virt = 0x00000000UL,
21 .phys = 0x00000000UL,
22 .size = 0x08000000UL,
23 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
24 PTE_BLOCK_INNER_SHARE
25 }, {
Tuomas Tynkkynene09ca642018-09-04 18:16:52 +030026 /* Lowmem peripherals */
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020027 .virt = 0x08000000UL,
28 .phys = 0x08000000UL,
29 .size = 0x38000000,
30 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
31 PTE_BLOCK_NON_SHARE |
32 PTE_BLOCK_PXN | PTE_BLOCK_UXN
33 }, {
34 /* RAM */
35 .virt = 0x40000000UL,
36 .phys = 0x40000000UL,
Tuomas Tynkkynenac927392018-05-14 18:47:51 +030037 .size = 255UL * SZ_1G,
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020038 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
39 PTE_BLOCK_INNER_SHARE
40 }, {
Tuomas Tynkkynene09ca642018-09-04 18:16:52 +030041 /* Highmem PCI-E ECAM memory area */
42 .virt = 0x4010000000ULL,
43 .phys = 0x4010000000ULL,
44 .size = 0x10000000,
45 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
46 PTE_BLOCK_NON_SHARE |
47 PTE_BLOCK_PXN | PTE_BLOCK_UXN
48 }, {
49 /* Highmem PCI-E MMIO memory area */
50 .virt = 0x8000000000ULL,
51 .phys = 0x8000000000ULL,
52 .size = 0x8000000000ULL,
53 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
54 PTE_BLOCK_NON_SHARE |
55 PTE_BLOCK_PXN | PTE_BLOCK_UXN
56 }, {
Tuomas Tynkkynendfdd46d2018-01-11 16:11:23 +020057 /* List terminator */
58 0,
59 }
60};
61
62struct mm_region *mem_map = qemu_arm64_mem_map;
63#endif
64
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030065int board_init(void)
66{
Bin Menga94f6a02018-10-15 02:21:19 -070067 /*
68 * Make sure virtio bus is enumerated so that peripherals
69 * on the virtio bus can be discovered by their drivers
70 */
71 virtio_init();
72
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030073 return 0;
74}
75
76int dram_init(void)
77{
Siva Durga Prasad Paladugub3d55ea2018-07-16 15:56:11 +053078 if (fdtdec_setup_mem_size_base() != 0)
Tuomas Tynkkynen28cac522017-09-19 23:18:07 +030079 return -EINVAL;
80
81 return 0;
82}
83
84int dram_init_banksize(void)
85{
86 fdtdec_setup_memory_banksize();
87
88 return 0;
89}
90
91void *board_fdt_blob_setup(void)
92{
93 /* QEMU loads a generated DTB for us at the start of RAM. */
94 return (void *)CONFIG_SYS_SDRAM_BASE;
95}
Sughosh Ganu7064a5d2019-12-29 00:01:05 +053096
97#if defined(CONFIG_EFI_RNG_PROTOCOL)
98#include <efi_loader.h>
99#include <efi_rng.h>
100
101#include <dm/device-internal.h>
102
103efi_status_t platform_get_rng_device(struct udevice **dev)
104{
105 int ret;
106 efi_status_t status = EFI_DEVICE_ERROR;
107 struct udevice *bus, *devp;
108
109 for (uclass_first_device(UCLASS_VIRTIO, &bus); bus;
110 uclass_next_device(&bus)) {
111 for (device_find_first_child(bus, &devp); devp;
112 device_find_next_child(&devp)) {
113 if (device_get_uclass_id(devp) == UCLASS_RNG) {
114 *dev = devp;
115 status = EFI_SUCCESS;
116 break;
117 }
118 }
119 }
120
121 if (status != EFI_SUCCESS) {
122 debug("No rng device found\n");
123 return EFI_DEVICE_ERROR;
124 }
125
126 if (*dev) {
127 ret = device_probe(*dev);
128 if (ret)
129 return EFI_DEVICE_ERROR;
130 } else {
131 debug("Couldn't get child device\n");
132 return EFI_DEVICE_ERROR;
133 }
134
135 return EFI_SUCCESS;
136}
137#endif /* CONFIG_EFI_RNG_PROTOCOL */