common: Drop init.h from common header
[pandora-u-boot.git] / arch / x86 / lib / tpl.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2018 Google, Inc
4  */
5
6 #include <common.h>
7 #include <debug_uart.h>
8 #include <dm.h>
9 #include <hang.h>
10 #include <image.h>
11 #include <init.h>
12 #include <spl.h>
13 #include <asm/cpu.h>
14 #include <asm/mtrr.h>
15 #include <asm/processor.h>
16 #include <asm-generic/sections.h>
17
18 DECLARE_GLOBAL_DATA_PTR;
19
20 __weak int arch_cpu_init_dm(void)
21 {
22         return 0;
23 }
24
25 static int x86_tpl_init(void)
26 {
27         int ret;
28
29         debug("%s starting\n", __func__);
30         ret = x86_cpu_init_tpl();
31         if (ret) {
32                 debug("%s: x86_cpu_init_tpl() failed\n", __func__);
33                 return ret;
34         }
35         ret = spl_init();
36         if (ret) {
37                 debug("%s: spl_init() failed\n", __func__);
38                 return ret;
39         }
40         ret = arch_cpu_init();
41         if (ret) {
42                 debug("%s: arch_cpu_init() failed\n", __func__);
43                 return ret;
44         }
45         ret = arch_cpu_init_dm();
46         if (ret) {
47                 debug("%s: arch_cpu_init_dm() failed\n", __func__);
48                 return ret;
49         }
50         preloader_console_init();
51
52         return 0;
53 }
54
55 void board_init_f(ulong flags)
56 {
57         int ret;
58
59         ret = x86_tpl_init();
60         if (ret) {
61                 debug("Error %d\n", ret);
62                 panic("x86_tpl_init fail");
63         }
64
65         /* Uninit CAR and jump to board_init_f_r() */
66         board_init_r(gd, 0);
67 }
68
69 void board_init_f_r(void)
70 {
71         /* Not used since we never call board_init_f_r_trampoline() */
72         while (1);
73 }
74
75 u32 spl_boot_device(void)
76 {
77         return IS_ENABLED(CONFIG_CHROMEOS) ? BOOT_DEVICE_CROS_VBOOT :
78                 BOOT_DEVICE_SPI_MMAP;
79 }
80
81 int spl_start_uboot(void)
82 {
83         return 0;
84 }
85
86 void spl_board_announce_boot_device(void)
87 {
88         printf("SPI flash");
89 }
90
91 static int spl_board_load_image(struct spl_image_info *spl_image,
92                                 struct spl_boot_device *bootdev)
93 {
94         spl_image->size = CONFIG_SYS_MONITOR_LEN;  /* We don't know SPL size */
95         spl_image->entry_point = CONFIG_SPL_TEXT_BASE;
96         spl_image->load_addr = CONFIG_SPL_TEXT_BASE;
97         spl_image->os = IH_OS_U_BOOT;
98         spl_image->name = "U-Boot";
99
100         debug("Loading to %lx\n", spl_image->load_addr);
101
102         return 0;
103 }
104 SPL_LOAD_IMAGE_METHOD("SPI", 5, BOOT_DEVICE_SPI_MMAP, spl_board_load_image);
105
106 int spl_spi_load_image(void)
107 {
108         return -EPERM;
109 }
110
111 void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
112 {
113         debug("Jumping to U-Boot SPL at %lx\n", (ulong)spl_image->entry_point);
114         jump_to_spl(spl_image->entry_point);
115         hang();
116 }
117
118 void spl_board_init(void)
119 {
120         preloader_console_init();
121 }
122
123 #if !CONFIG_IS_ENABLED(PCI)
124 /*
125  * This is a fake PCI bus for TPL when it doesn't have proper PCI. It is enough
126  * to bind the devices on the PCI bus, some of which have early-regs properties
127  * providing fixed BARs. Individual drivers program these BARs themselves so
128  * that they can access the devices. The BARs are allocated statically in the
129  * device tree.
130  *
131  * Once SPL is running it enables PCI properly, but does not auto-assign BARs
132  * for devices, so the TPL BARs continue to be used. Once U-Boot starts it does
133  * the auto allocation (after relocation).
134  */
135 static const struct udevice_id tpl_fake_pci_ids[] = {
136         { .compatible = "pci-x86" },
137         { }
138 };
139
140 U_BOOT_DRIVER(pci_x86) = {
141         .name   = "pci_x86",
142         .id     = UCLASS_SIMPLE_BUS,
143         .of_match = tpl_fake_pci_ids,
144 };
145 #endif