blob: b93384929c4cbc2f7274820dbfaf549aa9e274fd [file] [log] [blame]
Michael Ellermana1218722005-11-03 15:33:31 +11001#ifndef _PSERIES_PLPAR_WRAPPERS_H
2#define _PSERIES_PLPAR_WRAPPERS_H
3
Paul Gortmaker614f15b2011-07-22 18:04:33 -04004#include <linux/string.h>
Li Zhongfb912562012-10-17 21:30:13 +00005#include <linux/irqflags.h>
Paul Gortmaker614f15b2011-07-22 18:04:33 -04006
Michael Ellermana1218722005-11-03 15:33:31 +11007#include <asm/hvcall.h>
Paul Gortmaker614f15b2011-07-22 18:04:33 -04008#include <asm/paca.h>
Brian King370e4582008-08-16 05:09:33 +10009#include <asm/page.h>
Michael Ellermana1218722005-11-03 15:33:31 +110010
Michael Neulingf8b67692010-04-28 13:39:41 +000011/* Get state of physical CPU from query_cpu_stopped */
12int smp_query_cpu_stopped(unsigned int pcpu);
13#define QCSS_STOPPED 0
14#define QCSS_STOPPING 1
15#define QCSS_NOT_STOPPED 2
16#define QCSS_HARDWARE_ERROR -1
17#define QCSS_HARDWARE_BUSY -2
18
Michael Ellermana1218722005-11-03 15:33:31 +110019static inline long poll_pending(void)
20{
Anton Blanchardb9377ff2006-07-19 08:01:28 +100021 return plpar_hcall_norets(H_POLL_PENDING);
Michael Ellermana1218722005-11-03 15:33:31 +110022}
23
Gautham R Shenoy69ddb572009-10-29 19:22:48 +000024static inline u8 get_cede_latency_hint(void)
25{
Anton Blanchardcf8a0562012-04-10 16:20:54 +000026 return get_lppaca()->cede_latency_hint;
Gautham R Shenoy69ddb572009-10-29 19:22:48 +000027}
28
29static inline void set_cede_latency_hint(u8 latency_hint)
30{
Anton Blanchardcf8a0562012-04-10 16:20:54 +000031 get_lppaca()->cede_latency_hint = latency_hint;
Gautham R Shenoy69ddb572009-10-29 19:22:48 +000032}
33
Michael Ellermana1218722005-11-03 15:33:31 +110034static inline long cede_processor(void)
35{
Anton Blanchardb9377ff2006-07-19 08:01:28 +100036 return plpar_hcall_norets(H_CEDE);
Michael Ellermana1218722005-11-03 15:33:31 +110037}
38
Gautham R Shenoy69ddb572009-10-29 19:22:48 +000039static inline long extended_cede_processor(unsigned long latency_hint)
40{
41 long rc;
42 u8 old_latency_hint = get_cede_latency_hint();
43
44 set_cede_latency_hint(latency_hint);
Li Zhongfb912562012-10-17 21:30:13 +000045
Gautham R Shenoy69ddb572009-10-29 19:22:48 +000046 rc = cede_processor();
Li Zhongfb912562012-10-17 21:30:13 +000047#ifdef CONFIG_TRACE_IRQFLAGS
48 /* Ensure that H_CEDE returns with IRQs on */
49 if (WARN_ON(!(mfmsr() & MSR_EE)))
50 __hard_irq_enable();
51#endif
52
Gautham R Shenoy69ddb572009-10-29 19:22:48 +000053 set_cede_latency_hint(old_latency_hint);
54
55 return rc;
56}
57
Michael Ellerman40765d22005-11-03 19:34:38 +110058static inline long vpa_call(unsigned long flags, unsigned long cpu,
Michael Ellermana1218722005-11-03 15:33:31 +110059 unsigned long vpa)
60{
Michael Ellerman40765d22005-11-03 19:34:38 +110061 /* flags are in bits 16-18 (counting from most significant bit) */
62 flags = flags << (63 - 18);
63
64 return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa);
Michael Ellermana1218722005-11-03 15:33:31 +110065}
66
Anton Blanchard598c8232011-07-25 01:46:34 +000067static inline long unregister_vpa(unsigned long cpu)
Michael Ellerman40765d22005-11-03 19:34:38 +110068{
Anton Blanchard598c8232011-07-25 01:46:34 +000069 return vpa_call(0x5, cpu, 0);
Michael Ellerman40765d22005-11-03 19:34:38 +110070}
71
72static inline long register_vpa(unsigned long cpu, unsigned long vpa)
73{
74 return vpa_call(0x1, cpu, vpa);
75}
76
Anton Blanchard598c8232011-07-25 01:46:34 +000077static inline long unregister_slb_shadow(unsigned long cpu)
Michael Neuling2f6093c2006-08-07 16:19:19 +100078{
Anton Blanchard598c8232011-07-25 01:46:34 +000079 return vpa_call(0x7, cpu, 0);
Michael Neuling2f6093c2006-08-07 16:19:19 +100080}
81
82static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa)
83{
84 return vpa_call(0x3, cpu, vpa);
85}
86
Anton Blanchardb1301792011-07-25 01:46:32 +000087static inline long unregister_dtl(unsigned long cpu)
Jeremy Kerrfc59a3f2009-03-11 17:55:52 +000088{
Anton Blanchardb1301792011-07-25 01:46:32 +000089 return vpa_call(0x6, cpu, 0);
Jeremy Kerrfc59a3f2009-03-11 17:55:52 +000090}
91
92static inline long register_dtl(unsigned long cpu, unsigned long vpa)
93{
94 return vpa_call(0x2, cpu, vpa);
95}
96
Brian King86630a32008-07-24 04:29:16 +100097static inline long plpar_page_set_loaned(unsigned long vpa)
98{
Brian King370e4582008-08-16 05:09:33 +100099 unsigned long cmo_page_sz = cmo_get_page_size();
100 long rc = 0;
101 int i;
102
103 for (i = 0; !rc && i < PAGE_SIZE; i += cmo_page_sz)
104 rc = plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_LOANED, vpa + i, 0);
105
106 for (i -= cmo_page_sz; rc && i != 0; i -= cmo_page_sz)
107 plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_ACTIVE,
108 vpa + i - cmo_page_sz, 0);
109
110 return rc;
Brian King86630a32008-07-24 04:29:16 +1000111}
112
113static inline long plpar_page_set_active(unsigned long vpa)
114{
Brian King370e4582008-08-16 05:09:33 +1000115 unsigned long cmo_page_sz = cmo_get_page_size();
116 long rc = 0;
117 int i;
118
119 for (i = 0; !rc && i < PAGE_SIZE; i += cmo_page_sz)
120 rc = plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_ACTIVE, vpa + i, 0);
121
122 for (i -= cmo_page_sz; rc && i != 0; i -= cmo_page_sz)
123 plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_LOANED,
124 vpa + i - cmo_page_sz, 0);
125
126 return rc;
Brian King86630a32008-07-24 04:29:16 +1000127}
128
Michael Ellerman40765d22005-11-03 19:34:38 +1100129extern void vpa_init(int cpu);
Michael Ellermana1218722005-11-03 15:33:31 +1100130
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000131static inline long plpar_pte_enter(unsigned long flags,
132 unsigned long hpte_group, unsigned long hpte_v,
133 unsigned long hpte_r, unsigned long *slot)
134{
135 long rc;
136 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
137
138 rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r);
139
140 *slot = retbuf[0];
141
142 return rc;
143}
144
Michael Ellermana1218722005-11-03 15:33:31 +1100145static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex,
146 unsigned long avpn, unsigned long *old_pteh_ret,
147 unsigned long *old_ptel_ret)
148{
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000149 long rc;
150 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
151
152 rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn);
153
154 *old_pteh_ret = retbuf[0];
155 *old_ptel_ret = retbuf[1];
156
157 return rc;
Michael Ellermana1218722005-11-03 15:33:31 +1100158}
159
Mohan Kumar Mb4aea362007-03-21 11:21:32 +0530160/* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */
161static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex,
162 unsigned long avpn, unsigned long *old_pteh_ret,
163 unsigned long *old_ptel_ret)
164{
165 long rc;
166 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
167
168 rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn);
169
170 *old_pteh_ret = retbuf[0];
171 *old_ptel_ret = retbuf[1];
172
173 return rc;
174}
175
Michael Ellermana1218722005-11-03 15:33:31 +1100176static inline long plpar_pte_read(unsigned long flags, unsigned long ptex,
177 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
178{
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000179 long rc;
180 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
181
182 rc = plpar_hcall(H_READ, retbuf, flags, ptex);
183
184 *old_pteh_ret = retbuf[0];
185 *old_ptel_ret = retbuf[1];
186
187 return rc;
Michael Ellermana1218722005-11-03 15:33:31 +1100188}
189
Sachin P. Santb7abc5c2007-06-14 15:31:34 +1000190/* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */
191static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex,
192 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
193{
194 long rc;
195 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
196
197 rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex);
198
199 *old_pteh_ret = retbuf[0];
200 *old_ptel_ret = retbuf[1];
201
202 return rc;
203}
204
Michael Neulingf90ece22010-05-10 20:28:26 +0000205/*
206 * plpar_pte_read_4_raw can be called in real mode.
207 * ptes must be 8*sizeof(unsigned long)
208 */
209static inline long plpar_pte_read_4_raw(unsigned long flags, unsigned long ptex,
210 unsigned long *ptes)
211
212{
213 long rc;
214 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
215
216 rc = plpar_hcall9_raw(H_READ, retbuf, flags | H_READ_4, ptex);
217
218 memcpy(ptes, retbuf, 8*sizeof(unsigned long));
219
220 return rc;
221}
222
Michael Ellermana1218722005-11-03 15:33:31 +1100223static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex,
224 unsigned long avpn)
225{
226 return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn);
227}
228
229static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba,
230 unsigned long *tce_ret)
231{
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000232 long rc;
233 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
234
235 rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba);
236
237 *tce_ret = retbuf[0];
238
239 return rc;
Michael Ellermana1218722005-11-03 15:33:31 +1100240}
241
242static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba,
243 unsigned long tceval)
244{
245 return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval);
246}
247
248static inline long plpar_tce_put_indirect(unsigned long liobn,
249 unsigned long ioba, unsigned long page, unsigned long count)
250{
251 return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count);
252}
253
254static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba,
255 unsigned long tceval, unsigned long count)
256{
257 return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count);
258}
259
260static inline long plpar_get_term_char(unsigned long termno,
261 unsigned long *len_ret, char *buf_ret)
262{
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000263 long rc;
264 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
Michael Ellermana1218722005-11-03 15:33:31 +1100265 unsigned long *lbuf = (unsigned long *)buf_ret; /* TODO: alignment? */
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000266
267 rc = plpar_hcall(H_GET_TERM_CHAR, retbuf, termno);
268
269 *len_ret = retbuf[0];
270 lbuf[0] = retbuf[1];
271 lbuf[1] = retbuf[2];
272
273 return rc;
Michael Ellermana1218722005-11-03 15:33:31 +1100274}
275
276static inline long plpar_put_term_char(unsigned long termno, unsigned long len,
277 const char *buffer)
278{
279 unsigned long *lbuf = (unsigned long *)buffer; /* TODO: alignment? */
280 return plpar_hcall_norets(H_PUT_TERM_CHAR, termno, len, lbuf[0],
281 lbuf[1]);
282}
283
Ian Munsied8f48ec2012-11-06 16:15:17 +1100284/* Set various resource mode parameters */
285static inline long plpar_set_mode(unsigned long mflags, unsigned long resource,
286 unsigned long value1, unsigned long value2)
287{
288 return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2);
289}
Ian Munsie798042d2012-11-08 15:57:04 +1100290
291/*
292 * Enable relocation on exceptions on this partition
293 *
294 * Note: this call has a partition wide scope and can take a while to complete.
295 * If it returns H_LONG_BUSY_* it should be retried periodically until it
296 * returns H_SUCCESS.
297 */
298static inline long enable_reloc_on_exceptions(void)
299{
300 /* mflags = 3: Exceptions at 0xC000000000004000 */
301 return plpar_set_mode(3, 3, 0, 0);
302}
303
304/*
305 * Disable relocation on exceptions on this partition
306 *
307 * Note: this call has a partition wide scope and can take a while to complete.
308 * If it returns H_LONG_BUSY_* it should be retried periodically until it
309 * returns H_SUCCESS.
310 */
311static inline long disable_reloc_on_exceptions(void) {
312 return plpar_set_mode(0, 3, 0, 0);
313}
314
Michael Ellermana1218722005-11-03 15:33:31 +1100315#endif /* _PSERIES_PLPAR_WRAPPERS_H */