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>
39 #define TCES_PER_PAGE (PAGE_SIZE / sizeof(u64))
41 /* WARNING: This will be called in real-mode on HV KVM and virtual
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
;
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
)
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
;
74 /* Didn't find the liobn, punt it to userspace */
77 EXPORT_SYMBOL_GPL(kvmppc_h_put_tce
);