3 * Copyright � 2010 - 2013 UNISYS CORPORATION
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.
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
18 #include <linux/uuid.h>
21 #include "visorbus_private.h"
23 #include "periodic_work.h"
24 #include "vbuschannel.h"
25 #include "guestlinuxdebug.h"
26 #include "vmcallinterface.h"
28 #define MYDRVNAME "visorbus"
30 /* module parameters */
32 int visorbus_forcematch;
33 int visorbus_forcenomatch;
34 #define MAXDEVICETEST 4
35 int visorbus_devicetest;
36 int visorbus_debugref;
37 #define SERIALLOOPBACKCHANADDR (100 * 1024 * 1024)
39 /** This is the private data that we store for each bus device instance.
41 struct visorbus_devdata {
42 int devno; /* this is the chipset busNo */
43 struct list_head list_all;
46 struct visorchannel *chan; /* channel area for bus itself */
48 struct spar_vbus_headerinfo vbus_hdr_info;
51 /* These forward declarations are required since our drivers are out-of-tree.
52 * The structures referenced are kernel-private and are not in the headers, but
53 * it is impossible to make a functioning bus driver without them.
55 struct subsys_private {
57 struct kset *devices_kset;
59 struct kset *drivers_kset;
60 struct klist klist_devices;
61 struct klist klist_drivers;
62 struct blocking_notifier_head bus_notifier;
63 unsigned int drivers_autoprobe:1;
66 struct list_head class_interfaces;
67 struct kset glue_dirs;
68 struct mutex class_mutex; /* ignore */
72 struct bus_type_private {
74 struct kset *drivers_kset;
75 struct kset *devices_kset;
76 struct klist klist_devices;
77 struct klist klist_drivers;
78 struct blocking_notifier_head bus_notifier;
79 unsigned int drivers_autoprobe:1;
83 #define CURRENT_FILE_PC VISOR_BUS_PC_visorbus_main_c
84 #define POLLJIFFIES_TESTWORK 100
85 #define POLLJIFFIES_NORMALCHANNEL 10
87 static int visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env);
88 static int visorbus_match(struct device *xdev, struct device_driver *xdrv);
89 static void fix_vbus_dev_info(struct visor_device *visordev);
91 /* BUS type attributes
93 * define & implement display of bus attributes under
98 static ssize_t version_show(struct bus_type *bus, char *buf)
100 return snprintf(buf, PAGE_SIZE, "%s\n", VERSION);
103 static BUS_ATTR_RO(version);
105 static struct attribute *visorbus_bus_attrs[] = {
106 &bus_attr_version.attr,
110 static const struct attribute_group visorbus_bus_group = {
111 .attrs = visorbus_bus_attrs,
114 const struct attribute_group *visorbus_bus_groups[] = {
120 /** This describes the TYPE of bus.
121 * (Don't confuse this with an INSTANCE of the bus.)
123 static struct bus_type visorbus_type = {
125 .match = visorbus_match,
126 .uevent = visorbus_uevent,
127 .bus_groups = visorbus_bus_groups,
130 static struct delayed_work periodic_work;
132 /* YES, we need 2 workqueues.
133 * The reason is, workitems on the test queue may need to cancel
134 * workitems on the other queue. You will be in for trouble if you try to
135 * do this with workitems queued on the same workqueue.
137 static struct workqueue_struct *periodic_test_workqueue;
138 static struct workqueue_struct *periodic_dev_workqueue;
139 static long long bus_count; /** number of bus instances */
140 static long long total_devices_created;
141 /** ever-increasing */
143 static void chipset_bus_create(u32 bus_no);
144 static void chipset_bus_destroy(u32 bus_no);
145 static void chipset_device_create(u32 bus_no, u32 dev_no);
146 static void chipset_device_destroy(u32 bus_no, u32 dev_no);
147 static void chipset_device_pause(u32 bus_no, u32 dev_no);
148 static void chipset_device_resume(u32 bus_no, u32 dev_no);
150 /** These functions are implemented herein, and are called by the chipset
151 * driver to notify us about specific events.
153 static struct visorchipset_busdev_notifiers chipset_notifiers = {
154 .bus_create = chipset_bus_create,
155 .bus_destroy = chipset_bus_destroy,
156 .device_create = chipset_device_create,
157 .device_destroy = chipset_device_destroy,
158 .device_pause = chipset_device_pause,
159 .device_resume = chipset_device_resume,
162 /** These functions are implemented in the chipset driver, and we call them
163 * herein when we want to acknowledge a specific event.
165 static struct visorchipset_busdev_responders chipset_responders;
167 /* filled in with info about parent chipset driver when we register with it */
168 static struct ultra_vbus_deviceinfo chipset_driverinfo;
169 /* filled in with info about this driver, wrt it servicing client busses */
170 static struct ultra_vbus_deviceinfo clientbus_driverinfo;
172 /** list of visorbus_devdata structs, linked via .list_all */
173 static LIST_HEAD(list_all_bus_instances);
174 /** list of visor_device structs, linked via .list_all */
175 static LIST_HEAD(list_all_device_instances);
178 visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env)
180 if (add_uevent_var(env, "VERSION=%s", VERSION))
185 /* This is called automatically upon adding a visor_device (device_add), or
186 * adding a visor_driver (visorbus_register_visor_driver), and returns 1 iff the
187 * provided driver can control the specified device.
190 visorbus_match(struct device *xdev, struct device_driver *xdrv)
192 uuid_le channel_type;
195 struct visor_device *dev;
196 struct visor_driver *drv;
198 dev = to_visor_device(xdev);
199 drv = to_visor_driver(xdrv);
200 channel_type = visorchannel_get_uuid(dev->visorchannel);
201 if (visorbus_forcematch) {
205 if (visorbus_forcenomatch)
208 if (!drv->channel_types)
211 (uuid_le_cmp(drv->channel_types[i].guid, NULL_UUID_LE) != 0) ||
212 (drv->channel_types[i].name);
214 if (uuid_le_cmp(drv->channel_types[i].guid,
215 channel_type) == 0) {
223 /** This is called when device_unregister() is called for the bus device
224 * instance, after all other tasks involved with destroying the device
228 visorbus_release_busdevice(struct device *xdev)
230 struct visorbus_devdata *devdata = dev_get_drvdata(xdev);
232 dev_set_drvdata(xdev, NULL);
237 /** This is called when device_unregister() is called for each child
241 visorbus_release_device(struct device *xdev)
243 struct visor_device *dev = to_visor_device(xdev);
245 if (dev->periodic_work) {
246 visor_periodic_work_destroy(dev->periodic_work);
247 dev->periodic_work = NULL;
249 if (dev->visorchannel) {
250 visorchannel_destroy(dev->visorchannel);
251 dev->visorchannel = NULL;
256 /* Implement publishing of device node attributes under:
258 * /sys/bus/visorbus<x>/dev<y>/devmajorminor
262 #define to_devmajorminor_attr(_attr) \
263 container_of(_attr, struct devmajorminor_attribute, attr)
264 #define to_visor_device_from_kobjdevmajorminor(obj) \
265 container_of(obj, struct visor_device, kobjdevmajorminor)
267 struct devmajorminor_attribute {
268 struct attribute attr;
270 ssize_t (*show)(struct visor_device *, int slot, char *buf);
271 ssize_t (*store)(struct visor_device *, int slot, const char *buf,
275 static ssize_t DEVMAJORMINOR_ATTR(struct visor_device *dev, int slot, char *buf)
277 int maxdevnodes = ARRAY_SIZE(dev->devnodes) / sizeof(dev->devnodes[0]);
279 if (slot < 0 || slot >= maxdevnodes)
281 return snprintf(buf, PAGE_SIZE, "%d:%d\n",
282 dev->devnodes[slot].major, dev->devnodes[slot].minor);
286 devmajorminor_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
288 struct devmajorminor_attribute *devmajorminor_attr =
289 to_devmajorminor_attr(attr);
290 struct visor_device *dev = to_visor_device_from_kobjdevmajorminor(kobj);
293 if (devmajorminor_attr->show)
294 ret = devmajorminor_attr->show(dev,
295 devmajorminor_attr->slot, buf);
300 devmajorminor_attr_store(struct kobject *kobj,
301 struct attribute *attr, const char *buf, size_t count)
303 struct devmajorminor_attribute *devmajorminor_attr =
304 to_devmajorminor_attr(attr);
305 struct visor_device *dev = to_visor_device_from_kobjdevmajorminor(kobj);
308 if (devmajorminor_attr->store)
309 ret = devmajorminor_attr->store(dev,
310 devmajorminor_attr->slot,
315 static int register_devmajorminor_attributes(struct visor_device *dev);
318 devmajorminor_create_file(struct visor_device *dev, const char *name,
319 int major, int minor)
321 int maxdevnodes = ARRAY_SIZE(dev->devnodes) / sizeof(dev->devnodes[0]);
322 struct devmajorminor_attribute *myattr = NULL;
323 int x = -1, rc = 0, slot = -1;
325 register_devmajorminor_attributes(dev);
326 for (slot = 0; slot < maxdevnodes; slot++)
327 if (!dev->devnodes[slot].attr)
329 if (slot == maxdevnodes) {
333 myattr = kmalloc(sizeof(*myattr), GFP_KERNEL);
338 memset(myattr, 0, sizeof(struct devmajorminor_attribute));
339 myattr->show = DEVMAJORMINOR_ATTR;
340 myattr->store = NULL;
342 myattr->attr.name = name;
343 myattr->attr.mode = S_IRUGO;
344 dev->devnodes[slot].attr = myattr;
345 dev->devnodes[slot].major = major;
346 dev->devnodes[slot].minor = minor;
347 x = sysfs_create_file(&dev->kobjdevmajorminor, &myattr->attr);
352 kobject_uevent(&dev->device.kobj, KOBJ_ONLINE);
357 dev->devnodes[slot].attr = NULL;
363 devmajorminor_remove_file(struct visor_device *dev, int slot)
365 int maxdevnodes = ARRAY_SIZE(dev->devnodes) / sizeof(dev->devnodes[0]);
366 struct devmajorminor_attribute *myattr = NULL;
368 if (slot < 0 || slot >= maxdevnodes)
370 myattr = (struct devmajorminor_attribute *)(dev->devnodes[slot].attr);
373 sysfs_remove_file(&dev->kobjdevmajorminor, &myattr->attr);
374 kobject_uevent(&dev->device.kobj, KOBJ_OFFLINE);
375 dev->devnodes[slot].attr = NULL;
380 devmajorminor_remove_all_files(struct visor_device *dev)
383 int maxdevnodes = ARRAY_SIZE(dev->devnodes) / sizeof(dev->devnodes[0]);
385 for (i = 0; i < maxdevnodes; i++)
386 devmajorminor_remove_file(dev, i);
389 static const struct sysfs_ops devmajorminor_sysfs_ops = {
390 .show = devmajorminor_attr_show,
391 .store = devmajorminor_attr_store,
394 static struct kobj_type devmajorminor_kobj_type = {
395 .sysfs_ops = &devmajorminor_sysfs_ops
399 register_devmajorminor_attributes(struct visor_device *dev)
403 if (dev->kobjdevmajorminor.parent)
404 goto away; /* already registered */
405 x = kobject_init_and_add(&dev->kobjdevmajorminor,
406 &devmajorminor_kobj_type, &dev->device.kobj,
413 kobject_uevent(&dev->kobjdevmajorminor, KOBJ_ADD);
420 unregister_devmajorminor_attributes(struct visor_device *dev)
422 if (!dev->kobjdevmajorminor.parent)
423 return; /* already unregistered */
424 devmajorminor_remove_all_files(dev);
426 kobject_del(&dev->kobjdevmajorminor);
427 kobject_put(&dev->kobjdevmajorminor);
428 dev->kobjdevmajorminor.parent = NULL;
431 /* Implement publishing of channel attributes under:
433 * /sys/bus/visorbus<x>/dev<y>/channel
437 #define to_channel_attr(_attr) \
438 container_of(_attr, struct channel_attribute, attr)
439 #define to_visor_device_from_kobjchannel(obj) \
440 container_of(obj, struct visor_device, kobjchannel)
442 struct channel_attribute {
443 struct attribute attr;
444 ssize_t (*show)(struct visor_device*, char *buf);
445 ssize_t (*store)(struct visor_device*, const char *buf, size_t count);
448 /* begin implementation of specific channel attributes to appear under
449 * /sys/bus/visorbus<x>/dev<y>/channel
451 static ssize_t devicechannel_attr_physaddr(struct visor_device *dev, char *buf)
453 if (!dev->visorchannel)
455 return snprintf(buf, PAGE_SIZE, "0x%Lx\n",
456 visorchannel_get_physaddr(dev->visorchannel));
459 static ssize_t devicechannel_attr_nbytes(struct visor_device *dev, char *buf)
461 if (!dev->visorchannel)
463 return snprintf(buf, PAGE_SIZE, "0x%lx\n",
464 visorchannel_get_nbytes(dev->visorchannel));
467 static ssize_t devicechannel_attr_clientpartition(struct visor_device *dev,
469 if (!dev->visorchannel)
471 return snprintf(buf, PAGE_SIZE, "0x%Lx\n",
472 visorchannel_get_clientpartition(dev->visorchannel));
475 static ssize_t devicechannel_attr_typeguid(struct visor_device *dev, char *buf)
479 if (!dev->visorchannel)
481 return snprintf(buf, PAGE_SIZE, "%s\n",
482 visorchannel_id(dev->visorchannel, s));
485 static ssize_t devicechannel_attr_zoneguid(struct visor_device *dev, char *buf)
489 if (!dev->visorchannel)
491 return snprintf(buf, PAGE_SIZE, "%s\n",
492 visorchannel_zoneid(dev->visorchannel, s));
495 static ssize_t devicechannel_attr_typename(struct visor_device *dev, char *buf)
498 struct bus_type *xbus = dev->device.bus;
499 struct device_driver *xdrv = dev->device.driver;
500 struct visor_driver *drv = NULL;
502 if (!dev->visorchannel || !xbus || !xdrv)
504 i = xbus->match(&dev->device, xdrv);
507 drv = to_visor_driver(xdrv);
508 return snprintf(buf, PAGE_SIZE, "%s\n", drv->channel_types[i - 1].name);
511 static ssize_t devicechannel_attr_dump(struct visor_device *dev, char *buf)
514 /* TODO: replace this with debugfs code
515 struct seq_file *m = NULL;
516 if (dev->visorchannel == NULL)
518 m = visor_seq_file_new_buffer(buf, PAGE_SIZE - 1);
521 visorchannel_debug(dev->visorchannel, 1, m, 0);
523 visor_seq_file_done_buffer(m);
529 static struct channel_attribute all_channel_attrs[] = {
530 __ATTR(physaddr, S_IRUGO,
531 devicechannel_attr_physaddr, NULL),
532 __ATTR(nbytes, S_IRUGO,
533 devicechannel_attr_nbytes, NULL),
534 __ATTR(clientpartition, S_IRUGO,
535 devicechannel_attr_clientpartition, NULL),
536 __ATTR(typeguid, S_IRUGO,
537 devicechannel_attr_typeguid, NULL),
538 __ATTR(zoneguid, S_IRUGO,
539 devicechannel_attr_zoneguid, NULL),
540 __ATTR(typename, S_IRUGO,
541 devicechannel_attr_typename, NULL),
542 __ATTR(dump, S_IRUGO,
543 devicechannel_attr_dump, NULL),
546 /* end implementation of specific channel attributes */
548 static ssize_t channel_attr_show(struct kobject *kobj, struct attribute *attr,
551 struct channel_attribute *channel_attr = to_channel_attr(attr);
552 struct visor_device *dev = to_visor_device_from_kobjchannel(kobj);
555 if (channel_attr->show)
556 ret = channel_attr->show(dev, buf);
560 static ssize_t channel_attr_store(struct kobject *kobj, struct attribute *attr,
561 const char *buf, size_t count)
563 struct channel_attribute *channel_attr = to_channel_attr(attr);
564 struct visor_device *dev = to_visor_device_from_kobjchannel(kobj);
567 if (channel_attr->store)
568 ret = channel_attr->store(dev, buf, count);
572 static int channel_create_file(struct visor_device *dev,
573 struct channel_attribute *attr)
575 return sysfs_create_file(&dev->kobjchannel, &attr->attr);
578 static void channel_remove_file(struct visor_device *dev,
579 struct channel_attribute *attr)
581 sysfs_remove_file(&dev->kobjchannel, &attr->attr);
584 static const struct sysfs_ops channel_sysfs_ops = {
585 .show = channel_attr_show,
586 .store = channel_attr_store,
589 static struct kobj_type channel_kobj_type = {
590 .sysfs_ops = &channel_sysfs_ops
593 int register_channel_attributes(struct visor_device *dev)
595 int rc = 0, i = 0, x = 0;
597 if (dev->kobjchannel.parent)
598 goto away; /* already registered */
599 x = kobject_init_and_add(&dev->kobjchannel, &channel_kobj_type,
600 &dev->device.kobj, "channel");
606 kobject_uevent(&dev->kobjchannel, KOBJ_ADD);
609 i < sizeof(all_channel_attrs) / sizeof(struct channel_attribute);
611 x = channel_create_file(dev, &all_channel_attrs[i]);
614 channel_remove_file(dev, &all_channel_attrs[i]);
615 kobject_del(&dev->kobjchannel);
616 kobject_put(&dev->kobjchannel);
624 void unregister_channel_attributes(struct visor_device *dev)
628 if (!dev->kobjchannel.parent)
629 return; /* already unregistered */
631 i < sizeof(all_channel_attrs) / sizeof(struct channel_attribute);
633 channel_remove_file(dev, &all_channel_attrs[i]);
635 kobject_del(&dev->kobjchannel);
636 kobject_put(&dev->kobjchannel);
637 dev->kobjchannel.parent = NULL;
639 #define to_visorbus_devdata(obj) \
640 container_of(obj, struct visorbus_devdata, dev)
642 /* BUS instance attributes
644 * define & implement display of bus attributes under
645 * /sys/bus/visorbus/busses/visorbus<n>.
647 * This is a bit hoaky because the kernel does not yet have the infrastructure
648 * to separate bus INSTANCE attributes from bus TYPE attributes...
649 * so we roll our own. See businst.c / businst.h.
653 static ssize_t partition_handle_show(struct device *dev,
654 struct device_attribute *attr,
656 struct visorbus_devdata *businst = to_visorbus_devdata(dev);
657 struct visorchipset_bus_info bus_info;
660 if (businst && visorchipset_get_bus_info(businst->devno, &bus_info))
661 len = snprintf(buf, PAGE_SIZE,
663 (unsigned long long)bus_info.partition_handle);
667 static ssize_t partition_guid_show(struct device *dev,
668 struct device_attribute *attr,
670 struct visorbus_devdata *businst = to_visorbus_devdata(dev);
671 struct visorchipset_bus_info bus_info;
674 if (businst && visorchipset_get_bus_info(businst->devno, &bus_info))
675 len = snprintf(buf, PAGE_SIZE, "{%pUb}\n",
676 &bus_info.partition_uuid);
680 static ssize_t partition_name_show(struct device *dev,
681 struct device_attribute *attr,
683 struct visorbus_devdata *businst = to_visorbus_devdata(dev);
684 struct visorchipset_bus_info bus_info;
688 visorchipset_get_bus_info(businst->devno, &bus_info) &&
690 len = snprintf(buf, PAGE_SIZE, "%s\n", bus_info.name);
694 static ssize_t channel_addr_show(struct device *dev,
695 struct device_attribute *attr,
697 struct visorbus_devdata *businst = to_visorbus_devdata(dev);
698 struct visorchipset_bus_info bus_info;
701 if (businst && visorchipset_get_bus_info(businst->devno, &bus_info))
702 len = snprintf(buf, PAGE_SIZE, "0x%Lx\n", (unsigned long long)
703 bus_info.chan_info.channel_addr);
707 static ssize_t channel_bytes_show(struct device *dev,
708 struct device_attribute *attr,
710 struct visorbus_devdata *businst = to_visorbus_devdata(dev);
711 struct visorchipset_bus_info bus_info;
714 if (businst && visorchipset_get_bus_info(businst->devno, &bus_info))
715 len = snprintf(buf, PAGE_SIZE, "0x%Lx\n", (unsigned long long)
716 bus_info.chan_info.n_channel_bytes);
720 static ssize_t channel_id_show(struct device *dev,
721 struct device_attribute *attr,
723 struct visorbus_devdata *businst = to_visorbus_devdata(dev);
726 if (businst && businst->chan) {
727 visorchannel_id(businst->chan, buf);
734 static ssize_t client_bus_info_show(struct device *dev,
735 struct device_attribute *attr,
737 struct visorbus_devdata *businst = to_visorbus_devdata(dev);
738 struct visorchipset_bus_info bus_info;
739 int i, x, remain = PAGE_SIZE;
743 struct ultra_vbus_deviceinfo dev_info;
746 if (businst && businst->chan) {
747 if (visorchipset_get_bus_info(businst->devno, &bus_info) &&
749 partition_name = bus_info.name;
750 x = snprintf(p, remain,
751 "Client device / client driver info for %s partition (vbus #%d):\n",
752 partition_name, businst->devno);
755 x = visorchannel_read(businst->chan,
757 spar_vbus_channel_protocol,
759 &dev_info, sizeof(dev_info));
761 x = vbuschannel_devinfo_to_string(&dev_info, p,
766 x = visorchannel_read(businst->chan,
768 spar_vbus_channel_protocol,
770 &dev_info, sizeof(dev_info));
772 x = vbuschannel_devinfo_to_string(&dev_info, p,
777 off = offsetof(struct spar_vbus_channel_protocol, dev_info);
779 while (off + sizeof(dev_info) <=
780 visorchannel_get_nbytes(businst->chan)) {
781 x = visorchannel_read(businst->chan,
782 off, &dev_info, sizeof(dev_info));
784 x = vbuschannel_devinfo_to_string
785 (&dev_info, p, remain, i);
789 off += sizeof(dev_info);
793 return PAGE_SIZE - remain;
796 static DEVICE_ATTR_RO(partition_handle);
797 static DEVICE_ATTR_RO(partition_guid);
798 static DEVICE_ATTR_RO(partition_name);
799 static DEVICE_ATTR_RO(channel_addr);
800 static DEVICE_ATTR_RO(channel_bytes);
801 static DEVICE_ATTR_RO(channel_id);
802 static DEVICE_ATTR_RO(client_bus_info);
804 static struct attribute *dev_attrs[] = {
805 &dev_attr_partition_handle.attr,
806 &dev_attr_partition_guid.attr,
807 &dev_attr_partition_name.attr,
808 &dev_attr_channel_addr.attr,
809 &dev_attr_channel_bytes.attr,
810 &dev_attr_channel_id.attr,
811 &dev_attr_client_bus_info.attr,
815 static struct attribute_group dev_attr_grp = {
819 static const struct attribute_group *visorbus_groups[] = {
826 * define & implement display of driver attributes under
827 * /sys/bus/visorbus/drivers/<drivername>.
832 DRIVER_ATTR_version(struct device_driver *xdrv, char *buf)
834 struct visor_driver *drv = to_visor_driver(xdrv);
836 return snprintf(buf, PAGE_SIZE, "%s\n", drv->version);
840 register_driver_attributes(struct visor_driver *drv)
843 struct driver_attribute version =
844 __ATTR(version, S_IRUGO, DRIVER_ATTR_version, NULL);
845 drv->version_attr = version;
846 rc = driver_create_file(&drv->driver, &drv->version_attr);
851 unregister_driver_attributes(struct visor_driver *drv)
853 driver_remove_file(&drv->driver, &drv->version_attr);
858 * define & implement display of device attributes under
859 * /sys/bus/visorbus/devices/<devicename>.
863 #define DEVATTR(nam, func) { \
864 .attr = { .name = __stringify(nam), \
866 .owner = THIS_MODULE }, \
870 static struct device_attribute visor_device_attrs[] = {
871 /* DEVATTR(channel_nbytes, DEVICE_ATTR_channel_nbytes), */
876 dev_periodic_work(void *xdev)
878 struct visor_device *dev = (struct visor_device *)xdev;
879 struct visor_driver *drv = to_visor_driver(dev->device.driver);
881 down(&dev->visordriver_callback_lock);
882 if (drv->channel_interrupt)
883 drv->channel_interrupt(dev);
884 up(&dev->visordriver_callback_lock);
885 if (!visor_periodic_work_nextperiod(dev->periodic_work))
886 put_device(&dev->device);
890 dev_start_periodic_work(struct visor_device *dev)
892 if (dev->being_removed)
894 /* now up by at least 2 */
895 get_device(&dev->device);
896 if (!visor_periodic_work_start(dev->periodic_work))
897 put_device(&dev->device);
901 dev_stop_periodic_work(struct visor_device *dev)
903 if (visor_periodic_work_stop(dev->periodic_work))
904 put_device(&dev->device);
907 /** This is called automatically upon adding a visor_device (device_add), or
908 * adding a visor_driver (visorbus_register_visor_driver), but only after
909 * visorbus_match has returned 1 to indicate a successful match between
913 visordriver_probe_device(struct device *xdev)
916 struct visor_driver *drv;
917 struct visor_device *dev;
919 drv = to_visor_driver(xdev->driver);
920 dev = to_visor_device(xdev);
921 down(&dev->visordriver_callback_lock);
922 dev->being_removed = false;
924 * ensure that the dev->being_removed flag is cleared before
928 get_device(&dev->device);
930 up(&dev->visordriver_callback_lock);
934 rc = drv->probe(dev);
938 fix_vbus_dev_info(dev);
939 up(&dev->visordriver_callback_lock);
943 put_device(&dev->device);
944 /* We could get here more than once if the child driver module is
945 * unloaded and re-loaded while devices are present. That's why we
946 * need a flag to be sure that we only respond to the device_create
947 * once. We cannot respond to the device_create prior to here,
948 * because until we call drv->probe() above, the channel has not been
951 if (!dev->responded_to_device_create) {
952 dev->responded_to_device_create = true;
953 if (chipset_responders.device_create)
954 (*chipset_responders.device_create)(dev->chipset_bus_no,
961 /** This is called when device_unregister() is called for each child device
962 * instance, to notify the appropriate visorbus_driver that the device is
963 * going away, and to decrease the reference count of the device.
966 visordriver_remove_device(struct device *xdev)
969 struct visor_device *dev;
970 struct visor_driver *drv;
972 dev = to_visor_device(xdev);
973 drv = to_visor_driver(xdev->driver);
974 down(&dev->visordriver_callback_lock);
975 dev->being_removed = true;
977 * ensure that the dev->being_removed flag is set before we start the
985 up(&dev->visordriver_callback_lock);
986 dev_stop_periodic_work(dev);
987 devmajorminor_remove_all_files(dev);
989 put_device(&dev->device);
994 /** A particular type of visor driver calls this function to register
995 * the driver. The caller MUST fill in the following fields within the
997 * name, version, owner, channel_types, probe, remove
999 * Here's how the whole Linux bus / driver / device model works.
1001 * At system start-up, the visorbus kernel module is loaded, which registers
1002 * visorbus_type as a bus type, using bus_register().
1004 * All kernel modules that support particular device types on a
1005 * visorbus bus are loaded. Each of these kernel modules calls
1006 * visorbus_register_visor_driver() in their init functions, passing a
1007 * visor_driver struct. visorbus_register_visor_driver() in turn calls
1008 * register_driver(&visor_driver.driver). This .driver member is
1009 * initialized with generic methods (like probe), whose sole responsibility
1010 * is to act as a broker for the real methods, which are within the
1011 * visor_driver struct. (This is the way the subclass behavior is
1012 * implemented, since visor_driver is essentially a subclass of the
1013 * generic driver.) Whenever a driver_register() happens, core bus code in
1014 * the kernel does (see device_attach() in drivers/base/dd.c):
1016 * for each dev associated with the bus (the bus that driver is on) that
1017 * does not yet have a driver
1018 * if bus.match(dev,newdriver) == yes_matched ** .match specified
1019 * ** during bus_register().
1020 * newdriver.probe(dev) ** for visor drivers, this will call
1021 * ** the generic driver.probe implemented in visorbus.c,
1022 * ** which in turn calls the probe specified within the
1023 * ** struct visor_driver (which was specified by the
1024 * ** actual device driver as part of
1025 * ** visorbus_register_visor_driver()).
1027 * The above dance also happens when a new device appears.
1028 * So the question is, how are devices created within the system?
1029 * Basically, just call device_add(dev). See pci_bus_add_devices().
1030 * pci_scan_device() shows an example of how to build a device struct. It
1031 * returns the newly-created struct to pci_scan_single_device(), who adds it
1032 * to the list of devices at PCIBUS.devices. That list of devices is what
1033 * is traversed by pci_bus_add_devices().
1036 int visorbus_register_visor_driver(struct visor_driver *drv)
1040 drv->driver.name = drv->name;
1041 drv->driver.bus = &visorbus_type;
1042 drv->driver.probe = visordriver_probe_device;
1043 drv->driver.remove = visordriver_remove_device;
1044 drv->driver.owner = drv->owner;
1046 /* driver_register does this:
1047 * bus_add_driver(drv)
1048 * ->if (drv.bus) ** (bus_type) **
1049 * driver_attach(drv)
1050 * for each dev with bus type of drv.bus
1051 * if (!dev.drv) ** no driver assigned yet **
1052 * if (bus.match(dev,drv)) [visorbus_match]
1054 * if (!drv.probe(dev)) [visordriver_probe_device]
1058 rc = driver_register(&drv->driver);
1061 rc = register_driver_attributes(drv);
1064 EXPORT_SYMBOL_GPL(visorbus_register_visor_driver);
1066 /** A particular type of visor driver calls this function to unregister
1067 * the driver, i.e., within its module_exit function.
1070 visorbus_unregister_visor_driver(struct visor_driver *drv)
1072 unregister_driver_attributes(drv);
1073 driver_unregister(&drv->driver);
1075 EXPORT_SYMBOL_GPL(visorbus_unregister_visor_driver);
1078 visorbus_read_channel(struct visor_device *dev, unsigned long offset,
1079 void *dest, unsigned long nbytes)
1081 return visorchannel_read(dev->visorchannel, offset, dest, nbytes);
1083 EXPORT_SYMBOL_GPL(visorbus_read_channel);
1086 visorbus_write_channel(struct visor_device *dev, unsigned long offset,
1087 void *src, unsigned long nbytes)
1089 return visorchannel_write(dev->visorchannel, offset, src, nbytes);
1091 EXPORT_SYMBOL_GPL(visorbus_write_channel);
1094 visorbus_clear_channel(struct visor_device *dev, unsigned long offset, u8 ch,
1095 unsigned long nbytes)
1097 return visorchannel_clear(dev->visorchannel, offset, ch, nbytes);
1099 EXPORT_SYMBOL_GPL(visorbus_clear_channel);
1102 visorbus_registerdevnode(struct visor_device *dev,
1103 const char *name, int major, int minor)
1105 return devmajorminor_create_file(dev, name, major, minor);
1107 EXPORT_SYMBOL_GPL(visorbus_registerdevnode);
1109 /** We don't really have a real interrupt, so for now we just call the
1110 * interrupt function periodically...
1113 visorbus_enable_channel_interrupts(struct visor_device *dev)
1115 dev_start_periodic_work(dev);
1117 EXPORT_SYMBOL_GPL(visorbus_enable_channel_interrupts);
1120 visorbus_disable_channel_interrupts(struct visor_device *dev)
1122 dev_stop_periodic_work(dev);
1124 EXPORT_SYMBOL_GPL(visorbus_disable_channel_interrupts);
1126 /** This is how everything starts from the device end.
1127 * This function is called when a channel first appears via a ControlVM
1128 * message. In response, this function allocates a visor_device to
1129 * correspond to the new channel, and attempts to connect it the appropriate
1130 * driver. If the appropriate driver is found, the visor_driver.probe()
1131 * function for that driver will be called, and will be passed the new
1132 * visor_device that we just created.
1134 * It's ok if the appropriate driver is not yet loaded, because in that case
1135 * the new device struct will just stick around in the bus' list of devices.
1136 * When the appropriate driver calls visorbus_register_visor_driver(), the
1137 * visor_driver.probe() for the new driver will be called with the new
1141 create_visor_device(struct visorbus_devdata *devdata,
1142 unsigned long chipset_bus_no, unsigned long chipset_dev_no,
1143 struct visorchipset_channel_info chan_info,
1144 u64 partition_handle)
1147 struct visorchannel *visorchannel = NULL;
1148 struct visor_device *dev = NULL;
1149 bool gotten = false, registered1 = false, registered2 = false;
1151 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, chipset_dev_no, chipset_bus_no,
1152 POSTCODE_SEVERITY_INFO);
1153 /* prepare chan_hdr (abstraction to read/write channel memory) */
1154 visorchannel = visorchannel_create(chan_info.channel_addr,
1155 chan_info.n_channel_bytes,
1157 chan_info.channel_type_uuid);
1158 if (!visorchannel) {
1159 POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, chipset_dev_no,
1163 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
1165 POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, chipset_dev_no,
1170 memset(dev, 0, sizeof(struct visor_device));
1171 dev->visorchannel = visorchannel;
1172 dev->channel_type_guid = chan_info.channel_type_uuid;
1173 dev->channel_bytes = chan_info.n_channel_bytes;
1174 dev->chipset_bus_no = chipset_bus_no;
1175 dev->chipset_dev_no = chipset_dev_no;
1176 dev->device.parent = &devdata->dev;
1177 sema_init(&dev->visordriver_callback_lock, 1); /* unlocked */
1178 dev->device.bus = &visorbus_type;
1179 device_initialize(&dev->device);
1180 dev->device.release = visorbus_release_device;
1181 /* keep a reference just for us (now 2) */
1182 get_device(&dev->device);
1184 dev->periodic_work =
1185 visor_periodic_work_create(POLLJIFFIES_NORMALCHANNEL,
1186 periodic_dev_workqueue,
1188 dev, dev_name(&dev->device));
1189 if (!dev->periodic_work) {
1190 POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, chipset_dev_no,
1195 /* bus_id must be a unique name with respect to this bus TYPE
1196 * (NOT bus instance). That's why we need to include the bus
1197 * number within the name.
1199 dev_set_name(&dev->device, "vbus%lu:dev%lu",
1200 chipset_bus_no, chipset_dev_no);
1202 /* device_add does this:
1203 * bus_add_device(dev)
1204 * ->device_attach(dev)
1205 * ->for each driver drv registered on the bus that dev is on
1206 * if (dev.drv) ** device already has a driver **
1207 * ** not sure we could ever get here... **
1209 * if (bus.match(dev,drv)) [visorbus_match]
1211 * if (!drv.probe(dev)) [visordriver_probe_device]
1214 * Note that device_add does NOT fail if no driver failed to
1215 * claim the device. The device will be linked onto
1216 * bus_type.klist_devices regardless (use bus_for_each_dev).
1218 rc = device_add(&dev->device);
1220 POSTCODE_LINUX_3(DEVICE_ADD_PC, chipset_bus_no,
1225 /* note: device_register is simply device_initialize + device_add */
1226 rc = register_channel_attributes(dev);
1228 POSTCODE_LINUX_3(DEVICE_REGISTER_FAILURE_PC, chipset_dev_no,
1235 rc = register_devmajorminor_attributes(dev);
1237 POSTCODE_LINUX_3(DEVICE_REGISTER_FAILURE_PC, chipset_dev_no,
1248 unregister_devmajorminor_attributes(dev);
1250 unregister_channel_attributes(dev);
1252 put_device(&dev->device);
1254 visorchannel_destroy(visorchannel);
1257 total_devices_created++;
1258 list_add_tail(&dev->list_all, &list_all_device_instances);
1264 remove_visor_device(struct visor_device *dev)
1266 list_del(&dev->list_all);
1267 unregister_devmajorminor_attributes(dev);
1268 unregister_channel_attributes(dev);
1269 put_device(&dev->device);
1270 device_unregister(&dev->device);
1273 static struct visor_device *
1274 find_visor_device_by_channel(u64 channel_physaddr)
1276 struct list_head *listentry, *listtmp;
1278 list_for_each_safe(listentry, listtmp, &list_all_device_instances) {
1279 struct visor_device *dev = list_entry(listentry,
1280 struct visor_device,
1282 if (visorchannel_get_physaddr(dev->visorchannel) ==
1290 init_vbus_channel(struct visorchannel *chan)
1293 unsigned long allocated_bytes = visorchannel_get_nbytes(chan);
1294 struct spar_vbus_channel_protocol *x =
1295 kmalloc(sizeof(struct spar_vbus_channel_protocol),
1298 POSTCODE_LINUX_3(VBUS_CHANNEL_ENTRY_PC, rc, POSTCODE_SEVERITY_INFO);
1301 POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR);
1304 if (visorchannel_clear(chan, 0, 0, allocated_bytes) < 0) {
1305 POSTCODE_LINUX_2(VBUS_CHANNEL_FAILURE_PC,
1306 POSTCODE_SEVERITY_ERR);
1309 if (visorchannel_read
1310 (chan, 0, x, sizeof(struct spar_vbus_channel_protocol)) < 0) {
1311 POSTCODE_LINUX_2(VBUS_CHANNEL_FAILURE_PC,
1312 POSTCODE_SEVERITY_ERR);
1315 if (!SPAR_VBUS_CHANNEL_OK_SERVER(allocated_bytes)) {
1316 POSTCODE_LINUX_2(VBUS_CHANNEL_FAILURE_PC,
1317 POSTCODE_SEVERITY_ERR);
1321 if (visorchannel_write
1322 (chan, 0, x, sizeof(struct spar_vbus_channel_protocol)) < 0) {
1323 POSTCODE_LINUX_3(VBUS_CHANNEL_FAILURE_PC, chan,
1324 POSTCODE_SEVERITY_ERR);
1328 POSTCODE_LINUX_3(VBUS_CHANNEL_EXIT_PC, chan, POSTCODE_SEVERITY_INFO);
1338 get_vbus_header_info(struct visorchannel *chan,
1339 struct spar_vbus_headerinfo *hdr_info)
1343 if (!SPAR_VBUS_CHANNEL_OK_CLIENT(visorchannel_get_header(chan)))
1345 if (visorchannel_read(chan, sizeof(struct channel_header), hdr_info,
1346 sizeof(*hdr_info)) < 0) {
1349 if (hdr_info->struct_bytes < sizeof(struct spar_vbus_headerinfo))
1351 if (hdr_info->device_info_struct_bytes <
1352 sizeof(struct ultra_vbus_deviceinfo)) {
1360 /* Write the contents of <info> to the struct
1361 * spar_vbus_channel_protocol.chp_info. */
1364 write_vbus_chp_info(struct visorchannel *chan,
1365 struct spar_vbus_headerinfo *hdr_info,
1366 struct ultra_vbus_deviceinfo *info)
1368 int off = sizeof(struct channel_header) + hdr_info->chp_info_offset;
1370 if (hdr_info->chp_info_offset == 0)
1373 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
1378 /* Write the contents of <info> to the struct
1379 * spar_vbus_channel_protocol.bus_info. */
1382 write_vbus_bus_info(struct visorchannel *chan,
1383 struct spar_vbus_headerinfo *hdr_info,
1384 struct ultra_vbus_deviceinfo *info)
1386 int off = sizeof(struct channel_header) + hdr_info->bus_info_offset;
1388 if (hdr_info->bus_info_offset == 0)
1391 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
1396 /* Write the contents of <info> to the
1397 * struct spar_vbus_channel_protocol.dev_info[<devix>].
1400 write_vbus_dev_info(struct visorchannel *chan,
1401 struct spar_vbus_headerinfo *hdr_info,
1402 struct ultra_vbus_deviceinfo *info, int devix)
1405 (sizeof(struct channel_header) + hdr_info->dev_info_offset) +
1406 (hdr_info->device_info_struct_bytes * devix);
1408 if (hdr_info->dev_info_offset == 0)
1411 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
1416 /* For a child device just created on a client bus, fill in
1417 * information about the driver that is controlling this device into
1418 * the the appropriate slot within the vbus channel of the bus
1422 fix_vbus_dev_info(struct visor_device *visordev)
1425 struct visorchipset_bus_info bus_info;
1426 struct visorbus_devdata *devdata = NULL;
1427 struct visor_driver *visordrv;
1428 int bus_no = visordev->chipset_bus_no;
1429 int dev_no = visordev->chipset_dev_no;
1430 struct ultra_vbus_deviceinfo dev_info;
1431 const char *chan_type_name = NULL;
1433 if (!visordev->device.driver)
1436 visordrv = to_visor_driver(visordev->device.driver);
1437 if (!visorchipset_get_bus_info(bus_no, &bus_info))
1440 devdata = (struct visorbus_devdata *)(bus_info.bus_driver_context);
1444 if (!devdata->vbus_valid)
1447 /* Within the list of device types (by GUID) that the driver
1448 * says it supports, find out which one of those types matches
1449 * the type of this device, so that we can include the device
1452 for (i = 0; visordrv->channel_types[i].name; i++) {
1453 if (memcmp(&visordrv->channel_types[i].guid,
1454 &visordev->channel_type_guid,
1455 sizeof(visordrv->channel_types[i].guid)) == 0) {
1456 chan_type_name = visordrv->channel_types[i].name;
1461 bus_device_info_init(&dev_info, chan_type_name,
1462 visordrv->name, visordrv->version,
1464 write_vbus_dev_info(devdata->chan,
1465 &devdata->vbus_hdr_info, &dev_info, dev_no);
1467 /* Re-write bus+chipset info, because it is possible that this
1468 * was previously written by our evil counterpart, virtpci.
1470 write_vbus_chp_info(devdata->chan, &devdata->vbus_hdr_info,
1471 &chipset_driverinfo);
1472 write_vbus_bus_info(devdata->chan, &devdata->vbus_hdr_info,
1473 &clientbus_driverinfo);
1476 /** Create a device instance for the visor bus itself.
1478 static struct visorbus_devdata *
1479 create_bus_instance(int id)
1481 struct visorbus_devdata *rc = NULL;
1482 struct visorbus_devdata *devdata = NULL;
1483 struct visorchipset_bus_info bus_info;
1485 POSTCODE_LINUX_2(BUS_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
1486 devdata = kzalloc(sizeof(*devdata), GFP_KERNEL);
1488 POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR);
1492 dev_set_name(&devdata->dev, "visorbus%d", id);
1493 devdata->dev.bus = &visorbus_type;
1494 devdata->dev.groups = visorbus_groups;
1495 devdata->dev.release = visorbus_release_busdevice;
1496 if (device_register(&devdata->dev) < 0) {
1497 POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, id,
1498 POSTCODE_SEVERITY_ERR);
1502 devdata->devno = id;
1503 if ((visorchipset_get_bus_info(id, &bus_info)) &&
1504 (bus_info.chan_info.channel_addr > 0) &&
1505 (bus_info.chan_info.n_channel_bytes > 0)) {
1506 u64 channel_addr = bus_info.chan_info.channel_addr;
1507 unsigned long n_channel_bytes =
1509 bus_info.chan_info.n_channel_bytes;
1510 uuid_le channel_type_guid =
1511 bus_info.chan_info.channel_type_uuid;
1513 devdata->chan = visorchannel_create(channel_addr,
1517 if (!devdata->chan) {
1518 POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, channel_addr,
1519 POSTCODE_SEVERITY_ERR);
1521 if (bus_info.flags.server) {
1522 init_vbus_channel(devdata->chan);
1524 if (get_vbus_header_info(devdata->chan,
1526 vbus_hdr_info) >= 0) {
1527 devdata->vbus_valid = true;
1528 write_vbus_chp_info(devdata->chan,
1533 write_vbus_bus_info(devdata->chan,
1536 &clientbus_driverinfo);
1542 list_add_tail(&devdata->list_all, &list_all_bus_instances);
1544 devdata = devdata; /* for testing ONLY */
1545 dev_set_drvdata(&devdata->dev, devdata);
1551 /** Remove a device instance for the visor bus itself.
1554 remove_bus_instance(struct visorbus_devdata *devdata)
1556 /* Note that this will result in the release method for
1557 * devdata->dev being called, which will call
1558 * visorbus_release_busdevice(). This has something to do with
1559 * the put_device() done in device_unregister(), but I have never
1560 * successfully been able to trace thru the code to see where/how
1561 * release() gets called. But I know it does.
1564 if (devdata->chan) {
1565 visorchannel_destroy(devdata->chan);
1566 devdata->chan = NULL;
1568 list_del(&devdata->list_all);
1569 device_unregister(&devdata->dev);
1572 /** Create and register the one-and-only one instance of
1573 * the visor bus type (visorbus_type).
1576 create_bus_type(void)
1580 visorbus_type.dev_attrs = visor_device_attrs;
1581 rc = bus_register(&visorbus_type);
1585 /** Remove the one-and-only one instance of the visor bus type (visorbus_type).
1588 remove_bus_type(void)
1590 bus_unregister(&visorbus_type);
1593 /** Remove all child visor bus device instances.
1596 remove_all_visor_devices(void)
1598 struct list_head *listentry, *listtmp;
1600 list_for_each_safe(listentry, listtmp, &list_all_device_instances) {
1601 struct visor_device *dev = list_entry(listentry,
1602 struct visor_device,
1604 remove_visor_device(dev);
1608 static bool entered_testing_mode;
1609 static struct visorchipset_channel_info test_channel_infos[MAXDEVICETEST];
1610 static unsigned long test_bus_nos[MAXDEVICETEST];
1611 static unsigned long test_dev_nos[MAXDEVICETEST];
1614 chipset_bus_create(u32 bus_no)
1616 struct visorchipset_bus_info bus_info;
1617 struct visorbus_devdata *devdata;
1620 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, bus_no, POSTCODE_SEVERITY_INFO);
1621 if (!visorchipset_get_bus_info(bus_no, &bus_info))
1623 devdata = create_bus_instance(bus_no);
1626 if (!visorchipset_set_bus_context(bus_no, devdata))
1628 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus_no, POSTCODE_SEVERITY_INFO);
1632 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no,
1633 POSTCODE_SEVERITY_ERR);
1636 POSTCODE_LINUX_3(CHIPSET_INIT_SUCCESS_PC, bus_no,
1637 POSTCODE_SEVERITY_INFO);
1638 if (chipset_responders.bus_create)
1639 (*chipset_responders.bus_create) (bus_no, rc);
1643 chipset_bus_destroy(u32 bus_no)
1645 struct visorchipset_bus_info bus_info;
1646 struct visorbus_devdata *devdata;
1649 if (!visorchipset_get_bus_info(bus_no, &bus_info))
1651 devdata = (struct visorbus_devdata *)(bus_info.bus_driver_context);
1654 remove_bus_instance(devdata);
1655 if (!visorchipset_set_bus_context(bus_no, NULL))
1661 if (chipset_responders.bus_destroy)
1662 (*chipset_responders.bus_destroy)(bus_no, rc);
1666 chipset_device_create(u32 bus_no, u32 dev_no)
1668 struct visorchipset_device_info dev_info;
1669 struct visorchipset_bus_info bus_info;
1670 struct visorbus_devdata *devdata = NULL;
1673 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no,
1674 POSTCODE_SEVERITY_INFO);
1676 if (entered_testing_mode)
1678 if (!visorchipset_get_device_info(bus_no, dev_no, &dev_info))
1680 if (!visorchipset_get_bus_info(bus_no, &bus_info))
1682 if (visorbus_devicetest)
1683 if (total_devices_created < MAXDEVICETEST) {
1684 test_channel_infos[total_devices_created] =
1686 test_bus_nos[total_devices_created] = bus_no;
1687 test_dev_nos[total_devices_created] = dev_no;
1689 POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, dev_no, bus_no,
1690 POSTCODE_SEVERITY_INFO);
1694 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
1695 POSTCODE_SEVERITY_ERR);
1698 devdata = (struct visorbus_devdata *)(bus_info.bus_driver_context);
1699 rc = create_visor_device(devdata, bus_no, dev_no,
1700 dev_info.chan_info, bus_info.partition_handle);
1701 POSTCODE_LINUX_4(DEVICE_CREATE_SUCCESS_PC, dev_no, bus_no,
1702 POSTCODE_SEVERITY_INFO);
1704 if (chipset_responders.device_create)
1705 (*chipset_responders.device_create)(bus_no, dev_no, rc);
1709 chipset_device_destroy(u32 bus_no, u32 dev_no)
1711 struct visorchipset_device_info dev_info;
1712 struct visor_device *dev;
1715 if (entered_testing_mode)
1717 if (!visorchipset_get_device_info(bus_no, dev_no, &dev_info))
1719 dev = find_visor_device_by_channel(dev_info.chan_info.channel_addr);
1727 if (chipset_responders.device_destroy)
1728 (*chipset_responders.device_destroy) (bus_no, dev_no, rc);
1729 remove_visor_device(dev);
1732 /* This is the callback function specified for a function driver, to
1733 * be called when a pending "pause device" operation has been
1737 pause_state_change_complete(struct visor_device *dev, int status)
1742 dev->pausing = false;
1743 if (!chipset_responders.device_pause) /* this can never happen! */
1746 /* Notify the chipset driver that the pause is complete, which
1747 * will presumably want to send some sort of response to the
1749 (*chipset_responders.device_pause) (dev->chipset_bus_no,
1750 dev->chipset_dev_no, status);
1753 /* This is the callback function specified for a function driver, to
1754 * be called when a pending "resume device" operation has been
1758 resume_state_change_complete(struct visor_device *dev, int status)
1763 dev->resuming = false;
1764 if (!chipset_responders.device_resume) /* this can never happen! */
1767 /* Notify the chipset driver that the resume is complete,
1768 * which will presumably want to send some sort of response to
1770 (*chipset_responders.device_resume) (dev->chipset_bus_no,
1771 dev->chipset_dev_no, status);
1774 /* Tell the subordinate function driver for a specific device to pause
1775 * or resume that device. Result is returned asynchronously via a
1776 * callback function.
1779 initiate_chipset_device_pause_resume(u32 bus_no, u32 dev_no, bool is_pause)
1781 struct visorchipset_device_info dev_info;
1782 struct visor_device *dev = NULL;
1784 struct visor_driver *drv = NULL;
1785 void (*notify_func)(u32 bus_no, u32 dev_no, int response) = NULL;
1788 notify_func = chipset_responders.device_pause;
1790 notify_func = chipset_responders.device_resume;
1794 if (!visorchipset_get_device_info(bus_no, dev_no, &dev_info))
1797 dev = find_visor_device_by_channel(dev_info.chan_info.channel_addr);
1801 drv = to_visor_driver(dev->device.driver);
1805 if (dev->pausing || dev->resuming)
1808 /* Note that even though both drv->pause() and drv->resume
1809 * specify a callback function, it is NOT necessary for us to
1810 * increment our local module usage count. Reason is, there
1811 * is already a linkage dependency between child function
1812 * drivers and visorbus, so it is already IMPOSSIBLE to unload
1813 * visorbus while child function drivers are still running.
1819 dev->pausing = true;
1820 x = drv->pause(dev, pause_state_change_complete);
1822 /* This should be done at BUS resume time, but an
1823 * existing problem prevents us from ever getting a bus
1824 * resume... This hack would fail to work should we
1825 * ever have a bus that contains NO devices, since we
1826 * would never even get here in that case. */
1827 fix_vbus_dev_info(dev);
1831 dev->resuming = true;
1832 x = drv->resume(dev, resume_state_change_complete);
1836 dev->pausing = false;
1838 dev->resuming = false;
1845 (*notify_func)(bus_no, dev_no, rc);
1850 chipset_device_pause(u32 bus_no, u32 dev_no)
1852 initiate_chipset_device_pause_resume(bus_no, dev_no, true);
1856 chipset_device_resume(u32 bus_no, u32 dev_no)
1858 initiate_chipset_device_pause_resume(bus_no, dev_no, false);
1861 struct channel_size_info {
1863 unsigned long min_size;
1864 unsigned long max_size;
1872 POSTCODE_LINUX_3(DRIVER_ENTRY_PC, rc, POSTCODE_SEVERITY_INFO);
1873 bus_device_info_init(&clientbus_driverinfo,
1874 "clientbus", "visorbus",
1877 /* process module options */
1879 if (visorbus_devicetest > MAXDEVICETEST)
1880 visorbus_devicetest = MAXDEVICETEST;
1882 rc = create_bus_type();
1884 POSTCODE_LINUX_2(BUS_CREATE_ENTRY_PC, DIAG_SEVERITY_ERR);
1888 periodic_dev_workqueue = create_singlethread_workqueue("visorbus_dev");
1889 if (!periodic_dev_workqueue) {
1890 POSTCODE_LINUX_2(CREATE_WORKQUEUE_PC, DIAG_SEVERITY_ERR);
1895 /* This enables us to receive notifications when devices appear for
1896 * which this service partition is to be a server for.
1898 visorchipset_register_busdev(&chipset_notifiers,
1899 &chipset_responders,
1900 &chipset_driverinfo);
1906 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, rc,
1907 POSTCODE_SEVERITY_ERR);
1914 struct list_head *listentry, *listtmp;
1916 visorchipset_register_busdev(NULL, NULL, NULL);
1917 remove_all_visor_devices();
1919 flush_workqueue(periodic_dev_workqueue); /* better not be any work! */
1920 destroy_workqueue(periodic_dev_workqueue);
1921 periodic_dev_workqueue = NULL;
1923 if (periodic_test_workqueue) {
1924 cancel_delayed_work(&periodic_work);
1925 flush_workqueue(periodic_test_workqueue);
1926 destroy_workqueue(periodic_test_workqueue);
1927 periodic_test_workqueue = NULL;
1930 list_for_each_safe(listentry, listtmp, &list_all_bus_instances) {
1931 struct visorbus_devdata *devdata = list_entry(listentry,
1935 remove_bus_instance(devdata);
1940 module_param_named(debug, visorbus_debug, int, S_IRUGO);
1941 MODULE_PARM_DESC(visorbus_debug, "1 to debug");
1942 int visorbus_debug = 0;
1944 module_param_named(forcematch, visorbus_forcematch, int, S_IRUGO);
1945 MODULE_PARM_DESC(visorbus_forcematch,
1946 "1 to force a successful dev <--> drv match");
1947 int visorbus_forcematch = 0;
1949 module_param_named(forcenomatch, visorbus_forcenomatch, int, S_IRUGO);
1950 MODULE_PARM_DESC(visorbus_forcenomatch,
1951 "1 to force an UNsuccessful dev <--> drv match");
1952 int visorbus_forcenomatch = 0;
1954 module_param_named(devicetest, visorbus_devicetest, int, S_IRUGO);
1955 MODULE_PARM_DESC(visorbus_devicetest,
1956 "non-0 to just test device creation and destruction");
1957 int visorbus_devicetest = 0;
1959 module_param_named(debugref, visorbus_debugref, int, S_IRUGO);
1960 MODULE_PARM_DESC(visorbus_debugref, "1 to debug reference counting");
1961 int visorbus_debugref = 0;
1963 MODULE_AUTHOR("Unisys");
1964 MODULE_LICENSE("GPL");
1965 MODULE_DESCRIPTION("Supervisor bus driver for service partition: ver " VERSION);
1966 MODULE_VERSION(VERSION);