setup_64.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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/module.h>
  14. #include <linux/string.h>
  15. #include <linux/sched.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/reboot.h>
  19. #include <linux/delay.h>
  20. #include <linux/initrd.h>
  21. #include <linux/ide.h>
  22. #include <linux/seq_file.h>
  23. #include <linux/ioport.h>
  24. #include <linux/console.h>
  25. #include <linux/utsname.h>
  26. #include <linux/tty.h>
  27. #include <linux/root_dev.h>
  28. #include <linux/notifier.h>
  29. #include <linux/cpu.h>
  30. #include <linux/unistd.h>
  31. #include <linux/serial.h>
  32. #include <linux/serial_8250.h>
  33. #include <linux/bootmem.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. dev_t boot_dev;
  71. u64 ppc64_pft_size;
  72. /* Pick defaults since we might want to patch instructions
  73. * before we've read this from the device tree.
  74. */
  75. struct ppc64_caches ppc64_caches = {
  76. .dline_size = 0x80,
  77. .log_dline_size = 7,
  78. .iline_size = 0x80,
  79. .log_iline_size = 7
  80. };
  81. EXPORT_SYMBOL_GPL(ppc64_caches);
  82. /*
  83. * These are used in binfmt_elf.c to put aux entries on the stack
  84. * for each elf executable being started.
  85. */
  86. int dcache_bsize;
  87. int icache_bsize;
  88. int ucache_bsize;
  89. #ifdef CONFIG_MAGIC_SYSRQ
  90. unsigned long SYSRQ_KEY;
  91. #endif /* CONFIG_MAGIC_SYSRQ */
  92. #ifdef CONFIG_SMP
  93. static int smt_enabled_cmdline;
  94. /* Look for ibm,smt-enabled OF option */
  95. static void check_smt_enabled(void)
  96. {
  97. struct device_node *dn;
  98. char *smt_option;
  99. /* Allow the command line to overrule the OF option */
  100. if (smt_enabled_cmdline)
  101. return;
  102. dn = of_find_node_by_path("/options");
  103. if (dn) {
  104. smt_option = (char *)get_property(dn, "ibm,smt-enabled", NULL);
  105. if (smt_option) {
  106. if (!strcmp(smt_option, "on"))
  107. smt_enabled_at_boot = 1;
  108. else if (!strcmp(smt_option, "off"))
  109. smt_enabled_at_boot = 0;
  110. }
  111. }
  112. }
  113. /* Look for smt-enabled= cmdline option */
  114. static int __init early_smt_enabled(char *p)
  115. {
  116. smt_enabled_cmdline = 1;
  117. if (!p)
  118. return 0;
  119. if (!strcmp(p, "on") || !strcmp(p, "1"))
  120. smt_enabled_at_boot = 1;
  121. else if (!strcmp(p, "off") || !strcmp(p, "0"))
  122. smt_enabled_at_boot = 0;
  123. return 0;
  124. }
  125. early_param("smt-enabled", early_smt_enabled);
  126. #else
  127. #define check_smt_enabled()
  128. #endif /* CONFIG_SMP */
  129. /* Put the paca pointer into r13 and SPRG3 */
  130. void __init setup_paca(int cpu)
  131. {
  132. local_paca = &paca[cpu];
  133. mtspr(SPRN_SPRG3, local_paca);
  134. }
  135. /*
  136. * Early initialization entry point. This is called by head.S
  137. * with MMU translation disabled. We rely on the "feature" of
  138. * the CPU that ignores the top 2 bits of the address in real
  139. * mode so we can access kernel globals normally provided we
  140. * only toy with things in the RMO region. From here, we do
  141. * some early parsing of the device-tree to setup out LMB
  142. * data structures, and allocate & initialize the hash table
  143. * and segment tables so we can start running with translation
  144. * enabled.
  145. *
  146. * It is this function which will call the probe() callback of
  147. * the various platform types and copy the matching one to the
  148. * global ppc_md structure. Your platform can eventually do
  149. * some very early initializations from the probe() routine, but
  150. * this is not recommended, be very careful as, for example, the
  151. * device-tree is not accessible via normal means at this point.
  152. */
  153. void __init early_setup(unsigned long dt_ptr)
  154. {
  155. /* Assume we're on cpu 0 for now. Don't write to the paca yet! */
  156. setup_paca(0);
  157. /* Enable early debugging if any specified (see udbg.h) */
  158. udbg_early_init();
  159. DBG(" -> early_setup(), dt_ptr: 0x%lx\n", dt_ptr);
  160. /*
  161. * Do early initializations using the flattened device
  162. * tree, like retreiving the physical memory map or
  163. * calculating/retreiving the hash table size
  164. */
  165. early_init_devtree(__va(dt_ptr));
  166. /* Now we know the logical id of our boot cpu, setup the paca. */
  167. setup_paca(boot_cpuid);
  168. /* Fix up paca fields required for the boot cpu */
  169. get_paca()->cpu_start = 1;
  170. get_paca()->stab_real = __pa((u64)&initial_stab);
  171. get_paca()->stab_addr = (u64)&initial_stab;
  172. /* Probe the machine type */
  173. probe_machine();
  174. setup_kdump_trampoline();
  175. DBG("Found, Initializing memory management...\n");
  176. /*
  177. * Initialize the MMU Hash table and create the linear mapping
  178. * of memory. Has to be done before stab/slb initialization as
  179. * this is currently where the page size encoding is obtained
  180. */
  181. htab_initialize();
  182. /*
  183. * Initialize stab / SLB management except on iSeries
  184. */
  185. if (cpu_has_feature(CPU_FTR_SLB))
  186. slb_initialize();
  187. else if (!firmware_has_feature(FW_FEATURE_ISERIES))
  188. stab_initialize(get_paca()->stab_real);
  189. DBG(" <- early_setup()\n");
  190. }
  191. #ifdef CONFIG_SMP
  192. void early_setup_secondary(void)
  193. {
  194. struct paca_struct *lpaca = get_paca();
  195. /* Mark enabled in PACA */
  196. lpaca->proc_enabled = 0;
  197. /* Initialize hash table for that CPU */
  198. htab_initialize_secondary();
  199. /* Initialize STAB/SLB. We use a virtual address as it works
  200. * in real mode on pSeries and we want a virutal address on
  201. * iSeries anyway
  202. */
  203. if (cpu_has_feature(CPU_FTR_SLB))
  204. slb_initialize();
  205. else
  206. stab_initialize(lpaca->stab_addr);
  207. }
  208. #endif /* CONFIG_SMP */
  209. #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
  210. void smp_release_cpus(void)
  211. {
  212. extern unsigned long __secondary_hold_spinloop;
  213. unsigned long *ptr;
  214. DBG(" -> smp_release_cpus()\n");
  215. /* All secondary cpus are spinning on a common spinloop, release them
  216. * all now so they can start to spin on their individual paca
  217. * spinloops. For non SMP kernels, the secondary cpus never get out
  218. * of the common spinloop.
  219. * This is useless but harmless on iSeries, secondaries are already
  220. * waiting on their paca spinloops. */
  221. ptr = (unsigned long *)((unsigned long)&__secondary_hold_spinloop
  222. - PHYSICAL_START);
  223. *ptr = 1;
  224. mb();
  225. DBG(" <- smp_release_cpus()\n");
  226. }
  227. #endif /* CONFIG_SMP || CONFIG_KEXEC */
  228. /*
  229. * Initialize some remaining members of the ppc64_caches and systemcfg
  230. * structures
  231. * (at least until we get rid of them completely). This is mostly some
  232. * cache informations about the CPU that will be used by cache flush
  233. * routines and/or provided to userland
  234. */
  235. static void __init initialize_cache_info(void)
  236. {
  237. struct device_node *np;
  238. unsigned long num_cpus = 0;
  239. DBG(" -> initialize_cache_info()\n");
  240. for (np = NULL; (np = of_find_node_by_type(np, "cpu"));) {
  241. num_cpus += 1;
  242. /* We're assuming *all* of the CPUs have the same
  243. * d-cache and i-cache sizes... -Peter
  244. */
  245. if ( num_cpus == 1 ) {
  246. u32 *sizep, *lsizep;
  247. u32 size, lsize;
  248. const char *dc, *ic;
  249. /* Then read cache informations */
  250. if (machine_is(powermac)) {
  251. dc = "d-cache-block-size";
  252. ic = "i-cache-block-size";
  253. } else {
  254. dc = "d-cache-line-size";
  255. ic = "i-cache-line-size";
  256. }
  257. size = 0;
  258. lsize = cur_cpu_spec->dcache_bsize;
  259. sizep = (u32 *)get_property(np, "d-cache-size", NULL);
  260. if (sizep != NULL)
  261. size = *sizep;
  262. lsizep = (u32 *) get_property(np, dc, NULL);
  263. if (lsizep != NULL)
  264. lsize = *lsizep;
  265. if (sizep == 0 || lsizep == 0)
  266. DBG("Argh, can't find dcache properties ! "
  267. "sizep: %p, lsizep: %p\n", sizep, lsizep);
  268. ppc64_caches.dsize = size;
  269. ppc64_caches.dline_size = lsize;
  270. ppc64_caches.log_dline_size = __ilog2(lsize);
  271. ppc64_caches.dlines_per_page = PAGE_SIZE / lsize;
  272. size = 0;
  273. lsize = cur_cpu_spec->icache_bsize;
  274. sizep = (u32 *)get_property(np, "i-cache-size", NULL);
  275. if (sizep != NULL)
  276. size = *sizep;
  277. lsizep = (u32 *)get_property(np, ic, NULL);
  278. if (lsizep != NULL)
  279. lsize = *lsizep;
  280. if (sizep == 0 || lsizep == 0)
  281. DBG("Argh, can't find icache properties ! "
  282. "sizep: %p, lsizep: %p\n", sizep, lsizep);
  283. ppc64_caches.isize = size;
  284. ppc64_caches.iline_size = lsize;
  285. ppc64_caches.log_iline_size = __ilog2(lsize);
  286. ppc64_caches.ilines_per_page = PAGE_SIZE / lsize;
  287. }
  288. }
  289. DBG(" <- initialize_cache_info()\n");
  290. }
  291. /*
  292. * Do some initial setup of the system. The parameters are those which
  293. * were passed in from the bootloader.
  294. */
  295. void __init setup_system(void)
  296. {
  297. DBG(" -> setup_system()\n");
  298. /*
  299. * Unflatten the device-tree passed by prom_init or kexec
  300. */
  301. unflatten_device_tree();
  302. /*
  303. * Fill the ppc64_caches & systemcfg structures with informations
  304. * retrieved from the device-tree.
  305. */
  306. initialize_cache_info();
  307. /*
  308. * Initialize irq remapping subsystem
  309. */
  310. irq_early_init();
  311. #ifdef CONFIG_PPC_RTAS
  312. /*
  313. * Initialize RTAS if available
  314. */
  315. rtas_initialize();
  316. #endif /* CONFIG_PPC_RTAS */
  317. /*
  318. * Check if we have an initrd provided via the device-tree
  319. */
  320. check_for_initrd();
  321. /*
  322. * Do some platform specific early initializations, that includes
  323. * setting up the hash table pointers. It also sets up some interrupt-mapping
  324. * related options that will be used by finish_device_tree()
  325. */
  326. ppc_md.init_early();
  327. /*
  328. * We can discover serial ports now since the above did setup the
  329. * hash table management for us, thus ioremap works. We do that early
  330. * so that further code can be debugged
  331. */
  332. find_legacy_serial_ports();
  333. /*
  334. * Initialize xmon
  335. */
  336. #ifdef CONFIG_XMON_DEFAULT
  337. xmon_init(1);
  338. #endif
  339. /*
  340. * Register early console
  341. */
  342. register_early_udbg_console();
  343. if (do_early_xmon)
  344. debugger(NULL);
  345. check_smt_enabled();
  346. smp_setup_cpu_maps();
  347. #ifdef CONFIG_SMP
  348. /* Release secondary cpus out of their spinloops at 0x60 now that
  349. * we can map physical -> logical CPU ids
  350. */
  351. smp_release_cpus();
  352. #endif
  353. printk("Starting Linux PPC64 %s\n", system_utsname.version);
  354. printk("-----------------------------------------------------\n");
  355. printk("ppc64_pft_size = 0x%lx\n", ppc64_pft_size);
  356. printk("physicalMemorySize = 0x%lx\n", lmb_phys_mem_size());
  357. printk("ppc64_caches.dcache_line_size = 0x%x\n",
  358. ppc64_caches.dline_size);
  359. printk("ppc64_caches.icache_line_size = 0x%x\n",
  360. ppc64_caches.iline_size);
  361. printk("htab_address = 0x%p\n", htab_address);
  362. printk("htab_hash_mask = 0x%lx\n", htab_hash_mask);
  363. #if PHYSICAL_START > 0
  364. printk("physical_start = 0x%x\n", PHYSICAL_START);
  365. #endif
  366. printk("-----------------------------------------------------\n");
  367. DBG(" <- setup_system()\n");
  368. }
  369. #ifdef CONFIG_IRQSTACKS
  370. static void __init irqstack_early_init(void)
  371. {
  372. unsigned int i;
  373. /*
  374. * interrupt stacks must be under 256MB, we cannot afford to take
  375. * SLB misses on them.
  376. */
  377. for_each_possible_cpu(i) {
  378. softirq_ctx[i] = (struct thread_info *)
  379. __va(lmb_alloc_base(THREAD_SIZE,
  380. THREAD_SIZE, 0x10000000));
  381. hardirq_ctx[i] = (struct thread_info *)
  382. __va(lmb_alloc_base(THREAD_SIZE,
  383. THREAD_SIZE, 0x10000000));
  384. }
  385. }
  386. #else
  387. #define irqstack_early_init()
  388. #endif
  389. /*
  390. * Stack space used when we detect a bad kernel stack pointer, and
  391. * early in SMP boots before relocation is enabled.
  392. */
  393. static void __init emergency_stack_init(void)
  394. {
  395. unsigned long limit;
  396. unsigned int i;
  397. /*
  398. * Emergency stacks must be under 256MB, we cannot afford to take
  399. * SLB misses on them. The ABI also requires them to be 128-byte
  400. * aligned.
  401. *
  402. * Since we use these as temporary stacks during secondary CPU
  403. * bringup, we need to get at them in real mode. This means they
  404. * must also be within the RMO region.
  405. */
  406. limit = min(0x10000000UL, lmb.rmo_size);
  407. for_each_possible_cpu(i)
  408. paca[i].emergency_sp =
  409. __va(lmb_alloc_base(HW_PAGE_SIZE, 128, limit)) + HW_PAGE_SIZE;
  410. }
  411. /*
  412. * Called into from start_kernel, after lock_kernel has been called.
  413. * Initializes bootmem, which is unsed to manage page allocation until
  414. * mem_init is called.
  415. */
  416. void __init setup_arch(char **cmdline_p)
  417. {
  418. ppc64_boot_msg(0x12, "Setup Arch");
  419. *cmdline_p = cmd_line;
  420. /*
  421. * Set cache line size based on type of cpu as a default.
  422. * Systems with OF can look in the properties on the cpu node(s)
  423. * for a possibly more accurate value.
  424. */
  425. dcache_bsize = ppc64_caches.dline_size;
  426. icache_bsize = ppc64_caches.iline_size;
  427. /* reboot on panic */
  428. panic_timeout = 180;
  429. if (ppc_md.panic)
  430. setup_panic();
  431. init_mm.start_code = PAGE_OFFSET;
  432. init_mm.end_code = (unsigned long) _etext;
  433. init_mm.end_data = (unsigned long) _edata;
  434. init_mm.brk = klimit;
  435. irqstack_early_init();
  436. emergency_stack_init();
  437. stabs_alloc();
  438. /* set up the bootmem stuff with available memory */
  439. do_init_bootmem();
  440. sparse_init();
  441. #ifdef CONFIG_DUMMY_CONSOLE
  442. conswitchp = &dummy_con;
  443. #endif
  444. ppc_md.setup_arch();
  445. paging_init();
  446. ppc64_boot_msg(0x15, "Setup Done");
  447. }
  448. /* ToDo: do something useful if ppc_md is not yet setup. */
  449. #define PPC64_LINUX_FUNCTION 0x0f000000
  450. #define PPC64_IPL_MESSAGE 0xc0000000
  451. #define PPC64_TERM_MESSAGE 0xb0000000
  452. static void ppc64_do_msg(unsigned int src, const char *msg)
  453. {
  454. if (ppc_md.progress) {
  455. char buf[128];
  456. sprintf(buf, "%08X\n", src);
  457. ppc_md.progress(buf, 0);
  458. snprintf(buf, 128, "%s", msg);
  459. ppc_md.progress(buf, 0);
  460. }
  461. }
  462. /* Print a boot progress message. */
  463. void ppc64_boot_msg(unsigned int src, const char *msg)
  464. {
  465. ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_IPL_MESSAGE|src, msg);
  466. printk("[boot]%04x %s\n", src, msg);
  467. }
  468. /* Print a termination message (print only -- does not stop the kernel) */
  469. void ppc64_terminate_msg(unsigned int src, const char *msg)
  470. {
  471. ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_TERM_MESSAGE|src, msg);
  472. printk("[terminate]%04x %s\n", src, msg);
  473. }
  474. void cpu_die(void)
  475. {
  476. if (ppc_md.cpu_die)
  477. ppc_md.cpu_die();
  478. }
  479. #ifdef CONFIG_SMP
  480. void __init setup_per_cpu_areas(void)
  481. {
  482. int i;
  483. unsigned long size;
  484. char *ptr;
  485. /* Copy section for each CPU (we discard the original) */
  486. size = ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES);
  487. #ifdef CONFIG_MODULES
  488. if (size < PERCPU_ENOUGH_ROOM)
  489. size = PERCPU_ENOUGH_ROOM;
  490. #endif
  491. for_each_possible_cpu(i) {
  492. ptr = alloc_bootmem_node(NODE_DATA(cpu_to_node(i)), size);
  493. if (!ptr)
  494. panic("Cannot allocate cpu data for CPU %d\n", i);
  495. paca[i].data_offset = ptr - __per_cpu_start;
  496. memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
  497. }
  498. }
  499. #endif