xref: /rk3399_rockchip-uboot/include/common.h (revision 9272a9b4f637347267329c7dc48712ea6c31feaa)
1e2211743Swdenk /*
23b74e7ecSWolfgang Denk  * (C) Copyright 2000-2009
3e2211743Swdenk  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4e2211743Swdenk  *
51a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
6e2211743Swdenk  */
7e2211743Swdenk 
8e2211743Swdenk #ifndef __COMMON_H_
9d0b8feefSWolfgang Denk #define __COMMON_H_	1
10e2211743Swdenk 
11fcd3c87eSWolfgang Denk #ifndef __ASSEMBLY__		/* put C only stuff in this section */
12fcd3c87eSWolfgang Denk 
13e2211743Swdenk typedef unsigned char		uchar;
14e2211743Swdenk typedef volatile unsigned long	vu_long;
15e2211743Swdenk typedef volatile unsigned short vu_short;
16e2211743Swdenk typedef volatile unsigned char	vu_char;
17e2211743Swdenk 
18e2211743Swdenk #include <config.h>
1925ddd1fbSWolfgang Denk #include <asm-offsets.h>
20e2211743Swdenk #include <linux/bitops.h>
21e2211743Swdenk #include <linux/types.h>
22e2211743Swdenk #include <linux/string.h>
239aed5080SMarek Vasut #include <linux/stringify.h>
24e2211743Swdenk #include <asm/ptrace.h>
25e2211743Swdenk #include <stdarg.h>
26a821d08dSStefan Roese #if defined(CONFIG_PCI) && defined(CONFIG_4xx)
27e2211743Swdenk #include <pci.h>
28e2211743Swdenk #endif
29180d3f74Swdenk #if defined(CONFIG_8xx)
30e2211743Swdenk #include <asm/8xx_immap.h>
31d4ca31c4Swdenk #if defined(CONFIG_MPC852)	|| defined(CONFIG_MPC852T)	|| \
32d4ca31c4Swdenk     defined(CONFIG_MPC859)	|| defined(CONFIG_MPC859T)	|| \
332535d602Swdenk     defined(CONFIG_MPC859DSL)	|| \
34d4ca31c4Swdenk     defined(CONFIG_MPC866)	|| defined(CONFIG_MPC866T)	|| \
35d4ca31c4Swdenk     defined(CONFIG_MPC866P)
36d0b8feefSWolfgang Denk # define CONFIG_MPC866_FAMILY 1
37180d3f74Swdenk #elif defined(CONFIG_MPC870) \
38180d3f74Swdenk    || defined(CONFIG_MPC875) \
39180d3f74Swdenk    || defined(CONFIG_MPC880) \
40180d3f74Swdenk    || defined(CONFIG_MPC885)
41d0b8feefSWolfgang Denk # define CONFIG_MPC885_FAMILY   1
42180d3f74Swdenk #endif
43180d3f74Swdenk #if   defined(CONFIG_MPC860)	   \
44180d3f74Swdenk    || defined(CONFIG_MPC860T)	   \
451114257cSwdenk    || defined(CONFIG_MPC866_FAMILY) \
461114257cSwdenk    || defined(CONFIG_MPC885_FAMILY)
47d0b8feefSWolfgang Denk # define CONFIG_MPC86x 1
482535d602Swdenk #endif
490db5bca8Swdenk #elif defined(CONFIG_5xx)
500db5bca8Swdenk #include <asm/5xx_immap.h>
517e6bf358Swdenk #elif defined(CONFIG_MPC5xxx)
527e6bf358Swdenk #include <mpc5xxx.h>
538993e54bSRafal Jaworowski #elif defined(CONFIG_MPC512X)
548993e54bSRafal Jaworowski #include <asm/immap_512x.h>
5558dac327SMasahiro Yamada #elif defined(CONFIG_MPC8260)
5604a85b3bSwdenk #if   defined(CONFIG_MPC8247) \
5704a85b3bSwdenk    || defined(CONFIG_MPC8248) \
5804a85b3bSwdenk    || defined(CONFIG_MPC8271) \
5904a85b3bSwdenk    || defined(CONFIG_MPC8272)
60d0b8feefSWolfgang Denk #define CONFIG_MPC8272_FAMILY	1
6104a85b3bSwdenk #endif
62e2211743Swdenk #include <asm/immap_8260.h>
63e2211743Swdenk #endif
64debb7354SJon Loeliger #ifdef CONFIG_MPC86xx
65debb7354SJon Loeliger #include <mpc86xx.h>
66debb7354SJon Loeliger #include <asm/immap_86xx.h>
67debb7354SJon Loeliger #endif
6842d1f039Swdenk #ifdef CONFIG_MPC85xx
6942d1f039Swdenk #include <mpc85xx.h>
7042d1f039Swdenk #include <asm/immap_85xx.h>
7142d1f039Swdenk #endif
720f898604SPeter Tyser #ifdef CONFIG_MPC83xx
73f046ccd1SEran Liberty #include <mpc83xx.h>
74f046ccd1SEran Liberty #include <asm/immap_83xx.h>
75f046ccd1SEran Liberty #endif
76e2211743Swdenk #ifdef	CONFIG_4xx
77b36df561SStefan Roese #include <asm/ppc4xx.h>
78e2211743Swdenk #endif
79e2211743Swdenk #ifdef CONFIG_HYMOD
806dd652faSwdenk #include <board/hymod/hymod.h>
81e2211743Swdenk #endif
82e2211743Swdenk #ifdef CONFIG_ARM
83e2211743Swdenk #define asmlinkage	/* nothing */
84e2211743Swdenk #endif
856cfcce67SMike Frysinger #ifdef CONFIG_BLACKFIN
866cfcce67SMike Frysinger #include <asm/blackfin.h>
876cfcce67SMike Frysinger #endif
882819e136SSekhar Nori #ifdef CONFIG_SOC_DA8XX
892819e136SSekhar Nori #include <asm/arch/hardware.h>
902819e136SSekhar Nori #endif
91e2211743Swdenk 
92e2211743Swdenk #include <part.h>
93e2211743Swdenk #include <flash.h>
94e2211743Swdenk #include <image.h>
95e2211743Swdenk 
964d1fd7f1SYork Sun #ifdef __LP64__
974d1fd7f1SYork Sun #define CONFIG_SYS_SUPPORT_64BIT_DATA
984d1fd7f1SYork Sun #endif
994d1fd7f1SYork Sun 
100e2211743Swdenk #ifdef DEBUG
10121726a7aSSimon Glass #define _DEBUG	1
10221726a7aSSimon Glass #else
10321726a7aSSimon Glass #define _DEBUG	0
10421726a7aSSimon Glass #endif
10521726a7aSSimon Glass 
10621726a7aSSimon Glass /*
10788a85fb9SMarek Vasut  * Output a debug text when condition "cond" is met. The "cond" should be
10888a85fb9SMarek Vasut  * computed by a preprocessor in the best case, allowing for the best
10988a85fb9SMarek Vasut  * optimization.
11088a85fb9SMarek Vasut  */
11188a85fb9SMarek Vasut #define debug_cond(cond, fmt, args...)		\
11288a85fb9SMarek Vasut 	do {					\
11388a85fb9SMarek Vasut 		if (cond)			\
11488a85fb9SMarek Vasut 			printf(fmt, ##args);	\
11588a85fb9SMarek Vasut 	} while (0)
11688a85fb9SMarek Vasut 
11788a85fb9SMarek Vasut #define debug(fmt, args...)			\
11888a85fb9SMarek Vasut 	debug_cond(_DEBUG, fmt, ##args)
11988a85fb9SMarek Vasut 
12088a85fb9SMarek Vasut /*
12121726a7aSSimon Glass  * An assertion is run-time check done in debug mode only. If DEBUG is not
12221726a7aSSimon Glass  * defined then it is skipped. If DEBUG is defined and the assertion fails,
12321726a7aSSimon Glass  * then it calls panic*( which may or may not reset/halt U-Boot (see
12421726a7aSSimon Glass  * CONFIG_PANIC_HANG), It is hoped that all failing assertions are found
12521726a7aSSimon Glass  * before release, and after release it is hoped that they don't matter. But
12621726a7aSSimon Glass  * in any case these failing assertions cannot be fixed with a reset (which
12721726a7aSSimon Glass  * may just do the same assertion again).
12821726a7aSSimon Glass  */
12921726a7aSSimon Glass void __assert_fail(const char *assertion, const char *file, unsigned line,
13021726a7aSSimon Glass 		   const char *function);
13121726a7aSSimon Glass #define assert(x) \
13221726a7aSSimon Glass 	({ if (!(x) && _DEBUG) \
13321726a7aSSimon Glass 		__assert_fail(#x, __FILE__, __LINE__, __func__); })
13421726a7aSSimon Glass 
135594d57d0SMatthias Kaehlcke #define error(fmt, args...) do {					\
136594d57d0SMatthias Kaehlcke 		printf("ERROR: " fmt "\nat %s:%d/%s()\n",		\
137594d57d0SMatthias Kaehlcke 			##args, __FILE__, __LINE__, __func__);		\
138594d57d0SMatthias Kaehlcke } while (0)
139594d57d0SMatthias Kaehlcke 
140cfa460adSWilliam Juul #ifndef BUG
14143835aacSDetlev Zundel #define BUG() do { \
14243835aacSDetlev Zundel 	printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
14343835aacSDetlev Zundel 	panic("BUG!"); \
14443835aacSDetlev Zundel } while (0)
14543835aacSDetlev Zundel #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
146cfa460adSWilliam Juul #endif /* BUG */
14743835aacSDetlev Zundel 
148c00e17c7SHeiko Schocher /* Force a compilation error if condition is true */
149c00e17c7SHeiko Schocher #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
150c00e17c7SHeiko Schocher 
151e2211743Swdenk typedef void (interrupt_handler_t)(void *);
152e2211743Swdenk 
153e2211743Swdenk #include <asm/u-boot.h> /* boot information for Linux kernel */
154e2211743Swdenk #include <asm/global_data.h>	/* global data used for startup functions */
155e2211743Swdenk 
15671f95118Swdenk /*
15771f95118Swdenk  * enable common handling for all TQM8xxL/M boards:
15811d9eec4SMartin Krause  * - CONFIG_TQM8xxM will be defined for all TQM8xxM boards
15971f95118Swdenk  * - CONFIG_TQM8xxL will be defined for all TQM8xxL _and_ TQM8xxM boards
16011d9eec4SMartin Krause  *                  and for the TQM885D board
16171f95118Swdenk  */
16271f95118Swdenk #if defined(CONFIG_TQM823M) || defined(CONFIG_TQM850M) || \
16371f95118Swdenk     defined(CONFIG_TQM855M) || defined(CONFIG_TQM860M) || \
16411d9eec4SMartin Krause     defined(CONFIG_TQM862M) || defined(CONFIG_TQM866M)
16571f95118Swdenk # ifndef CONFIG_TQM8xxM
16671f95118Swdenk #  define CONFIG_TQM8xxM
16771f95118Swdenk # endif
16871f95118Swdenk #endif
169e2211743Swdenk #if defined(CONFIG_TQM823L) || defined(CONFIG_TQM850L) || \
170d126bfbdSwdenk     defined(CONFIG_TQM855L) || defined(CONFIG_TQM860L) || \
17111d9eec4SMartin Krause     defined(CONFIG_TQM862L) || defined(CONFIG_TQM8xxM) || \
17211d9eec4SMartin Krause     defined(CONFIG_TQM885D)
173e2211743Swdenk # ifndef CONFIG_TQM8xxL
174e2211743Swdenk #  define CONFIG_TQM8xxL
175e2211743Swdenk # endif
176e2211743Swdenk #endif
177e2211743Swdenk 
178e2211743Swdenk /*
179c7de829cSwdenk  * General Purpose Utilities
180c7de829cSwdenk  */
181c7de829cSwdenk #define min(X, Y)				\
1821472af34SAaron Williams 	({ typeof(X) __x = (X);			\
1831472af34SAaron Williams 		typeof(Y) __y = (Y);		\
184c7de829cSwdenk 		(__x < __y) ? __x : __y; })
185c7de829cSwdenk 
186c7de829cSwdenk #define max(X, Y)				\
1871472af34SAaron Williams 	({ typeof(X) __x = (X);			\
1881472af34SAaron Williams 		typeof(Y) __y = (Y);		\
189c7de829cSwdenk 		(__x > __y) ? __x : __y; })
190c7de829cSwdenk 
19120d04774SAndy Fleming #define MIN(x, y)  min(x, y)
19220d04774SAndy Fleming #define MAX(x, y)  max(x, y)
1934f4eab4dSVivek Gautam 
1944f4eab4dSVivek Gautam #define min3(X, Y, Z)				\
1954f4eab4dSVivek Gautam 	({ typeof(X) __x = (X);			\
1964f4eab4dSVivek Gautam 		typeof(Y) __y = (Y);		\
1974f4eab4dSVivek Gautam 		typeof(Z) __z = (Z);		\
1984f4eab4dSVivek Gautam 		__x < __y ? (__x < __z ? __x : __z) :	\
1994f4eab4dSVivek Gautam 		(__y < __z ? __y : __z); })
2004f4eab4dSVivek Gautam 
2014f4eab4dSVivek Gautam #define max3(X, Y, Z)				\
2024f4eab4dSVivek Gautam 	({ typeof(X) __x = (X);			\
2034f4eab4dSVivek Gautam 		typeof(Y) __y = (Y);		\
2044f4eab4dSVivek Gautam 		typeof(Z) __z = (Z);		\
2054f4eab4dSVivek Gautam 		__x > __y ? (__x > __z ? __x : __z) :	\
2064f4eab4dSVivek Gautam 		(__y > __z ? __y : __z); })
2074f4eab4dSVivek Gautam 
2084f4eab4dSVivek Gautam #define MIN3(x, y, z)  min3(x, y, z)
2094f4eab4dSVivek Gautam #define MAX3(x, y, z)  max3(x, y, z)
21020d04774SAndy Fleming 
211a35925b8SSimon Glass /*
212a35925b8SSimon Glass  * Return the absolute value of a number.
213a35925b8SSimon Glass  *
214a35925b8SSimon Glass  * This handles unsigned and signed longs, ints, shorts and chars.  For all
215a35925b8SSimon Glass  * input types abs() returns a signed long.
216a35925b8SSimon Glass  *
217a35925b8SSimon Glass  * For 64-bit types, use abs64()
218a35925b8SSimon Glass  */
219a35925b8SSimon Glass #define abs(x) ({						\
220a35925b8SSimon Glass 		long ret;					\
221a35925b8SSimon Glass 		if (sizeof(x) == sizeof(long)) {		\
222a35925b8SSimon Glass 			long __x = (x);				\
223a35925b8SSimon Glass 			ret = (__x < 0) ? -__x : __x;		\
224a35925b8SSimon Glass 		} else {					\
225a35925b8SSimon Glass 			int __x = (x);				\
226a35925b8SSimon Glass 			ret = (__x < 0) ? -__x : __x;		\
227a35925b8SSimon Glass 		}						\
228a35925b8SSimon Glass 		ret;						\
229a35925b8SSimon Glass 	})
230a35925b8SSimon Glass 
231a35925b8SSimon Glass #define abs64(x) ({				\
232a35925b8SSimon Glass 		s64 __x = (x);			\
233a35925b8SSimon Glass 		(__x < 0) ? -__x : __x;		\
234a35925b8SSimon Glass 	})
235a35925b8SSimon Glass 
2363fbeeea6SHeiko Schocher #if defined(CONFIG_ENV_IS_EMBEDDED)
2373fbeeea6SHeiko Schocher #define TOTAL_MALLOC_LEN	CONFIG_SYS_MALLOC_LEN
2383fbeeea6SHeiko Schocher #elif ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \
2393fbeeea6SHeiko Schocher 	(CONFIG_ENV_ADDR >= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)) ) || \
2403fbeeea6SHeiko Schocher       defined(CONFIG_ENV_IS_IN_NVRAM)
2413fbeeea6SHeiko Schocher #define	TOTAL_MALLOC_LEN	(CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
2423fbeeea6SHeiko Schocher #else
2433fbeeea6SHeiko Schocher #define	TOTAL_MALLOC_LEN	CONFIG_SYS_MALLOC_LEN
2443fbeeea6SHeiko Schocher #endif
245c7de829cSwdenk 
24628901120SHaavard Skinnemoen /**
24728901120SHaavard Skinnemoen  * container_of - cast a member of a structure out to the containing structure
24828901120SHaavard Skinnemoen  * @ptr:	the pointer to the member.
24928901120SHaavard Skinnemoen  * @type:	the type of the container struct this is embedded in.
25028901120SHaavard Skinnemoen  * @member:	the name of the member within the struct.
25128901120SHaavard Skinnemoen  *
25228901120SHaavard Skinnemoen  */
25328901120SHaavard Skinnemoen #define container_of(ptr, type, member) ({			\
25428901120SHaavard Skinnemoen 	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
25528901120SHaavard Skinnemoen 	(type *)( (char *)__mptr - offsetof(type,member) );})
25628901120SHaavard Skinnemoen 
257c7de829cSwdenk /*
258e2211743Swdenk  * Function Prototypes
259e2211743Swdenk  */
260e2211743Swdenk 
261e2211743Swdenk void	hang		(void) __attribute__ ((noreturn));
262e2211743Swdenk 
263f6c019c4SWolfgang Denk int	timer_init(void);
264f6c019c4SWolfgang Denk int	cpu_init(void);
265f6c019c4SWolfgang Denk 
266e2211743Swdenk /* */
2679973e3c6SBecky Bruce phys_size_t initdram (int);
268e2211743Swdenk int	display_options (void);
2694b42c905STimur Tabi void	print_size(unsigned long long, const char *);
270bda32ffcSSimon Glass int print_buffer(ulong addr, const void *data, uint width, uint count,
271bda32ffcSSimon Glass 		 uint linelen);
272e2211743Swdenk 
273e2211743Swdenk /* common/main.c */
274e2211743Swdenk void	main_loop	(void);
275009dde19SSimon Glass int run_command(const char *cmd, int flag);
276d51004a8SSimon Glass 
277d51004a8SSimon Glass /**
278d51004a8SSimon Glass  * Run a list of commands separated by ; or even \0
279d51004a8SSimon Glass  *
280d51004a8SSimon Glass  * Note that if 'len' is not -1, then the command does not need to be nul
281d51004a8SSimon Glass  * terminated, Memory will be allocated for the command in that case.
282d51004a8SSimon Glass  *
283d51004a8SSimon Glass  * @param cmd	List of commands to run, each separated bu semicolon
284d51004a8SSimon Glass  * @param len	Length of commands excluding terminator if known (-1 if not)
285d51004a8SSimon Glass  * @param flag	Execution flags (CMD_FLAG_...)
286d51004a8SSimon Glass  * @return 0 on success, or != 0 on error.
287d51004a8SSimon Glass  */
288d51004a8SSimon Glass int run_command_list(const char *cmd, int len, int flag);
289e3150460SIgor Grinberg extern char console_buffer[];
290e2211743Swdenk 
291ea0364f1SPeter Tyser /* arch/$(ARCH)/lib/board.c */
292e05e5de7SAlbert ARIBAUD void	board_init_f(ulong);
2936d1b6f9fSMike Frysinger void	board_init_r  (gd_t *, ulong) __attribute__ ((noreturn));
294e2211743Swdenk int	checkboard    (void);
295e2211743Swdenk int	checkflash    (void);
296e2211743Swdenk int	checkdram     (void);
297e2211743Swdenk int	last_stage_init(void);
2983b57fe0aSwdenk extern ulong monitor_flash_len;
299bea3f28dSHaiying Wang int mac_read_from_eeprom(void);
3006ab6b2afSMasahiro Yamada extern u8 __dtb_dt_begin[];	/* embedded device tree blob */
3018f5d4687SHadli, Manjunath int set_cpu_clk_info(void);
302*9272a9b4SSimon Glass int mdm_init(void);
303365475e6SMasahiro Yamada #if defined(CONFIG_DISPLAY_CPUINFO)
3041938f4a5SSimon Glass int print_cpuinfo(void);
305365475e6SMasahiro Yamada #else
306365475e6SMasahiro Yamada static inline int print_cpuinfo(void)
307365475e6SMasahiro Yamada {
308365475e6SMasahiro Yamada 	return 0;
309365475e6SMasahiro Yamada }
310365475e6SMasahiro Yamada #endif
311c2240d4dSSimon Glass int update_flash_size(int flash_size);
3122c072c95SSimon Glass int arch_early_init_r(void);
313e2211743Swdenk 
31415a33e49SSimon Glass /**
31515a33e49SSimon Glass  * Show the DRAM size in a board-specific way
31615a33e49SSimon Glass  *
31715a33e49SSimon Glass  * This is used by boards to display DRAM information in their own way.
31815a33e49SSimon Glass  *
31915a33e49SSimon Glass  * @param size	Size of DRAM (which should be displayed along with other info)
32015a33e49SSimon Glass  */
32115a33e49SSimon Glass void board_show_dram(ulong size);
32215a33e49SSimon Glass 
32313d06981SSimon Glass /**
32413d06981SSimon Glass  * arch_fixup_memory_node() - Write arch-specific memory information to fdt
32513d06981SSimon Glass  *
32613d06981SSimon Glass  * Defined in arch/$(ARCH)/lib/bootm.c
32713d06981SSimon Glass  *
32813d06981SSimon Glass  * @blob:	FDT blob to write to
32913d06981SSimon Glass  * @return 0 if ok, or -ve FDT_ERR_... on failure
33013d06981SSimon Glass  */
33113d06981SSimon Glass int arch_fixup_memory_node(void *blob);
33213d06981SSimon Glass 
333e2211743Swdenk /* common/flash.c */
334e2211743Swdenk void flash_perror (int);
335e2211743Swdenk 
33674de7aefSWolfgang Denk /* common/cmd_source.c */
33774de7aefSWolfgang Denk int	source (ulong addr, const char *fit_uname);
338e2211743Swdenk 
339e2211743Swdenk extern ulong load_addr;		/* Default Load Address */
3401aec244aSSimon Glass extern ulong save_addr;		/* Default Save Address */
3411aec244aSSimon Glass extern ulong save_size;		/* Default Save Size */
342e2211743Swdenk 
3434394f9a8SWolfgang Denk /* common/cmd_doc.c */
3444394f9a8SWolfgang Denk void	doc_probe(unsigned long physadr);
3454394f9a8SWolfgang Denk 
34606283a64SJason Hobbs /* common/cmd_net.c */
34706283a64SJason Hobbs int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
34806283a64SJason Hobbs 
349669df7e4SRob Herring /* common/cmd_fat.c */
350669df7e4SRob Herring int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
351669df7e4SRob Herring 
352669df7e4SRob Herring /* common/cmd_ext2.c */
353669df7e4SRob Herring int do_ext2load(cmd_tbl_t *, int, int, char * const []);
354669df7e4SRob Herring 
355e2211743Swdenk /* common/cmd_nvedit.c */
356e2211743Swdenk int	env_init     (void);
357e2211743Swdenk void	env_relocate (void);
35826a41790SRafal Jaworowski int	envmatch     (uchar *, int);
35920f86a0aSSimon Glass 
36020f86a0aSSimon Glass /* Avoid unfortunate conflict with libc's getenv() */
36120f86a0aSSimon Glass #ifdef CONFIG_SANDBOX
36220f86a0aSSimon Glass #define getenv uboot_getenv
36320f86a0aSSimon Glass #endif
36484b5e802SWolfgang Denk char	*getenv	     (const char *);
36584b5e802SWolfgang Denk int	getenv_f     (const char *name, char *buf, unsigned len);
3664a9b4131SSimon Glass ulong getenv_ulong(const char *name, int base, ulong default_val);
36776b8f79cSSimon Glass 
36876b8f79cSSimon Glass /**
36976b8f79cSSimon Glass  * getenv_hex() - Return an environment variable as a hex value
37076b8f79cSSimon Glass  *
37176b8f79cSSimon Glass  * Decode an environment as a hex number (it may or may not have a 0x
37276b8f79cSSimon Glass  * prefix). If the environment variable cannot be found, or does not start
37376b8f79cSSimon Glass  * with hex digits, the default value is returned.
37476b8f79cSSimon Glass  *
37576b8f79cSSimon Glass  * @varname:		Variable to decode
37676b8f79cSSimon Glass  * @default_val:	Value to return on error
37776b8f79cSSimon Glass  */
37876b8f79cSSimon Glass ulong getenv_hex(const char *varname, ulong default_val);
37976b8f79cSSimon Glass 
380ec8a252cSJoe Hershberger /*
381ec8a252cSJoe Hershberger  * Read an environment variable as a boolean
382ec8a252cSJoe Hershberger  * Return -1 if variable does not exist (default to true)
383ec8a252cSJoe Hershberger  */
384ec8a252cSJoe Hershberger int getenv_yesno(const char *var);
385e2211743Swdenk int	saveenv	     (void);
38684b5e802SWolfgang Denk int	setenv	     (const char *, const char *);
387d67f10ceSSimon Glass int setenv_ulong(const char *varname, ulong value);
388bfc59966SSimon Glass int setenv_hex(const char *varname, ulong value);
389bfc59966SSimon Glass /**
390bfc59966SSimon Glass  * setenv_addr - Set an environment variable to an address in hex
391bfc59966SSimon Glass  *
3921bce2aebSRobert P. J. Day  * @varname:	Environment variable to set
393bfc59966SSimon Glass  * @addr:	Value to set it to
394bfc59966SSimon Glass  * @return 0 if ok, 1 on error
395bfc59966SSimon Glass  */
396bfc59966SSimon Glass static inline int setenv_addr(const char *varname, const void *addr)
397bfc59966SSimon Glass {
398bfc59966SSimon Glass 	return setenv_hex(varname, (ulong)addr);
399bfc59966SSimon Glass }
400bfc59966SSimon Glass 
401e2211743Swdenk #ifdef CONFIG_ARM
40296085e34Swdenk # include <asm/mach-types.h>
403b6e4c403Swdenk # include <asm/setup.h>
404e2211743Swdenk # include <asm/u-boot-arm.h>	/* ARM version to be fixed! */
405e2211743Swdenk #endif /* CONFIG_ARM */
406fea25720SGraeme Russ #ifdef CONFIG_X86		/* x86 version to be fixed! */
407fea25720SGraeme Russ # include <asm/u-boot-x86.h>
408fea25720SGraeme Russ #endif /* CONFIG_X86 */
409744d9859SSimon Glass #ifdef CONFIG_SANDBOX
410744d9859SSimon Glass # include <asm/u-boot-sandbox.h>	/* TODO(sjg) what needs to be fixed? */
411744d9859SSimon Glass #endif
412e7083844SMacpaul Lin #ifdef CONFIG_NDS32
413e7083844SMacpaul Lin # include <asm/mach-types.h>
414e3c58b02Sken kuo # include <asm/setup.h>
415e7083844SMacpaul Lin # include <asm/u-boot-nds32.h>
416e7083844SMacpaul Lin #endif /* CONFIG_NDS32 */
417e034ea3bSDaniel Schwierzeck #ifdef CONFIG_MIPS
418e034ea3bSDaniel Schwierzeck # include <asm/u-boot-mips.h>
419e034ea3bSDaniel Schwierzeck #endif /* CONFIG_MIPS */
420bc5d5428SAlexey Brodkin #ifdef CONFIG_ARC
421bc5d5428SAlexey Brodkin # include <asm/u-boot-arc.h>
422bc5d5428SAlexey Brodkin #endif /* CONFIG_ARC */
423e2211743Swdenk 
42404a85b3bSwdenk #ifdef CONFIG_AUTO_COMPLETE
42504a85b3bSwdenk int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf);
42604a85b3bSwdenk #endif
4272f70c49eSHeiko Schocher int get_env_id (void);
42804a85b3bSwdenk 
429e2211743Swdenk void	pci_init      (void);
430ad10dd9aSstroese void	pci_init_board(void);
431e2211743Swdenk void	pciinfo	      (int, int);
432e2211743Swdenk 
433a821d08dSStefan Roese #if defined(CONFIG_PCI) && defined(CONFIG_4xx)
434e2211743Swdenk     int	   pci_pre_init	       (struct pci_controller *);
435c71103f9SMatthias Fuchs     int	   is_pci_host	       (struct pci_controller *);
436e2211743Swdenk #endif
437466fff1aSStefan Roese 
438dbbd1257SStefan Roese #if defined(CONFIG_PCI) && (defined(CONFIG_440) || defined(CONFIG_405EX))
4396d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #   if defined(CONFIG_SYS_PCI_TARGET_INIT)
440e2211743Swdenk 	void	pci_target_init	     (struct pci_controller *);
441e2211743Swdenk #   endif
4426d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #   if defined(CONFIG_SYS_PCI_MASTER_INIT)
443e2211743Swdenk 	void	pci_master_init	     (struct pci_controller *);
444e2211743Swdenk #   endif
4456f2eb3f3SStefan Roese #if defined(CONFIG_440SPE) || \
4466f2eb3f3SStefan Roese     defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
4476f2eb3f3SStefan Roese     defined(CONFIG_405EX)
4487f191393SGrzegorz Bernacki    void pcie_setup_hoses(int busno);
449692519b1SRafal Jaworowski #endif
450e2211743Swdenk #endif
451e2211743Swdenk 
452e2211743Swdenk int	misc_init_f   (void);
453e2211743Swdenk int	misc_init_r   (void);
454e2211743Swdenk 
45527b207fdSwdenk /* common/exports.c */
45627b207fdSwdenk void	jumptable_init(void);
45727b207fdSwdenk 
458ecb1dc89SMike Frysinger /* common/kallsysm.c */
459ecb1dc89SMike Frysinger const char *symbol_lookup(unsigned long addr, unsigned long *caddr);
460ecb1dc89SMike Frysinger 
461500856ebSRafal Jaworowski /* api/api.c */
462500856ebSRafal Jaworowski void	api_init (void);
463500856ebSRafal Jaworowski 
464c83bf6a2Swdenk /* common/memsize.c */
465a55d23ccSAlbert ARIBAUD long	get_ram_size  (long *, long);
466e3866163SYork Sun phys_size_t get_effective_memsize(void);
467c83bf6a2Swdenk 
468e2211743Swdenk /* $(BOARD)/$(BOARD).c */
469e2211743Swdenk void	reset_phy     (void);
4707f6c2cbcSwdenk void	fdc_hw_init   (void);
471e2211743Swdenk 
472e2211743Swdenk /* $(BOARD)/eeprom.c */
473e2211743Swdenk void eeprom_init  (void);
4746dd652faSwdenk #ifndef CONFIG_SPI
4756dd652faSwdenk int  eeprom_probe (unsigned dev_addr, unsigned offset);
4766dd652faSwdenk #endif
477e2211743Swdenk int  eeprom_read  (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
478e2211743Swdenk int  eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
479e2211743Swdenk #ifdef CONFIG_LWMON
480e2211743Swdenk extern uchar pic_read  (uchar reg);
481e2211743Swdenk extern void  pic_write (uchar reg, uchar val);
482e2211743Swdenk #endif
483e2211743Swdenk 
484e2211743Swdenk /*
485e2211743Swdenk  * Set this up regardless of board
486e2211743Swdenk  * type, to prevent errors.
487e2211743Swdenk  */
4886d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_SPI) || !defined(CONFIG_SYS_I2C_EEPROM_ADDR)
4896d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # define CONFIG_SYS_DEF_EEPROM_ADDR 0
490e2211743Swdenk #else
491548738b4SHeiko Schocher #if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
4926d0f6bcfSJean-Christophe PLAGNIOL-VILLARD # define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR
493548738b4SHeiko Schocher #endif
4946d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #endif /* CONFIG_SPI || !defined(CONFIG_SYS_I2C_EEPROM_ADDR) */
495e2211743Swdenk 
496bdccc4feSwdenk #if defined(CONFIG_SPI)
497e2211743Swdenk extern void spi_init_f (void);
498e2211743Swdenk extern void spi_init_r (void);
499e2211743Swdenk extern ssize_t spi_read	 (uchar *, int, uchar *, int);
500e2211743Swdenk extern ssize_t spi_write (uchar *, int, uchar *, int);
501e2211743Swdenk #endif
502e2211743Swdenk 
503e63c8ee3Swdenk void rpxlite_init (void);
504e63c8ee3Swdenk 
505e2211743Swdenk #ifdef CONFIG_HERMES
506e2211743Swdenk /* $(BOARD)/hermes.c */
507e2211743Swdenk void hermes_start_lxt980 (int speed);
508e2211743Swdenk #endif
509e2211743Swdenk 
510e2211743Swdenk #ifdef CONFIG_EVB64260
511e2211743Swdenk void  evb64260_init(void);
512e2211743Swdenk void  debug_led(int, int);
513e2211743Swdenk void  display_mem_map(void);
514e2211743Swdenk void  perform_soft_reset(void);
515e2211743Swdenk #endif
516e2211743Swdenk 
517e2211743Swdenk /* $(BOARD)/$(BOARD).c */
518c837dcb1Swdenk int board_early_init_f (void);
519c837dcb1Swdenk int board_late_init (void);
520e2211743Swdenk int board_postclk_init (void); /* after clocks/timebase, before env/serial */
521c837dcb1Swdenk int board_early_init_r (void);
522e2211743Swdenk void board_poweroff (void);
523e2211743Swdenk 
5246d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_SYS_DRAM_TEST)
525e2211743Swdenk int testdram(void);
5266d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #endif /* CONFIG_SYS_DRAM_TEST */
527e2211743Swdenk 
528e2211743Swdenk /* $(CPU)/start.S */
5290db5bca8Swdenk #if defined(CONFIG_5xx) || \
5300db5bca8Swdenk     defined(CONFIG_8xx)
531e2211743Swdenk uint	get_immr      (uint);
532e2211743Swdenk #endif
53342d1f039Swdenk uint	get_pir	      (void);
53436c72877Swdenk #if defined(CONFIG_MPC5xxx)
53536c72877Swdenk uint	get_svr       (void);
53636c72877Swdenk #endif
537e2211743Swdenk uint	get_pvr	      (void);
538547b4cb2Swdenk uint	get_svr	      (void);
539e2211743Swdenk uint	rd_ic_cst     (void);
540e2211743Swdenk void	wr_ic_cst     (uint);
541e2211743Swdenk void	wr_ic_adr     (uint);
542e2211743Swdenk uint	rd_dc_cst     (void);
543e2211743Swdenk void	wr_dc_cst     (uint);
544e2211743Swdenk void	wr_dc_adr     (uint);
545e2211743Swdenk int	icache_status (void);
546e2211743Swdenk void	icache_enable (void);
547e2211743Swdenk void	icache_disable(void);
548e2211743Swdenk int	dcache_status (void);
549e2211743Swdenk void	dcache_enable (void);
550e2211743Swdenk void	dcache_disable(void);
5512c451f78SAneesh V void	mmu_disable(void);
5525c6db120SBenoît Thébaudeau #if defined(CONFIG_ARM)
5535c6db120SBenoît Thébaudeau void	relocate_code(ulong);
5545c6db120SBenoît Thébaudeau #else
5555c6db120SBenoît Thébaudeau void	relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
556959eaa74SBenoît Thébaudeau #endif
557e2211743Swdenk ulong	get_endaddr   (void);
558e2211743Swdenk void	trap_init     (ulong);
559e2211743Swdenk #if defined (CONFIG_4xx)	|| \
560eeb1b77bSwdenk     defined (CONFIG_MPC5xxx)	|| \
561e2211743Swdenk     defined (CONFIG_74xx_7xx)	|| \
562e2211743Swdenk     defined (CONFIG_74x)	|| \
563e2211743Swdenk     defined (CONFIG_75x)	|| \
5640ac6f8b7Swdenk     defined (CONFIG_74xx)	|| \
565cd94ba39SMarian Balakowicz     defined (CONFIG_MPC85xx)	|| \
566debb7354SJon Loeliger     defined (CONFIG_MPC86xx)	|| \
5670f898604SPeter Tyser     defined (CONFIG_MPC83xx)
568e2211743Swdenk unsigned char	in8(unsigned int);
569e2211743Swdenk void		out8(unsigned int, unsigned char);
570e2211743Swdenk unsigned short	in16(unsigned int);
571e2211743Swdenk unsigned short	in16r(unsigned int);
572e2211743Swdenk void		out16(unsigned int, unsigned short value);
573e2211743Swdenk void		out16r(unsigned int, unsigned short value);
574e2211743Swdenk unsigned long	in32(unsigned int);
575e2211743Swdenk unsigned long	in32r(unsigned int);
576e2211743Swdenk void		out32(unsigned int, unsigned long value);
577e2211743Swdenk void		out32r(unsigned int, unsigned long value);
578e2211743Swdenk void		ppcDcbf(unsigned long value);
579e2211743Swdenk void		ppcDcbi(unsigned long value);
580e2211743Swdenk void		ppcSync(void);
5810ac6f8b7Swdenk void		ppcDcbz(unsigned long value);
582e2211743Swdenk #endif
5830643631aSMichal Simek #if defined (CONFIG_MICROBLAZE)
5840643631aSMichal Simek unsigned short	in16(unsigned int);
5850643631aSMichal Simek void		out16(unsigned int, unsigned short value);
5860643631aSMichal Simek #endif
587e2211743Swdenk 
5880f898604SPeter Tyser #if defined (CONFIG_MPC83xx)
58990f30a71SDave Liu void		ppcDWload(unsigned int *addr, unsigned int *ret);
59090f30a71SDave Liu void		ppcDWstore(unsigned int *addr, unsigned int *value);
5917c6db910SHeiko Schocher void disable_addr_trans(void);
5927c6db910SHeiko Schocher void enable_addr_trans(void);
5937c6db910SHeiko Schocher #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
5947c6db910SHeiko Schocher void ddr_enable_ecc(unsigned int dram_size);
5957c6db910SHeiko Schocher #endif
59690f30a71SDave Liu #endif
59790f30a71SDave Liu 
598fc9ae1baSRajeshwari Shinde /*
599fc9ae1baSRajeshwari Shinde  * Return the current value of a monotonically increasing microsecond timer.
600fc9ae1baSRajeshwari Shinde  * Granularity may be larger than 1us if hardware does not support this.
601fc9ae1baSRajeshwari Shinde  */
602fc9ae1baSRajeshwari Shinde ulong timer_get_us(void);
603fc9ae1baSRajeshwari Shinde 
604e2211743Swdenk /* $(CPU)/cpu.c */
605fbb9ecf7STimur Tabi static inline int cpumask_next(int cpu, unsigned int mask)
606fbb9ecf7STimur Tabi {
607fbb9ecf7STimur Tabi 	for (cpu++; !((1 << cpu) & mask); cpu++)
608fbb9ecf7STimur Tabi 		;
609fbb9ecf7STimur Tabi 
610fbb9ecf7STimur Tabi 	return cpu;
611fbb9ecf7STimur Tabi }
612fbb9ecf7STimur Tabi 
613fbb9ecf7STimur Tabi #define for_each_cpu(iter, cpu, num_cpus, mask) \
614fbb9ecf7STimur Tabi 	for (iter = 0, cpu = cpumask_next(-1, mask); \
615fbb9ecf7STimur Tabi 		iter < num_cpus; \
616fbb9ecf7STimur Tabi 		iter++, cpu = cpumask_next(cpu, mask)) \
617fbb9ecf7STimur Tabi 
6180e870980SPoonam Aggrwal int	cpu_numcores  (void);
619fbb9ecf7STimur Tabi u32	cpu_mask      (void);
620fbb9ecf7STimur Tabi int	is_core_valid (unsigned int);
6210e870980SPoonam Aggrwal int	probecpu      (void);
622e2211743Swdenk int	checkcpu      (void);
623e2211743Swdenk int	checkicache   (void);
624e2211743Swdenk int	checkdcache   (void);
625e2211743Swdenk void	upmconfig     (unsigned int, unsigned int *, unsigned int);
626e2211743Swdenk ulong	get_tbclk     (void);
6273ec924a3Swdenk void	reset_cpu     (ulong addr);
6286a16e0dfSKim Phillips #if defined (CONFIG_OF_LIBFDT) && defined (CONFIG_OF_BOARD_SETUP)
6296a16e0dfSKim Phillips void ft_cpu_setup(void *blob, bd_t *bd);
6306a16e0dfSKim Phillips #ifdef CONFIG_PCI
6316a16e0dfSKim Phillips void ft_pci_setup(void *blob, bd_t *bd);
6326a16e0dfSKim Phillips #endif
6336a16e0dfSKim Phillips #endif
6346a16e0dfSKim Phillips 
635ba6a1698SAndre Przywara void smp_set_core_boot_addr(unsigned long addr, int corenr);
636ba6a1698SAndre Przywara void smp_kick_all_cpus(void);
637e2211743Swdenk 
638e2211743Swdenk /* $(CPU)/serial.c */
639e2211743Swdenk int	serial_init   (void);
640e2211743Swdenk void	serial_setbrg (void);
641e2211743Swdenk void	serial_putc   (const char);
642756f586aSwdenk void	serial_putc_raw(const char);
643e2211743Swdenk void	serial_puts   (const char *);
644e2211743Swdenk int	serial_getc   (void);
645e2211743Swdenk int	serial_tstc   (void);
646e2211743Swdenk 
647756f586aSwdenk void	_serial_setbrg (const int);
648756f586aSwdenk void	_serial_putc   (const char, const int);
649756f586aSwdenk void	_serial_putc_raw(const char, const int);
650756f586aSwdenk void	_serial_puts   (const char *, const int);
651756f586aSwdenk int	_serial_getc   (const int);
652756f586aSwdenk int	_serial_tstc   (const int);
653756f586aSwdenk 
654e2211743Swdenk /* $(CPU)/speed.c */
655e2211743Swdenk int	get_clocks (void);
656c178d3daSwdenk int	get_clocks_866 (void);
657c178d3daSwdenk int	sdram_adjust_866 (void);
658e9132ea9Swdenk int	adjust_sdram_tbs_8xx (void);
65958dac327SMasahiro Yamada #if defined(CONFIG_MPC8260)
660e2211743Swdenk int	prt_8260_clks (void);
661f046ccd1SEran Liberty #elif defined(CONFIG_MPC5xxx)
662945af8d7Swdenk int	prt_mpc5xxx_clks (void);
663945af8d7Swdenk #endif
664e2211743Swdenk #ifdef CONFIG_4xx
665e2211743Swdenk ulong	get_OPB_freq (void);
666e2211743Swdenk ulong	get_PCI_freq (void);
667e2211743Swdenk #endif
668ac67804fSkevin.morfitt@fearnside-systems.co.uk #if defined(CONFIG_S3C24X0) || \
669ac67804fSkevin.morfitt@fearnside-systems.co.uk     defined(CONFIG_LH7A40X) || \
670fcfb632bSMatthias Kaehlcke     defined(CONFIG_EP93XX)
671e2211743Swdenk ulong	get_FCLK (void);
672e2211743Swdenk ulong	get_HCLK (void);
673e2211743Swdenk ulong	get_PCLK (void);
674e2211743Swdenk ulong	get_UCLK (void);
675e2211743Swdenk #endif
676f39748aeSwdenk #if defined(CONFIG_LH7A40X)
677f39748aeSwdenk ulong	get_PLLCLK (void);
678f39748aeSwdenk #endif
679281e00a3Swdenk #if defined(CONFIG_IMX)
680281e00a3Swdenk ulong get_systemPLLCLK(void);
681281e00a3Swdenk ulong get_FCLK(void);
682281e00a3Swdenk ulong get_HCLK(void);
683281e00a3Swdenk ulong get_BCLK(void);
684281e00a3Swdenk ulong get_PERCLK1(void);
685281e00a3Swdenk ulong get_PERCLK2(void);
686281e00a3Swdenk ulong get_PERCLK3(void);
687281e00a3Swdenk #endif
688e2211743Swdenk ulong	get_bus_freq  (ulong);
689550650ddSStefan Roese int get_serial_clock(void);
690e2211743Swdenk 
691d29d17d7SYork Sun #if defined(CONFIG_MPC83xx) || defined(CONFIG_MPC85xx)
692d29d17d7SYork Sun ulong get_ddr_freq(ulong);
693d29d17d7SYork Sun #endif
69442d1f039Swdenk #if defined(CONFIG_MPC85xx)
69542d1f039Swdenk typedef MPC85xx_SYS_INFO sys_info_t;
69642d1f039Swdenk void	get_sys_info  ( sys_info_t * );
697871a57bbSMiao Yan #  if defined(CONFIG_OF_LIBFDT)
698871a57bbSMiao Yan 	void ft_fixup_cpu(void *, u64);
699871a57bbSMiao Yan 	void ft_fixup_num_cores(void *);
700871a57bbSMiao Yan #  endif
70142d1f039Swdenk #endif
702debb7354SJon Loeliger #if defined(CONFIG_MPC86xx)
703debb7354SJon Loeliger typedef MPC86xx_SYS_INFO sys_info_t;
704debb7354SJon Loeliger void   get_sys_info  ( sys_info_t * );
7055df4b0adSKumar Gala static inline ulong get_ddr_freq(ulong dummy)
7065df4b0adSKumar Gala {
7075df4b0adSKumar Gala 	return get_bus_freq(dummy);
7085df4b0adSKumar Gala }
709debb7354SJon Loeliger #endif
71042d1f039Swdenk 
71199bcad18SStefan Roese #if defined(CONFIG_4xx)
712e2211743Swdenk #  if defined(CONFIG_440)
7136c5879f3SMarian Balakowicz #	if defined(CONFIG_440SPE)
7146c5879f3SMarian Balakowicz 	 unsigned long determine_sysper(void);
7156c5879f3SMarian Balakowicz 	 unsigned long determine_pci_clock_per(void);
7166c5879f3SMarian Balakowicz #	endif
717e2211743Swdenk #  endif
718087dfdb7SStefan Roese typedef PPC4xx_SYS_INFO sys_info_t;
719f31d38b9SStefan Roese int	ppc440spe_revB(void);
720e2211743Swdenk void	get_sys_info  ( sys_info_t * );
721e2211743Swdenk #endif
722e2211743Swdenk 
723e2211743Swdenk /* $(CPU)/cpu_init.c */
72458dac327SMasahiro Yamada #if defined(CONFIG_8xx) || defined(CONFIG_MPC8260)
725e2211743Swdenk void	cpu_init_f    (volatile immap_t *immr);
726e2211743Swdenk #endif
727701e6401SYork Sun #if defined(CONFIG_4xx) || defined(CONFIG_MCF52x2) || defined(CONFIG_MPC86xx)
728e2211743Swdenk void	cpu_init_f    (void);
729e2211743Swdenk #endif
730701e6401SYork Sun #ifdef CONFIG_MPC85xx
731701e6401SYork Sun ulong cpu_init_f(void);
732701e6401SYork Sun #endif
733bf9e3b38Swdenk 
734e2211743Swdenk int	cpu_init_r    (void);
73558dac327SMasahiro Yamada #if defined(CONFIG_MPC8260)
736e2211743Swdenk int	prt_8260_rsr  (void);
7370f898604SPeter Tyser #elif defined(CONFIG_MPC83xx)
7389be39a67SDave Liu int	prt_83xx_rsr  (void);
739e2211743Swdenk #endif
740e2211743Swdenk 
741e2211743Swdenk /* $(CPU)/interrupts.c */
742e2211743Swdenk int	interrupt_init	   (void);
743e2211743Swdenk void	timer_interrupt	   (struct pt_regs *);
744e2211743Swdenk void	external_interrupt (struct pt_regs *);
745e2211743Swdenk void	irq_install_handler(int, interrupt_handler_t *, void *);
746e2211743Swdenk void	irq_free_handler   (int);
747e2211743Swdenk void	reset_timer	   (void);
748e2211743Swdenk ulong	get_timer	   (ulong base);
749b2e16a85SSimon Glass 
750b2e16a85SSimon Glass /* Return value of monotonic microsecond timer */
751b2e16a85SSimon Glass unsigned long timer_get_us(void);
752b2e16a85SSimon Glass 
753e2211743Swdenk void	enable_interrupts  (void);
754e2211743Swdenk int	disable_interrupts (void);
755e2211743Swdenk 
756e2211743Swdenk /* $(CPU)/.../commproc.c */
757e2211743Swdenk int	dpram_init (void);
758e2211743Swdenk uint	dpram_base(void);
759e2211743Swdenk uint	dpram_base_align(uint align);
760e2211743Swdenk uint	dpram_alloc(uint size);
761e2211743Swdenk uint	dpram_alloc_align(uint size,uint align);
762bdccc4feSwdenk void	bootcount_store (ulong);
763bdccc4feSwdenk ulong	bootcount_load (void);
764bdccc4feSwdenk #define BOOTCOUNT_MAGIC		0xB001C041
765e2211743Swdenk 
766e2211743Swdenk /* $(CPU)/.../<eth> */
767c5bded3cSWolfgang Denk void mii_init (void);
768e2211743Swdenk 
769e2211743Swdenk /* $(CPU)/.../lcd.c */
770e2211743Swdenk ulong	lcd_setmem (ulong);
771e2211743Swdenk 
772e2211743Swdenk /* $(CPU)/.../video.c */
773e2211743Swdenk ulong	video_setmem (ulong);
774e2211743Swdenk 
775ea0364f1SPeter Tyser /* arch/$(ARCH)/lib/cache.c */
776cba4b180SAneesh V void	enable_caches(void);
777e2211743Swdenk void	flush_cache   (unsigned long, unsigned long);
7782c451f78SAneesh V void	flush_dcache_all(void);
77903d3bfb0SStefan Roese void	flush_dcache_range(unsigned long start, unsigned long stop);
78003d3bfb0SStefan Roese void	invalidate_dcache_range(unsigned long start, unsigned long stop);
7812c451f78SAneesh V void	invalidate_dcache_all(void);
7822c451f78SAneesh V void	invalidate_icache_all(void);
7830db5bca8Swdenk 
784ea0364f1SPeter Tyser /* arch/$(ARCH)/lib/ticks.S */
785e2211743Swdenk unsigned long long get_ticks(void);
786e2211743Swdenk void	wait_ticks    (unsigned long);
787e2211743Swdenk 
788ea0364f1SPeter Tyser /* arch/$(ARCH)/lib/time.c */
7893eb90badSIngo van Lil void	__udelay      (unsigned long);
790e2211743Swdenk ulong	usec2ticks    (unsigned long usec);
791e2211743Swdenk ulong	ticks2usec    (unsigned long ticks);
792e2211743Swdenk int	init_timebase (void);
793e2211743Swdenk 
79478acc472SPeter Tyser /* lib/gunzip.c */
79587d93a1bSWolfgang Wegner int gunzip(void *, int, unsigned char *, unsigned long *);
79687d93a1bSWolfgang Wegner int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
79787d93a1bSWolfgang Wegner 						int stoponerr, int offset);
79887d93a1bSWolfgang Wegner 
79954c6977eSWolfgang Denk /* lib/qsort.c */
80054c6977eSWolfgang Denk void qsort(void *base, size_t nmemb, size_t size,
80154c6977eSWolfgang Denk 	   int(*compar)(const void *, const void *));
802560d424bSMike Frysinger int strcmp_compar(const void *, const void *);
80354c6977eSWolfgang Denk 
80478acc472SPeter Tyser /* lib/time.c */
8053eb90badSIngo van Lil void	udelay        (unsigned long);
806c4c9fbebSAnatolij Gustschin void mdelay(unsigned long);
8073eb90badSIngo van Lil 
808e11938eaSJason Hobbs /* lib/uuid.c */
809d718ded0SPrzemyslaw Marczak #include <uuid.h>
810e11938eaSJason Hobbs 
81178acc472SPeter Tyser /* lib/vsprintf.c */
8129785c905SSimon Glass #include <vsprintf.h>
813e2211743Swdenk 
81478acc472SPeter Tyser /* lib/strmhz.c */
81555f7934dSEd Swarthout char *	strmhz(char *buf, unsigned long hz);
8160768b7a8SHaavard Skinnemoen 
81778acc472SPeter Tyser /* lib/crc32.c */
818449609f5SPrafulla Wadaskar #include <u-boot/crc.h>
819e2211743Swdenk 
8209acf1ca5SMichael Walle /* lib/rand.c */
8219acf1ca5SMichael Walle #define RAND_MAX -1U
8229acf1ca5SMichael Walle void srand(unsigned int seed);
8239acf1ca5SMichael Walle unsigned int rand(void);
8249acf1ca5SMichael Walle unsigned int rand_r(unsigned int *seedp);
8259acf1ca5SMichael Walle 
826e2211743Swdenk /* common/console.c */
827e2211743Swdenk int	console_init_f(void);	/* Before relocation; uses the serial  stuff	*/
828e2211743Swdenk int	console_init_r(void);	/* After  relocation; uses the console stuff	*/
829d7be3056SMike Frysinger int	console_assign(int file, const char *devname);	/* Assign the console	*/
830e2211743Swdenk int	ctrlc (void);
831e2211743Swdenk int	had_ctrlc (void);	/* have we had a Control-C since last clear? */
832e2211743Swdenk void	clear_ctrlc (void);	/* clear the Control-C condition */
833e2211743Swdenk int	disable_ctrlc (int);	/* 1 to disable, 0 to enable Control-C detect */
834a5dffa4bSPierre Aubert int confirm_yesno(void);        /*  1 if input is "y", "Y", "yes" or "YES" */
835e2211743Swdenk /*
836e2211743Swdenk  * STDIO based functions (can always be used)
837e2211743Swdenk  */
838e2211743Swdenk /* serial stuff */
839d9c27253SWolfgang Denk int	serial_printf (const char *fmt, ...)
840dc4b0b38SAndrew Klossner 		__attribute__ ((format (__printf__, 1, 2)));
841e2211743Swdenk /* stdin */
842e2211743Swdenk int	getc(void);
843e2211743Swdenk int	tstc(void);
844e2211743Swdenk 
845e2211743Swdenk /* stdout */
846e2211743Swdenk void	putc(const char c);
847e2211743Swdenk void	puts(const char *s);
848d9c27253SWolfgang Denk int	printf(const char *fmt, ...)
849dc4b0b38SAndrew Klossner 		__attribute__ ((format (__printf__, 1, 2)));
850d9c27253SWolfgang Denk int	vprintf(const char *fmt, va_list args);
851e2211743Swdenk 
852e2211743Swdenk /* stderr */
853e2211743Swdenk #define eputc(c)		fputc(stderr, c)
854e2211743Swdenk #define eputs(s)		fputs(stderr, s)
855e2211743Swdenk #define eprintf(fmt,args...)	fprintf(stderr,fmt ,##args)
856e2211743Swdenk 
857e2211743Swdenk /*
858e2211743Swdenk  * FILE based functions (can only be used AFTER relocation!)
859e2211743Swdenk  */
860e2211743Swdenk #define stdin		0
861e2211743Swdenk #define stdout		1
862e2211743Swdenk #define stderr		2
863e2211743Swdenk #define MAX_FILES	3
864e2211743Swdenk 
865d9c27253SWolfgang Denk int	fprintf(int file, const char *fmt, ...)
866dc4b0b38SAndrew Klossner 		__attribute__ ((format (__printf__, 2, 3)));
867e2211743Swdenk void	fputs(int file, const char *s);
868e2211743Swdenk void	fputc(int file, const char c);
869e2211743Swdenk int	ftstc(int file);
870e2211743Swdenk int	fgetc(int file);
871e2211743Swdenk 
87288d52c6aSLei Wen /* lib/gzip.c */
87388d52c6aSLei Wen int gzip(void *dst, unsigned long *lenp,
87488d52c6aSLei Wen 		unsigned char *src, unsigned long srclen);
87588d52c6aSLei Wen int zzip(void *dst, unsigned long *lenp, unsigned char *src,
87688d52c6aSLei Wen 		unsigned long srclen, int stoponerr,
87788d52c6aSLei Wen 		int (*func)(unsigned long, unsigned long));
87888d52c6aSLei Wen 
8794ef8d53cSJoe Hershberger /* lib/net_utils.c */
8804ef8d53cSJoe Hershberger #include <net.h>
8814ef8d53cSJoe Hershberger static inline IPaddr_t getenv_IPaddr(char *var)
8824ef8d53cSJoe Hershberger {
8834ef8d53cSJoe Hershberger 	return string_to_ip(getenv(var));
8844ef8d53cSJoe Hershberger }
8854ef8d53cSJoe Hershberger 
88616a28ef2SGary Jennejohn /*
88716a28ef2SGary Jennejohn  * CONSOLE multiplexing.
88816a28ef2SGary Jennejohn  */
88916a28ef2SGary Jennejohn #ifdef CONFIG_CONSOLE_MUX
89016a28ef2SGary Jennejohn #include <iomux.h>
89116a28ef2SGary Jennejohn #endif
89216a28ef2SGary Jennejohn 
893e2211743Swdenk int	pcmcia_init (void);
894e2211743Swdenk 
895fb364becSWolfgang Denk #ifdef CONFIG_STATUS_LED
896fb364becSWolfgang Denk # include <status_led.h>
897fb364becSWolfgang Denk #endif
898097e1783SSimon Glass 
899097e1783SSimon Glass #include <bootstage.h>
900e2211743Swdenk 
90148522bb5SJoe Hershberger #ifdef CONFIG_SHOW_ACTIVITY
90248522bb5SJoe Hershberger void show_activity(int arg);
90348522bb5SJoe Hershberger #endif
90448522bb5SJoe Hershberger 
905fcd3c87eSWolfgang Denk /* Multicore arch functions */
906fcd3c87eSWolfgang Denk #ifdef CONFIG_MP
907fcd3c87eSWolfgang Denk int cpu_status(int nr);
908fcd3c87eSWolfgang Denk int cpu_reset(int nr);
9094194b366SKumar Gala int cpu_disable(int nr);
91054841ab5SWolfgang Denk int cpu_release(int nr, int argc, char * const argv[]);
911fcd3c87eSWolfgang Denk #endif
912fcd3c87eSWolfgang Denk 
9134213fc29SSimon Glass /* Define a null map_sysmem() if the architecture doesn't use it */
9144213fc29SSimon Glass # ifndef CONFIG_ARCH_MAP_SYSMEM
9154213fc29SSimon Glass static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
9164213fc29SSimon Glass {
9174213fc29SSimon Glass 	return (void *)(uintptr_t)paddr;
9184213fc29SSimon Glass }
9194213fc29SSimon Glass 
9204213fc29SSimon Glass static inline void unmap_sysmem(const void *vaddr)
9214213fc29SSimon Glass {
9224213fc29SSimon Glass }
923781adb57SSimon Glass 
924ed072b96SSimon Glass static inline phys_addr_t map_to_sysmem(const void *ptr)
925781adb57SSimon Glass {
926781adb57SSimon Glass 	return (phys_addr_t)(uintptr_t)ptr;
927781adb57SSimon Glass }
9284213fc29SSimon Glass # endif
9294213fc29SSimon Glass 
930fcd3c87eSWolfgang Denk #endif /* __ASSEMBLY__ */
931fcd3c87eSWolfgang Denk 
93213e95e42SStefan Roese #ifdef CONFIG_PPC
93313e95e42SStefan Roese /*
93413e95e42SStefan Roese  * Has to be included outside of the #ifndef __ASSEMBLY__ section.
93513e95e42SStefan Roese  * Otherwise might lead to compilation errors in assembler files.
93613e95e42SStefan Roese  */
93713e95e42SStefan Roese #include <asm/cache.h>
93813e95e42SStefan Roese #endif
93913e95e42SStefan Roese 
940fcd3c87eSWolfgang Denk /* Put only stuff here that the assembler can digest */
941fcd3c87eSWolfgang Denk 
942fcd3c87eSWolfgang Denk #ifdef CONFIG_POST
943fcd3c87eSWolfgang Denk #define CONFIG_HAS_POST
944800eb096SMichael Zaidman #ifndef CONFIG_POST_ALT_LIST
945800eb096SMichael Zaidman #define CONFIG_POST_STD_LIST
946800eb096SMichael Zaidman #endif
947fcd3c87eSWolfgang Denk #endif
948fcd3c87eSWolfgang Denk 
9498aa1a2d1Swdenk #ifdef CONFIG_INIT_CRITICAL
9502f6fa46dSWolfgang Denk #error CONFIG_INIT_CRITICAL is deprecated!
9518aa1a2d1Swdenk #error Read section CONFIG_SKIP_LOWLEVEL_INIT in README.
9528aa1a2d1Swdenk #endif
9538aa1a2d1Swdenk 
9543cfb0c51SKumar Gala #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
9553cfb0c51SKumar Gala 
956155cfb5eSAnton Staaf #define ROUND(a,b)		(((a) + (b) - 1) & ~((b) - 1))
957d50c7d4bSWolfgang Denk #define DIV_ROUND(n,d)		(((n) + ((d)/2)) / (d))
958022f1216SKumar Gala #define DIV_ROUND_UP(n,d)	(((n) + (d) - 1) / (d))
959022f1216SKumar Gala #define roundup(x, y)		((((x) + ((y) - 1)) / (y)) * (y))
960022f1216SKumar Gala 
96123d5c738SSoren Brinkmann /*
96223d5c738SSoren Brinkmann  * Divide positive or negative dividend by positive divisor and round
96323d5c738SSoren Brinkmann  * to closest integer. Result is undefined for negative divisors and
96423d5c738SSoren Brinkmann  * for negative dividends if the divisor variable type is unsigned.
96523d5c738SSoren Brinkmann  */
96623d5c738SSoren Brinkmann #define DIV_ROUND_CLOSEST(x, divisor)(			\
96723d5c738SSoren Brinkmann {							\
96823d5c738SSoren Brinkmann 	typeof(x) __x = x;				\
96923d5c738SSoren Brinkmann 	typeof(divisor) __d = divisor;			\
97023d5c738SSoren Brinkmann 	(((typeof(x))-1) > 0 ||				\
97123d5c738SSoren Brinkmann 	 ((typeof(divisor))-1) > 0 || (__x) > 0) ?	\
97223d5c738SSoren Brinkmann 		(((__x) + ((__d) / 2)) / (__d)) :	\
97323d5c738SSoren Brinkmann 		(((__x) - ((__d) / 2)) / (__d));	\
97423d5c738SSoren Brinkmann }							\
97523d5c738SSoren Brinkmann )
97623d5c738SSoren Brinkmann 
9774b03ac8bSAndy Fleming #define ALIGN(x,a)		__ALIGN_MASK((x),(typeof(x))(a)-1)
9784b03ac8bSAndy Fleming #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
9794b03ac8bSAndy Fleming 
9801e41f5adSAnton Staaf /*
9811e41f5adSAnton Staaf  * ARCH_DMA_MINALIGN is defined in asm/cache.h for each architecture.  It
9821e41f5adSAnton Staaf  * is used to align DMA buffers.
9831e41f5adSAnton Staaf  */
9841e41f5adSAnton Staaf #ifndef __ASSEMBLY__
9851e41f5adSAnton Staaf #include <asm/cache.h>
9861e41f5adSAnton Staaf #endif
9871e41f5adSAnton Staaf 
98846a6d51cSAnton staaf /*
98946a6d51cSAnton staaf  * The ALLOC_CACHE_ALIGN_BUFFER macro is used to allocate a buffer on the
99046a6d51cSAnton staaf  * stack that meets the minimum architecture alignment requirements for DMA.
99146a6d51cSAnton staaf  * Such a buffer is useful for DMA operations where flushing and invalidating
99246a6d51cSAnton staaf  * the cache before and after a read and/or write operation is required for
99346a6d51cSAnton staaf  * correct operations.
99446a6d51cSAnton staaf  *
99546a6d51cSAnton staaf  * When called the macro creates an array on the stack that is sized such
99646a6d51cSAnton staaf  * that:
99746a6d51cSAnton staaf  *
99846a6d51cSAnton staaf  * 1) The beginning of the array can be advanced enough to be aligned.
99946a6d51cSAnton staaf  *
100046a6d51cSAnton staaf  * 2) The size of the aligned portion of the array is a multiple of the minimum
100146a6d51cSAnton staaf  *    architecture alignment required for DMA.
100246a6d51cSAnton staaf  *
100346a6d51cSAnton staaf  * 3) The aligned portion contains enough space for the original number of
100446a6d51cSAnton staaf  *    elements requested.
100546a6d51cSAnton staaf  *
100646a6d51cSAnton staaf  * The macro then creates a pointer to the aligned portion of this array and
100746a6d51cSAnton staaf  * assigns to the pointer the address of the first element in the aligned
100846a6d51cSAnton staaf  * portion of the array.
100946a6d51cSAnton staaf  *
101046a6d51cSAnton staaf  * Calling the macro as:
101146a6d51cSAnton staaf  *
101246a6d51cSAnton staaf  *     ALLOC_CACHE_ALIGN_BUFFER(uint32_t, buffer, 1024);
101346a6d51cSAnton staaf  *
101446a6d51cSAnton staaf  * Will result in something similar to saying:
101546a6d51cSAnton staaf  *
101646a6d51cSAnton staaf  *     uint32_t    buffer[1024];
101746a6d51cSAnton staaf  *
101846a6d51cSAnton staaf  * The following differences exist:
101946a6d51cSAnton staaf  *
102046a6d51cSAnton staaf  * 1) The resulting buffer is guaranteed to be aligned to the value of
102146a6d51cSAnton staaf  *    ARCH_DMA_MINALIGN.
102246a6d51cSAnton staaf  *
102346a6d51cSAnton staaf  * 2) The buffer variable created by the macro is a pointer to the specified
102446a6d51cSAnton staaf  *    type, and NOT an array of the specified type.  This can be very important
102546a6d51cSAnton staaf  *    if you want the address of the buffer, which you probably do, to pass it
102646a6d51cSAnton staaf  *    to the DMA hardware.  The value of &buffer is different in the two cases.
102746a6d51cSAnton staaf  *    In the macro case it will be the address of the pointer, not the address
102846a6d51cSAnton staaf  *    of the space reserved for the buffer.  However, in the second case it
102946a6d51cSAnton staaf  *    would be the address of the buffer.  So if you are replacing hard coded
103046a6d51cSAnton staaf  *    stack buffers with this macro you need to make sure you remove the & from
103146a6d51cSAnton staaf  *    the locations where you are taking the address of the buffer.
103246a6d51cSAnton staaf  *
103346a6d51cSAnton staaf  * Note that the size parameter is the number of array elements to allocate,
103446a6d51cSAnton staaf  * not the number of bytes.
103546a6d51cSAnton staaf  *
103646a6d51cSAnton staaf  * This macro can not be used outside of function scope, or for the creation
103746a6d51cSAnton staaf  * of a function scoped static buffer.  It can not be used to create a cache
103846a6d51cSAnton staaf  * line aligned global buffer.
103946a6d51cSAnton staaf  */
1040e8232feaSMischa Jonker #define PAD_COUNT(s, pad) (((s) - 1) / (pad) + 1)
1041ae1768a7SEgbert Eich #define PAD_SIZE(s, pad) (PAD_COUNT(s, pad) * pad)
1042ae1768a7SEgbert Eich #define ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, pad)		\
1043e8232feaSMischa Jonker 	char __##name[ROUND(PAD_SIZE((size) * sizeof(type), pad), align)  \
1044ae1768a7SEgbert Eich 		      + (align - 1)];					\
104546a6d51cSAnton staaf 									\
1046de4d1135SMarek Vasut 	type *name = (type *) ALIGN((uintptr_t)__##name, align)
1047ae1768a7SEgbert Eich #define ALLOC_ALIGN_BUFFER(type, name, size, align)		\
1048ae1768a7SEgbert Eich 	ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, 1)
1049ae1768a7SEgbert Eich #define ALLOC_CACHE_ALIGN_BUFFER_PAD(type, name, size, pad)		\
1050ae1768a7SEgbert Eich 	ALLOC_ALIGN_BUFFER_PAD(type, name, size, ARCH_DMA_MINALIGN, pad)
1051de4d1135SMarek Vasut #define ALLOC_CACHE_ALIGN_BUFFER(type, name, size)			\
1052de4d1135SMarek Vasut 	ALLOC_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
1053de4d1135SMarek Vasut 
1054de4d1135SMarek Vasut /*
1055de4d1135SMarek Vasut  * DEFINE_CACHE_ALIGN_BUFFER() is similar to ALLOC_CACHE_ALIGN_BUFFER, but it's
1056de4d1135SMarek Vasut  * purpose is to allow allocating aligned buffers outside of function scope.
1057de4d1135SMarek Vasut  * Usage of this macro shall be avoided or used with extreme care!
1058de4d1135SMarek Vasut  */
1059de4d1135SMarek Vasut #define DEFINE_ALIGN_BUFFER(type, name, size, align)			\
1060de4d1135SMarek Vasut 	static char __##name[roundup(size * sizeof(type), align)]	\
1061d7ea4d4dSEgbert Eich 			__aligned(align);				\
1062de4d1135SMarek Vasut 									\
1063de4d1135SMarek Vasut 	static type *name = (type *)__##name
1064de4d1135SMarek Vasut #define DEFINE_CACHE_ALIGN_BUFFER(type, name, size)			\
1065de4d1135SMarek Vasut 	DEFINE_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
106646a6d51cSAnton staaf 
1067c3eb3fe4SMike Frysinger /* Pull in stuff for the build system */
1068c3eb3fe4SMike Frysinger #ifdef DO_DEPS_ONLY
1069c3eb3fe4SMike Frysinger # include <environment.h>
1070c3eb3fe4SMike Frysinger #endif
1071c3eb3fe4SMike Frysinger 
1072e2211743Swdenk #endif	/* __COMMON_H_ */
1073