Commit | Line | Data |
---|---|---|
a1218720 ME |
1 | #ifndef _PSERIES_PLPAR_WRAPPERS_H |
2 | #define _PSERIES_PLPAR_WRAPPERS_H | |
3 | ||
614f15b4 PG |
4 | #include <linux/string.h> |
5 | ||
a1218720 | 6 | #include <asm/hvcall.h> |
614f15b4 | 7 | #include <asm/paca.h> |
370e4587 | 8 | #include <asm/page.h> |
a1218720 | 9 | |
f8b67691 MN |
10 | /* Get state of physical CPU from query_cpu_stopped */ |
11 | int smp_query_cpu_stopped(unsigned int pcpu); | |
12 | #define QCSS_STOPPED 0 | |
13 | #define QCSS_STOPPING 1 | |
14 | #define QCSS_NOT_STOPPED 2 | |
15 | #define QCSS_HARDWARE_ERROR -1 | |
16 | #define QCSS_HARDWARE_BUSY -2 | |
17 | ||
a1218720 ME |
18 | static inline long poll_pending(void) |
19 | { | |
b9377ffc | 20 | return plpar_hcall_norets(H_POLL_PENDING); |
a1218720 ME |
21 | } |
22 | ||
69ddb57c GS |
23 | static inline u8 get_cede_latency_hint(void) |
24 | { | |
cf8a056a | 25 | return get_lppaca()->cede_latency_hint; |
69ddb57c GS |
26 | } |
27 | ||
28 | static inline void set_cede_latency_hint(u8 latency_hint) | |
29 | { | |
cf8a056a | 30 | get_lppaca()->cede_latency_hint = latency_hint; |
69ddb57c GS |
31 | } |
32 | ||
a1218720 ME |
33 | static inline long cede_processor(void) |
34 | { | |
b9377ffc | 35 | return plpar_hcall_norets(H_CEDE); |
a1218720 ME |
36 | } |
37 | ||
69ddb57c GS |
38 | static inline long extended_cede_processor(unsigned long latency_hint) |
39 | { | |
40 | long rc; | |
41 | u8 old_latency_hint = get_cede_latency_hint(); | |
42 | ||
43 | set_cede_latency_hint(latency_hint); | |
44 | rc = cede_processor(); | |
45 | set_cede_latency_hint(old_latency_hint); | |
46 | ||
47 | return rc; | |
48 | } | |
49 | ||
40765d2b | 50 | static inline long vpa_call(unsigned long flags, unsigned long cpu, |
a1218720 ME |
51 | unsigned long vpa) |
52 | { | |
40765d2b ME |
53 | /* flags are in bits 16-18 (counting from most significant bit) */ |
54 | flags = flags << (63 - 18); | |
55 | ||
56 | return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa); | |
57 | } | |
58 | ||
598c8231 | 59 | static inline long unregister_vpa(unsigned long cpu) |
40765d2b | 60 | { |
598c8231 | 61 | return vpa_call(0x5, cpu, 0); |
40765d2b ME |
62 | } |
63 | ||
64 | static inline long register_vpa(unsigned long cpu, unsigned long vpa) | |
65 | { | |
66 | return vpa_call(0x1, cpu, vpa); | |
a1218720 ME |
67 | } |
68 | ||
598c8231 | 69 | static inline long unregister_slb_shadow(unsigned long cpu) |
2f6093c8 | 70 | { |
598c8231 | 71 | return vpa_call(0x7, cpu, 0); |
2f6093c8 MN |
72 | } |
73 | ||
74 | static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa) | |
75 | { | |
76 | return vpa_call(0x3, cpu, vpa); | |
77 | } | |
78 | ||
b1301797 | 79 | static inline long unregister_dtl(unsigned long cpu) |
fc59a3fc | 80 | { |
b1301797 | 81 | return vpa_call(0x6, cpu, 0); |
fc59a3fc JK |
82 | } |
83 | ||
84 | static inline long register_dtl(unsigned long cpu, unsigned long vpa) | |
85 | { | |
86 | return vpa_call(0x2, cpu, vpa); | |
87 | } | |
88 | ||
86630a32 BK |
89 | static inline long plpar_page_set_loaned(unsigned long vpa) |
90 | { | |
370e4587 BK |
91 | unsigned long cmo_page_sz = cmo_get_page_size(); |
92 | long rc = 0; | |
93 | int i; | |
94 | ||
95 | for (i = 0; !rc && i < PAGE_SIZE; i += cmo_page_sz) | |
96 | rc = plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_LOANED, vpa + i, 0); | |
97 | ||
98 | for (i -= cmo_page_sz; rc && i != 0; i -= cmo_page_sz) | |
99 | plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_ACTIVE, | |
100 | vpa + i - cmo_page_sz, 0); | |
101 | ||
102 | return rc; | |
86630a32 BK |
103 | } |
104 | ||
105 | static inline long plpar_page_set_active(unsigned long vpa) | |
106 | { | |
370e4587 BK |
107 | unsigned long cmo_page_sz = cmo_get_page_size(); |
108 | long rc = 0; | |
109 | int i; | |
110 | ||
111 | for (i = 0; !rc && i < PAGE_SIZE; i += cmo_page_sz) | |
112 | rc = plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_ACTIVE, vpa + i, 0); | |
113 | ||
114 | for (i -= cmo_page_sz; rc && i != 0; i -= cmo_page_sz) | |
115 | plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_LOANED, | |
116 | vpa + i - cmo_page_sz, 0); | |
117 | ||
118 | return rc; | |
86630a32 BK |
119 | } |
120 | ||
40765d2b | 121 | extern void vpa_init(int cpu); |
a1218720 | 122 | |
b9377ffc AB |
123 | static inline long plpar_pte_enter(unsigned long flags, |
124 | unsigned long hpte_group, unsigned long hpte_v, | |
125 | unsigned long hpte_r, unsigned long *slot) | |
126 | { | |
127 | long rc; | |
128 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; | |
129 | ||
130 | rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r); | |
131 | ||
132 | *slot = retbuf[0]; | |
133 | ||
134 | return rc; | |
135 | } | |
136 | ||
a1218720 ME |
137 | static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex, |
138 | unsigned long avpn, unsigned long *old_pteh_ret, | |
139 | unsigned long *old_ptel_ret) | |
140 | { | |
b9377ffc AB |
141 | long rc; |
142 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; | |
143 | ||
144 | rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn); | |
145 | ||
146 | *old_pteh_ret = retbuf[0]; | |
147 | *old_ptel_ret = retbuf[1]; | |
148 | ||
149 | return rc; | |
a1218720 ME |
150 | } |
151 | ||
b4aea36b MK |
152 | /* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */ |
153 | static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex, | |
154 | unsigned long avpn, unsigned long *old_pteh_ret, | |
155 | unsigned long *old_ptel_ret) | |
156 | { | |
157 | long rc; | |
158 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; | |
159 | ||
160 | rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn); | |
161 | ||
162 | *old_pteh_ret = retbuf[0]; | |
163 | *old_ptel_ret = retbuf[1]; | |
164 | ||
165 | return rc; | |
166 | } | |
167 | ||
a1218720 ME |
168 | static inline long plpar_pte_read(unsigned long flags, unsigned long ptex, |
169 | unsigned long *old_pteh_ret, unsigned long *old_ptel_ret) | |
170 | { | |
b9377ffc AB |
171 | long rc; |
172 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; | |
173 | ||
174 | rc = plpar_hcall(H_READ, retbuf, flags, ptex); | |
175 | ||
176 | *old_pteh_ret = retbuf[0]; | |
177 | *old_ptel_ret = retbuf[1]; | |
178 | ||
179 | return rc; | |
a1218720 ME |
180 | } |
181 | ||
b7abc5c5 SS |
182 | /* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */ |
183 | static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex, | |
184 | unsigned long *old_pteh_ret, unsigned long *old_ptel_ret) | |
185 | { | |
186 | long rc; | |
187 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; | |
188 | ||
189 | rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex); | |
190 | ||
191 | *old_pteh_ret = retbuf[0]; | |
192 | *old_ptel_ret = retbuf[1]; | |
193 | ||
194 | return rc; | |
195 | } | |
196 | ||
f90ece28 MN |
197 | /* |
198 | * plpar_pte_read_4_raw can be called in real mode. | |
199 | * ptes must be 8*sizeof(unsigned long) | |
200 | */ | |
201 | static inline long plpar_pte_read_4_raw(unsigned long flags, unsigned long ptex, | |
202 | unsigned long *ptes) | |
203 | ||
204 | { | |
205 | long rc; | |
206 | unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; | |
207 | ||
208 | rc = plpar_hcall9_raw(H_READ, retbuf, flags | H_READ_4, ptex); | |
209 | ||
210 | memcpy(ptes, retbuf, 8*sizeof(unsigned long)); | |
211 | ||
212 | return rc; | |
213 | } | |
214 | ||
a1218720 ME |
215 | static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex, |
216 | unsigned long avpn) | |
217 | { | |
218 | return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn); | |
219 | } | |
220 | ||
221 | static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba, | |
222 | unsigned long *tce_ret) | |
223 | { | |
b9377ffc AB |
224 | long rc; |
225 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; | |
226 | ||
227 | rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba); | |
228 | ||
229 | *tce_ret = retbuf[0]; | |
230 | ||
231 | return rc; | |
a1218720 ME |
232 | } |
233 | ||
234 | static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba, | |
235 | unsigned long tceval) | |
236 | { | |
237 | return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval); | |
238 | } | |
239 | ||
240 | static inline long plpar_tce_put_indirect(unsigned long liobn, | |
241 | unsigned long ioba, unsigned long page, unsigned long count) | |
242 | { | |
243 | return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count); | |
244 | } | |
245 | ||
246 | static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba, | |
247 | unsigned long tceval, unsigned long count) | |
248 | { | |
249 | return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count); | |
250 | } | |
251 | ||
252 | static inline long plpar_get_term_char(unsigned long termno, | |
253 | unsigned long *len_ret, char *buf_ret) | |
254 | { | |
b9377ffc AB |
255 | long rc; |
256 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; | |
a1218720 | 257 | unsigned long *lbuf = (unsigned long *)buf_ret; /* TODO: alignment? */ |
b9377ffc AB |
258 | |
259 | rc = plpar_hcall(H_GET_TERM_CHAR, retbuf, termno); | |
260 | ||
261 | *len_ret = retbuf[0]; | |
262 | lbuf[0] = retbuf[1]; | |
263 | lbuf[1] = retbuf[2]; | |
264 | ||
265 | return rc; | |
a1218720 ME |
266 | } |
267 | ||
268 | static inline long plpar_put_term_char(unsigned long termno, unsigned long len, | |
269 | const char *buffer) | |
270 | { | |
271 | unsigned long *lbuf = (unsigned long *)buffer; /* TODO: alignment? */ | |
272 | return plpar_hcall_norets(H_PUT_TERM_CHAR, termno, len, lbuf[0], | |
273 | lbuf[1]); | |
274 | } | |
275 | ||
d8f48ecc IM |
276 | /* Set various resource mode parameters */ |
277 | static inline long plpar_set_mode(unsigned long mflags, unsigned long resource, | |
278 | unsigned long value1, unsigned long value2) | |
279 | { | |
280 | return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2); | |
281 | } | |
798042da IM |
282 | |
283 | /* | |
284 | * Enable relocation on exceptions on this partition | |
285 | * | |
286 | * Note: this call has a partition wide scope and can take a while to complete. | |
287 | * If it returns H_LONG_BUSY_* it should be retried periodically until it | |
288 | * returns H_SUCCESS. | |
289 | */ | |
290 | static inline long enable_reloc_on_exceptions(void) | |
291 | { | |
292 | /* mflags = 3: Exceptions at 0xC000000000004000 */ | |
293 | return plpar_set_mode(3, 3, 0, 0); | |
294 | } | |
295 | ||
296 | /* | |
297 | * Disable relocation on exceptions on this partition | |
298 | * | |
299 | * Note: this call has a partition wide scope and can take a while to complete. | |
300 | * If it returns H_LONG_BUSY_* it should be retried periodically until it | |
301 | * returns H_SUCCESS. | |
302 | */ | |
303 | static inline long disable_reloc_on_exceptions(void) { | |
304 | return plpar_set_mode(0, 3, 0, 0); | |
305 | } | |
306 | ||
a1218720 | 307 | #endif /* _PSERIES_PLPAR_WRAPPERS_H */ |