setup_64.c 32 KB

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