Commit | Line | Data |
---|---|---|
b0d82bd5 DN |
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. | |
5 | * | |
7a6d94f0 | 6 | * (C) Copyright 2020 Hewlett Packard Enterprise Development LP |
45d9ca49 | 7 | * Copyright (c) 2004-2008 Silicon Graphics, Inc. All Rights Reserved. |
b0d82bd5 DN |
8 | */ |
9 | ||
b0d82bd5 DN |
10 | /* |
11 | * Cross Partition (XP) base. | |
12 | * | |
13 | * XP provides a base from which its users can interact | |
14 | * with XPC, yet not be dependent on XPC. | |
15 | * | |
16 | */ | |
17 | ||
b0d82bd5 | 18 | #include <linux/module.h> |
bc63d387 | 19 | #include <linux/device.h> |
45d9ca49 | 20 | #include "xp.h" |
b0d82bd5 | 21 | |
bc63d387 | 22 | /* define the XP debug device structures to be used with dev_dbg() et al */ |
2c2b94f9 | 23 | |
d0e87470 | 24 | static struct device_driver xp_dbg_name = { |
bc63d387 DN |
25 | .name = "xp" |
26 | }; | |
27 | ||
d0e87470 | 28 | static struct device xp_dbg_subname = { |
bb0dc43e | 29 | .init_name = "", /* set to "" */ |
bc63d387 DN |
30 | .driver = &xp_dbg_name |
31 | }; | |
32 | ||
33 | struct device *xp = &xp_dbg_subname; | |
34 | ||
35 | /* max #of partitions possible */ | |
36 | short xp_max_npartitions; | |
37 | EXPORT_SYMBOL_GPL(xp_max_npartitions); | |
b0d82bd5 | 38 | |
261f3b49 DN |
39 | short xp_partition_id; |
40 | EXPORT_SYMBOL_GPL(xp_partition_id); | |
41 | ||
42 | u8 xp_region_size; | |
43 | EXPORT_SYMBOL_GPL(xp_region_size); | |
44 | ||
a812dcc3 DN |
45 | unsigned long (*xp_pa) (void *addr); |
46 | EXPORT_SYMBOL_GPL(xp_pa); | |
47 | ||
68212893 RH |
48 | unsigned long (*xp_socket_pa) (unsigned long gpa); |
49 | EXPORT_SYMBOL_GPL(xp_socket_pa); | |
50 | ||
a812dcc3 DN |
51 | enum xp_retval (*xp_remote_memcpy) (unsigned long dst_gpa, |
52 | const unsigned long src_gpa, size_t len); | |
908787db DN |
53 | EXPORT_SYMBOL_GPL(xp_remote_memcpy); |
54 | ||
261f3b49 DN |
55 | int (*xp_cpu_to_nasid) (int cpuid); |
56 | EXPORT_SYMBOL_GPL(xp_cpu_to_nasid); | |
57 | ||
6c1c325d DN |
58 | enum xp_retval (*xp_expand_memprotect) (unsigned long phys_addr, |
59 | unsigned long size); | |
60 | EXPORT_SYMBOL_GPL(xp_expand_memprotect); | |
61 | enum xp_retval (*xp_restrict_memprotect) (unsigned long phys_addr, | |
62 | unsigned long size); | |
63 | EXPORT_SYMBOL_GPL(xp_restrict_memprotect); | |
64 | ||
b0d82bd5 DN |
65 | /* |
66 | * xpc_registrations[] keeps track of xpc_connect()'s done by the kernel-level | |
67 | * users of XPC. | |
68 | */ | |
bc63d387 | 69 | struct xpc_registration xpc_registrations[XPC_MAX_NCHANNELS]; |
2c2b94f9 | 70 | EXPORT_SYMBOL_GPL(xpc_registrations); |
b0d82bd5 | 71 | |
b0d82bd5 | 72 | /* |
234041df | 73 | * Initialize the XPC interface to NULL to indicate that XPC isn't loaded. |
b0d82bd5 | 74 | */ |
234041df | 75 | struct xpc_interface xpc_interface = { }; |
2c2b94f9 | 76 | EXPORT_SYMBOL_GPL(xpc_interface); |
b0d82bd5 | 77 | |
b0d82bd5 DN |
78 | /* |
79 | * XPC calls this when it (the XPC module) has been loaded. | |
80 | */ | |
81 | void | |
4a3ad2dd DN |
82 | xpc_set_interface(void (*connect) (int), |
83 | void (*disconnect) (int), | |
97bf1aa1 DN |
84 | enum xp_retval (*send) (short, int, u32, void *, u16), |
85 | enum xp_retval (*send_notify) (short, int, u32, void *, u16, | |
4a3ad2dd | 86 | xpc_notify_func, void *), |
64d032ba DN |
87 | void (*received) (short, int, void *), |
88 | enum xp_retval (*partid_to_nasids) (short, void *)) | |
b0d82bd5 DN |
89 | { |
90 | xpc_interface.connect = connect; | |
91 | xpc_interface.disconnect = disconnect; | |
b0d82bd5 DN |
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 | } | |
2c2b94f9 | 97 | EXPORT_SYMBOL_GPL(xpc_set_interface); |
b0d82bd5 | 98 | |
b0d82bd5 DN |
99 | /* |
100 | * XPC calls this when it (the XPC module) is being unloaded. | |
101 | */ | |
102 | void | |
103 | xpc_clear_interface(void) | |
104 | { | |
234041df | 105 | memset(&xpc_interface, 0, sizeof(xpc_interface)); |
b0d82bd5 | 106 | } |
2c2b94f9 | 107 | EXPORT_SYMBOL_GPL(xpc_clear_interface); |
b0d82bd5 | 108 | |
b0d82bd5 DN |
109 | /* |
110 | * Register for automatic establishment of a channel connection whenever | |
111 | * a partition comes up. | |
112 | * | |
113 | * Arguments: | |
114 | * | |
115 | * ch_number - channel # to register for connection. | |
116 | * func - function to call for asynchronous notification of channel | |
117 | * state changes (i.e., connection, disconnection, error) and | |
118 | * the arrival of incoming messages. | |
119 | * key - pointer to optional user-defined value that gets passed back | |
120 | * to the user on any callouts made to func. | |
121 | * payload_size - size in bytes of the XPC message's payload area which | |
122 | * contains a user-defined message. The user should make | |
123 | * this large enough to hold their largest message. | |
124 | * nentries - max #of XPC message entries a message queue can contain. | |
125 | * The actual number, which is determined when a connection | |
126 | * is established and may be less then requested, will be | |
65c17b80 | 127 | * passed to the user via the xpConnected callout. |
b0d82bd5 DN |
128 | * assigned_limit - max number of kthreads allowed to be processing |
129 | * messages (per connection) at any given instant. | |
130 | * idle_limit - max number of kthreads allowed to be idle at any given | |
131 | * instant. | |
132 | */ | |
65c17b80 | 133 | enum xp_retval |
b0d82bd5 | 134 | xpc_connect(int ch_number, xpc_channel_func func, void *key, u16 payload_size, |
4a3ad2dd | 135 | u16 nentries, u32 assigned_limit, u32 idle_limit) |
b0d82bd5 DN |
136 | { |
137 | struct xpc_registration *registration; | |
138 | ||
bc63d387 | 139 | DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS); |
b0d82bd5 DN |
140 | DBUG_ON(payload_size == 0 || nentries == 0); |
141 | DBUG_ON(func == NULL); | |
142 | DBUG_ON(assigned_limit == 0 || idle_limit > assigned_limit); | |
143 | ||
bd3e64c1 DN |
144 | if (XPC_MSG_SIZE(payload_size) > XPC_MSG_MAX_SIZE) |
145 | return xpPayloadTooBig; | |
146 | ||
b0d82bd5 DN |
147 | registration = &xpc_registrations[ch_number]; |
148 | ||
2c2b94f9 | 149 | if (mutex_lock_interruptible(®istration->mutex) != 0) |
65c17b80 | 150 | return xpInterrupted; |
b0d82bd5 DN |
151 | |
152 | /* if XPC_CHANNEL_REGISTERED(ch_number) */ | |
153 | if (registration->func != NULL) { | |
f9e505a9 | 154 | mutex_unlock(®istration->mutex); |
65c17b80 | 155 | return xpAlreadyRegistered; |
b0d82bd5 DN |
156 | } |
157 | ||
158 | /* register the channel for connection */ | |
bd3e64c1 | 159 | registration->entry_size = XPC_MSG_SIZE(payload_size); |
b0d82bd5 DN |
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 | ||
f9e505a9 | 166 | mutex_unlock(®istration->mutex); |
b0d82bd5 | 167 | |
234041df KC |
168 | if (xpc_interface.connect) |
169 | xpc_interface.connect(ch_number); | |
b0d82bd5 | 170 | |
65c17b80 | 171 | return xpSuccess; |
b0d82bd5 | 172 | } |
2c2b94f9 | 173 | EXPORT_SYMBOL_GPL(xpc_connect); |
b0d82bd5 | 174 | |
b0d82bd5 DN |
175 | /* |
176 | * Remove the registration for automatic connection of the specified channel | |
177 | * when a partition comes up. | |
178 | * | |
179 | * Before returning this xpc_disconnect() will wait for all connections on the | |
180 | * specified channel have been closed/torndown. So the caller can be assured | |
181 | * that they will not be receiving any more callouts from XPC to their | |
182 | * function registered via xpc_connect(). | |
183 | * | |
184 | * Arguments: | |
185 | * | |
186 | * ch_number - channel # to unregister. | |
187 | */ | |
188 | void | |
189 | xpc_disconnect(int ch_number) | |
190 | { | |
191 | struct xpc_registration *registration; | |
192 | ||
bc63d387 | 193 | DBUG_ON(ch_number < 0 || ch_number >= XPC_MAX_NCHANNELS); |
b0d82bd5 DN |
194 | |
195 | registration = &xpc_registrations[ch_number]; | |
196 | ||
197 | /* | |
198 | * We've decided not to make this a down_interruptible(), since we | |
199 | * figured XPC's users will just turn around and call xpc_disconnect() | |
200 | * again anyways, so we might as well wait, if need be. | |
201 | */ | |
f9e505a9 | 202 | mutex_lock(®istration->mutex); |
b0d82bd5 DN |
203 | |
204 | /* if !XPC_CHANNEL_REGISTERED(ch_number) */ | |
205 | if (registration->func == NULL) { | |
f9e505a9 | 206 | mutex_unlock(®istration->mutex); |
b0d82bd5 DN |
207 | return; |
208 | } | |
209 | ||
210 | /* remove the connection registration for the specified channel */ | |
211 | registration->func = NULL; | |
212 | registration->key = NULL; | |
213 | registration->nentries = 0; | |
bd3e64c1 | 214 | registration->entry_size = 0; |
b0d82bd5 DN |
215 | registration->assigned_limit = 0; |
216 | registration->idle_limit = 0; | |
217 | ||
234041df KC |
218 | if (xpc_interface.disconnect) |
219 | xpc_interface.disconnect(ch_number); | |
b0d82bd5 | 220 | |
f9e505a9 | 221 | mutex_unlock(®istration->mutex); |
b0d82bd5 DN |
222 | |
223 | return; | |
224 | } | |
2c2b94f9 | 225 | EXPORT_SYMBOL_GPL(xpc_disconnect); |
b0d82bd5 | 226 | |
95ef32cd | 227 | static int __init |
b0d82bd5 DN |
228 | xp_init(void) |
229 | { | |
bc63d387 DN |
230 | enum xp_retval ret; |
231 | int ch_number; | |
b0d82bd5 | 232 | |
e873cff0 RH |
233 | /* initialize the connection registration mutex */ |
234 | for (ch_number = 0; ch_number < XPC_MAX_NCHANNELS; ch_number++) | |
235 | mutex_init(&xpc_registrations[ch_number].mutex); | |
236 | ||
788b66e3 | 237 | if (is_uv_system()) |
bc63d387 | 238 | ret = xp_init_uv(); |
2c2b94f9 | 239 | else |
e873cff0 | 240 | ret = 0; |
bc63d387 DN |
241 | |
242 | if (ret != xpSuccess) | |
e873cff0 | 243 | return ret; |
b0d82bd5 DN |
244 | |
245 | return 0; | |
246 | } | |
b0d82bd5 | 247 | |
4a3ad2dd | 248 | module_init(xp_init); |
b0d82bd5 | 249 | |
95ef32cd | 250 | static void __exit |
b0d82bd5 DN |
251 | xp_exit(void) |
252 | { | |
788b66e3 | 253 | if (is_uv_system()) |
bc63d387 | 254 | xp_exit_uv(); |
b0d82bd5 | 255 | } |
b0d82bd5 | 256 | |
4a3ad2dd | 257 | module_exit(xp_exit); |
b0d82bd5 DN |
258 | |
259 | MODULE_AUTHOR("Silicon Graphics, Inc."); | |
260 | MODULE_DESCRIPTION("Cross Partition (XP) base"); | |
261 | MODULE_LICENSE("GPL"); |