Linux 4.13.16
[linux/fpc-iii.git] / arch / powerpc / include / asm / plpar_wrappers.h
blobc7b164836bc37739a05662a5881bf31ff243576e
1 #ifndef _ASM_POWERPC_PLPAR_WRAPPERS_H
2 #define _ASM_POWERPC_PLPAR_WRAPPERS_H
4 #include <linux/string.h>
5 #include <linux/irqflags.h>
7 #include <asm/hvcall.h>
8 #include <asm/paca.h>
9 #include <asm/page.h>
11 /* Get state of physical CPU from query_cpu_stopped */
12 int 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
19 static inline long poll_pending(void)
21 return plpar_hcall_norets(H_POLL_PENDING);
24 static inline u8 get_cede_latency_hint(void)
26 return get_lppaca()->cede_latency_hint;
29 static inline void set_cede_latency_hint(u8 latency_hint)
31 get_lppaca()->cede_latency_hint = latency_hint;
34 static inline long cede_processor(void)
36 return plpar_hcall_norets(H_CEDE);
39 static inline long extended_cede_processor(unsigned long latency_hint)
41 long rc;
42 u8 old_latency_hint = get_cede_latency_hint();
44 set_cede_latency_hint(latency_hint);
46 rc = cede_processor();
47 #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
53 set_cede_latency_hint(old_latency_hint);
55 return rc;
58 static inline long vpa_call(unsigned long flags, unsigned long cpu,
59 unsigned long vpa)
61 flags = flags << H_VPA_FUNC_SHIFT;
63 return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa);
66 static inline long unregister_vpa(unsigned long cpu)
68 return vpa_call(H_VPA_DEREG_VPA, cpu, 0);
71 static inline long register_vpa(unsigned long cpu, unsigned long vpa)
73 return vpa_call(H_VPA_REG_VPA, cpu, vpa);
76 static inline long unregister_slb_shadow(unsigned long cpu)
78 return vpa_call(H_VPA_DEREG_SLB, cpu, 0);
81 static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa)
83 return vpa_call(H_VPA_REG_SLB, cpu, vpa);
86 static inline long unregister_dtl(unsigned long cpu)
88 return vpa_call(H_VPA_DEREG_DTL, cpu, 0);
91 static inline long register_dtl(unsigned long cpu, unsigned long vpa)
93 return vpa_call(H_VPA_REG_DTL, cpu, vpa);
96 extern void vpa_init(int cpu);
98 static 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)
102 long rc;
103 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
105 rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r);
107 *slot = retbuf[0];
109 return rc;
112 static 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)
116 long rc;
117 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
119 rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn);
121 *old_pteh_ret = retbuf[0];
122 *old_ptel_ret = retbuf[1];
124 return rc;
127 /* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */
128 static 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)
132 long rc;
133 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
135 rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn);
137 *old_pteh_ret = retbuf[0];
138 *old_ptel_ret = retbuf[1];
140 return rc;
143 static inline long plpar_pte_read(unsigned long flags, unsigned long ptex,
144 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
146 long rc;
147 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
149 rc = plpar_hcall(H_READ, retbuf, flags, ptex);
151 *old_pteh_ret = retbuf[0];
152 *old_ptel_ret = retbuf[1];
154 return rc;
157 /* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */
158 static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex,
159 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
161 long rc;
162 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
164 rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex);
166 *old_pteh_ret = retbuf[0];
167 *old_ptel_ret = retbuf[1];
169 return rc;
173 * ptes must be 8*sizeof(unsigned long)
175 static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex,
176 unsigned long *ptes)
179 long rc;
180 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
182 rc = plpar_hcall9(H_READ, retbuf, flags | H_READ_4, ptex);
184 memcpy(ptes, retbuf, 8*sizeof(unsigned long));
186 return rc;
190 * plpar_pte_read_4_raw can be called in real mode.
191 * ptes must be 8*sizeof(unsigned long)
193 static inline long plpar_pte_read_4_raw(unsigned long flags, unsigned long ptex,
194 unsigned long *ptes)
197 long rc;
198 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
200 rc = plpar_hcall9_raw(H_READ, retbuf, flags | H_READ_4, ptex);
202 memcpy(ptes, retbuf, 8*sizeof(unsigned long));
204 return rc;
207 static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex,
208 unsigned long avpn)
210 return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn);
213 static inline long plpar_resize_hpt_prepare(unsigned long flags,
214 unsigned long shift)
216 return plpar_hcall_norets(H_RESIZE_HPT_PREPARE, flags, shift);
219 static inline long plpar_resize_hpt_commit(unsigned long flags,
220 unsigned long shift)
222 return plpar_hcall_norets(H_RESIZE_HPT_COMMIT, flags, shift);
225 static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba,
226 unsigned long *tce_ret)
228 long rc;
229 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
231 rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba);
233 *tce_ret = retbuf[0];
235 return rc;
238 static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba,
239 unsigned long tceval)
241 return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval);
244 static inline long plpar_tce_put_indirect(unsigned long liobn,
245 unsigned long ioba, unsigned long page, unsigned long count)
247 return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count);
250 static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba,
251 unsigned long tceval, unsigned long count)
253 return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count);
256 /* Set various resource mode parameters */
257 static inline long plpar_set_mode(unsigned long mflags, unsigned long resource,
258 unsigned long value1, unsigned long value2)
260 return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2);
264 * Enable relocation on exceptions on this partition
266 * Note: this call has a partition wide scope and can take a while to complete.
267 * If it returns H_LONG_BUSY_* it should be retried periodically until it
268 * returns H_SUCCESS.
270 static inline long enable_reloc_on_exceptions(void)
272 /* mflags = 3: Exceptions at 0xC000000000004000 */
273 return plpar_set_mode(3, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0);
277 * Disable relocation on exceptions on this partition
279 * Note: this call has a partition wide scope and can take a while to complete.
280 * If it returns H_LONG_BUSY_* it should be retried periodically until it
281 * returns H_SUCCESS.
283 static inline long disable_reloc_on_exceptions(void) {
284 return plpar_set_mode(0, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0);
288 * Take exceptions in big endian mode on this partition
290 * Note: this call has a partition wide scope and can take a while to complete.
291 * If it returns H_LONG_BUSY_* it should be retried periodically until it
292 * returns H_SUCCESS.
294 static inline long enable_big_endian_exceptions(void)
296 /* mflags = 0: big endian exceptions */
297 return plpar_set_mode(0, H_SET_MODE_RESOURCE_LE, 0, 0);
301 * Take exceptions in little endian mode on this partition
303 * Note: this call has a partition wide scope and can take a while to complete.
304 * If it returns H_LONG_BUSY_* it should be retried periodically until it
305 * returns H_SUCCESS.
307 static inline long enable_little_endian_exceptions(void)
309 /* mflags = 1: little endian exceptions */
310 return plpar_set_mode(1, H_SET_MODE_RESOURCE_LE, 0, 0);
313 static inline long plapr_set_ciabr(unsigned long ciabr)
315 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_CIABR, ciabr, 0);
318 static inline long plapr_set_watchpoint0(unsigned long dawr0, unsigned long dawrx0)
320 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR, dawr0, dawrx0);
323 static inline long plapr_signal_sys_reset(long cpu)
325 return plpar_hcall_norets(H_SIGNAL_SYS_RESET, cpu);
328 #endif /* _ASM_POWERPC_PLPAR_WRAPPERS_H */