1 #ifndef _ASM_POWERPC_PLPAR_WRAPPERS_H 2 #define _ASM_POWERPC_PLPAR_WRAPPERS_H 3 4 #include <linux/string.h> 5 #include <linux/irqflags.h> 6 7 #include <asm/hvcall.h> 8 #include <asm/paca.h> 9 #include <asm/page.h> 10 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 18 19 static inline long poll_pending(void) 20 { 21 return plpar_hcall_norets(H_POLL_PENDING); 22 } 23 24 static inline u8 get_cede_latency_hint(void) 25 { 26 return get_lppaca()->cede_latency_hint; 27 } 28 29 static inline void set_cede_latency_hint(u8 latency_hint) 30 { 31 get_lppaca()->cede_latency_hint = latency_hint; 32 } 33 34 static inline long cede_processor(void) 35 { 36 return plpar_hcall_norets(H_CEDE); 37 } 38 39 static 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); 45 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 52 53 set_cede_latency_hint(old_latency_hint); 54 55 return rc; 56 } 57 58 static inline long vpa_call(unsigned long flags, unsigned long cpu, 59 unsigned long vpa) 60 { 61 flags = flags << H_VPA_FUNC_SHIFT; 62 63 return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa); 64 } 65 66 static inline long unregister_vpa(unsigned long cpu) 67 { 68 return vpa_call(H_VPA_DEREG_VPA, cpu, 0); 69 } 70 71 static inline long register_vpa(unsigned long cpu, unsigned long vpa) 72 { 73 return vpa_call(H_VPA_REG_VPA, cpu, vpa); 74 } 75 76 static inline long unregister_slb_shadow(unsigned long cpu) 77 { 78 return vpa_call(H_VPA_DEREG_SLB, cpu, 0); 79 } 80 81 static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa) 82 { 83 return vpa_call(H_VPA_REG_SLB, cpu, vpa); 84 } 85 86 static inline long unregister_dtl(unsigned long cpu) 87 { 88 return vpa_call(H_VPA_DEREG_DTL, cpu, 0); 89 } 90 91 static inline long register_dtl(unsigned long cpu, unsigned long vpa) 92 { 93 return vpa_call(H_VPA_REG_DTL, cpu, vpa); 94 } 95 96 extern void vpa_init(int cpu); 97 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) 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 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) 115 { 116 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; 125 } 126 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) 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 143 static inline long plpar_pte_read(unsigned long flags, unsigned long ptex, 144 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret) 145 { 146 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; 155 } 156 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) 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 172 /* 173 * ptes must be 8*sizeof(unsigned long) 174 */ 175 static 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 /* 190 * plpar_pte_read_4_raw can be called in real mode. 191 * ptes must be 8*sizeof(unsigned long) 192 */ 193 static 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 207 static 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 213 static inline long plpar_resize_hpt_prepare(unsigned long flags, 214 unsigned long shift) 215 { 216 return plpar_hcall_norets(H_RESIZE_HPT_PREPARE, flags, shift); 217 } 218 219 static inline long plpar_resize_hpt_commit(unsigned long flags, 220 unsigned long shift) 221 { 222 return plpar_hcall_norets(H_RESIZE_HPT_COMMIT, flags, shift); 223 } 224 225 static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba, 226 unsigned long *tce_ret) 227 { 228 long rc; 229 unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; 230 231 rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba); 232 233 *tce_ret = retbuf[0]; 234 235 return rc; 236 } 237 238 static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba, 239 unsigned long tceval) 240 { 241 return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval); 242 } 243 244 static inline long plpar_tce_put_indirect(unsigned long liobn, 245 unsigned long ioba, unsigned long page, unsigned long count) 246 { 247 return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count); 248 } 249 250 static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba, 251 unsigned long tceval, unsigned long count) 252 { 253 return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count); 254 } 255 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) 259 { 260 return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2); 261 } 262 263 /* 264 * Enable relocation on exceptions on this partition 265 * 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. 269 */ 270 static inline long enable_reloc_on_exceptions(void) 271 { 272 /* mflags = 3: Exceptions at 0xC000000000004000 */ 273 return plpar_set_mode(3, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0); 274 } 275 276 /* 277 * Disable relocation on exceptions on this partition 278 * 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. 282 */ 283 static inline long disable_reloc_on_exceptions(void) { 284 return plpar_set_mode(0, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0); 285 } 286 287 /* 288 * Take exceptions in big endian mode on this partition 289 * 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. 293 */ 294 static inline long enable_big_endian_exceptions(void) 295 { 296 /* mflags = 0: big endian exceptions */ 297 return plpar_set_mode(0, H_SET_MODE_RESOURCE_LE, 0, 0); 298 } 299 300 /* 301 * Take exceptions in little endian mode on this partition 302 * 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. 306 */ 307 static inline long enable_little_endian_exceptions(void) 308 { 309 /* mflags = 1: little endian exceptions */ 310 return plpar_set_mode(1, H_SET_MODE_RESOURCE_LE, 0, 0); 311 } 312 313 static inline long plapr_set_ciabr(unsigned long ciabr) 314 { 315 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_CIABR, ciabr, 0); 316 } 317 318 static inline long plapr_set_watchpoint0(unsigned long dawr0, unsigned long dawrx0) 319 { 320 return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR, dawr0, dawrx0); 321 } 322 323 static inline long plapr_signal_sys_reset(long cpu) 324 { 325 return plpar_hcall_norets(H_SIGNAL_SYS_RESET, cpu); 326 } 327 328 #endif /* _ASM_POWERPC_PLPAR_WRAPPERS_H */ 329