0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/of.h>
0009 #include <linux/of_fdt.h>
0010 #include <asm/epapr_hcalls.h>
0011 #include <asm/cacheflush.h>
0012 #include <asm/code-patching.h>
0013 #include <asm/machdep.h>
0014 #include <asm/inst.h>
0015
0016 #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
0017 extern void epapr_ev_idle(void);
0018 extern u32 epapr_ev_idle_start[];
0019 #endif
0020
0021 bool epapr_paravirt_enabled;
0022 static bool __maybe_unused epapr_has_idle;
0023
0024 static int __init early_init_dt_scan_epapr(unsigned long node,
0025 const char *uname,
0026 int depth, void *data)
0027 {
0028 const u32 *insts;
0029 int len;
0030 int i;
0031
0032 insts = of_get_flat_dt_prop(node, "hcall-instructions", &len);
0033 if (!insts)
0034 return 0;
0035
0036 if (len % 4 || len > (4 * 4))
0037 return -1;
0038
0039 for (i = 0; i < (len / 4); i++) {
0040 ppc_inst_t inst = ppc_inst(be32_to_cpu(insts[i]));
0041 patch_instruction(epapr_hypercall_start + i, inst);
0042 #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
0043 patch_instruction(epapr_ev_idle_start + i, inst);
0044 #endif
0045 }
0046
0047 #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
0048 if (of_get_flat_dt_prop(node, "has-idle", NULL))
0049 epapr_has_idle = true;
0050 #endif
0051
0052 epapr_paravirt_enabled = true;
0053
0054 return 1;
0055 }
0056
0057 int __init epapr_paravirt_early_init(void)
0058 {
0059 of_scan_flat_dt(early_init_dt_scan_epapr, NULL);
0060
0061 return 0;
0062 }
0063
0064 static int __init epapr_idle_init(void)
0065 {
0066 #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
0067 if (epapr_has_idle)
0068 ppc_md.power_save = epapr_ev_idle;
0069 #endif
0070
0071 return 0;
0072 }
0073
0074 postcore_initcall(epapr_idle_init);