1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_PLPAR_WRAPPERS_H
3 #define _ASM_POWERPC_PLPAR_WRAPPERS_H
5 #ifdef CONFIG_PPC_PSERIES
7 #include <linux/string.h>
8 #include <linux/irqflags.h>
10 #include <asm/hvcall.h>
14 static inline long poll_pending(void)
16 return plpar_hcall_norets(H_POLL_PENDING);
19 static inline u8 get_cede_latency_hint(void)
21 return get_lppaca()->cede_latency_hint;
24 static inline void set_cede_latency_hint(u8 latency_hint)
26 get_lppaca()->cede_latency_hint = latency_hint;
29 static inline long cede_processor(void)
32 * We cannot call tracepoints inside RCU idle regions which
33 * means we must not trace H_CEDE.
35 return plpar_hcall_norets_notrace(H_CEDE);
38 static inline long extended_cede_processor(unsigned long latency_hint)
41 u8 old_latency_hint = get_cede_latency_hint();
43 set_cede_latency_hint(latency_hint);
45 rc = cede_processor();
47 /* Ensure that H_CEDE returns with IRQs on */
48 if (WARN_ON(IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG) && !(mfmsr() & MSR_EE)))
51 set_cede_latency_hint(old_latency_hint);
56 static inline long vpa_call(unsigned long flags, unsigned long cpu,
59 flags = flags << H_VPA_FUNC_SHIFT;
61 return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa);
64 static inline long unregister_vpa(unsigned long cpu)
66 return vpa_call(H_VPA_DEREG_VPA, cpu, 0);
69 static inline long register_vpa(unsigned long cpu, unsigned long vpa)
71 return vpa_call(H_VPA_REG_VPA, cpu, vpa);
74 static inline long unregister_slb_shadow(unsigned long cpu)
76 return vpa_call(H_VPA_DEREG_SLB, cpu, 0);
79 static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa)
81 return vpa_call(H_VPA_REG_SLB, cpu, vpa);
84 static inline long unregister_dtl(unsigned long cpu)
86 return vpa_call(H_VPA_DEREG_DTL, cpu, 0);
89 static inline long register_dtl(unsigned long cpu, unsigned long vpa)
91 return vpa_call(H_VPA_REG_DTL, cpu, vpa);
94 extern void vpa_init(int cpu);
96 static inline long plpar_pte_enter(unsigned long flags,
97 unsigned long hpte_group, unsigned long hpte_v,
98 unsigned long hpte_r, unsigned long *slot)
101 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
103 rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r);
110 static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex,
111 unsigned long avpn, unsigned long *old_pteh_ret,
112 unsigned long *old_ptel_ret)
115 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
117 rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn);
119 *old_pteh_ret = retbuf[0];
120 *old_ptel_ret = retbuf[1];
125 /* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */
126 static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex,
127 unsigned long avpn, unsigned long *old_pteh_ret,
128 unsigned long *old_ptel_ret)
131 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
133 rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn);
135 *old_pteh_ret = retbuf[0];
136 *old_ptel_ret = retbuf[1];
141 static inline long plpar_pte_read(unsigned long flags, unsigned long ptex,
142 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
145 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
147 rc = plpar_hcall(H_READ, retbuf, flags, ptex);
149 *old_pteh_ret = retbuf[0];
150 *old_ptel_ret = retbuf[1];
155 /* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */
156 static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex,
157 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
160 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
162 rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex);
164 *old_pteh_ret = retbuf[0];
165 *old_ptel_ret = retbuf[1];
171 * ptes must be 8*sizeof(unsigned long)
173 static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex,
178 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
180 rc = plpar_hcall9(H_READ, retbuf, flags | H_READ_4, ptex);
182 memcpy(ptes, retbuf, 8*sizeof(unsigned long));
188 * plpar_pte_read_4_raw can be called in real mode.
189 * ptes must be 8*sizeof(unsigned long)
191 static inline long plpar_pte_read_4_raw(unsigned long flags, unsigned long ptex,
196 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
198 rc = plpar_hcall9_raw(H_READ, retbuf, flags | H_READ_4, ptex);
200 memcpy(ptes, retbuf, 8*sizeof(unsigned long));
205 static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex,
208 return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn);
211 static inline long plpar_resize_hpt_prepare(unsigned long flags,
214 return plpar_hcall_norets(H_RESIZE_HPT_PREPARE, flags, shift);
217 static inline long plpar_resize_hpt_commit(unsigned long flags,
220 return plpar_hcall_norets(H_RESIZE_HPT_COMMIT, flags, shift);
223 static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba,
224 unsigned long *tce_ret)
227 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
229 rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba);
231 *tce_ret = retbuf[0];
236 static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba,
237 unsigned long tceval)
239 return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval);
242 static inline long plpar_tce_put_indirect(unsigned long liobn,
243 unsigned long ioba, unsigned long page, unsigned long count)
245 return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count);
248 static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba,
249 unsigned long tceval, unsigned long count)
251 return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count);
254 /* Set various resource mode parameters */
255 static inline long plpar_set_mode(unsigned long mflags, unsigned long resource,
256 unsigned long value1, unsigned long value2)
258 return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2);
262 * Enable relocation on exceptions on this partition
264 * Note: this call has a partition wide scope and can take a while to complete.
265 * If it returns H_LONG_BUSY_* it should be retried periodically until it
268 static inline long enable_reloc_on_exceptions(void)
270 /* mflags = 3: Exceptions at 0xC000000000004000 */
271 return plpar_set_mode(3, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0);
275 * Disable relocation on exceptions on this partition
277 * Note: this call has a partition wide scope and can take a while to complete.
278 * If it returns H_LONG_BUSY_* it should be retried periodically until it
281 static inline long disable_reloc_on_exceptions(void) {
282 return plpar_set_mode(0, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0);
286 * Take exceptions in big endian mode on this partition
288 * Note: this call has a partition wide scope and can take a while to complete.
289 * If it returns H_LONG_BUSY_* it should be retried periodically until it
292 static inline long enable_big_endian_exceptions(void)
294 /* mflags = 0: big endian exceptions */
295 return plpar_set_mode(0, H_SET_MODE_RESOURCE_LE, 0, 0);
299 * Take exceptions in little endian mode on this partition
301 * Note: this call has a partition wide scope and can take a while to complete.
302 * If it returns H_LONG_BUSY_* it should be retried periodically until it
305 static inline long enable_little_endian_exceptions(void)
307 /* mflags = 1: little endian exceptions */
308 return plpar_set_mode(1, H_SET_MODE_RESOURCE_LE, 0, 0);
311 static inline long plpar_set_ciabr(unsigned long ciabr)
313 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_CIABR, ciabr, 0);
316 static inline long plpar_set_watchpoint0(unsigned long dawr0, unsigned long dawrx0)
318 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR0, dawr0, dawrx0);
321 static inline long plpar_set_watchpoint1(unsigned long dawr1, unsigned long dawrx1)
323 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR1, dawr1, dawrx1);
326 static inline long plpar_signal_sys_reset(long cpu)
328 return plpar_hcall_norets(H_SIGNAL_SYS_RESET, cpu);
331 static inline long plpar_get_cpu_characteristics(struct h_cpu_char_result *p)
333 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
336 rc = plpar_hcall(H_GET_CPU_CHARACTERISTICS, retbuf);
337 if (rc == H_SUCCESS) {
338 p->character = retbuf[0];
339 p->behaviour = retbuf[1];
346 * Wrapper to H_RPT_INVALIDATE hcall that handles return values appropriately
348 * - Returns H_SUCCESS on success
349 * - For H_BUSY return value, we retry the hcall.
350 * - For any other hcall failures, attempt a full flush once before
351 * resorting to BUG().
353 * Note: This hcall is expected to fail only very rarely. The correct
354 * error recovery of killing the process/guest will be eventually
357 static inline long pseries_rpt_invalidate(u32 pid, u64 target, u64 type,
358 u64 page_sizes, u64 start, u64 end)
364 rc = plpar_hcall_norets(H_RPT_INVALIDATE, pid, target, type,
365 page_sizes, start, end);
369 } else if (rc == H_SUCCESS)
372 /* Flush request failed, try with a full flush once */
373 if (type & H_RPTI_TYPE_NESTED)
374 all = H_RPTI_TYPE_NESTED | H_RPTI_TYPE_NESTED_ALL;
376 all = H_RPTI_TYPE_ALL;
378 rc = plpar_hcall_norets(H_RPT_INVALIDATE, pid, target,
379 all, page_sizes, 0, -1UL);
383 } else if (rc == H_SUCCESS)
390 #else /* !CONFIG_PPC_PSERIES */
392 static inline long plpar_set_ciabr(unsigned long ciabr)
397 static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex,
403 static inline long pseries_rpt_invalidate(u32 pid, u64 target, u64 type,
404 u64 page_sizes, u64 start, u64 end)
409 #endif /* CONFIG_PPC_PSERIES */
411 #endif /* _ASM_POWERPC_PLPAR_WRAPPERS_H */