common.h 28 KB

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