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