init.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  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
  8. */
  9. #ifndef __INIT_H_
  10. #define __INIT_H_ 1
  11. #ifndef __ASSEMBLY__ /* put C only stuff in this section */
  12. #include <linux/types.h>
  13. /*
  14. * In case of the EFI app the UEFI firmware provides the low-level
  15. * initialisation.
  16. */
  17. #ifdef CONFIG_EFI
  18. #define ll_boot_init() false
  19. #else
  20. #include <asm/global_data.h>
  21. #define ll_boot_init() (!(gd->flags & GD_FLG_SKIP_LL_INIT))
  22. #endif
  23. /*
  24. * Function Prototypes
  25. */
  26. /* common/board_f.c */
  27. void board_init_f(ulong dummy);
  28. /**
  29. * arch_cpu_init() - basic cpu-dependent setup for an architecture
  30. *
  31. * This is called after early malloc is available. It should handle any
  32. * CPU- or SoC- specific init needed to continue the init sequence. See
  33. * board_f.c for where it is called. If this is not provided, a default
  34. * version (which does nothing) will be used.
  35. *
  36. * Return: 0 on success, otherwise error
  37. */
  38. int arch_cpu_init(void);
  39. /**
  40. * mach_cpu_init() - SoC/machine dependent CPU setup
  41. *
  42. * This is called after arch_cpu_init(). It should handle any
  43. * SoC or machine specific init needed to continue the init sequence. See
  44. * board_f.c for where it is called. If this is not provided, a default
  45. * version (which does nothing) will be used.
  46. *
  47. * Return: 0 on success, otherwise error
  48. */
  49. int mach_cpu_init(void);
  50. /**
  51. * arch_fsp_init() - perform firmware support package init
  52. *
  53. * Where U-Boot relies on binary blobs to handle part of the system init, this
  54. * function can be used to set up the blobs. This is used on some Intel
  55. * platforms.
  56. *
  57. * Return: 0
  58. */
  59. int arch_fsp_init(void);
  60. /**
  61. * 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. */
  69. int arch_fsp_init_r(void);
  70. int dram_init(void);
  71. /**
  72. * dram_init_banksize() - Set up DRAM bank sizes
  73. *
  74. * This can be implemented by boards to set up the DRAM bank information in
  75. * gd->bd->bi_dram(). It is called just before relocation, after dram_init()
  76. * is called.
  77. *
  78. * If this is not provided, a default implementation will try to set up a
  79. * single bank. It will do this if CONFIG_NR_DRAM_BANKS and
  80. * CFG_SYS_SDRAM_BASE are set. The bank will have a start address of
  81. * CFG_SYS_SDRAM_BASE and the size will be determined by a call to
  82. * get_effective_memsize().
  83. *
  84. * Return: 0 if OK, -ve on error
  85. */
  86. int dram_init_banksize(void);
  87. long get_ram_size(long *base, long size);
  88. phys_size_t get_effective_memsize(void);
  89. int testdram(void);
  90. /**
  91. * arch_setup_dest_addr() - Fix up initial reloc address
  92. *
  93. * This is called in generic board init sequence in common/board_f.c at the end
  94. * of the setup_dest_addr() initcall. Each architecture could provide this
  95. * function to make adjustments to the initial reloc address.
  96. *
  97. * If an implementation is not provided, it will just be a nop stub.
  98. *
  99. * Return: 0 if OK
  100. */
  101. int arch_setup_dest_addr(void);
  102. /**
  103. * arch_reserve_stacks() - Reserve all necessary stacks
  104. *
  105. * This is used in generic board init sequence in common/board_f.c. Each
  106. * architecture could provide this function to tailor the required stacks.
  107. *
  108. * On entry gd->start_addr_sp is pointing to the suggested top of the stack.
  109. * The callee ensures gd->start_add_sp is 16-byte aligned, so architectures
  110. * require only this can leave it untouched.
  111. *
  112. * On exit gd->start_addr_sp and gd->irq_sp should be set to the respective
  113. * positions of the stack. The stack pointer(s) will be set to this later.
  114. * gd->irq_sp is only required, if the architecture needs it.
  115. *
  116. * Return: 0 if no error
  117. */
  118. int arch_reserve_stacks(void);
  119. /**
  120. * arch_reserve_mmu() - Reserve memory for MMU TLB table
  121. *
  122. * Architecture-specific routine for reserving memory for the MMU TLB table.
  123. * This is used in generic board init sequence in common/board_f.c.
  124. *
  125. * If an implementation is not provided, it will just be a nop stub.
  126. *
  127. * Return: 0 if OK
  128. */
  129. int arch_reserve_mmu(void);
  130. /**
  131. * arch_setup_bdinfo() - Architecture dependent boardinfo setup
  132. *
  133. * Architecture-specific routine for populating various boardinfo fields of
  134. * gd->bd. It is called during the generic board init sequence.
  135. *
  136. * If an implementation is not provided, it will just be a nop stub.
  137. *
  138. * Return: 0 if OK
  139. */
  140. int arch_setup_bdinfo(void);
  141. /**
  142. * setup_bdinfo() - Generic boardinfo setup
  143. *
  144. * Routine for populating various generic boardinfo fields of
  145. * gd->bd. It is called during the generic board init sequence.
  146. *
  147. * Return: 0 if OK
  148. */
  149. int setup_bdinfo(void);
  150. #if defined(CONFIG_SAVE_PREV_BL_INITRAMFS_START_ADDR) || \
  151. defined(CONFIG_SAVE_PREV_BL_FDT_ADDR)
  152. /**
  153. * save_prev_bl_data - Save prev bl data in env vars.
  154. *
  155. * When u-boot is chain-loaded, save previous bootloader data,
  156. * like initramfs address to environment variables.
  157. *
  158. * Return: 0 if ok; -ENODATA on error
  159. */
  160. int save_prev_bl_data(void);
  161. #endif
  162. /**
  163. * cpu_secondary_init_r() - CPU-specific secondary initialization
  164. *
  165. * After non-volatile devices, environment and cpu code are setup, have
  166. * another round to deal with any initialization that might require
  167. * full access to the environment or loading of some image (firmware)
  168. * from a non-volatile device.
  169. *
  170. * It is called during the generic post-relocation init sequence.
  171. *
  172. * Return: 0 if OK
  173. */
  174. int cpu_secondary_init_r(void);
  175. /**
  176. * pci_ep_init() - Initialize pci endpoint devices
  177. *
  178. * It is called during the generic post-relocation init sequence.
  179. *
  180. * Return: 0 if OK
  181. */
  182. int pci_ep_init(void);
  183. /**
  184. * pci_init() - Enumerate pci devices
  185. *
  186. * It is called during the generic post-relocation init sequence to enumerate
  187. * pci buses. This is needed, for instance, in the case of DM PCI-based
  188. * Ethernet devices, which will not be detected without having the enumeration
  189. * performed earlier.
  190. *
  191. * Return: 0 if OK
  192. */
  193. int pci_init(void);
  194. /**
  195. * init_cache_f_r() - Turn on the cache in preparation for relocation
  196. *
  197. * Return: 0 if OK, -ve on error
  198. */
  199. int init_cache_f_r(void);
  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. */
  206. int print_cpuinfo(void);
  207. #endif
  208. int timer_init(void);
  209. #if defined(CONFIG_DTB_RESELECT)
  210. int embedded_dtb_select(void);
  211. #endif
  212. /* common/init/board_init.c */
  213. extern ulong monitor_flash_len;
  214. /**
  215. * ulong board_init_f_alloc_reserve - allocate reserved area
  216. * @top: top of the reserve area, growing down.
  217. *
  218. * This function is called by each architecture very early in the start-up
  219. * code to allow the C runtime to reserve space on the stack for writable
  220. * 'globals' such as GD and the malloc arena.
  221. *
  222. * Return: bottom of reserved area
  223. */
  224. ulong board_init_f_alloc_reserve(ulong top);
  225. /**
  226. * board_init_f_init_reserve - initialize the reserved area(s)
  227. * @base: top from which reservation was done
  228. *
  229. * This function is called once the C runtime has allocated the reserved
  230. * area on the stack. It must initialize the GD at the base of that area.
  231. */
  232. void board_init_f_init_reserve(ulong base);
  233. struct global_data;
  234. /**
  235. * arch_setup_gd() - Set up the global_data pointer
  236. * @gd_ptr: Pointer to global data
  237. *
  238. * This pointer is special in some architectures and cannot easily be assigned
  239. * to. For example on x86 it is implemented by adding a specific record to its
  240. * Global Descriptor Table! So we we provide a function to carry out this task.
  241. * For most architectures this can simply be:
  242. *
  243. * gd = gd_ptr;
  244. */
  245. void arch_setup_gd(struct global_data *gd_ptr);
  246. /* common/board_r.c */
  247. void board_init_r(struct global_data *id, ulong dest_addr)
  248. __attribute__ ((noreturn));
  249. int cpu_init_r(void);
  250. int last_stage_init(void);
  251. int mac_read_from_eeprom(void);
  252. int set_cpu_clk_info(void);
  253. int update_flash_size(int flash_size);
  254. int arch_early_init_r(void);
  255. int misc_init_r(void);
  256. #if defined(CONFIG_VID)
  257. int init_func_vid(void);
  258. #endif
  259. /* common/board_info.c */
  260. int checkboard(void);
  261. int show_board_info(void);
  262. /**
  263. * board_get_usable_ram_top() - get uppermost address for U-Boot relocation
  264. *
  265. * Some systems have reserved memory areas in high memory. By implementing this
  266. * function boards can indicate the highest address value to be used when
  267. * relocating U-Boot. The returned address is exclusive (i.e. 1 byte above the
  268. * last usable address).
  269. *
  270. * Due to overflow on systems with 32bit phys_addr_t a value 0 is used instead
  271. * of 4GiB.
  272. *
  273. * @total_size: monitor length in bytes (size of U-Boot code)
  274. * Return: uppermost address for U-Boot relocation
  275. */
  276. phys_addr_t board_get_usable_ram_top(phys_size_t total_size);
  277. int board_early_init_f(void);
  278. /* manipulate the U-Boot fdt before its relocation */
  279. int board_fix_fdt(void *rw_fdt_blob);
  280. int board_late_init(void);
  281. int board_postclk_init(void); /* after clocks/timebase, before env/serial */
  282. int board_early_init_r(void);
  283. /**
  284. * arch_initr_trap() - Init traps
  285. *
  286. * Arch specific routine for initializing traps. It is called during the
  287. * generic board init sequence, after relocation.
  288. *
  289. * Return: 0 if OK
  290. */
  291. int arch_initr_trap(void);
  292. /**
  293. * init_addr_map()
  294. *
  295. * Initialize non-identity virtual-physical memory mappings for 32bit CPUs.
  296. * It is called during the generic board init sequence, after relocation.
  297. *
  298. * Return: 0 if OK
  299. */
  300. int init_addr_map(void);
  301. /**
  302. * main_loop() - Enter the main loop of U-Boot
  303. *
  304. * This normally runs the command line.
  305. */
  306. void main_loop(void);
  307. #if defined(CONFIG_ARM)
  308. void relocate_code(ulong addr_moni);
  309. #else
  310. void relocate_code(ulong start_addr_sp, struct global_data *new_gd,
  311. ulong relocaddr)
  312. __attribute__ ((noreturn));
  313. #endif
  314. /* Print a numeric value (for use in arch_print_bdinfo()) */
  315. void bdinfo_print_num_l(const char *name, ulong value);
  316. void bdinfo_print_num_ll(const char *name, unsigned long long value);
  317. /* Print a string value (for use in arch_print_bdinfo()) */
  318. void bdinfo_print_str(const char *name, const char *str);
  319. /* Print a clock speed in MHz */
  320. void bdinfo_print_mhz(const char *name, unsigned long hz);
  321. /**
  322. * bdinfo_print_size - print size variables in bdinfo format
  323. * @name: string to print before the size
  324. * @size: size to print
  325. *
  326. * Helper function for displaying size variables as properly formatted bdinfo
  327. * entries. The size is printed as "xxx Bytes", "xxx KiB", "xxx MiB",
  328. * "xxx GiB", etc. as needed;
  329. *
  330. * For use in arch_print_bdinfo().
  331. */
  332. void bdinfo_print_size(const char *name, uint64_t size);
  333. /* Show arch-specific information for the 'bd' command */
  334. void arch_print_bdinfo(void);
  335. int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
  336. #endif /* __ASSEMBLY__ */
  337. /* Put only stuff here that the assembler can digest */
  338. #endif /* __INIT_H_ */