common.h 9.9 KB

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