common.h 26 KB

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