blob: 02bb4ce13e74a3b2e0a7a83ba43cf53837c0f269 [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/**
61 * arch_fsp_init() - perform 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.
Mario Six86c45a42018-08-06 10:23:40 +020066 *
67 * Return: 0
Patrick Delaunaya0a2b212018-03-13 13:57:00 +010068 */
69int arch_fsp_init(void);
70
Simon Glass564a4a02019-12-06 21:42:20 -070071/**
72 * arch_fsp_init() - perform post-relocation firmware support package init
73 *
74 * Where U-Boot relies on binary blobs to handle part of the system init, this
75 * function can be used to set up the blobs. This is used on some Intel
76 * platforms.
77 *
78 * Return: 0
79 */
80int arch_fsp_init_r(void);
81
Patrick Delaunaya0a2b212018-03-13 13:57:00 +010082int dram_init(void);
83
84/**
85 * dram_init_banksize() - Set up DRAM bank sizes
86 *
87 * This can be implemented by boards to set up the DRAM bank information in
88 * gd->bd->bi_dram(). It is called just before relocation, after dram_init()
89 * is called.
90 *
91 * If this is not provided, a default implementation will try to set up a
92 * single bank. It will do this if CONFIG_NR_DRAM_BANKS and
93 * CONFIG_SYS_SDRAM_BASE are set. The bank will have a start address of
94 * CONFIG_SYS_SDRAM_BASE and the size will be determined by a call to
95 * get_effective_memsize().
96 *
Mario Six86c45a42018-08-06 10:23:40 +020097 * Return: 0 if OK, -ve on error
Patrick Delaunaya0a2b212018-03-13 13:57:00 +010098 */
99int dram_init_banksize(void);
100
Simon Glass8e16b1e2019-12-28 10:45:05 -0700101long get_ram_size(long *base, long size);
102phys_size_t get_effective_memsize(void);
103
Simon Glass0ffd9db2019-12-28 10:45:06 -0700104int testdram(void);
105
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100106/**
Mario Six86c45a42018-08-06 10:23:40 +0200107 * arch_reserve_stacks() - Reserve all necessary stacks
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100108 *
109 * This is used in generic board init sequence in common/board_f.c. Each
110 * architecture could provide this function to tailor the required stacks.
111 *
112 * On entry gd->start_addr_sp is pointing to the suggested top of the stack.
113 * The callee ensures gd->start_add_sp is 16-byte aligned, so architectures
114 * require only this can leave it untouched.
115 *
116 * On exit gd->start_addr_sp and gd->irq_sp should be set to the respective
117 * positions of the stack. The stack pointer(s) will be set to this later.
118 * gd->irq_sp is only required, if the architecture needs it.
119 *
Mario Six86c45a42018-08-06 10:23:40 +0200120 * Return: 0 if no error
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100121 */
122int arch_reserve_stacks(void);
123
Patrick Delaunay18c50642018-03-13 13:57:04 +0100124/**
Ovidiu Panait2a2941b2020-03-29 20:57:41 +0300125 * arch_reserve_mmu() - Reserve memory for MMU TLB table
126 *
127 * Architecture-specific routine for reserving memory for the MMU TLB table.
128 * This is used in generic board init sequence in common/board_f.c.
129 *
130 * If an implementation is not provided, it will just be a nop stub.
131 *
132 * Return: 0 if OK
133 */
134int arch_reserve_mmu(void);
135
136/**
Ovidiu Panait3d0b0402020-07-24 14:12:15 +0300137 * arch_setup_bdinfo() - Architecture dependent boardinfo setup
138 *
139 * Architecture-specific routine for populating various boardinfo fields of
140 * gd->bd. It is called during the generic board init sequence.
141 *
142 * If an implementation is not provided, it will just be a nop stub.
143 *
144 * Return: 0 if OK
145 */
146int arch_setup_bdinfo(void);
147
148/**
Ovidiu Panait0c5e9a02020-07-24 14:12:14 +0300149 * setup_bdinfo() - Generic boardinfo setup
150 *
151 * Routine for populating various generic boardinfo fields of
152 * gd->bd. It is called during the generic board init sequence.
153 *
154 * Return: 0 if OK
155 */
156int setup_bdinfo(void);
157
Dzmitry Sankouskia3463062022-02-22 21:49:52 +0300158#if defined(CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR) || \
159defined(CONFIG_SAVE_PREV_BL_FDT_ADDR)
160/**
161 * save_prev_bl_data - Save prev bl data in env vars.
162 *
163 * When u-boot is chain-loaded, save previous bootloader data,
164 * like initramfs address to environment variables.
165 *
166 * Return: 0 if ok; -ENODATA on error
167 */
168int save_prev_bl_data(void);
169#endif
170
Ovidiu Panait0c5e9a02020-07-24 14:12:14 +0300171/**
Ovidiu Panaitc14c0f92020-11-28 10:43:09 +0200172 * cpu_secondary_init_r() - CPU-specific secondary initialization
173 *
174 * After non-volatile devices, environment and cpu code are setup, have
175 * another round to deal with any initialization that might require
176 * full access to the environment or loading of some image (firmware)
177 * from a non-volatile device.
178 *
179 * It is called during the generic post-relocation init sequence.
180 *
181 * Return: 0 if OK
182 */
183int cpu_secondary_init_r(void);
184
185/**
Ovidiu Panaita45c6e12020-11-28 10:43:11 +0200186 * pci_ep_init() - Initialize pci endpoint devices
187 *
188 * It is called during the generic post-relocation init sequence.
189 *
190 * Return: 0 if OK
191 */
192int pci_ep_init(void);
193
194/**
Ovidiu Panaite353edb2020-11-28 10:43:12 +0200195 * pci_init() - Enumerate pci devices
196 *
197 * It is called during the generic post-relocation init sequence to enumerate
198 * pci buses. This is needed, for instance, in the case of DM PCI-based
199 * Ethernet devices, which will not be detected without having the enumeration
200 * performed earlier.
201 *
202 * Return: 0 if OK
203 */
204int pci_init(void);
205
206/**
Patrick Delaunay18c50642018-03-13 13:57:04 +0100207 * init_cache_f_r() - Turn on the cache in preparation for relocation
208 *
Mario Six86c45a42018-08-06 10:23:40 +0200209 * Return: 0 if OK, -ve on error
Patrick Delaunay18c50642018-03-13 13:57:04 +0100210 */
211int init_cache_f_r(void);
212
Mario Six97bbb602018-08-06 10:23:41 +0200213#if !CONFIG_IS_ENABLED(CPU)
214/**
215 * print_cpuinfo() - Display information about the CPU
216 *
217 * Return: 0 if OK, -ve on error
218 */
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100219int print_cpuinfo(void);
Mario Six97bbb602018-08-06 10:23:41 +0200220#endif
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100221int timer_init(void);
Mario Six86c45a42018-08-06 10:23:40 +0200222
Patrick Delaunaya0a2b212018-03-13 13:57:00 +0100223#if defined(CONFIG_DTB_RESELECT)
224int embedded_dtb_select(void);
225#endif
226
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100227/* common/init/board_init.c */
228extern ulong monitor_flash_len;
229
230/**
231 * ulong board_init_f_alloc_reserve - allocate reserved area
Mario Six86c45a42018-08-06 10:23:40 +0200232 * @top: top of the reserve area, growing down.
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100233 *
234 * This function is called by each architecture very early in the start-up
235 * code to allow the C runtime to reserve space on the stack for writable
236 * 'globals' such as GD and the malloc arena.
237 *
Mario Six86c45a42018-08-06 10:23:40 +0200238 * Return: bottom of reserved area
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100239 */
240ulong board_init_f_alloc_reserve(ulong top);
241
242/**
243 * board_init_f_init_reserve - initialize the reserved area(s)
Mario Six86c45a42018-08-06 10:23:40 +0200244 * @base: top from which reservation was done
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100245 *
246 * This function is called once the C runtime has allocated the reserved
247 * area on the stack. It must initialize the GD at the base of that area.
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100248 */
249void board_init_f_init_reserve(ulong base);
250
Simon Glass6980b6b2019-11-14 12:57:45 -0700251struct global_data;
252
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100253/**
254 * arch_setup_gd() - Set up the global_data pointer
Mario Six86c45a42018-08-06 10:23:40 +0200255 * @gd_ptr: Pointer to global data
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100256 *
257 * This pointer is special in some architectures and cannot easily be assigned
258 * to. For example on x86 it is implemented by adding a specific record to its
259 * Global Descriptor Table! So we we provide a function to carry out this task.
260 * For most architectures this can simply be:
261 *
262 * gd = gd_ptr;
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100263 */
Simon Glass6980b6b2019-11-14 12:57:45 -0700264void arch_setup_gd(struct global_data *gd_ptr);
Patrick Delaunay98c8bbc2018-03-13 13:57:01 +0100265
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +0100266/* common/board_r.c */
Simon Glass6980b6b2019-11-14 12:57:45 -0700267void board_init_r(struct global_data *id, ulong dest_addr)
268 __attribute__ ((noreturn));
Patrick Delaunayb76e7cf2018-03-13 13:57:02 +0100269
270int cpu_init_r(void);
271int last_stage_init(void);
272int mac_read_from_eeprom(void);
273int set_cpu_clk_info(void);
274int update_flash_size(int flash_size);
275int arch_early_init_r(void);
Patrick Delaunayb76e7cf2018-03-13 13:57:02 +0100276int misc_init_r(void);
277#if defined(CONFIG_VID)
278int init_func_vid(void);
279#endif
280
Patrick Delaunayb1d23442018-03-13 13:57:03 +0100281/* common/board_info.c */
282int checkboard(void);
283int show_board_info(void);
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +0100284
Simon Glass6980b6b2019-11-14 12:57:45 -0700285/**
286 * Get the uppermost pointer that is valid to access
287 *
288 * Some systems may not map all of their address space. This function allows
289 * boards to indicate what their highest support pointer value is for DRAM
290 * access.
291 *
292 * @param total_size Size of U-Boot (unused?)
293 */
294ulong board_get_usable_ram_top(ulong total_size);
295
Simon Glassa7b51302019-11-14 12:57:46 -0700296int board_early_init_f(void);
297
298/* manipulate the U-Boot fdt before its relocation */
299int board_fix_fdt(void *rw_fdt_blob);
300int board_late_init(void);
301int board_postclk_init(void); /* after clocks/timebase, before env/serial */
302int board_early_init_r(void);
303
Ovidiu Panait2c823912020-11-28 10:43:18 +0200304/**
305 * arch_initr_trap() - Init traps
306 *
307 * Arch specific routine for initializing traps. It is called during the
308 * generic board init sequence, after relocation.
309 *
310 * Return: 0 if OK
311 */
312int arch_initr_trap(void);
Simon Glass537ecc92019-11-14 12:57:48 -0700313
Simon Glassa5037e22019-12-28 10:44:39 -0700314/**
Ovidiu Panait7dbb0212022-01-01 19:13:29 +0200315 * init_addr_map()
316 *
317 * Initialize non-identity virtual-physical memory mappings for 32bit CPUs.
318 * It is called during the generic board init sequence, after relocation.
319 *
320 * Return: 0 if OK
321 */
322int init_addr_map(void);
323
324/**
Simon Glassa5037e22019-12-28 10:44:39 -0700325 * main_loop() - Enter the main loop of U-Boot
326 *
327 * This normally runs the command line.
328 */
329void main_loop(void);
330
Simon Glass284f71b2019-12-28 10:44:45 -0700331#if defined(CONFIG_ARM)
332void relocate_code(ulong addr_moni);
333#else
334void relocate_code(ulong start_addr_sp, struct global_data *new_gd,
335 ulong relocaddr)
336 __attribute__ ((noreturn));
337#endif
338
Simon Glass7e246632020-05-10 14:16:55 -0600339/* Print a numeric value (for use in arch_print_bdinfo()) */
Bin Meng1ae7a0c2021-01-31 20:36:05 +0800340void bdinfo_print_num_l(const char *name, ulong value);
341void bdinfo_print_num_ll(const char *name, unsigned long long value);
Simon Glass7e246632020-05-10 14:16:55 -0600342
343/* Print a clock speed in MHz */
344void bdinfo_print_mhz(const char *name, unsigned long hz);
345
Ovidiu Panait608c11e2022-08-29 20:02:04 +0300346/**
347 * bdinfo_print_size - print size variables in bdinfo format
348 * @name: string to print before the size
349 * @size: size to print
350 *
351 * Helper function for displaying size variables as properly formatted bdinfo
352 * entries. The size is printed as "xxx Bytes", "xxx KiB", "xxx MiB",
353 * "xxx GiB", etc. as needed;
354 *
355 * For use in arch_print_bdinfo().
356 */
357void bdinfo_print_size(const char *name, uint64_t size);
358
Simon Glassa83ab162020-05-10 14:16:56 -0600359/* Show arch-specific information for the 'bd' command */
360void arch_print_bdinfo(void);
361
Andy Shevchenkoe3b3ad92021-11-08 21:03:38 +0300362int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
363
Patrick Delaunayc6bfcd52018-03-09 18:28:12 +0100364#endif /* __ASSEMBLY__ */
365/* Put only stuff here that the assembler can digest */
366
367#endif /* __INIT_H_ */