booke_host.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright IBM Corp. 2008
  16. *
  17. * Authors: Hollis Blanchard <hollisb@us.ibm.com>
  18. */
  19. #include <linux/errno.h>
  20. #include <linux/kvm_host.h>
  21. #include <linux/module.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/kvm_ppc.h>
  24. unsigned long kvmppc_booke_handlers;
  25. static int kvmppc_booke_init(void)
  26. {
  27. unsigned long ivor[16];
  28. unsigned long max_ivor = 0;
  29. int i;
  30. /* We install our own exception handlers by hijacking IVPR. IVPR must
  31. * be 16-bit aligned, so we need a 64KB allocation. */
  32. kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO,
  33. VCPU_SIZE_ORDER);
  34. if (!kvmppc_booke_handlers)
  35. return -ENOMEM;
  36. /* XXX make sure our handlers are smaller than Linux's */
  37. /* Copy our interrupt handlers to match host IVORs. That way we don't
  38. * have to swap the IVORs on every guest/host transition. */
  39. ivor[0] = mfspr(SPRN_IVOR0);
  40. ivor[1] = mfspr(SPRN_IVOR1);
  41. ivor[2] = mfspr(SPRN_IVOR2);
  42. ivor[3] = mfspr(SPRN_IVOR3);
  43. ivor[4] = mfspr(SPRN_IVOR4);
  44. ivor[5] = mfspr(SPRN_IVOR5);
  45. ivor[6] = mfspr(SPRN_IVOR6);
  46. ivor[7] = mfspr(SPRN_IVOR7);
  47. ivor[8] = mfspr(SPRN_IVOR8);
  48. ivor[9] = mfspr(SPRN_IVOR9);
  49. ivor[10] = mfspr(SPRN_IVOR10);
  50. ivor[11] = mfspr(SPRN_IVOR11);
  51. ivor[12] = mfspr(SPRN_IVOR12);
  52. ivor[13] = mfspr(SPRN_IVOR13);
  53. ivor[14] = mfspr(SPRN_IVOR14);
  54. ivor[15] = mfspr(SPRN_IVOR15);
  55. for (i = 0; i < 16; i++) {
  56. if (ivor[i] > max_ivor)
  57. max_ivor = ivor[i];
  58. memcpy((void *)kvmppc_booke_handlers + ivor[i],
  59. kvmppc_handlers_start + i * kvmppc_handler_len,
  60. kvmppc_handler_len);
  61. }
  62. flush_icache_range(kvmppc_booke_handlers,
  63. kvmppc_booke_handlers + max_ivor + kvmppc_handler_len);
  64. return kvm_init(NULL, sizeof(struct kvm_vcpu), THIS_MODULE);
  65. }
  66. static void __exit kvmppc_booke_exit(void)
  67. {
  68. free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER);
  69. kvm_exit();
  70. }
  71. module_init(kvmppc_booke_init)
  72. module_exit(kvmppc_booke_exit)