Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 1 | #ifndef _PSERIES_PLPAR_WRAPPERS_H |
| 2 | #define _PSERIES_PLPAR_WRAPPERS_H |
| 3 | |
| 4 | #include <asm/hvcall.h> |
Brian King | 370e458 | 2008-08-16 05:09:33 +1000 | [diff] [blame] | 5 | #include <asm/page.h> |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 6 | |
| 7 | static inline long poll_pending(void) |
| 8 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 9 | return plpar_hcall_norets(H_POLL_PENDING); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 10 | } |
| 11 | |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 12 | static inline u8 get_cede_latency_hint(void) |
| 13 | { |
| 14 | return get_lppaca()->gpr5_dword.fields.cede_latency_hint; |
| 15 | } |
| 16 | |
| 17 | static inline void set_cede_latency_hint(u8 latency_hint) |
| 18 | { |
| 19 | get_lppaca()->gpr5_dword.fields.cede_latency_hint = latency_hint; |
| 20 | } |
| 21 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 22 | static inline long cede_processor(void) |
| 23 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 24 | return plpar_hcall_norets(H_CEDE); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 25 | } |
| 26 | |
Gautham R Shenoy | 69ddb57 | 2009-10-29 19:22:48 +0000 | [diff] [blame] | 27 | static inline long extended_cede_processor(unsigned long latency_hint) |
| 28 | { |
| 29 | long rc; |
| 30 | u8 old_latency_hint = get_cede_latency_hint(); |
| 31 | |
| 32 | set_cede_latency_hint(latency_hint); |
| 33 | rc = cede_processor(); |
| 34 | set_cede_latency_hint(old_latency_hint); |
| 35 | |
| 36 | return rc; |
| 37 | } |
| 38 | |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 39 | static inline long vpa_call(unsigned long flags, unsigned long cpu, |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 40 | unsigned long vpa) |
| 41 | { |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 42 | /* flags are in bits 16-18 (counting from most significant bit) */ |
| 43 | flags = flags << (63 - 18); |
| 44 | |
| 45 | return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 46 | } |
| 47 | |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 48 | static inline long unregister_vpa(unsigned long cpu, unsigned long vpa) |
| 49 | { |
| 50 | return vpa_call(0x5, cpu, vpa); |
| 51 | } |
| 52 | |
| 53 | static inline long register_vpa(unsigned long cpu, unsigned long vpa) |
| 54 | { |
| 55 | return vpa_call(0x1, cpu, vpa); |
| 56 | } |
| 57 | |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 58 | static inline long unregister_slb_shadow(unsigned long cpu, unsigned long vpa) |
| 59 | { |
| 60 | return vpa_call(0x7, cpu, vpa); |
| 61 | } |
| 62 | |
| 63 | static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa) |
| 64 | { |
| 65 | return vpa_call(0x3, cpu, vpa); |
| 66 | } |
| 67 | |
Jeremy Kerr | fc59a3f | 2009-03-11 17:55:52 +0000 | [diff] [blame] | 68 | static inline long unregister_dtl(unsigned long cpu, unsigned long vpa) |
| 69 | { |
| 70 | return vpa_call(0x6, cpu, vpa); |
| 71 | } |
| 72 | |
| 73 | static inline long register_dtl(unsigned long cpu, unsigned long vpa) |
| 74 | { |
| 75 | return vpa_call(0x2, cpu, vpa); |
| 76 | } |
| 77 | |
Brian King | 86630a3 | 2008-07-24 04:29:16 +1000 | [diff] [blame] | 78 | static inline long plpar_page_set_loaned(unsigned long vpa) |
| 79 | { |
Brian King | 370e458 | 2008-08-16 05:09:33 +1000 | [diff] [blame] | 80 | unsigned long cmo_page_sz = cmo_get_page_size(); |
| 81 | long rc = 0; |
| 82 | int i; |
| 83 | |
| 84 | for (i = 0; !rc && i < PAGE_SIZE; i += cmo_page_sz) |
| 85 | rc = plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_LOANED, vpa + i, 0); |
| 86 | |
| 87 | for (i -= cmo_page_sz; rc && i != 0; i -= cmo_page_sz) |
| 88 | plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_ACTIVE, |
| 89 | vpa + i - cmo_page_sz, 0); |
| 90 | |
| 91 | return rc; |
Brian King | 86630a3 | 2008-07-24 04:29:16 +1000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static inline long plpar_page_set_active(unsigned long vpa) |
| 95 | { |
Brian King | 370e458 | 2008-08-16 05:09:33 +1000 | [diff] [blame] | 96 | unsigned long cmo_page_sz = cmo_get_page_size(); |
| 97 | long rc = 0; |
| 98 | int i; |
| 99 | |
| 100 | for (i = 0; !rc && i < PAGE_SIZE; i += cmo_page_sz) |
| 101 | rc = plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_ACTIVE, vpa + i, 0); |
| 102 | |
| 103 | for (i -= cmo_page_sz; rc && i != 0; i -= cmo_page_sz) |
| 104 | plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_LOANED, |
| 105 | vpa + i - cmo_page_sz, 0); |
| 106 | |
| 107 | return rc; |
Brian King | 86630a3 | 2008-07-24 04:29:16 +1000 | [diff] [blame] | 108 | } |
| 109 | |
Michael Ellerman | 40765d2 | 2005-11-03 19:34:38 +1100 | [diff] [blame] | 110 | extern void vpa_init(int cpu); |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 111 | |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 112 | static inline long plpar_pte_enter(unsigned long flags, |
| 113 | unsigned long hpte_group, unsigned long hpte_v, |
| 114 | unsigned long hpte_r, unsigned long *slot) |
| 115 | { |
| 116 | long rc; |
| 117 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 118 | |
| 119 | rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r); |
| 120 | |
| 121 | *slot = retbuf[0]; |
| 122 | |
| 123 | return rc; |
| 124 | } |
| 125 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 126 | static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex, |
| 127 | unsigned long avpn, unsigned long *old_pteh_ret, |
| 128 | unsigned long *old_ptel_ret) |
| 129 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 130 | long rc; |
| 131 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 132 | |
| 133 | rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn); |
| 134 | |
| 135 | *old_pteh_ret = retbuf[0]; |
| 136 | *old_ptel_ret = retbuf[1]; |
| 137 | |
| 138 | return rc; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 139 | } |
| 140 | |
Mohan Kumar M | b4aea36 | 2007-03-21 11:21:32 +0530 | [diff] [blame] | 141 | /* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */ |
| 142 | static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex, |
| 143 | unsigned long avpn, unsigned long *old_pteh_ret, |
| 144 | unsigned long *old_ptel_ret) |
| 145 | { |
| 146 | long rc; |
| 147 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 148 | |
| 149 | rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn); |
| 150 | |
| 151 | *old_pteh_ret = retbuf[0]; |
| 152 | *old_ptel_ret = retbuf[1]; |
| 153 | |
| 154 | return rc; |
| 155 | } |
| 156 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 157 | static inline long plpar_pte_read(unsigned long flags, unsigned long ptex, |
| 158 | unsigned long *old_pteh_ret, unsigned long *old_ptel_ret) |
| 159 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 160 | long rc; |
| 161 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 162 | |
| 163 | rc = plpar_hcall(H_READ, retbuf, flags, ptex); |
| 164 | |
| 165 | *old_pteh_ret = retbuf[0]; |
| 166 | *old_ptel_ret = retbuf[1]; |
| 167 | |
| 168 | return rc; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 169 | } |
| 170 | |
Sachin P. Sant | b7abc5c | 2007-06-14 15:31:34 +1000 | [diff] [blame] | 171 | /* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */ |
| 172 | static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex, |
| 173 | unsigned long *old_pteh_ret, unsigned long *old_ptel_ret) |
| 174 | { |
| 175 | long rc; |
| 176 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 177 | |
| 178 | rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex); |
| 179 | |
| 180 | *old_pteh_ret = retbuf[0]; |
| 181 | *old_ptel_ret = retbuf[1]; |
| 182 | |
| 183 | return rc; |
| 184 | } |
| 185 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 186 | static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex, |
| 187 | unsigned long avpn) |
| 188 | { |
| 189 | return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn); |
| 190 | } |
| 191 | |
| 192 | static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba, |
| 193 | unsigned long *tce_ret) |
| 194 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 195 | long rc; |
| 196 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 197 | |
| 198 | rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba); |
| 199 | |
| 200 | *tce_ret = retbuf[0]; |
| 201 | |
| 202 | return rc; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba, |
| 206 | unsigned long tceval) |
| 207 | { |
| 208 | return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval); |
| 209 | } |
| 210 | |
| 211 | static inline long plpar_tce_put_indirect(unsigned long liobn, |
| 212 | unsigned long ioba, unsigned long page, unsigned long count) |
| 213 | { |
| 214 | return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count); |
| 215 | } |
| 216 | |
| 217 | static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba, |
| 218 | unsigned long tceval, unsigned long count) |
| 219 | { |
| 220 | return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count); |
| 221 | } |
| 222 | |
| 223 | static inline long plpar_get_term_char(unsigned long termno, |
| 224 | unsigned long *len_ret, char *buf_ret) |
| 225 | { |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 226 | long rc; |
| 227 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 228 | unsigned long *lbuf = (unsigned long *)buf_ret; /* TODO: alignment? */ |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 229 | |
| 230 | rc = plpar_hcall(H_GET_TERM_CHAR, retbuf, termno); |
| 231 | |
| 232 | *len_ret = retbuf[0]; |
| 233 | lbuf[0] = retbuf[1]; |
| 234 | lbuf[1] = retbuf[2]; |
| 235 | |
| 236 | return rc; |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static inline long plpar_put_term_char(unsigned long termno, unsigned long len, |
| 240 | const char *buffer) |
| 241 | { |
| 242 | unsigned long *lbuf = (unsigned long *)buffer; /* TODO: alignment? */ |
| 243 | return plpar_hcall_norets(H_PUT_TERM_CHAR, termno, len, lbuf[0], |
| 244 | lbuf[1]); |
| 245 | } |
| 246 | |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 247 | static inline long plpar_eoi(unsigned long xirr) |
| 248 | { |
| 249 | return plpar_hcall_norets(H_EOI, xirr); |
| 250 | } |
| 251 | |
| 252 | static inline long plpar_cppr(unsigned long cppr) |
| 253 | { |
| 254 | return plpar_hcall_norets(H_CPPR, cppr); |
| 255 | } |
| 256 | |
| 257 | static inline long plpar_ipi(unsigned long servernum, unsigned long mfrr) |
| 258 | { |
| 259 | return plpar_hcall_norets(H_IPI, servernum, mfrr); |
| 260 | } |
| 261 | |
Mark Nelson | f09b7b2 | 2010-01-31 20:12:58 +0000 | [diff] [blame] | 262 | static inline long plpar_xirr(unsigned long *xirr_ret, unsigned char cppr) |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 263 | { |
| 264 | long rc; |
| 265 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 266 | |
Mark Nelson | f09b7b2 | 2010-01-31 20:12:58 +0000 | [diff] [blame] | 267 | rc = plpar_hcall(H_XIRR, retbuf, cppr); |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 268 | |
| 269 | *xirr_ret = retbuf[0]; |
| 270 | |
| 271 | return rc; |
| 272 | } |
| 273 | |
Michael Ellerman | a121872 | 2005-11-03 15:33:31 +1100 | [diff] [blame] | 274 | #endif /* _PSERIES_PLPAR_WRAPPERS_H */ |