Merge branch 'x86-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6] / arch / powerpc / platforms / pseries / plpar_wrappers.h
1 #ifndef _PSERIES_PLPAR_WRAPPERS_H
2 #define _PSERIES_PLPAR_WRAPPERS_H
3
4 #include <asm/hvcall.h>
5 #include <asm/page.h>
6
7 static inline long poll_pending(void)
8 {
9         return plpar_hcall_norets(H_POLL_PENDING);
10 }
11
12 static inline long cede_processor(void)
13 {
14         return plpar_hcall_norets(H_CEDE);
15 }
16
17 static inline long vpa_call(unsigned long flags, unsigned long cpu,
18                 unsigned long vpa)
19 {
20         /* flags are in bits 16-18 (counting from most significant bit) */
21         flags = flags << (63 - 18);
22
23         return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa);
24 }
25
26 static inline long unregister_vpa(unsigned long cpu, unsigned long vpa)
27 {
28         return vpa_call(0x5, cpu, vpa);
29 }
30
31 static inline long register_vpa(unsigned long cpu, unsigned long vpa)
32 {
33         return vpa_call(0x1, cpu, vpa);
34 }
35
36 static inline long unregister_slb_shadow(unsigned long cpu, unsigned long vpa)
37 {
38         return vpa_call(0x7, cpu, vpa);
39 }
40
41 static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa)
42 {
43         return vpa_call(0x3, cpu, vpa);
44 }
45
46 static inline long plpar_page_set_loaned(unsigned long vpa)
47 {
48         unsigned long cmo_page_sz = cmo_get_page_size();
49         long rc = 0;
50         int i;
51
52         for (i = 0; !rc && i < PAGE_SIZE; i += cmo_page_sz)
53                 rc = plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_LOANED, vpa + i, 0);
54
55         for (i -= cmo_page_sz; rc && i != 0; i -= cmo_page_sz)
56                 plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_ACTIVE,
57                                    vpa + i - cmo_page_sz, 0);
58
59         return rc;
60 }
61
62 static inline long plpar_page_set_active(unsigned long vpa)
63 {
64         unsigned long cmo_page_sz = cmo_get_page_size();
65         long rc = 0;
66         int i;
67
68         for (i = 0; !rc && i < PAGE_SIZE; i += cmo_page_sz)
69                 rc = plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_ACTIVE, vpa + i, 0);
70
71         for (i -= cmo_page_sz; rc && i != 0; i -= cmo_page_sz)
72                 plpar_hcall_norets(H_PAGE_INIT, H_PAGE_SET_LOANED,
73                                    vpa + i - cmo_page_sz, 0);
74
75         return rc;
76 }
77
78 extern void vpa_init(int cpu);
79
80 static inline long plpar_pte_enter(unsigned long flags,
81                 unsigned long hpte_group, unsigned long hpte_v,
82                 unsigned long hpte_r, unsigned long *slot)
83 {
84         long rc;
85         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
86
87         rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r);
88
89         *slot = retbuf[0];
90
91         return rc;
92 }
93
94 static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex,
95                 unsigned long avpn, unsigned long *old_pteh_ret,
96                 unsigned long *old_ptel_ret)
97 {
98         long rc;
99         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
100
101         rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn);
102
103         *old_pteh_ret = retbuf[0];
104         *old_ptel_ret = retbuf[1];
105
106         return rc;
107 }
108
109 /* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */
110 static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex,
111                 unsigned long avpn, unsigned long *old_pteh_ret,
112                 unsigned long *old_ptel_ret)
113 {
114         long rc;
115         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
116
117         rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn);
118
119         *old_pteh_ret = retbuf[0];
120         *old_ptel_ret = retbuf[1];
121
122         return rc;
123 }
124
125 static inline long plpar_pte_read(unsigned long flags, unsigned long ptex,
126                 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
127 {
128         long rc;
129         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
130
131         rc = plpar_hcall(H_READ, retbuf, flags, ptex);
132
133         *old_pteh_ret = retbuf[0];
134         *old_ptel_ret = retbuf[1];
135
136         return rc;
137 }
138
139 /* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */
140 static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex,
141                 unsigned long *old_pteh_ret, unsigned long *old_ptel_ret)
142 {
143         long rc;
144         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
145
146         rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex);
147
148         *old_pteh_ret = retbuf[0];
149         *old_ptel_ret = retbuf[1];
150
151         return rc;
152 }
153
154 static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex,
155                 unsigned long avpn)
156 {
157         return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn);
158 }
159
160 static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba,
161                 unsigned long *tce_ret)
162 {
163         long rc;
164         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
165
166         rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba);
167
168         *tce_ret = retbuf[0];
169
170         return rc;
171 }
172
173 static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba,
174                 unsigned long tceval)
175 {
176         return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval);
177 }
178
179 static inline long plpar_tce_put_indirect(unsigned long liobn,
180                 unsigned long ioba, unsigned long page, unsigned long count)
181 {
182         return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count);
183 }
184
185 static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba,
186                 unsigned long tceval, unsigned long count)
187 {
188         return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count);
189 }
190
191 static inline long plpar_get_term_char(unsigned long termno,
192                 unsigned long *len_ret, char *buf_ret)
193 {
194         long rc;
195         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
196         unsigned long *lbuf = (unsigned long *)buf_ret; /* TODO: alignment? */
197
198         rc = plpar_hcall(H_GET_TERM_CHAR, retbuf, termno);
199
200         *len_ret = retbuf[0];
201         lbuf[0] = retbuf[1];
202         lbuf[1] = retbuf[2];
203
204         return rc;
205 }
206
207 static inline long plpar_put_term_char(unsigned long termno, unsigned long len,
208                 const char *buffer)
209 {
210         unsigned long *lbuf = (unsigned long *)buffer;  /* TODO: alignment? */
211         return plpar_hcall_norets(H_PUT_TERM_CHAR, termno, len, lbuf[0],
212                         lbuf[1]);
213 }
214
215 static inline long plpar_eoi(unsigned long xirr)
216 {
217         return plpar_hcall_norets(H_EOI, xirr);
218 }
219
220 static inline long plpar_cppr(unsigned long cppr)
221 {
222         return plpar_hcall_norets(H_CPPR, cppr);
223 }
224
225 static inline long plpar_ipi(unsigned long servernum, unsigned long mfrr)
226 {
227         return plpar_hcall_norets(H_IPI, servernum, mfrr);
228 }
229
230 static inline long plpar_xirr(unsigned long *xirr_ret)
231 {
232         long rc;
233         unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
234
235         rc = plpar_hcall(H_XIRR, retbuf);
236
237         *xirr_ret = retbuf[0];
238
239         return rc;
240 }
241
242 #endif /* _PSERIES_PLPAR_WRAPPERS_H */