Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Patrick Delaunay | dafa84d | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 2 | /* |
| 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 Delaunay | dafa84d | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef __INIT_H_ |
| 11 | #define __INIT_H_ 1 |
| 12 | |
| 13 | #ifndef __ASSEMBLY__ /* put C only stuff in this section */ |
| 14 | |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <linux/types.h> |
| 16 | |
Simon Glass | 9079486 | 2021-12-29 11:57:43 -0700 | [diff] [blame] | 17 | /* |
| 18 | * In case of the EFI app the UEFI firmware provides the low-level |
| 19 | * initialisation. |
| 20 | */ |
| 21 | #ifdef CONFIG_EFI |
Simon Glass | 35a3f87 | 2019-12-28 10:44:56 -0700 | [diff] [blame] | 22 | #define ll_boot_init() false |
| 23 | #else |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 24 | #include <asm/global_data.h> |
| 25 | |
Simon Glass | ba974a0 | 2020-04-26 09:12:57 -0600 | [diff] [blame] | 26 | #define ll_boot_init() (!(gd->flags & GD_FLG_SKIP_LL_INIT)) |
Simon Glass | 35a3f87 | 2019-12-28 10:44:56 -0700 | [diff] [blame] | 27 | #endif |
| 28 | |
Patrick Delaunay | dafa84d | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 29 | /* |
| 30 | * Function Prototypes |
| 31 | */ |
| 32 | |
| 33 | /* common/board_f.c */ |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 34 | void board_init_f(ulong dummy); |
Patrick Delaunay | dafa84d | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 35 | |
| 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 Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 44 | * Return: 0 on success, otherwise error |
Patrick Delaunay | dafa84d | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 45 | */ |
| 46 | int 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 Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 56 | * Return: 0 on success, otherwise error |
Patrick Delaunay | dafa84d | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 57 | */ |
| 58 | int mach_cpu_init(void); |
| 59 | |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 60 | /** |
| 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 Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 66 | * |
| 67 | * Return: 0 |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 68 | */ |
| 69 | int arch_fsp_init(void); |
| 70 | |
Simon Glass | fe08d39 | 2019-12-06 21:42:20 -0700 | [diff] [blame] | 71 | /** |
| 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 | */ |
| 80 | int arch_fsp_init_r(void); |
| 81 | |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 82 | int 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 Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 97 | * Return: 0 if OK, -ve on error |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 98 | */ |
| 99 | int dram_init_banksize(void); |
| 100 | |
Simon Glass | 9b4a205 | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 101 | long get_ram_size(long *base, long size); |
| 102 | phys_size_t get_effective_memsize(void); |
| 103 | |
Simon Glass | 49acd56 | 2019-12-28 10:45:06 -0700 | [diff] [blame] | 104 | int testdram(void); |
| 105 | |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 106 | /** |
Mario Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 107 | * arch_reserve_stacks() - Reserve all necessary stacks |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 108 | * |
| 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 Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 120 | * Return: 0 if no error |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 121 | */ |
| 122 | int arch_reserve_stacks(void); |
| 123 | |
Patrick Delaunay | b8aa55c | 2018-03-13 13:57:04 +0100 | [diff] [blame] | 124 | /** |
Ovidiu Panait | 79926e4 | 2020-03-29 20:57:41 +0300 | [diff] [blame] | 125 | * 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 | */ |
| 134 | int arch_reserve_mmu(void); |
| 135 | |
| 136 | /** |
Ovidiu Panait | 81e7cb1 | 2020-07-24 14:12:15 +0300 | [diff] [blame] | 137 | * 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 | */ |
| 146 | int arch_setup_bdinfo(void); |
| 147 | |
| 148 | /** |
Ovidiu Panait | ba74310 | 2020-07-24 14:12:14 +0300 | [diff] [blame] | 149 | * 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 | */ |
| 156 | int setup_bdinfo(void); |
| 157 | |
| 158 | /** |
Ovidiu Panait | fb504b2 | 2020-11-28 10:43:09 +0200 | [diff] [blame] | 159 | * cpu_secondary_init_r() - CPU-specific secondary initialization |
| 160 | * |
| 161 | * After non-volatile devices, environment and cpu code are setup, have |
| 162 | * another round to deal with any initialization that might require |
| 163 | * full access to the environment or loading of some image (firmware) |
| 164 | * from a non-volatile device. |
| 165 | * |
| 166 | * It is called during the generic post-relocation init sequence. |
| 167 | * |
| 168 | * Return: 0 if OK |
| 169 | */ |
| 170 | int cpu_secondary_init_r(void); |
| 171 | |
| 172 | /** |
Ovidiu Panait | c343e8c | 2020-11-28 10:43:11 +0200 | [diff] [blame] | 173 | * pci_ep_init() - Initialize pci endpoint devices |
| 174 | * |
| 175 | * It is called during the generic post-relocation init sequence. |
| 176 | * |
| 177 | * Return: 0 if OK |
| 178 | */ |
| 179 | int pci_ep_init(void); |
| 180 | |
| 181 | /** |
Ovidiu Panait | b9f6d0f | 2020-11-28 10:43:12 +0200 | [diff] [blame] | 182 | * pci_init() - Enumerate pci devices |
| 183 | * |
| 184 | * It is called during the generic post-relocation init sequence to enumerate |
| 185 | * pci buses. This is needed, for instance, in the case of DM PCI-based |
| 186 | * Ethernet devices, which will not be detected without having the enumeration |
| 187 | * performed earlier. |
| 188 | * |
| 189 | * Return: 0 if OK |
| 190 | */ |
| 191 | int pci_init(void); |
| 192 | |
| 193 | /** |
Patrick Delaunay | b8aa55c | 2018-03-13 13:57:04 +0100 | [diff] [blame] | 194 | * init_cache_f_r() - Turn on the cache in preparation for relocation |
| 195 | * |
Mario Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 196 | * Return: 0 if OK, -ve on error |
Patrick Delaunay | b8aa55c | 2018-03-13 13:57:04 +0100 | [diff] [blame] | 197 | */ |
| 198 | int init_cache_f_r(void); |
| 199 | |
Mario Six | 5d6c61a | 2018-08-06 10:23:41 +0200 | [diff] [blame] | 200 | #if !CONFIG_IS_ENABLED(CPU) |
| 201 | /** |
| 202 | * print_cpuinfo() - Display information about the CPU |
| 203 | * |
| 204 | * Return: 0 if OK, -ve on error |
| 205 | */ |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 206 | int print_cpuinfo(void); |
Mario Six | 5d6c61a | 2018-08-06 10:23:41 +0200 | [diff] [blame] | 207 | #endif |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 208 | int timer_init(void); |
Mario Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 209 | |
Patrick Delaunay | d6f8771 | 2018-03-13 13:57:00 +0100 | [diff] [blame] | 210 | #if defined(CONFIG_DTB_RESELECT) |
| 211 | int embedded_dtb_select(void); |
| 212 | #endif |
| 213 | |
Patrick Delaunay | 11f86cb | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 214 | /* common/init/board_init.c */ |
| 215 | extern ulong monitor_flash_len; |
| 216 | |
| 217 | /** |
| 218 | * ulong board_init_f_alloc_reserve - allocate reserved area |
Mario Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 219 | * @top: top of the reserve area, growing down. |
Patrick Delaunay | 11f86cb | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 220 | * |
| 221 | * This function is called by each architecture very early in the start-up |
| 222 | * code to allow the C runtime to reserve space on the stack for writable |
| 223 | * 'globals' such as GD and the malloc arena. |
| 224 | * |
Mario Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 225 | * Return: bottom of reserved area |
Patrick Delaunay | 11f86cb | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 226 | */ |
| 227 | ulong board_init_f_alloc_reserve(ulong top); |
| 228 | |
| 229 | /** |
| 230 | * board_init_f_init_reserve - initialize the reserved area(s) |
Mario Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 231 | * @base: top from which reservation was done |
Patrick Delaunay | 11f86cb | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 232 | * |
| 233 | * This function is called once the C runtime has allocated the reserved |
| 234 | * area on the stack. It must initialize the GD at the base of that area. |
Patrick Delaunay | 11f86cb | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 235 | */ |
| 236 | void board_init_f_init_reserve(ulong base); |
| 237 | |
Simon Glass | 67c4e9f | 2019-11-14 12:57:45 -0700 | [diff] [blame] | 238 | struct global_data; |
| 239 | |
Patrick Delaunay | 11f86cb | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 240 | /** |
| 241 | * arch_setup_gd() - Set up the global_data pointer |
Mario Six | dc145a7 | 2018-08-06 10:23:40 +0200 | [diff] [blame] | 242 | * @gd_ptr: Pointer to global data |
Patrick Delaunay | 11f86cb | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 243 | * |
| 244 | * This pointer is special in some architectures and cannot easily be assigned |
| 245 | * to. For example on x86 it is implemented by adding a specific record to its |
| 246 | * Global Descriptor Table! So we we provide a function to carry out this task. |
| 247 | * For most architectures this can simply be: |
| 248 | * |
| 249 | * gd = gd_ptr; |
Patrick Delaunay | 11f86cb | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 250 | */ |
Simon Glass | 67c4e9f | 2019-11-14 12:57:45 -0700 | [diff] [blame] | 251 | void arch_setup_gd(struct global_data *gd_ptr); |
Patrick Delaunay | 11f86cb | 2018-03-13 13:57:01 +0100 | [diff] [blame] | 252 | |
Patrick Delaunay | dafa84d | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 253 | /* common/board_r.c */ |
Simon Glass | 67c4e9f | 2019-11-14 12:57:45 -0700 | [diff] [blame] | 254 | void board_init_r(struct global_data *id, ulong dest_addr) |
| 255 | __attribute__ ((noreturn)); |
Patrick Delaunay | e2c219c | 2018-03-13 13:57:02 +0100 | [diff] [blame] | 256 | |
| 257 | int cpu_init_r(void); |
| 258 | int last_stage_init(void); |
| 259 | int mac_read_from_eeprom(void); |
| 260 | int set_cpu_clk_info(void); |
| 261 | int update_flash_size(int flash_size); |
| 262 | int arch_early_init_r(void); |
Patrick Delaunay | e2c219c | 2018-03-13 13:57:02 +0100 | [diff] [blame] | 263 | int misc_init_r(void); |
| 264 | #if defined(CONFIG_VID) |
| 265 | int init_func_vid(void); |
| 266 | #endif |
| 267 | |
Patrick Delaunay | fc22ee2 | 2018-03-13 13:57:03 +0100 | [diff] [blame] | 268 | /* common/board_info.c */ |
| 269 | int checkboard(void); |
| 270 | int show_board_info(void); |
Patrick Delaunay | dafa84d | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 271 | |
Simon Glass | 67c4e9f | 2019-11-14 12:57:45 -0700 | [diff] [blame] | 272 | /** |
| 273 | * Get the uppermost pointer that is valid to access |
| 274 | * |
| 275 | * Some systems may not map all of their address space. This function allows |
| 276 | * boards to indicate what their highest support pointer value is for DRAM |
| 277 | * access. |
| 278 | * |
| 279 | * @param total_size Size of U-Boot (unused?) |
| 280 | */ |
| 281 | ulong board_get_usable_ram_top(ulong total_size); |
| 282 | |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 283 | int board_early_init_f(void); |
| 284 | |
| 285 | /* manipulate the U-Boot fdt before its relocation */ |
| 286 | int board_fix_fdt(void *rw_fdt_blob); |
| 287 | int board_late_init(void); |
| 288 | int board_postclk_init(void); /* after clocks/timebase, before env/serial */ |
| 289 | int board_early_init_r(void); |
| 290 | |
Ovidiu Panait | 130845b | 2020-11-28 10:43:18 +0200 | [diff] [blame] | 291 | /** |
| 292 | * arch_initr_trap() - Init traps |
| 293 | * |
| 294 | * Arch specific routine for initializing traps. It is called during the |
| 295 | * generic board init sequence, after relocation. |
| 296 | * |
| 297 | * Return: 0 if OK |
| 298 | */ |
| 299 | int arch_initr_trap(void); |
Simon Glass | d67bdaa | 2019-11-14 12:57:48 -0700 | [diff] [blame] | 300 | |
Simon Glass | 6b8d3ce | 2019-12-28 10:44:39 -0700 | [diff] [blame] | 301 | /** |
Ovidiu Panait | 2fd81be | 2022-01-01 19:13:29 +0200 | [diff] [blame] | 302 | * init_addr_map() |
| 303 | * |
| 304 | * Initialize non-identity virtual-physical memory mappings for 32bit CPUs. |
| 305 | * It is called during the generic board init sequence, after relocation. |
| 306 | * |
| 307 | * Return: 0 if OK |
| 308 | */ |
| 309 | int init_addr_map(void); |
| 310 | |
| 311 | /** |
Simon Glass | 6b8d3ce | 2019-12-28 10:44:39 -0700 | [diff] [blame] | 312 | * main_loop() - Enter the main loop of U-Boot |
| 313 | * |
| 314 | * This normally runs the command line. |
| 315 | */ |
| 316 | void main_loop(void); |
| 317 | |
Simon Glass | 9413387 | 2019-12-28 10:44:45 -0700 | [diff] [blame] | 318 | #if defined(CONFIG_ARM) |
| 319 | void relocate_code(ulong addr_moni); |
| 320 | #else |
| 321 | void relocate_code(ulong start_addr_sp, struct global_data *new_gd, |
| 322 | ulong relocaddr) |
| 323 | __attribute__ ((noreturn)); |
| 324 | #endif |
| 325 | |
Simon Glass | 655f17f | 2020-05-10 14:16:55 -0600 | [diff] [blame] | 326 | /* Print a numeric value (for use in arch_print_bdinfo()) */ |
Bin Meng | 98592c7 | 2021-01-31 20:36:05 +0800 | [diff] [blame] | 327 | void bdinfo_print_num_l(const char *name, ulong value); |
| 328 | void bdinfo_print_num_ll(const char *name, unsigned long long value); |
Simon Glass | 655f17f | 2020-05-10 14:16:55 -0600 | [diff] [blame] | 329 | |
| 330 | /* Print a clock speed in MHz */ |
| 331 | void bdinfo_print_mhz(const char *name, unsigned long hz); |
| 332 | |
Simon Glass | 59b0d7d | 2020-05-10 14:16:56 -0600 | [diff] [blame] | 333 | /* Show arch-specific information for the 'bd' command */ |
| 334 | void arch_print_bdinfo(void); |
| 335 | |
Andy Shevchenko | 4b32531 | 2021-11-08 21:03:38 +0300 | [diff] [blame] | 336 | int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); |
| 337 | |
Patrick Delaunay | dafa84d | 2018-03-09 18:28:12 +0100 | [diff] [blame] | 338 | #endif /* __ASSEMBLY__ */ |
| 339 | /* Put only stuff here that the assembler can digest */ |
| 340 | |
| 341 | #endif /* __INIT_H_ */ |