Deepthi Dharwar | 212bebb | 2013-08-22 15:23:52 +0530 | [diff] [blame] | 1 | #ifndef _ASM_POWERPC_PLPAR_WRAPPERS_H |
| 2 | #define _ASM_POWERPC_PLPAR_WRAPPERS_H |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 3 | |
Paul Gortmaker | 614f15b | 2011-07-22 18:04:33 -0400 | [diff] [blame] | 4 | #include <linux/string.h> |
Li Zhong | fb91256 | 2012-10-17 21:30:13 +0000 | [diff] [blame] | 5 | #include <linux/irqflags.h> |
Paul Gortmaker | 614f15b | 2011-07-22 18:04:33 -0400 | [diff] [blame] | 6 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 7 | #include <asm/hvcall.h> |
Paul Gortmaker | 614f15b | 2011-07-22 18:04:33 -0400 | [diff] [blame] | 8 | #include <asm/paca.h> |
Brian King | 370e458 | 2008-08-16 05:09:33 +1000 | [diff] [blame] | 9 | #include <asm/page.h> |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 10 | |
Michael Neuling | f8b6769 | 2010-04-28 13:39:41 +0000 | [diff] [blame] | 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 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 19 | static inline long poll_pending(void) |
| 20 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 21 | return plpar_hcall_norets(H_POLL_PENDING); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 22 | } |
| 23 | |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 24 | static inline u8 get_cede_latency_hint(void) |
| 25 | { |
Anton Blanchard | cf8a056 | 2012-04-10 16:20:54 +0000 | [diff] [blame] | 26 | return get_lppaca()->cede_latency_hint; |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | static inline void set_cede_latency_hint(u8 latency_hint) |
| 30 | { |
Anton Blanchard | cf8a056 | 2012-04-10 16:20:54 +0000 | [diff] [blame] | 31 | get_lppaca()->cede_latency_hint = latency_hint; |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 34 | static inline long cede_processor(void) |
| 35 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 36 | return plpar_hcall_norets(H_CEDE); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 37 | } |
| 38 | |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 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); |
Li Zhong | fb91256 | 2012-10-17 21:30:13 +0000 | [diff] [blame] | 45 | |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 46 | rc = cede_processor(); |
Li Zhong | fb91256 | 2012-10-17 21:30:13 +0000 | [diff] [blame] | 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 | |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 53 | set_cede_latency_hint(old_latency_hint); |
| 54 | |
| 55 | return rc; |
| 56 | } |
| 57 | |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 58 | static inline long vpa_call(unsigned long flags, unsigned long cpu, |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 59 | unsigned long vpa) |
| 60 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 61 | flags = flags << H_VPA_FUNC_SHIFT; |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 62 | |
| 63 | return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 64 | } |
| 65 | |
Anton Blanchard | 598c823 | 2011-07-25 01:46:34 +0000 | [diff] [blame] | 66 | static inline long unregister_vpa(unsigned long cpu) |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 67 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 68 | return vpa_call(H_VPA_DEREG_VPA, cpu, 0); |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static inline long register_vpa(unsigned long cpu, unsigned long vpa) |
| 72 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 73 | return vpa_call(H_VPA_REG_VPA, cpu, vpa); |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 74 | } |
| 75 | |
Anton Blanchard | 598c823 | 2011-07-25 01:46:34 +0000 | [diff] [blame] | 76 | static inline long unregister_slb_shadow(unsigned long cpu) |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 77 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 78 | return vpa_call(H_VPA_DEREG_SLB, cpu, 0); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa) |
| 82 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 83 | return vpa_call(H_VPA_REG_SLB, cpu, vpa); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 84 | } |
| 85 | |
Anton Blanchard | b130179 | 2011-07-25 01:46:32 +0000 | [diff] [blame] | 86 | static inline long unregister_dtl(unsigned long cpu) |
Jeremy Kerr | fc59a3f | 2009-03-11 17:55:52 +0000 | [diff] [blame] | 87 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 88 | return vpa_call(H_VPA_DEREG_DTL, cpu, 0); |
Jeremy Kerr | fc59a3f | 2009-03-11 17:55:52 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static inline long register_dtl(unsigned long cpu, unsigned long vpa) |
| 92 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 93 | return vpa_call(H_VPA_REG_DTL, cpu, vpa); |
Jeremy Kerr | fc59a3f | 2009-03-11 17:55:52 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 96 | extern void vpa_init(int cpu); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 97 | |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 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 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 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 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 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; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 125 | } |
| 126 | |
Mohan Kumar M | b4aea36 | 2007-03-21 11:21:32 +0530 | [diff] [blame] | 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 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 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 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 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; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 155 | } |
| 156 | |
Sachin P. Sant | b7abc5c | 2007-06-14 15:31:34 +1000 | [diff] [blame] | 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 | |
Michael Neuling | f90ece2 | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 172 | /* |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 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 | /* |
Michael Neuling | f90ece2 | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 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 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 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 | |
David Gibson | 64b40ff | 2016-12-09 11:07:35 +1100 | [diff] [blame] | 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 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 225 | static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba, |
| 226 | unsigned long *tce_ret) |
| 227 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 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; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 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 | |
Ian Munsie | d8f48ec | 2012-11-06 16:15:17 +1100 | [diff] [blame] | 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 | } |
Ian Munsie | 798042d | 2012-11-08 15:57:04 +1100 | [diff] [blame] | 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 */ |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 273 | return plpar_set_mode(3, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0); |
Ian Munsie | 798042d | 2012-11-08 15:57:04 +1100 | [diff] [blame] | 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) { |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 284 | return plpar_set_mode(0, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0); |
Ian Munsie | 798042d | 2012-11-08 15:57:04 +1100 | [diff] [blame] | 285 | } |
| 286 | |
Anton Blanchard | e844b1e | 2013-11-20 22:14:59 +1100 | [diff] [blame] | 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 */ |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 297 | return plpar_set_mode(0, H_SET_MODE_RESOURCE_LE, 0, 0); |
Anton Blanchard | e844b1e | 2013-11-20 22:14:59 +1100 | [diff] [blame] | 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 */ |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 310 | return plpar_set_mode(1, H_SET_MODE_RESOURCE_LE, 0, 0); |
Anton Blanchard | e844b1e | 2013-11-20 22:14:59 +1100 | [diff] [blame] | 311 | } |
| 312 | |
Ian Munsie | 376a864 | 2012-12-20 14:06:41 +0000 | [diff] [blame] | 313 | static inline long plapr_set_ciabr(unsigned long ciabr) |
| 314 | { |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 315 | return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_CIABR, ciabr, 0); |
Ian Munsie | 376a864 | 2012-12-20 14:06:41 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | static inline long plapr_set_watchpoint0(unsigned long dawr0, unsigned long dawrx0) |
| 319 | { |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 320 | return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR, dawr0, dawrx0); |
Ian Munsie | 376a864 | 2012-12-20 14:06:41 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Nicholas Piggin | 53ce299 | 2016-11-08 17:08:06 +1100 | [diff] [blame] | 323 | static inline long plapr_signal_sys_reset(long cpu) |
| 324 | { |
| 325 | return plpar_hcall_norets(H_SIGNAL_SYS_RESET, cpu); |
| 326 | } |
| 327 | |
Deepthi Dharwar | 212bebb | 2013-08-22 15:23:52 +0530 | [diff] [blame] | 328 | #endif /* _ASM_POWERPC_PLPAR_WRAPPERS_H */ |