setup_64.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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/time.h>
  43. #include <asm/cputable.h>
  44. #include <asm/sections.h>
  45. #include <asm/btext.h>
  46. #include <asm/nvram.h>
  47. #include <asm/setup.h>
  48. #include <asm/system.h>
  49. #include <asm/rtas.h>
  50. #include <asm/iommu.h>
  51. #include <asm/serial.h>
  52. #include <asm/cache.h>
  53. #include <asm/page.h>
  54. #include <asm/mmu.h>
  55. #include <asm/lmb.h>
  56. #include <asm/iseries/it_lp_naca.h>
  57. #include <asm/firmware.h>
  58. #include <asm/xmon.h>
  59. #include <asm/udbg.h>
  60. #include <asm/kexec.h>
  61. #include "setup.h"
  62. #ifdef DEBUG
  63. #define DBG(fmt...) udbg_printf(fmt)
  64. #else
  65. #define DBG(fmt...)
  66. #endif
  67. /*
  68. * Here are some early debugging facilities. You can enable one
  69. * but your kernel will not boot on anything else if you do so
  70. */
  71. /* This one is for use on LPAR machines that support an HVC console
  72. * on vterm 0
  73. */
  74. extern void udbg_init_debug_lpar(void);
  75. /* This one is for use on Apple G5 machines
  76. */
  77. extern void udbg_init_pmac_realmode(void);
  78. /* That's RTAS panel debug */
  79. extern void call_rtas_display_status_delay(unsigned char c);
  80. /* Here's maple real mode debug */
  81. extern void udbg_init_maple_realmode(void);
  82. #define EARLY_DEBUG_INIT() do {} while(0)
  83. #if 0
  84. #define EARLY_DEBUG_INIT() udbg_init_debug_lpar()
  85. #define EARLY_DEBUG_INIT() udbg_init_maple_realmode()
  86. #define EARLY_DEBUG_INIT() udbg_init_pmac_realmode()
  87. #define EARLY_DEBUG_INIT() \
  88. do { udbg_putc = call_rtas_display_status_delay; } while(0)
  89. #endif
  90. int have_of = 1;
  91. int boot_cpuid = 0;
  92. int boot_cpuid_phys = 0;
  93. dev_t boot_dev;
  94. u64 ppc64_pft_size;
  95. /* Pick defaults since we might want to patch instructions
  96. * before we've read this from the device tree.
  97. */
  98. struct ppc64_caches ppc64_caches = {
  99. .dline_size = 0x80,
  100. .log_dline_size = 7,
  101. .iline_size = 0x80,
  102. .log_iline_size = 7
  103. };
  104. EXPORT_SYMBOL_GPL(ppc64_caches);
  105. /*
  106. * These are used in binfmt_elf.c to put aux entries on the stack
  107. * for each elf executable being started.
  108. */
  109. int dcache_bsize;
  110. int icache_bsize;
  111. int ucache_bsize;
  112. /* The main machine-dep calls structure
  113. */
  114. struct machdep_calls ppc_md;
  115. EXPORT_SYMBOL(ppc_md);
  116. #ifdef CONFIG_MAGIC_SYSRQ
  117. unsigned long SYSRQ_KEY;
  118. #endif /* CONFIG_MAGIC_SYSRQ */
  119. static int ppc64_panic_event(struct notifier_block *, unsigned long, void *);
  120. static struct notifier_block ppc64_panic_block = {
  121. .notifier_call = ppc64_panic_event,
  122. .priority = INT_MIN /* may not return; must be done last */
  123. };
  124. #ifdef CONFIG_SMP
  125. static int smt_enabled_cmdline;
  126. /* Look for ibm,smt-enabled OF option */
  127. static void check_smt_enabled(void)
  128. {
  129. struct device_node *dn;
  130. char *smt_option;
  131. /* Allow the command line to overrule the OF option */
  132. if (smt_enabled_cmdline)
  133. return;
  134. dn = of_find_node_by_path("/options");
  135. if (dn) {
  136. smt_option = (char *)get_property(dn, "ibm,smt-enabled", NULL);
  137. if (smt_option) {
  138. if (!strcmp(smt_option, "on"))
  139. smt_enabled_at_boot = 1;
  140. else if (!strcmp(smt_option, "off"))
  141. smt_enabled_at_boot = 0;
  142. }
  143. }
  144. }
  145. /* Look for smt-enabled= cmdline option */
  146. static int __init early_smt_enabled(char *p)
  147. {
  148. smt_enabled_cmdline = 1;
  149. if (!p)
  150. return 0;
  151. if (!strcmp(p, "on") || !strcmp(p, "1"))
  152. smt_enabled_at_boot = 1;
  153. else if (!strcmp(p, "off") || !strcmp(p, "0"))
  154. smt_enabled_at_boot = 0;
  155. return 0;
  156. }
  157. early_param("smt-enabled", early_smt_enabled);
  158. #else
  159. #define check_smt_enabled()
  160. #endif /* CONFIG_SMP */
  161. extern struct machdep_calls pSeries_md;
  162. extern struct machdep_calls pmac_md;
  163. extern struct machdep_calls maple_md;
  164. extern struct machdep_calls cell_md;
  165. extern struct machdep_calls iseries_md;
  166. /* Ultimately, stuff them in an elf section like initcalls... */
  167. static struct machdep_calls __initdata *machines[] = {
  168. #ifdef CONFIG_PPC_PSERIES
  169. &pSeries_md,
  170. #endif /* CONFIG_PPC_PSERIES */
  171. #ifdef CONFIG_PPC_PMAC
  172. &pmac_md,
  173. #endif /* CONFIG_PPC_PMAC */
  174. #ifdef CONFIG_PPC_MAPLE
  175. &maple_md,
  176. #endif /* CONFIG_PPC_MAPLE */
  177. #ifdef CONFIG_PPC_CELL
  178. &cell_md,
  179. #endif
  180. #ifdef CONFIG_PPC_ISERIES
  181. &iseries_md,
  182. #endif
  183. NULL
  184. };
  185. /*
  186. * Early initialization entry point. This is called by head.S
  187. * with MMU translation disabled. We rely on the "feature" of
  188. * the CPU that ignores the top 2 bits of the address in real
  189. * mode so we can access kernel globals normally provided we
  190. * only toy with things in the RMO region. From here, we do
  191. * some early parsing of the device-tree to setup out LMB
  192. * data structures, and allocate & initialize the hash table
  193. * and segment tables so we can start running with translation
  194. * enabled.
  195. *
  196. * It is this function which will call the probe() callback of
  197. * the various platform types and copy the matching one to the
  198. * global ppc_md structure. Your platform can eventually do
  199. * some very early initializations from the probe() routine, but
  200. * this is not recommended, be very careful as, for example, the
  201. * device-tree is not accessible via normal means at this point.
  202. */
  203. void __init early_setup(unsigned long dt_ptr)
  204. {
  205. struct paca_struct *lpaca = get_paca();
  206. static struct machdep_calls **mach;
  207. /*
  208. * Enable early debugging if any specified (see top of
  209. * this file)
  210. */
  211. EARLY_DEBUG_INIT();
  212. DBG(" -> early_setup()\n");
  213. /*
  214. * Do early initializations using the flattened device
  215. * tree, like retreiving the physical memory map or
  216. * calculating/retreiving the hash table size
  217. */
  218. early_init_devtree(__va(dt_ptr));
  219. /*
  220. * Iterate all ppc_md structures until we find the proper
  221. * one for the current machine type
  222. */
  223. DBG("Probing machine type for platform %x...\n", _machine);
  224. for (mach = machines; *mach; mach++) {
  225. if ((*mach)->probe(_machine))
  226. break;
  227. }
  228. /* What can we do if we didn't find ? */
  229. if (*mach == NULL) {
  230. DBG("No suitable machine found !\n");
  231. for (;;);
  232. }
  233. ppc_md = **mach;
  234. DBG("Found, Initializing memory management...\n");
  235. /*
  236. * Initialize the MMU Hash table and create the linear mapping
  237. * of memory. Has to be done before stab/slb initialization as
  238. * this is currently where the page size encoding is obtained
  239. */
  240. htab_initialize();
  241. /*
  242. * Initialize stab / SLB management except on iSeries
  243. */
  244. if (!firmware_has_feature(FW_FEATURE_ISERIES)) {
  245. if (cpu_has_feature(CPU_FTR_SLB))
  246. slb_initialize();
  247. else
  248. stab_initialize(lpaca->stab_real);
  249. }
  250. DBG(" <- early_setup()\n");
  251. }
  252. #ifdef CONFIG_SMP
  253. void early_setup_secondary(void)
  254. {
  255. struct paca_struct *lpaca = get_paca();
  256. /* Mark enabled in PACA */
  257. lpaca->proc_enabled = 0;
  258. /* Initialize hash table for that CPU */
  259. htab_initialize_secondary();
  260. /* Initialize STAB/SLB. We use a virtual address as it works
  261. * in real mode on pSeries and we want a virutal address on
  262. * iSeries anyway
  263. */
  264. if (cpu_has_feature(CPU_FTR_SLB))
  265. slb_initialize();
  266. else
  267. stab_initialize(lpaca->stab_addr);
  268. }
  269. #endif /* CONFIG_SMP */
  270. #if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
  271. void smp_release_cpus(void)
  272. {
  273. extern unsigned long __secondary_hold_spinloop;
  274. DBG(" -> smp_release_cpus()\n");
  275. /* All secondary cpus are spinning on a common spinloop, release them
  276. * all now so they can start to spin on their individual paca
  277. * spinloops. For non SMP kernels, the secondary cpus never get out
  278. * of the common spinloop.
  279. * This is useless but harmless on iSeries, secondaries are already
  280. * waiting on their paca spinloops. */
  281. __secondary_hold_spinloop = 1;
  282. mb();
  283. DBG(" <- smp_release_cpus()\n");
  284. }
  285. #else
  286. #define smp_release_cpus()
  287. #endif /* CONFIG_SMP || CONFIG_KEXEC */
  288. /*
  289. * Initialize some remaining members of the ppc64_caches and systemcfg
  290. * structures
  291. * (at least until we get rid of them completely). This is mostly some
  292. * cache informations about the CPU that will be used by cache flush
  293. * routines and/or provided to userland
  294. */
  295. static void __init initialize_cache_info(void)
  296. {
  297. struct device_node *np;
  298. unsigned long num_cpus = 0;
  299. DBG(" -> initialize_cache_info()\n");
  300. for (np = NULL; (np = of_find_node_by_type(np, "cpu"));) {
  301. num_cpus += 1;
  302. /* We're assuming *all* of the CPUs have the same
  303. * d-cache and i-cache sizes... -Peter
  304. */
  305. if ( num_cpus == 1 ) {
  306. u32 *sizep, *lsizep;
  307. u32 size, lsize;
  308. const char *dc, *ic;
  309. /* Then read cache informations */
  310. if (_machine == PLATFORM_POWERMAC) {
  311. dc = "d-cache-block-size";
  312. ic = "i-cache-block-size";
  313. } else {
  314. dc = "d-cache-line-size";
  315. ic = "i-cache-line-size";
  316. }
  317. size = 0;
  318. lsize = cur_cpu_spec->dcache_bsize;
  319. sizep = (u32 *)get_property(np, "d-cache-size", NULL);
  320. if (sizep != NULL)
  321. size = *sizep;
  322. lsizep = (u32 *) get_property(np, dc, NULL);
  323. if (lsizep != NULL)
  324. lsize = *lsizep;
  325. if (sizep == 0 || lsizep == 0)
  326. DBG("Argh, can't find dcache properties ! "
  327. "sizep: %p, lsizep: %p\n", sizep, lsizep);
  328. ppc64_caches.dsize = size;
  329. ppc64_caches.dline_size = lsize;
  330. ppc64_caches.log_dline_size = __ilog2(lsize);
  331. ppc64_caches.dlines_per_page = PAGE_SIZE / lsize;
  332. size = 0;
  333. lsize = cur_cpu_spec->icache_bsize;
  334. sizep = (u32 *)get_property(np, "i-cache-size", NULL);
  335. if (sizep != NULL)
  336. size = *sizep;
  337. lsizep = (u32 *)get_property(np, ic, NULL);
  338. if (lsizep != NULL)
  339. lsize = *lsizep;
  340. if (sizep == 0 || lsizep == 0)
  341. DBG("Argh, can't find icache properties ! "
  342. "sizep: %p, lsizep: %p\n", sizep, lsizep);
  343. ppc64_caches.isize = size;
  344. ppc64_caches.iline_size = lsize;
  345. ppc64_caches.log_iline_size = __ilog2(lsize);
  346. ppc64_caches.ilines_per_page = PAGE_SIZE / lsize;
  347. }
  348. }
  349. DBG(" <- initialize_cache_info()\n");
  350. }
  351. /*
  352. * Do some initial setup of the system. The parameters are those which
  353. * were passed in from the bootloader.
  354. */
  355. void __init setup_system(void)
  356. {
  357. DBG(" -> setup_system()\n");
  358. /*
  359. * Unflatten the device-tree passed by prom_init or kexec
  360. */
  361. unflatten_device_tree();
  362. #ifdef CONFIG_KEXEC
  363. kexec_setup(); /* requires unflattened device tree. */
  364. #endif
  365. /*
  366. * Fill the ppc64_caches & systemcfg structures with informations
  367. * retreived from the device-tree. Need to be called before
  368. * finish_device_tree() since the later requires some of the
  369. * informations filled up here to properly parse the interrupt
  370. * tree.
  371. * It also sets up the cache line sizes which allows to call
  372. * routines like flush_icache_range (used by the hash init
  373. * later on).
  374. */
  375. initialize_cache_info();
  376. #ifdef CONFIG_PPC_RTAS
  377. /*
  378. * Initialize RTAS if available
  379. */
  380. rtas_initialize();
  381. #endif /* CONFIG_PPC_RTAS */
  382. /*
  383. * Check if we have an initrd provided via the device-tree
  384. */
  385. check_for_initrd();
  386. /*
  387. * Do some platform specific early initializations, that includes
  388. * setting up the hash table pointers. It also sets up some interrupt-mapping
  389. * related options that will be used by finish_device_tree()
  390. */
  391. ppc_md.init_early();
  392. /*
  393. * "Finish" the device-tree, that is do the actual parsing of
  394. * some of the properties like the interrupt map
  395. */
  396. finish_device_tree();
  397. #ifdef CONFIG_BOOTX_TEXT
  398. init_boot_display();
  399. #endif
  400. /*
  401. * Initialize xmon
  402. */
  403. #ifdef CONFIG_XMON_DEFAULT
  404. xmon_init(1);
  405. #endif
  406. /*
  407. * Register early console
  408. */
  409. register_early_udbg_console();
  410. /* Save unparsed command line copy for /proc/cmdline */
  411. strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
  412. parse_early_param();
  413. check_smt_enabled();
  414. smp_setup_cpu_maps();
  415. /* Release secondary cpus out of their spinloops at 0x60 now that
  416. * we can map physical -> logical CPU ids
  417. */
  418. smp_release_cpus();
  419. printk("Starting Linux PPC64 %s\n", system_utsname.version);
  420. printk("-----------------------------------------------------\n");
  421. printk("ppc64_pft_size = 0x%lx\n", ppc64_pft_size);
  422. printk("ppc64_interrupt_controller = 0x%ld\n",
  423. ppc64_interrupt_controller);
  424. printk("platform = 0x%x\n", _machine);
  425. printk("physicalMemorySize = 0x%lx\n", lmb_phys_mem_size());
  426. printk("ppc64_caches.dcache_line_size = 0x%x\n",
  427. ppc64_caches.dline_size);
  428. printk("ppc64_caches.icache_line_size = 0x%x\n",
  429. ppc64_caches.iline_size);
  430. printk("htab_address = 0x%p\n", htab_address);
  431. printk("htab_hash_mask = 0x%lx\n", htab_hash_mask);
  432. printk("-----------------------------------------------------\n");
  433. mm_init_ppc64();
  434. DBG(" <- setup_system()\n");
  435. }
  436. static int ppc64_panic_event(struct notifier_block *this,
  437. unsigned long event, void *ptr)
  438. {
  439. ppc_md.panic((char *)ptr); /* May not return */
  440. return NOTIFY_DONE;
  441. }
  442. #ifdef CONFIG_IRQSTACKS
  443. static void __init irqstack_early_init(void)
  444. {
  445. unsigned int i;
  446. /*
  447. * interrupt stacks must be under 256MB, we cannot afford to take
  448. * SLB misses on them.
  449. */
  450. for_each_cpu(i) {
  451. softirq_ctx[i] = (struct thread_info *)
  452. __va(lmb_alloc_base(THREAD_SIZE,
  453. THREAD_SIZE, 0x10000000));
  454. hardirq_ctx[i] = (struct thread_info *)
  455. __va(lmb_alloc_base(THREAD_SIZE,
  456. THREAD_SIZE, 0x10000000));
  457. }
  458. }
  459. #else
  460. #define irqstack_early_init()
  461. #endif
  462. /*
  463. * Stack space used when we detect a bad kernel stack pointer, and
  464. * early in SMP boots before relocation is enabled.
  465. */
  466. static void __init emergency_stack_init(void)
  467. {
  468. unsigned long limit;
  469. unsigned int i;
  470. /*
  471. * Emergency stacks must be under 256MB, we cannot afford to take
  472. * SLB misses on them. The ABI also requires them to be 128-byte
  473. * aligned.
  474. *
  475. * Since we use these as temporary stacks during secondary CPU
  476. * bringup, we need to get at them in real mode. This means they
  477. * must also be within the RMO region.
  478. */
  479. limit = min(0x10000000UL, lmb.rmo_size);
  480. for_each_cpu(i)
  481. paca[i].emergency_sp =
  482. __va(lmb_alloc_base(HW_PAGE_SIZE, 128, limit)) + HW_PAGE_SIZE;
  483. }
  484. /*
  485. * Called into from start_kernel, after lock_kernel has been called.
  486. * Initializes bootmem, which is unsed to manage page allocation until
  487. * mem_init is called.
  488. */
  489. void __init setup_arch(char **cmdline_p)
  490. {
  491. extern void do_init_bootmem(void);
  492. ppc64_boot_msg(0x12, "Setup Arch");
  493. *cmdline_p = cmd_line;
  494. /*
  495. * Set cache line size based on type of cpu as a default.
  496. * Systems with OF can look in the properties on the cpu node(s)
  497. * for a possibly more accurate value.
  498. */
  499. dcache_bsize = ppc64_caches.dline_size;
  500. icache_bsize = ppc64_caches.iline_size;
  501. /* reboot on panic */
  502. panic_timeout = 180;
  503. if (ppc_md.panic)
  504. notifier_chain_register(&panic_notifier_list, &ppc64_panic_block);
  505. init_mm.start_code = PAGE_OFFSET;
  506. init_mm.end_code = (unsigned long) _etext;
  507. init_mm.end_data = (unsigned long) _edata;
  508. init_mm.brk = klimit;
  509. irqstack_early_init();
  510. emergency_stack_init();
  511. stabs_alloc();
  512. /* set up the bootmem stuff with available memory */
  513. do_init_bootmem();
  514. sparse_init();
  515. #ifdef CONFIG_DUMMY_CONSOLE
  516. conswitchp = &dummy_con;
  517. #endif
  518. ppc_md.setup_arch();
  519. /* Use the default idle loop if the platform hasn't provided one. */
  520. if (NULL == ppc_md.idle_loop) {
  521. ppc_md.idle_loop = default_idle;
  522. printk(KERN_INFO "Using default idle loop\n");
  523. }
  524. paging_init();
  525. ppc64_boot_msg(0x15, "Setup Done");
  526. }
  527. /* ToDo: do something useful if ppc_md is not yet setup. */
  528. #define PPC64_LINUX_FUNCTION 0x0f000000
  529. #define PPC64_IPL_MESSAGE 0xc0000000
  530. #define PPC64_TERM_MESSAGE 0xb0000000
  531. static void ppc64_do_msg(unsigned int src, const char *msg)
  532. {
  533. if (ppc_md.progress) {
  534. char buf[128];
  535. sprintf(buf, "%08X\n", src);
  536. ppc_md.progress(buf, 0);
  537. snprintf(buf, 128, "%s", msg);
  538. ppc_md.progress(buf, 0);
  539. }
  540. }
  541. /* Print a boot progress message. */
  542. void ppc64_boot_msg(unsigned int src, const char *msg)
  543. {
  544. ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_IPL_MESSAGE|src, msg);
  545. printk("[boot]%04x %s\n", src, msg);
  546. }
  547. /* Print a termination message (print only -- does not stop the kernel) */
  548. void ppc64_terminate_msg(unsigned int src, const char *msg)
  549. {
  550. ppc64_do_msg(PPC64_LINUX_FUNCTION|PPC64_TERM_MESSAGE|src, msg);
  551. printk("[terminate]%04x %s\n", src, msg);
  552. }
  553. #ifndef CONFIG_PPC_ISERIES
  554. /*
  555. * This function can be used by platforms to "find" legacy serial ports.
  556. * It works for "serial" nodes under an "isa" node, and will try to
  557. * respect the "ibm,aix-loc" property if any. It works with up to 8
  558. * ports.
  559. */
  560. #define MAX_LEGACY_SERIAL_PORTS 8
  561. static struct plat_serial8250_port serial_ports[MAX_LEGACY_SERIAL_PORTS+1];
  562. static unsigned int old_serial_count;
  563. void __init generic_find_legacy_serial_ports(u64 *physport,
  564. unsigned int *default_speed)
  565. {
  566. struct device_node *np;
  567. u32 *sizeprop;
  568. struct isa_reg_property {
  569. u32 space;
  570. u32 address;
  571. u32 size;
  572. };
  573. struct pci_reg_property {
  574. struct pci_address addr;
  575. u32 size_hi;
  576. u32 size_lo;
  577. };
  578. DBG(" -> generic_find_legacy_serial_port()\n");
  579. *physport = 0;
  580. if (default_speed)
  581. *default_speed = 0;
  582. np = of_find_node_by_path("/");
  583. if (!np)
  584. return;
  585. /* First fill our array */
  586. for (np = NULL; (np = of_find_node_by_type(np, "serial"));) {
  587. struct device_node *isa, *pci;
  588. struct isa_reg_property *reg;
  589. unsigned long phys_size, addr_size, io_base;
  590. u32 *rangesp;
  591. u32 *interrupts, *clk, *spd;
  592. char *typep;
  593. int index, rlen, rentsize;
  594. /* Ok, first check if it's under an "isa" parent */
  595. isa = of_get_parent(np);
  596. if (!isa || strcmp(isa->name, "isa")) {
  597. DBG("%s: no isa parent found\n", np->full_name);
  598. continue;
  599. }
  600. /* Now look for an "ibm,aix-loc" property that gives us ordering
  601. * if any...
  602. */
  603. typep = (char *)get_property(np, "ibm,aix-loc", NULL);
  604. /* Get the ISA port number */
  605. reg = (struct isa_reg_property *)get_property(np, "reg", NULL);
  606. if (reg == NULL)
  607. goto next_port;
  608. /* We assume the interrupt number isn't translated ... */
  609. interrupts = (u32 *)get_property(np, "interrupts", NULL);
  610. /* get clock freq. if present */
  611. clk = (u32 *)get_property(np, "clock-frequency", NULL);
  612. /* get default speed if present */
  613. spd = (u32 *)get_property(np, "current-speed", NULL);
  614. /* Default to locate at end of array */
  615. index = old_serial_count; /* end of the array by default */
  616. /* If we have a location index, then use it */
  617. if (typep && *typep == 'S') {
  618. index = simple_strtol(typep+1, NULL, 0) - 1;
  619. /* if index is out of range, use end of array instead */
  620. if (index >= MAX_LEGACY_SERIAL_PORTS)
  621. index = old_serial_count;
  622. /* if our index is still out of range, that mean that
  623. * array is full, we could scan for a free slot but that
  624. * make little sense to bother, just skip the port
  625. */
  626. if (index >= MAX_LEGACY_SERIAL_PORTS)
  627. goto next_port;
  628. if (index >= old_serial_count)
  629. old_serial_count = index + 1;
  630. /* Check if there is a port who already claimed our slot */
  631. if (serial_ports[index].iobase != 0) {
  632. /* if we still have some room, move it, else override */
  633. if (old_serial_count < MAX_LEGACY_SERIAL_PORTS) {
  634. DBG("Moved legacy port %d -> %d\n", index,
  635. old_serial_count);
  636. serial_ports[old_serial_count++] =
  637. serial_ports[index];
  638. } else {
  639. DBG("Replacing legacy port %d\n", index);
  640. }
  641. }
  642. }
  643. if (index >= MAX_LEGACY_SERIAL_PORTS)
  644. goto next_port;
  645. if (index >= old_serial_count)
  646. old_serial_count = index + 1;
  647. /* Now fill the entry */
  648. memset(&serial_ports[index], 0, sizeof(struct plat_serial8250_port));
  649. serial_ports[index].uartclk = clk ? *clk : BASE_BAUD * 16;
  650. serial_ports[index].iobase = reg->address;
  651. serial_ports[index].irq = interrupts ? interrupts[0] : 0;
  652. serial_ports[index].flags = ASYNC_BOOT_AUTOCONF;
  653. DBG("Added legacy port, index: %d, port: %x, irq: %d, clk: %d\n",
  654. index,
  655. serial_ports[index].iobase,
  656. serial_ports[index].irq,
  657. serial_ports[index].uartclk);
  658. /* Get phys address of IO reg for port 1 */
  659. if (index != 0)
  660. goto next_port;
  661. pci = of_get_parent(isa);
  662. if (!pci) {
  663. DBG("%s: no pci parent found\n", np->full_name);
  664. goto next_port;
  665. }
  666. rangesp = (u32 *)get_property(pci, "ranges", &rlen);
  667. if (rangesp == NULL) {
  668. of_node_put(pci);
  669. goto next_port;
  670. }
  671. rlen /= 4;
  672. /* we need the #size-cells of the PCI bridge node itself */
  673. phys_size = 1;
  674. sizeprop = (u32 *)get_property(pci, "#size-cells", NULL);
  675. if (sizeprop != NULL)
  676. phys_size = *sizeprop;
  677. /* we need the parent #addr-cells */
  678. addr_size = prom_n_addr_cells(pci);
  679. rentsize = 3 + addr_size + phys_size;
  680. io_base = 0;
  681. for (;rlen >= rentsize; rlen -= rentsize,rangesp += rentsize) {
  682. if (((rangesp[0] >> 24) & 0x3) != 1)
  683. continue; /* not IO space */
  684. io_base = rangesp[3];
  685. if (addr_size == 2)
  686. io_base = (io_base << 32) | rangesp[4];
  687. }
  688. if (io_base != 0) {
  689. *physport = io_base + reg->address;
  690. if (default_speed && spd)
  691. *default_speed = *spd;
  692. }
  693. of_node_put(pci);
  694. next_port:
  695. of_node_put(isa);
  696. }
  697. DBG(" <- generic_find_legacy_serial_port()\n");
  698. }
  699. static struct platform_device serial_device = {
  700. .name = "serial8250",
  701. .id = PLAT8250_DEV_PLATFORM,
  702. .dev = {
  703. .platform_data = serial_ports,
  704. },
  705. };
  706. static int __init serial_dev_init(void)
  707. {
  708. return platform_device_register(&serial_device);
  709. }
  710. arch_initcall(serial_dev_init);
  711. #endif /* CONFIG_PPC_ISERIES */
  712. int check_legacy_ioport(unsigned long base_port)
  713. {
  714. if (ppc_md.check_legacy_ioport == NULL)
  715. return 0;
  716. return ppc_md.check_legacy_ioport(base_port);
  717. }
  718. EXPORT_SYMBOL(check_legacy_ioport);
  719. void cpu_die(void)
  720. {
  721. if (ppc_md.cpu_die)
  722. ppc_md.cpu_die();
  723. }