common.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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, cpu.h and timer.h. Please think before adding more
  7. * things. 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. int cpu_init(void);
  56. #include <display_options.h>
  57. /* common/main.c */
  58. void main_loop (void);
  59. int run_command(const char *cmd, int flag);
  60. int run_command_repeatable(const char *cmd, int flag);
  61. /**
  62. * Run a list of commands separated by ; or even \0
  63. *
  64. * Note that if 'len' is not -1, then the command does not need to be nul
  65. * terminated, Memory will be allocated for the command in that case.
  66. *
  67. * @param cmd List of commands to run, each separated bu semicolon
  68. * @param len Length of commands excluding terminator if known (-1 if not)
  69. * @param flag Execution flags (CMD_FLAG_...)
  70. * @return 0 on success, or != 0 on error.
  71. */
  72. int run_command_list(const char *cmd, int len, int flag);
  73. int checkflash(void);
  74. int checkdram(void);
  75. extern u8 __dtb_dt_begin[]; /* embedded device tree blob */
  76. extern u8 __dtb_dt_spl_begin[]; /* embedded device tree blob for SPL/TPL */
  77. int mdm_init(void);
  78. /**
  79. * Show the DRAM size in a board-specific way
  80. *
  81. * This is used by boards to display DRAM information in their own way.
  82. *
  83. * @param size Size of DRAM (which should be displayed along with other info)
  84. */
  85. void board_show_dram(phys_size_t size);
  86. /**
  87. * Get the uppermost pointer that is valid to access
  88. *
  89. * Some systems may not map all of their address space. This function allows
  90. * boards to indicate what their highest support pointer value is for DRAM
  91. * access.
  92. *
  93. * @param total_size Size of U-Boot (unused?)
  94. */
  95. ulong board_get_usable_ram_top(ulong total_size);
  96. /**
  97. * arch_fixup_fdt() - Write arch-specific information to fdt
  98. *
  99. * Defined in arch/$(ARCH)/lib/bootm-fdt.c
  100. *
  101. * @blob: FDT blob to write to
  102. * @return 0 if ok, or -ve FDT_ERR_... on failure
  103. */
  104. int arch_fixup_fdt(void *blob);
  105. /* common/flash.c */
  106. void flash_perror (int);
  107. /* common/cmd_source.c */
  108. int source (ulong addr, const char *fit_uname);
  109. extern ulong load_addr; /* Default Load Address */
  110. extern ulong save_addr; /* Default Save Address */
  111. extern ulong save_size; /* Default Save Size */
  112. /* common/cmd_net.c */
  113. int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  114. /* common/cmd_fat.c */
  115. int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
  116. /* common/cmd_ext2.c */
  117. int do_ext2load(cmd_tbl_t *, int, int, char * const []);
  118. void pci_init_board(void);
  119. /* common/exports.c */
  120. void jumptable_init(void);
  121. /* common/kallsysm.c */
  122. const char *symbol_lookup(unsigned long addr, unsigned long *caddr);
  123. /* common/memsize.c */
  124. long get_ram_size (long *, long);
  125. phys_size_t get_effective_memsize(void);
  126. /* $(BOARD)/$(BOARD).c */
  127. void reset_phy (void);
  128. void fdc_hw_init (void);
  129. /* $(BOARD)/eeprom.c */
  130. #ifdef CONFIG_CMD_EEPROM
  131. void eeprom_init (int bus);
  132. int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  133. int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  134. #else
  135. /*
  136. * Some EEPROM code is depecated because it used the legacy I2C interface. Add
  137. * some macros here so we don't have to touch every one of those uses
  138. */
  139. #define eeprom_init(bus)
  140. #define eeprom_read(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
  141. #define eeprom_write(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
  142. #endif
  143. #if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
  144. # define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR
  145. #endif
  146. /* $(BOARD)/$(BOARD).c */
  147. int board_early_init_f (void);
  148. int board_fix_fdt (void *rw_fdt_blob); /* manipulate the U-Boot fdt before its relocation */
  149. int board_late_init (void);
  150. int board_postclk_init (void); /* after clocks/timebase, before env/serial */
  151. int board_early_init_r (void);
  152. #if defined(CONFIG_SYS_DRAM_TEST)
  153. int testdram(void);
  154. #endif /* CONFIG_SYS_DRAM_TEST */
  155. /* $(CPU)/start.S */
  156. int icache_status (void);
  157. void icache_enable (void);
  158. void icache_disable(void);
  159. int dcache_status (void);
  160. void dcache_enable (void);
  161. void dcache_disable(void);
  162. void mmu_disable(void);
  163. #if defined(CONFIG_ARM)
  164. void relocate_code(ulong);
  165. #else
  166. void relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
  167. #endif
  168. ulong get_endaddr (void);
  169. void trap_init (ulong);
  170. /* $(CPU)/cpu.c */
  171. static inline int cpumask_next(int cpu, unsigned int mask)
  172. {
  173. for (cpu++; !((1 << cpu) & mask); cpu++)
  174. ;
  175. return cpu;
  176. }
  177. #define for_each_cpu(iter, cpu, num_cpus, mask) \
  178. for (iter = 0, cpu = cpumask_next(-1, mask); \
  179. iter < num_cpus; \
  180. iter++, cpu = cpumask_next(cpu, mask)) \
  181. int cpu_numcores (void);
  182. int cpu_num_dspcores(void);
  183. u32 cpu_mask (void);
  184. u32 cpu_dsp_mask(void);
  185. int is_core_valid (unsigned int);
  186. void s_init(void);
  187. int checkcpu (void);
  188. int checkicache (void);
  189. int checkdcache (void);
  190. void upmconfig (unsigned int, unsigned int *, unsigned int);
  191. ulong get_tbclk (void);
  192. void reset_misc (void);
  193. void reset_cpu (ulong addr);
  194. void ft_cpu_setup(void *blob, bd_t *bd);
  195. void ft_pci_setup(void *blob, bd_t *bd);
  196. void smp_set_core_boot_addr(unsigned long addr, int corenr);
  197. void smp_kick_all_cpus(void);
  198. /* $(CPU)/serial.c */
  199. int serial_init (void);
  200. void serial_setbrg (void);
  201. void serial_putc (const char);
  202. void serial_putc_raw(const char);
  203. void serial_puts (const char *);
  204. int serial_getc (void);
  205. int serial_tstc (void);
  206. /* $(CPU)/speed.c */
  207. int get_clocks (void);
  208. ulong get_bus_freq (ulong);
  209. int get_serial_clock(void);
  210. /* $(CPU)/interrupts.c */
  211. int interrupt_init (void);
  212. void timer_interrupt (struct pt_regs *);
  213. void external_interrupt (struct pt_regs *);
  214. void irq_install_handler(int, interrupt_handler_t *, void *);
  215. void irq_free_handler (int);
  216. void reset_timer (void);
  217. /* Return value of monotonic microsecond timer */
  218. unsigned long timer_get_us(void);
  219. void enable_interrupts (void);
  220. int disable_interrupts (void);
  221. /* $(CPU)/.../commproc.c */
  222. void bootcount_store (ulong);
  223. ulong bootcount_load (void);
  224. /* $(CPU)/.../<eth> */
  225. void mii_init (void);
  226. /* arch/$(ARCH)/lib/cache.c */
  227. void enable_caches(void);
  228. void flush_cache (unsigned long, unsigned long);
  229. void flush_dcache_all(void);
  230. void flush_dcache_range(unsigned long start, unsigned long stop);
  231. void invalidate_dcache_range(unsigned long start, unsigned long stop);
  232. void invalidate_dcache_all(void);
  233. void invalidate_icache_all(void);
  234. enum {
  235. /* Disable caches (else flush caches but leave them active) */
  236. CBL_DISABLE_CACHES = 1 << 0,
  237. CBL_SHOW_BOOTSTAGE_REPORT = 1 << 1,
  238. CBL_ALL = 3,
  239. };
  240. /**
  241. * Clean up ready for linux
  242. *
  243. * @param flags Flags to control what is done
  244. */
  245. int cleanup_before_linux_select(int flags);
  246. /* arch/$(ARCH)/lib/ticks.S */
  247. uint64_t get_ticks(void);
  248. void wait_ticks (unsigned long);
  249. /* arch/$(ARCH)/lib/time.c */
  250. ulong usec2ticks (unsigned long usec);
  251. ulong ticks2usec (unsigned long ticks);
  252. /* lib/lz4_wrapper.c */
  253. int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
  254. /* lib/qsort.c */
  255. void qsort(void *base, size_t nmemb, size_t size,
  256. int(*compar)(const void *, const void *));
  257. int strcmp_compar(const void *, const void *);
  258. /* lib/uuid.c */
  259. #include <uuid.h>
  260. /* lib/vsprintf.c */
  261. #include <vsprintf.h>
  262. /* lib/strmhz.c */
  263. char * strmhz(char *buf, unsigned long hz);
  264. /*
  265. * STDIO based functions (can always be used)
  266. */
  267. /* serial stuff */
  268. int serial_printf (const char *fmt, ...)
  269. __attribute__ ((format (__printf__, 1, 2)));
  270. /* lib/net_utils.c */
  271. #include <net.h>
  272. static inline struct in_addr env_get_ip(char *var)
  273. {
  274. return string_to_ip(env_get(var));
  275. }
  276. #include <bootstage.h>
  277. #else /* __ASSEMBLY__ */
  278. #endif /* __ASSEMBLY__ */
  279. /* Put only stuff here that the assembler can digest */
  280. #ifdef CONFIG_POST
  281. #define CONFIG_HAS_POST
  282. #ifndef CONFIG_POST_ALT_LIST
  283. #define CONFIG_POST_STD_LIST
  284. #endif
  285. #endif
  286. #define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1))
  287. /*
  288. * check_member() - Check the offset of a structure member
  289. *
  290. * @structure: Name of structure (e.g. global_data)
  291. * @member: Name of member (e.g. baudrate)
  292. * @offset: Expected offset in bytes
  293. */
  294. #define check_member(structure, member, offset) _Static_assert( \
  295. offsetof(struct structure, member) == offset, \
  296. "`struct " #structure "` offset for `" #member "` is not " #offset)
  297. /* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */
  298. #ifdef CONFIG_EFI_STUB
  299. #define ll_boot_init() false
  300. #else
  301. #define ll_boot_init() true
  302. #endif
  303. /* Pull in stuff for the build system */
  304. #ifdef DO_DEPS_ONLY
  305. # include <env_internal.h>
  306. #endif
  307. #endif /* __COMMON_H_ */