blob: a05f8d427856c39767e1627fab0c44b4f3b8cd35 [file] [log] [blame]
Michael Ellermana1218722005-11-03 15:33:31 +11001#ifndef _PSERIES_PLPAR_WRAPPERS_H
2#define _PSERIES_PLPAR_WRAPPERS_H
3
4#include <asm/hvcall.h>
Brian King370e4582008-08-16 05:09:33 +10005#include <asm/page.h>
Michael Ellermana1218722005-11-03 15:33:31 +11006
7static inline long poll_pending(void)
8{
Anton Blanchardb9377ff2006-07-19 08:01:28 +10009 return plpar_hcall_norets(H_POLL_PENDING);
Michael Ellermana1218722005-11-03 15:33:31 +110010}
11
Gautham R Shenoy69ddb572009-10-29 19:22:48 +000012static inline u8 get_cede_latency_hint(void)
13{
14 return get_lppaca()->gpr5_dword.fields.cede_latency_hint;
15}
16
17static inline void set_cede_latency_hint(u8 latency_hint)
18{
19 get_lppaca()->gpr5_dword.fields.cede_latency_hint = latency_hint;
20}
21
Michael Ellermana1218722005-11-03 15:33:31 +110022static inline long cede_processor(void)
23{
Anton Blanchardb9377ff2006-07-19 08:01:28 +100024 return plpar_hcall_norets(H_CEDE);
Michael Ellermana1218722005-11-03 15:33:31 +110025}
26
Gautham R Shenoy69ddb572009-10-29 19:22:48 +000027static 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 Ellerman40765d22005-11-03 19:34:38 +110039static inline long vpa_call(unsigned long flags, unsigned long cpu,
Michael Ellermana1218722005-11-03 15:33:31 +110040 unsigned long vpa)
41{
Michael Ellerman40765d22005-11-03 19:34:38 +110042 /* 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 Ellermana1218722005-11-03 15:33:31 +110046}
47
Michael Ellerman40765d22005-11-03 19:34:38 +110048static inline long unregister_vpa(unsigned long cpu, unsigned long vpa)
49{
50 return vpa_call(0x5, cpu, vpa);
51}
52
53static inline long register_vpa(unsigned long cpu, unsigned long vpa)
54{
55 return vpa_call(0x1, cpu, vpa);
56}
57
Michael Neuling2f6093c2006-08-07 16:19:19 +100058static inline long unregister_slb_shadow(unsigned long cpu, unsigned long vpa)
59{
60 return vpa_call(0x7, cpu, vpa);
61}
62
63static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa)
64{
65 return vpa_call(0x3, cpu, vpa);
66}
67
Jeremy Kerrfc59a3f2009-03-11 17:55:52 +000068static inline long unregister_dtl(unsigned long cpu, unsigned long vpa)
69{
70 return vpa_call(0x6, cpu, vpa);
71}
72
73static inline long register_dtl(unsigned long cpu, unsigned long vpa)
74{
75 return vpa_call(0x2, cpu, vpa);
76}
77
Brian King86630a32008-07-24 04:29:16 +100078static inline long plpar_page_set_loaned(unsigned long vpa)
79{
Brian King370e4582008-08-16 05:09:33 +100080 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 King86630a32008-07-24 04:29:16 +100092}
93
94static inline long plpar_page_set_active(unsigned long vpa)
95{
Brian King370e4582008-08-16 05:09:33 +100096 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 King86630a32008-07-24 04:29:16 +1000108}
109
Michael Ellerman40765d22005-11-03 19:34:38 +1100110extern void vpa_init(int cpu);
Michael Ellermana1218722005-11-03 15:33:31 +1100111
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000112static 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 Ellermana1218722005-11-03 15:33:31 +1100126static 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 Blanchardb9377ff2006-07-19 08:01:28 +1000130 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 Ellermana1218722005-11-03 15:33:31 +1100139}
140
Mohan Kumar Mb4aea362007-03-21 11:21:32 +0530141/* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */
142static 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 Ellermana1218722005-11-03 15:33:31 +1100157static inline long plpar_pte_read(unsigned long flags, unsigned long ptex,
158 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
159{
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000160 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 Ellermana1218722005-11-03 15:33:31 +1100169}
170
Sachin P. Santb7abc5c2007-06-14 15:31:34 +1000171/* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */
172static 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 Ellermana1218722005-11-03 15:33:31 +1100186static 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
192static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba,
193 unsigned long *tce_ret)
194{
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000195 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 Ellermana1218722005-11-03 15:33:31 +1100203}
204
205static 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
211static 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
217static 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
223static inline long plpar_get_term_char(unsigned long termno,
224 unsigned long *len_ret, char *buf_ret)
225{
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000226 long rc;
227 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
Michael Ellermana1218722005-11-03 15:33:31 +1100228 unsigned long *lbuf = (unsigned long *)buf_ret; /* TODO: alignment? */
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000229
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 Ellermana1218722005-11-03 15:33:31 +1100237}
238
239static 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 Blanchardb9377ff2006-07-19 08:01:28 +1000247static inline long plpar_eoi(unsigned long xirr)
248{
249 return plpar_hcall_norets(H_EOI, xirr);
250}
251
252static inline long plpar_cppr(unsigned long cppr)
253{
254 return plpar_hcall_norets(H_CPPR, cppr);
255}
256
257static inline long plpar_ipi(unsigned long servernum, unsigned long mfrr)
258{
259 return plpar_hcall_norets(H_IPI, servernum, mfrr);
260}
261
Mark Nelsonf09b7b22010-01-31 20:12:58 +0000262static inline long plpar_xirr(unsigned long *xirr_ret, unsigned char cppr)
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000263{
264 long rc;
265 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
266
Mark Nelsonf09b7b22010-01-31 20:12:58 +0000267 rc = plpar_hcall(H_XIRR, retbuf, cppr);
Anton Blanchardb9377ff2006-07-19 08:01:28 +1000268
269 *xirr_ret = retbuf[0];
270
271 return rc;
272}
273
Michael Ellermana1218722005-11-03 15:33:31 +1100274#endif /* _PSERIES_PLPAR_WRAPPERS_H */