common.h 26 KB

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