forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/arch/powerpc/platforms/pseries/setup.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * 64-bit pSeries and RS/6000 setup code.
34 *
....@@ -5,11 +6,6 @@
56 * Adapted from 'alpha' version by Gary Thomas
67 * Modified by Cort Dougan (cort@cs.nmt.edu)
78 * 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.
139 */
1410
1511 /*
....@@ -42,11 +38,11 @@
4238 #include <linux/of.h>
4339 #include <linux/of_pci.h>
4440 #include <linux/memblock.h>
41
+#include <linux/swiotlb.h>
4542
4643 #include <asm/mmu.h>
4744 #include <asm/processor.h>
4845 #include <asm/io.h>
49
-#include <asm/pgtable.h>
5046 #include <asm/prom.h>
5147 #include <asm/rtas.h>
5248 #include <asm/pci-bridge.h>
....@@ -71,6 +67,10 @@
7167 #include <asm/isa-bridge.h>
7268 #include <asm/security_features.h>
7369 #include <asm/asm-const.h>
70
+#include <asm/idle.h>
71
+#include <asm/swiotlb.h>
72
+#include <asm/svm.h>
73
+#include <asm/dtl.h>
7474
7575 #include "pseries.h"
7676 #include "../../../../drivers/pci/pci.h"
....@@ -84,6 +84,7 @@
8484 EXPORT_SYMBOL(CMO_PageSize);
8585
8686 int fwnmi_active; /* TRUE if an FWNMI handler is present */
87
+int ibm_nmi_interlock_token;
8788
8889 static void pSeries_show_cpuinfo(struct seq_file *m)
8990 {
....@@ -110,9 +111,18 @@
110111 u8 *mce_data_buf;
111112 unsigned int i;
112113 int nr_cpus = num_possible_cpus();
114
+#ifdef CONFIG_PPC_BOOK3S_64
115
+ struct slb_entry *slb_ptr;
116
+ size_t size;
117
+#endif
118
+ int ibm_nmi_register_token;
113119
114
- int ibm_nmi_register = rtas_token("ibm,nmi-register");
115
- if (ibm_nmi_register == RTAS_UNKNOWN_SERVICE)
120
+ ibm_nmi_register_token = rtas_token("ibm,nmi-register");
121
+ if (ibm_nmi_register_token == RTAS_UNKNOWN_SERVICE)
122
+ return;
123
+
124
+ ibm_nmi_interlock_token = rtas_token("ibm,nmi-interlock");
125
+ if (WARN_ON(ibm_nmi_interlock_token == RTAS_UNKNOWN_SERVICE))
116126 return;
117127
118128 /* If the kernel's not linked at zero we point the firmware at low
....@@ -120,8 +130,8 @@
120130 system_reset_addr = __pa(system_reset_fwnmi) - PHYSICAL_START;
121131 machine_check_addr = __pa(machine_check_fwnmi) - PHYSICAL_START;
122132
123
- if (0 == rtas_call(ibm_nmi_register, 2, 1, NULL, system_reset_addr,
124
- machine_check_addr))
133
+ if (0 == rtas_call(ibm_nmi_register_token, 2, 1, NULL,
134
+ system_reset_addr, machine_check_addr))
125135 fwnmi_active = 1;
126136
127137 /*
....@@ -129,12 +139,33 @@
129139 * It will be used in real mode mce handler, hence it needs to be
130140 * below RMA.
131141 */
132
- mce_data_buf = __va(memblock_alloc_base(RTAS_ERROR_LOG_MAX * nr_cpus,
133
- RTAS_ERROR_LOG_MAX, ppc64_rma_size));
142
+ mce_data_buf = memblock_alloc_try_nid_raw(RTAS_ERROR_LOG_MAX * nr_cpus,
143
+ RTAS_ERROR_LOG_MAX, MEMBLOCK_LOW_LIMIT,
144
+ ppc64_rma_size, NUMA_NO_NODE);
145
+ if (!mce_data_buf)
146
+ panic("Failed to allocate %d bytes below %pa for MCE buffer\n",
147
+ RTAS_ERROR_LOG_MAX * nr_cpus, &ppc64_rma_size);
148
+
134149 for_each_possible_cpu(i) {
135150 paca_ptrs[i]->mce_data_buf = mce_data_buf +
136151 (RTAS_ERROR_LOG_MAX * i);
137152 }
153
+
154
+#ifdef CONFIG_PPC_BOOK3S_64
155
+ if (!radix_enabled()) {
156
+ /* Allocate per cpu area to save old slb contents during MCE */
157
+ size = sizeof(struct slb_entry) * mmu_slb_size * nr_cpus;
158
+ slb_ptr = memblock_alloc_try_nid_raw(size,
159
+ sizeof(struct slb_entry), MEMBLOCK_LOW_LIMIT,
160
+ ppc64_rma_size, NUMA_NO_NODE);
161
+ if (!slb_ptr)
162
+ panic("Failed to allocate %zu bytes below %pa for slb area\n",
163
+ size, &ppc64_rma_size);
164
+
165
+ for_each_possible_cpu(i)
166
+ paca_ptrs[i]->mce_faulty_slbs = slb_ptr + (mmu_slb_size * i);
167
+ }
168
+#endif
138169 }
139170
140171 static void pseries_8259_cascade(struct irq_desc *desc)
....@@ -180,7 +211,7 @@
180211 of_node_put(old);
181212 if (np == NULL)
182213 break;
183
- if (strcmp(np->name, "pci") != 0)
214
+ if (!of_node_name_eq(np, "pci"))
184215 continue;
185216 addrp = of_get_property(np, "8259-interrupt-acknowledge", NULL);
186217 if (addrp == NULL)
....@@ -257,46 +288,16 @@
257288 */
258289 static int alloc_dispatch_logs(void)
259290 {
260
- int cpu, ret;
261
- struct paca_struct *pp;
262
- struct dtl_entry *dtl;
263
-
264291 if (!firmware_has_feature(FW_FEATURE_SPLPAR))
265292 return 0;
266293
267294 if (!dtl_cache)
268295 return 0;
269296
270
- for_each_possible_cpu(cpu) {
271
- pp = paca_ptrs[cpu];
272
- dtl = kmem_cache_alloc(dtl_cache, GFP_KERNEL);
273
- if (!dtl) {
274
- pr_warn("Failed to allocate dispatch trace log for cpu %d\n",
275
- cpu);
276
- pr_warn("Stolen time statistics will be unreliable\n");
277
- break;
278
- }
279
-
280
- pp->dtl_ridx = 0;
281
- pp->dispatch_log = dtl;
282
- pp->dispatch_log_end = dtl + N_DISPATCH_LOG;
283
- pp->dtl_curr = dtl;
284
- }
297
+ alloc_dtl_buffers(0);
285298
286299 /* Register the DTL for the current (boot) cpu */
287
- dtl = get_paca()->dispatch_log;
288
- get_paca()->dtl_ridx = 0;
289
- get_paca()->dtl_curr = dtl;
290
- get_paca()->lppaca_ptr->dtl_idx = 0;
291
-
292
- /* hypervisor reads buffer length from this field */
293
- dtl->enqueue_to_dispatch_time = cpu_to_be32(DISPATCH_LOG_BYTES);
294
- ret = register_dtl(hard_smp_processor_id(), __pa(dtl));
295
- if (ret)
296
- pr_err("WARNING: DTL registration of cpu %d (hw %d) failed "
297
- "with %d\n", smp_processor_id(),
298
- hard_smp_processor_id(), ret);
299
- get_paca()->lppaca_ptr->dtl_enable_mask = 2;
300
+ register_dtl_buffer(smp_processor_id());
300301
301302 return 0;
302303 }
....@@ -309,8 +310,10 @@
309310
310311 static int alloc_dispatch_log_kmem_cache(void)
311312 {
313
+ void (*ctor)(void *) = get_dtl_cache_ctor();
314
+
312315 dtl_cache = kmem_cache_create("dtl", DISPATCH_LOG_BYTES,
313
- DISPATCH_LOG_BYTES, 0, NULL);
316
+ DISPATCH_LOG_BYTES, 0, ctor);
314317 if (!dtl_cache) {
315318 pr_warn("Failed to create dispatch trace log buffer cache\n");
316319 pr_warn("Stolen time statistics will be unreliable\n");
....@@ -321,6 +324,9 @@
321324 }
322325 machine_early_initcall(pseries, alloc_dispatch_log_kmem_cache);
323326
327
+DEFINE_PER_CPU(u64, idle_spurr_cycles);
328
+DEFINE_PER_CPU(u64, idle_entry_purr_snap);
329
+DEFINE_PER_CPU(u64, idle_entry_spurr_snap);
324330 static void pseries_lpar_idle(void)
325331 {
326332 /*
....@@ -332,7 +338,7 @@
332338 return;
333339
334340 /* Indicate to hypervisor that we are idle. */
335
- get_lppaca()->idle = 1;
341
+ pseries_idle_prolog();
336342
337343 /*
338344 * Yield the processor to the hypervisor. We return if
....@@ -343,7 +349,7 @@
343349 */
344350 cede_processor();
345351
346
- get_lppaca()->idle = 0;
352
+ pseries_idle_epilog();
347353 }
348354
349355 /*
....@@ -353,7 +359,7 @@
353359 * to ever be a problem in practice we can move this into a kernel thread to
354360 * finish off the process later in boot.
355361 */
356
-void pseries_enable_reloc_on_exc(void)
362
+bool pseries_enable_reloc_on_exc(void)
357363 {
358364 long rc;
359365 unsigned int delay, total_delay = 0;
....@@ -364,11 +370,13 @@
364370 if (rc == H_P2) {
365371 pr_info("Relocation on exceptions not"
366372 " supported\n");
373
+ return false;
367374 } else if (rc != H_SUCCESS) {
368375 pr_warn("Unable to enable relocation"
369376 " on exceptions: %ld\n", rc);
377
+ return false;
370378 }
371
- break;
379
+ return true;
372380 }
373381
374382 delay = get_longbusy_msecs(rc);
....@@ -377,7 +385,7 @@
377385 pr_warn("Warning: Giving up waiting to enable "
378386 "relocation on exceptions (%u msec)!\n",
379387 total_delay);
380
- return;
388
+ return false;
381389 }
382390
383391 mdelay(delay);
....@@ -462,8 +470,8 @@
462470 struct device_node *root = of_find_node_by_path("/");
463471
464472 for_each_child_of_node(root, node) {
465
- if (node->type == NULL || (strcmp(node->type, "pci") != 0 &&
466
- strcmp(node->type, "pciex") != 0))
473
+ if (!of_node_is_type(node, "pci") &&
474
+ !of_node_is_type(node, "pciex"))
467475 continue;
468476
469477 phb = pcibios_alloc_controller(node);
....@@ -511,8 +519,14 @@
511519 if (result->character & H_CPU_CHAR_BCCTR_FLUSH_ASSIST)
512520 security_ftr_set(SEC_FTR_BCCTR_FLUSH_ASSIST);
513521
522
+ if (result->character & H_CPU_CHAR_BCCTR_LINK_FLUSH_ASSIST)
523
+ security_ftr_set(SEC_FTR_BCCTR_LINK_FLUSH_ASSIST);
524
+
514525 if (result->behaviour & H_CPU_BEHAV_FLUSH_COUNT_CACHE)
515526 security_ftr_set(SEC_FTR_FLUSH_COUNT_CACHE);
527
+
528
+ if (result->behaviour & H_CPU_BEHAV_FLUSH_LINK_STACK)
529
+ security_ftr_set(SEC_FTR_FLUSH_LINK_STACK);
516530
517531 /*
518532 * The features below are enabled by default, so we instead look to see
....@@ -524,11 +538,17 @@
524538 if (!(result->behaviour & H_CPU_BEHAV_L1D_FLUSH_PR))
525539 security_ftr_clear(SEC_FTR_L1D_FLUSH_PR);
526540
541
+ if (result->behaviour & H_CPU_BEHAV_NO_L1D_FLUSH_ENTRY)
542
+ security_ftr_clear(SEC_FTR_L1D_FLUSH_ENTRY);
543
+
544
+ if (result->behaviour & H_CPU_BEHAV_NO_L1D_FLUSH_UACCESS)
545
+ security_ftr_clear(SEC_FTR_L1D_FLUSH_UACCESS);
546
+
527547 if (!(result->behaviour & H_CPU_BEHAV_BNDS_CHK_SPEC_BAR))
528548 security_ftr_clear(SEC_FTR_BNDS_CHK_SPEC_BAR);
529549 }
530550
531
-void pseries_setup_rfi_flush(void)
551
+void pseries_setup_security_mitigations(void)
532552 {
533553 struct h_cpu_char_result result;
534554 enum l1d_flush_type types;
....@@ -573,6 +593,8 @@
573593 enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) &&
574594 security_ftr_enabled(SEC_FTR_L1D_FLUSH_UACCESS);
575595 setup_uaccess_flush(enable);
596
+
597
+ setup_stf_barrier();
576598 }
577599
578600 #ifdef CONFIG_PCI_IOV
....@@ -748,6 +770,11 @@
748770 smp_init_pseries();
749771
750772
773
+ if (radix_enabled() && !mmu_has_feature(MMU_FTR_GTSE))
774
+ if (!firmware_has_feature(FW_FEATURE_RPT_INVALIDATE))
775
+ panic("BUG: Radix support requires either GTSE or RPT_INVALIDATE\n");
776
+
777
+
751778 /* openpic global configuration register (64-bit format). */
752779 /* openpic Interrupt Source Unit pointer (64-bit format). */
753780 /* python0 facility area (mmio) (64-bit format) REAL address. */
....@@ -757,8 +784,8 @@
757784
758785 fwnmi_init();
759786
760
- pseries_setup_rfi_flush();
761
- setup_stf_barrier();
787
+ pseries_setup_security_mitigations();
788
+ pseries_lpar_read_hblkrm_characteristics();
762789
763790 /* By default, only probe PCI (can be overridden by rtas_pci) */
764791 pci_add_flags(PCI_PROBE_ONLY);
....@@ -773,8 +800,10 @@
773800 if (firmware_has_feature(FW_FEATURE_LPAR)) {
774801 vpa_init(boot_cpuid);
775802
776
- if (lppaca_shared_proc(get_lppaca()))
803
+ if (lppaca_shared_proc()) {
777804 static_branch_enable(&shared_processor);
805
+ pv_spinlocks_init();
806
+ }
778807
779808 ppc_md.power_save = pseries_lpar_idle;
780809 ppc_md.enable_pmcs = pseries_lpar_enable_pmcs;
....@@ -792,6 +821,11 @@
792821 }
793822
794823 ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare;
824
+
825
+ if (swiotlb_force == SWIOTLB_FORCE)
826
+ ppc_swiotlb_enable = 1;
827
+
828
+ pseries_rng_init();
795829 }
796830
797831 static void pseries_panic(char *str)
....@@ -830,12 +864,15 @@
830864 return plpar_hcall_norets(H_SET_XDABR, dabr, dabrx);
831865 }
832866
833
-static int pseries_set_dawr(unsigned long dawr, unsigned long dawrx)
867
+static int pseries_set_dawr(int nr, unsigned long dawr, unsigned long dawrx)
834868 {
835869 /* PAPR says we can't set HYP */
836870 dawrx &= ~DAWRX_HYP;
837871
838
- return plpar_set_watchpoint0(dawr, dawrx);
872
+ if (nr == 0)
873
+ return plpar_set_watchpoint0(dawr, dawrx);
874
+ else
875
+ return plpar_set_watchpoint1(dawr, dawrx);
839876 }
840877
841878 #define CMO_CHARACTERISTICS_TOKEN 44
....@@ -983,11 +1020,7 @@
9831020
9841021 static int __init pSeries_probe(void)
9851022 {
986
- const char *dtype = of_get_property(of_root, "device_type", NULL);
987
-
988
- if (dtype == NULL)
989
- return 0;
990
- if (strcmp(dtype, "chrp"))
1023
+ if (!of_node_is_type(of_root, "chrp"))
9911024 return 0;
9921025
9931026 /* Cell blades firmware claims to be chrp while it's not. Until this
....@@ -1035,6 +1068,7 @@
10351068 .calibrate_decr = generic_calibrate_decr,
10361069 .progress = rtas_progress,
10371070 .system_reset_exception = pSeries_system_reset_exception,
1071
+ .machine_check_early = pseries_machine_check_realmode,
10381072 .machine_check_exception = pSeries_machine_check_exception,
10391073 #ifdef CONFIG_KEXEC_CORE
10401074 .machine_kexec = pSeries_machine_kexec,