1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/module.h>
18#include <linux/device.h>
19#include "xp.h"
20
21
22
23struct device_driver xp_dbg_name = {
24 .name = "xp"
25};
26
27struct device xp_dbg_subname = {
28 .init_name = "",
29 .driver = &xp_dbg_name
30};
31
32struct device *xp = &xp_dbg_subname;
33
34
35short xp_max_npartitions;
36EXPORT_SYMBOL_GPL(xp_max_npartitions);
37
38short xp_partition_id;
39EXPORT_SYMBOL_GPL(xp_partition_id);
40
41u8 xp_region_size;
42EXPORT_SYMBOL_GPL(xp_region_size);
43
44unsigned long (*xp_pa) (void *addr);
45EXPORT_SYMBOL_GPL(xp_pa);
46
47enum xp_retval (*xp_remote_memcpy) (unsigned long dst_gpa,
48 const unsigned long src_gpa, size_t len);
49EXPORT_SYMBOL_GPL(xp_remote_memcpy);
50
51int (*xp_cpu_to_nasid) (int cpuid);
52EXPORT_SYMBOL_GPL(xp_cpu_to_nasid);
53
54enum xp_retval (*xp_expand_memprotect) (unsigned long phys_addr,
55 unsigned long size);
56EXPORT_SYMBOL_GPL(xp_expand_memprotect);
57enum xp_retval (*xp_restrict_memprotect) (unsigned long phys_addr,
58 unsigned long size);
59EXPORT_SYMBOL_GPL(xp_restrict_memprotect);
60
61
62
63
64
65struct xpc_registration xpc_registrations[XPC_MAX_NCHANNELS];
66EXPORT_SYMBOL_GPL(xpc_registrations);
67
68
69
70
71static enum xp_retval
72xpc_notloaded(void)
73{
74 return xpNotLoaded;
75}
76
77struct xpc_interface xpc_interface = {
78 (void (*)(int))xpc_notloaded,
79 (void (*)(int))xpc_notloaded,
80 (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
81 (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
82 void *))xpc_notloaded,
83 (void (*)(short, int, void *))xpc_notloaded,
84 (enum xp_retval(*)(short, void *))xpc_notloaded
85};
86EXPORT_SYMBOL_GPL(xpc_interface);
87
88
89
90
91void
92xpc_set_interface(void (*connect) (int),
93 void (*disconnect) (int),
94 enum xp_retval (*send) (short, int, u32, void *, u16),
95 enum xp_retval (*send_notify) (short, int, u32, void *, u16,
96 xpc_notify_func, void *),
97 void (*received) (short, int, void *),
98 enum xp_retval (*partid_to_nasids) (short, void *))
99{
100 xpc_interface.connect = connect;
101 xpc_interface.disconnect = disconnect;
102 xpc_interface.send = send;
103 xpc_interface.send_notify = send_notify;
104 xpc_interface.received = received;
105 xpc_interface.partid_to_nasids = partid_to_nasids;
106}
107EXPORT_SYMBOL_GPL(xpc_set_interface);
108
109
110
111
112void
113xpc_clear_interface(void)
114{
115 xpc_interface.connect = (void (*)(int))xpc_notloaded;
116 xpc_interface.disconnect = (void (*)(int))xpc_notloaded;
117 xpc_interface.send = (enum xp_retval(*)(short, int, u32, void *, u16))
118 xpc_notloaded;
119 xpc_interface.send_notify = (enum xp_retval(*)(short, int, u32, void *,
120 u16, xpc_notify_func,
121 void *))xpc_notloaded;
122 xpc_interface.received = (void (*)(short, int, void *))
123 xpc_notloaded;
124 xpc_interface.partid_to_nasids = (enum xp_retval(*)(short, void *))
125 xpc_notloaded;
126}
127EXPORT_SYMBOL_GPL(xpc_clear_interface);
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153enum xp_retval
154xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
155 u16 nentries, u32 assigned_limit, u32 idle_limit)
156{
157 struct xpc_registration *registration;
158
159 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
160 DBUG_ON(payload_size == 0 || nentries == 0);
161 DBUG_ON(func == NULL);
162 DBUG_ON(assigned_limit == 0 || idle_limit > assigned_limit);
163
164 if (XPC_MSG_SIZE(payload_size) > XPC_MSG_MAX_SIZE)
165 return xpPayloadTooBig;
166
167 registration = &xpc_registrations[ch_number];
168
169 if (mutex_lock_interruptible(®istration->mutex) != 0)
170 return xpInterrupted;
171
172
173 if (registration->func != NULL) {
174 mutex_unlock(®istration->mutex);
175 return xpAlreadyRegistered;
176 }
177
178
179 registration->entry_size = XPC_MSG_SIZE(payload_size);
180 registration->nentries = nentries;
181 registration->assigned_limit = assigned_limit;
182 registration->idle_limit = idle_limit;
183 registration->key = key;
184 registration->func = func;
185
186 mutex_unlock(®istration->mutex);
187
188 xpc_interface.connect(ch_number);
189
190 return xpSuccess;
191}
192EXPORT_SYMBOL_GPL(xpc_connect);
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207void
208xpc_disconnect(int ch_number)
209{
210 struct xpc_registration *registration;
211
212 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
213
214 registration = &xpc_registrations[ch_number];
215
216
217
218
219
220
221 mutex_lock(®istration->mutex);
222
223
224 if (registration->func == NULL) {
225 mutex_unlock(®istration->mutex);
226 return;
227 }
228
229
230 registration->func = NULL;
231 registration->key = NULL;
232 registration->nentries = 0;
233 registration->entry_size = 0;
234 registration->assigned_limit = 0;
235 registration->idle_limit = 0;
236
237 xpc_interface.disconnect(ch_number);
238
239 mutex_unlock(®istration->mutex);
240
241 return;
242}
243EXPORT_SYMBOL_GPL(xpc_disconnect);
244
245int __init
246xp_init(void)
247{
248 enum xp_retval ret;
249 int ch_number;
250
251
252 for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++)
253 mutex_init(&xpc_registrations[ch_number].mutex);
254
255 if (is_shub())
256 ret = xp_init_sn2();
257 else if (is_uv())
258 ret = xp_init_uv();
259 else
260 ret = 0;
261
262 if (ret != xpSuccess)
263 return ret;
264
265 return 0;
266}
267
268module_init(xp_init);
269
270void __exit
271xp_exit(void)
272{
273 if (is_shub())
274 xp_exit_sn2();
275 else if (is_uv())
276 xp_exit_uv();
277}
278
279module_exit(xp_exit);
280
281MODULE_AUTHOR("Silicon Graphics, Inc.");
282MODULE_DESCRIPTION("Cross Partition (XP) base");
283MODULE_LICENSE("GPL");
284