common.h 27 KB

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