Blame view

kernel/linux-rt-4.4.41/arch/powerpc/kvm/book3s_64_vio_hv.c 3 KB
5113f6f70   김현기   kernel add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  /*
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License, version 2, as
   * published by the Free Software Foundation.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   *
   * Copyright 2010 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
   * Copyright 2011 David Gibson, IBM Corporation <dwg@au1.ibm.com>
   */
  
  #include <linux/types.h>
  #include <linux/string.h>
  #include <linux/kvm.h>
  #include <linux/kvm_host.h>
  #include <linux/highmem.h>
  #include <linux/gfp.h>
  #include <linux/slab.h>
  #include <linux/hugetlb.h>
  #include <linux/list.h>
  
  #include <asm/tlbflush.h>
  #include <asm/kvm_ppc.h>
  #include <asm/kvm_book3s.h>
  #include <asm/mmu-hash64.h>
  #include <asm/hvcall.h>
  #include <asm/synch.h>
  #include <asm/ppc-opcode.h>
  #include <asm/kvm_host.h>
  #include <asm/udbg.h>
  
  #define TCES_PER_PAGE	(PAGE_SIZE / sizeof(u64))
  
  /* WARNING: This will be called in real-mode on HV KVM and virtual
   *          mode on PR KVM
   */
  long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
  		      unsigned long ioba, unsigned long tce)
  {
  	struct kvm *kvm = vcpu->kvm;
  	struct kvmppc_spapr_tce_table *stt;
  
  	/* udbg_printf("H_PUT_TCE(): liobn=0x%lx ioba=0x%lx, tce=0x%lx
  ", */
  	/* 	    liobn, ioba, tce); */
  
  	list_for_each_entry(stt, &kvm->arch.spapr_tce_tables, list) {
  		if (stt->liobn == liobn) {
  			unsigned long idx = ioba >> SPAPR_TCE_SHIFT;
  			struct page *page;
  			u64 *tbl;
  
  			/* udbg_printf("H_PUT_TCE: liobn 0x%lx => stt=%p  window_size=0x%x
  ", */
  			/* 	    liobn, stt, stt->window_size); */
  			if (ioba >= stt->window_size)
  				return H_PARAMETER;
  
  			page = stt->pages[idx / TCES_PER_PAGE];
  			tbl = (u64 *)page_address(page);
  
  			/* FIXME: Need to validate the TCE itself */
  			/* udbg_printf("tce @ %p
  ", &tbl[idx % TCES_PER_PAGE]); */
  			tbl[idx % TCES_PER_PAGE] = tce;
  			return H_SUCCESS;
  		}
  	}
  
  	/* Didn't find the liobn, punt it to userspace */
  	return H_TOO_HARD;
  }
  EXPORT_SYMBOL_GPL(kvmppc_h_put_tce);
  
  long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
  		      unsigned long ioba)
  {
  	struct kvm *kvm = vcpu->kvm;
  	struct kvmppc_spapr_tce_table *stt;
  
  	list_for_each_entry(stt, &kvm->arch.spapr_tce_tables, list) {
  		if (stt->liobn == liobn) {
  			unsigned long idx = ioba >> SPAPR_TCE_SHIFT;
  			struct page *page;
  			u64 *tbl;
  
  			if (ioba >= stt->window_size)
  				return H_PARAMETER;
  
  			page = stt->pages[idx / TCES_PER_PAGE];
  			tbl = (u64 *)page_address(page);
  
  			vcpu->arch.gpr[4] = tbl[idx % TCES_PER_PAGE];
  			return H_SUCCESS;
  		}
  	}
  
  	/* Didn't find the liobn, punt it to userspace */
  	return H_TOO_HARD;
  }
  EXPORT_SYMBOL_GPL(kvmppc_h_get_tce);