common.h 26 KB

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