Thomas Gleixner | d94d71c | 2019-05-29 07:12:40 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 2 | /* |
| 3 | * ePAPR para-virtualization support. |
| 4 | * |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 5 | * Copyright (C) 2012 Freescale Semiconductor, Inc. |
| 6 | */ |
| 7 | |
| 8 | #include <linux/of.h> |
Rob Herring | 26a2056 | 2013-09-26 07:40:04 -0500 | [diff] [blame] | 9 | #include <linux/of_fdt.h> |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 10 | #include <asm/epapr_hcalls.h> |
| 11 | #include <asm/cacheflush.h> |
| 12 | #include <asm/code-patching.h> |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 13 | #include <asm/machdep.h> |
Jordan Niethe | 7534625 | 2020-05-06 13:40:26 +1000 | [diff] [blame] | 14 | #include <asm/inst.h> |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 15 | |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 16 | #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64) |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 17 | extern void epapr_ev_idle(void); |
| 18 | extern u32 epapr_ev_idle_start[]; |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 19 | #endif |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 20 | |
| 21 | bool epapr_paravirt_enabled; |
Scott Wood | 8067bd8 | 2014-05-15 11:28:26 -0500 | [diff] [blame] | 22 | static bool __maybe_unused epapr_has_idle; |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 23 | |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 24 | static int __init early_init_dt_scan_epapr(unsigned long node, |
| 25 | const char *uname, |
| 26 | int depth, void *data) |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 27 | { |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 28 | const u32 *insts; |
Rob Herring | 9d0c4df | 2014-04-01 23:49:03 -0500 | [diff] [blame] | 29 | int len; |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 30 | int i; |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 31 | |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 32 | insts = of_get_flat_dt_prop(node, "hcall-instructions", &len); |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 33 | if (!insts) |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 34 | return 0; |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 35 | |
| 36 | if (len % 4 || len > (4 * 4)) |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 37 | return -1; |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 38 | |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 39 | for (i = 0; i < (len / 4); i++) { |
Jordan Niethe | 94afd06 | 2020-05-06 13:40:31 +1000 | [diff] [blame] | 40 | struct ppc_inst inst = ppc_inst(be32_to_cpu(insts[i])); |
| 41 | patch_instruction((struct ppc_inst *)(epapr_hypercall_start + i), inst); |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 42 | #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64) |
Jordan Niethe | 94afd06 | 2020-05-06 13:40:31 +1000 | [diff] [blame] | 43 | patch_instruction((struct ppc_inst *)(epapr_ev_idle_start + i), inst); |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 44 | #endif |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 47 | #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64) |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 48 | if (of_get_flat_dt_prop(node, "has-idle", NULL)) |
Stuart Yoder | 83e267d | 2014-04-30 18:34:23 -0500 | [diff] [blame] | 49 | epapr_has_idle = true; |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 50 | #endif |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 51 | |
| 52 | epapr_paravirt_enabled = true; |
| 53 | |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 54 | return 1; |
| 55 | } |
| 56 | |
| 57 | int __init epapr_paravirt_early_init(void) |
| 58 | { |
| 59 | of_scan_flat_dt(early_init_dt_scan_epapr, NULL); |
| 60 | |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
Stuart Yoder | 83e267d | 2014-04-30 18:34:23 -0500 | [diff] [blame] | 64 | static int __init epapr_idle_init(void) |
| 65 | { |
Scott Wood | 440d74d | 2014-05-12 10:05:19 -0500 | [diff] [blame] | 66 | #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64) |
Stuart Yoder | 83e267d | 2014-04-30 18:34:23 -0500 | [diff] [blame] | 67 | if (epapr_has_idle) |
| 68 | ppc_md.power_save = epapr_ev_idle; |
Scott Wood | 440d74d | 2014-05-12 10:05:19 -0500 | [diff] [blame] | 69 | #endif |
Stuart Yoder | 83e267d | 2014-04-30 18:34:23 -0500 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | postcore_initcall(epapr_idle_init); |