setup.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /*
  2. * arch/xtensa/kernel/setup.c
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 1995 Linus Torvalds
  9. * Copyright (C) 2001 - 2005 Tensilica Inc.
  10. *
  11. * Chris Zankel <chris@zankel.net>
  12. * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
  13. * Kevin Chea
  14. * Marc Gauthier<marc@tensilica.com> <marc@alumni.uwaterloo.ca>
  15. */
  16. #include <linux/errno.h>
  17. #include <linux/init.h>
  18. #include <linux/proc_fs.h>
  19. #include <linux/screen_info.h>
  20. #include <linux/bootmem.h>
  21. #include <linux/kernel.h>
  22. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  23. # include <linux/console.h>
  24. #endif
  25. #ifdef CONFIG_RTC
  26. # include <linux/timex.h>
  27. #endif
  28. #ifdef CONFIG_PROC_FS
  29. # include <linux/seq_file.h>
  30. #endif
  31. #include <asm/system.h>
  32. #include <asm/bootparam.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/processor.h>
  35. #include <asm/timex.h>
  36. #include <asm/platform.h>
  37. #include <asm/page.h>
  38. #include <asm/setup.h>
  39. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  40. struct screen_info screen_info = { 0, 24, 0, 0, 0, 80, 0, 0, 0, 24, 1, 16};
  41. #endif
  42. #ifdef CONFIG_BLK_DEV_FD
  43. extern struct fd_ops no_fd_ops;
  44. struct fd_ops *fd_ops;
  45. #endif
  46. #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
  47. extern struct ide_ops no_ide_ops;
  48. struct ide_ops *ide_ops;
  49. #endif
  50. extern struct rtc_ops no_rtc_ops;
  51. struct rtc_ops *rtc_ops;
  52. #ifdef CONFIG_PC_KEYB
  53. extern struct kbd_ops no_kbd_ops;
  54. struct kbd_ops *kbd_ops;
  55. #endif
  56. #ifdef CONFIG_BLK_DEV_INITRD
  57. extern void *initrd_start;
  58. extern void *initrd_end;
  59. extern void *__initrd_start;
  60. extern void *__initrd_end;
  61. int initrd_is_mapped = 0;
  62. extern int initrd_below_start_ok;
  63. #endif
  64. unsigned char aux_device_present;
  65. extern unsigned long loops_per_jiffy;
  66. /* Command line specified as configuration option. */
  67. static char command_line[COMMAND_LINE_SIZE];
  68. #ifdef CONFIG_CMDLINE_BOOL
  69. static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
  70. #endif
  71. sysmem_info_t __initdata sysmem;
  72. #ifdef CONFIG_BLK_DEV_INITRD
  73. int initrd_is_mapped;
  74. #endif
  75. extern void init_mmu(void);
  76. /*
  77. * Boot parameter parsing.
  78. *
  79. * The Xtensa port uses a list of variable-sized tags to pass data to
  80. * the kernel. The first tag must be a BP_TAG_FIRST tag for the list
  81. * to be recognised. The list is terminated with a zero-sized
  82. * BP_TAG_LAST tag.
  83. */
  84. typedef struct tagtable {
  85. u32 tag;
  86. int (*parse)(const bp_tag_t*);
  87. } tagtable_t;
  88. #define __tagtable(tag, fn) static tagtable_t __tagtable_##fn \
  89. __attribute__((unused, __section__(".taglist"))) = { tag, fn }
  90. /* parse current tag */
  91. static int __init parse_tag_mem(const bp_tag_t *tag)
  92. {
  93. meminfo_t *mi = (meminfo_t*)(tag->data);
  94. if (mi->type != MEMORY_TYPE_CONVENTIONAL)
  95. return -1;
  96. if (sysmem.nr_banks >= SYSMEM_BANKS_MAX) {
  97. printk(KERN_WARNING
  98. "Ignoring memory bank 0x%08lx size %ldKB\n",
  99. (unsigned long)mi->start,
  100. (unsigned long)mi->end - (unsigned long)mi->start);
  101. return -EINVAL;
  102. }
  103. sysmem.bank[sysmem.nr_banks].type = mi->type;
  104. sysmem.bank[sysmem.nr_banks].start = PAGE_ALIGN(mi->start);
  105. sysmem.bank[sysmem.nr_banks].end = mi->end & PAGE_SIZE;
  106. sysmem.nr_banks++;
  107. return 0;
  108. }
  109. __tagtable(BP_TAG_MEMORY, parse_tag_mem);
  110. #ifdef CONFIG_BLK_DEV_INITRD
  111. static int __init parse_tag_initrd(const bp_tag_t* tag)
  112. {
  113. meminfo_t* mi;
  114. mi = (meminfo_t*)(tag->data);
  115. initrd_start = (void*)(mi->start);
  116. initrd_end = (void*)(mi->end);
  117. return 0;
  118. }
  119. __tagtable(BP_TAG_INITRD, parse_tag_initrd);
  120. #endif /* CONFIG_BLK_DEV_INITRD */
  121. static int __init parse_tag_cmdline(const bp_tag_t* tag)
  122. {
  123. strncpy(command_line, (char*)(tag->data), COMMAND_LINE_SIZE);
  124. command_line[COMMAND_LINE_SIZE - 1] = '\0';
  125. return 0;
  126. }
  127. __tagtable(BP_TAG_COMMAND_LINE, parse_tag_cmdline);
  128. static int __init parse_bootparam(const bp_tag_t* tag)
  129. {
  130. extern tagtable_t __tagtable_begin, __tagtable_end;
  131. tagtable_t *t;
  132. /* Boot parameters must start with a BP_TAG_FIRST tag. */
  133. if (tag->id != BP_TAG_FIRST) {
  134. printk(KERN_WARNING "Invalid boot parameters!\n");
  135. return 0;
  136. }
  137. tag = (bp_tag_t*)((unsigned long)tag + sizeof(bp_tag_t) + tag->size);
  138. /* Parse all tags. */
  139. while (tag != NULL && tag->id != BP_TAG_LAST) {
  140. for (t = &__tagtable_begin; t < &__tagtable_end; t++) {
  141. if (tag->id == t->tag) {
  142. t->parse(tag);
  143. break;
  144. }
  145. }
  146. if (t == &__tagtable_end)
  147. printk(KERN_WARNING "Ignoring tag "
  148. "0x%08x\n", tag->id);
  149. tag = (bp_tag_t*)((unsigned long)(tag + 1) + tag->size);
  150. }
  151. return 0;
  152. }
  153. /*
  154. * Initialize architecture. (Early stage)
  155. */
  156. void __init init_arch(bp_tag_t *bp_start)
  157. {
  158. #ifdef CONFIG_BLK_DEV_INITRD
  159. initrd_start = &__initrd_start;
  160. initrd_end = &__initrd_end;
  161. #endif
  162. sysmem.nr_banks = 0;
  163. #ifdef CONFIG_CMDLINE_BOOL
  164. strcpy(command_line, default_command_line);
  165. #endif
  166. /* Parse boot parameters */
  167. if (bp_start)
  168. parse_bootparam(bp_start);
  169. if (sysmem.nr_banks == 0) {
  170. sysmem.nr_banks = 1;
  171. sysmem.bank[0].start = PLATFORM_DEFAULT_MEM_START;
  172. sysmem.bank[0].end = PLATFORM_DEFAULT_MEM_START
  173. + PLATFORM_DEFAULT_MEM_SIZE;
  174. }
  175. /* Early hook for platforms */
  176. platform_init(bp_start);
  177. /* Initialize MMU. */
  178. init_mmu();
  179. }
  180. /*
  181. * Initialize system. Setup memory and reserve regions.
  182. */
  183. extern char _end;
  184. extern char _stext;
  185. extern char _WindowVectors_text_start;
  186. extern char _WindowVectors_text_end;
  187. extern char _DebugInterruptVector_literal_start;
  188. extern char _DebugInterruptVector_text_end;
  189. extern char _KernelExceptionVector_literal_start;
  190. extern char _KernelExceptionVector_text_end;
  191. extern char _UserExceptionVector_literal_start;
  192. extern char _UserExceptionVector_text_end;
  193. extern char _DoubleExceptionVector_literal_start;
  194. extern char _DoubleExceptionVector_text_end;
  195. void __init setup_arch(char **cmdline_p)
  196. {
  197. extern int mem_reserve(unsigned long, unsigned long, int);
  198. extern void bootmem_init(void);
  199. memcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
  200. saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
  201. *cmdline_p = command_line;
  202. /* Reserve some memory regions */
  203. #ifdef CONFIG_BLK_DEV_INITRD
  204. if (initrd_start < initrd_end) {
  205. initrd_is_mapped = mem_reserve(__pa(initrd_start),
  206. __pa(initrd_end), 0);
  207. initrd_below_start_ok = 1;
  208. } else {
  209. initrd_start = 0;
  210. }
  211. #endif
  212. mem_reserve(__pa(&_stext),__pa(&_end), 1);
  213. mem_reserve(__pa(&_WindowVectors_text_start),
  214. __pa(&_WindowVectors_text_end), 0);
  215. mem_reserve(__pa(&_DebugInterruptVector_literal_start),
  216. __pa(&_DebugInterruptVector_text_end), 0);
  217. mem_reserve(__pa(&_KernelExceptionVector_literal_start),
  218. __pa(&_KernelExceptionVector_text_end), 0);
  219. mem_reserve(__pa(&_UserExceptionVector_literal_start),
  220. __pa(&_UserExceptionVector_text_end), 0);
  221. mem_reserve(__pa(&_DoubleExceptionVector_literal_start),
  222. __pa(&_DoubleExceptionVector_text_end), 0);
  223. bootmem_init();
  224. platform_setup(cmdline_p);
  225. paging_init();
  226. #ifdef CONFIG_VT
  227. # if defined(CONFIG_VGA_CONSOLE)
  228. conswitchp = &vga_con;
  229. # elif defined(CONFIG_DUMMY_CONSOLE)
  230. conswitchp = &dummy_con;
  231. # endif
  232. #endif
  233. #ifdef CONFIG_PCI
  234. platform_pcibios_init();
  235. #endif
  236. }
  237. void machine_restart(char * cmd)
  238. {
  239. platform_restart();
  240. }
  241. void machine_halt(void)
  242. {
  243. platform_halt();
  244. while (1);
  245. }
  246. void machine_power_off(void)
  247. {
  248. platform_power_off();
  249. while (1);
  250. }
  251. #ifdef CONFIG_PROC_FS
  252. /*
  253. * Display some core information through /proc/cpuinfo.
  254. */
  255. static int
  256. c_show(struct seq_file *f, void *slot)
  257. {
  258. /* high-level stuff */
  259. seq_printf(f,"processor\t: 0\n"
  260. "vendor_id\t: Tensilica\n"
  261. "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n"
  262. "core ID\t\t: " XCHAL_CORE_ID "\n"
  263. "build ID\t: 0x%x\n"
  264. "byte order\t: %s\n"
  265. "cpu MHz\t\t: %lu.%02lu\n"
  266. "bogomips\t: %lu.%02lu\n",
  267. XCHAL_BUILD_UNIQUE_ID,
  268. XCHAL_HAVE_BE ? "big" : "little",
  269. CCOUNT_PER_JIFFY/(1000000/HZ),
  270. (CCOUNT_PER_JIFFY/(10000/HZ)) % 100,
  271. loops_per_jiffy/(500000/HZ),
  272. (loops_per_jiffy/(5000/HZ)) % 100);
  273. seq_printf(f,"flags\t\t: "
  274. #if XCHAL_HAVE_NMI
  275. "nmi "
  276. #endif
  277. #if XCHAL_HAVE_DEBUG
  278. "debug "
  279. # if XCHAL_HAVE_OCD
  280. "ocd "
  281. # endif
  282. #endif
  283. #if XCHAL_HAVE_DENSITY
  284. "density "
  285. #endif
  286. #if XCHAL_HAVE_BOOLEANS
  287. "boolean "
  288. #endif
  289. #if XCHAL_HAVE_LOOPS
  290. "loop "
  291. #endif
  292. #if XCHAL_HAVE_NSA
  293. "nsa "
  294. #endif
  295. #if XCHAL_HAVE_MINMAX
  296. "minmax "
  297. #endif
  298. #if XCHAL_HAVE_SEXT
  299. "sext "
  300. #endif
  301. #if XCHAL_HAVE_CLAMPS
  302. "clamps "
  303. #endif
  304. #if XCHAL_HAVE_MAC16
  305. "mac16 "
  306. #endif
  307. #if XCHAL_HAVE_MUL16
  308. "mul16 "
  309. #endif
  310. #if XCHAL_HAVE_MUL32
  311. "mul32 "
  312. #endif
  313. #if XCHAL_HAVE_MUL32_HIGH
  314. "mul32h "
  315. #endif
  316. #if XCHAL_HAVE_FP
  317. "fpu "
  318. #endif
  319. "\n");
  320. /* Registers. */
  321. seq_printf(f,"physical aregs\t: %d\n"
  322. "misc regs\t: %d\n"
  323. "ibreak\t\t: %d\n"
  324. "dbreak\t\t: %d\n",
  325. XCHAL_NUM_AREGS,
  326. XCHAL_NUM_MISC_REGS,
  327. XCHAL_NUM_IBREAK,
  328. XCHAL_NUM_DBREAK);
  329. /* Interrupt. */
  330. seq_printf(f,"num ints\t: %d\n"
  331. "ext ints\t: %d\n"
  332. "int levels\t: %d\n"
  333. "timers\t\t: %d\n"
  334. "debug level\t: %d\n",
  335. XCHAL_NUM_INTERRUPTS,
  336. XCHAL_NUM_EXTINTERRUPTS,
  337. XCHAL_NUM_INTLEVELS,
  338. XCHAL_NUM_TIMERS,
  339. XCHAL_DEBUGLEVEL);
  340. /* Cache */
  341. seq_printf(f,"icache line size: %d\n"
  342. "icache ways\t: %d\n"
  343. "icache size\t: %d\n"
  344. "icache flags\t: "
  345. #if XCHAL_ICACHE_LINE_LOCKABLE
  346. "lock"
  347. #endif
  348. "\n"
  349. "dcache line size: %d\n"
  350. "dcache ways\t: %d\n"
  351. "dcache size\t: %d\n"
  352. "dcache flags\t: "
  353. #if XCHAL_DCACHE_IS_WRITEBACK
  354. "writeback"
  355. #endif
  356. #if XCHAL_DCACHE_LINE_LOCKABLE
  357. "lock"
  358. #endif
  359. "\n",
  360. XCHAL_ICACHE_LINESIZE,
  361. XCHAL_ICACHE_WAYS,
  362. XCHAL_ICACHE_SIZE,
  363. XCHAL_DCACHE_LINESIZE,
  364. XCHAL_DCACHE_WAYS,
  365. XCHAL_DCACHE_SIZE);
  366. return 0;
  367. }
  368. /*
  369. * We show only CPU #0 info.
  370. */
  371. static void *
  372. c_start(struct seq_file *f, loff_t *pos)
  373. {
  374. return (void *) ((*pos == 0) ? (void *)1 : NULL);
  375. }
  376. static void *
  377. c_next(struct seq_file *f, void *v, loff_t *pos)
  378. {
  379. return NULL;
  380. }
  381. static void
  382. c_stop(struct seq_file *f, void *v)
  383. {
  384. }
  385. struct seq_operations cpuinfo_op =
  386. {
  387. start: c_start,
  388. next: c_next,
  389. stop: c_stop,
  390. show: c_show
  391. };
  392. #endif /* CONFIG_PROC_FS */