1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/cpu.h>
20#include <linux/errno.h>
21#include <linux/sched.h>
22#include <linux/kernel.h>
23#include <linux/mm.h>
24#include <linux/stddef.h>
25#include <linux/unistd.h>
26#include <linux/user.h>
27#include <linux/tty.h>
28#include <linux/major.h>
29#include <linux/interrupt.h>
30#include <linux/reboot.h>
31#include <linux/init.h>
32#include <linux/ioport.h>
33#include <linux/console.h>
34#include <linux/pci.h>
35#include <linux/utsname.h>
36#include <linux/adb.h>
37#include <linux/export.h>
38#include <linux/delay.h>
39#include <linux/irq.h>
40#include <linux/seq_file.h>
41#include <linux/root_dev.h>
42#include <linux/of.h>
43#include <linux/of_pci.h>
44#include <linux/memblock.h>
45#include <linux/swiotlb.h>
46
47#include <asm/mmu.h>
48#include <asm/processor.h>
49#include <asm/io.h>
50#include <asm/pgtable.h>
51#include <asm/prom.h>
52#include <asm/rtas.h>
53#include <asm/pci-bridge.h>
54#include <asm/iommu.h>
55#include <asm/dma.h>
56#include <asm/machdep.h>
57#include <asm/irq.h>
58#include <asm/time.h>
59#include <asm/nvram.h>
60#include <asm/pmc.h>
61#include <asm/xics.h>
62#include <asm/xive.h>
63#include <asm/ppc-pci.h>
64#include <asm/i8259.h>
65#include <asm/udbg.h>
66#include <asm/smp.h>
67#include <asm/firmware.h>
68#include <asm/eeh.h>
69#include <asm/reg.h>
70#include <asm/plpar_wrappers.h>
71#include <asm/kexec.h>
72#include <asm/isa-bridge.h>
73#include <asm/security_features.h>
74#include <asm/idle.h>
75#include <asm/swiotlb.h>
76#include <asm/svm.h>
77#include <asm/dtl.h>
78
79#include "pseries.h"
80#include "../../../../drivers/pci/pci.h"
81
82DEFINE_STATIC_KEY_FALSE(shared_processor);
83EXPORT_SYMBOL_GPL(shared_processor);
84
85int CMO_PrPSP = -1;
86int CMO_SecPSP = -1;
87unsigned long CMO_PageSize = (ASM_CONST(1) << IOMMU_PAGE_SHIFT_4K);
88EXPORT_SYMBOL(CMO_PageSize);
89
90int fwnmi_active;
91u32 pseries_security_flavor;
92
93static void pSeries_show_cpuinfo(struct seq_file *m)
94{
95 struct device_node *root;
96 const char *model = "";
97
98 root = of_find_node_by_path("/");
99 if (root)
100 model = of_get_property(root, "model", NULL);
101 seq_printf(m, "machine\t\t: CHRP %s\n", model);
102 of_node_put(root);
103 if (radix_enabled())
104 seq_printf(m, "MMU\t\t: Radix\n");
105 else
106 seq_printf(m, "MMU\t\t: Hash\n");
107}
108
109
110
111
112static void __init fwnmi_init(void)
113{
114 unsigned long system_reset_addr, machine_check_addr;
115 u8 *mce_data_buf;
116 unsigned int i;
117 int nr_cpus = num_possible_cpus();
118#ifdef CONFIG_PPC_BOOK3S_64
119 struct slb_entry *slb_ptr;
120 size_t size;
121#endif
122
123 int ibm_nmi_register = rtas_token("ibm,nmi-register");
124 if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
125 return;
126
127
128
129 system_reset_addr = __pa(system_reset_fwnmi) - PHYSICAL_START;
130 machine_check_addr = __pa(machine_check_fwnmi) - PHYSICAL_START;
131
132 if (0 == rtas_call(ibm_nmi_register, 2, 1, NULL, system_reset_addr,
133 machine_check_addr))
134 fwnmi_active = 1;
135
136
137
138
139
140
141 mce_data_buf = __va(memblock_alloc_base(RTAS_ERROR_LOG_MAX * nr_cpus,
142 RTAS_ERROR_LOG_MAX, ppc64_rma_size));
143 for_each_possible_cpu(i) {
144 paca_ptrs[i]->mce_data_buf = mce_data_buf +
145 (RTAS_ERROR_LOG_MAX * i);
146 }
147
148#ifdef CONFIG_PPC_BOOK3S_64
149
150 size = sizeof(struct slb_entry) * mmu_slb_size * nr_cpus;
151 slb_ptr = __va(memblock_alloc_base(size, sizeof(struct slb_entry),
152 ppc64_rma_size));
153 for_each_possible_cpu(i)
154 paca_ptrs[i]->mce_faulty_slbs = slb_ptr + (mmu_slb_size * i);
155#endif
156}
157
158static void pseries_8259_cascade(struct irq_desc *desc)
159{
160 struct irq_chip *chip = irq_desc_get_chip(desc);
161 unsigned int cascade_irq = i8259_irq();
162
163 if (cascade_irq)
164 generic_handle_irq(cascade_irq);
165
166 chip->irq_eoi(&desc->irq_data);
167}
168
169static void __init pseries_setup_i8259_cascade(void)
170{
171 struct device_node *np, *old, *found = NULL;
172 unsigned int cascade;
173 const u32 *addrp;
174 unsigned long intack = 0;
175 int naddr;
176
177 for_each_node_by_type(np, "interrupt-controller") {
178 if (of_device_is_compatible(np, "chrp,iic")) {
179 found = np;
180 break;
181 }
182 }
183
184 if (found == NULL) {
185 printk(KERN_DEBUG "pic: no ISA interrupt controller\n");
186 return;
187 }
188
189 cascade = irq_of_parse_and_map(found, 0);
190 if (!cascade) {
191 printk(KERN_ERR "pic: failed to map cascade interrupt");
192 return;
193 }
194 pr_debug("pic: cascade mapped to irq %d\n", cascade);
195
196 for (old = of_node_get(found); old != NULL ; old = np) {
197 np = of_get_parent(old);
198 of_node_put(old);
199 if (np == NULL)
200 break;
201 if (strcmp(np->name, "pci") != 0)
202 continue;
203 addrp = of_get_property(np, "8259-interrupt-acknowledge", NULL);
204 if (addrp == NULL)
205 continue;
206 naddr = of_n_addr_cells(np);
207 intack = addrp[naddr-1];
208 if (naddr > 1)
209 intack |= ((unsigned long)addrp[naddr-2]) << 32;
210 }
211 if (intack)
212 printk(KERN_DEBUG "pic: PCI 8259 intack at 0x%016lx\n", intack);
213 i8259_init(found, intack);
214 of_node_put(found);
215 irq_set_chained_handler(cascade, pseries_8259_cascade);
216}
217
218static void __init pseries_init_irq(void)
219{
220
221 if (!xive_spapr_init()) {
222 xics_init();
223 pseries_setup_i8259_cascade();
224 }
225}
226
227static void pseries_lpar_enable_pmcs(void)
228{
229 unsigned long set, reset;
230
231 set = 1UL << 63;
232 reset = 0;
233 plpar_hcall_norets(H_PERFMON, set, reset);
234}
235
236static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data)
237{
238 struct of_reconfig_data *rd = data;
239 struct device_node *parent, *np = rd->dn;
240 struct pci_dn *pdn;
241 int err = NOTIFY_OK;
242
243 switch (action) {
244 case OF_RECONFIG_ATTACH_NODE:
245 parent = of_get_parent(np);
246 pdn = parent ? PCI_DN(parent) : NULL;
247 if (pdn)
248 pci_add_device_node_info(pdn->phb, np);
249
250 of_node_put(parent);
251 break;
252 case OF_RECONFIG_DETACH_NODE:
253 pdn = PCI_DN(np);
254 if (pdn)
255 list_del(&pdn->list);
256 break;
257 default:
258 err = NOTIFY_DONE;
259 break;
260 }
261 return err;
262}
263
264static struct notifier_block pci_dn_reconfig_nb = {
265 .notifier_call = pci_dn_reconfig_notifier,
266};
267
268struct kmem_cache *dtl_cache;
269
270#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
271
272
273
274
275
276static int alloc_dispatch_logs(void)
277{
278 if (!firmware_has_feature(FW_FEATURE_SPLPAR))
279 return 0;
280
281 if (!dtl_cache)
282 return 0;
283
284 alloc_dtl_buffers(0);
285
286
287 register_dtl_buffer(smp_processor_id());
288
289 return 0;
290}
291#else
292static inline int alloc_dispatch_logs(void)
293{
294 return 0;
295}
296#endif
297
298static int alloc_dispatch_log_kmem_cache(void)
299{
300 void (*ctor)(void *) = get_dtl_cache_ctor();
301
302 dtl_cache = kmem_cache_create("dtl", DISPATCH_LOG_BYTES,
303 DISPATCH_LOG_BYTES, 0, ctor);
304 if (!dtl_cache) {
305 pr_warn("Failed to create dispatch trace log buffer cache\n");
306 pr_warn("Stolen time statistics will be unreliable\n");
307 return 0;
308 }
309
310 return alloc_dispatch_logs();
311}
312machine_early_initcall(pseries, alloc_dispatch_log_kmem_cache);
313
314DEFINE_PER_CPU(u64, idle_spurr_cycles);
315DEFINE_PER_CPU(u64, idle_entry_purr_snap);
316DEFINE_PER_CPU(u64, idle_entry_spurr_snap);
317static void pseries_lpar_idle(void)
318{
319
320
321
322
323
324 if (!prep_irq_for_idle())
325 return;
326
327
328 pseries_idle_prolog();
329
330
331
332
333
334
335
336
337 cede_processor();
338
339 pseries_idle_epilog();
340}
341
342
343
344
345
346
347
348
349void pseries_enable_reloc_on_exc(void)
350{
351 long rc;
352 unsigned int delay, total_delay = 0;
353
354 while (1) {
355 rc = enable_reloc_on_exceptions();
356 if (!H_IS_LONG_BUSY(rc)) {
357 if (rc == H_P2) {
358 pr_info("Relocation on exceptions not"
359 " supported\n");
360 } else if (rc != H_SUCCESS) {
361 pr_warn("Unable to enable relocation"
362 " on exceptions: %ld\n", rc);
363 }
364 break;
365 }
366
367 delay = get_longbusy_msecs(rc);
368 total_delay += delay;
369 if (total_delay > 1000) {
370 pr_warn("Warning: Giving up waiting to enable "
371 "relocation on exceptions (%u msec)!\n",
372 total_delay);
373 return;
374 }
375
376 mdelay(delay);
377 }
378}
379EXPORT_SYMBOL(pseries_enable_reloc_on_exc);
380
381void pseries_disable_reloc_on_exc(void)
382{
383 long rc;
384
385 while (1) {
386 rc = disable_reloc_on_exceptions();
387 if (!H_IS_LONG_BUSY(rc))
388 break;
389 mdelay(get_longbusy_msecs(rc));
390 }
391 if (rc != H_SUCCESS)
392 pr_warn("Warning: Failed to disable relocation on exceptions: %ld\n",
393 rc);
394}
395EXPORT_SYMBOL(pseries_disable_reloc_on_exc);
396
397#ifdef CONFIG_KEXEC_CORE
398static void pSeries_machine_kexec(struct kimage *image)
399{
400 if (firmware_has_feature(FW_FEATURE_SET_MODE))
401 pseries_disable_reloc_on_exc();
402
403 default_machine_kexec(image);
404}
405#endif
406
407#ifdef __LITTLE_ENDIAN__
408void pseries_big_endian_exceptions(void)
409{
410 long rc;
411
412 while (1) {
413 rc = enable_big_endian_exceptions();
414 if (!H_IS_LONG_BUSY(rc))
415 break;
416 mdelay(get_longbusy_msecs(rc));
417 }
418
419
420
421
422
423
424
425
426
427
428
429
430 if (rc && !kdump_in_progress())
431 panic("Could not enable big endian exceptions");
432}
433
434void pseries_little_endian_exceptions(void)
435{
436 long rc;
437
438 while (1) {
439 rc = enable_little_endian_exceptions();
440 if (!H_IS_LONG_BUSY(rc))
441 break;
442 mdelay(get_longbusy_msecs(rc));
443 }
444 if (rc) {
445 ppc_md.progress("H_SET_MODE LE exception fail", 0);
446 panic("Could not enable little endian exceptions");
447 }
448}
449#endif
450
451static void __init pSeries_discover_phbs(void)
452{
453 struct device_node *node;
454 struct pci_controller *phb;
455 struct device_node *root = of_find_node_by_path("/");
456
457 for_each_child_of_node(root, node) {
458 if (node->type == NULL || (strcmp(node->type, "pci") != 0 &&
459 strcmp(node->type, "pciex") != 0))
460 continue;
461
462 phb = pcibios_alloc_controller(node);
463 if (!phb)
464 continue;
465 rtas_setup_phb(phb);
466 pci_process_bridge_OF_ranges(phb, node, 0);
467 isa_bridge_find_early(phb);
468 phb->controller_ops = pseries_pci_controller_ops;
469
470
471 pci_devs_phb_init_dynamic(phb);
472 }
473
474 of_node_put(root);
475
476
477
478
479
480 of_pci_check_probe_only();
481}
482
483static void init_cpu_char_feature_flags(struct h_cpu_char_result *result)
484{
485
486
487
488
489 if (result->character & H_CPU_CHAR_SPEC_BAR_ORI31)
490 security_ftr_set(SEC_FTR_SPEC_BAR_ORI31);
491
492 if (result->character & H_CPU_CHAR_BCCTRL_SERIALISED)
493 security_ftr_set(SEC_FTR_BCCTRL_SERIALISED);
494
495 if (result->character & H_CPU_CHAR_L1D_FLUSH_ORI30)
496 security_ftr_set(SEC_FTR_L1D_FLUSH_ORI30);
497
498 if (result->character & H_CPU_CHAR_L1D_FLUSH_TRIG2)
499 security_ftr_set(SEC_FTR_L1D_FLUSH_TRIG2);
500
501 if (result->character & H_CPU_CHAR_L1D_THREAD_PRIV)
502 security_ftr_set(SEC_FTR_L1D_THREAD_PRIV);
503
504 if (result->character & H_CPU_CHAR_COUNT_CACHE_DISABLED)
505 security_ftr_set(SEC_FTR_COUNT_CACHE_DISABLED);
506
507 if (result->character & H_CPU_CHAR_BCCTR_FLUSH_ASSIST)
508 security_ftr_set(SEC_FTR_BCCTR_FLUSH_ASSIST);
509
510 if (result->character & H_CPU_CHAR_BCCTR_LINK_FLUSH_ASSIST)
511 security_ftr_set(SEC_FTR_BCCTR_LINK_FLUSH_ASSIST);
512
513 if (result->behaviour & H_CPU_BEHAV_FLUSH_COUNT_CACHE)
514 security_ftr_set(SEC_FTR_FLUSH_COUNT_CACHE);
515
516 if (result->behaviour & H_CPU_BEHAV_FLUSH_LINK_STACK)
517 security_ftr_set(SEC_FTR_FLUSH_LINK_STACK);
518
519
520
521
522
523
524
525 if (!(result->behaviour & H_CPU_BEHAV_FAVOUR_SECURITY)) {
526 security_ftr_clear(SEC_FTR_FAVOUR_SECURITY);
527 pseries_security_flavor = 0;
528 } else if (result->behaviour & H_CPU_BEHAV_FAVOUR_SECURITY_H)
529 pseries_security_flavor = 1;
530 else
531 pseries_security_flavor = 2;
532
533 if (!(result->behaviour & H_CPU_BEHAV_L1D_FLUSH_PR))
534 security_ftr_clear(SEC_FTR_L1D_FLUSH_PR);
535
536 if (result->behaviour & H_CPU_BEHAV_NO_L1D_FLUSH_ENTRY)
537 security_ftr_clear(SEC_FTR_L1D_FLUSH_ENTRY);
538
539 if (result->behaviour & H_CPU_BEHAV_NO_L1D_FLUSH_UACCESS)
540 security_ftr_clear(SEC_FTR_L1D_FLUSH_UACCESS);
541
542 if (result->behaviour & H_CPU_BEHAV_NO_STF_BARRIER)
543 security_ftr_clear(SEC_FTR_STF_BARRIER);
544
545 if (!(result->behaviour & H_CPU_BEHAV_BNDS_CHK_SPEC_BAR))
546 security_ftr_clear(SEC_FTR_BNDS_CHK_SPEC_BAR);
547}
548
549void pseries_setup_rfi_flush(void)
550{
551 struct h_cpu_char_result result;
552 enum l1d_flush_type types;
553 bool enable;
554 long rc;
555
556
557
558
559
560
561 powerpc_security_features = SEC_FTR_DEFAULT;
562
563 rc = plpar_get_cpu_characteristics(&result);
564 if (rc == H_SUCCESS)
565 init_cpu_char_feature_flags(&result);
566
567
568
569
570
571 security_ftr_clear(SEC_FTR_L1D_FLUSH_HV);
572
573 types = L1D_FLUSH_FALLBACK;
574
575 if (security_ftr_enabled(SEC_FTR_L1D_FLUSH_TRIG2))
576 types |= L1D_FLUSH_MTTRIG;
577
578 if (security_ftr_enabled(SEC_FTR_L1D_FLUSH_ORI30))
579 types |= L1D_FLUSH_ORI;
580
581 enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) && \
582 security_ftr_enabled(SEC_FTR_L1D_FLUSH_PR);
583
584 setup_rfi_flush(types, enable);
585 setup_count_cache_flush();
586
587 enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) &&
588 security_ftr_enabled(SEC_FTR_L1D_FLUSH_ENTRY);
589 setup_entry_flush(enable);
590
591 enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) &&
592 security_ftr_enabled(SEC_FTR_L1D_FLUSH_UACCESS);
593 setup_uaccess_flush(enable);
594}
595
596#ifdef CONFIG_PCI_IOV
597enum rtas_iov_fw_value_map {
598 NUM_RES_PROPERTY = 0,
599 LOW_INT = 1,
600 START_OF_ENTRIES = 2,
601 APERTURE_PROPERTY = 2,
602 WDW_SIZE_PROPERTY = 4,
603 NEXT_ENTRY = 7
604};
605
606enum get_iov_fw_value_index {
607 BAR_ADDRS = 1,
608 APERTURE_SIZE = 2,
609 WDW_SIZE = 3
610};
611
612resource_size_t pseries_get_iov_fw_value(struct pci_dev *dev, int resno,
613 enum get_iov_fw_value_index value)
614{
615 const int *indexes;
616 struct device_node *dn = pci_device_to_OF_node(dev);
617 int i, num_res, ret = 0;
618
619 indexes = of_get_property(dn, "ibm,open-sriov-vf-bar-info", NULL);
620 if (!indexes)
621 return 0;
622
623
624
625
626
627
628 num_res = of_read_number(&indexes[NUM_RES_PROPERTY], 1);
629 if (resno >= num_res)
630 return 0;
631
632 i = START_OF_ENTRIES + NEXT_ENTRY * resno;
633 switch (value) {
634 case BAR_ADDRS:
635 ret = of_read_number(&indexes[i], 2);
636 break;
637 case APERTURE_SIZE:
638 ret = of_read_number(&indexes[i + APERTURE_PROPERTY], 2);
639 break;
640 case WDW_SIZE:
641 ret = of_read_number(&indexes[i + WDW_SIZE_PROPERTY], 2);
642 break;
643 }
644
645 return ret;
646}
647
648void of_pci_set_vf_bar_size(struct pci_dev *dev, const int *indexes)
649{
650 struct resource *res;
651 resource_size_t base, size;
652 int i, r, num_res;
653
654 num_res = of_read_number(&indexes[NUM_RES_PROPERTY], 1);
655 num_res = min_t(int, num_res, PCI_SRIOV_NUM_BARS);
656 for (i = START_OF_ENTRIES, r = 0; r < num_res && r < PCI_SRIOV_NUM_BARS;
657 i += NEXT_ENTRY, r++) {
658 res = &dev->resource[r + PCI_IOV_RESOURCES];
659 base = of_read_number(&indexes[i], 2);
660 size = of_read_number(&indexes[i + APERTURE_PROPERTY], 2);
661 res->flags = pci_parse_of_flags(of_read_number
662 (&indexes[i + LOW_INT], 1), 0);
663 res->flags |= (IORESOURCE_MEM_64 | IORESOURCE_PCI_FIXED);
664 res->name = pci_name(dev);
665 res->start = base;
666 res->end = base + size - 1;
667 }
668}
669
670void of_pci_parse_iov_addrs(struct pci_dev *dev, const int *indexes)
671{
672 struct resource *res, *root, *conflict;
673 resource_size_t base, size;
674 int i, r, num_res;
675
676
677
678
679
680
681 num_res = of_read_number(&indexes[NUM_RES_PROPERTY], 1);
682 for (i = START_OF_ENTRIES, r = 0; r < num_res && r < PCI_SRIOV_NUM_BARS;
683 i += NEXT_ENTRY, r++) {
684 res = &dev->resource[r + PCI_IOV_RESOURCES];
685 base = of_read_number(&indexes[i], 2);
686 size = of_read_number(&indexes[i + WDW_SIZE_PROPERTY], 2);
687 res->name = pci_name(dev);
688 res->start = base;
689 res->end = base + size - 1;
690 root = &iomem_resource;
691 dev_dbg(&dev->dev,
692 "pSeries IOV BAR %d: trying firmware assignment %pR\n",
693 r + PCI_IOV_RESOURCES, res);
694 conflict = request_resource_conflict(root, res);
695 if (conflict) {
696 dev_info(&dev->dev,
697 "BAR %d: %pR conflicts with %s %pR\n",
698 r + PCI_IOV_RESOURCES, res,
699 conflict->name, conflict);
700 res->flags |= IORESOURCE_UNSET;
701 }
702 }
703}
704
705static void pseries_disable_sriov_resources(struct pci_dev *pdev)
706{
707 int i;
708
709 pci_warn(pdev, "No hypervisor support for SR-IOV on this device, IOV BARs disabled.\n");
710 for (i = 0; i < PCI_SRIOV_NUM_BARS; i++)
711 pdev->resource[i + PCI_IOV_RESOURCES].flags = 0;
712}
713
714static void pseries_pci_fixup_resources(struct pci_dev *pdev)
715{
716 const int *indexes;
717 struct device_node *dn = pci_device_to_OF_node(pdev);
718
719
720 indexes = of_get_property(dn, "ibm,open-sriov-vf-bar-info", NULL);
721 if (indexes)
722 of_pci_set_vf_bar_size(pdev, indexes);
723 else
724 pseries_disable_sriov_resources(pdev);
725}
726
727static void pseries_pci_fixup_iov_resources(struct pci_dev *pdev)
728{
729 const int *indexes;
730 struct device_node *dn = pci_device_to_OF_node(pdev);
731
732 if (!pdev->is_physfn || pci_dev_is_added(pdev))
733 return;
734
735 indexes = of_get_property(dn, "ibm,open-sriov-vf-bar-info", NULL);
736 if (indexes)
737 of_pci_parse_iov_addrs(pdev, indexes);
738 else
739 pseries_disable_sriov_resources(pdev);
740}
741
742static resource_size_t pseries_pci_iov_resource_alignment(struct pci_dev *pdev,
743 int resno)
744{
745 const __be32 *reg;
746 struct device_node *dn = pci_device_to_OF_node(pdev);
747
748
749 reg = of_get_property(dn, "ibm,is-open-sriov-pf", NULL);
750 if (!reg)
751 return pci_iov_resource_size(pdev, resno);
752
753 if (!pdev->is_physfn)
754 return 0;
755 return pseries_get_iov_fw_value(pdev,
756 resno - PCI_IOV_RESOURCES,
757 APERTURE_SIZE);
758}
759#endif
760
761static void __init pSeries_setup_arch(void)
762{
763 set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT);
764
765
766 smp_init_pseries();
767
768
769 if (radix_enabled() && !mmu_has_feature(MMU_FTR_GTSE))
770 if (!firmware_has_feature(FW_FEATURE_RPT_INVALIDATE))
771 panic("BUG: Radix support requires either GTSE or RPT_INVALIDATE\n");
772
773
774
775
776
777
778
779 loops_per_jiffy = 50000000;
780
781 fwnmi_init();
782
783 pseries_setup_rfi_flush();
784 setup_stf_barrier();
785
786
787 pci_add_flags(PCI_PROBE_ONLY);
788
789
790 init_pci_config_tokens();
791 of_reconfig_notifier_register(&pci_dn_reconfig_nb);
792
793 pSeries_nvram_init();
794
795 if (firmware_has_feature(FW_FEATURE_LPAR)) {
796 vpa_init(boot_cpuid);
797
798 if (lppaca_shared_proc(get_lppaca())) {
799 static_branch_enable(&shared_processor);
800 pv_spinlocks_init();
801 }
802
803 ppc_md.power_save = pseries_lpar_idle;
804 ppc_md.enable_pmcs = pseries_lpar_enable_pmcs;
805#ifdef CONFIG_PCI_IOV
806 ppc_md.pcibios_fixup_resources =
807 pseries_pci_fixup_resources;
808 ppc_md.pcibios_fixup_sriov =
809 pseries_pci_fixup_iov_resources;
810 ppc_md.pcibios_iov_resource_alignment =
811 pseries_pci_iov_resource_alignment;
812#endif
813 } else {
814
815 ppc_md.enable_pmcs = power4_enable_pmcs;
816 }
817
818 ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
819
820 if (swiotlb_force == SWIOTLB_FORCE)
821 ppc_swiotlb_enable = 1;
822}
823
824static void pseries_panic(char *str)
825{
826 panic_flush_kmsg_end();
827 rtas_os_term(str);
828}
829
830static int __init pSeries_init_panel(void)
831{
832
833#ifdef __BIG_ENDIAN__
834 ppc_md.progress("Linux ppc64\n", 0);
835#else
836 ppc_md.progress("Linux ppc64le\n", 0);
837#endif
838 ppc_md.progress(init_utsname()->version, 0);
839
840 return 0;
841}
842machine_arch_initcall(pseries, pSeries_init_panel);
843
844static int pseries_set_dabr(unsigned long dabr, unsigned long dabrx)
845{
846 return plpar_hcall_norets(H_SET_DABR, dabr);
847}
848
849static int pseries_set_xdabr(unsigned long dabr, unsigned long dabrx)
850{
851
852 if (dabrx == 0 && dabr == 0)
853 dabrx = DABRX_USER;
854
855 dabrx &= DABRX_KERNEL | DABRX_USER;
856
857 return plpar_hcall_norets(H_SET_XDABR, dabr, dabrx);
858}
859
860static int pseries_set_dawr(int nr, unsigned long dawr, unsigned long dawrx)
861{
862
863 dawrx &= ~DAWRX_HYP;
864
865 if (nr == 0)
866 return plpar_set_watchpoint0(dawr, dawrx);
867 else
868 return plpar_set_watchpoint1(dawr, dawrx);
869}
870
871#define CMO_CHARACTERISTICS_TOKEN 44
872#define CMO_MAXLENGTH 1026
873
874void pSeries_coalesce_init(void)
875{
876 struct hvcall_mpp_x_data mpp_x_data;
877
878 if (firmware_has_feature(FW_FEATURE_CMO) && !h_get_mpp_x(&mpp_x_data))
879 powerpc_firmware_features |= FW_FEATURE_XCMO;
880 else
881 powerpc_firmware_features &= ~FW_FEATURE_XCMO;
882}
883
884
885
886
887
888static void pSeries_cmo_feature_init(void)
889{
890 char *ptr, *key, *value, *end;
891 int call_status;
892 int page_order = IOMMU_PAGE_SHIFT_4K;
893
894 pr_debug(" -> fw_cmo_feature_init()\n");
895 spin_lock(&rtas_data_buf_lock);
896 memset(rtas_data_buf, 0, RTAS_DATA_BUF_SIZE);
897 call_status = rtas_call(rtas_token("ibm,get-system-parameter"), 3, 1,
898 NULL,
899 CMO_CHARACTERISTICS_TOKEN,
900 __pa(rtas_data_buf),
901 RTAS_DATA_BUF_SIZE);
902
903 if (call_status != 0) {
904 spin_unlock(&rtas_data_buf_lock);
905 pr_debug("CMO not available\n");
906 pr_debug(" <- fw_cmo_feature_init()\n");
907 return;
908 }
909
910 end = rtas_data_buf + CMO_MAXLENGTH - 2;
911 ptr = rtas_data_buf + 2;
912 key = value = ptr;
913
914 while (*ptr && (ptr <= end)) {
915
916
917
918 if (ptr[0] == '=') {
919 ptr[0] = '\0';
920 value = ptr + 1;
921 } else if (ptr[0] == '\0' || ptr[0] == ',') {
922
923 ptr[0] = '\0';
924
925 if (key == value) {
926 pr_debug("Malformed key/value pair\n");
927
928 break;
929 }
930
931 if (0 == strcmp(key, "CMOPageSize"))
932 page_order = simple_strtol(value, NULL, 10);
933 else if (0 == strcmp(key, "PrPSP"))
934 CMO_PrPSP = simple_strtol(value, NULL, 10);
935 else if (0 == strcmp(key, "SecPSP"))
936 CMO_SecPSP = simple_strtol(value, NULL, 10);
937 value = key = ptr + 1;
938 }
939 ptr++;
940 }
941
942
943
944
945 CMO_PageSize = 1 << page_order;
946 pr_debug("CMO_PageSize = %lu\n", CMO_PageSize);
947
948 if (CMO_PrPSP != -1 || CMO_SecPSP != -1) {
949 pr_info("CMO enabled\n");
950 pr_debug("CMO enabled, PrPSP=%d, SecPSP=%d\n", CMO_PrPSP,
951 CMO_SecPSP);
952 powerpc_firmware_features |= FW_FEATURE_CMO;
953 pSeries_coalesce_init();
954 } else
955 pr_debug("CMO not enabled, PrPSP=%d, SecPSP=%d\n", CMO_PrPSP,
956 CMO_SecPSP);
957 spin_unlock(&rtas_data_buf_lock);
958 pr_debug(" <- fw_cmo_feature_init()\n");
959}
960
961
962
963
964static void __init pseries_init(void)
965{
966 pr_debug(" -> pseries_init()\n");
967
968#ifdef CONFIG_HVC_CONSOLE
969 if (firmware_has_feature(FW_FEATURE_LPAR))
970 hvc_vio_init_early();
971#endif
972 if (firmware_has_feature(FW_FEATURE_XDABR))
973 ppc_md.set_dabr = pseries_set_xdabr;
974 else if (firmware_has_feature(FW_FEATURE_DABR))
975 ppc_md.set_dabr = pseries_set_dabr;
976
977 if (firmware_has_feature(FW_FEATURE_SET_MODE))
978 ppc_md.set_dawr = pseries_set_dawr;
979
980 pSeries_cmo_feature_init();
981 iommu_init_early_pSeries();
982
983 pr_debug(" <- pseries_init()\n");
984}
985
986
987
988
989
990
991
992
993
994
995static void pseries_power_off(void)
996{
997 int rc;
998 int rtas_poweroff_ups_token = rtas_token("ibm,power-off-ups");
999
1000 if (rtas_flash_term_hook)
1001 rtas_flash_term_hook(SYS_POWER_OFF);
1002
1003 if (rtas_poweron_auto == 0 ||
1004 rtas_poweroff_ups_token == RTAS_UNKNOWN_SERVICE) {
1005 rc = rtas_call(rtas_token("power-off"), 2, 1, NULL, -1, -1);
1006 printk(KERN_INFO "RTAS power-off returned %d\n", rc);
1007 } else {
1008 rc = rtas_call(rtas_poweroff_ups_token, 0, 1, NULL);
1009 printk(KERN_INFO "RTAS ibm,power-off-ups returned %d\n", rc);
1010 }
1011 for (;;);
1012}
1013
1014static int __init pSeries_probe(void)
1015{
1016 const char *dtype = of_get_property(of_root, "device_type", NULL);
1017
1018 if (dtype == NULL)
1019 return 0;
1020 if (strcmp(dtype, "chrp"))
1021 return 0;
1022
1023
1024
1025
1026 if (of_machine_is_compatible("IBM,CPBW-1.0") ||
1027 of_machine_is_compatible("IBM,CBEA"))
1028 return 0;
1029
1030 pm_power_off = pseries_power_off;
1031
1032 pr_debug("Machine is%s LPAR !\n",
1033 (powerpc_firmware_features & FW_FEATURE_LPAR) ? "" : " not");
1034
1035 pseries_init();
1036
1037 return 1;
1038}
1039
1040static int pSeries_pci_probe_mode(struct pci_bus *bus)
1041{
1042 if (firmware_has_feature(FW_FEATURE_LPAR))
1043 return PCI_PROBE_DEVTREE;
1044 return PCI_PROBE_NORMAL;
1045}
1046
1047struct pci_controller_ops pseries_pci_controller_ops = {
1048 .probe_mode = pSeries_pci_probe_mode,
1049};
1050
1051define_machine(pseries) {
1052 .name = "pSeries",
1053 .probe = pSeries_probe,
1054 .setup_arch = pSeries_setup_arch,
1055 .init_IRQ = pseries_init_irq,
1056 .show_cpuinfo = pSeries_show_cpuinfo,
1057 .log_error = pSeries_log_error,
1058 .discover_phbs = pSeries_discover_phbs,
1059 .pcibios_fixup = pSeries_final_fixup,
1060 .restart = rtas_restart,
1061 .halt = rtas_halt,
1062 .panic = pseries_panic,
1063 .get_boot_time = rtas_get_boot_time,
1064 .get_rtc_time = rtas_get_rtc_time,
1065 .set_rtc_time = rtas_set_rtc_time,
1066 .calibrate_decr = generic_calibrate_decr,
1067 .progress = rtas_progress,
1068 .system_reset_exception = pSeries_system_reset_exception,
1069 .machine_check_early = pseries_machine_check_realmode,
1070 .machine_check_exception = pSeries_machine_check_exception,
1071#ifdef CONFIG_KEXEC_CORE
1072 .machine_kexec = pSeries_machine_kexec,
1073 .kexec_cpu_down = pseries_kexec_cpu_down,
1074#endif
1075#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
1076 .memory_block_size = pseries_memory_block_size,
1077#endif
1078};
1079