Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Deepthi Dharwar | 212bebb | 2013-08-22 15:23:52 +0530 | [diff] [blame] | 2 | #ifndef _ASM_POWERPC_PLPAR_WRAPPERS_H |
| 3 | #define _ASM_POWERPC_PLPAR_WRAPPERS_H |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 4 | |
Paul Gortmaker | 614f15b | 2011-07-22 18:04:33 -0400 | [diff] [blame] | 5 | #include <linux/string.h> |
Li Zhong | fb91256 | 2012-10-17 21:30:13 +0000 | [diff] [blame] | 6 | #include <linux/irqflags.h> |
Paul Gortmaker | 614f15b | 2011-07-22 18:04:33 -0400 | [diff] [blame] | 7 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 8 | #include <asm/hvcall.h> |
Paul Gortmaker | 614f15b | 2011-07-22 18:04:33 -0400 | [diff] [blame] | 9 | #include <asm/paca.h> |
Brian King | 370e458 | 2008-08-16 05:09:33 +1000 | [diff] [blame] | 10 | #include <asm/page.h> |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 11 | |
Michael Neuling | f8b6769 | 2010-04-28 13:39:41 +0000 | [diff] [blame] | 12 | /* Get state of physical CPU from query_cpu_stopped */ |
| 13 | int smp_query_cpu_stopped(unsigned int pcpu); |
| 14 | #define QCSS_STOPPED 0 |
| 15 | #define QCSS_STOPPING 1 |
| 16 | #define QCSS_NOT_STOPPED 2 |
| 17 | #define QCSS_HARDWARE_ERROR -1 |
| 18 | #define QCSS_HARDWARE_BUSY -2 |
| 19 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 20 | static inline long poll_pending(void) |
| 21 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 22 | return plpar_hcall_norets(H_POLL_PENDING); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 23 | } |
| 24 | |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 25 | static inline u8 get_cede_latency_hint(void) |
| 26 | { |
Anton Blanchard | cf8a056 | 2012-04-10 16:20:54 +0000 | [diff] [blame] | 27 | return get_lppaca()->cede_latency_hint; |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | static inline void set_cede_latency_hint(u8 latency_hint) |
| 31 | { |
Anton Blanchard | cf8a056 | 2012-04-10 16:20:54 +0000 | [diff] [blame] | 32 | get_lppaca()->cede_latency_hint = latency_hint; |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 35 | static inline long cede_processor(void) |
| 36 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 37 | return plpar_hcall_norets(H_CEDE); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 38 | } |
| 39 | |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 40 | static inline long extended_cede_processor(unsigned long latency_hint) |
| 41 | { |
| 42 | long rc; |
| 43 | u8 old_latency_hint = get_cede_latency_hint(); |
| 44 | |
| 45 | set_cede_latency_hint(latency_hint); |
Li Zhong | fb91256 | 2012-10-17 21:30:13 +0000 | [diff] [blame] | 46 | |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 47 | rc = cede_processor(); |
Li Zhong | fb91256 | 2012-10-17 21:30:13 +0000 | [diff] [blame] | 48 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 49 | /* Ensure that H_CEDE returns with IRQs on */ |
| 50 | if (WARN_ON(!(mfmsr() & MSR_EE))) |
| 51 | __hard_irq_enable(); |
| 52 | #endif |
| 53 | |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 54 | set_cede_latency_hint(old_latency_hint); |
| 55 | |
| 56 | return rc; |
| 57 | } |
| 58 | |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 59 | static inline long vpa_call(unsigned long flags, unsigned long cpu, |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 60 | unsigned long vpa) |
| 61 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 62 | flags = flags << H_VPA_FUNC_SHIFT; |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 63 | |
| 64 | return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 65 | } |
| 66 | |
Anton Blanchard | 598c823 | 2011-07-25 01:46:34 +0000 | [diff] [blame] | 67 | static inline long unregister_vpa(unsigned long cpu) |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 68 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 69 | return vpa_call(H_VPA_DEREG_VPA, cpu, 0); |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static inline long register_vpa(unsigned long cpu, unsigned long vpa) |
| 73 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 74 | return vpa_call(H_VPA_REG_VPA, cpu, vpa); |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 75 | } |
| 76 | |
Anton Blanchard | 598c823 | 2011-07-25 01:46:34 +0000 | [diff] [blame] | 77 | static inline long unregister_slb_shadow(unsigned long cpu) |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 78 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 79 | return vpa_call(H_VPA_DEREG_SLB, cpu, 0); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa) |
| 83 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 84 | return vpa_call(H_VPA_REG_SLB, cpu, vpa); |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 85 | } |
| 86 | |
Anton Blanchard | b130179 | 2011-07-25 01:46:32 +0000 | [diff] [blame] | 87 | static inline long unregister_dtl(unsigned long cpu) |
Jeremy Kerr | fc59a3f | 2009-03-11 17:55:52 +0000 | [diff] [blame] | 88 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 89 | return vpa_call(H_VPA_DEREG_DTL, cpu, 0); |
Jeremy Kerr | fc59a3f | 2009-03-11 17:55:52 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static inline long register_dtl(unsigned long cpu, unsigned long vpa) |
| 93 | { |
Li Zhong | bb18b3a | 2013-01-24 22:12:21 +0000 | [diff] [blame] | 94 | return vpa_call(H_VPA_REG_DTL, cpu, vpa); |
Jeremy Kerr | fc59a3f | 2009-03-11 17:55:52 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 97 | extern void vpa_init(int cpu); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 98 | |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 99 | static inline long plpar_pte_enter(unsigned long flags, |
| 100 | unsigned long hpte_group, unsigned long hpte_v, |
| 101 | unsigned long hpte_r, unsigned long *slot) |
| 102 | { |
| 103 | long rc; |
| 104 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 105 | |
| 106 | rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r); |
| 107 | |
| 108 | *slot = retbuf[0]; |
| 109 | |
| 110 | return rc; |
| 111 | } |
| 112 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 113 | static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex, |
| 114 | unsigned long avpn, unsigned long *old_pteh_ret, |
| 115 | unsigned long *old_ptel_ret) |
| 116 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 117 | long rc; |
| 118 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 119 | |
| 120 | rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn); |
| 121 | |
| 122 | *old_pteh_ret = retbuf[0]; |
| 123 | *old_ptel_ret = retbuf[1]; |
| 124 | |
| 125 | return rc; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 126 | } |
| 127 | |
Mohan Kumar M | b4aea36 | 2007-03-21 11:21:32 +0530 | [diff] [blame] | 128 | /* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */ |
| 129 | static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex, |
| 130 | unsigned long avpn, unsigned long *old_pteh_ret, |
| 131 | unsigned long *old_ptel_ret) |
| 132 | { |
| 133 | long rc; |
| 134 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 135 | |
| 136 | rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn); |
| 137 | |
| 138 | *old_pteh_ret = retbuf[0]; |
| 139 | *old_ptel_ret = retbuf[1]; |
| 140 | |
| 141 | return rc; |
| 142 | } |
| 143 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 144 | static inline long plpar_pte_read(unsigned long flags, unsigned long ptex, |
| 145 | unsigned long *old_pteh_ret, unsigned long *old_ptel_ret) |
| 146 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 147 | long rc; |
| 148 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 149 | |
| 150 | rc = plpar_hcall(H_READ, retbuf, flags, ptex); |
| 151 | |
| 152 | *old_pteh_ret = retbuf[0]; |
| 153 | *old_ptel_ret = retbuf[1]; |
| 154 | |
| 155 | return rc; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 156 | } |
| 157 | |
Sachin P. Sant | b7abc5c | 2007-06-14 15:31:34 +1000 | [diff] [blame] | 158 | /* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */ |
| 159 | static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex, |
| 160 | unsigned long *old_pteh_ret, unsigned long *old_ptel_ret) |
| 161 | { |
| 162 | long rc; |
| 163 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 164 | |
| 165 | rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex); |
| 166 | |
| 167 | *old_pteh_ret = retbuf[0]; |
| 168 | *old_ptel_ret = retbuf[1]; |
| 169 | |
| 170 | return rc; |
| 171 | } |
| 172 | |
Michael Neuling | f90ece2 | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 173 | /* |
Aneesh Kumar K.V | 4ad90c8 | 2015-12-01 09:06:59 +0530 | [diff] [blame] | 174 | * ptes must be 8*sizeof(unsigned long) |
| 175 | */ |
| 176 | static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex, |
| 177 | unsigned long *ptes) |
| 178 | |
| 179 | { |
| 180 | long rc; |
| 181 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; |
| 182 | |
| 183 | rc = plpar_hcall9(H_READ, retbuf, flags | H_READ_4, ptex); |
| 184 | |
| 185 | memcpy(ptes, retbuf, 8*sizeof(unsigned long)); |
| 186 | |
| 187 | return rc; |
| 188 | } |
| 189 | |
| 190 | /* |
Michael Neuling | f90ece2 | 2010-05-10 20:28:26 +0000 | [diff] [blame] | 191 | * plpar_pte_read_4_raw can be called in real mode. |
| 192 | * ptes must be 8*sizeof(unsigned long) |
| 193 | */ |
| 194 | static inline long plpar_pte_read_4_raw(unsigned long flags, unsigned long ptex, |
| 195 | unsigned long *ptes) |
| 196 | |
| 197 | { |
| 198 | long rc; |
| 199 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; |
| 200 | |
| 201 | rc = plpar_hcall9_raw(H_READ, retbuf, flags | H_READ_4, ptex); |
| 202 | |
| 203 | memcpy(ptes, retbuf, 8*sizeof(unsigned long)); |
| 204 | |
| 205 | return rc; |
| 206 | } |
| 207 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 208 | static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex, |
| 209 | unsigned long avpn) |
| 210 | { |
| 211 | return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn); |
| 212 | } |
| 213 | |
David Gibson | 64b40ff | 2016-12-09 11:07:35 +1100 | [diff] [blame] | 214 | static inline long plpar_resize_hpt_prepare(unsigned long flags, |
| 215 | unsigned long shift) |
| 216 | { |
| 217 | return plpar_hcall_norets(H_RESIZE_HPT_PREPARE, flags, shift); |
| 218 | } |
| 219 | |
| 220 | static inline long plpar_resize_hpt_commit(unsigned long flags, |
| 221 | unsigned long shift) |
| 222 | { |
| 223 | return plpar_hcall_norets(H_RESIZE_HPT_COMMIT, flags, shift); |
| 224 | } |
| 225 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 226 | static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba, |
| 227 | unsigned long *tce_ret) |
| 228 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 229 | long rc; |
| 230 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 231 | |
| 232 | rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba); |
| 233 | |
| 234 | *tce_ret = retbuf[0]; |
| 235 | |
| 236 | return rc; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba, |
| 240 | unsigned long tceval) |
| 241 | { |
| 242 | return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval); |
| 243 | } |
| 244 | |
| 245 | static inline long plpar_tce_put_indirect(unsigned long liobn, |
| 246 | unsigned long ioba, unsigned long page, unsigned long count) |
| 247 | { |
| 248 | return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count); |
| 249 | } |
| 250 | |
| 251 | static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba, |
| 252 | unsigned long tceval, unsigned long count) |
| 253 | { |
| 254 | return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count); |
| 255 | } |
| 256 | |
Ian Munsie | d8f48ec | 2012-11-06 16:15:17 +1100 | [diff] [blame] | 257 | /* Set various resource mode parameters */ |
| 258 | static inline long plpar_set_mode(unsigned long mflags, unsigned long resource, |
| 259 | unsigned long value1, unsigned long value2) |
| 260 | { |
| 261 | return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2); |
| 262 | } |
Ian Munsie | 798042d | 2012-11-08 15:57:04 +1100 | [diff] [blame] | 263 | |
| 264 | /* |
| 265 | * Enable relocation on exceptions on this partition |
| 266 | * |
| 267 | * Note: this call has a partition wide scope and can take a while to complete. |
| 268 | * If it returns H_LONG_BUSY_* it should be retried periodically until it |
| 269 | * returns H_SUCCESS. |
| 270 | */ |
| 271 | static inline long enable_reloc_on_exceptions(void) |
| 272 | { |
| 273 | /* mflags = 3: Exceptions at 0xC000000000004000 */ |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 274 | 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] | 275 | } |
| 276 | |
| 277 | /* |
| 278 | * Disable relocation on exceptions on this partition |
| 279 | * |
| 280 | * Note: this call has a partition wide scope and can take a while to complete. |
| 281 | * If it returns H_LONG_BUSY_* it should be retried periodically until it |
| 282 | * returns H_SUCCESS. |
| 283 | */ |
| 284 | static inline long disable_reloc_on_exceptions(void) { |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 285 | 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] | 286 | } |
| 287 | |
Anton Blanchard | e844b1e | 2013-11-20 22:14:59 +1100 | [diff] [blame] | 288 | /* |
| 289 | * Take exceptions in big endian mode on this partition |
| 290 | * |
| 291 | * Note: this call has a partition wide scope and can take a while to complete. |
| 292 | * If it returns H_LONG_BUSY_* it should be retried periodically until it |
| 293 | * returns H_SUCCESS. |
| 294 | */ |
| 295 | static inline long enable_big_endian_exceptions(void) |
| 296 | { |
| 297 | /* mflags = 0: big endian exceptions */ |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 298 | return plpar_set_mode(0, H_SET_MODE_RESOURCE_LE, 0, 0); |
Anton Blanchard | e844b1e | 2013-11-20 22:14:59 +1100 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Take exceptions in little endian mode on this partition |
| 303 | * |
| 304 | * Note: this call has a partition wide scope and can take a while to complete. |
| 305 | * If it returns H_LONG_BUSY_* it should be retried periodically until it |
| 306 | * returns H_SUCCESS. |
| 307 | */ |
| 308 | static inline long enable_little_endian_exceptions(void) |
| 309 | { |
| 310 | /* mflags = 1: little endian exceptions */ |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 311 | return plpar_set_mode(1, H_SET_MODE_RESOURCE_LE, 0, 0); |
Anton Blanchard | e844b1e | 2013-11-20 22:14:59 +1100 | [diff] [blame] | 312 | } |
| 313 | |
Ian Munsie | 376a864 | 2012-12-20 14:06:41 +0000 | [diff] [blame] | 314 | static inline long plapr_set_ciabr(unsigned long ciabr) |
| 315 | { |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 316 | 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] | 317 | } |
| 318 | |
| 319 | static inline long plapr_set_watchpoint0(unsigned long dawr0, unsigned long dawrx0) |
| 320 | { |
Michael Neuling | 60666de | 2014-05-29 17:45:47 +1000 | [diff] [blame] | 321 | 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] | 322 | } |
| 323 | |
Nicholas Piggin | 53ce299 | 2016-11-08 17:08:06 +1100 | [diff] [blame] | 324 | static inline long plapr_signal_sys_reset(long cpu) |
| 325 | { |
| 326 | return plpar_hcall_norets(H_SIGNAL_SYS_RESET, cpu); |
| 327 | } |
| 328 | |
Michael Neuling | 191eccb | 2018-01-09 03:52:05 +1100 | [diff] [blame^] | 329 | static inline long plpar_get_cpu_characteristics(struct h_cpu_char_result *p) |
| 330 | { |
| 331 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 332 | long rc; |
| 333 | |
| 334 | rc = plpar_hcall(H_GET_CPU_CHARACTERISTICS, retbuf); |
| 335 | if (rc == H_SUCCESS) { |
| 336 | p->character = retbuf[0]; |
| 337 | p->behaviour = retbuf[1]; |
| 338 | } |
| 339 | |
| 340 | return rc; |
| 341 | } |
| 342 | |
Deepthi Dharwar | 212bebb | 2013-08-22 15:23:52 +0530 | [diff] [blame] | 343 | #endif /* _ASM_POWERPC_PLPAR_WRAPPERS_H */ |