common.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Common header file for U-Boot
  4. *
  5. * This file still includes quite a bit of stuff that should be in separate
  6. * headers like command.h. Please think before adding more things.
  7. * Patches to remove things are welcome.
  8. *
  9. * (C) Copyright 2000-2009
  10. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  11. */
  12. #ifndef __COMMON_H_
  13. #define __COMMON_H_ 1
  14. #ifndef __ASSEMBLY__ /* put C only stuff in this section */
  15. typedef unsigned char uchar;
  16. typedef volatile unsigned long vu_long;
  17. typedef volatile unsigned short vu_short;
  18. typedef volatile unsigned char vu_char;
  19. #include <config.h>
  20. #include <errno.h>
  21. #include <time.h>
  22. #include <asm-offsets.h>
  23. #include <linux/bitops.h>
  24. #include <linux/bug.h>
  25. #include <linux/delay.h>
  26. #include <linux/types.h>
  27. #include <linux/printk.h>
  28. #include <linux/string.h>
  29. #include <linux/stringify.h>
  30. #include <asm/ptrace.h>
  31. #include <stdarg.h>
  32. #include <stdio.h>
  33. #include <linux/kernel.h>
  34. #include <part.h>
  35. #include <flash.h>
  36. #include <image.h>
  37. #ifdef __LP64__
  38. #define CONFIG_SYS_SUPPORT_64BIT_DATA
  39. #endif
  40. #include <log.h>
  41. typedef void (interrupt_handler_t)(void *);
  42. #include <asm/u-boot.h> /* boot information for Linux kernel */
  43. #include <asm/global_data.h> /* global data used for startup functions */
  44. /* startup functions, used in:
  45. * common/board_f.c
  46. * common/init/board_init.c
  47. * common/board_r.c
  48. * common/board_info.c
  49. */
  50. #include <init.h>
  51. /*
  52. * Function Prototypes
  53. */
  54. void hang (void) __attribute__ ((noreturn));
  55. #include <display_options.h>
  56. /* common/main.c */
  57. void main_loop (void);
  58. int run_command(const char *cmd, int flag);
  59. int run_command_repeatable(const char *cmd, int flag);
  60. /**
  61. * Run a list of commands separated by ; or even \0
  62. *
  63. * Note that if 'len' is not -1, then the command does not need to be nul
  64. * terminated, Memory will be allocated for the command in that case.
  65. *
  66. * @param cmd List of commands to run, each separated bu semicolon
  67. * @param len Length of commands excluding terminator if known (-1 if not)
  68. * @param flag Execution flags (CMD_FLAG_...)
  69. * @return 0 on success, or != 0 on error.
  70. */
  71. int run_command_list(const char *cmd, int len, int flag);
  72. int checkflash(void);
  73. int checkdram(void);
  74. extern u8 __dtb_dt_begin[]; /* embedded device tree blob */
  75. extern u8 __dtb_dt_spl_begin[]; /* embedded device tree blob for SPL/TPL */
  76. int mdm_init(void);
  77. /**
  78. * Show the DRAM size in a board-specific way
  79. *
  80. * This is used by boards to display DRAM information in their own way.
  81. *
  82. * @param size Size of DRAM (which should be displayed along with other info)
  83. */
  84. void board_show_dram(phys_size_t size);
  85. /**
  86. * Get the uppermost pointer that is valid to access
  87. *
  88. * Some systems may not map all of their address space. This function allows
  89. * boards to indicate what their highest support pointer value is for DRAM
  90. * access.
  91. *
  92. * @param total_size Size of U-Boot (unused?)
  93. */
  94. ulong board_get_usable_ram_top(ulong total_size);
  95. /**
  96. * arch_fixup_fdt() - Write arch-specific information to fdt
  97. *
  98. * Defined in arch/$(ARCH)/lib/bootm-fdt.c
  99. *
  100. * @blob: FDT blob to write to
  101. * @return 0 if ok, or -ve FDT_ERR_... on failure
  102. */
  103. int arch_fixup_fdt(void *blob);
  104. /* common/flash.c */
  105. void flash_perror (int);
  106. /* common/cmd_source.c */
  107. int source (ulong addr, const char *fit_uname);
  108. extern ulong load_addr; /* Default Load Address */
  109. extern ulong save_addr; /* Default Save Address */
  110. extern ulong save_size; /* Default Save Size */
  111. /* common/cmd_net.c */
  112. int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  113. /* common/cmd_fat.c */
  114. int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
  115. /* common/cmd_ext2.c */
  116. int do_ext2load(cmd_tbl_t *, int, int, char * const []);
  117. void pci_init_board(void);
  118. /* common/exports.c */
  119. void jumptable_init(void);
  120. /* common/kallsysm.c */
  121. const char *symbol_lookup(unsigned long addr, unsigned long *caddr);
  122. /* common/memsize.c */
  123. long get_ram_size (long *, long);
  124. phys_size_t get_effective_memsize(void);
  125. /* $(BOARD)/$(BOARD).c */
  126. void reset_phy (void);
  127. void fdc_hw_init (void);
  128. /* $(BOARD)/eeprom.c */
  129. #ifdef CONFIG_CMD_EEPROM
  130. void eeprom_init (int bus);
  131. int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  132. int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  133. #else
  134. /*
  135. * Some EEPROM code is depecated because it used the legacy I2C interface. Add
  136. * some macros here so we don't have to touch every one of those uses
  137. */
  138. #define eeprom_init(bus)
  139. #define eeprom_read(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
  140. #define eeprom_write(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
  141. #endif
  142. #if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
  143. # define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR
  144. #endif
  145. /* $(BOARD)/$(BOARD).c */
  146. int board_early_init_f (void);
  147. int board_fix_fdt (void *rw_fdt_blob); /* manipulate the U-Boot fdt before its relocation */
  148. int board_late_init (void);
  149. int board_postclk_init (void); /* after clocks/timebase, before env/serial */
  150. int board_early_init_r (void);
  151. #if defined(CONFIG_SYS_DRAM_TEST)
  152. int testdram(void);
  153. #endif /* CONFIG_SYS_DRAM_TEST */
  154. #if defined(CONFIG_ARM)
  155. void relocate_code(ulong);
  156. #else
  157. void relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
  158. #endif
  159. ulong get_endaddr (void);
  160. void trap_init (ulong);
  161. void s_init(void);
  162. int checkicache (void);
  163. int checkdcache (void);
  164. void upmconfig (unsigned int, unsigned int *, unsigned int);
  165. ulong get_tbclk (void);
  166. void reset_misc (void);
  167. void reset_cpu (ulong addr);
  168. void ft_cpu_setup(void *blob, bd_t *bd);
  169. void ft_pci_setup(void *blob, bd_t *bd);
  170. /* $(CPU)/speed.c */
  171. int get_clocks (void);
  172. ulong get_bus_freq (ulong);
  173. int get_serial_clock(void);
  174. /* $(CPU)/interrupts.c */
  175. int interrupt_init (void);
  176. void timer_interrupt (struct pt_regs *);
  177. void external_interrupt (struct pt_regs *);
  178. void irq_install_handler(int, interrupt_handler_t *, void *);
  179. void irq_free_handler (int);
  180. void reset_timer (void);
  181. void enable_interrupts (void);
  182. int disable_interrupts (void);
  183. /* arch/$(ARCH)/lib/cache.c */
  184. void enable_caches(void);
  185. void flush_cache (unsigned long, unsigned long);
  186. void flush_dcache_all(void);
  187. void flush_dcache_range(unsigned long start, unsigned long stop);
  188. void invalidate_dcache_range(unsigned long start, unsigned long stop);
  189. void invalidate_dcache_all(void);
  190. void invalidate_icache_all(void);
  191. enum {
  192. /* Disable caches (else flush caches but leave them active) */
  193. CBL_DISABLE_CACHES = 1 << 0,
  194. CBL_SHOW_BOOTSTAGE_REPORT = 1 << 1,
  195. CBL_ALL = 3,
  196. };
  197. /**
  198. * Clean up ready for linux
  199. *
  200. * @param flags Flags to control what is done
  201. */
  202. int cleanup_before_linux_select(int flags);
  203. /* lib/uuid.c */
  204. #include <uuid.h>
  205. /* lib/vsprintf.c */
  206. #include <vsprintf.h>
  207. /* lib/net_utils.c */
  208. #include <net.h>
  209. #include <bootstage.h>
  210. #else /* __ASSEMBLY__ */
  211. #endif /* __ASSEMBLY__ */
  212. /* Put only stuff here that the assembler can digest */
  213. #ifdef CONFIG_POST
  214. #define CONFIG_HAS_POST
  215. #ifndef CONFIG_POST_ALT_LIST
  216. #define CONFIG_POST_STD_LIST
  217. #endif
  218. #endif
  219. #define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1))
  220. /*
  221. * check_member() - Check the offset of a structure member
  222. *
  223. * @structure: Name of structure (e.g. global_data)
  224. * @member: Name of member (e.g. baudrate)
  225. * @offset: Expected offset in bytes
  226. */
  227. #define check_member(structure, member, offset) _Static_assert( \
  228. offsetof(struct structure, member) == offset, \
  229. "`struct " #structure "` offset for `" #member "` is not " #offset)
  230. /* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */
  231. #ifdef CONFIG_EFI_STUB
  232. #define ll_boot_init() false
  233. #else
  234. #define ll_boot_init() true
  235. #endif
  236. /* Pull in stuff for the build system */
  237. #ifdef DO_DEPS_ONLY
  238. # include <env_internal.h>
  239. #endif
  240. #endif /* __COMMON_H_ */