setup.c 6.6 KB

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