setup.c 9.9 KB

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