Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 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 | |
| 20 | #ifndef __POWERPC_KVM_PPC_H__ |
| 21 | #define __POWERPC_KVM_PPC_H__ |
| 22 | |
| 23 | /* This file exists just so we can dereference kvm_vcpu, avoiding nested header |
| 24 | * dependencies. */ |
| 25 | |
| 26 | #include <linux/mutex.h> |
| 27 | #include <linux/timer.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/kvm_types.h> |
| 30 | #include <linux/kvm_host.h> |
| 31 | |
| 32 | struct kvm_tlb { |
| 33 | struct tlbe guest_tlb[PPC44x_TLB_SIZE]; |
| 34 | struct tlbe shadow_tlb[PPC44x_TLB_SIZE]; |
| 35 | }; |
| 36 | |
| 37 | enum emulation_result { |
| 38 | EMULATE_DONE, /* no further processing */ |
| 39 | EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */ |
| 40 | EMULATE_DO_DCR, /* kvm_run filled with DCR request */ |
| 41 | EMULATE_FAIL, /* can't emulate this instruction */ |
| 42 | }; |
| 43 | |
| 44 | extern const unsigned char exception_priority[]; |
| 45 | extern const unsigned char priority_exception[]; |
| 46 | |
| 47 | extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); |
| 48 | extern char kvmppc_handlers_start[]; |
| 49 | extern unsigned long kvmppc_handler_len; |
| 50 | |
| 51 | extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu); |
| 52 | extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 53 | unsigned int rt, unsigned int bytes, |
| 54 | int is_bigendian); |
| 55 | extern int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 56 | u32 val, unsigned int bytes, int is_bigendian); |
| 57 | |
| 58 | extern int kvmppc_emulate_instruction(struct kvm_run *run, |
| 59 | struct kvm_vcpu *vcpu); |
Hollis Blanchard | ce263d7 | 2008-05-21 18:22:51 -0500 | [diff] [blame] | 60 | extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 61 | |
| 62 | extern void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gfn_t gfn, |
| 63 | u64 asid, u32 flags); |
Hollis Blanchard | cc04454 | 2008-07-25 13:54:50 -0500 | [diff] [blame] | 64 | extern void kvmppc_mmu_invalidate(struct kvm_vcpu *vcpu, gva_t eaddr, |
| 65 | gva_t eend, u32 asid); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 66 | extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode); |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 67 | extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 68 | |
Hollis Blanchard | 83aae4a | 2008-07-25 13:54:52 -0500 | [diff] [blame] | 69 | /* XXX Book E specific */ |
| 70 | extern void kvmppc_tlbe_set_modified(struct kvm_vcpu *vcpu, unsigned int i); |
| 71 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 72 | extern void kvmppc_check_and_deliver_interrupts(struct kvm_vcpu *vcpu); |
| 73 | |
| 74 | static inline void kvmppc_queue_exception(struct kvm_vcpu *vcpu, int exception) |
| 75 | { |
| 76 | unsigned int priority = exception_priority[exception]; |
| 77 | set_bit(priority, &vcpu->arch.pending_exceptions); |
| 78 | } |
| 79 | |
| 80 | static inline void kvmppc_clear_exception(struct kvm_vcpu *vcpu, int exception) |
| 81 | { |
| 82 | unsigned int priority = exception_priority[exception]; |
| 83 | clear_bit(priority, &vcpu->arch.pending_exceptions); |
| 84 | } |
| 85 | |
Hollis Blanchard | 45c5eb6 | 2008-04-25 17:55:49 -0500 | [diff] [blame] | 86 | /* Helper function for "full" MSR writes. No need to call this if only EE is |
| 87 | * changing. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 88 | static inline void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr) |
| 89 | { |
| 90 | if ((new_msr & MSR_PR) != (vcpu->arch.msr & MSR_PR)) |
| 91 | kvmppc_mmu_priv_switch(vcpu, new_msr & MSR_PR); |
| 92 | |
| 93 | vcpu->arch.msr = new_msr; |
Hollis Blanchard | 45c5eb6 | 2008-04-25 17:55:49 -0500 | [diff] [blame] | 94 | |
| 95 | if (vcpu->arch.msr & MSR_WE) |
| 96 | kvm_vcpu_block(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 97 | } |
| 98 | |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 99 | static inline void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 new_pid) |
| 100 | { |
| 101 | if (vcpu->arch.pid != new_pid) { |
| 102 | vcpu->arch.pid = new_pid; |
| 103 | vcpu->arch.swap_pid = 1; |
| 104 | } |
| 105 | } |
| 106 | |
Hollis Blanchard | c30f8a6 | 2008-11-24 11:37:38 -0600 | [diff] [blame^] | 107 | extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu); |
| 108 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 109 | #endif /* __POWERPC_KVM_PPC_H__ */ |