| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * PowerNV setup code. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2011 IBM Corp. |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or |
|---|
| 7 | | - * modify it under the terms of the GNU General Public License |
|---|
| 8 | | - * as published by the Free Software Foundation; either version |
|---|
| 9 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 10 | 6 | */ |
|---|
| 11 | 7 | |
|---|
| 12 | 8 | #undef DEBUG |
|---|
| .. | .. |
|---|
| 28 | 24 | #include <linux/bug.h> |
|---|
| 29 | 25 | #include <linux/pci.h> |
|---|
| 30 | 26 | #include <linux/cpufreq.h> |
|---|
| 27 | +#include <linux/memblock.h> |
|---|
| 31 | 28 | |
|---|
| 32 | 29 | #include <asm/machdep.h> |
|---|
| 33 | 30 | #include <asm/firmware.h> |
|---|
| .. | .. |
|---|
| 101 | 98 | security_ftr_clear(SEC_FTR_BNDS_CHK_SPEC_BAR); |
|---|
| 102 | 99 | } |
|---|
| 103 | 100 | |
|---|
| 104 | | -static void pnv_setup_rfi_flush(void) |
|---|
| 101 | +static void pnv_setup_security_mitigations(void) |
|---|
| 105 | 102 | { |
|---|
| 106 | 103 | struct device_node *np, *fw_features; |
|---|
| 107 | 104 | enum l1d_flush_type type; |
|---|
| .. | .. |
|---|
| 148 | 145 | enable = security_ftr_enabled(SEC_FTR_FAVOUR_SECURITY) && |
|---|
| 149 | 146 | security_ftr_enabled(SEC_FTR_L1D_FLUSH_UACCESS); |
|---|
| 150 | 147 | setup_uaccess_flush(enable); |
|---|
| 148 | + |
|---|
| 149 | + setup_stf_barrier(); |
|---|
| 150 | +} |
|---|
| 151 | + |
|---|
| 152 | +static void __init pnv_check_guarded_cores(void) |
|---|
| 153 | +{ |
|---|
| 154 | + struct device_node *dn; |
|---|
| 155 | + int bad_count = 0; |
|---|
| 156 | + |
|---|
| 157 | + for_each_node_by_type(dn, "cpu") { |
|---|
| 158 | + if (of_property_match_string(dn, "status", "bad") >= 0) |
|---|
| 159 | + bad_count++; |
|---|
| 160 | + }; |
|---|
| 161 | + |
|---|
| 162 | + if (bad_count) { |
|---|
| 163 | + printk(" _ _______________\n"); |
|---|
| 164 | + pr_cont(" | | / \\\n"); |
|---|
| 165 | + pr_cont(" | | | WARNING! |\n"); |
|---|
| 166 | + pr_cont(" | | | |\n"); |
|---|
| 167 | + pr_cont(" | | | It looks like |\n"); |
|---|
| 168 | + pr_cont(" |_| | you have %*d |\n", 3, bad_count); |
|---|
| 169 | + pr_cont(" _ | guarded cores |\n"); |
|---|
| 170 | + pr_cont(" (_) \\_______________/\n"); |
|---|
| 171 | + } |
|---|
| 151 | 172 | } |
|---|
| 152 | 173 | |
|---|
| 153 | 174 | static void __init pnv_setup_arch(void) |
|---|
| 154 | 175 | { |
|---|
| 155 | 176 | set_arch_panic_timeout(10, ARCH_PANIC_TIMEOUT); |
|---|
| 156 | 177 | |
|---|
| 157 | | - pnv_setup_rfi_flush(); |
|---|
| 158 | | - setup_stf_barrier(); |
|---|
| 178 | + pnv_setup_security_mitigations(); |
|---|
| 159 | 179 | |
|---|
| 160 | 180 | /* Initialize SMP */ |
|---|
| 161 | 181 | pnv_smp_init(); |
|---|
| .. | .. |
|---|
| 170 | 190 | /* Enable NAP mode */ |
|---|
| 171 | 191 | powersave_nap = 1; |
|---|
| 172 | 192 | |
|---|
| 193 | + pnv_check_guarded_cores(); |
|---|
| 194 | + |
|---|
| 173 | 195 | /* XXX PMCS */ |
|---|
| 196 | + |
|---|
| 197 | + pnv_rng_init(); |
|---|
| 174 | 198 | } |
|---|
| 175 | 199 | |
|---|
| 176 | 200 | static void __init pnv_init(void) |
|---|
| .. | .. |
|---|
| 187 | 211 | else |
|---|
| 188 | 212 | #endif |
|---|
| 189 | 213 | add_preferred_console("hvc", 0, NULL); |
|---|
| 214 | + |
|---|
| 215 | + if (!radix_enabled()) { |
|---|
| 216 | + size_t size = sizeof(struct slb_entry) * mmu_slb_size; |
|---|
| 217 | + int i; |
|---|
| 218 | + |
|---|
| 219 | + /* Allocate per cpu area to save old slb contents during MCE */ |
|---|
| 220 | + for_each_possible_cpu(i) { |
|---|
| 221 | + paca_ptrs[i]->mce_faulty_slbs = |
|---|
| 222 | + memblock_alloc_node(size, |
|---|
| 223 | + __alignof__(struct slb_entry), |
|---|
| 224 | + cpu_to_node(i)); |
|---|
| 225 | + } |
|---|
| 226 | + } |
|---|
| 190 | 227 | } |
|---|
| 191 | 228 | |
|---|
| 192 | 229 | static void __init pnv_init_IRQ(void) |
|---|
| .. | .. |
|---|
| 236 | 273 | |
|---|
| 237 | 274 | static void __noreturn pnv_restart(char *cmd) |
|---|
| 238 | 275 | { |
|---|
| 239 | | - long rc = OPAL_BUSY; |
|---|
| 276 | + long rc; |
|---|
| 240 | 277 | |
|---|
| 241 | 278 | pnv_prepare_going_down(); |
|---|
| 242 | 279 | |
|---|
| 243 | | - while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { |
|---|
| 244 | | - rc = opal_cec_reboot(); |
|---|
| 245 | | - if (rc == OPAL_BUSY_EVENT) |
|---|
| 246 | | - opal_poll_events(NULL); |
|---|
| 280 | + do { |
|---|
| 281 | + if (!cmd || !strlen(cmd)) |
|---|
| 282 | + rc = opal_cec_reboot(); |
|---|
| 283 | + else if (strcmp(cmd, "full") == 0) |
|---|
| 284 | + rc = opal_cec_reboot2(OPAL_REBOOT_FULL_IPL, NULL); |
|---|
| 285 | + else if (strcmp(cmd, "mpipl") == 0) |
|---|
| 286 | + rc = opal_cec_reboot2(OPAL_REBOOT_MPIPL, NULL); |
|---|
| 287 | + else if (strcmp(cmd, "error") == 0) |
|---|
| 288 | + rc = opal_cec_reboot2(OPAL_REBOOT_PLATFORM_ERROR, NULL); |
|---|
| 289 | + else if (strcmp(cmd, "fast") == 0) |
|---|
| 290 | + rc = opal_cec_reboot2(OPAL_REBOOT_FAST, NULL); |
|---|
| 247 | 291 | else |
|---|
| 292 | + rc = OPAL_UNSUPPORTED; |
|---|
| 293 | + |
|---|
| 294 | + if (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) { |
|---|
| 295 | + /* Opal is busy wait for some time and retry */ |
|---|
| 296 | + opal_poll_events(NULL); |
|---|
| 248 | 297 | mdelay(10); |
|---|
| 249 | | - } |
|---|
| 298 | + |
|---|
| 299 | + } else if (cmd && rc) { |
|---|
| 300 | + /* Unknown error while issuing reboot */ |
|---|
| 301 | + if (rc == OPAL_UNSUPPORTED) |
|---|
| 302 | + pr_err("Unsupported '%s' reboot.\n", cmd); |
|---|
| 303 | + else |
|---|
| 304 | + pr_err("Unable to issue '%s' reboot. Err=%ld\n", |
|---|
| 305 | + cmd, rc); |
|---|
| 306 | + pr_info("Forcing a cec-reboot\n"); |
|---|
| 307 | + cmd = NULL; |
|---|
| 308 | + rc = OPAL_BUSY; |
|---|
| 309 | + |
|---|
| 310 | + } else if (rc != OPAL_SUCCESS) { |
|---|
| 311 | + /* Unknown error while issuing cec-reboot */ |
|---|
| 312 | + pr_err("Unable to reboot. Err=%ld\n", rc); |
|---|
| 313 | + } |
|---|
| 314 | + |
|---|
| 315 | + } while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT); |
|---|
| 316 | + |
|---|
| 250 | 317 | for (;;) |
|---|
| 251 | 318 | opal_poll_events(NULL); |
|---|
| 252 | 319 | } |
|---|
| .. | .. |
|---|
| 381 | 448 | #ifdef CONFIG_MEMORY_HOTPLUG_SPARSE |
|---|
| 382 | 449 | static unsigned long pnv_memory_block_size(void) |
|---|
| 383 | 450 | { |
|---|
| 384 | | - return 256UL * 1024 * 1024; |
|---|
| 451 | + /* |
|---|
| 452 | + * We map the kernel linear region with 1GB large pages on radix. For |
|---|
| 453 | + * memory hot unplug to work our memory block size must be at least |
|---|
| 454 | + * this size. |
|---|
| 455 | + */ |
|---|
| 456 | + if (radix_enabled()) |
|---|
| 457 | + return radix_mem_block_size; |
|---|
| 458 | + else |
|---|
| 459 | + return 256UL * 1024 * 1024; |
|---|
| 385 | 460 | } |
|---|
| 386 | 461 | #endif |
|---|
| 387 | 462 | |
|---|
| .. | .. |
|---|
| 394 | 469 | /* ppc_md.system_reset_exception gets filled in by pnv_smp_init() */ |
|---|
| 395 | 470 | ppc_md.machine_check_exception = opal_machine_check; |
|---|
| 396 | 471 | ppc_md.mce_check_early_recovery = opal_mce_check_early_recovery; |
|---|
| 397 | | - ppc_md.hmi_exception_early = opal_hmi_exception_early; |
|---|
| 472 | + if (opal_check_token(OPAL_HANDLE_HMI2)) |
|---|
| 473 | + ppc_md.hmi_exception_early = opal_hmi_exception_early2; |
|---|
| 474 | + else |
|---|
| 475 | + ppc_md.hmi_exception_early = opal_hmi_exception_early; |
|---|
| 398 | 476 | ppc_md.handle_hmi_exception = opal_handle_hmi_exception; |
|---|
| 399 | 477 | } |
|---|
| 400 | 478 | |
|---|
| .. | .. |
|---|
| 454 | 532 | return ret_freq; |
|---|
| 455 | 533 | } |
|---|
| 456 | 534 | |
|---|
| 535 | +static long pnv_machine_check_early(struct pt_regs *regs) |
|---|
| 536 | +{ |
|---|
| 537 | + long handled = 0; |
|---|
| 538 | + |
|---|
| 539 | + if (cur_cpu_spec && cur_cpu_spec->machine_check_early) |
|---|
| 540 | + handled = cur_cpu_spec->machine_check_early(regs); |
|---|
| 541 | + |
|---|
| 542 | + return handled; |
|---|
| 543 | +} |
|---|
| 544 | + |
|---|
| 457 | 545 | define_machine(powernv) { |
|---|
| 458 | 546 | .name = "PowerNV", |
|---|
| 459 | 547 | .probe = pnv_probe, |
|---|
| .. | .. |
|---|
| 465 | 553 | .machine_shutdown = pnv_shutdown, |
|---|
| 466 | 554 | .power_save = NULL, |
|---|
| 467 | 555 | .calibrate_decr = generic_calibrate_decr, |
|---|
| 556 | + .machine_check_early = pnv_machine_check_early, |
|---|
| 468 | 557 | #ifdef CONFIG_KEXEC_CORE |
|---|
| 469 | 558 | .kexec_cpu_down = pnv_kexec_cpu_down, |
|---|
| 470 | 559 | #endif |
|---|