staging: unisys: remove BOOL,TRUE,FALSE definitions
[deliverable/linux.git] / drivers / staging / unisys / visorbus / visorbus_main.c
CommitLineData
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
4b78000e 20#include "visorbus.h"
c79b28f7 21#include "visorbus_private.h"
4b78000e 22#include "version.h"
a9a7c767 23#include "timskmod.h"
3703987c
EA
24#include "periodic_work.h"
25#include "vbuschannel.h"
26#include "guestlinuxdebug.h"
27#include "vbusdeviceinfo.h"
4b78000e 28
c79b28f7
PB
29#define MYDRVNAME "visorbus"
30
4b78000e
PB
31/* module parameters */
32int visorbus_debug;
33int visorbus_forcematch;
34int visorbus_forcenomatch;
35#define MAXDEVICETEST 4
36int visorbus_devicetest;
37int visorbus_debugref;
4b78000e
PB
38#define SERIALLOOPBACKCHANADDR (100 * 1024 * 1024)
39
40/** This is the private data that we store for each bus device instance.
41 */
42struct 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
3703987c
EA
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 */
56struct 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
73struct 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
88static int visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env);
89static int visorbus_match(struct device *xdev, struct device_driver *xdrv);
90static 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 */
95static struct bus_type visorbus_type = {
96 .name = "visorbus",
97 .match = visorbus_match,
98 .uevent = visorbus_uevent,
99};
100
101static 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 */
108static struct workqueue_struct *periodic_test_workqueue;
109static struct workqueue_struct *periodic_dev_workqueue;
110static long long bus_count; /** number of bus instances */
111static long long total_devices_created;
112 /** ever-increasing */
113
114static void chipset_bus_create(u32 bus_no);
115static void chipset_bus_destroy(u32 bus_no);
116static void chipset_device_create(u32 bus_no, u32 dev_no);
117static void chipset_device_destroy(u32 bus_no, u32 dev_no);
118static void chipset_device_pause(u32 bus_no, u32 dev_no);
119static 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 */
124static 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 */
136static struct visorchipset_busdev_responders chipset_responders;
137
138/* filled in with info about parent chipset driver when we register with it */
139static struct ultra_vbus_deviceinfo chipset_driverinfo;
140/* filled in with info about this driver, wrt it servicing client busses */
141static struct ultra_vbus_deviceinfo clientbus_driverinfo;
142
143/** list of visorbus_devdata structs, linked via .list_all */
144static LIST_HEAD(list_all_bus_instances);
145/** list of visor_device structs, linked via .list_all */
146static LIST_HEAD(list_all_device_instances);
147
148static int
149visorbus_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 */
160static int
161visorbus_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 }
190away:
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 */
198static void
199visorbus_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 */
211static void
212visorbus_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
32710457
PB
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
238struct 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
246static 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
256static ssize_t
257devmajorminor_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
270static ssize_t
271devmajorminor_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
286static int register_devmajorminor_attributes(struct visor_device *dev);
287
288int
289devmajorminor_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);
324away:
325 if (rc < 0) {
326 kfree(myattr);
327 myattr = NULL;
328 dev->devnodes[slot].attr = NULL;
329 }
330 return rc;
331}
332
333void
334devmajorminor_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
350void
351devmajorminor_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
360static const struct sysfs_ops devmajorminor_sysfs_ops = {
361 .show = devmajorminor_attr_show,
362 .store = devmajorminor_attr_store,
363};
364
365static struct kobj_type devmajorminor_kobj_type = {
366 .sysfs_ops = &devmajorminor_sysfs_ops
367};
368
369static int
370register_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
386away:
387 return rc;
388}
389
390void
391unregister_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
826b6a0f
PB
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
413struct 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*/
422static 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
430static 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
438static 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
446static 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
456static 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
466static 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
482static 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
500static 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
519static 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
531static 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
543static 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
549static void channel_remove_file(struct visor_device *dev,
550 struct channel_attribute *attr)
551{
552 sysfs_remove_file(&dev->kobjchannel, &attr->attr);
553}
554
555static const struct sysfs_ops channel_sysfs_ops = {
556 .show = channel_attr_show,
557 .store = channel_attr_store,
558};
559
560static struct kobj_type channel_kobj_type = {
561 .sysfs_ops = &channel_sysfs_ops
562};
563
564int 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 }
591away:
592 return rc;
593}
594
595void 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}
a9a7c767
PB
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
653struct 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
665static ssize_t
666businst_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
678static ssize_t
679businst_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
691static int
692businst_create_file(struct visorbus_devdata *bus,
693 struct businst_attribute *attr)
694{
695 return sysfs_create_file(&bus->kobj, &attr->attr);
696}
697
698static void
699businst_remove_file(struct visorbus_devdata *bus,
700 struct businst_attribute *attr)
701{
702 sysfs_remove_file(&bus->kobj, &attr->attr);
703}
704
3703987c
EA
705static const struct sysfs_ops businst_sysfs_ops = {
706 .show = businst_attr_show,
707 .store = businst_attr_store,
708};
709
710static struct kobj_type businst_kobj_type = {
711 .sysfs_ops = &businst_sysfs_ops
712};
713
714static 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
725static ssize_t
726BUSTYPE_ATTR_version(struct bus_type *bus, char *buf)
727{
728 return snprintf(buf, PAGE_SIZE, "%s\n", VERSION);
729}
730
731static struct bus_attribute bustype_attr_version =
732__ATTR(version, S_IRUGO, BUSTYPE_ATTR_version, NULL);
733
734static int
735register_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;
756away:
757 return rc;
758}
759
760static void
761unregister_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
778static 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
790static 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
801static 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
813static 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
824static 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
835static 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
847static 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
907static struct businst_attribute ba_partition_handle =
908 __ATTR(partition_handle, S_IRUGO, businst_attr_partition_handle, NULL);
909static struct businst_attribute ba_partition_guid =
910 __ATTR(partition_guid, S_IRUGO, businst_attr_partition_guid, NULL);
911static struct businst_attribute ba_partition_name =
912 __ATTR(partition_name, S_IRUGO, businst_attr_partition_name, NULL);
913static struct businst_attribute ba_channel_addr =
914 __ATTR(channel_addr, S_IRUGO, businst_attr_channel_addr, NULL);
915static struct businst_attribute ba_nchannel_bytes =
916 __ATTR(nchannel_bytes, S_IRUGO, businst_attr_nchannel_bytes, NULL);
917static struct businst_attribute ba_channel_id =
918 __ATTR(channel_id, S_IRUGO, businst_attr_channel_id, NULL);
919static struct businst_attribute ba_client_bus_info =
920 __ATTR(client_bus_info, S_IRUGO, businst_attr_client_bus_info, NULL);
921
922static int
923register_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;
964away:
965 return rc;
966}
967
968static void
969unregister_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
988static ssize_t
989DRIVER_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
996static int
997register_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
1007static void
1008unregister_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
1027static struct device_attribute visor_device_attrs[] = {
1028 /* DEVATTR(channel_nbytes, DEVICE_ATTR_channel_nbytes), */
1029 __ATTR_NULL
1030};
1031
1032static void
1033dev_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
1046static void
1047dev_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
1057static void
1058dev_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 */
1069static int
1070visordriver_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);
779d0752 1079 dev->being_removed = false;
3703987c
EA
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;
1098away:
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) {
779d0752 1109 dev->responded_to_device_create = true;
3703987c
EA
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 */
1122static int
1123visordriver_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);
779d0752 1132 dev->being_removed = true;
3703987c
EA
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 */
1193int 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}
1221EXPORT_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 */
1226void
1227visorbus_unregister_visor_driver(struct visor_driver *drv)
1228{
1229 unregister_driver_attributes(drv);
1230 driver_unregister(&drv->driver);
1231}
1232EXPORT_SYMBOL_GPL(visorbus_unregister_visor_driver);
1233
1234int
1235visorbus_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}
1240EXPORT_SYMBOL_GPL(visorbus_read_channel);
1241
1242int
1243visorbus_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}
1248EXPORT_SYMBOL_GPL(visorbus_write_channel);
1249
1250int
1251visorbus_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}
1256EXPORT_SYMBOL_GPL(visorbus_clear_channel);
1257
1258int
1259visorbus_registerdevnode(struct visor_device *dev,
1260 const char *name, int major, int minor)
1261{
1262 return devmajorminor_create_file(dev, name, major, minor);
1263}
1264EXPORT_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 */
1269void
1270visorbus_enable_channel_interrupts(struct visor_device *dev)
1271{
1272 dev_start_periodic_work(dev);
1273}
1274EXPORT_SYMBOL_GPL(visorbus_enable_channel_interrupts);
1275
1276void
1277visorbus_disable_channel_interrupts(struct visor_device *dev)
1278{
1279 dev_stop_periodic_work(dev);
1280}
1281EXPORT_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 */
1297static int
1298create_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;
779d0752 1306 bool gotten = false, registered1 = false, registered2 = false;
3703987c
EA
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);
779d0752 1340 gotten = true;
3703987c
EA
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
779d0752 1390 registered1 = true;
3703987c
EA
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
779d0752 1399 registered2 = true;
3703987c
EA
1400 rc = 0;
1401
1402away:
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
1420static void
1421remove_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
1430static struct visor_device *
1431find_visor_device_by_channel(HOSTADDRESS 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
1446static int
1447init_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
1488away:
1489 kfree(x);
1490 x = NULL;
1491 return rc;
1492}
1493
1494static int
1495get_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;
1513away:
1514 return rc;
1515}
1516
1517/* Write the contents of <info> to the struct
1518 * spar_vbus_channel_protocol.chp_info. */
1519
1520static int
1521write_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
1538static int
1539write_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 */
1556static int
1557write_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 */
1578static void
1579fix_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 (STRUCTSEQUAL(visordrv->channel_types[i].guid,
1611 visordev->channel_type_guid)) {
1612 chan_type_name = visordrv->channel_types[i].name;
1613 break;
1614 }
1615 }
1616
1617 bus_device_info_init(&dev_info, chan_type_name,
1618 visordrv->name, visordrv->version,
1619 visordrv->vertag);
1620 write_vbus_dev_info(devdata->chan,
1621 &devdata->vbus_hdr_info, &dev_info, dev_no);
1622
1623 /* Re-write bus+chipset info, because it is possible that this
1624 * was previously written by our evil counterpart, virtpci.
1625 */
1626 write_vbus_chp_info(devdata->chan, &devdata->vbus_hdr_info,
1627 &chipset_driverinfo);
1628 write_vbus_bus_info(devdata->chan, &devdata->vbus_hdr_info,
1629 &clientbus_driverinfo);
1630}
1631
1632/** Create a device instance for the visor bus itself.
1633 */
1634static struct visorbus_devdata *
1635create_bus_instance(int id)
1636{
1637 struct visorbus_devdata *rc = NULL;
1638 struct visorbus_devdata *devdata = NULL;
1639 struct device *dev;
1640 struct visorchipset_bus_info bus_info;
1641
1642 POSTCODE_LINUX_2(BUS_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
1643 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
1644 if (!dev) {
1645 POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR);
1646 rc = NULL;
1647 goto away;
1648 }
1649 memset(dev, 0, sizeof(struct device));
1650 dev_set_name(dev, "visorbus%d", id);
1651 dev->release = visorbus_release_busdevice;
1652 if (device_register(dev) < 0) {
1653 POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, id,
1654 POSTCODE_SEVERITY_ERR);
1655 rc = NULL;
1656 goto away;
1657 }
1658 devdata = kmalloc(sizeof(*devdata), GFP_KERNEL);
1659 if (!devdata) {
1660 POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR);
1661 rc = NULL;
1662 goto away;
1663 }
1664 memset(devdata, 0, sizeof(struct visorbus_devdata));
1665 devdata->devno = id;
1666 devdata->dev = dev;
1667 if ((visorchipset_get_bus_info(id, &bus_info)) &&
1668 (bus_info.chan_info.channel_addr > 0) &&
1669 (bus_info.chan_info.n_channel_bytes > 0)) {
1670 HOSTADDRESS channel_addr = bus_info.chan_info.channel_addr;
1671 unsigned long n_channel_bytes =
1672 (unsigned long)
1673 bus_info.chan_info.n_channel_bytes;
1674 uuid_le channel_type_guid =
1675 bus_info.chan_info.channel_type_uuid;
1676
1677 devdata->chan = visorchannel_create(channel_addr,
1678 n_channel_bytes,
1679 channel_type_guid);
1680 if (!devdata->chan) {
1681 POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, channel_addr,
1682 POSTCODE_SEVERITY_ERR);
1683 } else {
1684 if (bus_info.flags.server) {
1685 init_vbus_channel(devdata->chan);
1686 } else {
1687 if (get_vbus_header_info(devdata->chan,
1688 &devdata->
1689 vbus_hdr_info) >= 0) {
779d0752 1690 devdata->vbus_valid = true;
3703987c
EA
1691 write_vbus_chp_info(devdata->chan,
1692 &devdata->
1693 vbus_hdr_info,
1694 &chipset_driverinfo
1695 );
1696 write_vbus_bus_info(devdata->chan,
1697 &devdata->
1698 vbus_hdr_info,
1699 &clientbus_driverinfo);
1700 }
1701 }
1702 }
1703 }
1704 register_businst_attributes(devdata);
1705 bus_count++;
1706 list_add_tail(&devdata->list_all, &list_all_bus_instances);
1707 if (id == 0)
1708 devdata = devdata; /* for testing ONLY */
1709 dev_set_drvdata(dev, devdata);
1710 rc = devdata;
1711away:
1712 return rc;
1713}
1714
1715/** Remove a device instance for the visor bus itself.
1716 */
1717static void
1718remove_bus_instance(struct visorbus_devdata *devdata)
1719{
1720 /* Note that this will result in the release method for
1721 * devdata->dev being called, which will call
1722 * visorbus_release_busdevice(). This has something to do with
1723 * the put_device() done in device_unregister(), but I have never
1724 * successfully been able to trace thru the code to see where/how
1725 * release() gets called. But I know it does.
1726 */
1727 unregister_businst_attributes(devdata);
1728 bus_count--;
1729 if (devdata->chan) {
1730 visorchannel_destroy(devdata->chan);
1731 devdata->chan = NULL;
1732 }
1733 list_del(&devdata->list_all);
1734 device_unregister(devdata->dev);
1735}
1736
1737/** Create and register the one-and-only one instance of
1738 * the visor bus type (visorbus_type).
1739 */
1740static int
1741create_bus_type(void)
1742{
1743 int rc = 0;
1744
1745 visorbus_type.dev_attrs = visor_device_attrs;
1746 rc = bus_register(&visorbus_type);
1747 if (rc < 0)
1748 return rc;
1749
1750 rc = register_bustype_attributes();
1751 return rc;
1752}
1753
1754/** Remove the one-and-only one instance of the visor bus type (visorbus_type).
1755 */
1756static void
1757remove_bus_type(void)
1758{
1759 unregister_bustype_attributes();
1760 bus_unregister(&visorbus_type);
1761}
1762
1763/** Remove all child visor bus device instances.
1764 */
1765static void
1766remove_all_visor_devices(void)
1767{
1768 struct list_head *listentry, *listtmp;
1769
1770 list_for_each_safe(listentry, listtmp, &list_all_device_instances) {
1771 struct visor_device *dev = list_entry(listentry,
1772 struct visor_device,
1773 list_all);
1774 remove_visor_device(dev);
1775 }
1776}
1777
779d0752 1778static bool entered_testing_mode;
3703987c
EA
1779static struct visorchipset_channel_info test_channel_infos[MAXDEVICETEST];
1780static unsigned long test_bus_nos[MAXDEVICETEST];
1781static unsigned long test_dev_nos[MAXDEVICETEST];
1782
1783static void
1784chipset_bus_create(u32 bus_no)
1785{
1786 struct visorchipset_bus_info bus_info;
1787 struct visorbus_devdata *devdata;
1788 int rc = -1;
1789
1790 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, bus_no, POSTCODE_SEVERITY_INFO);
1791 if (!visorchipset_get_bus_info(bus_no, &bus_info))
1792 goto away;
1793 devdata = create_bus_instance(bus_no);
1794 if (!devdata)
1795 goto away;
1796 if (!visorchipset_set_bus_context(bus_no, devdata))
1797 goto away;
1798 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus_no, POSTCODE_SEVERITY_INFO);
1799 rc = 0;
1800away:
1801 if (rc < 0) {
1802 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no,
1803 POSTCODE_SEVERITY_ERR);
1804 return;
1805 }
1806 POSTCODE_LINUX_3(CHIPSET_INIT_SUCCESS_PC, bus_no,
1807 POSTCODE_SEVERITY_INFO);
1808 if (chipset_responders.bus_create)
1809 (*chipset_responders.bus_create) (bus_no, rc);
1810}
1811
1812static void
1813chipset_bus_destroy(u32 bus_no)
1814{
1815 struct visorchipset_bus_info bus_info;
1816 struct visorbus_devdata *devdata;
1817 int rc = -1;
1818
1819 if (!visorchipset_get_bus_info(bus_no, &bus_info))
1820 goto away;
1821 devdata = (struct visorbus_devdata *)(bus_info.bus_driver_context);
1822 if (!devdata)
1823 goto away;
1824 remove_bus_instance(devdata);
1825 if (!visorchipset_set_bus_context(bus_no, NULL))
1826 goto away;
1827 rc = 0;
1828away:
1829 if (rc < 0)
1830 return;
1831 if (chipset_responders.bus_destroy)
1832 (*chipset_responders.bus_destroy)(bus_no, rc);
1833}
1834
1835static void
1836chipset_device_create(u32 bus_no, u32 dev_no)
1837{
1838 struct visorchipset_device_info dev_info;
1839 struct visorchipset_bus_info bus_info;
1840 struct visorbus_devdata *devdata = NULL;
1841 int rc = -1;
1842
1843 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no,
1844 POSTCODE_SEVERITY_INFO);
1845
1846 if (entered_testing_mode)
1847 return;
1848 if (!visorchipset_get_device_info(bus_no, dev_no, &dev_info))
1849 goto away;
1850 if (!visorchipset_get_bus_info(bus_no, &bus_info))
1851 goto away;
1852 if (visorbus_devicetest)
1853 if (total_devices_created < MAXDEVICETEST) {
1854 test_channel_infos[total_devices_created] =
1855 dev_info.chan_info;
1856 test_bus_nos[total_devices_created] = bus_no;
1857 test_dev_nos[total_devices_created] = dev_no;
1858 }
1859 POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, dev_no, bus_no,
1860 POSTCODE_SEVERITY_INFO);
1861 rc = 0;
1862away:
1863 if (rc < 0) {
1864 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
1865 POSTCODE_SEVERITY_ERR);
1866 return;
1867 }
1868 devdata = (struct visorbus_devdata *)(bus_info.bus_driver_context);
1869 rc = create_visor_device(devdata, bus_no, dev_no,
1870 dev_info.chan_info, bus_info.partition_handle);
1871 POSTCODE_LINUX_4(DEVICE_CREATE_SUCCESS_PC, dev_no, bus_no,
1872 POSTCODE_SEVERITY_INFO);
1873 if (rc < 0)
1874 if (chipset_responders.device_create)
1875 (*chipset_responders.device_create)(bus_no, dev_no, rc);
1876}
1877
1878static void
1879chipset_device_destroy(u32 bus_no, u32 dev_no)
1880{
1881 struct visorchipset_device_info dev_info;
1882 struct visor_device *dev;
1883 int rc = -1;
1884
1885 if (entered_testing_mode)
1886 return;
1887 if (!visorchipset_get_device_info(bus_no, dev_no, &dev_info))
1888 goto away;
1889 dev = find_visor_device_by_channel(dev_info.chan_info.channel_addr);
1890 if (!dev)
1891 goto away;
1892 rc = 0;
1893away:
1894 if (rc < 0)
1895 return;
1896
1897 if (chipset_responders.device_destroy)
1898 (*chipset_responders.device_destroy) (bus_no, dev_no, rc);
1899 remove_visor_device(dev);
1900}
1901
1902/* This is the callback function specified for a function driver, to
1903 * be called when a pending "pause device" operation has been
1904 * completed.
1905 */
1906static void
1907pause_state_change_complete(struct visor_device *dev, int status)
1908{
1909 if (!dev->pausing)
1910 return;
1911
779d0752 1912 dev->pausing = false;
3703987c
EA
1913 if (!chipset_responders.device_pause) /* this can never happen! */
1914 return;
1915
1916 /* Notify the chipset driver that the pause is complete, which
1917 * will presumably want to send some sort of response to the
1918 * initiator. */
1919 (*chipset_responders.device_pause) (dev->chipset_bus_no,
1920 dev->chipset_dev_no, status);
1921}
1922
1923/* This is the callback function specified for a function driver, to
1924 * be called when a pending "resume device" operation has been
1925 * completed.
1926 */
1927static void
1928resume_state_change_complete(struct visor_device *dev, int status)
1929{
1930 if (!dev->resuming)
1931 return;
1932
779d0752 1933 dev->resuming = false;
3703987c
EA
1934 if (!chipset_responders.device_resume) /* this can never happen! */
1935 return;
1936
1937 /* Notify the chipset driver that the resume is complete,
1938 * which will presumably want to send some sort of response to
1939 * the initiator. */
1940 (*chipset_responders.device_resume) (dev->chipset_bus_no,
1941 dev->chipset_dev_no, status);
1942}
1943
1944/* Tell the subordinate function driver for a specific device to pause
1945 * or resume that device. Result is returned asynchronously via a
1946 * callback function.
1947 */
1948static void
1949initiate_chipset_device_pause_resume(u32 bus_no, u32 dev_no, bool is_pause)
1950{
1951 struct visorchipset_device_info dev_info;
1952 struct visor_device *dev = NULL;
1953 int rc = -1, x;
1954 struct visor_driver *drv = NULL;
1955 void (*notify_func)(u32 bus_no, u32 dev_no, int response) = NULL;
1956
1957 if (is_pause)
1958 notify_func = chipset_responders.device_pause;
1959 else
1960 notify_func = chipset_responders.device_resume;
1961 if (!notify_func)
1962 goto away;
1963
1964 if (!visorchipset_get_device_info(bus_no, dev_no, &dev_info))
1965 goto away;
1966
1967 dev = find_visor_device_by_channel(dev_info.chan_info.channel_addr);
1968 if (!dev)
1969 goto away;
1970
1971 drv = to_visor_driver(dev->device.driver);
1972 if (!drv)
1973 goto away;
1974
1975 if (dev->pausing || dev->resuming)
1976 goto away;
1977
1978 /* Note that even though both drv->pause() and drv->resume
1979 * specify a callback function, it is NOT necessary for us to
1980 * increment our local module usage count. Reason is, there
1981 * is already a linkage dependency between child function
1982 * drivers and visorbus, so it is already IMPOSSIBLE to unload
1983 * visorbus while child function drivers are still running.
1984 */
1985 if (is_pause) {
1986 if (!drv->pause)
1987 goto away;
1988
779d0752 1989 dev->pausing = true;
3703987c
EA
1990 x = drv->pause(dev, pause_state_change_complete);
1991 } else {
1992 /* This should be done at BUS resume time, but an
1993 * existing problem prevents us from ever getting a bus
1994 * resume... This hack would fail to work should we
1995 * ever have a bus that contains NO devices, since we
1996 * would never even get here in that case. */
1997 fix_vbus_dev_info(dev);
1998 if (!drv->resume)
1999 goto away;
2000
779d0752 2001 dev->resuming = true;
3703987c
EA
2002 x = drv->resume(dev, resume_state_change_complete);
2003 }
2004 if (x < 0) {
2005 if (is_pause)
779d0752 2006 dev->pausing = false;
3703987c 2007 else
779d0752 2008 dev->resuming = false;
3703987c
EA
2009 goto away;
2010 }
2011 rc = 0;
2012away:
2013 if (rc < 0) {
2014 if (notify_func)
2015 (*notify_func)(bus_no, dev_no, rc);
2016 }
2017}
2018
2019static void
2020chipset_device_pause(u32 bus_no, u32 dev_no)
2021{
779d0752 2022 initiate_chipset_device_pause_resume(bus_no, dev_no, true);
3703987c
EA
2023}
2024
2025static void
2026chipset_device_resume(u32 bus_no, u32 dev_no)
2027{
779d0752 2028 initiate_chipset_device_pause_resume(bus_no, dev_no, false);
3703987c
EA
2029}
2030
2031struct channel_size_info {
2032 uuid_le guid;
2033 unsigned long min_size;
2034 unsigned long max_size;
2035};
2036
c79b28f7 2037int __init
3703987c
EA
2038visorbus_init(void)
2039{
2040 int rc = 0;
2041
2042 POSTCODE_LINUX_3(DRIVER_ENTRY_PC, rc, POSTCODE_SEVERITY_INFO);
2043 bus_device_info_init(&clientbus_driverinfo,
46168810 2044 "clientbus", "visorbus",
3703987c
EA
2045 VERSION, NULL);
2046
2047 /* process module options */
2048
2049 if (visorbus_devicetest > MAXDEVICETEST)
2050 visorbus_devicetest = MAXDEVICETEST;
2051
2052 rc = create_bus_type();
2053 if (rc < 0) {
2054 POSTCODE_LINUX_2(BUS_CREATE_ENTRY_PC, DIAG_SEVERITY_ERR);
2055 goto away;
2056 }
2057
2058 periodic_dev_workqueue = create_singlethread_workqueue("visorbus_dev");
2059 if (!periodic_dev_workqueue) {
2060 POSTCODE_LINUX_2(CREATE_WORKQUEUE_PC, DIAG_SEVERITY_ERR);
2061 rc = -ENOMEM;
2062 goto away;
2063 }
2064
2065 /* This enables us to receive notifications when devices appear for
2066 * which this service partition is to be a server for.
2067 */
4da3336c
DK
2068 visorchipset_register_busdev(&chipset_notifiers,
2069 &chipset_responders,
2070 &chipset_driverinfo);
3703987c
EA
2071
2072 rc = 0;
2073
2074away:
2075 if (rc)
2076 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, rc,
2077 POSTCODE_SEVERITY_ERR);
2078 return rc;
2079}
2080
c79b28f7 2081void
3703987c
EA
2082visorbus_exit(void)
2083{
2084 struct list_head *listentry, *listtmp;
2085
4da3336c 2086 visorchipset_register_busdev(NULL, NULL, NULL);
3703987c
EA
2087 remove_all_visor_devices();
2088
2089 flush_workqueue(periodic_dev_workqueue); /* better not be any work! */
2090 destroy_workqueue(periodic_dev_workqueue);
2091 periodic_dev_workqueue = NULL;
2092
2093 if (periodic_test_workqueue) {
2094 cancel_delayed_work(&periodic_work);
2095 flush_workqueue(periodic_test_workqueue);
2096 destroy_workqueue(periodic_test_workqueue);
2097 periodic_test_workqueue = NULL;
2098 }
2099
2100 list_for_each_safe(listentry, listtmp, &list_all_bus_instances) {
2101 struct visorbus_devdata *devdata = list_entry(listentry,
2102 struct
2103 visorbus_devdata,
2104 list_all);
2105 remove_bus_instance(devdata);
2106 }
2107 remove_bus_type();
2108}
2109
2110module_param_named(debug, visorbus_debug, int, S_IRUGO);
2111MODULE_PARM_DESC(visorbus_debug, "1 to debug");
2112int visorbus_debug = 0;
2113
2114module_param_named(forcematch, visorbus_forcematch, int, S_IRUGO);
2115MODULE_PARM_DESC(visorbus_forcematch,
2116 "1 to force a successful dev <--> drv match");
2117int visorbus_forcematch = 0;
2118
2119module_param_named(forcenomatch, visorbus_forcenomatch, int, S_IRUGO);
2120MODULE_PARM_DESC(visorbus_forcenomatch,
2121 "1 to force an UNsuccessful dev <--> drv match");
2122int visorbus_forcenomatch = 0;
2123
2124module_param_named(devicetest, visorbus_devicetest, int, S_IRUGO);
2125MODULE_PARM_DESC(visorbus_devicetest,
2126 "non-0 to just test device creation and destruction");
2127int visorbus_devicetest = 0;
2128
2129module_param_named(debugref, visorbus_debugref, int, S_IRUGO);
2130MODULE_PARM_DESC(visorbus_debugref, "1 to debug reference counting");
2131int visorbus_debugref = 0;
2132
3703987c
EA
2133MODULE_AUTHOR("Unisys");
2134MODULE_LICENSE("GPL");
2135MODULE_DESCRIPTION("Supervisor bus driver for service partition: ver " VERSION);
2136MODULE_VERSION(VERSION);
This page took 0.110319 seconds and 5 git commands to generate.