setup_64.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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/prom.h>
  36. #include <asm/processor.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/smp.h>
  39. #include <asm/elf.h>
  40. #include <asm/machdep.h>
  41. #include <asm/paca.h>
  42. #include <asm/ppcdebug.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/ItLpNaca.h>
  58. #include <asm/firmware.h>
  59. #include <asm/systemcfg.h>
  60. #ifdef DEBUG
  61. #define DBG(fmt...) udbg_printf(fmt)
  62. #else
  63. #define DBG(fmt...)
  64. #endif
  65. /*
  66. * Here are some early debugging facilities. You can enable one
  67. * but your kernel will not boot on anything else if you do so
  68. */
  69. /* This one is for use on LPAR machines that support an HVC console
  70. * on vterm 0
  71. */
  72. extern void udbg_init_debug_lpar(void);
  73. /* This one is for use on Apple G5 machines
  74. */
  75. extern void udbg_init_pmac_realmode(void);
  76. /* That's RTAS panel debug */
  77. extern void call_rtas_display_status_delay(unsigned char c);
  78. /* Here's maple real mode debug */
  79. extern void udbg_init_maple_realmode(void);
  80. #define EARLY_DEBUG_INIT() do {} while(0)
  81. #if 0
  82. #define EARLY_DEBUG_INIT() udbg_init_debug_lpar()
  83. #define EARLY_DEBUG_INIT() udbg_init_maple_realmode()
  84. #define EARLY_DEBUG_INIT() udbg_init_pmac_realmode()
  85. #define EARLY_DEBUG_INIT() \
  86. do { udbg_putc = call_rtas_display_status_delay; } while(0)
  87. #endif
  88. /* extern void *stab; */
  89. extern unsigned long klimit;
  90. extern void mm_init_ppc64(void);
  91. extern void stab_initialize(unsigned long stab);
  92. extern void htab_initialize(void);
  93. extern void early_init_devtree(void *flat_dt);
  94. extern void unflatten_device_tree(void);
  95. extern void smp_release_cpus(void);
  96. int have_of = 1;
  97. int boot_cpuid = 0;
  98. int boot_cpuid_phys = 0;
  99. dev_t boot_dev;
  100. u64 ppc64_pft_size;
  101. struct ppc64_caches ppc64_caches;
  102. EXPORT_SYMBOL_GPL(ppc64_caches);
  103. /*
  104. * These are used in binfmt_elf.c to put aux entries on the stack
  105. * for each elf executable being started.
  106. */
  107. int dcache_bsize;
  108. int icache_bsize;
  109. int ucache_bsize;
  110. /* The main machine-dep calls structure
  111. */
  112. struct machdep_calls ppc_md;
  113. EXPORT_SYMBOL(ppc_md);
  114. #ifdef CONFIG_MAGIC_SYSRQ
  115. unsigned long SYSRQ_KEY;
  116. #endif /* CONFIG_MAGIC_SYSRQ */
  117. static int ppc64_panic_event(struct notifier_block *, unsigned long, void *);
  118. static struct notifier_block ppc64_panic_block = {
  119. .notifier_call = ppc64_panic_event,
  120. .priority = INT_MIN /* may not return; must be done last */
  121. };
  122. #ifdef CONFIG_SMP
  123. static int smt_enabled_cmdline;
  124. /* Look for ibm,smt-enabled OF option */
  125. static void check_smt_enabled(void)
  126. {
  127. struct device_node *dn;
  128. char *smt_option;
  129. /* Allow the command line to overrule the OF option */
  130. if (smt_enabled_cmdline)
  131. return;
  132. dn = of_find_node_by_path("/options");
  133. if (dn) {
  134. smt_option = (char *)get_property(dn, "ibm,smt-enabled", NULL);
  135. if (smt_option) {
  136. if (!strcmp(smt_option, "on"))
  137. smt_enabled_at_boot = 1;
  138. else if (!strcmp(smt_option, "off"))
  139. smt_enabled_at_boot = 0;
  140. }
  141. }
  142. }
  143. /* Look for smt-enabled= cmdline option */
  144. static int __init early_smt_enabled(char *p)
  145. {
  146. smt_enabled_cmdline = 1;
  147. if (!p)
  148. return 0;
  149. if (!strcmp(p, "on") || !strcmp(p, "1"))
  150. smt_enabled_at_boot = 1;
  151. else if (!strcmp(p, "off") || !strcmp(p, "0"))
  152. smt_enabled_at_boot = 0;
  153. return 0;
  154. }
  155. early_param("smt-enabled", early_smt_enabled);
  156. /**
  157. * setup_cpu_maps - initialize the following cpu maps:
  158. * cpu_possible_map
  159. * cpu_present_map
  160. * cpu_sibling_map
  161. *
  162. * Having the possible map set up early allows us to restrict allocations
  163. * of things like irqstacks to num_possible_cpus() rather than NR_CPUS.
  164. *
  165. * We do not initialize the online map here; cpus set their own bits in
  166. * cpu_online_map as they come up.
  167. *
  168. * This function is valid only for Open Firmware systems. finish_device_tree
  169. * must be called before using this.
  170. *
  171. * While we're here, we may as well set the "physical" cpu ids in the paca.
  172. */
  173. static void __init setup_cpu_maps(void)
  174. {
  175. struct device_node *dn = NULL;
  176. int cpu = 0;
  177. int swap_cpuid = 0;
  178. check_smt_enabled();
  179. while ((dn = of_find_node_by_type(dn, "cpu")) && cpu < NR_CPUS) {
  180. u32 *intserv;
  181. int j, len = sizeof(u32), nthreads;
  182. intserv = (u32 *)get_property(dn, "ibm,ppc-interrupt-server#s",
  183. &len);
  184. if (!intserv)
  185. intserv = (u32 *)get_property(dn, "reg", NULL);
  186. nthreads = len / sizeof(u32);
  187. for (j = 0; j < nthreads && cpu < NR_CPUS; j++) {
  188. cpu_set(cpu, cpu_present_map);
  189. set_hard_smp_processor_id(cpu, intserv[j]);
  190. if (intserv[j] == boot_cpuid_phys)
  191. swap_cpuid = cpu;
  192. cpu_set(cpu, cpu_possible_map);
  193. cpu++;
  194. }
  195. }
  196. /* Swap CPU id 0 with boot_cpuid_phys, so we can always assume that
  197. * boot cpu is logical 0.
  198. */
  199. if (boot_cpuid_phys != get_hard_smp_processor_id(0)) {
  200. u32 tmp;
  201. tmp = get_hard_smp_processor_id(0);
  202. set_hard_smp_processor_id(0, boot_cpuid_phys);
  203. set_hard_smp_processor_id(swap_cpuid, tmp);
  204. }
  205. /*
  206. * On pSeries LPAR, we need to know how many cpus
  207. * could possibly be added to this partition.
  208. */
  209. if (systemcfg->platform == PLATFORM_PSERIES_LPAR &&
  210. (dn = of_find_node_by_path("/rtas"))) {
  211. int num_addr_cell, num_size_cell, maxcpus;
  212. unsigned int *ireg;
  213. num_addr_cell = prom_n_addr_cells(dn);
  214. num_size_cell = prom_n_size_cells(dn);
  215. ireg = (unsigned int *)
  216. get_property(dn, "ibm,lrdr-capacity", NULL);
  217. if (!ireg)
  218. goto out;
  219. maxcpus = ireg[num_addr_cell + num_size_cell];
  220. /* Double maxcpus for processors which have SMT capability */
  221. if (cpu_has_feature(CPU_FTR_SMT))
  222. maxcpus *= 2;
  223. if (maxcpus > NR_CPUS) {
  224. printk(KERN_WARNING
  225. "Partition configured for %d cpus, "
  226. "operating system maximum is %d.\n",
  227. maxcpus, NR_CPUS);
  228. maxcpus = NR_CPUS;
  229. } else
  230. printk(KERN_INFO "Partition configured for %d cpus.\n",
  231. maxcpus);
  232. for (cpu = 0; cpu < maxcpus; cpu++)
  233. cpu_set(cpu, cpu_possible_map);
  234. out:
  235. of_node_put(dn);
  236. }
  237. /*
  238. * Do the sibling map; assume only two threads per processor.
  239. */
  240. for_each_cpu(cpu) {
  241. cpu_set(cpu, cpu_sibling_map[cpu]);
  242. if (cpu_has_feature(CPU_FTR_SMT))
  243. cpu_set(cpu ^ 0x1, cpu_sibling_map[cpu]);
  244. }
  245. systemcfg->processorCount = num_present_cpus();
  246. }
  247. #endif /* CONFIG_SMP */
  248. extern struct machdep_calls pSeries_md;
  249. extern struct machdep_calls pmac_md;
  250. extern struct machdep_calls maple_md;
  251. extern struct machdep_calls bpa_md;
  252. extern struct machdep_calls iseries_md;
  253. /* Ultimately, stuff them in an elf section like initcalls... */
  254. static struct machdep_calls __initdata *machines[] = {
  255. #ifdef CONFIG_PPC_PSERIES
  256. &pSeries_md,
  257. #endif /* CONFIG_PPC_PSERIES */
  258. #ifdef CONFIG_PPC_PMAC
  259. &pmac_md,
  260. #endif /* CONFIG_PPC_PMAC */
  261. #ifdef CONFIG_PPC_MAPLE
  262. &maple_md,
  263. #endif /* CONFIG_PPC_MAPLE */
  264. #ifdef CONFIG_PPC_BPA
  265. &bpa_md,
  266. #endif
  267. #ifdef CONFIG_PPC_ISERIES
  268. &iseries_md,
  269. #endif
  270. NULL
  271. };
  272. /*
  273. * Early initialization entry point. This is called by head.S
  274. * with MMU translation disabled. We rely on the "feature" of
  275. * the CPU that ignores the top 2 bits of the address in real
  276. * mode so we can access kernel globals normally provided we
  277. * only toy with things in the RMO region. From here, we do
  278. * some early parsing of the device-tree to setup out LMB
  279. * data structures, and allocate & initialize the hash table
  280. * and segment tables so we can start running with translation
  281. * enabled.
  282. *
  283. * It is this function which will call the probe() callback of
  284. * the various platform types and copy the matching one to the
  285. * global ppc_md structure. Your platform can eventually do
  286. * some very early initializations from the probe() routine, but
  287. * this is not recommended, be very careful as, for example, the
  288. * device-tree is not accessible via normal means at this point.
  289. */
  290. void __init early_setup(unsigned long dt_ptr)
  291. {
  292. struct paca_struct *lpaca = get_paca();
  293. static struct machdep_calls **mach;
  294. /*
  295. * Enable early debugging if any specified (see top of
  296. * this file)
  297. */
  298. EARLY_DEBUG_INIT();
  299. DBG(" -> early_setup()\n");
  300. /*
  301. * Fill the default DBG level (do we want to keep
  302. * that old mecanism around forever ?)
  303. */
  304. ppcdbg_initialize();
  305. /*
  306. * Do early initializations using the flattened device
  307. * tree, like retreiving the physical memory map or
  308. * calculating/retreiving the hash table size
  309. */
  310. early_init_devtree(__va(dt_ptr));
  311. /*
  312. * Iterate all ppc_md structures until we find the proper
  313. * one for the current machine type
  314. */
  315. DBG("Probing machine type for platform %x...\n",
  316. systemcfg->platform);
  317. for (mach = machines; *mach; mach++) {
  318. if ((*mach)->probe(systemcfg->platform))
  319. break;
  320. }
  321. /* What can we do if we didn't find ? */
  322. if (*mach == NULL) {
  323. DBG("No suitable machine found !\n");
  324. for (;;);
  325. }
  326. ppc_md = **mach;
  327. DBG("Found, Initializing memory management...\n");
  328. /*
  329. * Initialize stab / SLB management
  330. */
  331. if (!firmware_has_feature(FW_FEATURE_ISERIES))
  332. stab_initialize(lpaca->stab_real);
  333. /*
  334. * Initialize the MMU Hash table and create the linear mapping
  335. * of memory
  336. */
  337. htab_initialize();
  338. DBG(" <- early_setup()\n");
  339. }
  340. /*
  341. * Initialize some remaining members of the ppc64_caches and systemcfg structures
  342. * (at least until we get rid of them completely). This is mostly some
  343. * cache informations about the CPU that will be used by cache flush
  344. * routines and/or provided to userland
  345. */
  346. static void __init initialize_cache_info(void)
  347. {
  348. struct device_node *np;
  349. unsigned long num_cpus = 0;
  350. DBG(" -> initialize_cache_info()\n");
  351. for (np = NULL; (np = of_find_node_by_type(np, "cpu"));) {
  352. num_cpus += 1;
  353. /* We're assuming *all* of the CPUs have the same
  354. * d-cache and i-cache sizes... -Peter
  355. */
  356. if ( num_cpus == 1 ) {
  357. u32 *sizep, *lsizep;
  358. u32 size, lsize;
  359. const char *dc, *ic;
  360. /* Then read cache informations */
  361. if (systemcfg->platform == PLATFORM_POWERMAC) {
  362. dc = "d-cache-block-size";
  363. ic = "i-cache-block-size";
  364. } else {
  365. dc = "d-cache-line-size";
  366. ic = "i-cache-line-size";
  367. }
  368. size = 0;
  369. lsize = cur_cpu_spec->dcache_bsize;
  370. sizep = (u32 *)get_property(np, "d-cache-size", NULL);
  371. if (sizep != NULL)
  372. size = *sizep;
  373. lsizep = (u32 *) get_property(np, dc, NULL);
  374. if (lsizep != NULL)
  375. lsize = *lsizep;
  376. if (sizep == 0 || lsizep == 0)
  377. DBG("Argh, can't find dcache properties ! "
  378. "sizep: %p, lsizep: %p\n", sizep, lsizep);
  379. systemcfg->dcache_size = ppc64_caches.dsize = size;
  380. systemcfg->dcache_line_size =
  381. ppc64_caches.dline_size = lsize;
  382. ppc64_caches.log_dline_size = __ilog2(lsize);
  383. ppc64_caches.dlines_per_page = PAGE_SIZE / lsize;
  384. size = 0;
  385. lsize = cur_cpu_spec->icache_bsize;
  386. sizep = (u32 *)get_property(np, "i-cache-size", NULL);
  387. if (sizep != NULL)
  388. size = *sizep;
  389. lsizep = (u32 *)get_property(np, ic, NULL);
  390. if (lsizep != NULL)
  391. lsize = *lsizep;
  392. if (sizep == 0 || lsizep == 0)
  393. DBG("Argh, can't find icache properties ! "
  394. "sizep: %p, lsizep: %p\n", sizep, lsizep);
  395. systemcfg->icache_size = ppc64_caches.isize = size;
  396. systemcfg->icache_line_size =
  397. ppc64_caches.iline_size = lsize;
  398. ppc64_caches.log_iline_size = __ilog2(lsize);
  399. ppc64_caches.ilines_per_page = PAGE_SIZE / lsize;
  400. }
  401. }
  402. /* Add an eye catcher and the systemcfg layout version number */
  403. strcpy(systemcfg->eye_catcher, "SYSTEMCFG:PPC64");
  404. systemcfg->version.major = SYSTEMCFG_MAJOR;
  405. systemcfg->version.minor = SYSTEMCFG_MINOR;
  406. systemcfg->processor = mfspr(SPRN_PVR);
  407. DBG(" <- initialize_cache_info()\n");
  408. }
  409. static void __init check_for_initrd(void)
  410. {
  411. #ifdef CONFIG_BLK_DEV_INITRD
  412. u64 *prop;
  413. DBG(" -> check_for_initrd()\n");
  414. if (of_chosen) {
  415. prop = (u64 *)get_property(of_chosen,
  416. "linux,initrd-start", NULL);
  417. if (prop != NULL) {
  418. initrd_start = (unsigned long)__va(*prop);
  419. prop = (u64 *)get_property(of_chosen,
  420. "linux,initrd-end", NULL);
  421. if (prop != NULL) {
  422. initrd_end = (unsigned long)__va(*prop);
  423. initrd_below_start_ok = 1;
  424. } else
  425. initrd_start = 0;
  426. }
  427. }
  428. /* If we were passed an initrd, set the ROOT_DEV properly if the values
  429. * look sensible. If not, clear initrd reference.
  430. */
  431. if (initrd_start >= KERNELBASE && initrd_end >= KERNELBASE &&
  432. initrd_end > initrd_start)
  433. ROOT_DEV = Root_RAM0;
  434. else
  435. initrd_start = initrd_end = 0;
  436. if (initrd_start)
  437. printk("Found initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
  438. DBG(" <- check_for_initrd()\n");
  439. #endif /* CONFIG_BLK_DEV_INITRD */
  440. }
  441. /*
  442. * Do some initial setup of the system. The parameters are those which
  443. * were passed in from the bootloader.
  444. */
  445. void __init setup_system(void)
  446. {
  447. DBG(" -> setup_system()\n");
  448. /*
  449. * Unflatten the device-tree passed by prom_init or kexec
  450. */
  451. unflatten_device_tree();
  452. /*
  453. * Fill the ppc64_caches & systemcfg structures with informations
  454. * retreived from the device-tree. Need to be called before
  455. * finish_device_tree() since the later requires some of the
  456. * informations filled up here to properly parse the interrupt
  457. * tree.
  458. * It also sets up the cache line sizes which allows to call
  459. * routines like flush_icache_range (used by the hash init
  460. * later on).
  461. */
  462. initialize_cache_info();
  463. #ifdef CONFIG_PPC_RTAS
  464. /*
  465. * Initialize RTAS if available
  466. */
  467. rtas_initialize();
  468. #endif /* CONFIG_PPC_RTAS */
  469. /*
  470. * Check if we have an initrd provided via the device-tree
  471. */
  472. check_for_initrd();
  473. /*
  474. * Do some platform specific early initializations, that includes
  475. * setting up the hash table pointers. It also sets up some interrupt-mapping
  476. * related options that will be used by finish_device_tree()
  477. */
  478. ppc_md.init_early();
  479. /*
  480. * "Finish" the device-tree, that is do the actual parsing of
  481. * some of the properties like the interrupt map
  482. */
  483. finish_device_tree();
  484. #ifdef CONFIG_BOOTX_TEXT
  485. init_boot_display();
  486. #endif
  487. /*
  488. * Initialize xmon
  489. */
  490. #ifdef CONFIG_XMON_DEFAULT
  491. xmon_init(1);
  492. #endif
  493. /*
  494. * Register early console
  495. */
  496. register_early_udbg_console();
  497. /* Save unparsed command line copy for /proc/cmdline */
  498. strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
  499. parse_early_param();
  500. #ifdef CONFIG_SMP
  501. /*
  502. * iSeries has already initialized the cpu maps at this point.
  503. */
  504. setup_cpu_maps();
  505. /* Release secondary cpus out of their spinloops at 0x60 now that
  506. * we can map physical -> logical CPU ids
  507. */
  508. smp_release_cpus();
  509. #endif
  510. printk("Starting Linux PPC64 %s\n", system_utsname.version);
  511. printk("-----------------------------------------------------\n");
  512. printk("ppc64_pft_size = 0x%lx\n", ppc64_pft_size);
  513. printk("ppc64_debug_switch = 0x%lx\n", ppc64_debug_switch);
  514. printk("ppc64_interrupt_controller = 0x%ld\n", ppc64_interrupt_controller);
  515. printk("systemcfg = 0x%p\n", systemcfg);
  516. printk("systemcfg->platform = 0x%x\n", systemcfg->platform);
  517. printk("systemcfg->processorCount = 0x%lx\n", systemcfg->processorCount);
  518. printk("systemcfg->physicalMemorySize = 0x%lx\n", systemcfg->physicalMemorySize);
  519. printk("ppc64_caches.dcache_line_size = 0x%x\n",
  520. ppc64_caches.dline_size);
  521. printk("ppc64_caches.icache_line_size = 0x%x\n",
  522. ppc64_caches.iline_size);
  523. printk("htab_address = 0x%p\n", htab_address);
  524. printk("htab_hash_mask = 0x%lx\n", htab_hash_mask);
  525. printk("-----------------------------------------------------\n");
  526. mm_init_ppc64();
  527. DBG(" <- setup_system()\n");
  528. }
  529. static int ppc64_panic_event(struct notifier_block *this,
  530. unsigned long event, void *ptr)
  531. {
  532. ppc_md.panic((char *)ptr); /* May not return */
  533. return NOTIFY_DONE;
  534. }
  535. /*
  536. * These three variables are used to save values passed to us by prom_init()
  537. * via the device tree. The TCE variables are needed because with a memory_limit
  538. * in force we may need to explicitly map the TCE are at the top of RAM.
  539. */
  540. unsigned long memory_limit;
  541. unsigned long tce_alloc_start;
  542. unsigned long tce_alloc_end;
  543. #ifdef CONFIG_PPC_ISERIES
  544. /*
  545. * On iSeries we just parse the mem=X option from the command line.
  546. * On pSeries it's a bit more complicated, see prom_init_mem()
  547. */
  548. static int __init early_parsemem(char *p)
  549. {
  550. if (!p)
  551. return 0;
  552. memory_limit = ALIGN(memparse(p, &p), PAGE_SIZE);
  553. return 0;
  554. }
  555. early_param("mem", early_parsemem);
  556. #endif /* CONFIG_PPC_ISERIES */
  557. #ifdef CONFIG_IRQSTACKS
  558. static void __init irqstack_early_init(void)
  559. {
  560. unsigned int i;
  561. /*
  562. * interrupt stacks must be under 256MB, we cannot afford to take
  563. * SLB misses on them.
  564. */
  565. for_each_cpu(i) {
  566. softirq_ctx[i] = (struct thread_info *)__va(lmb_alloc_base(THREAD_SIZE,
  567. THREAD_SIZE, 0x10000000));
  568. hardirq_ctx[i] = (struct thread_info *)__va(lmb_alloc_base(THREAD_SIZE,
  569. THREAD_SIZE, 0x10000000));
  570. }
  571. }
  572. #else
  573. #define irqstack_early_init()
  574. #endif
  575. /*
  576. * Stack space used when we detect a bad kernel stack pointer, and
  577. * early in SMP boots before relocation is enabled.
  578. */
  579. static void __init emergency_stack_init(void)
  580. {
  581. unsigned long limit;
  582. unsigned int i;
  583. /*
  584. * Emergency stacks must be under 256MB, we cannot afford to take
  585. * SLB misses on them. The ABI also requires them to be 128-byte
  586. * aligned.
  587. *
  588. * Since we use these as temporary stacks during secondary CPU
  589. * bringup, we need to get at them in real mode. This means they
  590. * must also be within the RMO region.
  591. */
  592. limit = min(0x10000000UL, lmb.rmo_size);
  593. for_each_cpu(i)
  594. paca[i].emergency_sp = __va(lmb_alloc_base(PAGE_SIZE, 128,
  595. limit)) + PAGE_SIZE;
  596. }
  597. extern unsigned long *sys_call_table;
  598. extern unsigned long sys_ni_syscall;
  599. #ifdef CONFIG_PPC_MERGE
  600. #define SYS_CALL_ENTRY64(i) sys_call_table[(i) * 2]
  601. #define SYS_CALL_ENTRY32(i) sys_call_table[(i) * 2 + 1]
  602. #else
  603. extern unsigned long *sys_call_table32;
  604. #define SYS_CALL_ENTRY64(i) sys_call_table[(i)]
  605. #define SYS_CALL_ENTRY32(i) sys_call_table32[(i)]
  606. #endif
  607. /*
  608. * Called from setup_arch to initialize the bitmap of available
  609. * syscalls in the systemcfg page
  610. */
  611. void __init setup_syscall_map(void)
  612. {
  613. unsigned int i, count64 = 0, count32 = 0;
  614. for (i = 0; i < __NR_syscalls; i++) {
  615. if (SYS_CALL_ENTRY64(i) != sys_ni_syscall) {
  616. count64++;
  617. systemcfg->syscall_map_64[i >> 5] |=
  618. 0x80000000UL >> (i & 0x1f);
  619. }
  620. if (SYS_CALL_ENTRY32(i) != sys_ni_syscall) {
  621. count32++;
  622. systemcfg->syscall_map_32[i >> 5] |=
  623. 0x80000000UL >> (i & 0x1f);
  624. }
  625. }
  626. printk(KERN_INFO "Syscall map setup, %d 32-bit and %d 64-bit syscalls\n",
  627. count32, count64);
  628. }
  629. /*
  630. * Called into from start_kernel, after lock_kernel has been called.
  631. * Initializes bootmem, which is unsed to manage page allocation until
  632. * mem_init is called.
  633. */
  634. void __init setup_arch(char **cmdline_p)
  635. {
  636. extern void do_init_bootmem(void);
  637. ppc64_boot_msg(0x12, "Setup Arch");
  638. *cmdline_p = cmd_line;
  639. /*
  640. * Set cache line size based on type of cpu as a default.
  641. * Systems with OF can look in the properties on the cpu node(s)
  642. * for a possibly more accurate value.
  643. */
  644. dcache_bsize = ppc64_caches.dline_size;
  645. icache_bsize = ppc64_caches.iline_size;
  646. /* reboot on panic */
  647. panic_timeout = 180;
  648. if (ppc_md.panic)
  649. notifier_chain_register(&panic_notifier_list, &ppc64_panic_block);
  650. init_mm.start_code = PAGE_OFFSET;
  651. init_mm.end_code = (unsigned long) _etext;
  652. init_mm.end_data = (unsigned long) _edata;
  653. init_mm.brk = klimit;
  654. irqstack_early_init();
  655. emergency_stack_init();
  656. stabs_alloc();
  657. /* set up the bootmem stuff with available memory */
  658. do_init_bootmem();
  659. sparse_init();
  660. /* initialize the syscall map in systemcfg */
  661. setup_syscall_map();
  662. #ifdef CONFIG_DUMMY_CONSOLE
  663. conswitchp = &dummy_con;
  664. #endif
  665. ppc_md.setup_arch();
  666. /* Use the default idle loop if the platform hasn't provided one. */
  667. if (NULL == ppc_md.idle_loop) {
  668. ppc_md.idle_loop = default_idle;
  669. printk(KERN_INFO "Using default idle loop\n");
  670. }
  671. paging_init();
  672. ppc64_boot_msg(0x15, "Setup Done");
  673. }
  674. /* ToDo: do something useful if ppc_md is not yet setup. */
  675. #define PPC64_LINUX_FUNCTION 0x0f000000
  676. #define PPC64_IPL_MESSAGE 0xc0000000
  677. #define PPC64_TERM_MESSAGE 0xb0000000
  678. static void ppc64_do_msg(unsigned int src, const char *msg)
  679. {
  680. if (ppc_md.progress) {
  681. char buf[128];
  682. sprintf(buf, "%08X\n", src);
  683. ppc_md.progress(buf, 0);
  684. snprintf(buf, 128, "%s", msg);
  685. ppc_md.progress(buf, 0);
  686. }
  687. }
  688. /* Print a boot progress message. */
  689. void ppc64_boot_msg(unsigned int src, const char *msg)
  690. {
  691. ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_IPL_MESSAGE|src, msg);
  692. printk("[boot]%04x %s\n", src, msg);
  693. }
  694. /* Print a termination message (print only -- does not stop the kernel) */
  695. void ppc64_terminate_msg(unsigned int src, const char *msg)
  696. {
  697. ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_TERM_MESSAGE|src, msg);
  698. printk("[terminate]%04x %s\n", src, msg);
  699. }
  700. #ifndef CONFIG_PPC_ISERIES
  701. /*
  702. * This function can be used by platforms to "find" legacy serial ports.
  703. * It works for "serial" nodes under an "isa" node, and will try to
  704. * respect the "ibm,aix-loc" property if any. It works with up to 8
  705. * ports.
  706. */
  707. #define MAX_LEGACY_SERIAL_PORTS 8
  708. static struct plat_serial8250_port serial_ports[MAX_LEGACY_SERIAL_PORTS+1];
  709. static unsigned int old_serial_count;
  710. void __init generic_find_legacy_serial_ports(u64 *physport,
  711. unsigned int *default_speed)
  712. {
  713. struct device_node *np;
  714. u32 *sizeprop;
  715. struct isa_reg_property {
  716. u32 space;
  717. u32 address;
  718. u32 size;
  719. };
  720. struct pci_reg_property {
  721. struct pci_address addr;
  722. u32 size_hi;
  723. u32 size_lo;
  724. };
  725. DBG(" -> generic_find_legacy_serial_port()\n");
  726. *physport = 0;
  727. if (default_speed)
  728. *default_speed = 0;
  729. np = of_find_node_by_path("/");
  730. if (!np)
  731. return;
  732. /* First fill our array */
  733. for (np = NULL; (np = of_find_node_by_type(np, "serial"));) {
  734. struct device_node *isa, *pci;
  735. struct isa_reg_property *reg;
  736. unsigned long phys_size, addr_size, io_base;
  737. u32 *rangesp;
  738. u32 *interrupts, *clk, *spd;
  739. char *typep;
  740. int index, rlen, rentsize;
  741. /* Ok, first check if it's under an "isa" parent */
  742. isa = of_get_parent(np);
  743. if (!isa || strcmp(isa->name, "isa")) {
  744. DBG("%s: no isa parent found\n", np->full_name);
  745. continue;
  746. }
  747. /* Now look for an "ibm,aix-loc" property that gives us ordering
  748. * if any...
  749. */
  750. typep = (char *)get_property(np, "ibm,aix-loc", NULL);
  751. /* Get the ISA port number */
  752. reg = (struct isa_reg_property *)get_property(np, "reg", NULL);
  753. if (reg == NULL)
  754. goto next_port;
  755. /* We assume the interrupt number isn't translated ... */
  756. interrupts = (u32 *)get_property(np, "interrupts", NULL);
  757. /* get clock freq. if present */
  758. clk = (u32 *)get_property(np, "clock-frequency", NULL);
  759. /* get default speed if present */
  760. spd = (u32 *)get_property(np, "current-speed", NULL);
  761. /* Default to locate at end of array */
  762. index = old_serial_count; /* end of the array by default */
  763. /* If we have a location index, then use it */
  764. if (typep && *typep == 'S') {
  765. index = simple_strtol(typep+1, NULL, 0) - 1;
  766. /* if index is out of range, use end of array instead */
  767. if (index >= MAX_LEGACY_SERIAL_PORTS)
  768. index = old_serial_count;
  769. /* if our index is still out of range, that mean that
  770. * array is full, we could scan for a free slot but that
  771. * make little sense to bother, just skip the port
  772. */
  773. if (index >= MAX_LEGACY_SERIAL_PORTS)
  774. goto next_port;
  775. if (index >= old_serial_count)
  776. old_serial_count = index + 1;
  777. /* Check if there is a port who already claimed our slot */
  778. if (serial_ports[index].iobase != 0) {
  779. /* if we still have some room, move it, else override */
  780. if (old_serial_count < MAX_LEGACY_SERIAL_PORTS) {
  781. DBG("Moved legacy port %d -> %d\n", index,
  782. old_serial_count);
  783. serial_ports[old_serial_count++] =
  784. serial_ports[index];
  785. } else {
  786. DBG("Replacing legacy port %d\n", index);
  787. }
  788. }
  789. }
  790. if (index >= MAX_LEGACY_SERIAL_PORTS)
  791. goto next_port;
  792. if (index >= old_serial_count)
  793. old_serial_count = index + 1;
  794. /* Now fill the entry */
  795. memset(&serial_ports[index], 0, sizeof(struct plat_serial8250_port));
  796. serial_ports[index].uartclk = clk ? *clk : BASE_BAUD * 16;
  797. serial_ports[index].iobase = reg->address;
  798. serial_ports[index].irq = interrupts ? interrupts[0] : 0;
  799. serial_ports[index].flags = ASYNC_BOOT_AUTOCONF;
  800. DBG("Added legacy port, index: %d, port: %x, irq: %d, clk: %d\n",
  801. index,
  802. serial_ports[index].iobase,
  803. serial_ports[index].irq,
  804. serial_ports[index].uartclk);
  805. /* Get phys address of IO reg for port 1 */
  806. if (index != 0)
  807. goto next_port;
  808. pci = of_get_parent(isa);
  809. if (!pci) {
  810. DBG("%s: no pci parent found\n", np->full_name);
  811. goto next_port;
  812. }
  813. rangesp = (u32 *)get_property(pci, "ranges", &rlen);
  814. if (rangesp == NULL) {
  815. of_node_put(pci);
  816. goto next_port;
  817. }
  818. rlen /= 4;
  819. /* we need the #size-cells of the PCI bridge node itself */
  820. phys_size = 1;
  821. sizeprop = (u32 *)get_property(pci, "#size-cells", NULL);
  822. if (sizeprop != NULL)
  823. phys_size = *sizeprop;
  824. /* we need the parent #addr-cells */
  825. addr_size = prom_n_addr_cells(pci);
  826. rentsize = 3 + addr_size + phys_size;
  827. io_base = 0;
  828. for (;rlen >= rentsize; rlen -= rentsize,rangesp += rentsize) {
  829. if (((rangesp[0] >> 24) & 0x3) != 1)
  830. continue; /* not IO space */
  831. io_base = rangesp[3];
  832. if (addr_size == 2)
  833. io_base = (io_base << 32) | rangesp[4];
  834. }
  835. if (io_base != 0) {
  836. *physport = io_base + reg->address;
  837. if (default_speed && spd)
  838. *default_speed = *spd;
  839. }
  840. of_node_put(pci);
  841. next_port:
  842. of_node_put(isa);
  843. }
  844. DBG(" <- generic_find_legacy_serial_port()\n");
  845. }
  846. static struct platform_device serial_device = {
  847. .name = "serial8250",
  848. .id = PLAT8250_DEV_PLATFORM,
  849. .dev = {
  850. .platform_data = serial_ports,
  851. },
  852. };
  853. static int __init serial_dev_init(void)
  854. {
  855. return platform_device_register(&serial_device);
  856. }
  857. arch_initcall(serial_dev_init);
  858. #endif /* CONFIG_PPC_ISERIES */
  859. int check_legacy_ioport(unsigned long base_port)
  860. {
  861. if (ppc_md.check_legacy_ioport == NULL)
  862. return 0;
  863. return ppc_md.check_legacy_ioport(base_port);
  864. }
  865. EXPORT_SYMBOL(check_legacy_ioport);
  866. #ifdef CONFIG_XMON
  867. static int __init early_xmon(char *p)
  868. {
  869. /* ensure xmon is enabled */
  870. if (p) {
  871. if (strncmp(p, "on", 2) == 0)
  872. xmon_init(1);
  873. if (strncmp(p, "off", 3) == 0)
  874. xmon_init(0);
  875. if (strncmp(p, "early", 5) != 0)
  876. return 0;
  877. }
  878. xmon_init(1);
  879. debugger(NULL);
  880. return 0;
  881. }
  882. early_param("xmon", early_xmon);
  883. #endif
  884. void cpu_die(void)
  885. {
  886. if (ppc_md.cpu_die)
  887. ppc_md.cpu_die();
  888. }