common.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. /*
  2. * (C) Copyright 2000-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef __COMMON_H_
  24. #define __COMMON_H_ 1
  25. #undef _LINUX_CONFIG_H
  26. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  27. typedef unsigned char uchar;
  28. typedef volatile unsigned long vu_long;
  29. typedef volatile unsigned short vu_short;
  30. typedef volatile unsigned char vu_char;
  31. #include <config.h>
  32. #include <linux/bitops.h>
  33. #include <linux/types.h>
  34. #include <linux/string.h>
  35. #include <asm/ptrace.h>
  36. #include <stdarg.h>
  37. #if defined(CONFIG_PCI) && defined(CONFIG_440)
  38. #include <pci.h>
  39. #endif
  40. #ifdef CONFIG_8xx
  41. #include <asm/8xx_immap.h>
  42. #ifdef CONFIG_MPC860
  43. #define CONFIG_MPC86x 1
  44. #endif
  45. #ifdef CONFIG_MPC860T
  46. #define CONFIG_MPC86x 1
  47. #endif
  48. #if defined(CONFIG_MPC852) || defined(CONFIG_MPC852T) || \
  49. defined(CONFIG_MPC859) || defined(CONFIG_MPC859T) || \
  50. defined(CONFIG_MPC859DSL) || \
  51. defined(CONFIG_MPC866) || defined(CONFIG_MPC866T) || \
  52. defined(CONFIG_MPC866P)
  53. #define CONFIG_MPC866_et_al 1
  54. #define CONFIG_MPC86x 1
  55. #endif
  56. #elif defined(CONFIG_5xx)
  57. #include <asm/5xx_immap.h>
  58. #elif defined(CONFIG_8260)
  59. #include <asm/immap_8260.h>
  60. #endif
  61. #ifdef CONFIG_MPC85xx
  62. #include <mpc85xx.h>
  63. #include <asm/immap_85xx.h>
  64. #endif
  65. #ifdef CONFIG_4xx
  66. #include <ppc4xx.h>
  67. #endif
  68. #ifdef CONFIG_HYMOD
  69. #include <board/hymod/hymod.h>
  70. #endif
  71. #ifdef CONFIG_ARM
  72. #define asmlinkage /* nothing */
  73. #endif
  74. #include <part.h>
  75. #include <flash.h>
  76. #include <image.h>
  77. #ifdef DEBUG
  78. #define debug(fmt,args...) printf (fmt ,##args)
  79. #define debugX(level,fmt,args...) if (DEBUG>=level) printf(fmt,##args);
  80. #else
  81. #define debug(fmt,args...)
  82. #define debugX(level,fmt,args...)
  83. #endif /* DEBUG */
  84. typedef void (interrupt_handler_t)(void *);
  85. #include <asm/u-boot.h> /* boot information for Linux kernel */
  86. #include <asm/global_data.h> /* global data used for startup functions */
  87. /*
  88. * enable common handling for all TQM8xxL/M boards:
  89. * - CONFIG_TQM8xxM will be defined for all TQM8xxM boards
  90. * - CONFIG_TQM8xxL will be defined for all TQM8xxL _and_ TQM8xxM boards
  91. */
  92. #if defined(CONFIG_TQM823M) || defined(CONFIG_TQM850M) || \
  93. defined(CONFIG_TQM855M) || defined(CONFIG_TQM860M) || \
  94. defined(CONFIG_TQM862M) || defined(CONFIG_TQM866M)
  95. # ifndef CONFIG_TQM8xxM
  96. # define CONFIG_TQM8xxM
  97. # endif
  98. #endif
  99. #if defined(CONFIG_TQM823L) || defined(CONFIG_TQM850L) || \
  100. defined(CONFIG_TQM855L) || defined(CONFIG_TQM860L) || \
  101. defined(CONFIG_TQM862L) || defined(CONFIG_TQM8xxM)
  102. # ifndef CONFIG_TQM8xxL
  103. # define CONFIG_TQM8xxL
  104. # endif
  105. #endif
  106. /*
  107. * General Purpose Utilities
  108. */
  109. #define min(X, Y) \
  110. ({ typeof (X) __x = (X), __y = (Y); \
  111. (__x < __y) ? __x : __y; })
  112. #define max(X, Y) \
  113. ({ typeof (X) __x = (X), __y = (Y); \
  114. (__x > __y) ? __x : __y; })
  115. /*
  116. * Function Prototypes
  117. */
  118. #if CONFIG_SERIAL_SOFTWARE_FIFO
  119. void serial_buffered_init (void);
  120. void serial_buffered_putc (const char);
  121. void serial_buffered_puts (const char *);
  122. int serial_buffered_getc (void);
  123. int serial_buffered_tstc (void);
  124. #endif /* CONFIG_SERIAL_SOFTWARE_FIFO */
  125. void hang (void) __attribute__ ((noreturn));
  126. /* */
  127. long int initdram (int);
  128. int display_options (void);
  129. void print_size (ulong, const char *);
  130. /* common/main.c */
  131. void main_loop (void);
  132. int run_command (const char *cmd, int flag);
  133. int readline (const char *const prompt);
  134. void init_cmd_timeout(void);
  135. void reset_cmd_timeout(void);
  136. /* lib_$(ARCH)/board.c */
  137. void board_init_f (ulong);
  138. void board_init_r (gd_t *, ulong);
  139. int checkboard (void);
  140. int checkflash (void);
  141. int checkdram (void);
  142. char * strmhz(char *buf, long hz);
  143. int last_stage_init(void);
  144. extern ulong monitor_flash_len;
  145. /* common/flash.c */
  146. void flash_perror (int);
  147. /* common/cmd_autoscript.c */
  148. int autoscript (ulong addr);
  149. /* common/cmd_bootm.c */
  150. void print_image_hdr (image_header_t *hdr);
  151. extern ulong load_addr; /* Default Load Address */
  152. /* common/cmd_nvedit.c */
  153. int env_init (void);
  154. void env_relocate (void);
  155. char *getenv (uchar *);
  156. int getenv_r (uchar *name, uchar *buf, unsigned len);
  157. int saveenv (void);
  158. #ifdef CONFIG_PPC /* ARM version to be fixed! */
  159. void inline setenv (char *, char *);
  160. #else
  161. void setenv (char *, char *);
  162. #endif /* CONFIG_PPC */
  163. #ifdef CONFIG_ARM
  164. # include <asm/setup.h>
  165. # include <asm/u-boot-arm.h> /* ARM version to be fixed! */
  166. #endif /* CONFIG_ARM */
  167. #ifdef CONFIG_I386 /* x86 version to be fixed! */
  168. # include <asm/u-boot-i386.h>
  169. #endif /* CONFIG_I386 */
  170. void pci_init (void);
  171. void pci_init_board(void);
  172. void pciinfo (int, int);
  173. #if defined(CONFIG_PCI) && defined(CONFIG_440)
  174. # if defined(CFG_PCI_PRE_INIT)
  175. int pci_pre_init (struct pci_controller * );
  176. # endif
  177. # if defined(CFG_PCI_TARGET_INIT)
  178. void pci_target_init (struct pci_controller *);
  179. # endif
  180. # if defined(CFG_PCI_MASTER_INIT)
  181. void pci_master_init (struct pci_controller *);
  182. # endif
  183. int is_pci_host (struct pci_controller *);
  184. #endif
  185. int misc_init_f (void);
  186. int misc_init_r (void);
  187. /* common/exports.c */
  188. void jumptable_init(void);
  189. /* $(BOARD)/$(BOARD).c */
  190. void reset_phy (void);
  191. void fdc_hw_init (void);
  192. /* $(BOARD)/eeprom.c */
  193. void eeprom_init (void);
  194. #ifndef CONFIG_SPI
  195. int eeprom_probe (unsigned dev_addr, unsigned offset);
  196. #endif
  197. int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  198. int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  199. #ifdef CONFIG_LWMON
  200. extern uchar pic_read (uchar reg);
  201. extern void pic_write (uchar reg, uchar val);
  202. #endif
  203. /*
  204. * Set this up regardless of board
  205. * type, to prevent errors.
  206. */
  207. #if defined(CONFIG_SPI) || !defined(CFG_I2C_EEPROM_ADDR)
  208. # define CFG_DEF_EEPROM_ADDR 0
  209. #else
  210. # define CFG_DEF_EEPROM_ADDR CFG_I2C_EEPROM_ADDR
  211. #endif /* CONFIG_SPI || !defined(CFG_I2C_EEPROM_ADDR) */
  212. #if defined(CONFIG_SPI)
  213. extern void spi_init_f (void);
  214. extern void spi_init_r (void);
  215. extern ssize_t spi_read (uchar *, int, uchar *, int);
  216. extern ssize_t spi_write (uchar *, int, uchar *, int);
  217. #endif
  218. #ifdef CONFIG_RPXCLASSIC
  219. void rpxclassic_init (void);
  220. #endif
  221. #ifdef CONFIG_MBX
  222. /* $(BOARD)/mbx8xx.c */
  223. void mbx_init (void);
  224. void board_serial_init (void);
  225. void board_ether_init (void);
  226. #endif
  227. #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_MBX) || defined(CONFIG_IAD210)
  228. void board_get_enetaddr (uchar *addr);
  229. #endif
  230. #ifdef CONFIG_HERMES
  231. /* $(BOARD)/hermes.c */
  232. void hermes_start_lxt980 (int speed);
  233. #endif
  234. #ifdef CONFIG_EVB64260
  235. void evb64260_init(void);
  236. void debug_led(int, int);
  237. void display_mem_map(void);
  238. void perform_soft_reset(void);
  239. #endif
  240. void load_sernum_ethaddr (void);
  241. /* $(BOARD)/$(BOARD).c */
  242. int board_pre_init (void);
  243. int board_post_init (void);
  244. int board_postclk_init (void); /* after clocks/timebase, before env/serial */
  245. void board_poweroff (void);
  246. #if defined(CFG_DRAM_TEST)
  247. int testdram(void);
  248. #endif /* CFG_DRAM_TEST */
  249. /* $(CPU)/start.S */
  250. #if defined(CONFIG_5xx) || \
  251. defined(CONFIG_8xx)
  252. uint get_immr (uint);
  253. #endif
  254. uint get_pir (void);
  255. uint get_pvr (void);
  256. uint rd_ic_cst (void);
  257. void wr_ic_cst (uint);
  258. void wr_ic_adr (uint);
  259. uint rd_dc_cst (void);
  260. void wr_dc_cst (uint);
  261. void wr_dc_adr (uint);
  262. int icache_status (void);
  263. void icache_enable (void);
  264. void icache_disable(void);
  265. int dcache_status (void);
  266. void dcache_enable (void);
  267. void dcache_disable(void);
  268. void relocate_code (ulong, gd_t *, ulong);
  269. ulong get_endaddr (void);
  270. void trap_init (ulong);
  271. #if defined (CONFIG_4xx) || \
  272. defined (CONFIG_74xx_7xx) || \
  273. defined (CONFIG_74x) || \
  274. defined (CONFIG_75x) || \
  275. defined (CONFIG_74xx)
  276. unsigned char in8(unsigned int);
  277. void out8(unsigned int, unsigned char);
  278. unsigned short in16(unsigned int);
  279. unsigned short in16r(unsigned int);
  280. void out16(unsigned int, unsigned short value);
  281. void out16r(unsigned int, unsigned short value);
  282. unsigned long in32(unsigned int);
  283. unsigned long in32r(unsigned int);
  284. void out32(unsigned int, unsigned long value);
  285. void out32r(unsigned int, unsigned long value);
  286. void ppcDcbf(unsigned long value);
  287. void ppcDcbi(unsigned long value);
  288. void ppcSync(void);
  289. #endif
  290. /* $(CPU)/cpu.c */
  291. int checkcpu (void);
  292. int checkicache (void);
  293. int checkdcache (void);
  294. void upmconfig (unsigned int, unsigned int *, unsigned int);
  295. ulong get_tbclk (void);
  296. /* $(CPU)/serial.c */
  297. int serial_init (void);
  298. void serial_setbrg (void);
  299. void serial_putc (const char);
  300. void serial_puts (const char *);
  301. void serial_addr (unsigned int);
  302. int serial_getc (void);
  303. int serial_tstc (void);
  304. /* $(CPU)/speed.c */
  305. int get_clocks (void);
  306. #if defined(CONFIG_8260)
  307. int prt_8260_clks (void);
  308. #endif
  309. #if defined(CONFIG_MPC5XXX)
  310. int prt_mpc5xxx_clks (void);
  311. #endif
  312. #ifdef CONFIG_4xx
  313. ulong get_OPB_freq (void);
  314. ulong get_PCI_freq (void);
  315. #endif
  316. #if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410)
  317. ulong get_FCLK (void);
  318. ulong get_HCLK (void);
  319. ulong get_PCLK (void);
  320. ulong get_UCLK (void);
  321. #endif
  322. #if defined CONFIG_INCA_IP
  323. uint incaip_get_cpuclk (void);
  324. #endif
  325. ulong get_bus_freq (ulong);
  326. #if defined(CONFIG_MPC85xx)
  327. typedef MPC85xx_SYS_INFO sys_info_t;
  328. void get_sys_info ( sys_info_t * );
  329. #endif
  330. #if defined(CONFIG_4xx) || defined(CONFIG_IOP480)
  331. # if defined(CONFIG_440)
  332. typedef PPC440_SYS_INFO sys_info_t;
  333. # else
  334. typedef PPC405_SYS_INFO sys_info_t;
  335. # endif
  336. void get_sys_info ( sys_info_t * );
  337. #endif
  338. /* $(CPU)/cpu_init.c */
  339. #if defined(CONFIG_8xx) || defined(CONFIG_8260)
  340. void cpu_init_f (volatile immap_t *immr);
  341. #endif
  342. #if defined(CONFIG_4xx) || defined(CONFIG_MPC85xx)
  343. void cpu_init_f (void);
  344. #endif
  345. int cpu_init_r (void);
  346. #if defined(CONFIG_8260)
  347. int prt_8260_rsr (void);
  348. #endif
  349. /* $(CPU)/interrupts.c */
  350. int interrupt_init (void);
  351. void timer_interrupt (struct pt_regs *);
  352. void external_interrupt (struct pt_regs *);
  353. void irq_install_handler(int, interrupt_handler_t *, void *);
  354. void irq_free_handler (int);
  355. void reset_timer (void);
  356. ulong get_timer (ulong base);
  357. void set_timer (ulong t);
  358. void enable_interrupts (void);
  359. int disable_interrupts (void);
  360. /* $(CPU)/.../commproc.c */
  361. int dpram_init (void);
  362. uint dpram_base(void);
  363. uint dpram_base_align(uint align);
  364. uint dpram_alloc(uint size);
  365. uint dpram_alloc_align(uint size,uint align);
  366. void post_word_store (ulong);
  367. ulong post_word_load (void);
  368. void bootcount_store (ulong);
  369. ulong bootcount_load (void);
  370. #define BOOTCOUNT_MAGIC 0xB001C041
  371. /* $(CPU)/.../<eth> */
  372. void mii_init (void);
  373. /* $(CPU)/.../lcd.c */
  374. ulong lcd_setmem (ulong);
  375. /* $(CPU)/.../vfd.c */
  376. ulong vfd_setmem (ulong);
  377. /* $(CPU)/.../video.c */
  378. ulong video_setmem (ulong);
  379. /* ppc/cache.c */
  380. void flush_cache (unsigned long, unsigned long);
  381. /* lib_$(ARCH)/ticks.S */
  382. unsigned long long get_ticks(void);
  383. void wait_ticks (unsigned long);
  384. /* lib_$(ARCH)/time.c */
  385. void udelay (unsigned long);
  386. ulong usec2ticks (unsigned long usec);
  387. ulong ticks2usec (unsigned long ticks);
  388. int init_timebase (void);
  389. /* lib_generic/vsprintf.c */
  390. ulong simple_strtoul(const char *cp,char **endp,unsigned int base);
  391. long simple_strtol(const char *cp,char **endp,unsigned int base);
  392. void panic(const char *fmt, ...);
  393. int sprintf(char * buf, const char *fmt, ...);
  394. int vsprintf(char *buf, const char *fmt, va_list args);
  395. /* lib_generic/crc32.c */
  396. ulong crc32 (ulong, const unsigned char *, uint);
  397. ulong crc32_no_comp (ulong, const unsigned char *, uint);
  398. /* common/console.c */
  399. int console_init_f(void); /* Before relocation; uses the serial stuff */
  400. int console_init_r(void); /* After relocation; uses the console stuff */
  401. int console_assign (int file, char *devname); /* Assign the console */
  402. int ctrlc (void);
  403. int had_ctrlc (void); /* have we had a Control-C since last clear? */
  404. void clear_ctrlc (void); /* clear the Control-C condition */
  405. int disable_ctrlc (int); /* 1 to disable, 0 to enable Control-C detect */
  406. /*
  407. * STDIO based functions (can always be used)
  408. */
  409. /* serial stuff */
  410. void serial_printf (const char *fmt, ...);
  411. /* stdin */
  412. int getc(void);
  413. int tstc(void);
  414. /* stdout */
  415. void putc(const char c);
  416. void puts(const char *s);
  417. void printf(const char *fmt, ...);
  418. void vprintf(const char *fmt, va_list args);
  419. /* stderr */
  420. #define eputc(c) fputc(stderr, c)
  421. #define eputs(s) fputs(stderr, s)
  422. #define eprintf(fmt,args...) fprintf(stderr,fmt ,##args)
  423. /*
  424. * FILE based functions (can only be used AFTER relocation!)
  425. */
  426. #define stdin 0
  427. #define stdout 1
  428. #define stderr 2
  429. #define MAX_FILES 3
  430. void fprintf(int file, const char *fmt, ...);
  431. void fputs(int file, const char *s);
  432. void fputc(int file, const char c);
  433. int ftstc(int file);
  434. int fgetc(int file);
  435. int pcmcia_init (void);
  436. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  437. void show_boot_progress (int status);
  438. #endif
  439. #endif /* __COMMON_H_ */