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
47unsigned long (*xp_socket_pa) (unsigned long gpa);
48EXPORT_SYMBOL_GPL(xp_socket_pa);
49
50enum xp_retval (*xp_remote_memcpy) (unsigned long dst_gpa,
51 const unsigned long src_gpa, size_t len);
52EXPORT_SYMBOL_GPL(xp_remote_memcpy);
53
54int (*xp_cpu_to_nasid) (int cpuid);
55EXPORT_SYMBOL_GPL(xp_cpu_to_nasid);
56
57enum xp_retval (*xp_expand_memprotect) (unsigned long phys_addr,
58 unsigned long size);
59EXPORT_SYMBOL_GPL(xp_expand_memprotect);
60enum xp_retval (*xp_restrict_memprotect) (unsigned long phys_addr,
61 unsigned long size);
62EXPORT_SYMBOL_GPL(xp_restrict_memprotect);
63
64
65
66
67
68struct xpc_registration xpc_registrations[XPC_MAX_NCHANNELS];
69EXPORT_SYMBOL_GPL(xpc_registrations);
70
71
72
73
74struct xpc_interface xpc_interface = { };
75EXPORT_SYMBOL_GPL(xpc_interface);
76
77
78
79
80void
81xpc_set_interface(void (*connect) (int),
82 void (*disconnect) (int),
83 enum xp_retval (*send) (short, int, u32, void *, u16),
84 enum xp_retval (*send_notify) (short, int, u32, void *, u16,
85 xpc_notify_func, void *),
86 void (*received) (short, int, void *),
87 enum xp_retval (*partid_to_nasids) (short, void *))
88{
89 xpc_interface.connect = connect;
90 xpc_interface.disconnect = disconnect;
91 xpc_interface.send = send;
92 xpc_interface.send_notify = send_notify;
93 xpc_interface.received = received;
94 xpc_interface.partid_to_nasids = partid_to_nasids;
95}
96EXPORT_SYMBOL_GPL(xpc_set_interface);
97
98
99
100
101void
102xpc_clear_interface(void)
103{
104 memset(&xpc_interface, 0, sizeof(xpc_interface));
105}
106EXPORT_SYMBOL_GPL(xpc_clear_interface);
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132enum xp_retval
133xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
134 u16 nentries, u32 assigned_limit, u32 idle_limit)
135{
136 struct xpc_registration *registration;
137
138 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
139 DBUG_ON(payload_size == 0 || nentries == 0);
140 DBUG_ON(func == NULL);
141 DBUG_ON(assigned_limit == 0 || idle_limit > assigned_limit);
142
143 if (XPC_MSG_SIZE(payload_size) > XPC_MSG_MAX_SIZE)
144 return xpPayloadTooBig;
145
146 registration = &xpc_registrations[ch_number];
147
148 if (mutex_lock_interruptible(®istration->mutex) != 0)
149 return xpInterrupted;
150
151
152 if (registration->func != NULL) {
153 mutex_unlock(®istration->mutex);
154 return xpAlreadyRegistered;
155 }
156
157
158 registration->entry_size = XPC_MSG_SIZE(payload_size);
159 registration->nentries = nentries;
160 registration->assigned_limit = assigned_limit;
161 registration->idle_limit = idle_limit;
162 registration->key = key;
163 registration->func = func;
164
165 mutex_unlock(®istration->mutex);
166
167 if (xpc_interface.connect)
168 xpc_interface.connect(ch_number);
169
170 return xpSuccess;
171}
172EXPORT_SYMBOL_GPL(xpc_connect);
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187void
188xpc_disconnect(int ch_number)
189{
190 struct xpc_registration *registration;
191
192 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
193
194 registration = &xpc_registrations[ch_number];
195
196
197
198
199
200
201 mutex_lock(®istration->mutex);
202
203
204 if (registration->func == NULL) {
205 mutex_unlock(®istration->mutex);
206 return;
207 }
208
209
210 registration->func = NULL;
211 registration->key = NULL;
212 registration->nentries = 0;
213 registration->entry_size = 0;
214 registration->assigned_limit = 0;
215 registration->idle_limit = 0;
216
217 if (xpc_interface.disconnect)
218 xpc_interface.disconnect(ch_number);
219
220 mutex_unlock(®istration->mutex);
221
222 return;
223}
224EXPORT_SYMBOL_GPL(xpc_disconnect);
225
226int __init
227xp_init(void)
228{
229 enum xp_retval ret;
230 int ch_number;
231
232
233 for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++)
234 mutex_init(&xpc_registrations[ch_number].mutex);
235
236 if (is_shub())
237 ret = xp_init_sn2();
238 else if (is_uv())
239 ret = xp_init_uv();
240 else
241 ret = 0;
242
243 if (ret != xpSuccess)
244 return ret;
245
246 return 0;
247}
248
249module_init(xp_init);
250
251void __exit
252xp_exit(void)
253{
254 if (is_shub())
255 xp_exit_sn2();
256 else if (is_uv())
257 xp_exit_uv();
258}
259
260module_exit(xp_exit);
261
262MODULE_AUTHOR("Silicon Graphics, Inc.");
263MODULE_DESCRIPTION("Cross Partition (XP) base");
264MODULE_LICENSE("GPL");
265