Commit | Line | Data |
---|---|---|
3703987c EA |
1 | /* visorbus_main.c |
2 | * | |
3 | * Copyright � 2010 - 2013 UNISYS CORPORATION | |
4 | * All rights reserved. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or (at | |
9 | * your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | |
14 | * NON INFRINGEMENT. See the GNU General Public License for more | |
15 | * details. | |
16 | */ | |
17 | ||
18 | #include <linux/uuid.h> | |
19 | ||
20 | #include "visorbus_private.h" | |
a9a7c767 | 21 | #include "timskmod.h" |
3703987c EA |
22 | #include "channel_attr.h" |
23 | #include "devmajorminor_attr.h" | |
24 | #include "periodic_work.h" | |
25 | #include "vbuschannel.h" | |
26 | #include "guestlinuxdebug.h" | |
27 | #include "vbusdeviceinfo.h" | |
28 | /* These forward declarations are required since our drivers are out-of-tree. | |
29 | * The structures referenced are kernel-private and are not in the headers, but | |
30 | * it is impossible to make a functioning bus driver without them. | |
31 | */ | |
32 | struct subsys_private { | |
33 | struct kset subsys; | |
34 | struct kset *devices_kset; | |
35 | ||
36 | struct kset *drivers_kset; | |
37 | struct klist klist_devices; | |
38 | struct klist klist_drivers; | |
39 | struct blocking_notifier_head bus_notifier; | |
40 | unsigned int drivers_autoprobe:1; | |
41 | struct bus_type *bus; | |
42 | ||
43 | struct list_head class_interfaces; | |
44 | struct kset glue_dirs; | |
45 | struct mutex class_mutex; /* ignore */ | |
46 | struct class *class; | |
47 | }; | |
48 | ||
49 | struct bus_type_private { | |
50 | struct kset subsys; | |
51 | struct kset *drivers_kset; | |
52 | struct kset *devices_kset; | |
53 | struct klist klist_devices; | |
54 | struct klist klist_drivers; | |
55 | struct blocking_notifier_head bus_notifier; | |
56 | unsigned int drivers_autoprobe:1; | |
57 | struct bus_type *bus; | |
58 | }; | |
59 | ||
60 | #define CURRENT_FILE_PC VISOR_BUS_PC_visorbus_main_c | |
61 | #define POLLJIFFIES_TESTWORK 100 | |
62 | #define POLLJIFFIES_NORMALCHANNEL 10 | |
63 | ||
64 | static int visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env); | |
65 | static int visorbus_match(struct device *xdev, struct device_driver *xdrv); | |
66 | static void fix_vbus_dev_info(struct visor_device *visordev); | |
67 | ||
68 | /** This describes the TYPE of bus. | |
69 | * (Don't confuse this with an INSTANCE of the bus.) | |
70 | */ | |
71 | static struct bus_type visorbus_type = { | |
72 | .name = "visorbus", | |
73 | .match = visorbus_match, | |
74 | .uevent = visorbus_uevent, | |
75 | }; | |
76 | ||
77 | static struct delayed_work periodic_work; | |
78 | ||
79 | /* YES, we need 2 workqueues. | |
80 | * The reason is, workitems on the test queue may need to cancel | |
81 | * workitems on the other queue. You will be in for trouble if you try to | |
82 | * do this with workitems queued on the same workqueue. | |
83 | */ | |
84 | static struct workqueue_struct *periodic_test_workqueue; | |
85 | static struct workqueue_struct *periodic_dev_workqueue; | |
86 | static long long bus_count; /** number of bus instances */ | |
87 | static long long total_devices_created; | |
88 | /** ever-increasing */ | |
89 | ||
90 | static void chipset_bus_create(u32 bus_no); | |
91 | static void chipset_bus_destroy(u32 bus_no); | |
92 | static void chipset_device_create(u32 bus_no, u32 dev_no); | |
93 | static void chipset_device_destroy(u32 bus_no, u32 dev_no); | |
94 | static void chipset_device_pause(u32 bus_no, u32 dev_no); | |
95 | static void chipset_device_resume(u32 bus_no, u32 dev_no); | |
96 | ||
97 | /** These functions are implemented herein, and are called by the chipset | |
98 | * driver to notify us about specific events. | |
99 | */ | |
100 | static struct visorchipset_busdev_notifiers chipset_notifiers = { | |
101 | .bus_create = chipset_bus_create, | |
102 | .bus_destroy = chipset_bus_destroy, | |
103 | .device_create = chipset_device_create, | |
104 | .device_destroy = chipset_device_destroy, | |
105 | .device_pause = chipset_device_pause, | |
106 | .device_resume = chipset_device_resume, | |
107 | }; | |
108 | ||
109 | /** These functions are implemented in the chipset driver, and we call them | |
110 | * herein when we want to acknowledge a specific event. | |
111 | */ | |
112 | static struct visorchipset_busdev_responders chipset_responders; | |
113 | ||
114 | /* filled in with info about parent chipset driver when we register with it */ | |
115 | static struct ultra_vbus_deviceinfo chipset_driverinfo; | |
116 | /* filled in with info about this driver, wrt it servicing client busses */ | |
117 | static struct ultra_vbus_deviceinfo clientbus_driverinfo; | |
118 | ||
119 | /** list of visorbus_devdata structs, linked via .list_all */ | |
120 | static LIST_HEAD(list_all_bus_instances); | |
121 | /** list of visor_device structs, linked via .list_all */ | |
122 | static LIST_HEAD(list_all_device_instances); | |
123 | ||
124 | static int | |
125 | visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env) | |
126 | { | |
127 | if (add_uevent_var(env, "VERSION=%s", VERSION)) | |
128 | return -ENOMEM; | |
129 | return 0; | |
130 | } | |
131 | ||
132 | /* This is called automatically upon adding a visor_device (device_add), or | |
133 | * adding a visor_driver (visorbus_register_visor_driver), and returns 1 iff the | |
134 | * provided driver can control the specified device. | |
135 | */ | |
136 | static int | |
137 | visorbus_match(struct device *xdev, struct device_driver *xdrv) | |
138 | { | |
139 | uuid_le channel_type; | |
140 | int rc = 0; | |
141 | int i; | |
142 | struct visor_device *dev; | |
143 | struct visor_driver *drv; | |
144 | ||
145 | dev = to_visor_device(xdev); | |
146 | drv = to_visor_driver(xdrv); | |
147 | channel_type = visorchannel_get_uuid(dev->visorchannel); | |
148 | if (visorbus_forcematch) { | |
149 | rc = 1; | |
150 | goto away; | |
151 | } | |
152 | if (visorbus_forcenomatch) | |
153 | goto away; | |
154 | ||
155 | if (!drv->channel_types) | |
156 | goto away; | |
157 | for (i = 0; | |
158 | (uuid_le_cmp(drv->channel_types[i].guid, NULL_UUID_LE) != 0) || | |
159 | (drv->channel_types[i].name); | |
160 | i++) | |
161 | if (uuid_le_cmp(drv->channel_types[i].guid, | |
162 | channel_type) == 0) { | |
163 | rc = i + 1; | |
164 | goto away; | |
165 | } | |
166 | away: | |
167 | return rc; | |
168 | } | |
169 | ||
170 | /** This is called when device_unregister() is called for the bus device | |
171 | * instance, after all other tasks involved with destroying the device | |
172 | * are complete. | |
173 | */ | |
174 | static void | |
175 | visorbus_release_busdevice(struct device *xdev) | |
176 | { | |
177 | struct visorbus_devdata *devdata = dev_get_drvdata(xdev); | |
178 | ||
179 | dev_set_drvdata(xdev, NULL); | |
180 | kfree(devdata); | |
181 | kfree(xdev); | |
182 | } | |
183 | ||
184 | /** This is called when device_unregister() is called for each child | |
185 | * device instance. | |
186 | */ | |
187 | static void | |
188 | visorbus_release_device(struct device *xdev) | |
189 | { | |
190 | struct visor_device *dev = to_visor_device(xdev); | |
191 | ||
192 | if (dev->periodic_work) { | |
193 | visor_periodic_work_destroy(dev->periodic_work); | |
194 | dev->periodic_work = NULL; | |
195 | } | |
196 | if (dev->visorchannel) { | |
197 | visorchannel_destroy(dev->visorchannel); | |
198 | dev->visorchannel = NULL; | |
199 | } | |
200 | kfree(dev); | |
201 | } | |
202 | ||
a9a7c767 PB |
203 | /* This is actually something they forgot to put in the kernel. |
204 | * struct bus_type in the kernel SHOULD have a "busses" member, which | |
205 | * should be treated similarly to the "devices" and "drivers" members. | |
206 | * There SHOULD be: | |
207 | * - a "businst_attribute" analogous to the existing "bus_attribute" | |
208 | * - a "businst_create_file" and "businst_remove_file" analogous to the | |
209 | * existing "bus_create_file" and "bus_remove_file". | |
210 | * That's what I created businst.c and businst.h to do. | |
211 | * | |
212 | * We want to add the "busses" sub-tree in sysfs, where we will house the | |
213 | * names and properties of each bus instance: | |
214 | * | |
215 | * /sys/bus/<bustypename>/ | |
216 | * version | |
217 | * devices | |
218 | * <devname1> --> /sys/devices/<businstancename><devname1> | |
219 | * <devname2> --> /sys/devices/<businstancename><devname2> | |
220 | * drivers | |
221 | * <driverinstancename1> | |
222 | * <driverinstance1property1> | |
223 | * <driverinstance1property2> | |
224 | * ... | |
225 | * <driverinstancename2> | |
226 | * <driverinstance2property1> | |
227 | * <driverinstance2property2> | |
228 | * ... | |
229 | * >> busses | |
230 | * >> <businstancename1> | |
231 | * >> <businstance1property1> | |
232 | * >> <businstance1property2> | |
233 | * >> ... | |
234 | * >> <businstancename2> | |
235 | * >> <businstance2property1> | |
236 | * >> <businstance2property2> | |
237 | * >> ... | |
238 | * | |
239 | * I considered adding bus instance properties under | |
240 | * /sys/devices/<businstancename>. But I thought there may be existing | |
241 | * notions that ONLY device sub-trees should live under | |
242 | * /sys/devices/<businstancename>. So I stayed out of there. | |
243 | * | |
244 | */ | |
245 | ||
246 | struct businst_attribute { | |
247 | struct attribute attr; | |
248 | ssize_t (*show)(struct visorbus_devdata*, char *buf); | |
249 | ssize_t (*store)(struct visorbus_devdata*, const char *buf, | |
250 | size_t count); | |
251 | }; | |
252 | ||
253 | #define to_businst_attr(_attr) \ | |
254 | container_of(_attr, struct businst_attribute, attr) | |
255 | #define to_visorbus_devdata(obj) \ | |
256 | container_of(obj, struct visorbus_devdata, kobj) | |
257 | ||
258 | static ssize_t | |
259 | businst_attr_show(struct kobject *kobj, struct attribute *attr, | |
260 | char *buf) | |
261 | { | |
262 | struct businst_attribute *businst_attr = to_businst_attr(attr); | |
263 | struct visorbus_devdata *bus = to_visorbus_devdata(kobj); | |
264 | ssize_t ret = 0; | |
265 | ||
266 | if (businst_attr->show) | |
267 | ret = businst_attr->show(bus, buf); | |
268 | return ret; | |
269 | } | |
270 | ||
271 | static ssize_t | |
272 | businst_attr_store(struct kobject *kobj, struct attribute *attr, | |
273 | const char *buf, size_t count) | |
274 | { | |
275 | struct businst_attribute *businst_attr = to_businst_attr(attr); | |
276 | struct visorbus_devdata *bus = to_visorbus_devdata(kobj); | |
277 | ssize_t ret = 0; | |
278 | ||
279 | if (businst_attr->store) | |
280 | ret = businst_attr->store(bus, buf, count); | |
281 | return ret; | |
282 | } | |
283 | ||
284 | static int | |
285 | businst_create_file(struct visorbus_devdata *bus, | |
286 | struct businst_attribute *attr) | |
287 | { | |
288 | return sysfs_create_file(&bus->kobj, &attr->attr); | |
289 | } | |
290 | ||
291 | static void | |
292 | businst_remove_file(struct visorbus_devdata *bus, | |
293 | struct businst_attribute *attr) | |
294 | { | |
295 | sysfs_remove_file(&bus->kobj, &attr->attr); | |
296 | } | |
297 | ||
3703987c EA |
298 | static const struct sysfs_ops businst_sysfs_ops = { |
299 | .show = businst_attr_show, | |
300 | .store = businst_attr_store, | |
301 | }; | |
302 | ||
303 | static struct kobj_type businst_kobj_type = { | |
304 | .sysfs_ops = &businst_sysfs_ops | |
305 | }; | |
306 | ||
307 | static struct kset businstances = { /* should actually be a member of | |
308 | * bus_type */ | |
309 | }; | |
310 | ||
311 | /* BUS type attributes | |
312 | * | |
313 | * define & implement display of bus attributes under | |
314 | * /sys/bus/visorbus. | |
315 | * | |
316 | */ | |
317 | ||
318 | static ssize_t | |
319 | BUSTYPE_ATTR_version(struct bus_type *bus, char *buf) | |
320 | { | |
321 | return snprintf(buf, PAGE_SIZE, "%s\n", VERSION); | |
322 | } | |
323 | ||
324 | static struct bus_attribute bustype_attr_version = | |
325 | __ATTR(version, S_IRUGO, BUSTYPE_ATTR_version, NULL); | |
326 | ||
327 | static int | |
328 | register_bustype_attributes(void) | |
329 | { | |
330 | int rc = 0; | |
331 | ||
332 | rc = bus_create_file(&visorbus_type, &bustype_attr_version); | |
333 | if (rc < 0) | |
334 | goto away; | |
335 | ||
336 | /* Here we make up for the fact that bus_type does not yet have a | |
337 | * member to keep track of multiple bus instances for a given bus | |
338 | * type. This is useful for stashing properties for each bus | |
339 | * instance. | |
340 | */ | |
341 | kobject_set_name(&businstances.kobj, "busses"); | |
342 | businstances.kobj.ktype = &businst_kobj_type; | |
343 | businstances.kobj.parent = &visorbus_type.p->subsys.kobj; | |
344 | rc = kset_register(&businstances); | |
345 | if (rc < 0) | |
346 | goto away; | |
347 | ||
348 | rc = 0; | |
349 | away: | |
350 | return rc; | |
351 | } | |
352 | ||
353 | static void | |
354 | unregister_bustype_attributes(void) | |
355 | { | |
356 | bus_remove_file(&visorbus_type, &bustype_attr_version); | |
357 | kset_unregister(&businstances); | |
358 | } | |
359 | ||
360 | /* BUS instance attributes | |
361 | * | |
362 | * define & implement display of bus attributes under | |
363 | * /sys/bus/visorbus/busses/visorbus<n>. | |
364 | * | |
365 | * This is a bit hoaky because the kernel does not yet have the infrastructure | |
366 | * to separate bus INSTANCE attributes from bus TYPE attributes... | |
367 | * so we roll our own. See businst.c / businst.h. | |
368 | * | |
369 | */ | |
370 | ||
371 | static ssize_t businst_attr_partition_handle(struct visorbus_devdata *businst, | |
372 | char *buf) { | |
373 | struct visorchipset_bus_info bus_info; | |
374 | int len = 0; | |
375 | ||
376 | if (businst && visorchipset_get_bus_info(businst->devno, &bus_info)) | |
377 | len = snprintf(buf, PAGE_SIZE, | |
378 | "0x%Lx\n", | |
379 | (unsigned long long)bus_info.partition_handle); | |
380 | return len; | |
381 | } | |
382 | ||
383 | static ssize_t businst_attr_partition_guid(struct visorbus_devdata *businst, | |
384 | char *buf) { | |
385 | struct visorchipset_bus_info bus_info; | |
386 | int len = 0; | |
387 | ||
388 | if (businst && visorchipset_get_bus_info(businst->devno, &bus_info)) | |
389 | len = snprintf(buf, PAGE_SIZE, "{%pUb}\n", | |
390 | &bus_info.partition_uuid); | |
391 | return len; | |
392 | } | |
393 | ||
394 | static ssize_t businst_attr_partition_name(struct visorbus_devdata *businst, | |
395 | char *buf) { | |
396 | struct visorchipset_bus_info bus_info; | |
397 | int len = 0; | |
398 | ||
399 | if (businst && | |
400 | visorchipset_get_bus_info(businst->devno, &bus_info) && | |
401 | bus_info.name) | |
402 | len = snprintf(buf, PAGE_SIZE, "%s\n", bus_info.name); | |
403 | return len; | |
404 | } | |
405 | ||
406 | static ssize_t businst_attr_channel_addr(struct visorbus_devdata *businst, | |
407 | char *buf) { | |
408 | struct visorchipset_bus_info bus_info; | |
409 | int len = 0; | |
410 | ||
411 | if (businst && visorchipset_get_bus_info(businst->devno, &bus_info)) | |
412 | len = snprintf(buf, PAGE_SIZE, "0x%Lx\n", (unsigned long long) | |
413 | bus_info.chan_info.channel_addr); | |
414 | return len; | |
415 | } | |
416 | ||
417 | static ssize_t businst_attr_nchannel_bytes(struct visorbus_devdata *businst, | |
418 | char *buf) { | |
419 | struct visorchipset_bus_info bus_info; | |
420 | int len = 0; | |
421 | ||
422 | if (businst && visorchipset_get_bus_info(businst->devno, &bus_info)) | |
423 | len = snprintf(buf, PAGE_SIZE, "0x%Lx\n", (unsigned long long) | |
424 | bus_info.chan_info.n_channel_bytes); | |
425 | return len; | |
426 | } | |
427 | ||
428 | static ssize_t businst_attr_channel_id(struct visorbus_devdata *businst, | |
429 | char *buf) { | |
430 | int len = 0; | |
431 | ||
432 | if (businst && businst->chan) { | |
433 | visorchannel_id(businst->chan, buf); | |
434 | len = strlen(buf); | |
435 | buf[len++] = '\n'; | |
436 | } | |
437 | return len; | |
438 | } | |
439 | ||
440 | static ssize_t businst_attr_client_bus_info(struct visorbus_devdata *businst, | |
441 | char *buf) { | |
442 | struct visorchipset_bus_info bus_info; | |
443 | int i, x, remain = PAGE_SIZE; | |
444 | unsigned long off; | |
445 | char *p = buf; | |
446 | u8 *partition_name; | |
447 | struct ultra_vbus_deviceinfo dev_info; | |
448 | ||
449 | partition_name = ""; | |
450 | if (businst && businst->chan) { | |
451 | if (visorchipset_get_bus_info(businst->devno, &bus_info) && | |
452 | bus_info.name) | |
453 | partition_name = bus_info.name; | |
454 | x = snprintf(p, remain, | |
455 | "Client device / client driver info for %s partition (vbus #%d):\n", | |
456 | partition_name, businst->devno); | |
457 | p += x; | |
458 | remain -= x; | |
459 | x = visorchannel_read(businst->chan, | |
460 | offsetof(struct | |
461 | spar_vbus_channel_protocol, | |
462 | chp_info), | |
463 | &dev_info, sizeof(dev_info)); | |
464 | if (x >= 0) { | |
465 | x = vbuschannel_devinfo_to_string(&dev_info, p, | |
466 | remain, -1); | |
467 | p += x; | |
468 | remain -= x; | |
469 | } | |
470 | x = visorchannel_read(businst->chan, | |
471 | offsetof(struct | |
472 | spar_vbus_channel_protocol, | |
473 | bus_info), | |
474 | &dev_info, sizeof(dev_info)); | |
475 | if (x >= 0) { | |
476 | x = vbuschannel_devinfo_to_string(&dev_info, p, | |
477 | remain, -1); | |
478 | p += x; | |
479 | remain -= x; | |
480 | } | |
481 | off = offsetof(struct spar_vbus_channel_protocol, dev_info); | |
482 | i = 0; | |
483 | while (off + sizeof(dev_info) <= | |
484 | visorchannel_get_nbytes(businst->chan)) { | |
485 | x = visorchannel_read(businst->chan, | |
486 | off, &dev_info, sizeof(dev_info)); | |
487 | if (x >= 0) { | |
488 | x = vbuschannel_devinfo_to_string | |
489 | (&dev_info, p, remain, i); | |
490 | p += x; | |
491 | remain -= x; | |
492 | } | |
493 | off += sizeof(dev_info); | |
494 | i++; | |
495 | } | |
496 | } | |
497 | return PAGE_SIZE - remain; | |
498 | } | |
499 | ||
500 | static struct businst_attribute ba_partition_handle = | |
501 | __ATTR(partition_handle, S_IRUGO, businst_attr_partition_handle, NULL); | |
502 | static struct businst_attribute ba_partition_guid = | |
503 | __ATTR(partition_guid, S_IRUGO, businst_attr_partition_guid, NULL); | |
504 | static struct businst_attribute ba_partition_name = | |
505 | __ATTR(partition_name, S_IRUGO, businst_attr_partition_name, NULL); | |
506 | static struct businst_attribute ba_channel_addr = | |
507 | __ATTR(channel_addr, S_IRUGO, businst_attr_channel_addr, NULL); | |
508 | static struct businst_attribute ba_nchannel_bytes = | |
509 | __ATTR(nchannel_bytes, S_IRUGO, businst_attr_nchannel_bytes, NULL); | |
510 | static struct businst_attribute ba_channel_id = | |
511 | __ATTR(channel_id, S_IRUGO, businst_attr_channel_id, NULL); | |
512 | static struct businst_attribute ba_client_bus_info = | |
513 | __ATTR(client_bus_info, S_IRUGO, businst_attr_client_bus_info, NULL); | |
514 | ||
515 | static int | |
516 | register_businst_attributes(struct visorbus_devdata *businst) | |
517 | { | |
518 | int rc = 0; | |
519 | ||
520 | businst->kobj.kset = &businstances; /* identify parent sysfs dir */ | |
521 | rc = kobject_init_and_add(&businst->kobj, &businst_kobj_type, | |
522 | NULL, "visorbus%d", businst->devno); | |
523 | if (rc < 0) | |
524 | goto away; | |
525 | ||
526 | rc = businst_create_file(businst, &ba_partition_handle); | |
527 | if (rc < 0) | |
528 | goto away; | |
529 | ||
530 | rc = businst_create_file(businst, &ba_partition_guid); | |
531 | if (rc < 0) | |
532 | goto away; | |
533 | ||
534 | rc = businst_create_file(businst, &ba_partition_name); | |
535 | if (rc < 0) | |
536 | goto away; | |
537 | ||
538 | rc = businst_create_file(businst, &ba_channel_addr); | |
539 | if (rc < 0) | |
540 | goto away; | |
541 | ||
542 | rc = businst_create_file(businst, &ba_nchannel_bytes); | |
543 | if (rc < 0) | |
544 | goto away; | |
545 | ||
546 | rc = businst_create_file(businst, &ba_channel_id); | |
547 | if (rc < 0) | |
548 | goto away; | |
549 | ||
550 | rc = businst_create_file(businst, &ba_client_bus_info); | |
551 | if (rc < 0) | |
552 | goto away; | |
553 | ||
554 | kobject_uevent(&businst->kobj, KOBJ_ADD); | |
555 | ||
556 | rc = 0; | |
557 | away: | |
558 | return rc; | |
559 | } | |
560 | ||
561 | static void | |
562 | unregister_businst_attributes(struct visorbus_devdata *businst) | |
563 | { | |
564 | businst_remove_file(businst, &ba_partition_handle); | |
565 | businst_remove_file(businst, &ba_partition_guid); | |
566 | businst_remove_file(businst, &ba_partition_name); | |
567 | businst_remove_file(businst, &ba_channel_addr); | |
568 | businst_remove_file(businst, &ba_nchannel_bytes); | |
569 | businst_remove_file(businst, &ba_channel_id); | |
570 | businst_remove_file(businst, &ba_client_bus_info); | |
571 | kobject_put(&businst->kobj); | |
572 | } | |
573 | ||
574 | /* DRIVER attributes | |
575 | * | |
576 | * define & implement display of driver attributes under | |
577 | * /sys/bus/visorbus/drivers/<drivername>. | |
578 | * | |
579 | */ | |
580 | ||
581 | static ssize_t | |
582 | DRIVER_ATTR_version(struct device_driver *xdrv, char *buf) | |
583 | { | |
584 | struct visor_driver *drv = to_visor_driver(xdrv); | |
585 | ||
586 | return snprintf(buf, PAGE_SIZE, "%s\n", drv->version); | |
587 | } | |
588 | ||
589 | static int | |
590 | register_driver_attributes(struct visor_driver *drv) | |
591 | { | |
592 | int rc; | |
593 | struct driver_attribute version = | |
594 | __ATTR(version, S_IRUGO, DRIVER_ATTR_version, NULL); | |
595 | drv->version_attr = version; | |
596 | rc = driver_create_file(&drv->driver, &drv->version_attr); | |
597 | return rc; | |
598 | } | |
599 | ||
600 | static void | |
601 | unregister_driver_attributes(struct visor_driver *drv) | |
602 | { | |
603 | driver_remove_file(&drv->driver, &drv->version_attr); | |
604 | } | |
605 | ||
606 | /* DEVICE attributes | |
607 | * | |
608 | * define & implement display of device attributes under | |
609 | * /sys/bus/visorbus/devices/<devicename>. | |
610 | * | |
611 | */ | |
612 | ||
613 | #define DEVATTR(nam, func) { \ | |
614 | .attr = { .name = __stringify(nam), \ | |
615 | .mode = 0444, \ | |
616 | .owner = THIS_MODULE }, \ | |
617 | .show = func, \ | |
618 | } | |
619 | ||
620 | static struct device_attribute visor_device_attrs[] = { | |
621 | /* DEVATTR(channel_nbytes, DEVICE_ATTR_channel_nbytes), */ | |
622 | __ATTR_NULL | |
623 | }; | |
624 | ||
625 | static void | |
626 | dev_periodic_work(void *xdev) | |
627 | { | |
628 | struct visor_device *dev = (struct visor_device *)xdev; | |
629 | struct visor_driver *drv = to_visor_driver(dev->device.driver); | |
630 | ||
631 | down(&dev->visordriver_callback_lock); | |
632 | if (drv->channel_interrupt) | |
633 | drv->channel_interrupt(dev); | |
634 | up(&dev->visordriver_callback_lock); | |
635 | if (!visor_periodic_work_nextperiod(dev->periodic_work)) | |
636 | put_device(&dev->device); | |
637 | } | |
638 | ||
639 | static void | |
640 | dev_start_periodic_work(struct visor_device *dev) | |
641 | { | |
642 | if (dev->being_removed) | |
643 | return; | |
644 | /* now up by at least 2 */ | |
645 | get_device(&dev->device); | |
646 | if (!visor_periodic_work_start(dev->periodic_work)) | |
647 | put_device(&dev->device); | |
648 | } | |
649 | ||
650 | static void | |
651 | dev_stop_periodic_work(struct visor_device *dev) | |
652 | { | |
653 | if (visor_periodic_work_stop(dev->periodic_work)) | |
654 | put_device(&dev->device); | |
655 | } | |
656 | ||
657 | /** This is called automatically upon adding a visor_device (device_add), or | |
658 | * adding a visor_driver (visorbus_register_visor_driver), but only after | |
659 | * visorbus_match has returned 1 to indicate a successful match between | |
660 | * driver and device. | |
661 | */ | |
662 | static int | |
663 | visordriver_probe_device(struct device *xdev) | |
664 | { | |
665 | int rc; | |
666 | struct visor_driver *drv; | |
667 | struct visor_device *dev; | |
668 | ||
669 | drv = to_visor_driver(xdev->driver); | |
670 | dev = to_visor_device(xdev); | |
671 | down(&dev->visordriver_callback_lock); | |
672 | dev->being_removed = FALSE; | |
673 | /* | |
674 | * ensure that the dev->being_removed flag is cleared before | |
675 | * we start the probe | |
676 | */ | |
677 | wmb(); | |
678 | get_device(&dev->device); | |
679 | if (!drv->probe) { | |
680 | up(&dev->visordriver_callback_lock); | |
681 | rc = -1; | |
682 | goto away; | |
683 | } | |
684 | rc = drv->probe(dev); | |
685 | if (rc < 0) | |
686 | goto away; | |
687 | ||
688 | fix_vbus_dev_info(dev); | |
689 | up(&dev->visordriver_callback_lock); | |
690 | rc = 0; | |
691 | away: | |
692 | if (rc != 0) | |
693 | put_device(&dev->device); | |
694 | /* We could get here more than once if the child driver module is | |
695 | * unloaded and re-loaded while devices are present. That's why we | |
696 | * need a flag to be sure that we only respond to the device_create | |
697 | * once. We cannot respond to the device_create prior to here, | |
698 | * because until we call drv->probe() above, the channel has not been | |
699 | * initialized. | |
700 | */ | |
701 | if (!dev->responded_to_device_create) { | |
702 | dev->responded_to_device_create = TRUE; | |
703 | if (chipset_responders.device_create) | |
704 | (*chipset_responders.device_create)(dev->chipset_bus_no, | |
705 | dev->chipset_dev_no, | |
706 | rc); | |
707 | } | |
708 | return rc; | |
709 | } | |
710 | ||
711 | /** This is called when device_unregister() is called for each child device | |
712 | * instance, to notify the appropriate visorbus_driver that the device is | |
713 | * going away, and to decrease the reference count of the device. | |
714 | */ | |
715 | static int | |
716 | visordriver_remove_device(struct device *xdev) | |
717 | { | |
718 | int rc = 0; | |
719 | struct visor_device *dev; | |
720 | struct visor_driver *drv; | |
721 | ||
722 | dev = to_visor_device(xdev); | |
723 | drv = to_visor_driver(xdev->driver); | |
724 | down(&dev->visordriver_callback_lock); | |
725 | dev->being_removed = TRUE; | |
726 | /* | |
727 | * ensure that the dev->being_removed flag is set before we start the | |
728 | * actual removal | |
729 | */ | |
730 | wmb(); | |
731 | if (drv) { | |
732 | if (drv->remove) | |
733 | drv->remove(dev); | |
734 | } | |
735 | up(&dev->visordriver_callback_lock); | |
736 | dev_stop_periodic_work(dev); | |
737 | devmajorminor_remove_all_files(dev); | |
738 | ||
739 | put_device(&dev->device); | |
740 | ||
741 | return rc; | |
742 | } | |
743 | ||
744 | /** A particular type of visor driver calls this function to register | |
745 | * the driver. The caller MUST fill in the following fields within the | |
746 | * #drv structure: | |
747 | * name, version, owner, channel_types, probe, remove | |
748 | * | |
749 | * Here's how the whole Linux bus / driver / device model works. | |
750 | * | |
751 | * At system start-up, the visorbus kernel module is loaded, which registers | |
752 | * visorbus_type as a bus type, using bus_register(). | |
753 | * | |
754 | * All kernel modules that support particular device types on a | |
755 | * visorbus bus are loaded. Each of these kernel modules calls | |
756 | * visorbus_register_visor_driver() in their init functions, passing a | |
757 | * visor_driver struct. visorbus_register_visor_driver() in turn calls | |
758 | * register_driver(&visor_driver.driver). This .driver member is | |
759 | * initialized with generic methods (like probe), whose sole responsibility | |
760 | * is to act as a broker for the real methods, which are within the | |
761 | * visor_driver struct. (This is the way the subclass behavior is | |
762 | * implemented, since visor_driver is essentially a subclass of the | |
763 | * generic driver.) Whenever a driver_register() happens, core bus code in | |
764 | * the kernel does (see device_attach() in drivers/base/dd.c): | |
765 | * | |
766 | * for each dev associated with the bus (the bus that driver is on) that | |
767 | * does not yet have a driver | |
768 | * if bus.match(dev,newdriver) == yes_matched ** .match specified | |
769 | * ** during bus_register(). | |
770 | * newdriver.probe(dev) ** for visor drivers, this will call | |
771 | * ** the generic driver.probe implemented in visorbus.c, | |
772 | * ** which in turn calls the probe specified within the | |
773 | * ** struct visor_driver (which was specified by the | |
774 | * ** actual device driver as part of | |
775 | * ** visorbus_register_visor_driver()). | |
776 | * | |
777 | * The above dance also happens when a new device appears. | |
778 | * So the question is, how are devices created within the system? | |
779 | * Basically, just call device_add(dev). See pci_bus_add_devices(). | |
780 | * pci_scan_device() shows an example of how to build a device struct. It | |
781 | * returns the newly-created struct to pci_scan_single_device(), who adds it | |
782 | * to the list of devices at PCIBUS.devices. That list of devices is what | |
783 | * is traversed by pci_bus_add_devices(). | |
784 | * | |
785 | */ | |
786 | int visorbus_register_visor_driver(struct visor_driver *drv) | |
787 | { | |
788 | int rc = 0; | |
789 | ||
790 | drv->driver.name = drv->name; | |
791 | drv->driver.bus = &visorbus_type; | |
792 | drv->driver.probe = visordriver_probe_device; | |
793 | drv->driver.remove = visordriver_remove_device; | |
794 | drv->driver.owner = drv->owner; | |
795 | ||
796 | /* driver_register does this: | |
797 | * bus_add_driver(drv) | |
798 | * ->if (drv.bus) ** (bus_type) ** | |
799 | * driver_attach(drv) | |
800 | * for each dev with bus type of drv.bus | |
801 | * if (!dev.drv) ** no driver assigned yet ** | |
802 | * if (bus.match(dev,drv)) [visorbus_match] | |
803 | * dev.drv = drv | |
804 | * if (!drv.probe(dev)) [visordriver_probe_device] | |
805 | * dev.drv = NULL | |
806 | */ | |
807 | ||
808 | rc = driver_register(&drv->driver); | |
809 | if (rc < 0) | |
810 | return rc; | |
811 | rc = register_driver_attributes(drv); | |
812 | return rc; | |
813 | } | |
814 | EXPORT_SYMBOL_GPL(visorbus_register_visor_driver); | |
815 | ||
816 | /** A particular type of visor driver calls this function to unregister | |
817 | * the driver, i.e., within its module_exit function. | |
818 | */ | |
819 | void | |
820 | visorbus_unregister_visor_driver(struct visor_driver *drv) | |
821 | { | |
822 | unregister_driver_attributes(drv); | |
823 | driver_unregister(&drv->driver); | |
824 | } | |
825 | EXPORT_SYMBOL_GPL(visorbus_unregister_visor_driver); | |
826 | ||
827 | int | |
828 | visorbus_read_channel(struct visor_device *dev, unsigned long offset, | |
829 | void *dest, unsigned long nbytes) | |
830 | { | |
831 | return visorchannel_read(dev->visorchannel, offset, dest, nbytes); | |
832 | } | |
833 | EXPORT_SYMBOL_GPL(visorbus_read_channel); | |
834 | ||
835 | int | |
836 | visorbus_write_channel(struct visor_device *dev, unsigned long offset, | |
837 | void *src, unsigned long nbytes) | |
838 | { | |
839 | return visorchannel_write(dev->visorchannel, offset, src, nbytes); | |
840 | } | |
841 | EXPORT_SYMBOL_GPL(visorbus_write_channel); | |
842 | ||
843 | int | |
844 | visorbus_clear_channel(struct visor_device *dev, unsigned long offset, u8 ch, | |
845 | unsigned long nbytes) | |
846 | { | |
847 | return visorchannel_clear(dev->visorchannel, offset, ch, nbytes); | |
848 | } | |
849 | EXPORT_SYMBOL_GPL(visorbus_clear_channel); | |
850 | ||
851 | int | |
852 | visorbus_registerdevnode(struct visor_device *dev, | |
853 | const char *name, int major, int minor) | |
854 | { | |
855 | return devmajorminor_create_file(dev, name, major, minor); | |
856 | } | |
857 | EXPORT_SYMBOL_GPL(visorbus_registerdevnode); | |
858 | ||
859 | /** We don't really have a real interrupt, so for now we just call the | |
860 | * interrupt function periodically... | |
861 | */ | |
862 | void | |
863 | visorbus_enable_channel_interrupts(struct visor_device *dev) | |
864 | { | |
865 | dev_start_periodic_work(dev); | |
866 | } | |
867 | EXPORT_SYMBOL_GPL(visorbus_enable_channel_interrupts); | |
868 | ||
869 | void | |
870 | visorbus_disable_channel_interrupts(struct visor_device *dev) | |
871 | { | |
872 | dev_stop_periodic_work(dev); | |
873 | } | |
874 | EXPORT_SYMBOL_GPL(visorbus_disable_channel_interrupts); | |
875 | ||
876 | /** This is how everything starts from the device end. | |
877 | * This function is called when a channel first appears via a ControlVM | |
878 | * message. In response, this function allocates a visor_device to | |
879 | * correspond to the new channel, and attempts to connect it the appropriate | |
880 | * driver. If the appropriate driver is found, the visor_driver.probe() | |
881 | * function for that driver will be called, and will be passed the new | |
882 | * visor_device that we just created. | |
883 | * | |
884 | * It's ok if the appropriate driver is not yet loaded, because in that case | |
885 | * the new device struct will just stick around in the bus' list of devices. | |
886 | * When the appropriate driver calls visorbus_register_visor_driver(), the | |
887 | * visor_driver.probe() for the new driver will be called with the new | |
888 | * device. | |
889 | */ | |
890 | static int | |
891 | create_visor_device(struct visorbus_devdata *devdata, | |
892 | unsigned long chipset_bus_no, unsigned long chipset_dev_no, | |
893 | struct visorchipset_channel_info chan_info, | |
894 | u64 partition_handle) | |
895 | { | |
896 | int rc = -1; | |
897 | struct visorchannel *visorchannel = NULL; | |
898 | struct visor_device *dev = NULL; | |
899 | bool gotten = FALSE, registered1 = FALSE, registered2 = FALSE; | |
900 | ||
901 | POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, chipset_dev_no, chipset_bus_no, | |
902 | POSTCODE_SEVERITY_INFO); | |
903 | /* prepare chan_hdr (abstraction to read/write channel memory) */ | |
904 | visorchannel = visorchannel_create(chan_info.channel_addr, | |
905 | (unsigned long) | |
906 | chan_info.n_channel_bytes, | |
907 | chan_info.channel_type_uuid); | |
908 | if (!visorchannel) { | |
909 | POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, chipset_dev_no, | |
910 | DIAG_SEVERITY_ERR); | |
911 | goto away; | |
912 | } | |
913 | dev = kmalloc(sizeof(*dev), GFP_KERNEL); | |
914 | if (!dev) { | |
915 | POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, chipset_dev_no, | |
916 | DIAG_SEVERITY_ERR); | |
917 | goto away; | |
918 | } | |
919 | ||
920 | memset(dev, 0, sizeof(struct visor_device)); | |
921 | dev->visorchannel = visorchannel; | |
922 | dev->channel_type_guid = chan_info.channel_type_uuid; | |
923 | dev->channel_bytes = chan_info.n_channel_bytes; | |
924 | dev->chipset_bus_no = chipset_bus_no; | |
925 | dev->chipset_dev_no = chipset_dev_no; | |
926 | dev->device.parent = devdata->dev; | |
927 | sema_init(&dev->visordriver_callback_lock, 1); /* unlocked */ | |
928 | dev->device.bus = &visorbus_type; | |
929 | device_initialize(&dev->device); | |
930 | dev->device.release = visorbus_release_device; | |
931 | /* keep a reference just for us (now 2) */ | |
932 | get_device(&dev->device); | |
933 | gotten = TRUE; | |
934 | dev->periodic_work = | |
935 | visor_periodic_work_create(POLLJIFFIES_NORMALCHANNEL, | |
936 | periodic_dev_workqueue, | |
937 | dev_periodic_work, | |
938 | dev, dev_name(&dev->device)); | |
939 | if (!dev->periodic_work) { | |
940 | POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, chipset_dev_no, | |
941 | DIAG_SEVERITY_ERR); | |
942 | goto away; | |
943 | } | |
944 | ||
945 | /* bus_id must be a unique name with respect to this bus TYPE | |
946 | * (NOT bus instance). That's why we need to include the bus | |
947 | * number within the name. | |
948 | */ | |
949 | dev_set_name(&dev->device, "vbus%lu:dev%lu", | |
950 | chipset_bus_no, chipset_dev_no); | |
951 | ||
952 | /* device_add does this: | |
953 | * bus_add_device(dev) | |
954 | * ->device_attach(dev) | |
955 | * ->for each driver drv registered on the bus that dev is on | |
956 | * if (dev.drv) ** device already has a driver ** | |
957 | * ** not sure we could ever get here... ** | |
958 | * else | |
959 | * if (bus.match(dev,drv)) [visorbus_match] | |
960 | * dev.drv = drv | |
961 | * if (!drv.probe(dev)) [visordriver_probe_device] | |
962 | * dev.drv = NULL | |
963 | * | |
964 | * Note that device_add does NOT fail if no driver failed to | |
965 | * claim the device. The device will be linked onto | |
966 | * bus_type.klist_devices regardless (use bus_for_each_dev). | |
967 | */ | |
968 | rc = device_add(&dev->device); | |
969 | if (rc < 0) { | |
970 | POSTCODE_LINUX_3(DEVICE_ADD_PC, chipset_bus_no, | |
971 | DIAG_SEVERITY_ERR); | |
972 | goto away; | |
973 | } | |
974 | ||
975 | /* note: device_register is simply device_initialize + device_add */ | |
976 | rc = register_channel_attributes(dev); | |
977 | if (rc < 0) { | |
978 | POSTCODE_LINUX_3(DEVICE_REGISTER_FAILURE_PC, chipset_dev_no, | |
979 | DIAG_SEVERITY_ERR); | |
980 | goto away; | |
981 | } | |
982 | ||
983 | registered1 = TRUE; | |
984 | ||
985 | rc = register_devmajorminor_attributes(dev); | |
986 | if (rc < 0) { | |
987 | POSTCODE_LINUX_3(DEVICE_REGISTER_FAILURE_PC, chipset_dev_no, | |
988 | DIAG_SEVERITY_ERR); | |
989 | goto away; | |
990 | } | |
991 | ||
992 | registered2 = TRUE; | |
993 | rc = 0; | |
994 | ||
995 | away: | |
996 | if (rc < 0) { | |
997 | if (registered2) | |
998 | unregister_devmajorminor_attributes(dev); | |
999 | if (registered1) | |
1000 | unregister_channel_attributes(dev); | |
1001 | if (gotten) | |
1002 | put_device(&dev->device); | |
1003 | if (visorchannel) | |
1004 | visorchannel_destroy(visorchannel); | |
1005 | kfree(dev); | |
1006 | } else { | |
1007 | total_devices_created++; | |
1008 | list_add_tail(&dev->list_all, &list_all_device_instances); | |
1009 | } | |
1010 | return rc; | |
1011 | } | |
1012 | ||
1013 | static void | |
1014 | remove_visor_device(struct visor_device *dev) | |
1015 | { | |
1016 | list_del(&dev->list_all); | |
1017 | unregister_devmajorminor_attributes(dev); | |
1018 | unregister_channel_attributes(dev); | |
1019 | put_device(&dev->device); | |
1020 | device_unregister(&dev->device); | |
1021 | } | |
1022 | ||
1023 | static struct visor_device * | |
1024 | find_visor_device_by_channel(HOSTADDRESS channel_physaddr) | |
1025 | { | |
1026 | struct list_head *listentry, *listtmp; | |
1027 | ||
1028 | list_for_each_safe(listentry, listtmp, &list_all_device_instances) { | |
1029 | struct visor_device *dev = list_entry(listentry, | |
1030 | struct visor_device, | |
1031 | list_all); | |
1032 | if (visorchannel_get_physaddr(dev->visorchannel) == | |
1033 | channel_physaddr) | |
1034 | return dev; | |
1035 | } | |
1036 | return NULL; | |
1037 | } | |
1038 | ||
1039 | static int | |
1040 | init_vbus_channel(struct visorchannel *chan) | |
1041 | { | |
1042 | int rc = -1; | |
1043 | unsigned long allocated_bytes = visorchannel_get_nbytes(chan); | |
1044 | struct spar_vbus_channel_protocol *x = | |
1045 | kmalloc(sizeof(struct spar_vbus_channel_protocol), | |
1046 | GFP_KERNEL); | |
1047 | ||
1048 | POSTCODE_LINUX_3(VBUS_CHANNEL_ENTRY_PC, rc, POSTCODE_SEVERITY_INFO); | |
1049 | ||
1050 | if (x) { | |
1051 | POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR); | |
1052 | goto away; | |
1053 | } | |
1054 | if (visorchannel_clear(chan, 0, 0, allocated_bytes) < 0) { | |
1055 | POSTCODE_LINUX_2(VBUS_CHANNEL_FAILURE_PC, | |
1056 | POSTCODE_SEVERITY_ERR); | |
1057 | goto away; | |
1058 | } | |
1059 | if (visorchannel_read | |
1060 | (chan, 0, x, sizeof(struct spar_vbus_channel_protocol)) < 0) { | |
1061 | POSTCODE_LINUX_2(VBUS_CHANNEL_FAILURE_PC, | |
1062 | POSTCODE_SEVERITY_ERR); | |
1063 | goto away; | |
1064 | } | |
1065 | if (!SPAR_VBUS_CHANNEL_OK_SERVER(allocated_bytes)) { | |
1066 | POSTCODE_LINUX_2(VBUS_CHANNEL_FAILURE_PC, | |
1067 | POSTCODE_SEVERITY_ERR); | |
1068 | goto away; | |
1069 | } | |
1070 | ||
1071 | if (visorchannel_write | |
1072 | (chan, 0, x, sizeof(struct spar_vbus_channel_protocol)) < 0) { | |
1073 | POSTCODE_LINUX_3(VBUS_CHANNEL_FAILURE_PC, chan, | |
1074 | POSTCODE_SEVERITY_ERR); | |
1075 | goto away; | |
1076 | } | |
1077 | ||
1078 | POSTCODE_LINUX_3(VBUS_CHANNEL_EXIT_PC, chan, POSTCODE_SEVERITY_INFO); | |
1079 | rc = 0; | |
1080 | ||
1081 | away: | |
1082 | kfree(x); | |
1083 | x = NULL; | |
1084 | return rc; | |
1085 | } | |
1086 | ||
1087 | static int | |
1088 | get_vbus_header_info(struct visorchannel *chan, | |
1089 | struct spar_vbus_headerinfo *hdr_info) | |
1090 | { | |
1091 | int rc = -1; | |
1092 | ||
1093 | if (!SPAR_VBUS_CHANNEL_OK_CLIENT(visorchannel_get_header(chan))) | |
1094 | goto away; | |
1095 | if (visorchannel_read(chan, sizeof(struct channel_header), hdr_info, | |
1096 | sizeof(*hdr_info)) < 0) { | |
1097 | goto away; | |
1098 | } | |
1099 | if (hdr_info->struct_bytes < sizeof(struct spar_vbus_headerinfo)) | |
1100 | goto away; | |
1101 | if (hdr_info->device_info_struct_bytes < | |
1102 | sizeof(struct ultra_vbus_deviceinfo)) { | |
1103 | goto away; | |
1104 | } | |
1105 | rc = 0; | |
1106 | away: | |
1107 | return rc; | |
1108 | } | |
1109 | ||
1110 | /* Write the contents of <info> to the struct | |
1111 | * spar_vbus_channel_protocol.chp_info. */ | |
1112 | ||
1113 | static int | |
1114 | write_vbus_chp_info(struct visorchannel *chan, | |
1115 | struct spar_vbus_headerinfo *hdr_info, | |
1116 | struct ultra_vbus_deviceinfo *info) | |
1117 | { | |
1118 | int off = sizeof(struct channel_header) + hdr_info->chp_info_offset; | |
1119 | ||
1120 | if (hdr_info->chp_info_offset == 0) | |
1121 | return -1; | |
1122 | ||
1123 | if (visorchannel_write(chan, off, info, sizeof(*info)) < 0) | |
1124 | return -1; | |
1125 | return 0; | |
1126 | } | |
1127 | ||
1128 | /* Write the contents of <info> to the struct | |
1129 | * spar_vbus_channel_protocol.bus_info. */ | |
1130 | ||
1131 | static int | |
1132 | write_vbus_bus_info(struct visorchannel *chan, | |
1133 | struct spar_vbus_headerinfo *hdr_info, | |
1134 | struct ultra_vbus_deviceinfo *info) | |
1135 | { | |
1136 | int off = sizeof(struct channel_header) + hdr_info->bus_info_offset; | |
1137 | ||
1138 | if (hdr_info->bus_info_offset == 0) | |
1139 | return -1; | |
1140 | ||
1141 | if (visorchannel_write(chan, off, info, sizeof(*info)) < 0) | |
1142 | return -1; | |
1143 | return 0; | |
1144 | } | |
1145 | ||
1146 | /* Write the contents of <info> to the | |
1147 | * struct spar_vbus_channel_protocol.dev_info[<devix>]. | |
1148 | */ | |
1149 | static int | |
1150 | write_vbus_dev_info(struct visorchannel *chan, | |
1151 | struct spar_vbus_headerinfo *hdr_info, | |
1152 | struct ultra_vbus_deviceinfo *info, int devix) | |
1153 | { | |
1154 | int off = | |
1155 | (sizeof(struct channel_header) + hdr_info->dev_info_offset) + | |
1156 | (hdr_info->device_info_struct_bytes * devix); | |
1157 | ||
1158 | if (hdr_info->dev_info_offset == 0) | |
1159 | return -1; | |
1160 | ||
1161 | if (visorchannel_write(chan, off, info, sizeof(*info)) < 0) | |
1162 | return -1; | |
1163 | return 0; | |
1164 | } | |
1165 | ||
1166 | /* For a child device just created on a client bus, fill in | |
1167 | * information about the driver that is controlling this device into | |
1168 | * the the appropriate slot within the vbus channel of the bus | |
1169 | * instance. | |
1170 | */ | |
1171 | static void | |
1172 | fix_vbus_dev_info(struct visor_device *visordev) | |
1173 | { | |
1174 | int i; | |
1175 | struct visorchipset_bus_info bus_info; | |
1176 | struct visorbus_devdata *devdata = NULL; | |
1177 | struct visor_driver *visordrv; | |
1178 | int bus_no = visordev->chipset_bus_no; | |
1179 | int dev_no = visordev->chipset_dev_no; | |
1180 | struct ultra_vbus_deviceinfo dev_info; | |
1181 | const char *chan_type_name = NULL; | |
1182 | ||
1183 | if (!visordev->device.driver) | |
1184 | return; | |
1185 | ||
1186 | visordrv = to_visor_driver(visordev->device.driver); | |
1187 | if (!visorchipset_get_bus_info(bus_no, &bus_info)) | |
1188 | return; | |
1189 | ||
1190 | devdata = (struct visorbus_devdata *)(bus_info.bus_driver_context); | |
1191 | if (!devdata) | |
1192 | return; | |
1193 | ||
1194 | if (!devdata->vbus_valid) | |
1195 | return; | |
1196 | ||
1197 | /* Within the list of device types (by GUID) that the driver | |
1198 | * says it supports, find out which one of those types matches | |
1199 | * the type of this device, so that we can include the device | |
1200 | * type name | |
1201 | */ | |
1202 | for (i = 0; visordrv->channel_types[i].name; i++) { | |
1203 | if (STRUCTSEQUAL(visordrv->channel_types[i].guid, | |
1204 | visordev->channel_type_guid)) { | |
1205 | chan_type_name = visordrv->channel_types[i].name; | |
1206 | break; | |
1207 | } | |
1208 | } | |
1209 | ||
1210 | bus_device_info_init(&dev_info, chan_type_name, | |
1211 | visordrv->name, visordrv->version, | |
1212 | visordrv->vertag); | |
1213 | write_vbus_dev_info(devdata->chan, | |
1214 | &devdata->vbus_hdr_info, &dev_info, dev_no); | |
1215 | ||
1216 | /* Re-write bus+chipset info, because it is possible that this | |
1217 | * was previously written by our evil counterpart, virtpci. | |
1218 | */ | |
1219 | write_vbus_chp_info(devdata->chan, &devdata->vbus_hdr_info, | |
1220 | &chipset_driverinfo); | |
1221 | write_vbus_bus_info(devdata->chan, &devdata->vbus_hdr_info, | |
1222 | &clientbus_driverinfo); | |
1223 | } | |
1224 | ||
1225 | /** Create a device instance for the visor bus itself. | |
1226 | */ | |
1227 | static struct visorbus_devdata * | |
1228 | create_bus_instance(int id) | |
1229 | { | |
1230 | struct visorbus_devdata *rc = NULL; | |
1231 | struct visorbus_devdata *devdata = NULL; | |
1232 | struct device *dev; | |
1233 | struct visorchipset_bus_info bus_info; | |
1234 | ||
1235 | POSTCODE_LINUX_2(BUS_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO); | |
1236 | dev = kmalloc(sizeof(*dev), GFP_KERNEL); | |
1237 | if (!dev) { | |
1238 | POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR); | |
1239 | rc = NULL; | |
1240 | goto away; | |
1241 | } | |
1242 | memset(dev, 0, sizeof(struct device)); | |
1243 | dev_set_name(dev, "visorbus%d", id); | |
1244 | dev->release = visorbus_release_busdevice; | |
1245 | if (device_register(dev) < 0) { | |
1246 | POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, id, | |
1247 | POSTCODE_SEVERITY_ERR); | |
1248 | rc = NULL; | |
1249 | goto away; | |
1250 | } | |
1251 | devdata = kmalloc(sizeof(*devdata), GFP_KERNEL); | |
1252 | if (!devdata) { | |
1253 | POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR); | |
1254 | rc = NULL; | |
1255 | goto away; | |
1256 | } | |
1257 | memset(devdata, 0, sizeof(struct visorbus_devdata)); | |
1258 | devdata->devno = id; | |
1259 | devdata->dev = dev; | |
1260 | if ((visorchipset_get_bus_info(id, &bus_info)) && | |
1261 | (bus_info.chan_info.channel_addr > 0) && | |
1262 | (bus_info.chan_info.n_channel_bytes > 0)) { | |
1263 | HOSTADDRESS channel_addr = bus_info.chan_info.channel_addr; | |
1264 | unsigned long n_channel_bytes = | |
1265 | (unsigned long) | |
1266 | bus_info.chan_info.n_channel_bytes; | |
1267 | uuid_le channel_type_guid = | |
1268 | bus_info.chan_info.channel_type_uuid; | |
1269 | ||
1270 | devdata->chan = visorchannel_create(channel_addr, | |
1271 | n_channel_bytes, | |
1272 | channel_type_guid); | |
1273 | if (!devdata->chan) { | |
1274 | POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, channel_addr, | |
1275 | POSTCODE_SEVERITY_ERR); | |
1276 | } else { | |
1277 | if (bus_info.flags.server) { | |
1278 | init_vbus_channel(devdata->chan); | |
1279 | } else { | |
1280 | if (get_vbus_header_info(devdata->chan, | |
1281 | &devdata-> | |
1282 | vbus_hdr_info) >= 0) { | |
1283 | devdata->vbus_valid = TRUE; | |
1284 | write_vbus_chp_info(devdata->chan, | |
1285 | &devdata-> | |
1286 | vbus_hdr_info, | |
1287 | &chipset_driverinfo | |
1288 | ); | |
1289 | write_vbus_bus_info(devdata->chan, | |
1290 | &devdata-> | |
1291 | vbus_hdr_info, | |
1292 | &clientbus_driverinfo); | |
1293 | } | |
1294 | } | |
1295 | } | |
1296 | } | |
1297 | register_businst_attributes(devdata); | |
1298 | bus_count++; | |
1299 | list_add_tail(&devdata->list_all, &list_all_bus_instances); | |
1300 | if (id == 0) | |
1301 | devdata = devdata; /* for testing ONLY */ | |
1302 | dev_set_drvdata(dev, devdata); | |
1303 | rc = devdata; | |
1304 | away: | |
1305 | return rc; | |
1306 | } | |
1307 | ||
1308 | /** Remove a device instance for the visor bus itself. | |
1309 | */ | |
1310 | static void | |
1311 | remove_bus_instance(struct visorbus_devdata *devdata) | |
1312 | { | |
1313 | /* Note that this will result in the release method for | |
1314 | * devdata->dev being called, which will call | |
1315 | * visorbus_release_busdevice(). This has something to do with | |
1316 | * the put_device() done in device_unregister(), but I have never | |
1317 | * successfully been able to trace thru the code to see where/how | |
1318 | * release() gets called. But I know it does. | |
1319 | */ | |
1320 | unregister_businst_attributes(devdata); | |
1321 | bus_count--; | |
1322 | if (devdata->chan) { | |
1323 | visorchannel_destroy(devdata->chan); | |
1324 | devdata->chan = NULL; | |
1325 | } | |
1326 | list_del(&devdata->list_all); | |
1327 | device_unregister(devdata->dev); | |
1328 | } | |
1329 | ||
1330 | /** Create and register the one-and-only one instance of | |
1331 | * the visor bus type (visorbus_type). | |
1332 | */ | |
1333 | static int | |
1334 | create_bus_type(void) | |
1335 | { | |
1336 | int rc = 0; | |
1337 | ||
1338 | visorbus_type.dev_attrs = visor_device_attrs; | |
1339 | rc = bus_register(&visorbus_type); | |
1340 | if (rc < 0) | |
1341 | return rc; | |
1342 | ||
1343 | rc = register_bustype_attributes(); | |
1344 | return rc; | |
1345 | } | |
1346 | ||
1347 | /** Remove the one-and-only one instance of the visor bus type (visorbus_type). | |
1348 | */ | |
1349 | static void | |
1350 | remove_bus_type(void) | |
1351 | { | |
1352 | unregister_bustype_attributes(); | |
1353 | bus_unregister(&visorbus_type); | |
1354 | } | |
1355 | ||
1356 | /** Remove all child visor bus device instances. | |
1357 | */ | |
1358 | static void | |
1359 | remove_all_visor_devices(void) | |
1360 | { | |
1361 | struct list_head *listentry, *listtmp; | |
1362 | ||
1363 | list_for_each_safe(listentry, listtmp, &list_all_device_instances) { | |
1364 | struct visor_device *dev = list_entry(listentry, | |
1365 | struct visor_device, | |
1366 | list_all); | |
1367 | remove_visor_device(dev); | |
1368 | } | |
1369 | } | |
1370 | ||
1371 | static bool entered_testing_mode = FALSE; | |
1372 | static struct visorchipset_channel_info test_channel_infos[MAXDEVICETEST]; | |
1373 | static unsigned long test_bus_nos[MAXDEVICETEST]; | |
1374 | static unsigned long test_dev_nos[MAXDEVICETEST]; | |
1375 | ||
1376 | static void | |
1377 | chipset_bus_create(u32 bus_no) | |
1378 | { | |
1379 | struct visorchipset_bus_info bus_info; | |
1380 | struct visorbus_devdata *devdata; | |
1381 | int rc = -1; | |
1382 | ||
1383 | POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, bus_no, POSTCODE_SEVERITY_INFO); | |
1384 | if (!visorchipset_get_bus_info(bus_no, &bus_info)) | |
1385 | goto away; | |
1386 | devdata = create_bus_instance(bus_no); | |
1387 | if (!devdata) | |
1388 | goto away; | |
1389 | if (!visorchipset_set_bus_context(bus_no, devdata)) | |
1390 | goto away; | |
1391 | POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus_no, POSTCODE_SEVERITY_INFO); | |
1392 | rc = 0; | |
1393 | away: | |
1394 | if (rc < 0) { | |
1395 | POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no, | |
1396 | POSTCODE_SEVERITY_ERR); | |
1397 | return; | |
1398 | } | |
1399 | POSTCODE_LINUX_3(CHIPSET_INIT_SUCCESS_PC, bus_no, | |
1400 | POSTCODE_SEVERITY_INFO); | |
1401 | if (chipset_responders.bus_create) | |
1402 | (*chipset_responders.bus_create) (bus_no, rc); | |
1403 | } | |
1404 | ||
1405 | static void | |
1406 | chipset_bus_destroy(u32 bus_no) | |
1407 | { | |
1408 | struct visorchipset_bus_info bus_info; | |
1409 | struct visorbus_devdata *devdata; | |
1410 | int rc = -1; | |
1411 | ||
1412 | if (!visorchipset_get_bus_info(bus_no, &bus_info)) | |
1413 | goto away; | |
1414 | devdata = (struct visorbus_devdata *)(bus_info.bus_driver_context); | |
1415 | if (!devdata) | |
1416 | goto away; | |
1417 | remove_bus_instance(devdata); | |
1418 | if (!visorchipset_set_bus_context(bus_no, NULL)) | |
1419 | goto away; | |
1420 | rc = 0; | |
1421 | away: | |
1422 | if (rc < 0) | |
1423 | return; | |
1424 | if (chipset_responders.bus_destroy) | |
1425 | (*chipset_responders.bus_destroy)(bus_no, rc); | |
1426 | } | |
1427 | ||
1428 | static void | |
1429 | chipset_device_create(u32 bus_no, u32 dev_no) | |
1430 | { | |
1431 | struct visorchipset_device_info dev_info; | |
1432 | struct visorchipset_bus_info bus_info; | |
1433 | struct visorbus_devdata *devdata = NULL; | |
1434 | int rc = -1; | |
1435 | ||
1436 | POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no, | |
1437 | POSTCODE_SEVERITY_INFO); | |
1438 | ||
1439 | if (entered_testing_mode) | |
1440 | return; | |
1441 | if (!visorchipset_get_device_info(bus_no, dev_no, &dev_info)) | |
1442 | goto away; | |
1443 | if (!visorchipset_get_bus_info(bus_no, &bus_info)) | |
1444 | goto away; | |
1445 | if (visorbus_devicetest) | |
1446 | if (total_devices_created < MAXDEVICETEST) { | |
1447 | test_channel_infos[total_devices_created] = | |
1448 | dev_info.chan_info; | |
1449 | test_bus_nos[total_devices_created] = bus_no; | |
1450 | test_dev_nos[total_devices_created] = dev_no; | |
1451 | } | |
1452 | POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, dev_no, bus_no, | |
1453 | POSTCODE_SEVERITY_INFO); | |
1454 | rc = 0; | |
1455 | away: | |
1456 | if (rc < 0) { | |
1457 | POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, | |
1458 | POSTCODE_SEVERITY_ERR); | |
1459 | return; | |
1460 | } | |
1461 | devdata = (struct visorbus_devdata *)(bus_info.bus_driver_context); | |
1462 | rc = create_visor_device(devdata, bus_no, dev_no, | |
1463 | dev_info.chan_info, bus_info.partition_handle); | |
1464 | POSTCODE_LINUX_4(DEVICE_CREATE_SUCCESS_PC, dev_no, bus_no, | |
1465 | POSTCODE_SEVERITY_INFO); | |
1466 | if (rc < 0) | |
1467 | if (chipset_responders.device_create) | |
1468 | (*chipset_responders.device_create)(bus_no, dev_no, rc); | |
1469 | } | |
1470 | ||
1471 | static void | |
1472 | chipset_device_destroy(u32 bus_no, u32 dev_no) | |
1473 | { | |
1474 | struct visorchipset_device_info dev_info; | |
1475 | struct visor_device *dev; | |
1476 | int rc = -1; | |
1477 | ||
1478 | if (entered_testing_mode) | |
1479 | return; | |
1480 | if (!visorchipset_get_device_info(bus_no, dev_no, &dev_info)) | |
1481 | goto away; | |
1482 | dev = find_visor_device_by_channel(dev_info.chan_info.channel_addr); | |
1483 | if (!dev) | |
1484 | goto away; | |
1485 | rc = 0; | |
1486 | away: | |
1487 | if (rc < 0) | |
1488 | return; | |
1489 | ||
1490 | if (chipset_responders.device_destroy) | |
1491 | (*chipset_responders.device_destroy) (bus_no, dev_no, rc); | |
1492 | remove_visor_device(dev); | |
1493 | } | |
1494 | ||
1495 | /* This is the callback function specified for a function driver, to | |
1496 | * be called when a pending "pause device" operation has been | |
1497 | * completed. | |
1498 | */ | |
1499 | static void | |
1500 | pause_state_change_complete(struct visor_device *dev, int status) | |
1501 | { | |
1502 | if (!dev->pausing) | |
1503 | return; | |
1504 | ||
1505 | dev->pausing = FALSE; | |
1506 | if (!chipset_responders.device_pause) /* this can never happen! */ | |
1507 | return; | |
1508 | ||
1509 | /* Notify the chipset driver that the pause is complete, which | |
1510 | * will presumably want to send some sort of response to the | |
1511 | * initiator. */ | |
1512 | (*chipset_responders.device_pause) (dev->chipset_bus_no, | |
1513 | dev->chipset_dev_no, status); | |
1514 | } | |
1515 | ||
1516 | /* This is the callback function specified for a function driver, to | |
1517 | * be called when a pending "resume device" operation has been | |
1518 | * completed. | |
1519 | */ | |
1520 | static void | |
1521 | resume_state_change_complete(struct visor_device *dev, int status) | |
1522 | { | |
1523 | if (!dev->resuming) | |
1524 | return; | |
1525 | ||
1526 | dev->resuming = FALSE; | |
1527 | if (!chipset_responders.device_resume) /* this can never happen! */ | |
1528 | return; | |
1529 | ||
1530 | /* Notify the chipset driver that the resume is complete, | |
1531 | * which will presumably want to send some sort of response to | |
1532 | * the initiator. */ | |
1533 | (*chipset_responders.device_resume) (dev->chipset_bus_no, | |
1534 | dev->chipset_dev_no, status); | |
1535 | } | |
1536 | ||
1537 | /* Tell the subordinate function driver for a specific device to pause | |
1538 | * or resume that device. Result is returned asynchronously via a | |
1539 | * callback function. | |
1540 | */ | |
1541 | static void | |
1542 | initiate_chipset_device_pause_resume(u32 bus_no, u32 dev_no, bool is_pause) | |
1543 | { | |
1544 | struct visorchipset_device_info dev_info; | |
1545 | struct visor_device *dev = NULL; | |
1546 | int rc = -1, x; | |
1547 | struct visor_driver *drv = NULL; | |
1548 | void (*notify_func)(u32 bus_no, u32 dev_no, int response) = NULL; | |
1549 | ||
1550 | if (is_pause) | |
1551 | notify_func = chipset_responders.device_pause; | |
1552 | else | |
1553 | notify_func = chipset_responders.device_resume; | |
1554 | if (!notify_func) | |
1555 | goto away; | |
1556 | ||
1557 | if (!visorchipset_get_device_info(bus_no, dev_no, &dev_info)) | |
1558 | goto away; | |
1559 | ||
1560 | dev = find_visor_device_by_channel(dev_info.chan_info.channel_addr); | |
1561 | if (!dev) | |
1562 | goto away; | |
1563 | ||
1564 | drv = to_visor_driver(dev->device.driver); | |
1565 | if (!drv) | |
1566 | goto away; | |
1567 | ||
1568 | if (dev->pausing || dev->resuming) | |
1569 | goto away; | |
1570 | ||
1571 | /* Note that even though both drv->pause() and drv->resume | |
1572 | * specify a callback function, it is NOT necessary for us to | |
1573 | * increment our local module usage count. Reason is, there | |
1574 | * is already a linkage dependency between child function | |
1575 | * drivers and visorbus, so it is already IMPOSSIBLE to unload | |
1576 | * visorbus while child function drivers are still running. | |
1577 | */ | |
1578 | if (is_pause) { | |
1579 | if (!drv->pause) | |
1580 | goto away; | |
1581 | ||
1582 | dev->pausing = TRUE; | |
1583 | x = drv->pause(dev, pause_state_change_complete); | |
1584 | } else { | |
1585 | /* This should be done at BUS resume time, but an | |
1586 | * existing problem prevents us from ever getting a bus | |
1587 | * resume... This hack would fail to work should we | |
1588 | * ever have a bus that contains NO devices, since we | |
1589 | * would never even get here in that case. */ | |
1590 | fix_vbus_dev_info(dev); | |
1591 | if (!drv->resume) | |
1592 | goto away; | |
1593 | ||
1594 | dev->resuming = TRUE; | |
1595 | x = drv->resume(dev, resume_state_change_complete); | |
1596 | } | |
1597 | if (x < 0) { | |
1598 | if (is_pause) | |
1599 | dev->pausing = FALSE; | |
1600 | else | |
1601 | dev->resuming = FALSE; | |
1602 | goto away; | |
1603 | } | |
1604 | rc = 0; | |
1605 | away: | |
1606 | if (rc < 0) { | |
1607 | if (notify_func) | |
1608 | (*notify_func)(bus_no, dev_no, rc); | |
1609 | } | |
1610 | } | |
1611 | ||
1612 | static void | |
1613 | chipset_device_pause(u32 bus_no, u32 dev_no) | |
1614 | { | |
1615 | initiate_chipset_device_pause_resume(bus_no, dev_no, TRUE); | |
1616 | } | |
1617 | ||
1618 | static void | |
1619 | chipset_device_resume(u32 bus_no, u32 dev_no) | |
1620 | { | |
1621 | initiate_chipset_device_pause_resume(bus_no, dev_no, FALSE); | |
1622 | } | |
1623 | ||
1624 | struct channel_size_info { | |
1625 | uuid_le guid; | |
1626 | unsigned long min_size; | |
1627 | unsigned long max_size; | |
1628 | }; | |
1629 | ||
1630 | static int __init | |
1631 | visorbus_init(void) | |
1632 | { | |
1633 | int rc = 0; | |
1634 | ||
1635 | POSTCODE_LINUX_3(DRIVER_ENTRY_PC, rc, POSTCODE_SEVERITY_INFO); | |
1636 | bus_device_info_init(&clientbus_driverinfo, | |
1637 | "clientbus", MYDRVNAME, | |
1638 | VERSION, NULL); | |
1639 | ||
1640 | /* process module options */ | |
1641 | ||
1642 | if (visorbus_devicetest > MAXDEVICETEST) | |
1643 | visorbus_devicetest = MAXDEVICETEST; | |
1644 | ||
1645 | rc = create_bus_type(); | |
1646 | if (rc < 0) { | |
1647 | POSTCODE_LINUX_2(BUS_CREATE_ENTRY_PC, DIAG_SEVERITY_ERR); | |
1648 | goto away; | |
1649 | } | |
1650 | ||
1651 | periodic_dev_workqueue = create_singlethread_workqueue("visorbus_dev"); | |
1652 | if (!periodic_dev_workqueue) { | |
1653 | POSTCODE_LINUX_2(CREATE_WORKQUEUE_PC, DIAG_SEVERITY_ERR); | |
1654 | rc = -ENOMEM; | |
1655 | goto away; | |
1656 | } | |
1657 | ||
1658 | /* This enables us to receive notifications when devices appear for | |
1659 | * which this service partition is to be a server for. | |
1660 | */ | |
1661 | visorchipset_register_busdev_server(&chipset_notifiers, | |
1662 | &chipset_responders, | |
1663 | &chipset_driverinfo); | |
1664 | ||
1665 | rc = 0; | |
1666 | ||
1667 | away: | |
1668 | if (rc) | |
1669 | POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, rc, | |
1670 | POSTCODE_SEVERITY_ERR); | |
1671 | return rc; | |
1672 | } | |
1673 | ||
1674 | static void | |
1675 | visorbus_exit(void) | |
1676 | { | |
1677 | struct list_head *listentry, *listtmp; | |
1678 | ||
1679 | visorchipset_register_busdev_server(NULL, NULL, NULL); | |
1680 | remove_all_visor_devices(); | |
1681 | ||
1682 | flush_workqueue(periodic_dev_workqueue); /* better not be any work! */ | |
1683 | destroy_workqueue(periodic_dev_workqueue); | |
1684 | periodic_dev_workqueue = NULL; | |
1685 | ||
1686 | if (periodic_test_workqueue) { | |
1687 | cancel_delayed_work(&periodic_work); | |
1688 | flush_workqueue(periodic_test_workqueue); | |
1689 | destroy_workqueue(periodic_test_workqueue); | |
1690 | periodic_test_workqueue = NULL; | |
1691 | } | |
1692 | ||
1693 | list_for_each_safe(listentry, listtmp, &list_all_bus_instances) { | |
1694 | struct visorbus_devdata *devdata = list_entry(listentry, | |
1695 | struct | |
1696 | visorbus_devdata, | |
1697 | list_all); | |
1698 | remove_bus_instance(devdata); | |
1699 | } | |
1700 | remove_bus_type(); | |
1701 | } | |
1702 | ||
1703 | module_param_named(debug, visorbus_debug, int, S_IRUGO); | |
1704 | MODULE_PARM_DESC(visorbus_debug, "1 to debug"); | |
1705 | int visorbus_debug = 0; | |
1706 | ||
1707 | module_param_named(forcematch, visorbus_forcematch, int, S_IRUGO); | |
1708 | MODULE_PARM_DESC(visorbus_forcematch, | |
1709 | "1 to force a successful dev <--> drv match"); | |
1710 | int visorbus_forcematch = 0; | |
1711 | ||
1712 | module_param_named(forcenomatch, visorbus_forcenomatch, int, S_IRUGO); | |
1713 | MODULE_PARM_DESC(visorbus_forcenomatch, | |
1714 | "1 to force an UNsuccessful dev <--> drv match"); | |
1715 | int visorbus_forcenomatch = 0; | |
1716 | ||
1717 | module_param_named(devicetest, visorbus_devicetest, int, S_IRUGO); | |
1718 | MODULE_PARM_DESC(visorbus_devicetest, | |
1719 | "non-0 to just test device creation and destruction"); | |
1720 | int visorbus_devicetest = 0; | |
1721 | ||
1722 | module_param_named(debugref, visorbus_debugref, int, S_IRUGO); | |
1723 | MODULE_PARM_DESC(visorbus_debugref, "1 to debug reference counting"); | |
1724 | int visorbus_debugref = 0; | |
1725 | ||
1726 | module_param_named(serialloopbacktest, visorbus_serialloopbacktest, | |
1727 | int, S_IRUGO); | |
1728 | MODULE_PARM_DESC(visorbus_serialloopbacktest, | |
1729 | "non-0 to just create 2 serial devices on the same channel"); | |
1730 | int visorbus_serialloopbacktest = 0; | |
1731 | ||
1732 | module_init(visorbus_init); | |
1733 | module_exit(visorbus_exit); | |
1734 | ||
1735 | MODULE_AUTHOR("Unisys"); | |
1736 | MODULE_LICENSE("GPL"); | |
1737 | MODULE_DESCRIPTION("Supervisor bus driver for service partition: ver " VERSION); | |
1738 | MODULE_VERSION(VERSION); |