epapr_paravirt.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * ePAPR para-virtualization support.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License, version 2, as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. *
  17. * Copyright (C) 2012 Freescale Semiconductor, Inc.
  18. */
  19. #include <linux/of.h>
  20. #include <linux/of_fdt.h>
  21. #include <asm/epapr_hcalls.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/code-patching.h>
  24. #include <asm/machdep.h>
  25. #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
  26. extern void epapr_ev_idle(void);
  27. extern u32 epapr_ev_idle_start[];
  28. #endif
  29. bool epapr_paravirt_enabled;
  30. static bool __maybe_unused epapr_has_idle;
  31. static int __init early_init_dt_scan_epapr(unsigned long node,
  32. const char *uname,
  33. int depth, void *data)
  34. {
  35. const u32 *insts;
  36. int len;
  37. int i;
  38. insts = of_get_flat_dt_prop(node, "hcall-instructions", &len);
  39. if (!insts)
  40. return 0;
  41. if (len % 4 || len > (4 * 4))
  42. return -1;
  43. for (i = 0; i < (len / 4); i++) {
  44. u32 inst = be32_to_cpu(insts[i]);
  45. patch_instruction(epapr_hypercall_start + i, inst);
  46. #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
  47. patch_instruction(epapr_ev_idle_start + i, inst);
  48. #endif
  49. }
  50. #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
  51. if (of_get_flat_dt_prop(node, "has-idle", NULL))
  52. epapr_has_idle = true;
  53. #endif
  54. epapr_paravirt_enabled = true;
  55. return 1;
  56. }
  57. int __init epapr_paravirt_early_init(void)
  58. {
  59. of_scan_flat_dt(early_init_dt_scan_epapr, NULL);
  60. return 0;
  61. }
  62. static int __init epapr_idle_init(void)
  63. {
  64. #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
  65. if (epapr_has_idle)
  66. ppc_md.power_save = epapr_ev_idle;
  67. #endif
  68. return 0;
  69. }
  70. postcore_initcall(epapr_idle_init);