Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_POWERPC_PLPAR_WRAPPERS_H
0003 #define _ASM_POWERPC_PLPAR_WRAPPERS_H
0004 
0005 #ifdef CONFIG_PPC_PSERIES
0006 
0007 #include <linux/string.h>
0008 #include <linux/irqflags.h>
0009 
0010 #include <asm/hvcall.h>
0011 #include <asm/paca.h>
0012 #include <asm/page.h>
0013 
0014 static inline long poll_pending(void)
0015 {
0016     return plpar_hcall_norets(H_POLL_PENDING);
0017 }
0018 
0019 static inline u8 get_cede_latency_hint(void)
0020 {
0021     return get_lppaca()->cede_latency_hint;
0022 }
0023 
0024 static inline void set_cede_latency_hint(u8 latency_hint)
0025 {
0026     get_lppaca()->cede_latency_hint = latency_hint;
0027 }
0028 
0029 static inline long cede_processor(void)
0030 {
0031     /*
0032      * We cannot call tracepoints inside RCU idle regions which
0033      * means we must not trace H_CEDE.
0034      */
0035     return plpar_hcall_norets_notrace(H_CEDE);
0036 }
0037 
0038 static inline long extended_cede_processor(unsigned long latency_hint)
0039 {
0040     long rc;
0041     u8 old_latency_hint = get_cede_latency_hint();
0042 
0043     set_cede_latency_hint(latency_hint);
0044 
0045     rc = cede_processor();
0046 
0047     /* Ensure that H_CEDE returns with IRQs on */
0048     if (WARN_ON(IS_ENABLED(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG) && !(mfmsr() & MSR_EE)))
0049         __hard_irq_enable();
0050 
0051     set_cede_latency_hint(old_latency_hint);
0052 
0053     return rc;
0054 }
0055 
0056 static inline long vpa_call(unsigned long flags, unsigned long cpu,
0057         unsigned long vpa)
0058 {
0059     flags = flags << H_VPA_FUNC_SHIFT;
0060 
0061     return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa);
0062 }
0063 
0064 static inline long unregister_vpa(unsigned long cpu)
0065 {
0066     return vpa_call(H_VPA_DEREG_VPA, cpu, 0);
0067 }
0068 
0069 static inline long register_vpa(unsigned long cpu, unsigned long vpa)
0070 {
0071     return vpa_call(H_VPA_REG_VPA, cpu, vpa);
0072 }
0073 
0074 static inline long unregister_slb_shadow(unsigned long cpu)
0075 {
0076     return vpa_call(H_VPA_DEREG_SLB, cpu, 0);
0077 }
0078 
0079 static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa)
0080 {
0081     return vpa_call(H_VPA_REG_SLB, cpu, vpa);
0082 }
0083 
0084 static inline long unregister_dtl(unsigned long cpu)
0085 {
0086     return vpa_call(H_VPA_DEREG_DTL, cpu, 0);
0087 }
0088 
0089 static inline long register_dtl(unsigned long cpu, unsigned long vpa)
0090 {
0091     return vpa_call(H_VPA_REG_DTL, cpu, vpa);
0092 }
0093 
0094 extern void vpa_init(int cpu);
0095 
0096 static inline long plpar_pte_enter(unsigned long flags,
0097         unsigned long hpte_group, unsigned long hpte_v,
0098         unsigned long hpte_r, unsigned long *slot)
0099 {
0100     long rc;
0101     unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
0102 
0103     rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r);
0104 
0105     *slot = retbuf[0];
0106 
0107     return rc;
0108 }
0109 
0110 static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex,
0111         unsigned long avpn, unsigned long *old_pteh_ret,
0112         unsigned long *old_ptel_ret)
0113 {
0114     long rc;
0115     unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
0116 
0117     rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn);
0118 
0119     *old_pteh_ret = retbuf[0];
0120     *old_ptel_ret = retbuf[1];
0121 
0122     return rc;
0123 }
0124 
0125 /* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */
0126 static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex,
0127         unsigned long avpn, unsigned long *old_pteh_ret,
0128         unsigned long *old_ptel_ret)
0129 {
0130     long rc;
0131     unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
0132 
0133     rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn);
0134 
0135     *old_pteh_ret = retbuf[0];
0136     *old_ptel_ret = retbuf[1];
0137 
0138     return rc;
0139 }
0140 
0141 static inline long plpar_pte_read(unsigned long flags, unsigned long ptex,
0142         unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
0143 {
0144     long rc;
0145     unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
0146 
0147     rc = plpar_hcall(H_READ, retbuf, flags, ptex);
0148 
0149     *old_pteh_ret = retbuf[0];
0150     *old_ptel_ret = retbuf[1];
0151 
0152     return rc;
0153 }
0154 
0155 /* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */
0156 static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex,
0157         unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
0158 {
0159     long rc;
0160     unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
0161 
0162     rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex);
0163 
0164     *old_pteh_ret = retbuf[0];
0165     *old_ptel_ret = retbuf[1];
0166 
0167     return rc;
0168 }
0169 
0170 /*
0171  * ptes must be 8*sizeof(unsigned long)
0172  */
0173 static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex,
0174                     unsigned long *ptes)
0175 
0176 {
0177     long rc;
0178     unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
0179 
0180     rc = plpar_hcall9(H_READ, retbuf, flags | H_READ_4, ptex);
0181 
0182     memcpy(ptes, retbuf, 8*sizeof(unsigned long));
0183 
0184     return rc;
0185 }
0186 
0187 /*
0188  * plpar_pte_read_4_raw can be called in real mode.
0189  * ptes must be 8*sizeof(unsigned long)
0190  */
0191 static inline long plpar_pte_read_4_raw(unsigned long flags, unsigned long ptex,
0192                     unsigned long *ptes)
0193 
0194 {
0195     long rc;
0196     unsigned long retbuf[PLPAR_HCALL9_BUFSIZE];
0197 
0198     rc = plpar_hcall9_raw(H_READ, retbuf, flags | H_READ_4, ptex);
0199 
0200     memcpy(ptes, retbuf, 8*sizeof(unsigned long));
0201 
0202     return rc;
0203 }
0204 
0205 static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex,
0206         unsigned long avpn)
0207 {
0208     return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn);
0209 }
0210 
0211 static inline long plpar_resize_hpt_prepare(unsigned long flags,
0212                         unsigned long shift)
0213 {
0214     return plpar_hcall_norets(H_RESIZE_HPT_PREPARE, flags, shift);
0215 }
0216 
0217 static inline long plpar_resize_hpt_commit(unsigned long flags,
0218                        unsigned long shift)
0219 {
0220     return plpar_hcall_norets(H_RESIZE_HPT_COMMIT, flags, shift);
0221 }
0222 
0223 static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba,
0224         unsigned long *tce_ret)
0225 {
0226     long rc;
0227     unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
0228 
0229     rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba);
0230 
0231     *tce_ret = retbuf[0];
0232 
0233     return rc;
0234 }
0235 
0236 static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba,
0237         unsigned long tceval)
0238 {
0239     return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval);
0240 }
0241 
0242 static inline long plpar_tce_put_indirect(unsigned long liobn,
0243         unsigned long ioba, unsigned long page, unsigned long count)
0244 {
0245     return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count);
0246 }
0247 
0248 static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba,
0249         unsigned long tceval, unsigned long count)
0250 {
0251     return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count);
0252 }
0253 
0254 /* Set various resource mode parameters */
0255 static inline long plpar_set_mode(unsigned long mflags, unsigned long resource,
0256         unsigned long value1, unsigned long value2)
0257 {
0258     return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2);
0259 }
0260 
0261 /*
0262  * Enable relocation on exceptions on this partition
0263  *
0264  * Note: this call has a partition wide scope and can take a while to complete.
0265  * If it returns H_LONG_BUSY_* it should be retried periodically until it
0266  * returns H_SUCCESS.
0267  */
0268 static inline long enable_reloc_on_exceptions(void)
0269 {
0270     /* mflags = 3: Exceptions at 0xC000000000004000 */
0271     return plpar_set_mode(3, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0);
0272 }
0273 
0274 /*
0275  * Disable relocation on exceptions on this partition
0276  *
0277  * Note: this call has a partition wide scope and can take a while to complete.
0278  * If it returns H_LONG_BUSY_* it should be retried periodically until it
0279  * returns H_SUCCESS.
0280  */
0281 static inline long disable_reloc_on_exceptions(void) {
0282     return plpar_set_mode(0, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0);
0283 }
0284 
0285 /*
0286  * Take exceptions in big endian mode on this partition
0287  *
0288  * Note: this call has a partition wide scope and can take a while to complete.
0289  * If it returns H_LONG_BUSY_* it should be retried periodically until it
0290  * returns H_SUCCESS.
0291  */
0292 static inline long enable_big_endian_exceptions(void)
0293 {
0294     /* mflags = 0: big endian exceptions */
0295     return plpar_set_mode(0, H_SET_MODE_RESOURCE_LE, 0, 0);
0296 }
0297 
0298 /*
0299  * Take exceptions in little endian mode on this partition
0300  *
0301  * Note: this call has a partition wide scope and can take a while to complete.
0302  * If it returns H_LONG_BUSY_* it should be retried periodically until it
0303  * returns H_SUCCESS.
0304  */
0305 static inline long enable_little_endian_exceptions(void)
0306 {
0307     /* mflags = 1: little endian exceptions */
0308     return plpar_set_mode(1, H_SET_MODE_RESOURCE_LE, 0, 0);
0309 }
0310 
0311 static inline long plpar_set_ciabr(unsigned long ciabr)
0312 {
0313     return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_CIABR, ciabr, 0);
0314 }
0315 
0316 static inline long plpar_set_watchpoint0(unsigned long dawr0, unsigned long dawrx0)
0317 {
0318     return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR0, dawr0, dawrx0);
0319 }
0320 
0321 static inline long plpar_set_watchpoint1(unsigned long dawr1, unsigned long dawrx1)
0322 {
0323     return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR1, dawr1, dawrx1);
0324 }
0325 
0326 static inline long plpar_signal_sys_reset(long cpu)
0327 {
0328     return plpar_hcall_norets(H_SIGNAL_SYS_RESET, cpu);
0329 }
0330 
0331 static inline long plpar_get_cpu_characteristics(struct h_cpu_char_result *p)
0332 {
0333     unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
0334     long rc;
0335 
0336     rc = plpar_hcall(H_GET_CPU_CHARACTERISTICS, retbuf);
0337     if (rc == H_SUCCESS) {
0338         p->character = retbuf[0];
0339         p->behaviour = retbuf[1];
0340     }
0341 
0342     return rc;
0343 }
0344 
0345 /*
0346  * Wrapper to H_RPT_INVALIDATE hcall that handles return values appropriately
0347  *
0348  * - Returns H_SUCCESS on success
0349  * - For H_BUSY return value, we retry the hcall.
0350  * - For any other hcall failures, attempt a full flush once before
0351  *   resorting to BUG().
0352  *
0353  * Note: This hcall is expected to fail only very rarely. The correct
0354  * error recovery of killing the process/guest will be eventually
0355  * needed.
0356  */
0357 static inline long pseries_rpt_invalidate(u32 pid, u64 target, u64 type,
0358                       u64 page_sizes, u64 start, u64 end)
0359 {
0360     long rc;
0361     unsigned long all;
0362 
0363     while (true) {
0364         rc = plpar_hcall_norets(H_RPT_INVALIDATE, pid, target, type,
0365                     page_sizes, start, end);
0366         if (rc == H_BUSY) {
0367             cpu_relax();
0368             continue;
0369         } else if (rc == H_SUCCESS)
0370             return rc;
0371 
0372         /* Flush request failed, try with a full flush once */
0373         if (type & H_RPTI_TYPE_NESTED)
0374             all = H_RPTI_TYPE_NESTED | H_RPTI_TYPE_NESTED_ALL;
0375         else
0376             all = H_RPTI_TYPE_ALL;
0377 retry:
0378         rc = plpar_hcall_norets(H_RPT_INVALIDATE, pid, target,
0379                     all, page_sizes, 0, -1UL);
0380         if (rc == H_BUSY) {
0381             cpu_relax();
0382             goto retry;
0383         } else if (rc == H_SUCCESS)
0384             return rc;
0385 
0386         BUG();
0387     }
0388 }
0389 
0390 #else /* !CONFIG_PPC_PSERIES */
0391 
0392 static inline long plpar_set_ciabr(unsigned long ciabr)
0393 {
0394     return 0;
0395 }
0396 
0397 static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex,
0398                     unsigned long *ptes)
0399 {
0400     return 0;
0401 }
0402 
0403 static inline long pseries_rpt_invalidate(u32 pid, u64 target, u64 type,
0404                       u64 page_sizes, u64 start, u64 end)
0405 {
0406     return 0;
0407 }
0408 
0409 #endif /* CONFIG_PPC_PSERIES */
0410 
0411 #endif /* _ASM_POWERPC_PLPAR_WRAPPERS_H */