setup.c 10 KB

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