setup.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * linux/arch/h8300/kernel/setup.c
  3. *
  4. * Copyleft ()) 2000 James D. Schettine {james@telos-systems.com}
  5. * Copyright (C) 1999,2000 Greg Ungerer (gerg@snapgear.com)
  6. * Copyright (C) 1998,1999 D. Jeff Dionne <jeff@lineo.ca>
  7. * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
  8. * Copyright (C) 1995 Hamish Macdonald
  9. * Copyright (C) 2000 Lineo Inc. (www.lineo.com)
  10. * Copyright (C) 2001 Lineo, Inc. <www.lineo.com>
  11. *
  12. * H8/300 porting Yoshinori Sato <ysato@users.sourceforge.jp>
  13. */
  14. /*
  15. * This file handles the architecture-dependent parts of system setup
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/delay.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/fs.h>
  22. #include <linux/fb.h>
  23. #include <linux/console.h>
  24. #include <linux/genhd.h>
  25. #include <linux/errno.h>
  26. #include <linux/string.h>
  27. #include <linux/major.h>
  28. #include <linux/bootmem.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/init.h>
  31. #include <asm/setup.h>
  32. #include <asm/irq.h>
  33. #include <asm/pgtable.h>
  34. #if defined(__H8300H__)
  35. #define CPU "H8/300H"
  36. #include <asm/regs306x.h>
  37. #endif
  38. #if defined(__H8300S__)
  39. #define CPU "H8S"
  40. #include <asm/regs267x.h>
  41. #endif
  42. #define STUBSIZE 0xc000;
  43. unsigned long rom_length;
  44. unsigned long memory_start;
  45. unsigned long memory_end;
  46. char __initdata command_line[COMMAND_LINE_SIZE];
  47. extern int _stext, _etext, _sdata, _edata, _sbss, _ebss, _end;
  48. extern int _ramstart, _ramend;
  49. extern char _target_name[];
  50. extern void h8300_gpio_init(void);
  51. #if (defined(CONFIG_H8300H_SIM) || defined(CONFIG_H8S_SIM)) \
  52. && defined(CONFIG_GDB_MAGICPRINT)
  53. /* printk with gdb service */
  54. static void gdb_console_output(struct console *c, const char *msg, unsigned len)
  55. {
  56. for (; len > 0; len--) {
  57. asm("mov.w %0,r2\n\t"
  58. "jsr @0xc4"::"r"(*msg++):"er2");
  59. }
  60. }
  61. /*
  62. * Setup initial baud/bits/parity. We do two things here:
  63. * - construct a cflag setting for the first rs_open()
  64. * - initialize the serial port
  65. * Return non-zero if we didn't find a serial port.
  66. */
  67. static int __init gdb_console_setup(struct console *co, char *options)
  68. {
  69. return 0;
  70. }
  71. static const struct console gdb_console = {
  72. .name = "gdb_con",
  73. .write = gdb_console_output,
  74. .device = NULL,
  75. .setup = gdb_console_setup,
  76. .flags = CON_PRINTBUFFER,
  77. .index = -1,
  78. };
  79. #endif
  80. void __init setup_arch(char **cmdline_p)
  81. {
  82. int bootmap_size;
  83. memory_start = (unsigned long) &_ramstart;
  84. /* allow for ROMFS on the end of the kernel */
  85. if (memcmp((void *)memory_start, "-rom1fs-", 8) == 0) {
  86. #if defined(CONFIG_BLK_DEV_INITRD)
  87. initrd_start = memory_start;
  88. initrd_end = memory_start += be32_to_cpu(((unsigned long *) (memory_start))[2]);
  89. #else
  90. memory_start += be32_to_cpu(((unsigned long *) memory_start)[2]);
  91. #endif
  92. }
  93. memory_start = PAGE_ALIGN(memory_start);
  94. #if !defined(CONFIG_BLKDEV_RESERVE)
  95. memory_end = (unsigned long) &_ramend; /* by now the stack is part of the init task */
  96. #if defined(CONFIG_GDB_DEBUG)
  97. memory_end -= STUBSIZE;
  98. #endif
  99. #else
  100. if ((memory_end < CONFIG_BLKDEV_RESERVE_ADDRESS) &&
  101. (memory_end > CONFIG_BLKDEV_RESERVE_ADDRESS))
  102. /* overlap userarea */
  103. memory_end = CONFIG_BLKDEV_RESERVE_ADDRESS;
  104. #endif
  105. init_mm.start_code = (unsigned long) &_stext;
  106. init_mm.end_code = (unsigned long) &_etext;
  107. init_mm.end_data = (unsigned long) &_edata;
  108. init_mm.brk = (unsigned long) 0;
  109. #if (defined(CONFIG_H8300H_SIM) || defined(CONFIG_H8S_SIM)) && defined(CONFIG_GDB_MAGICPRINT)
  110. register_console((struct console *)&gdb_console);
  111. #endif
  112. printk(KERN_INFO "\r\n\nuClinux " CPU "\n");
  113. printk(KERN_INFO "Target Hardware: %s\n",_target_name);
  114. printk(KERN_INFO "Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
  115. printk(KERN_INFO "H8/300 series support by Yoshinori Sato <ysato@users.sourceforge.jp>\n");
  116. #ifdef DEBUG
  117. printk(KERN_DEBUG "KERNEL -> TEXT=0x%06x-0x%06x DATA=0x%06x-0x%06x "
  118. "BSS=0x%06x-0x%06x\n", (int) &_stext, (int) &_etext,
  119. (int) &_sdata, (int) &_edata,
  120. (int) &_sbss, (int) &_ebss);
  121. printk(KERN_DEBUG "KERNEL -> ROMFS=0x%06x-0x%06x MEM=0x%06x-0x%06x "
  122. "STACK=0x%06x-0x%06x\n",
  123. (int) &_ebss, (int) memory_start,
  124. (int) memory_start, (int) memory_end,
  125. (int) memory_end, (int) &_ramend);
  126. #endif
  127. #ifdef CONFIG_DEFAULT_CMDLINE
  128. /* set from default command line */
  129. if (*command_line == '\0')
  130. strcpy(command_line,CONFIG_KERNEL_COMMAND);
  131. #endif
  132. /* Keep a copy of command line */
  133. *cmdline_p = &command_line[0];
  134. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  135. boot_command_line[COMMAND_LINE_SIZE-1] = 0;
  136. #ifdef DEBUG
  137. if (strlen(*cmdline_p))
  138. printk(KERN_DEBUG "Command line: '%s'\n", *cmdline_p);
  139. #endif
  140. /*
  141. * give all the memory to the bootmap allocator, tell it to put the
  142. * boot mem_map at the start of memory
  143. */
  144. bootmap_size = init_bootmem_node(
  145. NODE_DATA(0),
  146. memory_start >> PAGE_SHIFT, /* map goes here */
  147. PAGE_OFFSET >> PAGE_SHIFT, /* 0 on coldfire */
  148. memory_end >> PAGE_SHIFT);
  149. /*
  150. * free the usable memory, we have to make sure we do not free
  151. * the bootmem bitmap so we then reserve it after freeing it :-)
  152. */
  153. free_bootmem(memory_start, memory_end - memory_start);
  154. reserve_bootmem(memory_start, bootmap_size);
  155. /*
  156. * get kmalloc into gear
  157. */
  158. paging_init();
  159. h8300_gpio_init();
  160. #if defined(CONFIG_H8300_AKI3068NET) && defined(CONFIG_IDE)
  161. {
  162. #define AREABIT(addr) (1 << (((addr) >> 21) & 7))
  163. /* setup BSC */
  164. volatile unsigned char *abwcr = (volatile unsigned char *)ABWCR;
  165. volatile unsigned char *cscr = (volatile unsigned char *)CSCR;
  166. *abwcr &= ~(AREABIT(CONFIG_H8300_IDE_BASE) | AREABIT(CONFIG_H8300_IDE_ALT));
  167. *cscr |= (AREABIT(CONFIG_H8300_IDE_BASE) | AREABIT(CONFIG_H8300_IDE_ALT)) | 0x0f;
  168. }
  169. #endif
  170. #ifdef DEBUG
  171. printk(KERN_DEBUG "Done setup_arch\n");
  172. #endif
  173. }
  174. /*
  175. * Get CPU information for use by the procfs.
  176. */
  177. static int show_cpuinfo(struct seq_file *m, void *v)
  178. {
  179. char *cpu;
  180. int mode;
  181. u_long clockfreq;
  182. cpu = CPU;
  183. mode = *(volatile unsigned char *)MDCR & 0x07;
  184. clockfreq = CONFIG_CPU_CLOCK;
  185. seq_printf(m, "CPU:\t\t%s (mode:%d)\n"
  186. "Clock:\t\t%lu.%1luMHz\n"
  187. "BogoMips:\t%lu.%02lu\n"
  188. "Calibration:\t%lu loops\n",
  189. cpu,mode,
  190. clockfreq/1000,clockfreq%1000,
  191. (loops_per_jiffy*HZ)/500000,((loops_per_jiffy*HZ)/5000)%100,
  192. (loops_per_jiffy*HZ));
  193. return 0;
  194. }
  195. static void *c_start(struct seq_file *m, loff_t *pos)
  196. {
  197. return *pos < NR_CPUS ? ((void *) 0x12345678) : NULL;
  198. }
  199. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  200. {
  201. ++*pos;
  202. return c_start(m, pos);
  203. }
  204. static void c_stop(struct seq_file *m, void *v)
  205. {
  206. }
  207. struct seq_operations cpuinfo_op = {
  208. .start = c_start,
  209. .next = c_next,
  210. .stop = c_stop,
  211. .show = show_cpuinfo,
  212. };