common.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /*
  2. * (C) Copyright 2000-2002
  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. #elif defined(CONFIG_5xx)
  43. #include <asm/5xx_immap.h>
  44. #elif defined(CONFIG_8260)
  45. #include <asm/immap_8260.h>
  46. #endif
  47. #ifdef CONFIG_4xx
  48. #include <ppc4xx.h>
  49. #endif
  50. #ifdef CONFIG_HYMOD
  51. #include <board/hymod/hymod.h>
  52. #endif
  53. #ifdef CONFIG_ARM
  54. #define asmlinkage /* nothing */
  55. #endif
  56. #include <part.h>
  57. #include <flash.h>
  58. #include <image.h>
  59. #ifdef DEBUG
  60. #define debug(fmt,args...) printf (fmt ,##args)
  61. #define debugX(level,fmt,args...) if (DEBUG>=level) printf(fmt,##args);
  62. #else
  63. #define debug(fmt,args...)
  64. #define debugX(level,fmt,args...)
  65. #endif /* DEBUG */
  66. typedef void (interrupt_handler_t)(void *);
  67. #include <asm/u-boot.h> /* boot information for Linux kernel */
  68. #include <asm/global_data.h> /* global data used for startup functions */
  69. /*
  70. * enable common handling for all TQM8xxL/M boards:
  71. * - CONFIG_TQM8xxM will be defined for all TQM8xxM boards
  72. * - CONFIG_TQM8xxL will be defined for all TQM8xxL _and_ TQM8xxM boards
  73. */
  74. #if defined(CONFIG_TQM823M) || defined(CONFIG_TQM850M) || \
  75. defined(CONFIG_TQM855M) || defined(CONFIG_TQM860M) || \
  76. defined(CONFIG_TQM862M)
  77. # ifndef CONFIG_TQM8xxM
  78. # define CONFIG_TQM8xxM
  79. # endif
  80. #endif
  81. #if defined(CONFIG_TQM823L) || defined(CONFIG_TQM850L) || \
  82. defined(CONFIG_TQM855L) || defined(CONFIG_TQM860L) || \
  83. defined(CONFIG_TQM862L) || defined(CONFIG_TQM8xxM)
  84. # ifndef CONFIG_TQM8xxL
  85. # define CONFIG_TQM8xxL
  86. # endif
  87. #endif
  88. /*
  89. * General Purpose Utilities
  90. */
  91. #define min(X, Y) \
  92. ({ typeof (X) __x = (X), __y = (Y); \
  93. (__x < __y) ? __x : __y; })
  94. #define max(X, Y) \
  95. ({ typeof (X) __x = (X), __y = (Y); \
  96. (__x > __y) ? __x : __y; })
  97. /*
  98. * Function Prototypes
  99. */
  100. #if CONFIG_SERIAL_SOFTWARE_FIFO
  101. void serial_buffered_init (void);
  102. void serial_buffered_putc (const char);
  103. void serial_buffered_puts (const char *);
  104. int serial_buffered_getc (void);
  105. int serial_buffered_tstc (void);
  106. #endif /* CONFIG_SERIAL_SOFTWARE_FIFO */
  107. void hang (void) __attribute__ ((noreturn));
  108. /* */
  109. long int initdram (int);
  110. int display_options (void);
  111. void print_size (ulong, const char *);
  112. /* common/main.c */
  113. void main_loop (void);
  114. int run_command (const char *cmd, int flag);
  115. int readline (const char *const prompt);
  116. void init_cmd_timeout(void);
  117. void reset_cmd_timeout(void);
  118. /* common/board.c */
  119. void board_init_f (ulong);
  120. void board_init_r (gd_t *, ulong);
  121. int checkboard (void);
  122. int checkflash (void);
  123. int checkdram (void);
  124. char * strmhz(char *buf, long hz);
  125. int last_stage_init(void);
  126. extern ulong monitor_flash_len;
  127. /* common/flash.c */
  128. void flash_perror (int);
  129. /* common/cmd_bootm.c */
  130. void print_image_hdr (image_header_t *hdr);
  131. extern ulong load_addr; /* Default Load Address */
  132. /* common/cmd_nvedit.c */
  133. int env_init (void);
  134. void env_relocate (void);
  135. char *getenv (uchar *);
  136. int getenv_r (uchar *name, uchar *buf, unsigned len);
  137. int saveenv (void);
  138. #ifdef CONFIG_PPC /* ARM version to be fixed! */
  139. void inline setenv (char *, char *);
  140. #else
  141. void setenv (char *, char *);
  142. #endif /* CONFIG_PPC */
  143. #ifdef CONFIG_ARM
  144. # include <asm/u-boot-arm.h> /* ARM version to be fixed! */
  145. #endif /* CONFIG_ARM */
  146. #ifdef CONFIG_I386 /* x86 version to be fixed! */
  147. # include <asm/u-boot-i386.h>
  148. #endif /* CONFIG_I386 */
  149. void pci_init (void);
  150. void pci_init_board(void);
  151. void pciinfo (int, int);
  152. #if defined(CONFIG_PCI) && defined(CONFIG_440)
  153. # if defined(CFG_PCI_PRE_INIT)
  154. int pci_pre_init (struct pci_controller * );
  155. # endif
  156. # if defined(CFG_PCI_TARGET_INIT)
  157. void pci_target_init (struct pci_controller *);
  158. # endif
  159. # if defined(CFG_PCI_MASTER_INIT)
  160. void pci_master_init (struct pci_controller *);
  161. # endif
  162. int is_pci_host (struct pci_controller *);
  163. #endif
  164. int misc_init_f (void);
  165. int misc_init_r (void);
  166. /* $(BOARD)/$(BOARD).c */
  167. void reset_phy (void);
  168. void fdc_hw_init (void);
  169. /* $(BOARD)/eeprom.c */
  170. void eeprom_init (void);
  171. #ifndef CONFIG_SPI
  172. int eeprom_probe (unsigned dev_addr, unsigned offset);
  173. #endif
  174. int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  175. int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  176. #ifdef CONFIG_LWMON
  177. extern uchar pic_read (uchar reg);
  178. extern void pic_write (uchar reg, uchar val);
  179. #endif
  180. /*
  181. * Set this up regardless of board
  182. * type, to prevent errors.
  183. */
  184. #if defined(CONFIG_SPI) || !defined(CFG_I2C_EEPROM_ADDR)
  185. # define CFG_DEF_EEPROM_ADDR 0
  186. #else
  187. # define CFG_DEF_EEPROM_ADDR CFG_I2C_EEPROM_ADDR
  188. #endif /* CONFIG_SPI || !defined(CFG_I2C_EEPROM_ADDR) */
  189. #if defined(CONFIG_PCU_E) || defined(CONFIG_CCM) || defined(CONFIG_ATC)
  190. extern void spi_init_f (void);
  191. extern void spi_init_r (void);
  192. extern ssize_t spi_read (uchar *, int, uchar *, int);
  193. extern ssize_t spi_write (uchar *, int, uchar *, int);
  194. #endif
  195. #ifdef CONFIG_RPXCLASSIC
  196. void rpxclassic_init (void);
  197. #endif
  198. #ifdef CONFIG_MBX
  199. /* $(BOARD)/mbx8xx.c */
  200. void mbx_init (void);
  201. void board_serial_init (void);
  202. void board_ether_init (void);
  203. #endif
  204. #if defined(CONFIG_RPXCLASSIC) || defined(CONFIG_MBX) || defined(CONFIG_IAD210)
  205. void board_get_enetaddr (uchar *addr);
  206. #endif
  207. #ifdef CONFIG_HERMES
  208. /* $(BOARD)/hermes.c */
  209. void hermes_start_lxt980 (int speed);
  210. #endif
  211. #ifdef CONFIG_EVB64260
  212. void evb64260_init(void);
  213. void debug_led(int, int);
  214. void display_mem_map(void);
  215. void perform_soft_reset(void);
  216. #endif
  217. void load_sernum_ethaddr (void);
  218. /* $(BOARD)/$(BOARD).c */
  219. int board_pre_init (void);
  220. int board_post_init (void);
  221. int board_postclk_init (void); /* after clocks/timebase, before env/serial */
  222. void board_poweroff (void);
  223. #if defined(CFG_DRAM_TEST)
  224. int testdram(void);
  225. #endif /* CFG_DRAM_TEST */
  226. /* $(CPU)/start.S */
  227. #if defined(CONFIG_5xx) || \
  228. defined(CONFIG_8xx)
  229. uint get_immr (uint);
  230. #endif
  231. uint get_pvr (void);
  232. uint rd_ic_cst (void);
  233. void wr_ic_cst (uint);
  234. void wr_ic_adr (uint);
  235. uint rd_dc_cst (void);
  236. void wr_dc_cst (uint);
  237. void wr_dc_adr (uint);
  238. int icache_status (void);
  239. void icache_enable (void);
  240. void icache_disable(void);
  241. int dcache_status (void);
  242. void dcache_enable (void);
  243. void dcache_disable(void);
  244. void relocate_code (ulong, gd_t *, ulong);
  245. ulong get_endaddr (void);
  246. void trap_init (ulong);
  247. #if defined (CONFIG_4xx) || \
  248. defined (CONFIG_74xx_7xx) || \
  249. defined (CONFIG_74x) || \
  250. defined (CONFIG_75x) || \
  251. defined (CONFIG_74xx)
  252. unsigned char in8(unsigned int);
  253. void out8(unsigned int, unsigned char);
  254. unsigned short in16(unsigned int);
  255. unsigned short in16r(unsigned int);
  256. void out16(unsigned int, unsigned short value);
  257. void out16r(unsigned int, unsigned short value);
  258. unsigned long in32(unsigned int);
  259. unsigned long in32r(unsigned int);
  260. void out32(unsigned int, unsigned long value);
  261. void out32r(unsigned int, unsigned long value);
  262. void ppcDcbf(unsigned long value);
  263. void ppcDcbi(unsigned long value);
  264. void ppcSync(void);
  265. #endif
  266. /* $(CPU)/cpu.c */
  267. int checkcpu (void);
  268. int checkicache (void);
  269. int checkdcache (void);
  270. void upmconfig (unsigned int, unsigned int *, unsigned int);
  271. ulong get_tbclk (void);
  272. /* $(CPU)/serial.c */
  273. int serial_init (void);
  274. void serial_setbrg (void);
  275. void serial_putc (const char);
  276. void serial_puts (const char *);
  277. void serial_addr (unsigned int);
  278. int serial_getc (void);
  279. int serial_tstc (void);
  280. /* $(CPU)/speed.c */
  281. int get_clocks (void);
  282. #if defined(CONFIG_8260)
  283. int prt_8260_clks (void);
  284. #endif
  285. #ifdef CONFIG_4xx
  286. ulong get_OPB_freq (void);
  287. ulong get_PCI_freq (void);
  288. #endif
  289. #if defined(CONFIG_S3C2400) || defined(CONFIG_S3C2410)
  290. ulong get_FCLK (void);
  291. ulong get_HCLK (void);
  292. ulong get_PCLK (void);
  293. ulong get_UCLK (void);
  294. #endif
  295. ulong get_bus_freq (ulong);
  296. #if defined(CONFIG_4xx) || defined(CONFIG_IOP480)
  297. # if defined(CONFIG_440)
  298. typedef PPC440_SYS_INFO sys_info_t;
  299. # else
  300. typedef PPC405_SYS_INFO sys_info_t;
  301. # endif
  302. void get_sys_info ( sys_info_t * );
  303. #endif
  304. /* $(CPU)/cpu_init.c */
  305. #if defined(CONFIG_8xx) || defined(CONFIG_8260)
  306. void cpu_init_f (volatile immap_t *immr);
  307. #endif
  308. #ifdef CONFIG_4xx
  309. void cpu_init_f (void);
  310. #endif
  311. int cpu_init_r (void);
  312. #if defined(CONFIG_8260)
  313. int prt_8260_rsr (void);
  314. #endif
  315. /* $(CPU)/interrupts.c */
  316. int interrupt_init (void);
  317. void timer_interrupt (struct pt_regs *);
  318. void external_interrupt (struct pt_regs *);
  319. void irq_install_handler(int, interrupt_handler_t *, void *);
  320. void irq_free_handler (int);
  321. void reset_timer (void);
  322. ulong get_timer (ulong base);
  323. void set_timer (ulong t);
  324. void enable_interrupts (void);
  325. int disable_interrupts (void);
  326. /* $(CPU)/.../commproc.c */
  327. int dpram_init (void);
  328. uint dpram_base(void);
  329. uint dpram_base_align(uint align);
  330. uint dpram_alloc(uint size);
  331. uint dpram_alloc_align(uint size,uint align);
  332. void post_word_store (ulong);
  333. ulong post_word_load (void);
  334. /* $(CPU)/.../<eth> */
  335. void mii_init (void);
  336. /* $(CPU)/.../lcd.c */
  337. ulong lcd_setmem (ulong);
  338. /* $(CPU)/.../vfd.c */
  339. ulong vfd_setmem (ulong);
  340. /* $(CPU)/.../video.c */
  341. ulong video_setmem (ulong);
  342. /* ppc/cache.c */
  343. void flush_cache (unsigned long, unsigned long);
  344. /* ppc/ticks.S */
  345. unsigned long long get_ticks(void);
  346. void wait_ticks (unsigned long);
  347. /* ppc/time.c */
  348. void udelay (unsigned long);
  349. ulong usec2ticks (unsigned long usec);
  350. ulong ticks2usec (unsigned long ticks);
  351. int init_timebase (void);
  352. /* ppc/vsprintf.c */
  353. ulong simple_strtoul(const char *cp,char **endp,unsigned int base);
  354. long simple_strtol(const char *cp,char **endp,unsigned int base);
  355. void panic(const char *fmt, ...);
  356. int sprintf(char * buf, const char *fmt, ...);
  357. int vsprintf(char *buf, const char *fmt, va_list args);
  358. /* ppc/crc32.c */
  359. ulong crc32 (ulong, const unsigned char *, uint);
  360. ulong crc32_no_comp (ulong, const unsigned char *, uint);
  361. /* common/console.c */
  362. extern void **syscall_tbl;
  363. int console_init_f(void); /* Before relocation; uses the serial stuff */
  364. int console_init_r(void); /* After relocation; uses the console stuff */
  365. int console_assign (int file, char *devname); /* Assign the console */
  366. int ctrlc (void);
  367. int had_ctrlc (void); /* have we had a Control-C since last clear? */
  368. void clear_ctrlc (void); /* clear the Control-C condition */
  369. int disable_ctrlc (int); /* 1 to disable, 0 to enable Control-C detect */
  370. /*
  371. * STDIO based functions (can always be used)
  372. */
  373. /* serial stuff */
  374. void serial_printf (const char *fmt, ...);
  375. /* stdin */
  376. int getc(void);
  377. int tstc(void);
  378. /* stdout */
  379. void putc(const char c);
  380. void puts(const char *s);
  381. void printf(const char *fmt, ...);
  382. void vprintf(const char *fmt, va_list args);
  383. /* stderr */
  384. #define eputc(c) fputc(stderr, c)
  385. #define eputs(s) fputs(stderr, s)
  386. #define eprintf(fmt,args...) fprintf(stderr,fmt ,##args)
  387. /*
  388. * FILE based functions (can only be used AFTER relocation!)
  389. */
  390. #define stdin 0
  391. #define stdout 1
  392. #define stderr 2
  393. #define MAX_FILES 3
  394. void fprintf(int file, const char *fmt, ...);
  395. void fputs(int file, const char *s);
  396. void fputc(int file, const char c);
  397. int ftstc(int file);
  398. int fgetc(int file);
  399. int pcmcia_init (void);
  400. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  401. void show_boot_progress (int status);
  402. #endif
  403. #endif /* __COMMON_H_ */