powerpc/pseries: Pass CPPR value to H_XIRR hcall
[linux-2.6.git] / arch / powerpc / platforms / pseries / plpar_wrappers.h
1 #ifndef _PSERIES_PLPAR_WRAPPERS_H
2 #define _PSERIES_PLPAR_WRAPPERS_H
3
4 #include <asm/hvcall.h>
5 #include <asm/page.h>
6
7 static inline long poll_pending(void)
8 {
9         return plpar_hcall_norets(H_POLL_PENDING);
10 }
11
12 static inline u8 get_cede_latency_hint(void)
13 {
14         return get_lppaca()->gpr5_dword.fields.cede_latency_hint;
15 }
16
17 static inline void set_cede_latency_hint(u8 latency_hint)
18 {
19         get_lppaca()->gpr5_dword.fields.cede_latency_hint = latency_hint;
20 }
21
22 static inline long cede_processor(void)
23 {
24         return plpar_hcall_norets(H_CEDE);
25 }
26
27 static inline long extended_cede_processor(unsigned long latency_hint)
28 {
29         long rc;
30         u8 old_latency_hint = get_cede_latency_hint();
31
32         set_cede_latency_hint(latency_hint);
33         rc = cede_processor();
34         set_cede_latency_hint(old_latency_hint);
35
36         return rc;
37 }
38
39 static inline long vpa_call(unsigned long flags, unsigned long cpu,
40                 unsigned long vpa)
41 {
42         /* flags are in bits 16-18 (counting from most significant bit) */
43         flags = flags << (63 - 18);
44
45         return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa);
46 }
47
48 static inline long unregister_vpa(unsigned long cpu, unsigned long vpa)
49 {
50         return vpa_call(0x5, cpu, vpa);
51 }
52
53 static inline long register_vpa(unsigned long cpu, unsigned long vpa)
54 {
55         return vpa_call(0x1, cpu, vpa);
56 }
57
58 static inline long unregister_slb_shadow(unsigned long cpu, unsigned long vpa)
59 {
60         return vpa_call(0x7, cpu, vpa);
61 }
62
63 static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa)
64 {
65         return vpa_call(0x3, cpu, vpa);
66 }
67
68 static inline long unregister_dtl(unsigned long cpu, unsigned long vpa)
69 {
70         return vpa_call(0x6, cpu, vpa);
71 }
72
73 static inline long register_dtl(unsigned long cpu, unsigned long vpa)
74 {
75         return vpa_call(0x2, cpu, vpa);
76 }
77
78 static inline long plpar_page_set_loaned(unsigned long vpa)
79 {
80         unsigned long cmo_page_sz = cmo_get_page_size();
81         long rc = 0;
82         int i;
83
84         for (i = 0; !rc && i < PAGE_SIZE; i += cmo_page_sz)
85                 rc = plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_LOANED, vpa + i, 0);
86
87         for (i -= cmo_page_sz; rc && i != 0; i -= cmo_page_sz)
88                 plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_ACTIVE,
89                                    vpa + i - cmo_page_sz, 0);
90
91         return rc;
92 }
93
94 static inline long plpar_page_set_active(unsigned long vpa)
95 {
96         unsigned long cmo_page_sz = cmo_get_page_size();
97         long rc = 0;
98         int i;
99
100         for (i = 0; !rc && i < PAGE_SIZE; i += cmo_page_sz)
101                 rc = plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_ACTIVE, vpa + i, 0);
102
103         for (i -= cmo_page_sz; rc && i != 0; i -= cmo_page_sz)
104                 plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_LOANED,
105                                    vpa + i - cmo_page_sz, 0);
106
107         return rc;
108 }
109
110 extern void vpa_init(int cpu);
111
112 static inline long plpar_pte_enter(unsigned long flags,
113                 unsigned long hpte_group, unsigned long hpte_v,
114                 unsigned long hpte_r, unsigned long *slot)
115 {
116         long rc;
117         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
118
119         rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r);
120
121         *slot = retbuf[0];
122
123         return rc;
124 }
125
126 static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex,
127                 unsigned long avpn, unsigned long *old_pteh_ret,
128                 unsigned long *old_ptel_ret)
129 {
130         long rc;
131         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
132
133         rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn);
134
135         *old_pteh_ret = retbuf[0];
136         *old_ptel_ret = retbuf[1];
137
138         return rc;
139 }
140
141 /* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */
142 static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex,
143                 unsigned long avpn, unsigned long *old_pteh_ret,
144                 unsigned long *old_ptel_ret)
145 {
146         long rc;
147         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
148
149         rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn);
150
151         *old_pteh_ret = retbuf[0];
152         *old_ptel_ret = retbuf[1];
153
154         return rc;
155 }
156
157 static inline long plpar_pte_read(unsigned long flags, unsigned long ptex,
158                 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
159 {
160         long rc;
161         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
162
163         rc = plpar_hcall(H_READ, retbuf, flags, ptex);
164
165         *old_pteh_ret = retbuf[0];
166         *old_ptel_ret = retbuf[1];
167
168         return rc;
169 }
170
171 /* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */
172 static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex,
173                 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
174 {
175         long rc;
176         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
177
178         rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex);
179
180         *old_pteh_ret = retbuf[0];
181         *old_ptel_ret = retbuf[1];
182
183         return rc;
184 }
185
186 static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex,
187                 unsigned long avpn)
188 {
189         return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn);
190 }
191
192 static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba,
193                 unsigned long *tce_ret)
194 {
195         long rc;
196         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
197
198         rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba);
199
200         *tce_ret = retbuf[0];
201
202         return rc;
203 }
204
205 static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba,
206                 unsigned long tceval)
207 {
208         return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval);
209 }
210
211 static inline long plpar_tce_put_indirect(unsigned long liobn,
212                 unsigned long ioba, unsigned long page, unsigned long count)
213 {
214         return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count);
215 }
216
217 static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba,
218                 unsigned long tceval, unsigned long count)
219 {
220         return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count);
221 }
222
223 static inline long plpar_get_term_char(unsigned long termno,
224                 unsigned long *len_ret, char *buf_ret)
225 {
226         long rc;
227         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
228         unsigned long *lbuf = (unsigned long *)buf_ret; /* TODO: alignment? */
229
230         rc = plpar_hcall(H_GET_TERM_CHAR, retbuf, termno);
231
232         *len_ret = retbuf[0];
233         lbuf[0] = retbuf[1];
234         lbuf[1] = retbuf[2];
235
236         return rc;
237 }
238
239 static inline long plpar_put_term_char(unsigned long termno, unsigned long len,
240                 const char *buffer)
241 {
242         unsigned long *lbuf = (unsigned long *)buffer;  /* TODO: alignment? */
243         return plpar_hcall_norets(H_PUT_TERM_CHAR, termno, len, lbuf[0],
244                         lbuf[1]);
245 }
246
247 static inline long plpar_eoi(unsigned long xirr)
248 {
249         return plpar_hcall_norets(H_EOI, xirr);
250 }
251
252 static inline long plpar_cppr(unsigned long cppr)
253 {
254         return plpar_hcall_norets(H_CPPR, cppr);
255 }
256
257 static inline long plpar_ipi(unsigned long servernum, unsigned long mfrr)
258 {
259         return plpar_hcall_norets(H_IPI, servernum, mfrr);
260 }
261
262 static inline long plpar_xirr(unsigned long *xirr_ret, unsigned char cppr)
263 {
264         long rc;
265         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
266
267         rc = plpar_hcall(H_XIRR, retbuf, cppr);
268
269         *xirr_ret = retbuf[0];
270
271         return rc;
272 }
273
274 #endif /* _PSERIES_PLPAR_WRAPPERS_H */