blob: 4e7fe26c200445fed03926abe09d910721fe2315 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +01002/*
3 * (C) Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6 * Copy the startup prototype, previously defined in common.h
7 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +01008 */
9
10#ifndef __INIT_H_
11#define __INIT_H_ 1
12
13#ifndef __ASSEMBLY__ /* put C only stuff in this section */
14
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <linux/types.h>
16
Simon Glass3f369742021-12-29 11:57:43 -070017/*
18 * In case of the EFI app the UEFI firmware provides the low-level
19 * initialisation.
20 */
21#ifdef CONFIG_EFI
Simon Glassda25eff2019-12-28 10:44:56 -070022#define ll_boot_init() false
23#else
Simon Glass3ba929a2020-10-30 21:38:53 -060024#include <asm/global_data.h>
25
Simon Glass0b2f1912020-04-26 09:12:57 -060026#define ll_boot_init() (!(gd->flags & GD_FLG_SKIP_LL_INIT))
Simon Glassda25eff2019-12-28 10:44:56 -070027#endif
28
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +010029/*
30 * Function Prototypes
31 */
32
33/* common/board_f.c */
Patrick Delaunaya0a2b212018-03-13 13:57:00 +010034void board_init_f(ulong dummy);
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +010035
36/**
37 * arch_cpu_init() - basic cpu-dependent setup for an architecture
38 *
39 * This is called after early malloc is available. It should handle any
40 * CPU- or SoC- specific init needed to continue the init sequence. See
41 * board_f.c for where it is called. If this is not provided, a default
42 * version (which does nothing) will be used.
43 *
Mario Six86c45a42018-08-06 10:23:40 +020044 * Return: 0 on success, otherwise error
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +010045 */
46int arch_cpu_init(void);
47
48/**
49 * mach_cpu_init() - SoC/machine dependent CPU setup
50 *
51 * This is called after arch_cpu_init(). It should handle any
52 * SoC or machine specific init needed to continue the init sequence. See
53 * board_f.c for where it is called. If this is not provided, a default
54 * version (which does nothing) will be used.
55 *
Mario Six86c45a42018-08-06 10:23:40 +020056 * Return: 0 on success, otherwise error
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +010057 */
58int mach_cpu_init(void);
59
Patrick Delaunaya0a2b212018-03-13 13:57:00 +010060/**
Simon Glass564a4a02019-12-06 21:42:20 -070061 * arch_fsp_init() - perform post-relocation firmware support package init
62 *
63 * Where U-Boot relies on binary blobs to handle part of the system init, this
64 * function can be used to set up the blobs. This is used on some Intel
65 * platforms.
66 *
67 * Return: 0
68 */
69int arch_fsp_init_r(void);
70
Patrick Delaunaya0a2b212018-03-13 13:57:00 +010071int dram_init(void);
72
73/**
74 * dram_init_banksize() - Set up DRAM bank sizes
75 *
76 * This can be implemented by boards to set up the DRAM bank information in
77 * gd->bd->bi_dram(). It is called just before relocation, after dram_init()
78 * is called.
79 *
80 * If this is not provided, a default implementation will try to set up a
81 * single bank. It will do this if CONFIG_NR_DRAM_BANKS and
Tom Rinibb4dd962022-11-16 13:10:37 -050082 * CFG_SYS_SDRAM_BASE are set. The bank will have a start address of
83 * CFG_SYS_SDRAM_BASE and the size will be determined by a call to
Patrick Delaunaya0a2b212018-03-13 13:57:00 +010084 * get_effective_memsize().
85 *
Mario Six86c45a42018-08-06 10:23:40 +020086 * Return: 0 if OK, -ve on error
Patrick Delaunaya0a2b212018-03-13 13:57:00 +010087 */
88int dram_init_banksize(void);
89
Simon Glass8e16b1e2019-12-28 10:45:05 -070090long get_ram_size(long *base, long size);
91phys_size_t get_effective_memsize(void);
92
Simon Glass0ffd9db2019-12-28 10:45:06 -070093int testdram(void);
94
Patrick Delaunaya0a2b212018-03-13 13:57:00 +010095/**
Ovidiu Panaitbbce5f32022-09-13 21:31:28 +030096 * arch_setup_dest_addr() - Fix up initial reloc address
97 *
98 * This is called in generic board init sequence in common/board_f.c at the end
99 * of the setup_dest_addr() initcall. Each architecture could provide this
100 * function to make adjustments to the initial reloc address.
101 *
102 * If an implementation is not provided, it will just be a nop stub.
103 *
104 * Return: 0 if OK
105 */
106int arch_setup_dest_addr(void);
107
108/**
Mario Six86c45a42018-08-06 10:23:40 +0200109 * arch_reserve_stacks() - Reserve all necessary stacks
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100110 *
111 * This is used in generic board init sequence in common/board_f.c. Each
112 * architecture could provide this function to tailor the required stacks.
113 *
114 * On entry gd->start_addr_sp is pointing to the suggested top of the stack.
115 * The callee ensures gd->start_add_sp is 16-byte aligned, so architectures
116 * require only this can leave it untouched.
117 *
118 * On exit gd->start_addr_sp and gd->irq_sp should be set to the respective
119 * positions of the stack. The stack pointer(s) will be set to this later.
120 * gd->irq_sp is only required, if the architecture needs it.
121 *
Mario Six86c45a42018-08-06 10:23:40 +0200122 * Return: 0 if no error
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100123 */
124int arch_reserve_stacks(void);
125
Patrick Delaunay18c50642018-03-13 13:57:04 +0100126/**
Ovidiu Panait2a2941b2020-03-29 20:57:41 +0300127 * arch_reserve_mmu() - Reserve memory for MMU TLB table
128 *
129 * Architecture-specific routine for reserving memory for the MMU TLB table.
130 * This is used in generic board init sequence in common/board_f.c.
131 *
132 * If an implementation is not provided, it will just be a nop stub.
133 *
134 * Return: 0 if OK
135 */
136int arch_reserve_mmu(void);
137
138/**
Ovidiu Panait3d0b0402020-07-24 14:12:15 +0300139 * arch_setup_bdinfo() - Architecture dependent boardinfo setup
140 *
141 * Architecture-specific routine for populating various boardinfo fields of
142 * gd->bd. It is called during the generic board init sequence.
143 *
144 * If an implementation is not provided, it will just be a nop stub.
145 *
146 * Return: 0 if OK
147 */
148int arch_setup_bdinfo(void);
149
150/**
Ovidiu Panait0c5e9a02020-07-24 14:12:14 +0300151 * setup_bdinfo() - Generic boardinfo setup
152 *
153 * Routine for populating various generic boardinfo fields of
154 * gd->bd. It is called during the generic board init sequence.
155 *
156 * Return: 0 if OK
157 */
158int setup_bdinfo(void);
159
Dzmitry Sankouskia3463062022-02-22 21:49:52 +0300160#if defined(CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR) || \
161defined(CONFIG_SAVE_PREV_BL_FDT_ADDR)
162/**
163 * save_prev_bl_data - Save prev bl data in env vars.
164 *
165 * When u-boot is chain-loaded, save previous bootloader data,
166 * like initramfs address to environment variables.
167 *
168 * Return: 0 if ok; -ENODATA on error
169 */
170int save_prev_bl_data(void);
171#endif
172
Ovidiu Panait0c5e9a02020-07-24 14:12:14 +0300173/**
Ovidiu Panaitc14c0f92020-11-28 10:43:09 +0200174 * cpu_secondary_init_r() - CPU-specific secondary initialization
175 *
176 * After non-volatile devices, environment and cpu code are setup, have
177 * another round to deal with any initialization that might require
178 * full access to the environment or loading of some image (firmware)
179 * from a non-volatile device.
180 *
181 * It is called during the generic post-relocation init sequence.
182 *
183 * Return: 0 if OK
184 */
185int cpu_secondary_init_r(void);
186
187/**
Ovidiu Panaita45c6e12020-11-28 10:43:11 +0200188 * pci_ep_init() - Initialize pci endpoint devices
189 *
190 * It is called during the generic post-relocation init sequence.
191 *
192 * Return: 0 if OK
193 */
194int pci_ep_init(void);
195
196/**
Ovidiu Panaite353edb2020-11-28 10:43:12 +0200197 * pci_init() - Enumerate pci devices
198 *
199 * It is called during the generic post-relocation init sequence to enumerate
200 * pci buses. This is needed, for instance, in the case of DM PCI-based
201 * Ethernet devices, which will not be detected without having the enumeration
202 * performed earlier.
203 *
204 * Return: 0 if OK
205 */
206int pci_init(void);
207
208/**
Patrick Delaunay18c50642018-03-13 13:57:04 +0100209 * init_cache_f_r() - Turn on the cache in preparation for relocation
210 *
Mario Six86c45a42018-08-06 10:23:40 +0200211 * Return: 0 if OK, -ve on error
Patrick Delaunay18c50642018-03-13 13:57:04 +0100212 */
213int init_cache_f_r(void);
214
Mario Six97bbb602018-08-06 10:23:41 +0200215#if !CONFIG_IS_ENABLED(CPU)
216/**
217 * print_cpuinfo() - Display information about the CPU
218 *
219 * Return: 0 if OK, -ve on error
220 */
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100221int print_cpuinfo(void);
Mario Six97bbb602018-08-06 10:23:41 +0200222#endif
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100223int timer_init(void);
Mario Six86c45a42018-08-06 10:23:40 +0200224
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100225#if defined(CONFIG_DTB_RESELECT)
226int embedded_dtb_select(void);
227#endif
228
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100229/* common/init/board_init.c */
230extern ulong monitor_flash_len;
231
232/**
233 * ulong board_init_f_alloc_reserve - allocate reserved area
Mario Six86c45a42018-08-06 10:23:40 +0200234 * @top: top of the reserve area, growing down.
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100235 *
236 * This function is called by each architecture very early in the start-up
237 * code to allow the C runtime to reserve space on the stack for writable
238 * 'globals' such as GD and the malloc arena.
239 *
Mario Six86c45a42018-08-06 10:23:40 +0200240 * Return: bottom of reserved area
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100241 */
242ulong board_init_f_alloc_reserve(ulong top);
243
244/**
245 * board_init_f_init_reserve - initialize the reserved area(s)
Mario Six86c45a42018-08-06 10:23:40 +0200246 * @base: top from which reservation was done
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100247 *
248 * This function is called once the C runtime has allocated the reserved
249 * area on the stack. It must initialize the GD at the base of that area.
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100250 */
251void board_init_f_init_reserve(ulong base);
252
Simon Glass6980b6b2019-11-14 12:57:45 -0700253struct global_data;
254
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100255/**
256 * arch_setup_gd() - Set up the global_data pointer
Mario Six86c45a42018-08-06 10:23:40 +0200257 * @gd_ptr: Pointer to global data
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100258 *
259 * This pointer is special in some architectures and cannot easily be assigned
260 * to. For example on x86 it is implemented by adding a specific record to its
261 * Global Descriptor Table! So we we provide a function to carry out this task.
262 * For most architectures this can simply be:
263 *
264 * gd = gd_ptr;
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100265 */
Simon Glass6980b6b2019-11-14 12:57:45 -0700266void arch_setup_gd(struct global_data *gd_ptr);
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100267
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +0100268/* common/board_r.c */
Simon Glass6980b6b2019-11-14 12:57:45 -0700269void board_init_r(struct global_data *id, ulong dest_addr)
270 __attribute__ ((noreturn));
Patrick Delaunayb76e7cf2018-03-13 13:57:02 +0100271
272int cpu_init_r(void);
Patrick Delaunayb76e7cf2018-03-13 13:57:02 +0100273int mac_read_from_eeprom(void);
274int set_cpu_clk_info(void);
275int update_flash_size(int flash_size);
276int arch_early_init_r(void);
Patrick Delaunayb76e7cf2018-03-13 13:57:02 +0100277int misc_init_r(void);
Patrick Delaunayb76e7cf2018-03-13 13:57:02 +0100278
Patrick Delaunayb1d23442018-03-13 13:57:03 +0100279/* common/board_info.c */
280int checkboard(void);
281int show_board_info(void);
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +0100282
Simon Glass6980b6b2019-11-14 12:57:45 -0700283/**
Heinrich Schuchardtaaafaea2023-08-14 08:44:26 +0200284 * board_get_usable_ram_top() - get uppermost address for U-Boot relocation
Simon Glass6980b6b2019-11-14 12:57:45 -0700285 *
Heinrich Schuchardtaaafaea2023-08-14 08:44:26 +0200286 * Some systems have reserved memory areas in high memory. By implementing this
287 * function boards can indicate the highest address value to be used when
288 * relocating U-Boot. The returned address is exclusive (i.e. 1 byte above the
289 * last usable address).
290 *
291 * Due to overflow on systems with 32bit phys_addr_t a value 0 is used instead
292 * of 4GiB.
Simon Glass6980b6b2019-11-14 12:57:45 -0700293 *
Heinrich Schuchardtaaafaea2023-08-14 08:44:26 +0200294 * @total_size: monitor length in bytes (size of U-Boot code)
295 * Return: uppermost address for U-Boot relocation
Simon Glass6980b6b2019-11-14 12:57:45 -0700296 */
Heinrich Schuchardt51a9aac2023-08-12 20:16:58 +0200297phys_addr_t board_get_usable_ram_top(phys_size_t total_size);
Simon Glass6980b6b2019-11-14 12:57:45 -0700298
Simon Glassa7b51302019-11-14 12:57:46 -0700299int board_early_init_f(void);
300
301/* manipulate the U-Boot fdt before its relocation */
302int board_fix_fdt(void *rw_fdt_blob);
303int board_late_init(void);
304int board_postclk_init(void); /* after clocks/timebase, before env/serial */
305int board_early_init_r(void);
306
Ovidiu Panait2c823912020-11-28 10:43:18 +0200307/**
308 * arch_initr_trap() - Init traps
309 *
310 * Arch specific routine for initializing traps. It is called during the
311 * generic board init sequence, after relocation.
312 *
313 * Return: 0 if OK
314 */
315int arch_initr_trap(void);
Simon Glass537ecc92019-11-14 12:57:48 -0700316
Simon Glassa5037e22019-12-28 10:44:39 -0700317/**
Ovidiu Panait7dbb0212022-01-01 19:13:29 +0200318 * init_addr_map()
319 *
320 * Initialize non-identity virtual-physical memory mappings for 32bit CPUs.
321 * It is called during the generic board init sequence, after relocation.
322 *
323 * Return: 0 if OK
324 */
325int init_addr_map(void);
326
327/**
Simon Glassa5037e22019-12-28 10:44:39 -0700328 * main_loop() - Enter the main loop of U-Boot
329 *
330 * This normally runs the command line.
331 */
332void main_loop(void);
333
Simon Glass284f71b2019-12-28 10:44:45 -0700334#if defined(CONFIG_ARM)
335void relocate_code(ulong addr_moni);
336#else
337void relocate_code(ulong start_addr_sp, struct global_data *new_gd,
338 ulong relocaddr)
339 __attribute__ ((noreturn));
340#endif
341
Simon Glass7e246632020-05-10 14:16:55 -0600342/* Print a numeric value (for use in arch_print_bdinfo()) */
Bin Meng1ae7a0c2021-01-31 20:36:05 +0800343void bdinfo_print_num_l(const char *name, ulong value);
344void bdinfo_print_num_ll(const char *name, unsigned long long value);
Simon Glass7e246632020-05-10 14:16:55 -0600345
Simon Glass3a127252023-03-10 12:47:14 -0800346/* Print a string value (for use in arch_print_bdinfo()) */
347void bdinfo_print_str(const char *name, const char *str);
348
Simon Glass7e246632020-05-10 14:16:55 -0600349/* Print a clock speed in MHz */
350void bdinfo_print_mhz(const char *name, unsigned long hz);
351
Ovidiu Panait608c11e2022-08-29 20:02:04 +0300352/**
353 * bdinfo_print_size - print size variables in bdinfo format
354 * @name: string to print before the size
355 * @size: size to print
356 *
357 * Helper function for displaying size variables as properly formatted bdinfo
358 * entries. The size is printed as "xxx Bytes", "xxx KiB", "xxx MiB",
359 * "xxx GiB", etc. as needed;
360 *
361 * For use in arch_print_bdinfo().
362 */
363void bdinfo_print_size(const char *name, uint64_t size);
364
Simon Glassa83ab162020-05-10 14:16:56 -0600365/* Show arch-specific information for the 'bd' command */
366void arch_print_bdinfo(void);
367
Andy Shevchenkoe3b3ad92021-11-08 21:03:38 +0300368int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
369
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +0100370#endif /* __ASSEMBLY__ */
371/* Put only stuff here that the assembler can digest */
372
373#endif /* __INIT_H_ */