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();
46 #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
47 /* Ensure that H_CEDE returns with IRQs on */
48 if (WARN_ON(!(mfmsr() & MSR_EE)))
52 set_cede_latency_hint(old_latency_hint);
57 static inline long vpa_call(unsigned long flags, unsigned long cpu,
60 flags = flags << H_VPA_FUNC_SHIFT;
62 return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa);
65 static inline long unregister_vpa(unsigned long cpu)
67 return vpa_call(H_VPA_DEREG_VPA, cpu, 0);
70 static inline long register_vpa(unsigned long cpu, unsigned long vpa)
72 return vpa_call(H_VPA_REG_VPA, cpu, vpa);
75 static inline long unregister_slb_shadow(unsigned long cpu)
77 return vpa_call(H_VPA_DEREG_SLB, cpu, 0);
80 static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa)
82 return vpa_call(H_VPA_REG_SLB, cpu, vpa);
85 static inline long unregister_dtl(unsigned long cpu)
87 return vpa_call(H_VPA_DEREG_DTL, cpu, 0);
90 static inline long register_dtl(unsigned long cpu, unsigned long vpa)
92 return vpa_call(H_VPA_REG_DTL, cpu, vpa);
95 extern void vpa_init(int cpu);
97 static inline long plpar_pte_enter(unsigned long flags,
98 unsigned long hpte_group, unsigned long hpte_v,
99 unsigned long hpte_r, unsigned long *slot)
102 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
104 rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r);
111 static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex,
112 unsigned long avpn, unsigned long *old_pteh_ret,
113 unsigned long *old_ptel_ret)
116 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
118 rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn);
120 *old_pteh_ret = retbuf[0];
121 *old_ptel_ret = retbuf[1];
126 /* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */
127 static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex,
128 unsigned long avpn, unsigned long *old_pteh_ret,
129 unsigned long *old_ptel_ret)
132 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
134 rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn);
136 *old_pteh_ret = retbuf[0];
137 *old_ptel_ret = retbuf[1];
142 static inline long plpar_pte_read(unsigned long flags, unsigned long ptex,
143 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
146 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
148 rc = plpar_hcall(H_READ, retbuf, flags, ptex);
150 *old_pteh_ret = retbuf[0];
151 *old_ptel_ret = retbuf[1];
156 /* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */
157 static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex,
158 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
161 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
163 rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex);
165 *old_pteh_ret = retbuf[0];
166 *old_ptel_ret = retbuf[1];
172 * ptes must be 8*sizeof(unsigned long)
174 static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex,
179 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
181 rc = plpar_hcall9(H_READ, retbuf, flags | H_READ_4, ptex);
183 memcpy(ptes, retbuf, 8*sizeof(unsigned long));
189 * plpar_pte_read_4_raw can be called in real mode.
190 * ptes must be 8*sizeof(unsigned long)
192 static inline long plpar_pte_read_4_raw(unsigned long flags, unsigned long ptex,
197 unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
199 rc = plpar_hcall9_raw(H_READ, retbuf, flags | H_READ_4, ptex);
201 memcpy(ptes, retbuf, 8*sizeof(unsigned long));
206 static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex,
209 return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn);
212 static inline long plpar_resize_hpt_prepare(unsigned long flags,
215 return plpar_hcall_norets(H_RESIZE_HPT_PREPARE, flags, shift);
218 static inline long plpar_resize_hpt_commit(unsigned long flags,
221 return plpar_hcall_norets(H_RESIZE_HPT_COMMIT, flags, shift);
224 static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba,
225 unsigned long *tce_ret)
228 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
230 rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba);
232 *tce_ret = retbuf[0];
237 static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba,
238 unsigned long tceval)
240 return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval);
243 static inline long plpar_tce_put_indirect(unsigned long liobn,
244 unsigned long ioba, unsigned long page, unsigned long count)
246 return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count);
249 static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba,
250 unsigned long tceval, unsigned long count)
252 return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count);
255 /* Set various resource mode parameters */
256 static inline long plpar_set_mode(unsigned long mflags, unsigned long resource,
257 unsigned long value1, unsigned long value2)
259 return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2);
263 * Enable relocation on exceptions on this partition
265 * Note: this call has a partition wide scope and can take a while to complete.
266 * If it returns H_LONG_BUSY_* it should be retried periodically until it
269 static inline long enable_reloc_on_exceptions(void)
271 /* mflags = 3: Exceptions at 0xC000000000004000 */
272 return plpar_set_mode(3, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0);
276 * Disable relocation on exceptions on this partition
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
282 static inline long disable_reloc_on_exceptions(void) {
283 return plpar_set_mode(0, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0);
287 * Take exceptions in big endian mode on this partition
289 * Note: this call has a partition wide scope and can take a while to complete.
290 * If it returns H_LONG_BUSY_* it should be retried periodically until it
293 static inline long enable_big_endian_exceptions(void)
295 /* mflags = 0: big endian exceptions */
296 return plpar_set_mode(0, H_SET_MODE_RESOURCE_LE, 0, 0);
300 * Take exceptions in little endian mode on this partition
302 * Note: this call has a partition wide scope and can take a while to complete.
303 * If it returns H_LONG_BUSY_* it should be retried periodically until it
306 static inline long enable_little_endian_exceptions(void)
308 /* mflags = 1: little endian exceptions */
309 return plpar_set_mode(1, H_SET_MODE_RESOURCE_LE, 0, 0);
312 static inline long plpar_set_ciabr(unsigned long ciabr)
314 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_CIABR, ciabr, 0);
317 static inline long plpar_set_watchpoint0(unsigned long dawr0, unsigned long dawrx0)
319 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR0, dawr0, dawrx0);
322 static inline long plpar_set_watchpoint1(unsigned long dawr1, unsigned long dawrx1)
324 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR1, dawr1, dawrx1);
327 static inline long plpar_signal_sys_reset(long cpu)
329 return plpar_hcall_norets(H_SIGNAL_SYS_RESET, cpu);
332 static inline long plpar_get_cpu_characteristics(struct h_cpu_char_result *p)
334 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
337 rc = plpar_hcall(H_GET_CPU_CHARACTERISTICS, retbuf);
338 if (rc == H_SUCCESS) {
339 p->character = retbuf[0];
340 p->behaviour = retbuf[1];
347 * Wrapper to H_RPT_INVALIDATE hcall that handles return values appropriately
349 * - Returns H_SUCCESS on success
350 * - For H_BUSY return value, we retry the hcall.
351 * - For any other hcall failures, attempt a full flush once before
352 * resorting to BUG().
354 * Note: This hcall is expected to fail only very rarely. The correct
355 * error recovery of killing the process/guest will be eventually
358 static inline long pseries_rpt_invalidate(u32 pid, u64 target, u64 type,
359 u64 page_sizes, u64 start, u64 end)
365 rc = plpar_hcall_norets(H_RPT_INVALIDATE, pid, target, type,
366 page_sizes, start, end);
370 } else if (rc == H_SUCCESS)
373 /* Flush request failed, try with a full flush once */
374 if (type & H_RPTI_TYPE_NESTED)
375 all = H_RPTI_TYPE_NESTED | H_RPTI_TYPE_NESTED_ALL;
377 all = H_RPTI_TYPE_ALL;
379 rc = plpar_hcall_norets(H_RPT_INVALIDATE, pid, target,
380 all, page_sizes, 0, -1UL);
384 } else if (rc == H_SUCCESS)
391 #else /* !CONFIG_PPC_PSERIES */
393 static inline long plpar_set_ciabr(unsigned long ciabr)
398 static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex,
404 static inline long pseries_rpt_invalidate(u32 pid, u64 target, u64 type,
405 u64 page_sizes, u64 start, u64 end)
410 #endif /* CONFIG_PPC_PSERIES */
412 #endif /* _ASM_POWERPC_PLPAR_WRAPPERS_H */