common.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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/u-boot-arm.h> /* ARM version to be fixed! */
  165. #endif /* CONFIG_ARM */
  166. #ifdef CONFIG_I386 /* x86 version to be fixed! */
  167. # include <asm/u-boot-i386.h>
  168. #endif /* CONFIG_I386 */
  169. void pci_init (void);
  170. void pci_init_board(void);
  171. void pciinfo (int, int);
  172. #if defined(CONFIG_PCI) && defined(CONFIG_440)
  173. # if defined(CFG_PCI_PRE_INIT)
  174. int pci_pre_init (struct pci_controller * );
  175. # endif
  176. # if defined(CFG_PCI_TARGET_INIT)
  177. void pci_target_init (struct pci_controller *);
  178. # endif
  179. # if defined(CFG_PCI_MASTER_INIT)
  180. void pci_master_init (struct pci_controller *);
  181. # endif
  182. int is_pci_host (struct pci_controller *);
  183. #endif
  184. int misc_init_f (void);
  185. int misc_init_r (void);
  186. /* common/exports.c */
  187. void jumptable_init(void);
  188. /* $(BOARD)/$(BOARD).c */
  189. void reset_phy (void);
  190. void fdc_hw_init (void);
  191. /* $(BOARD)/eeprom.c */
  192. void eeprom_init (void);
  193. #ifndef CONFIG_SPI
  194. int eeprom_probe (unsigned dev_addr, unsigned offset);
  195. #endif
  196. int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  197. int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  198. #ifdef CONFIG_LWMON
  199. extern uchar pic_read (uchar reg);
  200. extern void pic_write (uchar reg, uchar val);
  201. #endif
  202. /*
  203. * Set this up regardless of board
  204. * type, to prevent errors.
  205. */
  206. #if defined(CONFIG_SPI) || !defined(CFG_I2C_EEPROM_ADDR)
  207. # define CFG_DEF_EEPROM_ADDR 0
  208. #else
  209. # define CFG_DEF_EEPROM_ADDR CFG_I2C_EEPROM_ADDR
  210. #endif /* CONFIG_SPI || !defined(CFG_I2C_EEPROM_ADDR) */
  211. #if defined(CONFIG_SPI)
  212. extern void spi_init_f (void);
  213. extern void spi_init_r (void);
  214. extern ssize_t spi_read (uchar *, int, uchar *, int);
  215. extern ssize_t spi_write (uchar *, int, uchar *, int);
  216. #endif
  217. #ifdef CONFIG_RPXCLASSIC
  218. void rpxclassic_init (void);
  219. #endif
  220. #ifdef CONFIG_MBX
  221. /* $(BOARD)/mbx8xx.c */
  222. void mbx_init (void);
  223. void board_serial_init (void);
  224. void board_ether_init (void);
  225. #endif
  226. #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_MBX) || defined(CONFIG_IAD210)
  227. void board_get_enetaddr (uchar *addr);
  228. #endif
  229. #ifdef CONFIG_HERMES
  230. /* $(BOARD)/hermes.c */
  231. void hermes_start_lxt980 (int speed);
  232. #endif
  233. #ifdef CONFIG_EVB64260
  234. void evb64260_init(void);
  235. void debug_led(int, int);
  236. void display_mem_map(void);
  237. void perform_soft_reset(void);
  238. #endif
  239. void load_sernum_ethaddr (void);
  240. /* $(BOARD)/$(BOARD).c */
  241. int board_pre_init (void);
  242. int board_post_init (void);
  243. int board_postclk_init (void); /* after clocks/timebase, before env/serial */
  244. void board_poweroff (void);
  245. #if defined(CFG_DRAM_TEST)
  246. int testdram(void);
  247. #endif /* CFG_DRAM_TEST */
  248. /* $(CPU)/start.S */
  249. #if defined(CONFIG_5xx) || \
  250. defined(CONFIG_8xx)
  251. uint get_immr (uint);
  252. #endif
  253. uint get_pir (void);
  254. uint get_pvr (void);
  255. uint rd_ic_cst (void);
  256. void wr_ic_cst (uint);
  257. void wr_ic_adr (uint);
  258. uint rd_dc_cst (void);
  259. void wr_dc_cst (uint);
  260. void wr_dc_adr (uint);
  261. int icache_status (void);
  262. void icache_enable (void);
  263. void icache_disable(void);
  264. int dcache_status (void);
  265. void dcache_enable (void);
  266. void dcache_disable(void);
  267. void relocate_code (ulong, gd_t *, ulong);
  268. ulong get_endaddr (void);
  269. void trap_init (ulong);
  270. #if defined (CONFIG_4xx) || \
  271. defined (CONFIG_74xx_7xx) || \
  272. defined (CONFIG_74x) || \
  273. defined (CONFIG_75x) || \
  274. defined (CONFIG_74xx)
  275. unsigned char in8(unsigned int);
  276. void out8(unsigned int, unsigned char);
  277. unsigned short in16(unsigned int);
  278. unsigned short in16r(unsigned int);
  279. void out16(unsigned int, unsigned short value);
  280. void out16r(unsigned int, unsigned short value);
  281. unsigned long in32(unsigned int);
  282. unsigned long in32r(unsigned int);
  283. void out32(unsigned int, unsigned long value);
  284. void out32r(unsigned int, unsigned long value);
  285. void ppcDcbf(unsigned long value);
  286. void ppcDcbi(unsigned long value);
  287. void ppcSync(void);
  288. #endif
  289. /* $(CPU)/cpu.c */
  290. int checkcpu (void);
  291. int checkicache (void);
  292. int checkdcache (void);
  293. void upmconfig (unsigned int, unsigned int *, unsigned int);
  294. ulong get_tbclk (void);
  295. /* $(CPU)/serial.c */
  296. int serial_init (void);
  297. void serial_setbrg (void);
  298. void serial_putc (const char);
  299. void serial_puts (const char *);
  300. void serial_addr (unsigned int);
  301. int serial_getc (void);
  302. int serial_tstc (void);
  303. /* $(CPU)/speed.c */
  304. int get_clocks (void);
  305. #if defined(CONFIG_8260)
  306. int prt_8260_clks (void);
  307. #endif
  308. #if defined(CONFIG_MPC5XXX)
  309. int prt_mpc5xxx_clks (void);
  310. #endif
  311. #ifdef CONFIG_4xx
  312. ulong get_OPB_freq (void);
  313. ulong get_PCI_freq (void);
  314. #endif
  315. #if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410)
  316. ulong get_FCLK (void);
  317. ulong get_HCLK (void);
  318. ulong get_PCLK (void);
  319. ulong get_UCLK (void);
  320. #endif
  321. #if defined CONFIG_INCA_IP
  322. uint incaip_get_cpuclk (void);
  323. #endif
  324. ulong get_bus_freq (ulong);
  325. #if defined(CONFIG_MPC85xx)
  326. typedef MPC85xx_SYS_INFO sys_info_t;
  327. void get_sys_info ( sys_info_t * );
  328. #endif
  329. #if defined(CONFIG_4xx) || defined(CONFIG_IOP480)
  330. # if defined(CONFIG_440)
  331. typedef PPC440_SYS_INFO sys_info_t;
  332. # else
  333. typedef PPC405_SYS_INFO sys_info_t;
  334. # endif
  335. void get_sys_info ( sys_info_t * );
  336. #endif
  337. /* $(CPU)/cpu_init.c */
  338. #if defined(CONFIG_8xx) || defined(CONFIG_8260)
  339. void cpu_init_f (volatile immap_t *immr);
  340. #endif
  341. #if defined(CONFIG_4xx) || defined(CONFIG_MPC85xx)
  342. void cpu_init_f (void);
  343. #endif
  344. int cpu_init_r (void);
  345. #if defined(CONFIG_8260)
  346. int prt_8260_rsr (void);
  347. #endif
  348. /* $(CPU)/interrupts.c */
  349. int interrupt_init (void);
  350. void timer_interrupt (struct pt_regs *);
  351. void external_interrupt (struct pt_regs *);
  352. void irq_install_handler(int, interrupt_handler_t *, void *);
  353. void irq_free_handler (int);
  354. void reset_timer (void);
  355. ulong get_timer (ulong base);
  356. void set_timer (ulong t);
  357. void enable_interrupts (void);
  358. int disable_interrupts (void);
  359. /* $(CPU)/.../commproc.c */
  360. int dpram_init (void);
  361. uint dpram_base(void);
  362. uint dpram_base_align(uint align);
  363. uint dpram_alloc(uint size);
  364. uint dpram_alloc_align(uint size,uint align);
  365. void post_word_store (ulong);
  366. ulong post_word_load (void);
  367. void bootcount_store (ulong);
  368. ulong bootcount_load (void);
  369. #define BOOTCOUNT_MAGIC 0xB001C041
  370. /* $(CPU)/.../<eth> */
  371. void mii_init (void);
  372. /* $(CPU)/.../lcd.c */
  373. ulong lcd_setmem (ulong);
  374. /* $(CPU)/.../vfd.c */
  375. ulong vfd_setmem (ulong);
  376. /* $(CPU)/.../video.c */
  377. ulong video_setmem (ulong);
  378. /* ppc/cache.c */
  379. void flush_cache (unsigned long, unsigned long);
  380. /* lib_$(ARCH)/ticks.S */
  381. unsigned long long get_ticks(void);
  382. void wait_ticks (unsigned long);
  383. /* lib_$(ARCH)/time.c */
  384. void udelay (unsigned long);
  385. ulong usec2ticks (unsigned long usec);
  386. ulong ticks2usec (unsigned long ticks);
  387. int init_timebase (void);
  388. /* lib_generic/vsprintf.c */
  389. ulong simple_strtoul(const char *cp,char **endp,unsigned int base);
  390. long simple_strtol(const char *cp,char **endp,unsigned int base);
  391. void panic(const char *fmt, ...);
  392. int sprintf(char * buf, const char *fmt, ...);
  393. int vsprintf(char *buf, const char *fmt, va_list args);
  394. /* lib_generic/crc32.c */
  395. ulong crc32 (ulong, const unsigned char *, uint);
  396. ulong crc32_no_comp (ulong, const unsigned char *, uint);
  397. /* common/console.c */
  398. int console_init_f(void); /* Before relocation; uses the serial stuff */
  399. int console_init_r(void); /* After relocation; uses the console stuff */
  400. int console_assign (int file, char *devname); /* Assign the console */
  401. int ctrlc (void);
  402. int had_ctrlc (void); /* have we had a Control-C since last clear? */
  403. void clear_ctrlc (void); /* clear the Control-C condition */
  404. int disable_ctrlc (int); /* 1 to disable, 0 to enable Control-C detect */
  405. /*
  406. * STDIO based functions (can always be used)
  407. */
  408. /* serial stuff */
  409. void serial_printf (const char *fmt, ...);
  410. /* stdin */
  411. int getc(void);
  412. int tstc(void);
  413. /* stdout */
  414. void putc(const char c);
  415. void puts(const char *s);
  416. void printf(const char *fmt, ...);
  417. void vprintf(const char *fmt, va_list args);
  418. /* stderr */
  419. #define eputc(c) fputc(stderr, c)
  420. #define eputs(s) fputs(stderr, s)
  421. #define eprintf(fmt,args...) fprintf(stderr,fmt ,##args)
  422. /*
  423. * FILE based functions (can only be used AFTER relocation!)
  424. */
  425. #define stdin 0
  426. #define stdout 1
  427. #define stderr 2
  428. #define MAX_FILES 3
  429. void fprintf(int file, const char *fmt, ...);
  430. void fputs(int file, const char *s);
  431. void fputc(int file, const char c);
  432. int ftstc(int file);
  433. int fgetc(int file);
  434. int pcmcia_init (void);
  435. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  436. void show_boot_progress (int status);
  437. #endif
  438. #endif /* __COMMON_H_ */