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