setup.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. /*
  2. * 64-bit pSeries and RS/6000 setup code.
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. * Adapted from 'alpha' version by Gary Thomas
  6. * Modified by Cort Dougan (cort@cs.nmt.edu)
  7. * Modified by PPC64 Team, IBM Corp
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. /*
  15. * bootup setup stuff..
  16. */
  17. #include <linux/cpu.h>
  18. #include <linux/errno.h>
  19. #include <linux/sched.h>
  20. #include <linux/kernel.h>
  21. #include <linux/mm.h>
  22. #include <linux/stddef.h>
  23. #include <linux/unistd.h>
  24. #include <linux/user.h>
  25. #include <linux/tty.h>
  26. #include <linux/major.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/reboot.h>
  29. #include <linux/init.h>
  30. #include <linux/ioport.h>
  31. #include <linux/console.h>
  32. #include <linux/pci.h>
  33. #include <linux/utsname.h>
  34. #include <linux/adb.h>
  35. #include <linux/export.h>
  36. #include <linux/delay.h>
  37. #include <linux/irq.h>
  38. #include <linux/seq_file.h>
  39. #include <linux/root_dev.h>
  40. #include <linux/of.h>
  41. #include <linux/of_pci.h>
  42. #include <asm/mmu.h>
  43. #include <asm/processor.h>
  44. #include <asm/io.h>
  45. #include <asm/pgtable.h>
  46. #include <asm/prom.h>
  47. #include <asm/rtas.h>
  48. #include <asm/pci-bridge.h>
  49. #include <asm/iommu.h>
  50. #include <asm/dma.h>
  51. #include <asm/machdep.h>
  52. #include <asm/irq.h>
  53. #include <asm/time.h>
  54. #include <asm/nvram.h>
  55. #include <asm/pmc.h>
  56. #include <asm/xics.h>
  57. #include <asm/xive.h>
  58. #include <asm/ppc-pci.h>
  59. #include <asm/i8259.h>
  60. #include <asm/udbg.h>
  61. #include <asm/smp.h>
  62. #include <asm/firmware.h>
  63. #include <asm/eeh.h>
  64. #include <asm/reg.h>
  65. #include <asm/plpar_wrappers.h>
  66. #include <asm/kexec.h>
  67. #include <asm/isa-bridge.h>
  68. #include <asm/security_features.h>
  69. #include "pseries.h"
  70. #include "../../../../drivers/pci/pci.h"
  71. int CMO_PrPSP = -1;
  72. int CMO_SecPSP = -1;
  73. unsigned long CMO_PageSize = (ASM_CONST(1) << IOMMU_PAGE_SHIFT_4K);
  74. EXPORT_SYMBOL(CMO_PageSize);
  75. int fwnmi_active; /* TRUE if an FWNMI handler is present */
  76. static void pSeries_show_cpuinfo(struct seq_file *m)
  77. {
  78. struct device_node *root;
  79. const char *model = "";
  80. root = of_find_node_by_path("/");
  81. if (root)
  82. model = of_get_property(root, "model", NULL);
  83. seq_printf(m, "machine\t\t: CHRP %s\n", model);
  84. of_node_put(root);
  85. if (radix_enabled())
  86. seq_printf(m, "MMU\t\t: Radix\n");
  87. else
  88. seq_printf(m, "MMU\t\t: Hash\n");
  89. }
  90. /* Initialize firmware assisted non-maskable interrupts if
  91. * the firmware supports this feature.
  92. */
  93. static void __init fwnmi_init(void)
  94. {
  95. unsigned long system_reset_addr, machine_check_addr;
  96. int ibm_nmi_register = rtas_token("ibm,nmi-register");
  97. if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
  98. return;
  99. /* If the kernel's not linked at zero we point the firmware at low
  100. * addresses anyway, and use a trampoline to get to the real code. */
  101. system_reset_addr = __pa(system_reset_fwnmi) - PHYSICAL_START;
  102. machine_check_addr = __pa(machine_check_fwnmi) - PHYSICAL_START;
  103. if (0 == rtas_call(ibm_nmi_register, 2, 1, NULL, system_reset_addr,
  104. machine_check_addr))
  105. fwnmi_active = 1;
  106. }
  107. static void pseries_8259_cascade(struct irq_desc *desc)
  108. {
  109. struct irq_chip *chip = irq_desc_get_chip(desc);
  110. unsigned int cascade_irq = i8259_irq();
  111. if (cascade_irq)
  112. generic_handle_irq(cascade_irq);
  113. chip->irq_eoi(&desc->irq_data);
  114. }
  115. static void __init pseries_setup_i8259_cascade(void)
  116. {
  117. struct device_node *np, *old, *found = NULL;
  118. unsigned int cascade;
  119. const u32 *addrp;
  120. unsigned long intack = 0;
  121. int naddr;
  122. for_each_node_by_type(np, "interrupt-controller") {
  123. if (of_device_is_compatible(np, "chrp,iic")) {
  124. found = np;
  125. break;
  126. }
  127. }
  128. if (found == NULL) {
  129. printk(KERN_DEBUG "pic: no ISA interrupt controller\n");
  130. return;
  131. }
  132. cascade = irq_of_parse_and_map(found, 0);
  133. if (!cascade) {
  134. printk(KERN_ERR "pic: failed to map cascade interrupt");
  135. return;
  136. }
  137. pr_debug("pic: cascade mapped to irq %d\n", cascade);
  138. for (old = of_node_get(found); old != NULL ; old = np) {
  139. np = of_get_parent(old);
  140. of_node_put(old);
  141. if (np == NULL)
  142. break;
  143. if (strcmp(np->name, "pci") != 0)
  144. continue;
  145. addrp = of_get_property(np, "8259-interrupt-acknowledge", NULL);
  146. if (addrp == NULL)
  147. continue;
  148. naddr = of_n_addr_cells(np);
  149. intack = addrp[naddr-1];
  150. if (naddr > 1)
  151. intack |= ((unsigned long)addrp[naddr-2]) << 32;
  152. }
  153. if (intack)
  154. printk(KERN_DEBUG "pic: PCI 8259 intack at 0x%016lx\n", intack);
  155. i8259_init(found, intack);
  156. of_node_put(found);
  157. irq_set_chained_handler(cascade, pseries_8259_cascade);
  158. }
  159. static void __init pseries_init_irq(void)
  160. {
  161. /* Try using a XIVE if available, otherwise use a XICS */
  162. if (!xive_spapr_init()) {
  163. xics_init();
  164. pseries_setup_i8259_cascade();
  165. }
  166. }
  167. static void pseries_lpar_enable_pmcs(void)
  168. {
  169. unsigned long set, reset;
  170. set = 1UL << 63;
  171. reset = 0;
  172. plpar_hcall_norets(H_PERFMON, set, reset);
  173. }
  174. static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data)
  175. {
  176. struct of_reconfig_data *rd = data;
  177. struct device_node *parent, *np = rd->dn;
  178. struct pci_dn *pdn;
  179. int err = NOTIFY_OK;
  180. switch (action) {
  181. case OF_RECONFIG_ATTACH_NODE:
  182. parent = of_get_parent(np);
  183. pdn = parent ? PCI_DN(parent) : NULL;
  184. if (pdn)
  185. pci_add_device_node_info(pdn->phb, np);
  186. of_node_put(parent);
  187. break;
  188. case OF_RECONFIG_DETACH_NODE:
  189. pdn = PCI_DN(np);
  190. if (pdn)
  191. list_del(&pdn->list);
  192. break;
  193. default:
  194. err = NOTIFY_DONE;
  195. break;
  196. }
  197. return err;
  198. }
  199. static struct notifier_block pci_dn_reconfig_nb = {
  200. .notifier_call = pci_dn_reconfig_notifier,
  201. };
  202. struct kmem_cache *dtl_cache;
  203. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  204. /*
  205. * Allocate space for the dispatch trace log for all possible cpus
  206. * and register the buffers with the hypervisor. This is used for
  207. * computing time stolen by the hypervisor.
  208. */
  209. static int alloc_dispatch_logs(void)
  210. {
  211. int cpu, ret;
  212. struct paca_struct *pp;
  213. struct dtl_entry *dtl;
  214. if (!firmware_has_feature(FW_FEATURE_SPLPAR))
  215. return 0;
  216. if (!dtl_cache)
  217. return 0;
  218. for_each_possible_cpu(cpu) {
  219. pp = paca_ptrs[cpu];
  220. dtl = kmem_cache_alloc(dtl_cache, GFP_KERNEL);
  221. if (!dtl) {
  222. pr_warn("Failed to allocate dispatch trace log for cpu %d\n",
  223. cpu);
  224. pr_warn("Stolen time statistics will be unreliable\n");
  225. break;
  226. }
  227. pp->dtl_ridx = 0;
  228. pp->dispatch_log = dtl;
  229. pp->dispatch_log_end = dtl + N_DISPATCH_LOG;
  230. pp->dtl_curr = dtl;
  231. }
  232. /* Register the DTL for the current (boot) cpu */
  233. dtl = get_paca()->dispatch_log;
  234. get_paca()->dtl_ridx = 0;
  235. get_paca()->dtl_curr = dtl;
  236. get_paca()->lppaca_ptr->dtl_idx = 0;
  237. /* hypervisor reads buffer length from this field */
  238. dtl->enqueue_to_dispatch_time = cpu_to_be32(DISPATCH_LOG_BYTES);
  239. ret = register_dtl(hard_smp_processor_id(), __pa(dtl));
  240. if (ret)
  241. pr_err("WARNING: DTL registration of cpu %d (hw %d) failed "
  242. "with %d\n", smp_processor_id(),
  243. hard_smp_processor_id(), ret);
  244. get_paca()->lppaca_ptr->dtl_enable_mask = 2;
  245. return 0;
  246. }
  247. #else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
  248. static inline int alloc_dispatch_logs(void)
  249. {
  250. return 0;
  251. }
  252. #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
  253. static int alloc_dispatch_log_kmem_cache(void)
  254. {
  255. dtl_cache = kmem_cache_create("dtl", DISPATCH_LOG_BYTES,
  256. DISPATCH_LOG_BYTES, 0, NULL);
  257. if (!dtl_cache) {
  258. pr_warn("Failed to create dispatch trace log buffer cache\n");
  259. pr_warn("Stolen time statistics will be unreliable\n");
  260. return 0;
  261. }
  262. return alloc_dispatch_logs();
  263. }
  264. machine_early_initcall(pseries, alloc_dispatch_log_kmem_cache);
  265. static void pseries_lpar_idle(void)
  266. {
  267. /*
  268. * Default handler to go into low thread priority and possibly
  269. * low power mode by ceding processor to hypervisor
  270. */
  271. /* Indicate to hypervisor that we are idle. */
  272. get_lppaca()->idle = 1;
  273. /*
  274. * Yield the processor to the hypervisor. We return if
  275. * an external interrupt occurs (which are driven prior
  276. * to returning here) or if a prod occurs from another
  277. * processor. When returning here, external interrupts
  278. * are enabled.
  279. */
  280. cede_processor();
  281. get_lppaca()->idle = 0;
  282. }
  283. /*
  284. * Enable relocation on during exceptions. This has partition wide scope and
  285. * may take a while to complete, if it takes longer than one second we will
  286. * just give up rather than wasting any more time on this - if that turns out
  287. * to ever be a problem in practice we can move this into a kernel thread to
  288. * finish off the process later in boot.
  289. */
  290. void pseries_enable_reloc_on_exc(void)
  291. {
  292. long rc;
  293. unsigned int delay, total_delay = 0;
  294. while (1) {
  295. rc = enable_reloc_on_exceptions();
  296. if (!H_IS_LONG_BUSY(rc)) {
  297. if (rc == H_P2) {
  298. pr_info("Relocation on exceptions not"
  299. " supported\n");
  300. } else if (rc != H_SUCCESS) {
  301. pr_warn("Unable to enable relocation"
  302. " on exceptions: %ld\n", rc);
  303. }
  304. break;
  305. }
  306. delay = get_longbusy_msecs(rc);
  307. total_delay += delay;
  308. if (total_delay > 1000) {
  309. pr_warn("Warning: Giving up waiting to enable "
  310. "relocation on exceptions (%u msec)!\n",
  311. total_delay);
  312. return;
  313. }
  314. mdelay(delay);
  315. }
  316. }
  317. EXPORT_SYMBOL(pseries_enable_reloc_on_exc);
  318. void pseries_disable_reloc_on_exc(void)
  319. {
  320. long rc;
  321. while (1) {
  322. rc = disable_reloc_on_exceptions();
  323. if (!H_IS_LONG_BUSY(rc))
  324. break;
  325. mdelay(get_longbusy_msecs(rc));
  326. }
  327. if (rc != H_SUCCESS)
  328. pr_warn("Warning: Failed to disable relocation on exceptions: %ld\n",
  329. rc);
  330. }
  331. EXPORT_SYMBOL(pseries_disable_reloc_on_exc);
  332. #ifdef CONFIG_KEXEC_CORE
  333. static void pSeries_machine_kexec(struct kimage *image)
  334. {
  335. if (firmware_has_feature(FW_FEATURE_SET_MODE))
  336. pseries_disable_reloc_on_exc();
  337. default_machine_kexec(image);
  338. }
  339. #endif
  340. #ifdef __LITTLE_ENDIAN__
  341. void pseries_big_endian_exceptions(void)
  342. {
  343. long rc;
  344. while (1) {
  345. rc = enable_big_endian_exceptions();
  346. if (!H_IS_LONG_BUSY(rc))
  347. break;
  348. mdelay(get_longbusy_msecs(rc));
  349. }
  350. /*
  351. * At this point it is unlikely panic() will get anything
  352. * out to the user, since this is called very late in kexec
  353. * but at least this will stop us from continuing on further
  354. * and creating an even more difficult to debug situation.
  355. *
  356. * There is a known problem when kdump'ing, if cpus are offline
  357. * the above call will fail. Rather than panicking again, keep
  358. * going and hope the kdump kernel is also little endian, which
  359. * it usually is.
  360. */
  361. if (rc && !kdump_in_progress())
  362. panic("Could not enable big endian exceptions");
  363. }
  364. void pseries_little_endian_exceptions(void)
  365. {
  366. long rc;
  367. while (1) {
  368. rc = enable_little_endian_exceptions();
  369. if (!H_IS_LONG_BUSY(rc))
  370. break;
  371. mdelay(get_longbusy_msecs(rc));
  372. }
  373. if (rc) {
  374. ppc_md.progress("H_SET_MODE LE exception fail", 0);
  375. panic("Could not enable little endian exceptions");
  376. }
  377. }
  378. #endif
  379. static void __init find_and_init_phbs(void)
  380. {
  381. struct device_node *node;
  382. struct pci_controller *phb;
  383. struct device_node *root = of_find_node_by_path("/");
  384. for_each_child_of_node(root, node) {
  385. if (node->type == NULL || (strcmp(node->type, "pci") != 0 &&
  386. strcmp(node->type, "pciex") != 0))
  387. continue;
  388. phb = pcibios_alloc_controller(node);
  389. if (!phb)
  390. continue;
  391. rtas_setup_phb(phb);
  392. pci_process_bridge_OF_ranges(phb, node, 0);
  393. isa_bridge_find_early(phb);
  394. phb->controller_ops = pseries_pci_controller_ops;
  395. }
  396. of_node_put(root);
  397. /*
  398. * PCI_PROBE_ONLY and PCI_REASSIGN_ALL_BUS can be set via properties
  399. * in chosen.
  400. */
  401. of_pci_check_probe_only();
  402. }
  403. static void init_cpu_char_feature_flags(struct h_cpu_char_result *result)
  404. {
  405. /*
  406. * The features below are disabled by default, so we instead look to see
  407. * if firmware has *enabled* them, and set them if so.
  408. */
  409. if (result->character & H_CPU_CHAR_SPEC_BAR_ORI31)
  410. security_ftr_set(SEC_FTR_SPEC_BAR_ORI31);
  411. if (result->character & H_CPU_CHAR_BCCTRL_SERIALISED)
  412. security_ftr_set(SEC_FTR_BCCTRL_SERIALISED);
  413. if (result->character & H_CPU_CHAR_L1D_FLUSH_ORI30)
  414. security_ftr_set(SEC_FTR_L1D_FLUSH_ORI30);
  415. if (result->character & H_CPU_CHAR_L1D_FLUSH_TRIG2)
  416. security_ftr_set(SEC_FTR_L1D_FLUSH_TRIG2);
  417. if (result->character & H_CPU_CHAR_L1D_THREAD_PRIV)
  418. security_ftr_set(SEC_FTR_L1D_THREAD_PRIV);
  419. if (result->character & H_CPU_CHAR_COUNT_CACHE_DISABLED)
  420. security_ftr_set(SEC_FTR_COUNT_CACHE_DISABLED);
  421. /*
  422. * The features below are enabled by default, so we instead look to see
  423. * if firmware has *disabled* them, and clear them if so.
  424. */
  425. if (!(result->behaviour & H_CPU_BEHAV_FAVOUR_SECURITY))
  426. security_ftr_clear(SEC_FTR_FAVOUR_SECURITY);
  427. if (!(result->behaviour & H_CPU_BEHAV_L1D_FLUSH_PR))
  428. security_ftr_clear(SEC_FTR_L1D_FLUSH_PR);
  429. if (!(result->behaviour & H_CPU_BEHAV_BNDS_CHK_SPEC_BAR))
  430. security_ftr_clear(SEC_FTR_BNDS_CHK_SPEC_BAR);
  431. }
  432. void pseries_setup_rfi_flush(void)
  433. {
  434. struct h_cpu_char_result result;
  435. enum l1d_flush_type types;
  436. bool enable;
  437. long rc;
  438. /*
  439. * Set features to the defaults assumed by init_cpu_char_feature_flags()
  440. * so it can set/clear again any features that might have changed after
  441. * migration, and in case the hypercall fails and it is not even called.
  442. */
  443. powerpc_security_features = SEC_FTR_DEFAULT;
  444. rc = plpar_get_cpu_characteristics(&result);
  445. if (rc == H_SUCCESS)
  446. init_cpu_char_feature_flags(&result);
  447. /*
  448. * We're the guest so this doesn't apply to us, clear it to simplify
  449. * handling of it elsewhere.
  450. */
  451. security_ftr_clear(SEC_FTR_L1D_FLUSH_HV);
  452. types = L1D_FLUSH_FALLBACK;
  453. if (security_ftr_enabled(SEC_FTR_L1D_FLUSH_TRIG2))
  454. types |= L1D_FLUSH_MTTRIG;
  455. if (security_ftr_enabled(SEC_FTR_L1D_FLUSH_ORI30))
  456. types |= L1D_FLUSH_ORI;
  457. enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) && \
  458. security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR);
  459. setup_rfi_flush(types, enable);
  460. setup_barrier_nospec();
  461. }
  462. #ifdef CONFIG_PCI_IOV
  463. enum rtas_iov_fw_value_map {
  464. NUM_RES_PROPERTY = 0, /* Number of Resources */
  465. LOW_INT = 1, /* Lowest 32 bits of Address */
  466. START_OF_ENTRIES = 2, /* Always start of entry */
  467. APERTURE_PROPERTY = 2, /* Start of entry+ to Aperture Size */
  468. WDW_SIZE_PROPERTY = 4, /* Start of entry+ to Window Size */
  469. NEXT_ENTRY = 7 /* Go to next entry on array */
  470. };
  471. enum get_iov_fw_value_index {
  472. BAR_ADDRS = 1, /* Get Bar Address */
  473. APERTURE_SIZE = 2, /* Get Aperture Size */
  474. WDW_SIZE = 3 /* Get Window Size */
  475. };
  476. resource_size_t pseries_get_iov_fw_value(struct pci_dev *dev, int resno,
  477. enum get_iov_fw_value_index value)
  478. {
  479. const int *indexes;
  480. struct device_node *dn = pci_device_to_OF_node(dev);
  481. int i, num_res, ret = 0;
  482. indexes = of_get_property(dn, "ibm,open-sriov-vf-bar-info", NULL);
  483. if (!indexes)
  484. return 0;
  485. /*
  486. * First element in the array is the number of Bars
  487. * returned. Search through the list to find the matching
  488. * bar
  489. */
  490. num_res = of_read_number(&indexes[NUM_RES_PROPERTY], 1);
  491. if (resno >= num_res)
  492. return 0; /* or an errror */
  493. i = START_OF_ENTRIES + NEXT_ENTRY * resno;
  494. switch (value) {
  495. case BAR_ADDRS:
  496. ret = of_read_number(&indexes[i], 2);
  497. break;
  498. case APERTURE_SIZE:
  499. ret = of_read_number(&indexes[i + APERTURE_PROPERTY], 2);
  500. break;
  501. case WDW_SIZE:
  502. ret = of_read_number(&indexes[i + WDW_SIZE_PROPERTY], 2);
  503. break;
  504. }
  505. return ret;
  506. }
  507. void of_pci_set_vf_bar_size(struct pci_dev *dev, const int *indexes)
  508. {
  509. struct resource *res;
  510. resource_size_t base, size;
  511. int i, r, num_res;
  512. num_res = of_read_number(&indexes[NUM_RES_PROPERTY], 1);
  513. num_res = min_t(int, num_res, PCI_SRIOV_NUM_BARS);
  514. for (i = START_OF_ENTRIES, r = 0; r < num_res && r < PCI_SRIOV_NUM_BARS;
  515. i += NEXT_ENTRY, r++) {
  516. res = &dev->resource[r + PCI_IOV_RESOURCES];
  517. base = of_read_number(&indexes[i], 2);
  518. size = of_read_number(&indexes[i + APERTURE_PROPERTY], 2);
  519. res->flags = pci_parse_of_flags(of_read_number
  520. (&indexes[i + LOW_INT], 1), 0);
  521. res->flags |= (IORESOURCE_MEM_64 | IORESOURCE_PCI_FIXED);
  522. res->name = pci_name(dev);
  523. res->start = base;
  524. res->end = base + size - 1;
  525. }
  526. }
  527. void of_pci_parse_iov_addrs(struct pci_dev *dev, const int *indexes)
  528. {
  529. struct resource *res, *root, *conflict;
  530. resource_size_t base, size;
  531. int i, r, num_res;
  532. /*
  533. * First element in the array is the number of Bars
  534. * returned. Search through the list to find the matching
  535. * bars assign them from firmware into resources structure.
  536. */
  537. num_res = of_read_number(&indexes[NUM_RES_PROPERTY], 1);
  538. for (i = START_OF_ENTRIES, r = 0; r < num_res && r < PCI_SRIOV_NUM_BARS;
  539. i += NEXT_ENTRY, r++) {
  540. res = &dev->resource[r + PCI_IOV_RESOURCES];
  541. base = of_read_number(&indexes[i], 2);
  542. size = of_read_number(&indexes[i + WDW_SIZE_PROPERTY], 2);
  543. res->name = pci_name(dev);
  544. res->start = base;
  545. res->end = base + size - 1;
  546. root = &iomem_resource;
  547. dev_dbg(&dev->dev,
  548. "pSeries IOV BAR %d: trying firmware assignment %pR\n",
  549. r + PCI_IOV_RESOURCES, res);
  550. conflict = request_resource_conflict(root, res);
  551. if (conflict) {
  552. dev_info(&dev->dev,
  553. "BAR %d: %pR conflicts with %s %pR\n",
  554. r + PCI_IOV_RESOURCES, res,
  555. conflict->name, conflict);
  556. res->flags |= IORESOURCE_UNSET;
  557. }
  558. }
  559. }
  560. static void pseries_pci_fixup_resources(struct pci_dev *pdev)
  561. {
  562. const int *indexes;
  563. struct device_node *dn = pci_device_to_OF_node(pdev);
  564. /*Firmware must support open sriov otherwise dont configure*/
  565. indexes = of_get_property(dn, "ibm,open-sriov-vf-bar-info", NULL);
  566. if (!indexes)
  567. return;
  568. /* Assign the addresses from device tree*/
  569. of_pci_set_vf_bar_size(pdev, indexes);
  570. }
  571. static void pseries_pci_fixup_iov_resources(struct pci_dev *pdev)
  572. {
  573. const int *indexes;
  574. struct device_node *dn = pci_device_to_OF_node(pdev);
  575. if (!pdev->is_physfn || pci_dev_is_added(pdev))
  576. return;
  577. /*Firmware must support open sriov otherwise dont configure*/
  578. indexes = of_get_property(dn, "ibm,open-sriov-vf-bar-info", NULL);
  579. if (!indexes)
  580. return;
  581. /* Assign the addresses from device tree*/
  582. of_pci_parse_iov_addrs(pdev, indexes);
  583. }
  584. static resource_size_t pseries_pci_iov_resource_alignment(struct pci_dev *pdev,
  585. int resno)
  586. {
  587. const __be32 *reg;
  588. struct device_node *dn = pci_device_to_OF_node(pdev);
  589. /*Firmware must support open sriov otherwise report regular alignment*/
  590. reg = of_get_property(dn, "ibm,is-open-sriov-pf", NULL);
  591. if (!reg)
  592. return pci_iov_resource_size(pdev, resno);
  593. if (!pdev->is_physfn)
  594. return 0;
  595. return pseries_get_iov_fw_value(pdev,
  596. resno - PCI_IOV_RESOURCES,
  597. APERTURE_SIZE);
  598. }
  599. #endif
  600. static void __init pSeries_setup_arch(void)
  601. {
  602. set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT);
  603. /* Discover PIC type and setup ppc_md accordingly */
  604. smp_init_pseries();
  605. /* openpic global configuration register (64-bit format). */
  606. /* openpic Interrupt Source Unit pointer (64-bit format). */
  607. /* python0 facility area (mmio) (64-bit format) REAL address. */
  608. /* init to some ~sane value until calibrate_delay() runs */
  609. loops_per_jiffy = 50000000;
  610. fwnmi_init();
  611. pseries_setup_rfi_flush();
  612. setup_stf_barrier();
  613. /* By default, only probe PCI (can be overridden by rtas_pci) */
  614. pci_add_flags(PCI_PROBE_ONLY);
  615. /* Find and initialize PCI host bridges */
  616. init_pci_config_tokens();
  617. find_and_init_phbs();
  618. of_reconfig_notifier_register(&pci_dn_reconfig_nb);
  619. pSeries_nvram_init();
  620. if (firmware_has_feature(FW_FEATURE_LPAR)) {
  621. vpa_init(boot_cpuid);
  622. ppc_md.power_save = pseries_lpar_idle;
  623. ppc_md.enable_pmcs = pseries_lpar_enable_pmcs;
  624. #ifdef CONFIG_PCI_IOV
  625. ppc_md.pcibios_fixup_resources =
  626. pseries_pci_fixup_resources;
  627. ppc_md.pcibios_fixup_sriov =
  628. pseries_pci_fixup_iov_resources;
  629. ppc_md.pcibios_iov_resource_alignment =
  630. pseries_pci_iov_resource_alignment;
  631. #endif
  632. } else {
  633. /* No special idle routine */
  634. ppc_md.enable_pmcs = power4_enable_pmcs;
  635. }
  636. ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
  637. }
  638. static void pseries_panic(char *str)
  639. {
  640. panic_flush_kmsg_end();
  641. rtas_os_term(str);
  642. }
  643. static int __init pSeries_init_panel(void)
  644. {
  645. /* Manually leave the kernel version on the panel. */
  646. #ifdef __BIG_ENDIAN__
  647. ppc_md.progress("Linux ppc64\n", 0);
  648. #else
  649. ppc_md.progress("Linux ppc64le\n", 0);
  650. #endif
  651. ppc_md.progress(init_utsname()->version, 0);
  652. return 0;
  653. }
  654. machine_arch_initcall(pseries, pSeries_init_panel);
  655. static int pseries_set_dabr(unsigned long dabr, unsigned long dabrx)
  656. {
  657. return plpar_hcall_norets(H_SET_DABR, dabr);
  658. }
  659. static int pseries_set_xdabr(unsigned long dabr, unsigned long dabrx)
  660. {
  661. /* Have to set at least one bit in the DABRX according to PAPR */
  662. if (dabrx == 0 && dabr == 0)
  663. dabrx = DABRX_USER;
  664. /* PAPR says we can only set kernel and user bits */
  665. dabrx &= DABRX_KERNEL | DABRX_USER;
  666. return plpar_hcall_norets(H_SET_XDABR, dabr, dabrx);
  667. }
  668. static int pseries_set_dawr(unsigned long dawr, unsigned long dawrx)
  669. {
  670. /* PAPR says we can't set HYP */
  671. dawrx &= ~DAWRX_HYP;
  672. return plpar_set_watchpoint0(dawr, dawrx);
  673. }
  674. #define CMO_CHARACTERISTICS_TOKEN 44
  675. #define CMO_MAXLENGTH 1026
  676. void pSeries_coalesce_init(void)
  677. {
  678. struct hvcall_mpp_x_data mpp_x_data;
  679. if (firmware_has_feature(FW_FEATURE_CMO) && !h_get_mpp_x(&mpp_x_data))
  680. powerpc_firmware_features |= FW_FEATURE_XCMO;
  681. else
  682. powerpc_firmware_features &= ~FW_FEATURE_XCMO;
  683. }
  684. /**
  685. * fw_cmo_feature_init - FW_FEATURE_CMO is not stored in ibm,hypertas-functions,
  686. * handle that here. (Stolen from parse_system_parameter_string)
  687. */
  688. static void pSeries_cmo_feature_init(void)
  689. {
  690. char *ptr, *key, *value, *end;
  691. int call_status;
  692. int page_order = IOMMU_PAGE_SHIFT_4K;
  693. pr_debug(" -> fw_cmo_feature_init()\n");
  694. spin_lock(&rtas_data_buf_lock);
  695. memset(rtas_data_buf, 0, RTAS_DATA_BUF_SIZE);
  696. call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
  697. NULL,
  698. CMO_CHARACTERISTICS_TOKEN,
  699. __pa(rtas_data_buf),
  700. RTAS_DATA_BUF_SIZE);
  701. if (call_status != 0) {
  702. spin_unlock(&rtas_data_buf_lock);
  703. pr_debug("CMO not available\n");
  704. pr_debug(" <- fw_cmo_feature_init()\n");
  705. return;
  706. }
  707. end = rtas_data_buf + CMO_MAXLENGTH - 2;
  708. ptr = rtas_data_buf + 2; /* step over strlen value */
  709. key = value = ptr;
  710. while (*ptr && (ptr <= end)) {
  711. /* Separate the key and value by replacing '=' with '\0' and
  712. * point the value at the string after the '='
  713. */
  714. if (ptr[0] == '=') {
  715. ptr[0] = '\0';
  716. value = ptr + 1;
  717. } else if (ptr[0] == '\0' || ptr[0] == ',') {
  718. /* Terminate the string containing the key/value pair */
  719. ptr[0] = '\0';
  720. if (key == value) {
  721. pr_debug("Malformed key/value pair\n");
  722. /* Never found a '=', end processing */
  723. break;
  724. }
  725. if (0 == strcmp(key, "CMOPageSize"))
  726. page_order = simple_strtol(value, NULL, 10);
  727. else if (0 == strcmp(key, "PrPSP"))
  728. CMO_PrPSP = simple_strtol(value, NULL, 10);
  729. else if (0 == strcmp(key, "SecPSP"))
  730. CMO_SecPSP = simple_strtol(value, NULL, 10);
  731. value = key = ptr + 1;
  732. }
  733. ptr++;
  734. }
  735. /* Page size is returned as the power of 2 of the page size,
  736. * convert to the page size in bytes before returning
  737. */
  738. CMO_PageSize = 1 << page_order;
  739. pr_debug("CMO_PageSize = %lu\n", CMO_PageSize);
  740. if (CMO_PrPSP != -1 || CMO_SecPSP != -1) {
  741. pr_info("CMO enabled\n");
  742. pr_debug("CMO enabled, PrPSP=%d, SecPSP=%d\n", CMO_PrPSP,
  743. CMO_SecPSP);
  744. powerpc_firmware_features |= FW_FEATURE_CMO;
  745. pSeries_coalesce_init();
  746. } else
  747. pr_debug("CMO not enabled, PrPSP=%d, SecPSP=%d\n", CMO_PrPSP,
  748. CMO_SecPSP);
  749. spin_unlock(&rtas_data_buf_lock);
  750. pr_debug(" <- fw_cmo_feature_init()\n");
  751. }
  752. /*
  753. * Early initialization. Relocation is on but do not reference unbolted pages
  754. */
  755. static void __init pseries_init(void)
  756. {
  757. pr_debug(" -> pseries_init()\n");
  758. #ifdef CONFIG_HVC_CONSOLE
  759. if (firmware_has_feature(FW_FEATURE_LPAR))
  760. hvc_vio_init_early();
  761. #endif
  762. if (firmware_has_feature(FW_FEATURE_XDABR))
  763. ppc_md.set_dabr = pseries_set_xdabr;
  764. else if (firmware_has_feature(FW_FEATURE_DABR))
  765. ppc_md.set_dabr = pseries_set_dabr;
  766. if (firmware_has_feature(FW_FEATURE_SET_MODE))
  767. ppc_md.set_dawr = pseries_set_dawr;
  768. pSeries_cmo_feature_init();
  769. iommu_init_early_pSeries();
  770. pr_debug(" <- pseries_init()\n");
  771. }
  772. /**
  773. * pseries_power_off - tell firmware about how to power off the system.
  774. *
  775. * This function calls either the power-off rtas token in normal cases
  776. * or the ibm,power-off-ups token (if present & requested) in case of
  777. * a power failure. If power-off token is used, power on will only be
  778. * possible with power button press. If ibm,power-off-ups token is used
  779. * it will allow auto poweron after power is restored.
  780. */
  781. static void pseries_power_off(void)
  782. {
  783. int rc;
  784. int rtas_poweroff_ups_token = rtas_token("ibm,power-off-ups");
  785. if (rtas_flash_term_hook)
  786. rtas_flash_term_hook(SYS_POWER_OFF);
  787. if (rtas_poweron_auto == 0 ||
  788. rtas_poweroff_ups_token == RTAS_UNKNOWN_SERVICE) {
  789. rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);
  790. printk(KERN_INFO "RTAS power-off returned %d\n", rc);
  791. } else {
  792. rc = rtas_call(rtas_poweroff_ups_token, 0, 1, NULL);
  793. printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);
  794. }
  795. for (;;);
  796. }
  797. static int __init pSeries_probe(void)
  798. {
  799. const char *dtype = of_get_property(of_root, "device_type", NULL);
  800. if (dtype == NULL)
  801. return 0;
  802. if (strcmp(dtype, "chrp"))
  803. return 0;
  804. /* Cell blades firmware claims to be chrp while it's not. Until this
  805. * is fixed, we need to avoid those here.
  806. */
  807. if (of_machine_is_compatible("IBM,CPBW-1.0") ||
  808. of_machine_is_compatible("IBM,CBEA"))
  809. return 0;
  810. pm_power_off = pseries_power_off;
  811. pr_debug("Machine is%s LPAR !\n",
  812. (powerpc_firmware_features & FW_FEATURE_LPAR) ? "" : " not");
  813. pseries_init();
  814. return 1;
  815. }
  816. static int pSeries_pci_probe_mode(struct pci_bus *bus)
  817. {
  818. if (firmware_has_feature(FW_FEATURE_LPAR))
  819. return PCI_PROBE_DEVTREE;
  820. return PCI_PROBE_NORMAL;
  821. }
  822. struct pci_controller_ops pseries_pci_controller_ops = {
  823. .probe_mode = pSeries_pci_probe_mode,
  824. };
  825. define_machine(pseries) {
  826. .name = "pSeries",
  827. .probe = pSeries_probe,
  828. .setup_arch = pSeries_setup_arch,
  829. .init_IRQ = pseries_init_irq,
  830. .show_cpuinfo = pSeries_show_cpuinfo,
  831. .log_error = pSeries_log_error,
  832. .pcibios_fixup = pSeries_final_fixup,
  833. .restart = rtas_restart,
  834. .halt = rtas_halt,
  835. .panic = pseries_panic,
  836. .get_boot_time = rtas_get_boot_time,
  837. .get_rtc_time = rtas_get_rtc_time,
  838. .set_rtc_time = rtas_set_rtc_time,
  839. .calibrate_decr = generic_calibrate_decr,
  840. .progress = rtas_progress,
  841. .system_reset_exception = pSeries_system_reset_exception,
  842. .machine_check_exception = pSeries_machine_check_exception,
  843. #ifdef CONFIG_KEXEC_CORE
  844. .machine_kexec = pSeries_machine_kexec,
  845. .kexec_cpu_down = pseries_kexec_cpu_down,
  846. #endif
  847. #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
  848. .memory_block_size = pseries_memory_block_size,
  849. #endif
  850. };