setup.c 10.0 KB

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