blob: 0bcc75e295e317fbcb64e495e62e9b010c8f804c [file] [log] [blame]
Deepthi Dharwar212bebb2013-08-22 15:23:52 +05301#ifndef _ASM_POWERPC_PLPAR_WRAPPERS_H
2#define _ASM_POWERPC_PLPAR_WRAPPERS_H
Michael Ellermana1218722005-11-03 15:33:31 +11003
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{
Li Zhongbb18b3a2013-01-24 22:12:21 +000061 flags = flags << H_VPA_FUNC_SHIFT;
Michael Ellerman40765d22005-11-03 19:34:38 +110062
63 return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa);
Michael Ellermana1218722005-11-03 15:33:31 +110064}
65
Anton Blanchard598c8232011-07-25 01:46:34 +000066static inline long unregister_vpa(unsigned long cpu)
Michael Ellerman40765d22005-11-03 19:34:38 +110067{
Li Zhongbb18b3a2013-01-24 22:12:21 +000068 return vpa_call(H_VPA_DEREG_VPA, cpu, 0);
Michael Ellerman40765d22005-11-03 19:34:38 +110069}
70
71static inline long register_vpa(unsigned long cpu, unsigned long vpa)
72{
Li Zhongbb18b3a2013-01-24 22:12:21 +000073 return vpa_call(H_VPA_REG_VPA, cpu, vpa);
Michael Ellerman40765d22005-11-03 19:34:38 +110074}
75
Anton Blanchard598c8232011-07-25 01:46:34 +000076static inline long unregister_slb_shadow(unsigned long cpu)
Michael Neuling2f6093c2006-08-07 16:19:19 +100077{
Li Zhongbb18b3a2013-01-24 22:12:21 +000078 return vpa_call(H_VPA_DEREG_SLB, cpu, 0);
Michael Neuling2f6093c2006-08-07 16:19:19 +100079}
80
81static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa)
82{
Li Zhongbb18b3a2013-01-24 22:12:21 +000083 return vpa_call(H_VPA_REG_SLB, cpu, vpa);
Michael Neuling2f6093c2006-08-07 16:19:19 +100084}
85
Anton Blanchardb1301792011-07-25 01:46:32 +000086static inline long unregister_dtl(unsigned long cpu)
Jeremy Kerrfc59a3f2009-03-11 17:55:52 +000087{
Li Zhongbb18b3a2013-01-24 22:12:21 +000088 return vpa_call(H_VPA_DEREG_DTL, cpu, 0);
Jeremy Kerrfc59a3f2009-03-11 17:55:52 +000089}
90
91static inline long register_dtl(unsigned long cpu, unsigned long vpa)
92{
Li Zhongbb18b3a2013-01-24 22:12:21 +000093 return vpa_call(H_VPA_REG_DTL, cpu, vpa);
Jeremy Kerrfc59a3f2009-03-11 17:55:52 +000094}
95
Michael Ellerman40765d22005-11-03 19:34:38 +110096extern void vpa_init(int cpu);
Michael Ellermana1218722005-11-03 15:33:31 +110097
Anton Blanchardb9377ff2006-07-19 08:01:28 +100098static inline long plpar_pte_enter(unsigned long flags,
99 unsigned long hpte_group, unsigned long hpte_v,
100 unsigned long hpte_r, unsigned long *slot)
101{
102 long rc;
103 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
104
105 rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r);
106
107 *slot = retbuf[0];
108
109 return rc;
110}
111
Michael Ellermana1218722005-11-03 15:33:31 +1100112static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex,
113 unsigned long avpn, unsigned long *old_pteh_ret,
114 unsigned long *old_ptel_ret)
115{
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000116 long rc;
117 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
118
119 rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn);
120
121 *old_pteh_ret = retbuf[0];
122 *old_ptel_ret = retbuf[1];
123
124 return rc;
Michael Ellermana1218722005-11-03 15:33:31 +1100125}
126
Mohan Kumar Mb4aea362007-03-21 11:21:32 +0530127/* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */
128static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex,
129 unsigned long avpn, unsigned long *old_pteh_ret,
130 unsigned long *old_ptel_ret)
131{
132 long rc;
133 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
134
135 rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn);
136
137 *old_pteh_ret = retbuf[0];
138 *old_ptel_ret = retbuf[1];
139
140 return rc;
141}
142
Michael Ellermana1218722005-11-03 15:33:31 +1100143static inline long plpar_pte_read(unsigned long flags, unsigned long ptex,
144 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
145{
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000146 long rc;
147 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
148
149 rc = plpar_hcall(H_READ, retbuf, flags, ptex);
150
151 *old_pteh_ret = retbuf[0];
152 *old_ptel_ret = retbuf[1];
153
154 return rc;
Michael Ellermana1218722005-11-03 15:33:31 +1100155}
156
Sachin P. Santb7abc5c2007-06-14 15:31:34 +1000157/* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */
158static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex,
159 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
160{
161 long rc;
162 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
163
164 rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex);
165
166 *old_pteh_ret = retbuf[0];
167 *old_ptel_ret = retbuf[1];
168
169 return rc;
170}
171
Michael Neulingf90ece22010-05-10 20:28:26 +0000172/*
Aneesh Kumar K.V4ad90c82015-12-01 09:06:59 +0530173 * ptes must be 8*sizeof(unsigned long)
174 */
175static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex,
176 unsigned long *ptes)
177
178{
179 long rc;
180 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
181
182 rc = plpar_hcall9(H_READ, retbuf, flags | H_READ_4, ptex);
183
184 memcpy(ptes, retbuf, 8*sizeof(unsigned long));
185
186 return rc;
187}
188
189/*
Michael Neulingf90ece22010-05-10 20:28:26 +0000190 * plpar_pte_read_4_raw can be called in real mode.
191 * ptes must be 8*sizeof(unsigned long)
192 */
193static inline long plpar_pte_read_4_raw(unsigned long flags, unsigned long ptex,
194 unsigned long *ptes)
195
196{
197 long rc;
198 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
199
200 rc = plpar_hcall9_raw(H_READ, retbuf, flags | H_READ_4, ptex);
201
202 memcpy(ptes, retbuf, 8*sizeof(unsigned long));
203
204 return rc;
205}
206
Michael Ellermana1218722005-11-03 15:33:31 +1100207static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex,
208 unsigned long avpn)
209{
210 return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn);
211}
212
213static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba,
214 unsigned long *tce_ret)
215{
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000216 long rc;
217 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
218
219 rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba);
220
221 *tce_ret = retbuf[0];
222
223 return rc;
Michael Ellermana1218722005-11-03 15:33:31 +1100224}
225
226static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba,
227 unsigned long tceval)
228{
229 return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval);
230}
231
232static inline long plpar_tce_put_indirect(unsigned long liobn,
233 unsigned long ioba, unsigned long page, unsigned long count)
234{
235 return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count);
236}
237
238static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba,
239 unsigned long tceval, unsigned long count)
240{
241 return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count);
242}
243
Ian Munsied8f48ec2012-11-06 16:15:17 +1100244/* Set various resource mode parameters */
245static inline long plpar_set_mode(unsigned long mflags, unsigned long resource,
246 unsigned long value1, unsigned long value2)
247{
248 return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2);
249}
Ian Munsie798042d2012-11-08 15:57:04 +1100250
251/*
252 * Enable relocation on exceptions on this partition
253 *
254 * Note: this call has a partition wide scope and can take a while to complete.
255 * If it returns H_LONG_BUSY_* it should be retried periodically until it
256 * returns H_SUCCESS.
257 */
258static inline long enable_reloc_on_exceptions(void)
259{
260 /* mflags = 3: Exceptions at 0xC000000000004000 */
Michael Neuling60666de2014-05-29 17:45:47 +1000261 return plpar_set_mode(3, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0);
Ian Munsie798042d2012-11-08 15:57:04 +1100262}
263
264/*
265 * Disable relocation on exceptions on this partition
266 *
267 * Note: this call has a partition wide scope and can take a while to complete.
268 * If it returns H_LONG_BUSY_* it should be retried periodically until it
269 * returns H_SUCCESS.
270 */
271static inline long disable_reloc_on_exceptions(void) {
Michael Neuling60666de2014-05-29 17:45:47 +1000272 return plpar_set_mode(0, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0);
Ian Munsie798042d2012-11-08 15:57:04 +1100273}
274
Anton Blancharde844b1e2013-11-20 22:14:59 +1100275/*
276 * Take exceptions in big endian mode on this partition
277 *
278 * Note: this call has a partition wide scope and can take a while to complete.
279 * If it returns H_LONG_BUSY_* it should be retried periodically until it
280 * returns H_SUCCESS.
281 */
282static inline long enable_big_endian_exceptions(void)
283{
284 /* mflags = 0: big endian exceptions */
Michael Neuling60666de2014-05-29 17:45:47 +1000285 return plpar_set_mode(0, H_SET_MODE_RESOURCE_LE, 0, 0);
Anton Blancharde844b1e2013-11-20 22:14:59 +1100286}
287
288/*
289 * Take exceptions in little endian mode on this partition
290 *
291 * Note: this call has a partition wide scope and can take a while to complete.
292 * If it returns H_LONG_BUSY_* it should be retried periodically until it
293 * returns H_SUCCESS.
294 */
295static inline long enable_little_endian_exceptions(void)
296{
297 /* mflags = 1: little endian exceptions */
Michael Neuling60666de2014-05-29 17:45:47 +1000298 return plpar_set_mode(1, H_SET_MODE_RESOURCE_LE, 0, 0);
Anton Blancharde844b1e2013-11-20 22:14:59 +1100299}
300
Ian Munsie376a8642012-12-20 14:06:41 +0000301static inline long plapr_set_ciabr(unsigned long ciabr)
302{
Michael Neuling60666de2014-05-29 17:45:47 +1000303 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_CIABR, ciabr, 0);
Ian Munsie376a8642012-12-20 14:06:41 +0000304}
305
306static inline long plapr_set_watchpoint0(unsigned long dawr0, unsigned long dawrx0)
307{
Michael Neuling60666de2014-05-29 17:45:47 +1000308 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR, dawr0, dawrx0);
Ian Munsie376a8642012-12-20 14:06:41 +0000309}
310
Nicholas Piggin53ce2992016-11-08 17:08:06 +1100311static inline long plapr_signal_sys_reset(long cpu)
312{
313 return plpar_hcall_norets(H_SIGNAL_SYS_RESET, cpu);
314}
315
Deepthi Dharwar212bebb2013-08-22 15:23:52 +0530316#endif /* _ASM_POWERPC_PLPAR_WRAPPERS_H */