common.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. /*
  2. * (C) Copyright 2000-2009
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #ifndef __COMMON_H_
  8. #define __COMMON_H_ 1
  9. #ifndef __ASSEMBLY__ /* put C only stuff in this section */
  10. typedef unsigned char uchar;
  11. typedef volatile unsigned long vu_long;
  12. typedef volatile unsigned short vu_short;
  13. typedef volatile unsigned char vu_char;
  14. /* Allow sharing constants with type modifiers between C and assembly. */
  15. #define _AC(X, Y) (X##Y)
  16. #include <config.h>
  17. #include <errno.h>
  18. #include <time.h>
  19. #include <asm-offsets.h>
  20. #include <linux/bitops.h>
  21. #include <linux/delay.h>
  22. #include <linux/types.h>
  23. #include <linux/string.h>
  24. #include <linux/stringify.h>
  25. #include <asm/ptrace.h>
  26. #include <stdarg.h>
  27. #include <linux/kernel.h>
  28. #ifdef CONFIG_SOC_DA8XX
  29. #include <asm/arch/hardware.h>
  30. #endif
  31. #ifdef CONFIG_FSL_LSCH3
  32. #include <asm/arch/immap_lsch3.h>
  33. #endif
  34. #ifdef CONFIG_FSL_LSCH2
  35. #include <asm/arch/immap_lsch2.h>
  36. #endif
  37. #include <part.h>
  38. #include <flash.h>
  39. #include <image.h>
  40. /* Bring in printf format macros if inttypes.h is included */
  41. #define __STDC_FORMAT_MACROS
  42. #ifdef __LP64__
  43. #define CONFIG_SYS_SUPPORT_64BIT_DATA
  44. #endif
  45. #ifdef DEBUG
  46. #define _DEBUG 1
  47. #else
  48. #define _DEBUG 0
  49. #endif
  50. #ifdef CONFIG_SPL_BUILD
  51. #define _SPL_BUILD 1
  52. #else
  53. #define _SPL_BUILD 0
  54. #endif
  55. /* Define this at the top of a file to add a prefix to debug messages */
  56. #ifndef pr_fmt
  57. #define pr_fmt(fmt) fmt
  58. #endif
  59. /*
  60. * Output a debug text when condition "cond" is met. The "cond" should be
  61. * computed by a preprocessor in the best case, allowing for the best
  62. * optimization.
  63. */
  64. #define debug_cond(cond, fmt, args...) \
  65. do { \
  66. if (cond) \
  67. printf(pr_fmt(fmt), ##args); \
  68. } while (0)
  69. /* Show a message if DEBUG is defined in a file */
  70. #define debug(fmt, args...) \
  71. debug_cond(_DEBUG, fmt, ##args)
  72. /* Show a message if not in SPL */
  73. #define warn_non_spl(fmt, args...) \
  74. debug_cond(!_SPL_BUILD, fmt, ##args)
  75. /*
  76. * An assertion is run-time check done in debug mode only. If DEBUG is not
  77. * defined then it is skipped. If DEBUG is defined and the assertion fails,
  78. * then it calls panic*( which may or may not reset/halt U-Boot (see
  79. * CONFIG_PANIC_HANG), It is hoped that all failing assertions are found
  80. * before release, and after release it is hoped that they don't matter. But
  81. * in any case these failing assertions cannot be fixed with a reset (which
  82. * may just do the same assertion again).
  83. */
  84. void __assert_fail(const char *assertion, const char *file, unsigned line,
  85. const char *function);
  86. #define assert(x) \
  87. ({ if (!(x) && _DEBUG) \
  88. __assert_fail(#x, __FILE__, __LINE__, __func__); })
  89. #define error(fmt, args...) do { \
  90. printf("ERROR: " pr_fmt(fmt) "\nat %s:%d/%s()\n", \
  91. ##args, __FILE__, __LINE__, __func__); \
  92. } while (0)
  93. #ifndef BUG
  94. #define BUG() do { \
  95. printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
  96. panic("BUG!"); \
  97. } while (0)
  98. #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
  99. #endif /* BUG */
  100. typedef void (interrupt_handler_t)(void *);
  101. #include <asm/u-boot.h> /* boot information for Linux kernel */
  102. #include <asm/global_data.h> /* global data used for startup functions */
  103. /*
  104. * enable common handling for all TQM8xxL/M boards:
  105. * - CONFIG_TQM8xxM will be defined for all TQM8xxM boards
  106. * - CONFIG_TQM8xxL will be defined for all TQM8xxL _and_ TQM8xxM boards
  107. * and for the TQM885D board
  108. */
  109. #if defined(CONFIG_TQM823M) || defined(CONFIG_TQM850M) || \
  110. defined(CONFIG_TQM855M) || defined(CONFIG_TQM860M) || \
  111. defined(CONFIG_TQM862M) || defined(CONFIG_TQM866M)
  112. # ifndef CONFIG_TQM8xxM
  113. # define CONFIG_TQM8xxM
  114. # endif
  115. #endif
  116. #if defined(CONFIG_TQM823L) || defined(CONFIG_TQM850L) || \
  117. defined(CONFIG_TQM855L) || defined(CONFIG_TQM860L) || \
  118. defined(CONFIG_TQM862L) || defined(CONFIG_TQM8xxM) || \
  119. defined(CONFIG_TQM885D)
  120. # ifndef CONFIG_TQM8xxL
  121. # define CONFIG_TQM8xxL
  122. # endif
  123. #endif
  124. #if defined(CONFIG_ENV_IS_EMBEDDED)
  125. #define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
  126. #elif ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \
  127. (CONFIG_ENV_ADDR >= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)) ) || \
  128. defined(CONFIG_ENV_IS_IN_NVRAM)
  129. #define TOTAL_MALLOC_LEN (CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
  130. #else
  131. #define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
  132. #endif
  133. /*
  134. * Function Prototypes
  135. */
  136. int dram_init(void);
  137. /**
  138. * dram_init_banksize() - Set up DRAM bank sizes
  139. *
  140. * This can be implemented by boards to set up the DRAM bank information in
  141. * gd->bd->bi_dram(). It is called just before relocation, after dram_init()
  142. * is called.
  143. *
  144. * If this is not provided, a default implementation will try to set up a
  145. * single bank. It will do this if CONFIG_NR_DRAM_BANKS and
  146. * CONFIG_SYS_SDRAM_BASE are set. The bank will have a start address of
  147. * CONFIG_SYS_SDRAM_BASE and the size will be determined by a call to
  148. * get_effective_memsize().
  149. *
  150. * @return 0 if OK, -ve on error
  151. */
  152. int dram_init_banksize(void);
  153. void hang (void) __attribute__ ((noreturn));
  154. int timer_init(void);
  155. int cpu_init(void);
  156. #include <display_options.h>
  157. /* common/main.c */
  158. void main_loop (void);
  159. int run_command(const char *cmd, int flag);
  160. int run_command_repeatable(const char *cmd, int flag);
  161. /**
  162. * Run a list of commands separated by ; or even \0
  163. *
  164. * Note that if 'len' is not -1, then the command does not need to be nul
  165. * terminated, Memory will be allocated for the command in that case.
  166. *
  167. * @param cmd List of commands to run, each separated bu semicolon
  168. * @param len Length of commands excluding terminator if known (-1 if not)
  169. * @param flag Execution flags (CMD_FLAG_...)
  170. * @return 0 on success, or != 0 on error.
  171. */
  172. int run_command_list(const char *cmd, int len, int flag);
  173. /* arch/$(ARCH)/lib/board.c */
  174. void board_init_f(ulong);
  175. void board_init_r(gd_t *, ulong) __attribute__ ((noreturn));
  176. /**
  177. * ulong board_init_f_alloc_reserve - allocate reserved area
  178. *
  179. * This function is called by each architecture very early in the start-up
  180. * code to allow the C runtime to reserve space on the stack for writable
  181. * 'globals' such as GD and the malloc arena.
  182. *
  183. * @top: top of the reserve area, growing down.
  184. * @return: bottom of reserved area
  185. */
  186. ulong board_init_f_alloc_reserve(ulong top);
  187. /**
  188. * board_init_f_init_reserve - initialize the reserved area(s)
  189. *
  190. * This function is called once the C runtime has allocated the reserved
  191. * area on the stack. It must initialize the GD at the base of that area.
  192. *
  193. * @base: top from which reservation was done
  194. */
  195. void board_init_f_init_reserve(ulong base);
  196. /**
  197. * arch_setup_gd() - Set up the global_data pointer
  198. *
  199. * This pointer is special in some architectures and cannot easily be assigned
  200. * to. For example on x86 it is implemented by adding a specific record to its
  201. * Global Descriptor Table! So we we provide a function to carry out this task.
  202. * For most architectures this can simply be:
  203. *
  204. * gd = gd_ptr;
  205. *
  206. * @gd_ptr: Pointer to global data
  207. */
  208. void arch_setup_gd(gd_t *gd_ptr);
  209. int checkboard(void);
  210. int show_board_info(void);
  211. int checkflash(void);
  212. int checkdram(void);
  213. int last_stage_init(void);
  214. extern ulong monitor_flash_len;
  215. int mac_read_from_eeprom(void);
  216. extern u8 __dtb_dt_begin[]; /* embedded device tree blob */
  217. int set_cpu_clk_info(void);
  218. int mdm_init(void);
  219. int print_cpuinfo(void);
  220. int update_flash_size(int flash_size);
  221. int arch_early_init_r(void);
  222. /*
  223. * setup_board_extra() - Fill in extra details in the bd_t structure
  224. *
  225. * @return 0 if OK, -ve on error
  226. */
  227. int setup_board_extra(void);
  228. /**
  229. * arch_fsp_init() - perform firmware support package init
  230. *
  231. * Where U-Boot relies on binary blobs to handle part of the system init, this
  232. * function can be used to set up the blobs. This is used on some Intel
  233. * platforms.
  234. */
  235. int arch_fsp_init(void);
  236. /**
  237. * arch_cpu_init_dm() - init CPU after driver model is available
  238. *
  239. * This is called immediately after driver model is available before
  240. * relocation. This is similar to arch_cpu_init() but is able to reference
  241. * devices
  242. *
  243. * @return 0 if OK, -ve on error
  244. */
  245. int arch_cpu_init_dm(void);
  246. /**
  247. * Reserve all necessary stacks
  248. *
  249. * This is used in generic board init sequence in common/board_f.c. Each
  250. * architecture could provide this function to tailor the required stacks.
  251. *
  252. * On entry gd->start_addr_sp is pointing to the suggested top of the stack.
  253. * The callee ensures gd->start_add_sp is 16-byte aligned, so architectures
  254. * require only this can leave it untouched.
  255. *
  256. * On exit gd->start_addr_sp and gd->irq_sp should be set to the respective
  257. * positions of the stack. The stack pointer(s) will be set to this later.
  258. * gd->irq_sp is only required, if the architecture needs it.
  259. *
  260. * @return 0 if no error
  261. */
  262. __weak int arch_reserve_stacks(void);
  263. /**
  264. * Show the DRAM size in a board-specific way
  265. *
  266. * This is used by boards to display DRAM information in their own way.
  267. *
  268. * @param size Size of DRAM (which should be displayed along with other info)
  269. */
  270. void board_show_dram(phys_size_t size);
  271. /**
  272. * arch_fixup_fdt() - Write arch-specific information to fdt
  273. *
  274. * Defined in arch/$(ARCH)/lib/bootm-fdt.c
  275. *
  276. * @blob: FDT blob to write to
  277. * @return 0 if ok, or -ve FDT_ERR_... on failure
  278. */
  279. int arch_fixup_fdt(void *blob);
  280. /* common/flash.c */
  281. void flash_perror (int);
  282. /* common/cmd_source.c */
  283. int source (ulong addr, const char *fit_uname);
  284. extern ulong load_addr; /* Default Load Address */
  285. extern ulong save_addr; /* Default Save Address */
  286. extern ulong save_size; /* Default Save Size */
  287. /* common/cmd_net.c */
  288. int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  289. /* common/cmd_fat.c */
  290. int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
  291. /* common/cmd_ext2.c */
  292. int do_ext2load(cmd_tbl_t *, int, int, char * const []);
  293. /* common/cmd_nvedit.c */
  294. int env_init (void);
  295. void env_relocate (void);
  296. int envmatch (uchar *, int);
  297. /* Avoid unfortunate conflict with libc's getenv() */
  298. #ifdef CONFIG_SANDBOX
  299. #define getenv uboot_getenv
  300. #endif
  301. char *getenv (const char *);
  302. int getenv_f (const char *name, char *buf, unsigned len);
  303. ulong getenv_ulong(const char *name, int base, ulong default_val);
  304. /**
  305. * getenv_hex() - Return an environment variable as a hex value
  306. *
  307. * Decode an environment as a hex number (it may or may not have a 0x
  308. * prefix). If the environment variable cannot be found, or does not start
  309. * with hex digits, the default value is returned.
  310. *
  311. * @varname: Variable to decode
  312. * @default_val: Value to return on error
  313. */
  314. ulong getenv_hex(const char *varname, ulong default_val);
  315. /*
  316. * Read an environment variable as a boolean
  317. * Return -1 if variable does not exist (default to true)
  318. */
  319. int getenv_yesno(const char *var);
  320. int saveenv (void);
  321. int setenv (const char *, const char *);
  322. int setenv_ulong(const char *varname, ulong value);
  323. int setenv_hex(const char *varname, ulong value);
  324. /**
  325. * setenv_addr - Set an environment variable to an address in hex
  326. *
  327. * @varname: Environment variable to set
  328. * @addr: Value to set it to
  329. * @return 0 if ok, 1 on error
  330. */
  331. static inline int setenv_addr(const char *varname, const void *addr)
  332. {
  333. return setenv_hex(varname, (ulong)addr);
  334. }
  335. #ifdef CONFIG_AUTO_COMPLETE
  336. int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf);
  337. #endif
  338. int get_env_id (void);
  339. void pci_init (void);
  340. void pci_init_board(void);
  341. int misc_init_f (void);
  342. int misc_init_r (void);
  343. /* common/exports.c */
  344. void jumptable_init(void);
  345. /* common/kallsysm.c */
  346. const char *symbol_lookup(unsigned long addr, unsigned long *caddr);
  347. /* common/memsize.c */
  348. long get_ram_size (long *, long);
  349. phys_size_t get_effective_memsize(void);
  350. /* $(BOARD)/$(BOARD).c */
  351. void reset_phy (void);
  352. void fdc_hw_init (void);
  353. /* $(BOARD)/eeprom.c */
  354. #ifdef CONFIG_CMD_EEPROM
  355. void eeprom_init (int bus);
  356. int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  357. int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  358. #else
  359. /*
  360. * Some EEPROM code is depecated because it used the legacy I2C interface. Add
  361. * some macros here so we don't have to touch every one of those uses
  362. */
  363. #define eeprom_init(bus)
  364. #define eeprom_read(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
  365. #define eeprom_write(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
  366. #endif
  367. /*
  368. * Set this up regardless of board
  369. * type, to prevent errors.
  370. */
  371. #if defined(CONFIG_SPI) || !defined(CONFIG_SYS_I2C_EEPROM_ADDR)
  372. # define CONFIG_SYS_DEF_EEPROM_ADDR 0
  373. #else
  374. #if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
  375. # define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR
  376. #endif
  377. #endif /* CONFIG_SPI || !defined(CONFIG_SYS_I2C_EEPROM_ADDR) */
  378. #if defined(CONFIG_SPI)
  379. extern void spi_init_f (void);
  380. extern void spi_init_r (void);
  381. extern ssize_t spi_read (uchar *, int, uchar *, int);
  382. extern ssize_t spi_write (uchar *, int, uchar *, int);
  383. #endif
  384. /* $(BOARD)/$(BOARD).c */
  385. int board_early_init_f (void);
  386. int board_fix_fdt (void *rw_fdt_blob); /* manipulate the U-Boot fdt before its relocation */
  387. int board_late_init (void);
  388. int board_postclk_init (void); /* after clocks/timebase, before env/serial */
  389. int board_early_init_r (void);
  390. void board_poweroff (void);
  391. #if defined(CONFIG_SYS_DRAM_TEST)
  392. int testdram(void);
  393. #endif /* CONFIG_SYS_DRAM_TEST */
  394. /* $(CPU)/start.S */
  395. #if defined(CONFIG_5xx) || \
  396. defined(CONFIG_8xx)
  397. uint get_immr (uint);
  398. #endif
  399. #if defined(CONFIG_MPC5xxx)
  400. uint get_svr (void);
  401. #endif
  402. uint get_pvr (void);
  403. uint get_svr (void);
  404. uint rd_ic_cst (void);
  405. void wr_ic_cst (uint);
  406. void wr_ic_adr (uint);
  407. uint rd_dc_cst (void);
  408. void wr_dc_cst (uint);
  409. void wr_dc_adr (uint);
  410. int icache_status (void);
  411. void icache_enable (void);
  412. void icache_disable(void);
  413. int dcache_status (void);
  414. void dcache_enable (void);
  415. void dcache_disable(void);
  416. void mmu_disable(void);
  417. #if defined(CONFIG_ARM)
  418. void relocate_code(ulong);
  419. #else
  420. void relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
  421. #endif
  422. ulong get_endaddr (void);
  423. void trap_init (ulong);
  424. #if defined (CONFIG_4xx) || \
  425. defined (CONFIG_MPC5xxx) || \
  426. defined (CONFIG_MPC85xx) || \
  427. defined (CONFIG_MPC86xx) || \
  428. defined (CONFIG_MPC83xx)
  429. unsigned char in8(unsigned int);
  430. void out8(unsigned int, unsigned char);
  431. unsigned short in16(unsigned int);
  432. unsigned short in16r(unsigned int);
  433. void out16(unsigned int, unsigned short value);
  434. void out16r(unsigned int, unsigned short value);
  435. unsigned long in32(unsigned int);
  436. unsigned long in32r(unsigned int);
  437. void out32(unsigned int, unsigned long value);
  438. void out32r(unsigned int, unsigned long value);
  439. void ppcDcbf(unsigned long value);
  440. void ppcDcbi(unsigned long value);
  441. void ppcSync(void);
  442. void ppcDcbz(unsigned long value);
  443. #endif
  444. #if defined (CONFIG_MICROBLAZE)
  445. unsigned short in16(unsigned int);
  446. void out16(unsigned int, unsigned short value);
  447. #endif
  448. #if defined (CONFIG_MPC83xx)
  449. void ppcDWload(unsigned int *addr, unsigned int *ret);
  450. void ppcDWstore(unsigned int *addr, unsigned int *value);
  451. void disable_addr_trans(void);
  452. void enable_addr_trans(void);
  453. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  454. void ddr_enable_ecc(unsigned int dram_size);
  455. #endif
  456. #endif
  457. /* $(CPU)/cpu.c */
  458. static inline int cpumask_next(int cpu, unsigned int mask)
  459. {
  460. for (cpu++; !((1 << cpu) & mask); cpu++)
  461. ;
  462. return cpu;
  463. }
  464. #define for_each_cpu(iter, cpu, num_cpus, mask) \
  465. for (iter = 0, cpu = cpumask_next(-1, mask); \
  466. iter < num_cpus; \
  467. iter++, cpu = cpumask_next(cpu, mask)) \
  468. int cpu_numcores (void);
  469. int cpu_num_dspcores(void);
  470. u32 cpu_mask (void);
  471. u32 cpu_dsp_mask(void);
  472. int is_core_valid (unsigned int);
  473. /**
  474. * arch_cpu_init() - basic cpu-dependent setup for an architecture
  475. *
  476. * This is called after early malloc is available. It should handle any
  477. * CPU- or SoC- specific init needed to continue the init sequence. See
  478. * board_f.c for where it is called. If this is not provided, a default
  479. * version (which does nothing) will be used.
  480. */
  481. int arch_cpu_init(void);
  482. int checkcpu (void);
  483. int checkicache (void);
  484. int checkdcache (void);
  485. void upmconfig (unsigned int, unsigned int *, unsigned int);
  486. ulong get_tbclk (void);
  487. void reset_misc (void);
  488. void reset_cpu (ulong addr);
  489. void ft_cpu_setup(void *blob, bd_t *bd);
  490. void ft_pci_setup(void *blob, bd_t *bd);
  491. void smp_set_core_boot_addr(unsigned long addr, int corenr);
  492. void smp_kick_all_cpus(void);
  493. /* $(CPU)/serial.c */
  494. int serial_init (void);
  495. void serial_setbrg (void);
  496. void serial_putc (const char);
  497. void serial_putc_raw(const char);
  498. void serial_puts (const char *);
  499. int serial_getc (void);
  500. int serial_tstc (void);
  501. /* These versions take a stdio_dev pointer */
  502. struct stdio_dev;
  503. int serial_stub_getc(struct stdio_dev *sdev);
  504. int serial_stub_tstc(struct stdio_dev *sdev);
  505. /* $(CPU)/speed.c */
  506. int get_clocks (void);
  507. #if defined(CONFIG_MPC5xxx)
  508. int prt_mpc5xxx_clks (void);
  509. #endif
  510. #if defined(CONFIG_LH7A40X) || \
  511. defined(CONFIG_EP93XX)
  512. ulong get_FCLK (void);
  513. ulong get_HCLK (void);
  514. ulong get_PCLK (void);
  515. ulong get_UCLK (void);
  516. #endif
  517. #if defined(CONFIG_LH7A40X)
  518. ulong get_PLLCLK (void);
  519. #endif
  520. #if defined(CONFIG_IMX)
  521. ulong get_systemPLLCLK(void);
  522. ulong get_FCLK(void);
  523. ulong get_HCLK(void);
  524. ulong get_BCLK(void);
  525. ulong get_PERCLK1(void);
  526. ulong get_PERCLK2(void);
  527. ulong get_PERCLK3(void);
  528. #endif
  529. ulong get_bus_freq (ulong);
  530. int get_serial_clock(void);
  531. #if defined(CONFIG_MPC85xx)
  532. typedef MPC85xx_SYS_INFO sys_info_t;
  533. void get_sys_info ( sys_info_t * );
  534. void ft_fixup_cpu(void *, u64);
  535. void ft_fixup_num_cores(void *);
  536. #endif
  537. #if defined(CONFIG_MPC86xx)
  538. typedef MPC86xx_SYS_INFO sys_info_t;
  539. void get_sys_info ( sys_info_t * );
  540. static inline ulong get_ddr_freq(ulong dummy)
  541. {
  542. return get_bus_freq(dummy);
  543. }
  544. #else
  545. ulong get_ddr_freq(ulong);
  546. #endif
  547. int cpu_init_r (void);
  548. /* $(CPU)/interrupts.c */
  549. int interrupt_init (void);
  550. void timer_interrupt (struct pt_regs *);
  551. void external_interrupt (struct pt_regs *);
  552. void irq_install_handler(int, interrupt_handler_t *, void *);
  553. void irq_free_handler (int);
  554. void reset_timer (void);
  555. /* Return value of monotonic microsecond timer */
  556. unsigned long timer_get_us(void);
  557. void enable_interrupts (void);
  558. int disable_interrupts (void);
  559. /* $(CPU)/.../commproc.c */
  560. int dpram_init (void);
  561. uint dpram_base(void);
  562. uint dpram_base_align(uint align);
  563. uint dpram_alloc(uint size);
  564. uint dpram_alloc_align(uint size,uint align);
  565. void bootcount_store (ulong);
  566. ulong bootcount_load (void);
  567. #define BOOTCOUNT_MAGIC 0xB001C041
  568. /* $(CPU)/.../<eth> */
  569. void mii_init (void);
  570. /* $(CPU)/.../lcd.c */
  571. ulong lcd_setmem (ulong);
  572. /* $(CPU)/.../video.c */
  573. ulong video_setmem (ulong);
  574. /* arch/$(ARCH)/lib/cache.c */
  575. void enable_caches(void);
  576. void flush_cache (unsigned long, unsigned long);
  577. void flush_dcache_all(void);
  578. void flush_dcache_range(unsigned long start, unsigned long stop);
  579. void invalidate_dcache_range(unsigned long start, unsigned long stop);
  580. void invalidate_dcache_all(void);
  581. void invalidate_icache_all(void);
  582. enum {
  583. /* Disable caches (else flush caches but leave them active) */
  584. CBL_DISABLE_CACHES = 1 << 0,
  585. CBL_SHOW_BOOTSTAGE_REPORT = 1 << 1,
  586. CBL_ALL = 3,
  587. };
  588. /**
  589. * Clean up ready for linux
  590. *
  591. * @param flags Flags to control what is done
  592. */
  593. int cleanup_before_linux_select(int flags);
  594. /* arch/$(ARCH)/lib/ticks.S */
  595. uint64_t get_ticks(void);
  596. void wait_ticks (unsigned long);
  597. /* arch/$(ARCH)/lib/time.c */
  598. ulong usec2ticks (unsigned long usec);
  599. ulong ticks2usec (unsigned long ticks);
  600. /* lib/gunzip.c */
  601. int gunzip(void *, int, unsigned char *, unsigned long *);
  602. int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
  603. int stoponerr, int offset);
  604. /**
  605. * gzwrite progress indicators: defined weak to allow board-specific
  606. * overrides:
  607. *
  608. * gzwrite_progress_init called on startup
  609. * gzwrite_progress called during decompress/write loop
  610. * gzwrite_progress_finish called at end of loop to
  611. * indicate success (retcode=0) or failure
  612. */
  613. void gzwrite_progress_init(u64 expected_size);
  614. void gzwrite_progress(int iteration,
  615. u64 bytes_written,
  616. u64 total_bytes);
  617. void gzwrite_progress_finish(int retcode,
  618. u64 totalwritten,
  619. u64 totalsize,
  620. u32 expected_crc,
  621. u32 calculated_crc);
  622. /**
  623. * decompress and write gzipped image from memory to block device
  624. *
  625. * @param src compressed image address
  626. * @param len compressed image length in bytes
  627. * @param dev block device descriptor
  628. * @param szwritebuf bytes per write (pad to erase size)
  629. * @param startoffs offset in bytes of first write
  630. * @param szexpected expected uncompressed length
  631. * may be zero to use gzip trailer
  632. * for files under 4GiB
  633. */
  634. int gzwrite(unsigned char *src, int len,
  635. struct blk_desc *dev,
  636. unsigned long szwritebuf,
  637. u64 startoffs,
  638. u64 szexpected);
  639. /* lib/lz4_wrapper.c */
  640. int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
  641. /* lib/qsort.c */
  642. void qsort(void *base, size_t nmemb, size_t size,
  643. int(*compar)(const void *, const void *));
  644. int strcmp_compar(const void *, const void *);
  645. /* lib/uuid.c */
  646. #include <uuid.h>
  647. /* lib/vsprintf.c */
  648. #include <vsprintf.h>
  649. /* lib/strmhz.c */
  650. char * strmhz(char *buf, unsigned long hz);
  651. /* lib/crc32.c */
  652. #include <u-boot/crc.h>
  653. /* lib/rand.c */
  654. #define RAND_MAX -1U
  655. void srand(unsigned int seed);
  656. unsigned int rand(void);
  657. unsigned int rand_r(unsigned int *seedp);
  658. /*
  659. * STDIO based functions (can always be used)
  660. */
  661. /* serial stuff */
  662. int serial_printf (const char *fmt, ...)
  663. __attribute__ ((format (__printf__, 1, 2)));
  664. /* stdin */
  665. int getc(void);
  666. int tstc(void);
  667. /* stdout */
  668. #if !defined(CONFIG_SPL_BUILD) || \
  669. (defined(CONFIG_TPL_BUILD) && defined(CONFIG_TPL_SERIAL_SUPPORT)) || \
  670. (defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) && \
  671. defined(CONFIG_SPL_SERIAL_SUPPORT))
  672. void putc(const char c);
  673. void puts(const char *s);
  674. int printf(const char *fmt, ...)
  675. __attribute__ ((format (__printf__, 1, 2)));
  676. int vprintf(const char *fmt, va_list args);
  677. #else
  678. #define putc(...) do { } while (0)
  679. #define puts(...) do { } while (0)
  680. #define printf(...) do { } while (0)
  681. #define vprintf(...) do { } while (0)
  682. #endif
  683. /* stderr */
  684. #define eputc(c) fputc(stderr, c)
  685. #define eputs(s) fputs(stderr, s)
  686. #define eprintf(fmt,args...) fprintf(stderr,fmt ,##args)
  687. /*
  688. * FILE based functions (can only be used AFTER relocation!)
  689. */
  690. #define stdin 0
  691. #define stdout 1
  692. #define stderr 2
  693. #define MAX_FILES 3
  694. int fprintf(int file, const char *fmt, ...)
  695. __attribute__ ((format (__printf__, 2, 3)));
  696. void fputs(int file, const char *s);
  697. void fputc(int file, const char c);
  698. int ftstc(int file);
  699. int fgetc(int file);
  700. /* lib/gzip.c */
  701. int gzip(void *dst, unsigned long *lenp,
  702. unsigned char *src, unsigned long srclen);
  703. int zzip(void *dst, unsigned long *lenp, unsigned char *src,
  704. unsigned long srclen, int stoponerr,
  705. int (*func)(unsigned long, unsigned long));
  706. /* lib/net_utils.c */
  707. #include <net.h>
  708. static inline struct in_addr getenv_ip(char *var)
  709. {
  710. return string_to_ip(getenv(var));
  711. }
  712. int pcmcia_init (void);
  713. #ifdef CONFIG_LED_STATUS
  714. # include <status_led.h>
  715. #endif
  716. #include <bootstage.h>
  717. #ifdef CONFIG_SHOW_ACTIVITY
  718. void show_activity(int arg);
  719. #endif
  720. /* Multicore arch functions */
  721. #ifdef CONFIG_MP
  722. int cpu_status(int nr);
  723. int cpu_reset(int nr);
  724. int cpu_disable(int nr);
  725. int cpu_release(int nr, int argc, char * const argv[]);
  726. #endif
  727. #else /* __ASSEMBLY__ */
  728. /* Drop a C type modifier (like in 3UL) for constants used in assembly. */
  729. #define _AC(X, Y) X
  730. #endif /* __ASSEMBLY__ */
  731. #ifdef CONFIG_PPC
  732. /*
  733. * Has to be included outside of the #ifndef __ASSEMBLY__ section.
  734. * Otherwise might lead to compilation errors in assembler files.
  735. */
  736. #include <asm/cache.h>
  737. #endif
  738. /* Put only stuff here that the assembler can digest */
  739. /* Declare an unsigned long constant digestable both by C and an assembler. */
  740. #define UL(x) _AC(x, UL)
  741. #ifdef CONFIG_POST
  742. #define CONFIG_HAS_POST
  743. #ifndef CONFIG_POST_ALT_LIST
  744. #define CONFIG_POST_STD_LIST
  745. #endif
  746. #endif
  747. #ifdef CONFIG_INIT_CRITICAL
  748. #error CONFIG_INIT_CRITICAL is deprecated!
  749. #error Read section CONFIG_SKIP_LOWLEVEL_INIT in README.
  750. #endif
  751. #define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1))
  752. /*
  753. * check_member() - Check the offset of a structure member
  754. *
  755. * @structure: Name of structure (e.g. global_data)
  756. * @member: Name of member (e.g. baudrate)
  757. * @offset: Expected offset in bytes
  758. */
  759. #define check_member(structure, member, offset) _Static_assert( \
  760. offsetof(struct structure, member) == offset, \
  761. "`struct " #structure "` offset for `" #member "` is not " #offset)
  762. /* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */
  763. #ifdef CONFIG_EFI_STUB
  764. #define ll_boot_init() false
  765. #else
  766. #define ll_boot_init() true
  767. #endif
  768. /* Pull in stuff for the build system */
  769. #ifdef DO_DEPS_ONLY
  770. # include <environment.h>
  771. #endif
  772. #endif /* __COMMON_H_ */