Linux 4.1.18
[linux/fpc-iii.git] / arch / powerpc / kvm / book3s_64_vio_hv.c
blob89e96b3e00398d0fb45bd841924a7f6b541f6718
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.
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.
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.
15 * Copyright 2010 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
16 * Copyright 2011 David Gibson, IBM Corporation <dwg@au1.ibm.com>
19 #include <linux/types.h>
20 #include <linux/string.h>
21 #include <linux/kvm.h>
22 #include <linux/kvm_host.h>
23 #include <linux/highmem.h>
24 #include <linux/gfp.h>
25 #include <linux/slab.h>
26 #include <linux/hugetlb.h>
27 #include <linux/list.h>
29 #include <asm/tlbflush.h>
30 #include <asm/kvm_ppc.h>
31 #include <asm/kvm_book3s.h>
32 #include <asm/mmu-hash64.h>
33 #include <asm/hvcall.h>
34 #include <asm/synch.h>
35 #include <asm/ppc-opcode.h>
36 #include <asm/kvm_host.h>
37 #include <asm/udbg.h>
39 #define TCES_PER_PAGE (PAGE_SIZE / sizeof(u64))
41 /* WARNING: This will be called in real-mode on HV KVM and virtual
42 * mode on PR KVM
44 long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
45 unsigned long ioba, unsigned long tce)
47 struct kvm *kvm = vcpu->kvm;
48 struct kvmppc_spapr_tce_table *stt;
50 /* udbg_printf("H_PUT_TCE(): liobn=0x%lx ioba=0x%lx, tce=0x%lx\n", */
51 /* liobn, ioba, tce); */
53 list_for_each_entry(stt, &kvm->arch.spapr_tce_tables, list) {
54 if (stt->liobn == liobn) {
55 unsigned long idx = ioba >> SPAPR_TCE_SHIFT;
56 struct page *page;
57 u64 *tbl;
59 /* udbg_printf("H_PUT_TCE: liobn 0x%lx => stt=%p window_size=0x%x\n", */
60 /* liobn, stt, stt->window_size); */
61 if (ioba >= stt->window_size)
62 return H_PARAMETER;
64 page = stt->pages[idx / TCES_PER_PAGE];
65 tbl = (u64 *)page_address(page);
67 /* FIXME: Need to validate the TCE itself */
68 /* udbg_printf("tce @ %p\n", &tbl[idx % TCES_PER_PAGE]); */
69 tbl[idx % TCES_PER_PAGE] = tce;
70 return H_SUCCESS;
74 /* Didn't find the liobn, punt it to userspace */
75 return H_TOO_HARD;
77 EXPORT_SYMBOL_GPL(kvmppc_h_put_tce);
79 long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
80 unsigned long ioba)
82 struct kvm *kvm = vcpu->kvm;
83 struct kvmppc_spapr_tce_table *stt;
85 list_for_each_entry(stt, &kvm->arch.spapr_tce_tables, list) {
86 if (stt->liobn == liobn) {
87 unsigned long idx = ioba >> SPAPR_TCE_SHIFT;
88 struct page *page;
89 u64 *tbl;
91 if (ioba >= stt->window_size)
92 return H_PARAMETER;
94 page = stt->pages[idx / TCES_PER_PAGE];
95 tbl = (u64 *)page_address(page);
97 vcpu->arch.gpr[4] = tbl[idx % TCES_PER_PAGE];
98 return H_SUCCESS;
102 /* Didn't find the liobn, punt it to userspace */
103 return H_TOO_HARD;
105 EXPORT_SYMBOL_GPL(kvmppc_h_get_tce);