init.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. /* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */
  14. #ifdef CONFIG_EFI_STUB
  15. #define ll_boot_init() false
  16. #else
  17. #include <asm/global_data.h>
  18. #define ll_boot_init() (!(gd->flags & GD_FLG_SKIP_LL_INIT))
  19. #endif
  20. /*
  21. * Function Prototypes
  22. */
  23. /* common/board_f.c */
  24. void board_init_f(ulong dummy);
  25. /**
  26. * arch_cpu_init() - basic cpu-dependent setup for an architecture
  27. *
  28. * This is called after early malloc is available. It should handle any
  29. * CPU- or SoC- specific init needed to continue the init sequence. See
  30. * board_f.c for where it is called. If this is not provided, a default
  31. * version (which does nothing) will be used.
  32. *
  33. * Return: 0 on success, otherwise error
  34. */
  35. int arch_cpu_init(void);
  36. /**
  37. * arch_cpu_init_dm() - init CPU after driver model is available
  38. *
  39. * This is called immediately after driver model is available before
  40. * relocation. This is similar to arch_cpu_init() but is able to reference
  41. * devices
  42. *
  43. * Return: 0 if OK, -ve on error
  44. */
  45. int arch_cpu_init_dm(void);
  46. /**
  47. * mach_cpu_init() - SoC/machine dependent CPU setup
  48. *
  49. * This is called after arch_cpu_init(). It should handle any
  50. * SoC or machine specific init needed to continue the init sequence. See
  51. * board_f.c for where it is called. If this is not provided, a default
  52. * version (which does nothing) will be used.
  53. *
  54. * Return: 0 on success, otherwise error
  55. */
  56. int mach_cpu_init(void);
  57. /**
  58. * arch_fsp_init() - perform firmware support package init
  59. *
  60. * Where U-Boot relies on binary blobs to handle part of the system init, this
  61. * function can be used to set up the blobs. This is used on some Intel
  62. * platforms.
  63. *
  64. * Return: 0
  65. */
  66. int arch_fsp_init(void);
  67. /**
  68. * arch_fsp_init() - perform post-relocation firmware support package init
  69. *
  70. * Where U-Boot relies on binary blobs to handle part of the system init, this
  71. * function can be used to set up the blobs. This is used on some Intel
  72. * platforms.
  73. *
  74. * Return: 0
  75. */
  76. int arch_fsp_init_r(void);
  77. int dram_init(void);
  78. /**
  79. * dram_init_banksize() - Set up DRAM bank sizes
  80. *
  81. * This can be implemented by boards to set up the DRAM bank information in
  82. * gd->bd->bi_dram(). It is called just before relocation, after dram_init()
  83. * is called.
  84. *
  85. * If this is not provided, a default implementation will try to set up a
  86. * single bank. It will do this if CONFIG_NR_DRAM_BANKS and
  87. * CONFIG_SYS_SDRAM_BASE are set. The bank will have a start address of
  88. * CONFIG_SYS_SDRAM_BASE and the size will be determined by a call to
  89. * get_effective_memsize().
  90. *
  91. * Return: 0 if OK, -ve on error
  92. */
  93. int dram_init_banksize(void);
  94. long get_ram_size(long *base, long size);
  95. phys_size_t get_effective_memsize(void);
  96. int testdram(void);
  97. /**
  98. * arch_reserve_stacks() - Reserve all necessary stacks
  99. *
  100. * This is used in generic board init sequence in common/board_f.c. Each
  101. * architecture could provide this function to tailor the required stacks.
  102. *
  103. * On entry gd->start_addr_sp is pointing to the suggested top of the stack.
  104. * The callee ensures gd->start_add_sp is 16-byte aligned, so architectures
  105. * require only this can leave it untouched.
  106. *
  107. * On exit gd->start_addr_sp and gd->irq_sp should be set to the respective
  108. * positions of the stack. The stack pointer(s) will be set to this later.
  109. * gd->irq_sp is only required, if the architecture needs it.
  110. *
  111. * Return: 0 if no error
  112. */
  113. int arch_reserve_stacks(void);
  114. /**
  115. * arch_reserve_mmu() - Reserve memory for MMU TLB table
  116. *
  117. * Architecture-specific routine for reserving memory for the MMU TLB table.
  118. * This is used in generic board init sequence in common/board_f.c.
  119. *
  120. * If an implementation is not provided, it will just be a nop stub.
  121. *
  122. * Return: 0 if OK
  123. */
  124. int arch_reserve_mmu(void);
  125. /**
  126. * arch_setup_bdinfo() - Architecture dependent boardinfo setup
  127. *
  128. * Architecture-specific routine for populating various boardinfo fields of
  129. * gd->bd. It is called during the generic board init sequence.
  130. *
  131. * If an implementation is not provided, it will just be a nop stub.
  132. *
  133. * Return: 0 if OK
  134. */
  135. int arch_setup_bdinfo(void);
  136. /**
  137. * setup_bdinfo() - Generic boardinfo setup
  138. *
  139. * Routine for populating various generic boardinfo fields of
  140. * gd->bd. It is called during the generic board init sequence.
  141. *
  142. * Return: 0 if OK
  143. */
  144. int setup_bdinfo(void);
  145. /**
  146. * cpu_secondary_init_r() - CPU-specific secondary initialization
  147. *
  148. * After non-volatile devices, environment and cpu code are setup, have
  149. * another round to deal with any initialization that might require
  150. * full access to the environment or loading of some image (firmware)
  151. * from a non-volatile device.
  152. *
  153. * It is called during the generic post-relocation init sequence.
  154. *
  155. * Return: 0 if OK
  156. */
  157. int cpu_secondary_init_r(void);
  158. /**
  159. * pci_ep_init() - Initialize pci endpoint devices
  160. *
  161. * It is called during the generic post-relocation init sequence.
  162. *
  163. * Return: 0 if OK
  164. */
  165. int pci_ep_init(void);
  166. /**
  167. * pci_init() - Enumerate pci devices
  168. *
  169. * It is called during the generic post-relocation init sequence to enumerate
  170. * pci buses. This is needed, for instance, in the case of DM PCI-based
  171. * Ethernet devices, which will not be detected without having the enumeration
  172. * performed earlier.
  173. *
  174. * Return: 0 if OK
  175. */
  176. int pci_init(void);
  177. /**
  178. * init_cache_f_r() - Turn on the cache in preparation for relocation
  179. *
  180. * Return: 0 if OK, -ve on error
  181. */
  182. int init_cache_f_r(void);
  183. #if !CONFIG_IS_ENABLED(CPU)
  184. /**
  185. * print_cpuinfo() - Display information about the CPU
  186. *
  187. * Return: 0 if OK, -ve on error
  188. */
  189. int print_cpuinfo(void);
  190. #endif
  191. int timer_init(void);
  192. int misc_init_f(void);
  193. #if defined(CONFIG_DTB_RESELECT)
  194. int embedded_dtb_select(void);
  195. #endif
  196. /* common/init/board_init.c */
  197. extern ulong monitor_flash_len;
  198. /**
  199. * ulong board_init_f_alloc_reserve - allocate reserved area
  200. * @top: top of the reserve area, growing down.
  201. *
  202. * This function is called by each architecture very early in the start-up
  203. * code to allow the C runtime to reserve space on the stack for writable
  204. * 'globals' such as GD and the malloc arena.
  205. *
  206. * Return: bottom of reserved area
  207. */
  208. ulong board_init_f_alloc_reserve(ulong top);
  209. /**
  210. * board_init_f_init_reserve - initialize the reserved area(s)
  211. * @base: top from which reservation was done
  212. *
  213. * This function is called once the C runtime has allocated the reserved
  214. * area on the stack. It must initialize the GD at the base of that area.
  215. */
  216. void board_init_f_init_reserve(ulong base);
  217. struct global_data;
  218. /**
  219. * arch_setup_gd() - Set up the global_data pointer
  220. * @gd_ptr: Pointer to global data
  221. *
  222. * This pointer is special in some architectures and cannot easily be assigned
  223. * to. For example on x86 it is implemented by adding a specific record to its
  224. * Global Descriptor Table! So we we provide a function to carry out this task.
  225. * For most architectures this can simply be:
  226. *
  227. * gd = gd_ptr;
  228. */
  229. void arch_setup_gd(struct global_data *gd_ptr);
  230. /* common/board_r.c */
  231. void board_init_r(struct global_data *id, ulong dest_addr)
  232. __attribute__ ((noreturn));
  233. int cpu_init_r(void);
  234. int last_stage_init(void);
  235. int mac_read_from_eeprom(void);
  236. int set_cpu_clk_info(void);
  237. #if CONFIG_IS_ENABLED(TARGET_STARFIVE_DEVKITS)
  238. int set_pmic(void);
  239. #endif
  240. int update_flash_size(int flash_size);
  241. int arch_early_init_r(void);
  242. int misc_init_r(void);
  243. #if defined(CONFIG_VID)
  244. int init_func_vid(void);
  245. #endif
  246. /* common/board_info.c */
  247. int checkboard(void);
  248. int show_board_info(void);
  249. /**
  250. * Get the uppermost pointer that is valid to access
  251. *
  252. * Some systems may not map all of their address space. This function allows
  253. * boards to indicate what their highest support pointer value is for DRAM
  254. * access.
  255. *
  256. * @param total_size Size of U-Boot (unused?)
  257. */
  258. ulong board_get_usable_ram_top(ulong total_size);
  259. int board_early_init_f(void);
  260. /* manipulate the U-Boot fdt before its relocation */
  261. int board_fix_fdt(void *rw_fdt_blob);
  262. int board_late_init(void);
  263. int board_postclk_init(void); /* after clocks/timebase, before env/serial */
  264. int board_early_init_r(void);
  265. /**
  266. * arch_initr_trap() - Init traps
  267. *
  268. * Arch specific routine for initializing traps. It is called during the
  269. * generic board init sequence, after relocation.
  270. *
  271. * Return: 0 if OK
  272. */
  273. int arch_initr_trap(void);
  274. /**
  275. * main_loop() - Enter the main loop of U-Boot
  276. *
  277. * This normally runs the command line.
  278. */
  279. void main_loop(void);
  280. #if defined(CONFIG_ARM)
  281. void relocate_code(ulong addr_moni);
  282. #else
  283. void relocate_code(ulong start_addr_sp, struct global_data *new_gd,
  284. ulong relocaddr)
  285. __attribute__ ((noreturn));
  286. #endif
  287. /* Print a numeric value (for use in arch_print_bdinfo()) */
  288. void bdinfo_print_num_l(const char *name, ulong value);
  289. void bdinfo_print_num_ll(const char *name, unsigned long long value);
  290. /* Print a clock speed in MHz */
  291. void bdinfo_print_mhz(const char *name, unsigned long hz);
  292. /* Show arch-specific information for the 'bd' command */
  293. void arch_print_bdinfo(void);
  294. #endif /* __ASSEMBLY__ */
  295. /* Put only stuff here that the assembler can digest */
  296. #endif /* __INIT_H_ */