setup_64.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. *
  3. * Common boot and setup code.
  4. *
  5. * Copyright (C) 2001 PPC64 Team, IBM Corp
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #undef DEBUG
  13. #include <linux/config.h>
  14. #include <linux/module.h>
  15. #include <linux/string.h>
  16. #include <linux/sched.h>
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/reboot.h>
  20. #include <linux/delay.h>
  21. #include <linux/initrd.h>
  22. #include <linux/ide.h>
  23. #include <linux/seq_file.h>
  24. #include <linux/ioport.h>
  25. #include <linux/console.h>
  26. #include <linux/utsname.h>
  27. #include <linux/tty.h>
  28. #include <linux/root_dev.h>
  29. #include <linux/notifier.h>
  30. #include <linux/cpu.h>
  31. #include <linux/unistd.h>
  32. #include <linux/serial.h>
  33. #include <linux/serial_8250.h>
  34. #include <asm/io.h>
  35. #include <asm/kdump.h>
  36. #include <asm/prom.h>
  37. #include <asm/processor.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/smp.h>
  40. #include <asm/elf.h>
  41. #include <asm/machdep.h>
  42. #include <asm/paca.h>
  43. #include <asm/time.h>
  44. #include <asm/cputable.h>
  45. #include <asm/sections.h>
  46. #include <asm/btext.h>
  47. #include <asm/nvram.h>
  48. #include <asm/setup.h>
  49. #include <asm/system.h>
  50. #include <asm/rtas.h>
  51. #include <asm/iommu.h>
  52. #include <asm/serial.h>
  53. #include <asm/cache.h>
  54. #include <asm/page.h>
  55. #include <asm/mmu.h>
  56. #include <asm/lmb.h>
  57. #include <asm/iseries/it_lp_naca.h>
  58. #include <asm/firmware.h>
  59. #include <asm/xmon.h>
  60. #include <asm/udbg.h>
  61. #include <asm/kexec.h>
  62. #include "setup.h"
  63. #ifdef DEBUG
  64. #define DBG(fmt...) udbg_printf(fmt)
  65. #else
  66. #define DBG(fmt...)
  67. #endif
  68. int have_of = 1;
  69. int boot_cpuid = 0;
  70. int boot_cpuid_phys = 0;
  71. dev_t boot_dev;
  72. u64 ppc64_pft_size;
  73. /* Pick defaults since we might want to patch instructions
  74. * before we've read this from the device tree.
  75. */
  76. struct ppc64_caches ppc64_caches = {
  77. .dline_size = 0x80,
  78. .log_dline_size = 7,
  79. .iline_size = 0x80,
  80. .log_iline_size = 7
  81. };
  82. EXPORT_SYMBOL_GPL(ppc64_caches);
  83. /*
  84. * These are used in binfmt_elf.c to put aux entries on the stack
  85. * for each elf executable being started.
  86. */
  87. int dcache_bsize;
  88. int icache_bsize;
  89. int ucache_bsize;
  90. /* The main machine-dep calls structure
  91. */
  92. struct machdep_calls ppc_md;
  93. EXPORT_SYMBOL(ppc_md);
  94. #ifdef CONFIG_MAGIC_SYSRQ
  95. unsigned long SYSRQ_KEY;
  96. #endif /* CONFIG_MAGIC_SYSRQ */
  97. static int ppc64_panic_event(struct notifier_block *, unsigned long, void *);
  98. static struct notifier_block ppc64_panic_block = {
  99. .notifier_call = ppc64_panic_event,
  100. .priority = INT_MIN /* may not return; must be done last */
  101. };
  102. #ifdef CONFIG_SMP
  103. static int smt_enabled_cmdline;
  104. /* Look for ibm,smt-enabled OF option */
  105. static void check_smt_enabled(void)
  106. {
  107. struct device_node *dn;
  108. char *smt_option;
  109. /* Allow the command line to overrule the OF option */
  110. if (smt_enabled_cmdline)
  111. return;
  112. dn = of_find_node_by_path("/options");
  113. if (dn) {
  114. smt_option = (char *)get_property(dn, "ibm,smt-enabled", NULL);
  115. if (smt_option) {
  116. if (!strcmp(smt_option, "on"))
  117. smt_enabled_at_boot = 1;
  118. else if (!strcmp(smt_option, "off"))
  119. smt_enabled_at_boot = 0;
  120. }
  121. }
  122. }
  123. /* Look for smt-enabled= cmdline option */
  124. static int __init early_smt_enabled(char *p)
  125. {
  126. smt_enabled_cmdline = 1;
  127. if (!p)
  128. return 0;
  129. if (!strcmp(p, "on") || !strcmp(p, "1"))
  130. smt_enabled_at_boot = 1;
  131. else if (!strcmp(p, "off") || !strcmp(p, "0"))
  132. smt_enabled_at_boot = 0;
  133. return 0;
  134. }
  135. early_param("smt-enabled", early_smt_enabled);
  136. #else
  137. #define check_smt_enabled()
  138. #endif /* CONFIG_SMP */
  139. extern struct machdep_calls pSeries_md;
  140. extern struct machdep_calls pmac_md;
  141. extern struct machdep_calls maple_md;
  142. extern struct machdep_calls cell_md;
  143. extern struct machdep_calls iseries_md;
  144. /* Ultimately, stuff them in an elf section like initcalls... */
  145. static struct machdep_calls __initdata *machines[] = {
  146. #ifdef CONFIG_PPC_PSERIES
  147. &pSeries_md,
  148. #endif /* CONFIG_PPC_PSERIES */
  149. #ifdef CONFIG_PPC_PMAC
  150. &pmac_md,
  151. #endif /* CONFIG_PPC_PMAC */
  152. #ifdef CONFIG_PPC_MAPLE
  153. &maple_md,
  154. #endif /* CONFIG_PPC_MAPLE */
  155. #ifdef CONFIG_PPC_CELL
  156. &cell_md,
  157. #endif
  158. #ifdef CONFIG_PPC_ISERIES
  159. &iseries_md,
  160. #endif
  161. NULL
  162. };
  163. /*
  164. * Early initialization entry point. This is called by head.S
  165. * with MMU translation disabled. We rely on the "feature" of
  166. * the CPU that ignores the top 2 bits of the address in real
  167. * mode so we can access kernel globals normally provided we
  168. * only toy with things in the RMO region. From here, we do
  169. * some early parsing of the device-tree to setup out LMB
  170. * data structures, and allocate & initialize the hash table
  171. * and segment tables so we can start running with translation
  172. * enabled.
  173. *
  174. * It is this function which will call the probe() callback of
  175. * the various platform types and copy the matching one to the
  176. * global ppc_md structure. Your platform can eventually do
  177. * some very early initializations from the probe() routine, but
  178. * this is not recommended, be very careful as, for example, the
  179. * device-tree is not accessible via normal means at this point.
  180. */
  181. void __init early_setup(unsigned long dt_ptr)
  182. {
  183. struct paca_struct *lpaca = get_paca();
  184. static struct machdep_calls **mach;
  185. /* Enable early debugging if any specified (see udbg.h) */
  186. udbg_early_init();
  187. DBG(" -> early_setup()\n");
  188. /*
  189. * Do early initializations using the flattened device
  190. * tree, like retreiving the physical memory map or
  191. * calculating/retreiving the hash table size
  192. */
  193. early_init_devtree(__va(dt_ptr));
  194. /*
  195. * Iterate all ppc_md structures until we find the proper
  196. * one for the current machine type
  197. */
  198. DBG("Probing machine type for platform %x...\n", _machine);
  199. for (mach = machines; *mach; mach++) {
  200. if ((*mach)->probe(_machine))
  201. break;
  202. }
  203. /* What can we do if we didn't find ? */
  204. if (*mach == NULL) {
  205. DBG("No suitable machine found !\n");
  206. for (;;);
  207. }
  208. ppc_md = **mach;
  209. #ifdef CONFIG_CRASH_DUMP
  210. kdump_setup();
  211. #endif
  212. DBG("Found, Initializing memory management...\n");
  213. /*
  214. * Initialize the MMU Hash table and create the linear mapping
  215. * of memory. Has to be done before stab/slb initialization as
  216. * this is currently where the page size encoding is obtained
  217. */
  218. htab_initialize();
  219. /*
  220. * Initialize stab / SLB management except on iSeries
  221. */
  222. if (!firmware_has_feature(FW_FEATURE_ISERIES)) {
  223. if (cpu_has_feature(CPU_FTR_SLB))
  224. slb_initialize();
  225. else
  226. stab_initialize(lpaca->stab_real);
  227. }
  228. DBG(" <- early_setup()\n");
  229. }
  230. #ifdef CONFIG_SMP
  231. void early_setup_secondary(void)
  232. {
  233. struct paca_struct *lpaca = get_paca();
  234. /* Mark enabled in PACA */
  235. lpaca->proc_enabled = 0;
  236. /* Initialize hash table for that CPU */
  237. htab_initialize_secondary();
  238. /* Initialize STAB/SLB. We use a virtual address as it works
  239. * in real mode on pSeries and we want a virutal address on
  240. * iSeries anyway
  241. */
  242. if (cpu_has_feature(CPU_FTR_SLB))
  243. slb_initialize();
  244. else
  245. stab_initialize(lpaca->stab_addr);
  246. }
  247. #endif /* CONFIG_SMP */
  248. #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
  249. void smp_release_cpus(void)
  250. {
  251. extern unsigned long __secondary_hold_spinloop;
  252. unsigned long *ptr;
  253. DBG(" -> smp_release_cpus()\n");
  254. /* All secondary cpus are spinning on a common spinloop, release them
  255. * all now so they can start to spin on their individual paca
  256. * spinloops. For non SMP kernels, the secondary cpus never get out
  257. * of the common spinloop.
  258. * This is useless but harmless on iSeries, secondaries are already
  259. * waiting on their paca spinloops. */
  260. ptr = (unsigned long *)((unsigned long)&__secondary_hold_spinloop
  261. - PHYSICAL_START);
  262. *ptr = 1;
  263. mb();
  264. DBG(" <- smp_release_cpus()\n");
  265. }
  266. #else
  267. #define smp_release_cpus()
  268. #endif /* CONFIG_SMP || CONFIG_KEXEC */
  269. /*
  270. * Initialize some remaining members of the ppc64_caches and systemcfg
  271. * structures
  272. * (at least until we get rid of them completely). This is mostly some
  273. * cache informations about the CPU that will be used by cache flush
  274. * routines and/or provided to userland
  275. */
  276. static void __init initialize_cache_info(void)
  277. {
  278. struct device_node *np;
  279. unsigned long num_cpus = 0;
  280. DBG(" -> initialize_cache_info()\n");
  281. for (np = NULL; (np = of_find_node_by_type(np, "cpu"));) {
  282. num_cpus += 1;
  283. /* We're assuming *all* of the CPUs have the same
  284. * d-cache and i-cache sizes... -Peter
  285. */
  286. if ( num_cpus == 1 ) {
  287. u32 *sizep, *lsizep;
  288. u32 size, lsize;
  289. const char *dc, *ic;
  290. /* Then read cache informations */
  291. if (_machine == PLATFORM_POWERMAC) {
  292. dc = "d-cache-block-size";
  293. ic = "i-cache-block-size";
  294. } else {
  295. dc = "d-cache-line-size";
  296. ic = "i-cache-line-size";
  297. }
  298. size = 0;
  299. lsize = cur_cpu_spec->dcache_bsize;
  300. sizep = (u32 *)get_property(np, "d-cache-size", NULL);
  301. if (sizep != NULL)
  302. size = *sizep;
  303. lsizep = (u32 *) get_property(np, dc, NULL);
  304. if (lsizep != NULL)
  305. lsize = *lsizep;
  306. if (sizep == 0 || lsizep == 0)
  307. DBG("Argh, can't find dcache properties ! "
  308. "sizep: %p, lsizep: %p\n", sizep, lsizep);
  309. ppc64_caches.dsize = size;
  310. ppc64_caches.dline_size = lsize;
  311. ppc64_caches.log_dline_size = __ilog2(lsize);
  312. ppc64_caches.dlines_per_page = PAGE_SIZE / lsize;
  313. size = 0;
  314. lsize = cur_cpu_spec->icache_bsize;
  315. sizep = (u32 *)get_property(np, "i-cache-size", NULL);
  316. if (sizep != NULL)
  317. size = *sizep;
  318. lsizep = (u32 *)get_property(np, ic, NULL);
  319. if (lsizep != NULL)
  320. lsize = *lsizep;
  321. if (sizep == 0 || lsizep == 0)
  322. DBG("Argh, can't find icache properties ! "
  323. "sizep: %p, lsizep: %p\n", sizep, lsizep);
  324. ppc64_caches.isize = size;
  325. ppc64_caches.iline_size = lsize;
  326. ppc64_caches.log_iline_size = __ilog2(lsize);
  327. ppc64_caches.ilines_per_page = PAGE_SIZE / lsize;
  328. }
  329. }
  330. DBG(" <- initialize_cache_info()\n");
  331. }
  332. /*
  333. * Do some initial setup of the system. The parameters are those which
  334. * were passed in from the bootloader.
  335. */
  336. void __init setup_system(void)
  337. {
  338. DBG(" -> setup_system()\n");
  339. /*
  340. * Unflatten the device-tree passed by prom_init or kexec
  341. */
  342. unflatten_device_tree();
  343. #ifdef CONFIG_KEXEC
  344. kexec_setup(); /* requires unflattened device tree. */
  345. #endif
  346. /*
  347. * Fill the ppc64_caches & systemcfg structures with informations
  348. * retrieved from the device-tree. Need to be called before
  349. * finish_device_tree() since the later requires some of the
  350. * informations filled up here to properly parse the interrupt
  351. * tree.
  352. * It also sets up the cache line sizes which allows to call
  353. * routines like flush_icache_range (used by the hash init
  354. * later on).
  355. */
  356. initialize_cache_info();
  357. #ifdef CONFIG_PPC_RTAS
  358. /*
  359. * Initialize RTAS if available
  360. */
  361. rtas_initialize();
  362. #endif /* CONFIG_PPC_RTAS */
  363. /*
  364. * Check if we have an initrd provided via the device-tree
  365. */
  366. check_for_initrd();
  367. /*
  368. * Do some platform specific early initializations, that includes
  369. * setting up the hash table pointers. It also sets up some interrupt-mapping
  370. * related options that will be used by finish_device_tree()
  371. */
  372. ppc_md.init_early();
  373. /*
  374. * We can discover serial ports now since the above did setup the
  375. * hash table management for us, thus ioremap works. We do that early
  376. * so that further code can be debugged
  377. */
  378. find_legacy_serial_ports();
  379. /*
  380. * "Finish" the device-tree, that is do the actual parsing of
  381. * some of the properties like the interrupt map
  382. */
  383. finish_device_tree();
  384. /*
  385. * Initialize xmon
  386. */
  387. #ifdef CONFIG_XMON_DEFAULT
  388. xmon_init(1);
  389. #endif
  390. /*
  391. * Register early console
  392. */
  393. register_early_udbg_console();
  394. /* Save unparsed command line copy for /proc/cmdline */
  395. strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
  396. parse_early_param();
  397. check_smt_enabled();
  398. smp_setup_cpu_maps();
  399. /* Release secondary cpus out of their spinloops at 0x60 now that
  400. * we can map physical -> logical CPU ids
  401. */
  402. smp_release_cpus();
  403. printk("Starting Linux PPC64 %s\n", system_utsname.version);
  404. printk("-----------------------------------------------------\n");
  405. printk("ppc64_pft_size = 0x%lx\n", ppc64_pft_size);
  406. printk("ppc64_interrupt_controller = 0x%ld\n",
  407. ppc64_interrupt_controller);
  408. printk("platform = 0x%x\n", _machine);
  409. printk("physicalMemorySize = 0x%lx\n", lmb_phys_mem_size());
  410. printk("ppc64_caches.dcache_line_size = 0x%x\n",
  411. ppc64_caches.dline_size);
  412. printk("ppc64_caches.icache_line_size = 0x%x\n",
  413. ppc64_caches.iline_size);
  414. printk("htab_address = 0x%p\n", htab_address);
  415. printk("htab_hash_mask = 0x%lx\n", htab_hash_mask);
  416. #if PHYSICAL_START > 0
  417. printk("physical_start = 0x%x\n", PHYSICAL_START);
  418. #endif
  419. printk("-----------------------------------------------------\n");
  420. mm_init_ppc64();
  421. DBG(" <- setup_system()\n");
  422. }
  423. static int ppc64_panic_event(struct notifier_block *this,
  424. unsigned long event, void *ptr)
  425. {
  426. ppc_md.panic((char *)ptr); /* May not return */
  427. return NOTIFY_DONE;
  428. }
  429. #ifdef CONFIG_IRQSTACKS
  430. static void __init irqstack_early_init(void)
  431. {
  432. unsigned int i;
  433. /*
  434. * interrupt stacks must be under 256MB, we cannot afford to take
  435. * SLB misses on them.
  436. */
  437. for_each_cpu(i) {
  438. softirq_ctx[i] = (struct thread_info *)
  439. __va(lmb_alloc_base(THREAD_SIZE,
  440. THREAD_SIZE, 0x10000000));
  441. hardirq_ctx[i] = (struct thread_info *)
  442. __va(lmb_alloc_base(THREAD_SIZE,
  443. THREAD_SIZE, 0x10000000));
  444. }
  445. }
  446. #else
  447. #define irqstack_early_init()
  448. #endif
  449. /*
  450. * Stack space used when we detect a bad kernel stack pointer, and
  451. * early in SMP boots before relocation is enabled.
  452. */
  453. static void __init emergency_stack_init(void)
  454. {
  455. unsigned long limit;
  456. unsigned int i;
  457. /*
  458. * Emergency stacks must be under 256MB, we cannot afford to take
  459. * SLB misses on them. The ABI also requires them to be 128-byte
  460. * aligned.
  461. *
  462. * Since we use these as temporary stacks during secondary CPU
  463. * bringup, we need to get at them in real mode. This means they
  464. * must also be within the RMO region.
  465. */
  466. limit = min(0x10000000UL, lmb.rmo_size);
  467. for_each_cpu(i)
  468. paca[i].emergency_sp =
  469. __va(lmb_alloc_base(HW_PAGE_SIZE, 128, limit)) + HW_PAGE_SIZE;
  470. }
  471. /*
  472. * Called into from start_kernel, after lock_kernel has been called.
  473. * Initializes bootmem, which is unsed to manage page allocation until
  474. * mem_init is called.
  475. */
  476. void __init setup_arch(char **cmdline_p)
  477. {
  478. extern void do_init_bootmem(void);
  479. ppc64_boot_msg(0x12, "Setup Arch");
  480. *cmdline_p = cmd_line;
  481. /*
  482. * Set cache line size based on type of cpu as a default.
  483. * Systems with OF can look in the properties on the cpu node(s)
  484. * for a possibly more accurate value.
  485. */
  486. dcache_bsize = ppc64_caches.dline_size;
  487. icache_bsize = ppc64_caches.iline_size;
  488. /* reboot on panic */
  489. panic_timeout = 180;
  490. if (ppc_md.panic)
  491. notifier_chain_register(&panic_notifier_list, &ppc64_panic_block);
  492. init_mm.start_code = PAGE_OFFSET;
  493. init_mm.end_code = (unsigned long) _etext;
  494. init_mm.end_data = (unsigned long) _edata;
  495. init_mm.brk = klimit;
  496. irqstack_early_init();
  497. emergency_stack_init();
  498. stabs_alloc();
  499. /* set up the bootmem stuff with available memory */
  500. do_init_bootmem();
  501. sparse_init();
  502. #ifdef CONFIG_DUMMY_CONSOLE
  503. conswitchp = &dummy_con;
  504. #endif
  505. ppc_md.setup_arch();
  506. /* Use the default idle loop if the platform hasn't provided one. */
  507. if (NULL == ppc_md.idle_loop) {
  508. ppc_md.idle_loop = default_idle;
  509. printk(KERN_INFO "Using default idle loop\n");
  510. }
  511. paging_init();
  512. ppc64_boot_msg(0x15, "Setup Done");
  513. }
  514. /* ToDo: do something useful if ppc_md is not yet setup. */
  515. #define PPC64_LINUX_FUNCTION 0x0f000000
  516. #define PPC64_IPL_MESSAGE 0xc0000000
  517. #define PPC64_TERM_MESSAGE 0xb0000000
  518. static void ppc64_do_msg(unsigned int src, const char *msg)
  519. {
  520. if (ppc_md.progress) {
  521. char buf[128];
  522. sprintf(buf, "%08X\n", src);
  523. ppc_md.progress(buf, 0);
  524. snprintf(buf, 128, "%s", msg);
  525. ppc_md.progress(buf, 0);
  526. }
  527. }
  528. /* Print a boot progress message. */
  529. void ppc64_boot_msg(unsigned int src, const char *msg)
  530. {
  531. ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_IPL_MESSAGE|src, msg);
  532. printk("[boot]%04x %s\n", src, msg);
  533. }
  534. /* Print a termination message (print only -- does not stop the kernel) */
  535. void ppc64_terminate_msg(unsigned int src, const char *msg)
  536. {
  537. ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_TERM_MESSAGE|src, msg);
  538. printk("[terminate]%04x %s\n", src, msg);
  539. }
  540. int check_legacy_ioport(unsigned long base_port)
  541. {
  542. if (ppc_md.check_legacy_ioport == NULL)
  543. return 0;
  544. return ppc_md.check_legacy_ioport(base_port);
  545. }
  546. EXPORT_SYMBOL(check_legacy_ioport);
  547. void cpu_die(void)
  548. {
  549. if (ppc_md.cpu_die)
  550. ppc_md.cpu_die();
  551. }