epapr_paravirt.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ePAPR para-virtualization support.
  4. *
  5. * Copyright (C) 2012 Freescale Semiconductor, Inc.
  6. */
  7. #include <linux/of.h>
  8. #include <linux/of_fdt.h>
  9. #include <asm/epapr_hcalls.h>
  10. #include <asm/cacheflush.h>
  11. #include <asm/code-patching.h>
  12. #include <asm/machdep.h>
  13. #include <asm/inst.h>
  14. #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
  15. extern void epapr_ev_idle(void);
  16. extern u32 epapr_ev_idle_start[];
  17. #endif
  18. bool epapr_paravirt_enabled;
  19. static bool __maybe_unused epapr_has_idle;
  20. static int __init early_init_dt_scan_epapr(unsigned long node,
  21. const char *uname,
  22. int depth, void *data)
  23. {
  24. const u32 *insts;
  25. int len;
  26. int i;
  27. insts = of_get_flat_dt_prop(node, "hcall-instructions", &len);
  28. if (!insts)
  29. return 0;
  30. if (len % 4 || len > (4 * 4))
  31. return -1;
  32. for (i = 0; i < (len / 4); i++) {
  33. struct ppc_inst inst = ppc_inst(be32_to_cpu(insts[i]));
  34. patch_instruction((struct ppc_inst *)(epapr_hypercall_start + i), inst);
  35. #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
  36. patch_instruction((struct ppc_inst *)(epapr_ev_idle_start + i), inst);
  37. #endif
  38. }
  39. #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
  40. if (of_get_flat_dt_prop(node, "has-idle", NULL))
  41. epapr_has_idle = true;
  42. #endif
  43. epapr_paravirt_enabled = true;
  44. return 1;
  45. }
  46. int __init epapr_paravirt_early_init(void)
  47. {
  48. of_scan_flat_dt(early_init_dt_scan_epapr, NULL);
  49. return 0;
  50. }
  51. static int __init epapr_idle_init(void)
  52. {
  53. #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
  54. if (epapr_has_idle)
  55. ppc_md.power_save = epapr_ev_idle;
  56. #endif
  57. return 0;
  58. }
  59. postcore_initcall(epapr_idle_init);