e500.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
  3. *
  4. * Author: Yu Liu, <yu.liu@freescale.com>
  5. *
  6. * Description:
  7. * This file is derived from arch/powerpc/kvm/44x.c,
  8. * by Hollis Blanchard <hollisb@us.ibm.com>.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License, version 2, as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/kvm_host.h>
  15. #include <linux/err.h>
  16. #include <asm/reg.h>
  17. #include <asm/cputable.h>
  18. #include <asm/tlbflush.h>
  19. #include <asm/kvm_e500.h>
  20. #include <asm/kvm_ppc.h>
  21. #include "booke.h"
  22. #include "e500_tlb.h"
  23. void kvmppc_core_load_host_debugstate(struct kvm_vcpu *vcpu)
  24. {
  25. }
  26. void kvmppc_core_load_guest_debugstate(struct kvm_vcpu *vcpu)
  27. {
  28. }
  29. void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
  30. {
  31. kvmppc_e500_tlb_load(vcpu, cpu);
  32. }
  33. void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
  34. {
  35. kvmppc_e500_tlb_put(vcpu);
  36. }
  37. int kvmppc_core_check_processor_compat(void)
  38. {
  39. int r;
  40. if (strcmp(cur_cpu_spec->cpu_name, "e500v2") == 0)
  41. r = 0;
  42. else
  43. r = -ENOTSUPP;
  44. return r;
  45. }
  46. int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
  47. {
  48. struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
  49. kvmppc_e500_tlb_setup(vcpu_e500);
  50. return 0;
  51. }
  52. /* 'linear_address' is actually an encoding of AS|PID|EADDR . */
  53. int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
  54. struct kvm_translation *tr)
  55. {
  56. int index;
  57. gva_t eaddr;
  58. u8 pid;
  59. u8 as;
  60. eaddr = tr->linear_address;
  61. pid = (tr->linear_address >> 32) & 0xff;
  62. as = (tr->linear_address >> 40) & 0x1;
  63. index = kvmppc_e500_tlb_search(vcpu, eaddr, pid, as);
  64. if (index < 0) {
  65. tr->valid = 0;
  66. return 0;
  67. }
  68. tr->physical_address = kvmppc_mmu_xlate(vcpu, index, eaddr);
  69. /* XXX what does "writeable" and "usermode" even mean? */
  70. tr->valid = 1;
  71. return 0;
  72. }
  73. struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, unsigned int id)
  74. {
  75. struct kvmppc_vcpu_e500 *vcpu_e500;
  76. struct kvm_vcpu *vcpu;
  77. int err;
  78. vcpu_e500 = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
  79. if (!vcpu_e500) {
  80. err = -ENOMEM;
  81. goto out;
  82. }
  83. vcpu = &vcpu_e500->vcpu;
  84. err = kvm_vcpu_init(vcpu, kvm, id);
  85. if (err)
  86. goto free_vcpu;
  87. err = kvmppc_e500_tlb_init(vcpu_e500);
  88. if (err)
  89. goto uninit_vcpu;
  90. return vcpu;
  91. uninit_vcpu:
  92. kvm_vcpu_uninit(vcpu);
  93. free_vcpu:
  94. kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
  95. out:
  96. return ERR_PTR(err);
  97. }
  98. void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)
  99. {
  100. struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
  101. kvmppc_e500_tlb_uninit(vcpu_e500);
  102. kvm_vcpu_uninit(vcpu);
  103. kmem_cache_free(kvm_vcpu_cache, vcpu_e500);
  104. }
  105. static int __init kvmppc_e500_init(void)
  106. {
  107. int r, i;
  108. unsigned long ivor[3];
  109. unsigned long max_ivor = 0;
  110. r = kvmppc_booke_init();
  111. if (r)
  112. return r;
  113. /* copy extra E500 exception handlers */
  114. ivor[0] = mfspr(SPRN_IVOR32);
  115. ivor[1] = mfspr(SPRN_IVOR33);
  116. ivor[2] = mfspr(SPRN_IVOR34);
  117. for (i = 0; i < 3; i++) {
  118. if (ivor[i] > max_ivor)
  119. max_ivor = ivor[i];
  120. memcpy((void *)kvmppc_booke_handlers + ivor[i],
  121. kvmppc_handlers_start + (i + 16) * kvmppc_handler_len,
  122. kvmppc_handler_len);
  123. }
  124. flush_icache_range(kvmppc_booke_handlers,
  125. kvmppc_booke_handlers + max_ivor + kvmppc_handler_len);
  126. return kvm_init(NULL, sizeof(struct kvmppc_vcpu_e500), THIS_MODULE);
  127. }
  128. static void __init kvmppc_e500_exit(void)
  129. {
  130. kvmppc_booke_exit();
  131. }
  132. module_init(kvmppc_e500_init);
  133. module_exit(kvmppc_e500_exit);