common.h 27 KB

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