Linux 5.1.15
[linux/fpc-iii.git] / drivers / misc / sgi-xp / xp_main.c
blob6d7f557fd1c1a1e885eb3dad64886b3e0afe32fe
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
6 * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved.
7 */
9 /*
10 * Cross Partition (XP) base.
12 * XP provides a base from which its users can interact
13 * with XPC, yet not be dependent on XPC.
17 #include <linux/module.h>
18 #include <linux/device.h>
19 #include "xp.h"
21 /* define the XP debug device structures to be used with dev_dbg() et al */
23 struct device_driver xp_dbg_name = {
24 .name = "xp"
27 struct device xp_dbg_subname = {
28 .init_name = "", /* set to "" */
29 .driver = &xp_dbg_name
32 struct device *xp = &xp_dbg_subname;
34 /* max #of partitions possible */
35 short xp_max_npartitions;
36 EXPORT_SYMBOL_GPL(xp_max_npartitions);
38 short xp_partition_id;
39 EXPORT_SYMBOL_GPL(xp_partition_id);
41 u8 xp_region_size;
42 EXPORT_SYMBOL_GPL(xp_region_size);
44 unsigned long (*xp_pa) (void *addr);
45 EXPORT_SYMBOL_GPL(xp_pa);
47 unsigned long (*xp_socket_pa) (unsigned long gpa);
48 EXPORT_SYMBOL_GPL(xp_socket_pa);
50 enum xp_retval (*xp_remote_memcpy) (unsigned long dst_gpa,
51 const unsigned long src_gpa, size_t len);
52 EXPORT_SYMBOL_GPL(xp_remote_memcpy);
54 int (*xp_cpu_to_nasid) (int cpuid);
55 EXPORT_SYMBOL_GPL(xp_cpu_to_nasid);
57 enum xp_retval (*xp_expand_memprotect) (unsigned long phys_addr,
58 unsigned long size);
59 EXPORT_SYMBOL_GPL(xp_expand_memprotect);
60 enum xp_retval (*xp_restrict_memprotect) (unsigned long phys_addr,
61 unsigned long size);
62 EXPORT_SYMBOL_GPL(xp_restrict_memprotect);
65 * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level
66 * users of XPC.
68 struct xpc_registration xpc_registrations[XPC_MAX_NCHANNELS];
69 EXPORT_SYMBOL_GPL(xpc_registrations);
72 * Initialize the XPC interface to NULL to indicate that XPC isn't loaded.
74 struct xpc_interface xpc_interface = { };
75 EXPORT_SYMBOL_GPL(xpc_interface);
78 * XPC calls this when it (the XPC module) has been loaded.
80 void
81 xpc_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 *))
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;
96 EXPORT_SYMBOL_GPL(xpc_set_interface);
99 * XPC calls this when it (the XPC module) is being unloaded.
101 void
102 xpc_clear_interface(void)
104 memset(&xpc_interface, 0, sizeof(xpc_interface));
106 EXPORT_SYMBOL_GPL(xpc_clear_interface);
109 * Register for automatic establishment of a channel connection whenever
110 * a partition comes up.
112 * Arguments:
114 * ch_number - channel # to register for connection.
115 * func - function to call for asynchronous notification of channel
116 * state changes (i.e., connection, disconnection, error) and
117 * the arrival of incoming messages.
118 * key - pointer to optional user-defined value that gets passed back
119 * to the user on any callouts made to func.
120 * payload_size - size in bytes of the XPC message's payload area which
121 * contains a user-defined message. The user should make
122 * this large enough to hold their largest message.
123 * nentries - max #of XPC message entries a message queue can contain.
124 * The actual number, which is determined when a connection
125 * is established and may be less then requested, will be
126 * passed to the user via the xpConnected callout.
127 * assigned_limit - max number of kthreads allowed to be processing
128 * messages (per connection) at any given instant.
129 * idle_limit - max number of kthreads allowed to be idle at any given
130 * instant.
132 enum xp_retval
133 xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size,
134 u16 nentries, u32 assigned_limit, u32 idle_limit)
136 struct xpc_registration *registration;
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);
143 if (XPC_MSG_SIZE(payload_size) > XPC_MSG_MAX_SIZE)
144 return xpPayloadTooBig;
146 registration = &xpc_registrations[ch_number];
148 if (mutex_lock_interruptible(&registration->mutex) != 0)
149 return xpInterrupted;
151 /* if XPC_CHANNEL_REGISTERED(ch_number) */
152 if (registration->func != NULL) {
153 mutex_unlock(&registration->mutex);
154 return xpAlreadyRegistered;
157 /* register the channel for connection */
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;
165 mutex_unlock(&registration->mutex);
167 if (xpc_interface.connect)
168 xpc_interface.connect(ch_number);
170 return xpSuccess;
172 EXPORT_SYMBOL_GPL(xpc_connect);
175 * Remove the registration for automatic connection of the specified channel
176 * when a partition comes up.
178 * Before returning this xpc_disconnect() will wait for all connections on the
179 * specified channel have been closed/torndown. So the caller can be assured
180 * that they will not be receiving any more callouts from XPC to their
181 * function registered via xpc_connect().
183 * Arguments:
185 * ch_number - channel # to unregister.
187 void
188 xpc_disconnect(int ch_number)
190 struct xpc_registration *registration;
192 DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS);
194 registration = &xpc_registrations[ch_number];
197 * We've decided not to make this a down_interruptible(), since we
198 * figured XPC's users will just turn around and call xpc_disconnect()
199 * again anyways, so we might as well wait, if need be.
201 mutex_lock(&registration->mutex);
203 /* if !XPC_CHANNEL_REGISTERED(ch_number) */
204 if (registration->func == NULL) {
205 mutex_unlock(&registration->mutex);
206 return;
209 /* remove the connection registration for the specified channel */
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;
217 if (xpc_interface.disconnect)
218 xpc_interface.disconnect(ch_number);
220 mutex_unlock(&registration->mutex);
222 return;
224 EXPORT_SYMBOL_GPL(xpc_disconnect);
226 int __init
227 xp_init(void)
229 enum xp_retval ret;
230 int ch_number;
232 /* initialize the connection registration mutex */
233 for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++)
234 mutex_init(&xpc_registrations[ch_number].mutex);
236 if (is_shub())
237 ret = xp_init_sn2();
238 else if (is_uv())
239 ret = xp_init_uv();
240 else
241 ret = 0;
243 if (ret != xpSuccess)
244 return ret;
246 return 0;
249 module_init(xp_init);
251 void __exit
252 xp_exit(void)
254 if (is_shub())
255 xp_exit_sn2();
256 else if (is_uv())
257 xp_exit_uv();
260 module_exit(xp_exit);
262 MODULE_AUTHOR("Silicon Graphics, Inc.");
263 MODULE_DESCRIPTION("Cross Partition (XP) base");
264 MODULE_LICENSE("GPL");