Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / powerpc / kernel / epapr_paravirt.c
blob2ed14d4a47f5997b0866f6c2d96533d565b238f4
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * ePAPR para-virtualization support.
5 * Copyright (C) 2012 Freescale Semiconductor, Inc.
6 */
8 #include <linux/of.h>
9 #include <linux/of_fdt.h>
10 #include <asm/epapr_hcalls.h>
11 #include <asm/cacheflush.h>
12 #include <asm/code-patching.h>
13 #include <asm/machdep.h>
14 #include <asm/inst.h>
16 #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
17 extern void epapr_ev_idle(void);
18 extern u32 epapr_ev_idle_start[];
19 #endif
21 bool epapr_paravirt_enabled;
22 static bool __maybe_unused epapr_has_idle;
24 static int __init early_init_dt_scan_epapr(unsigned long node,
25 const char *uname,
26 int depth, void *data)
28 const u32 *insts;
29 int len;
30 int i;
32 insts = of_get_flat_dt_prop(node, "hcall-instructions", &len);
33 if (!insts)
34 return 0;
36 if (len % 4 || len > (4 * 4))
37 return -1;
39 for (i = 0; i < (len / 4); i++) {
40 struct ppc_inst inst = ppc_inst(be32_to_cpu(insts[i]));
41 patch_instruction((struct ppc_inst *)(epapr_hypercall_start + i), inst);
42 #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
43 patch_instruction((struct ppc_inst *)(epapr_ev_idle_start + i), inst);
44 #endif
47 #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
48 if (of_get_flat_dt_prop(node, "has-idle", NULL))
49 epapr_has_idle = true;
50 #endif
52 epapr_paravirt_enabled = true;
54 return 1;
57 int __init epapr_paravirt_early_init(void)
59 of_scan_flat_dt(early_init_dt_scan_epapr, NULL);
61 return 0;
64 static int __init epapr_idle_init(void)
66 #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
67 if (epapr_has_idle)
68 ppc_md.power_save = epapr_ev_idle;
69 #endif
71 return 0;
74 postcore_initcall(epapr_idle_init);