3 * Copyright � 2010 - 2015 UNISYS CORPORATION
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
17 #include <linux/debugfs.h>
18 #include <linux/uuid.h>
21 #include "visorbus_private.h"
22 #include "vmcallinterface.h"
24 #define MYDRVNAME "visorbus"
26 /* Display string that is guaranteed to be no longer the 99 characters*/
29 #define CURRENT_FILE_PC VISOR_BUS_PC_visorbus_main_c
30 #define POLLJIFFIES_NORMALCHANNEL 10
32 static bool initialized
; /* stores whether bus_registration was successful */
33 static struct dentry
*visorbus_debugfs_dir
;
36 * DEVICE type attributes
38 * The modalias file will contain the guid of the device.
40 static ssize_t
modalias_show(struct device
*dev
, struct device_attribute
*attr
,
43 struct visor_device
*vdev
;
46 vdev
= to_visor_device(dev
);
47 guid
= visorchannel_get_uuid(vdev
->visorchannel
);
48 return sprintf(buf
, "visorbus:%pUl\n", &guid
);
50 static DEVICE_ATTR_RO(modalias
);
52 static struct attribute
*visorbus_dev_attrs
[] = {
53 &dev_attr_modalias
.attr
,
57 /* sysfs example for bridge-only sysfs files using device_type's */
58 static const struct attribute_group visorbus_dev_group
= {
59 .attrs
= visorbus_dev_attrs
,
62 static const struct attribute_group
*visorbus_dev_groups
[] = {
67 /* filled in with info about parent chipset driver when we register with it */
68 static struct ultra_vbus_deviceinfo chipset_driverinfo
;
69 /* filled in with info about this driver, wrt it servicing client busses */
70 static struct ultra_vbus_deviceinfo clientbus_driverinfo
;
72 /* list of visor_device structs, linked via .list_all */
73 static LIST_HEAD(list_all_bus_instances
);
74 /* list of visor_device structs, linked via .list_all */
75 static LIST_HEAD(list_all_device_instances
);
78 visorbus_uevent(struct device
*xdev
, struct kobj_uevent_env
*env
)
80 struct visor_device
*dev
;
83 dev
= to_visor_device(xdev
);
84 guid
= visorchannel_get_uuid(dev
->visorchannel
);
86 return add_uevent_var(env
, "MODALIAS=visorbus:%pUl", &guid
);
90 * visorbus_match() - called automatically upon adding a visor_device
91 * (device_add), or adding a visor_driver
92 * (visorbus_register_visor_driver)
93 * @xdev: struct device for the device being matched
94 * @xdrv: struct device_driver for driver to match device against
96 * Return: 1 iff the provided driver can control the specified device
99 visorbus_match(struct device
*xdev
, struct device_driver
*xdrv
)
101 uuid_le channel_type
;
103 struct visor_device
*dev
;
104 struct visor_driver
*drv
;
106 dev
= to_visor_device(xdev
);
107 drv
= to_visor_driver(xdrv
);
108 channel_type
= visorchannel_get_uuid(dev
->visorchannel
);
110 if (!drv
->channel_types
)
114 (uuid_le_cmp(drv
->channel_types
[i
].guid
, NULL_UUID_LE
) != 0) ||
115 (drv
->channel_types
[i
].name
);
117 if (uuid_le_cmp(drv
->channel_types
[i
].guid
,
125 * This describes the TYPE of bus.
126 * (Don't confuse this with an INSTANCE of the bus.)
128 struct bus_type visorbus_type
= {
130 .match
= visorbus_match
,
131 .uevent
= visorbus_uevent
,
132 .dev_groups
= visorbus_dev_groups
,
136 * visorbus_release_busdevice() - called when device_unregister() is called for
137 * the bus device instance, after all other tasks
138 * involved with destroying the dev are complete
139 * @xdev: struct device for the bus being released
142 visorbus_release_busdevice(struct device
*xdev
)
144 struct visor_device
*dev
= dev_get_drvdata(xdev
);
146 debugfs_remove(dev
->debugfs_client_bus_info
);
147 debugfs_remove_recursive(dev
->debugfs_dir
);
152 * visorbus_release_device() - called when device_unregister() is called for
153 * each child device instance
154 * @xdev: struct device for the visor device being released
157 visorbus_release_device(struct device
*xdev
)
159 struct visor_device
*dev
= to_visor_device(xdev
);
161 if (dev
->visorchannel
) {
162 visorchannel_destroy(dev
->visorchannel
);
163 dev
->visorchannel
= NULL
;
169 * begin implementation of specific channel attributes to appear under
170 * /sys/bus/visorbus<x>/dev<y>/channel
173 static ssize_t
physaddr_show(struct device
*dev
, struct device_attribute
*attr
,
176 struct visor_device
*vdev
= to_visor_device(dev
);
178 return sprintf(buf
, "0x%llx\n",
179 visorchannel_get_physaddr(vdev
->visorchannel
));
181 static DEVICE_ATTR_RO(physaddr
);
183 static ssize_t
nbytes_show(struct device
*dev
, struct device_attribute
*attr
,
186 struct visor_device
*vdev
= to_visor_device(dev
);
188 return sprintf(buf
, "0x%lx\n",
189 visorchannel_get_nbytes(vdev
->visorchannel
));
191 static DEVICE_ATTR_RO(nbytes
);
193 static ssize_t
clientpartition_show(struct device
*dev
,
194 struct device_attribute
*attr
, char *buf
)
196 struct visor_device
*vdev
= to_visor_device(dev
);
198 return sprintf(buf
, "0x%llx\n",
199 visorchannel_get_clientpartition(vdev
->visorchannel
));
201 static DEVICE_ATTR_RO(clientpartition
);
203 static ssize_t
typeguid_show(struct device
*dev
, struct device_attribute
*attr
,
206 struct visor_device
*vdev
= to_visor_device(dev
);
207 char typeid[LINESIZE
];
209 return sprintf(buf
, "%s\n",
210 visorchannel_id(vdev
->visorchannel
, typeid));
212 static DEVICE_ATTR_RO(typeguid
);
214 static ssize_t
zoneguid_show(struct device
*dev
, struct device_attribute
*attr
,
217 struct visor_device
*vdev
= to_visor_device(dev
);
218 char zoneid
[LINESIZE
];
220 return sprintf(buf
, "%s\n",
221 visorchannel_zoneid(vdev
->visorchannel
, zoneid
));
223 static DEVICE_ATTR_RO(zoneguid
);
225 static ssize_t
typename_show(struct device
*dev
, struct device_attribute
*attr
,
229 struct bus_type
*xbus
= dev
->bus
;
230 struct device_driver
*xdrv
= dev
->driver
;
231 struct visor_driver
*drv
= NULL
;
235 i
= xbus
->match(dev
, xdrv
);
238 drv
= to_visor_driver(xdrv
);
239 return sprintf(buf
, "%s\n", drv
->channel_types
[i
- 1].name
);
241 static DEVICE_ATTR_RO(typename
);
243 static struct attribute
*channel_attrs
[] = {
244 &dev_attr_physaddr
.attr
,
245 &dev_attr_nbytes
.attr
,
246 &dev_attr_clientpartition
.attr
,
247 &dev_attr_typeguid
.attr
,
248 &dev_attr_zoneguid
.attr
,
249 &dev_attr_typename
.attr
,
253 static struct attribute_group channel_attr_grp
= {
255 .attrs
= channel_attrs
,
258 static const struct attribute_group
*visorbus_channel_groups
[] = {
263 /* end implementation of specific channel attributes */
266 * BUS instance attributes
268 * define & implement display of bus attributes under
269 * /sys/bus/visorbus/devices/visorbus<n>.
272 static ssize_t
partition_handle_show(struct device
*dev
,
273 struct device_attribute
*attr
,
275 struct visor_device
*vdev
= to_visor_device(dev
);
276 u64 handle
= visorchannel_get_clientpartition(vdev
->visorchannel
);
278 return sprintf(buf
, "0x%llx\n", handle
);
280 static DEVICE_ATTR_RO(partition_handle
);
282 static ssize_t
partition_guid_show(struct device
*dev
,
283 struct device_attribute
*attr
,
285 struct visor_device
*vdev
= to_visor_device(dev
);
287 return sprintf(buf
, "{%pUb}\n", &vdev
->partition_uuid
);
289 static DEVICE_ATTR_RO(partition_guid
);
291 static ssize_t
partition_name_show(struct device
*dev
,
292 struct device_attribute
*attr
,
294 struct visor_device
*vdev
= to_visor_device(dev
);
296 return sprintf(buf
, "%s\n", vdev
->name
);
298 static DEVICE_ATTR_RO(partition_name
);
300 static ssize_t
channel_addr_show(struct device
*dev
,
301 struct device_attribute
*attr
,
303 struct visor_device
*vdev
= to_visor_device(dev
);
304 u64 addr
= visorchannel_get_physaddr(vdev
->visorchannel
);
306 return sprintf(buf
, "0x%llx\n", addr
);
308 static DEVICE_ATTR_RO(channel_addr
);
310 static ssize_t
channel_bytes_show(struct device
*dev
,
311 struct device_attribute
*attr
,
313 struct visor_device
*vdev
= to_visor_device(dev
);
314 u64 nbytes
= visorchannel_get_nbytes(vdev
->visorchannel
);
316 return sprintf(buf
, "0x%llx\n", nbytes
);
318 static DEVICE_ATTR_RO(channel_bytes
);
320 static ssize_t
channel_id_show(struct device
*dev
,
321 struct device_attribute
*attr
,
323 struct visor_device
*vdev
= to_visor_device(dev
);
326 visorchannel_id(vdev
->visorchannel
, buf
);
332 static DEVICE_ATTR_RO(channel_id
);
334 static struct attribute
*dev_attrs
[] = {
335 &dev_attr_partition_handle
.attr
,
336 &dev_attr_partition_guid
.attr
,
337 &dev_attr_partition_name
.attr
,
338 &dev_attr_channel_addr
.attr
,
339 &dev_attr_channel_bytes
.attr
,
340 &dev_attr_channel_id
.attr
,
344 static struct attribute_group dev_attr_grp
= {
348 static const struct attribute_group
*visorbus_groups
[] = {
354 * BUS debugfs entries
356 * define & implement display of debugfs attributes under
357 * /sys/kernel/debug/visorbus/visorbus<n>.
360 * vbuschannel_print_devinfo() - format a struct ultra_vbus_deviceinfo
361 * and write it to a seq_file
362 * @devinfo: the struct ultra_vbus_deviceinfo to format
363 * @seq: seq_file to write to
364 * @devix: the device index to be included in the output data, or -1 if no
365 * device index is to be included
367 * Reads @devInfo, and writes it in human-readable notation to @seq.
370 vbuschannel_print_devinfo(struct ultra_vbus_deviceinfo
*devinfo
,
371 struct seq_file
*seq
, int devix
)
373 if (!isprint(devinfo
->devtype
[0]))
374 return; /* uninitialized vbus device entry */
377 seq_printf(seq
, "[%d]", devix
);
379 /* vbus device entry is for bus or chipset */
383 * Note: because the s-Par back-end is free to scribble in this area,
384 * we never assume '\0'-termination.
386 seq_printf(seq
, "%-*.*s ", (int)sizeof(devinfo
->devtype
),
387 (int)sizeof(devinfo
->devtype
), devinfo
->devtype
);
388 seq_printf(seq
, "%-*.*s ", (int)sizeof(devinfo
->drvname
),
389 (int)sizeof(devinfo
->drvname
), devinfo
->drvname
);
390 seq_printf(seq
, "%.*s\n", (int)sizeof(devinfo
->infostrs
),
394 static int client_bus_info_debugfs_show(struct seq_file
*seq
, void *v
)
396 struct visor_device
*vdev
= seq
->private;
397 struct visorchannel
*channel
= vdev
->visorchannel
;
401 struct ultra_vbus_deviceinfo dev_info
;
407 "Client device / client driver info for %s partition (vbus #%u):\n",
408 ((vdev
->name
) ? (char *)(vdev
->name
) : ""),
409 vdev
->chipset_bus_no
);
410 if (visorchannel_read(channel
,
411 offsetof(struct spar_vbus_channel_protocol
,
413 &dev_info
, sizeof(dev_info
)) >= 0)
414 vbuschannel_print_devinfo(&dev_info
, seq
, -1);
415 if (visorchannel_read(channel
,
416 offsetof(struct spar_vbus_channel_protocol
,
418 &dev_info
, sizeof(dev_info
)) >= 0)
419 vbuschannel_print_devinfo(&dev_info
, seq
, -1);
420 off
= offsetof(struct spar_vbus_channel_protocol
, dev_info
);
422 while (off
+ sizeof(dev_info
) <= visorchannel_get_nbytes(channel
)) {
423 if (visorchannel_read(channel
, off
, &dev_info
,
424 sizeof(dev_info
)) >= 0)
425 vbuschannel_print_devinfo(&dev_info
, seq
, i
);
426 off
+= sizeof(dev_info
);
433 static int client_bus_info_debugfs_open(struct inode
*inode
, struct file
*file
)
435 return single_open(file
, client_bus_info_debugfs_show
,
439 static const struct file_operations client_bus_info_debugfs_fops
= {
440 .owner
= THIS_MODULE
,
441 .open
= client_bus_info_debugfs_open
,
444 .release
= single_release
,
448 dev_periodic_work(unsigned long __opaque
)
450 struct visor_device
*dev
= (struct visor_device
*)__opaque
;
451 struct visor_driver
*drv
= to_visor_driver(dev
->device
.driver
);
453 drv
->channel_interrupt(dev
);
454 mod_timer(&dev
->timer
, jiffies
+ POLLJIFFIES_NORMALCHANNEL
);
458 dev_start_periodic_work(struct visor_device
*dev
)
460 if (dev
->being_removed
|| dev
->timer_active
)
462 /* now up by at least 2 */
463 get_device(&dev
->device
);
464 dev
->timer
.expires
= jiffies
+ POLLJIFFIES_NORMALCHANNEL
;
465 add_timer(&dev
->timer
);
466 dev
->timer_active
= true;
471 dev_stop_periodic_work(struct visor_device
*dev
)
473 if (!dev
->timer_active
)
475 del_timer_sync(&dev
->timer
);
476 dev
->timer_active
= false;
477 put_device(&dev
->device
);
481 * visordriver_remove_device() - handle visor device going away
482 * @xdev: struct device for the visor device being removed
484 * This is called when device_unregister() is called for each child device
485 * instance, to notify the appropriate visorbus function driver that the device
486 * is going away, and to decrease the reference count of the device.
488 * Return: 0 iff successful
491 visordriver_remove_device(struct device
*xdev
)
493 struct visor_device
*dev
;
494 struct visor_driver
*drv
;
496 dev
= to_visor_device(xdev
);
497 drv
= to_visor_driver(xdev
->driver
);
498 mutex_lock(&dev
->visordriver_callback_lock
);
499 dev
->being_removed
= true;
502 mutex_unlock(&dev
->visordriver_callback_lock
);
503 dev_stop_periodic_work(dev
);
505 put_device(&dev
->device
);
510 * visorbus_unregister_visor_driver() - unregisters the provided driver
511 * @drv: the driver to unregister
513 * A visor function driver calls this function to unregister the driver,
514 * i.e., within its module_exit function.
517 visorbus_unregister_visor_driver(struct visor_driver
*drv
)
519 driver_unregister(&drv
->driver
);
521 EXPORT_SYMBOL_GPL(visorbus_unregister_visor_driver
);
524 * visorbus_read_channel() - reads from the designated channel into
525 * the provided buffer
526 * @dev: the device whose channel is read from
527 * @offset: the offset into the channel at which reading starts
528 * @dest: the destination buffer that is written into from the channel
529 * @nbytes: the number of bytes to read from the channel
531 * If receiving a message, use the visorchannel_signalremove()
534 * Return: integer indicating success (zero) or failure (non-zero)
537 visorbus_read_channel(struct visor_device
*dev
, unsigned long offset
,
538 void *dest
, unsigned long nbytes
)
540 return visorchannel_read(dev
->visorchannel
, offset
, dest
, nbytes
);
542 EXPORT_SYMBOL_GPL(visorbus_read_channel
);
545 * visorbus_write_channel() - writes the provided buffer into the designated
547 * @dev: the device whose channel is written to
548 * @offset: the offset into the channel at which writing starts
549 * @src: the source buffer that is written into the channel
550 * @nbytes: the number of bytes to write into the channel
552 * If sending a message, use the visorchannel_signalinsert()
555 * Return: integer indicating success (zero) or failure (non-zero)
558 visorbus_write_channel(struct visor_device
*dev
, unsigned long offset
,
559 void *src
, unsigned long nbytes
)
561 return visorchannel_write(dev
->visorchannel
, offset
, src
, nbytes
);
563 EXPORT_SYMBOL_GPL(visorbus_write_channel
);
566 * visorbus_enable_channel_interrupts() - enables interrupts on the
568 * @dev: the device on which to enable interrupts
570 * Currently we don't yet have a real interrupt, so for now we just call the
571 * interrupt function periodically via a timer.
574 visorbus_enable_channel_interrupts(struct visor_device
*dev
)
576 struct visor_driver
*drv
= to_visor_driver(dev
->device
.driver
);
578 if (!drv
->channel_interrupt
) {
579 dev_err(&dev
->device
, "%s no interrupt function!\n", __func__
);
583 return dev_start_periodic_work(dev
);
585 EXPORT_SYMBOL_GPL(visorbus_enable_channel_interrupts
);
588 * visorbus_disable_channel_interrupts() - disables interrupts on the
590 * @dev: the device on which to disable interrupts
593 visorbus_disable_channel_interrupts(struct visor_device
*dev
)
595 dev_stop_periodic_work(dev
);
597 EXPORT_SYMBOL_GPL(visorbus_disable_channel_interrupts
);
600 * create_visor_device() - create visor device as a result of receiving the
601 * controlvm device_create message for a new device
602 * @dev: a freshly-zeroed struct visor_device, containing only filled-in values
603 * for chipset_bus_no and chipset_dev_no, that will be initialized
605 * This is how everything starts from the device end.
606 * This function is called when a channel first appears via a ControlVM
607 * message. In response, this function allocates a visor_device to
608 * correspond to the new channel, and attempts to connect it the appropriate
609 * driver. If the appropriate driver is found, the visor_driver.probe()
610 * function for that driver will be called, and will be passed the new
611 * visor_device that we just created.
613 * It's ok if the appropriate driver is not yet loaded, because in that case
614 * the new device struct will just stick around in the bus' list of devices.
615 * When the appropriate driver calls visorbus_register_visor_driver(), the
616 * visor_driver.probe() for the new driver will be called with the new
619 * Return: 0 if successful, otherwise the negative value returned by
620 * device_add() indicating the reason for failure
623 create_visor_device(struct visor_device
*dev
)
626 u32 chipset_bus_no
= dev
->chipset_bus_no
;
627 u32 chipset_dev_no
= dev
->chipset_dev_no
;
629 POSTCODE_LINUX(DEVICE_CREATE_ENTRY_PC
, chipset_dev_no
, chipset_bus_no
,
630 DIAG_SEVERITY_PRINT
);
632 mutex_init(&dev
->visordriver_callback_lock
);
633 dev
->device
.bus
= &visorbus_type
;
634 dev
->device
.groups
= visorbus_channel_groups
;
635 device_initialize(&dev
->device
);
636 dev
->device
.release
= visorbus_release_device
;
637 /* keep a reference just for us (now 2) */
638 get_device(&dev
->device
);
639 setup_timer(&dev
->timer
, dev_periodic_work
, (unsigned long)dev
);
642 * bus_id must be a unique name with respect to this bus TYPE
643 * (NOT bus instance). That's why we need to include the bus
644 * number within the name.
646 err
= dev_set_name(&dev
->device
, "vbus%u:dev%u",
647 chipset_bus_no
, chipset_dev_no
);
652 * device_add does this:
653 * bus_add_device(dev)
654 * ->device_attach(dev)
655 * ->for each driver drv registered on the bus that dev is on
656 * if (dev.drv) ** device already has a driver **
657 * ** not sure we could ever get here... **
659 * if (bus.match(dev,drv)) [visorbus_match]
661 * if (!drv.probe(dev)) [visordriver_probe_device]
664 * Note that device_add does NOT fail if no driver failed to
665 * claim the device. The device will be linked onto
666 * bus_type.klist_devices regardless (use bus_for_each_dev).
668 err
= device_add(&dev
->device
);
670 POSTCODE_LINUX(DEVICE_ADD_PC
, 0, chipset_bus_no
,
675 list_add_tail(&dev
->list_all
, &list_all_device_instances
);
676 return 0; /* success: reference kept via unmatched get_device() */
679 put_device(&dev
->device
);
684 remove_visor_device(struct visor_device
*dev
)
686 list_del(&dev
->list_all
);
687 put_device(&dev
->device
);
688 device_unregister(&dev
->device
);
692 get_vbus_header_info(struct visorchannel
*chan
,
693 struct spar_vbus_headerinfo
*hdr_info
)
697 if (!spar_check_channel(visorchannel_get_header(chan
),
698 spar_vbus_channel_protocol_uuid
,
700 sizeof(struct spar_vbus_channel_protocol
),
701 SPAR_VBUS_CHANNEL_PROTOCOL_VERSIONID
,
702 SPAR_VBUS_CHANNEL_PROTOCOL_SIGNATURE
))
705 err
= visorchannel_read(chan
, sizeof(struct channel_header
), hdr_info
,
710 if (hdr_info
->struct_bytes
< sizeof(struct spar_vbus_headerinfo
))
713 if (hdr_info
->device_info_struct_bytes
<
714 sizeof(struct ultra_vbus_deviceinfo
))
721 * write_vbus_chp_info() - write the contents of <info> to the struct
722 * spar_vbus_channel_protocol.chp_info
723 * @chan: indentifies the s-Par channel that will be updated
724 * @hdr_info: used to find appropriate channel offset to write data
725 * @info: contains the information to write
727 * Writes chipset info into the channel memory to be used for diagnostic
730 * Returns no value since this is debug information and not needed for
731 * device functionality.
734 write_vbus_chp_info(struct visorchannel
*chan
,
735 struct spar_vbus_headerinfo
*hdr_info
,
736 struct ultra_vbus_deviceinfo
*info
)
738 int off
= sizeof(struct channel_header
) + hdr_info
->chp_info_offset
;
740 if (hdr_info
->chp_info_offset
== 0)
743 visorchannel_write(chan
, off
, info
, sizeof(*info
));
747 * write_vbus_bus_info() - write the contents of <info> to the struct
748 * spar_vbus_channel_protocol.bus_info
749 * @chan: indentifies the s-Par channel that will be updated
750 * @hdr_info: used to find appropriate channel offset to write data
751 * @info: contains the information to write
753 * Writes bus info into the channel memory to be used for diagnostic
756 * Returns no value since this is debug information and not needed for
757 * device functionality.
760 write_vbus_bus_info(struct visorchannel
*chan
,
761 struct spar_vbus_headerinfo
*hdr_info
,
762 struct ultra_vbus_deviceinfo
*info
)
764 int off
= sizeof(struct channel_header
) + hdr_info
->bus_info_offset
;
766 if (hdr_info
->bus_info_offset
== 0)
769 visorchannel_write(chan
, off
, info
, sizeof(*info
));
773 * write_vbus_dev_info() - write the contents of <info> to the struct
774 * spar_vbus_channel_protocol.dev_info[<devix>]
775 * @chan: indentifies the s-Par channel that will be updated
776 * @hdr_info: used to find appropriate channel offset to write data
777 * @info: contains the information to write
778 * @devix: the relative device number (0..n-1) of the device on the bus
780 * Writes device info into the channel memory to be used for diagnostic
783 * Returns no value since this is debug information and not needed for
784 * device functionality.
787 write_vbus_dev_info(struct visorchannel
*chan
,
788 struct spar_vbus_headerinfo
*hdr_info
,
789 struct ultra_vbus_deviceinfo
*info
, unsigned int devix
)
792 (sizeof(struct channel_header
) + hdr_info
->dev_info_offset
) +
793 (hdr_info
->device_info_struct_bytes
* devix
);
795 if (hdr_info
->dev_info_offset
== 0)
798 visorchannel_write(chan
, off
, info
, sizeof(*info
));
801 static void bus_device_info_init(
802 struct ultra_vbus_deviceinfo
*bus_device_info_ptr
,
803 const char *dev_type
, const char *drv_name
)
805 memset(bus_device_info_ptr
, 0, sizeof(struct ultra_vbus_deviceinfo
));
806 snprintf(bus_device_info_ptr
->devtype
,
807 sizeof(bus_device_info_ptr
->devtype
),
808 "%s", (dev_type
) ? dev_type
: "unknownType");
809 snprintf(bus_device_info_ptr
->drvname
,
810 sizeof(bus_device_info_ptr
->drvname
),
811 "%s", (drv_name
) ? drv_name
: "unknownDriver");
812 snprintf(bus_device_info_ptr
->infostrs
,
813 sizeof(bus_device_info_ptr
->infostrs
), "kernel ver. %s",
818 * fix_vbus_dev_info() - for a child device just created on a client bus, fill
819 * in information about the driver that is controlling
820 * this device into the appropriate slot within the
821 * vbus channel of the bus instance
822 * @visordev: struct visor_device for the desired device
825 fix_vbus_dev_info(struct visor_device
*visordev
)
828 struct visor_device
*bdev
;
829 struct visor_driver
*visordrv
;
830 u32 bus_no
= visordev
->chipset_bus_no
;
831 u32 dev_no
= visordev
->chipset_dev_no
;
832 struct ultra_vbus_deviceinfo dev_info
;
833 const char *chan_type_name
= NULL
;
834 struct spar_vbus_headerinfo
*hdr_info
;
836 if (!visordev
->device
.driver
)
839 bdev
= visorbus_get_device_by_id(bus_no
, BUS_ROOT_DEVICE
, NULL
);
842 hdr_info
= (struct spar_vbus_headerinfo
*)bdev
->vbus_hdr_info
;
845 visordrv
= to_visor_driver(visordev
->device
.driver
);
848 * Within the list of device types (by GUID) that the driver
849 * says it supports, find out which one of those types matches
850 * the type of this device, so that we can include the device
853 for (i
= 0; visordrv
->channel_types
[i
].name
; i
++) {
854 if (memcmp(&visordrv
->channel_types
[i
].guid
,
855 &visordev
->channel_type_guid
,
856 sizeof(visordrv
->channel_types
[i
].guid
)) == 0) {
857 chan_type_name
= visordrv
->channel_types
[i
].name
;
862 bus_device_info_init(&dev_info
, chan_type_name
, visordrv
->name
);
863 write_vbus_dev_info(bdev
->visorchannel
, hdr_info
, &dev_info
, dev_no
);
865 write_vbus_chp_info(bdev
->visorchannel
, hdr_info
, &chipset_driverinfo
);
866 write_vbus_bus_info(bdev
->visorchannel
, hdr_info
,
867 &clientbus_driverinfo
);
871 * visordriver_probe_device() - handle new visor device coming online
872 * @xdev: struct device for the visor device being probed
874 * This is called automatically upon adding a visor_device (device_add), or
875 * adding a visor_driver (visorbus_register_visor_driver), but only after
876 * visorbus_match() has returned 1 to indicate a successful match between
879 * If successful, a reference to the device will be held onto via get_device().
881 * Return: 0 if successful, meaning the function driver's probe() function
882 * was successful with this device, otherwise a negative errno
883 * value indicating failure reason
886 visordriver_probe_device(struct device
*xdev
)
889 struct visor_driver
*drv
;
890 struct visor_device
*dev
;
892 drv
= to_visor_driver(xdev
->driver
);
893 dev
= to_visor_device(xdev
);
898 mutex_lock(&dev
->visordriver_callback_lock
);
899 dev
->being_removed
= false;
901 res
= drv
->probe(dev
);
903 /* success: reference kept via unmatched get_device() */
904 get_device(&dev
->device
);
905 fix_vbus_dev_info(dev
);
908 mutex_unlock(&dev
->visordriver_callback_lock
);
913 * visorbus_register_visor_driver() - registers the provided visor driver
914 * for handling one or more visor device
915 * types (channel_types)
916 * @drv: the driver to register
918 * A visor function driver calls this function to register
919 * the driver. The caller MUST fill in the following fields within the
921 * name, version, owner, channel_types, probe, remove
923 * Here's how the whole Linux bus / driver / device model works.
925 * At system start-up, the visorbus kernel module is loaded, which registers
926 * visorbus_type as a bus type, using bus_register().
928 * All kernel modules that support particular device types on a
929 * visorbus bus are loaded. Each of these kernel modules calls
930 * visorbus_register_visor_driver() in their init functions, passing a
931 * visor_driver struct. visorbus_register_visor_driver() in turn calls
932 * register_driver(&visor_driver.driver). This .driver member is
933 * initialized with generic methods (like probe), whose sole responsibility
934 * is to act as a broker for the real methods, which are within the
935 * visor_driver struct. (This is the way the subclass behavior is
936 * implemented, since visor_driver is essentially a subclass of the
937 * generic driver.) Whenever a driver_register() happens, core bus code in
938 * the kernel does (see device_attach() in drivers/base/dd.c):
940 * for each dev associated with the bus (the bus that driver is on) that
941 * does not yet have a driver
942 * if bus.match(dev,newdriver) == yes_matched ** .match specified
943 * ** during bus_register().
944 * newdriver.probe(dev) ** for visor drivers, this will call
945 * ** the generic driver.probe implemented in visorbus.c,
946 * ** which in turn calls the probe specified within the
947 * ** struct visor_driver (which was specified by the
948 * ** actual device driver as part of
949 * ** visorbus_register_visor_driver()).
951 * The above dance also happens when a new device appears.
952 * So the question is, how are devices created within the system?
953 * Basically, just call device_add(dev). See pci_bus_add_devices().
954 * pci_scan_device() shows an example of how to build a device struct. It
955 * returns the newly-created struct to pci_scan_single_device(), who adds it
956 * to the list of devices at PCIBUS.devices. That list of devices is what
957 * is traversed by pci_bus_add_devices().
959 * Return: integer indicating success (zero) or failure (non-zero)
961 int visorbus_register_visor_driver(struct visor_driver
*drv
)
964 return -ENODEV
; /* can't register on a nonexistent bus */
966 drv
->driver
.name
= drv
->name
;
967 drv
->driver
.bus
= &visorbus_type
;
968 drv
->driver
.probe
= visordriver_probe_device
;
969 drv
->driver
.remove
= visordriver_remove_device
;
970 drv
->driver
.owner
= drv
->owner
;
973 * driver_register does this:
974 * bus_add_driver(drv)
975 * ->if (drv.bus) ** (bus_type) **
977 * for each dev with bus type of drv.bus
978 * if (!dev.drv) ** no driver assigned yet **
979 * if (bus.match(dev,drv)) [visorbus_match]
981 * if (!drv.probe(dev)) [visordriver_probe_device]
985 return driver_register(&drv
->driver
);
987 EXPORT_SYMBOL_GPL(visorbus_register_visor_driver
);
990 * create_bus_instance() - create a device instance for the visor bus itself
991 * @dev: struct visor_device indicating the bus instance
993 * Return: 0 for success, otherwise negative errno value indicating reason for
997 create_bus_instance(struct visor_device
*dev
)
999 int id
= dev
->chipset_bus_no
;
1001 struct spar_vbus_headerinfo
*hdr_info
;
1003 POSTCODE_LINUX(BUS_CREATE_ENTRY_PC
, 0, 0, DIAG_SEVERITY_PRINT
);
1005 hdr_info
= kzalloc(sizeof(*hdr_info
), GFP_KERNEL
);
1009 dev_set_name(&dev
->device
, "visorbus%d", id
);
1010 dev
->device
.bus
= &visorbus_type
;
1011 dev
->device
.groups
= visorbus_groups
;
1012 dev
->device
.release
= visorbus_release_busdevice
;
1014 dev
->debugfs_dir
= debugfs_create_dir(dev_name(&dev
->device
),
1015 visorbus_debugfs_dir
);
1016 dev
->debugfs_client_bus_info
=
1017 debugfs_create_file("client_bus_info", 0440,
1018 dev
->debugfs_dir
, dev
,
1019 &client_bus_info_debugfs_fops
);
1021 dev_set_drvdata(&dev
->device
, dev
);
1022 err
= get_vbus_header_info(dev
->visorchannel
, hdr_info
);
1024 goto err_debugfs_dir
;
1026 err
= device_register(&dev
->device
);
1028 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC
, 0, id
,
1030 goto err_debugfs_dir
;
1033 list_add_tail(&dev
->list_all
, &list_all_bus_instances
);
1035 dev
->vbus_hdr_info
= (void *)hdr_info
;
1036 write_vbus_chp_info(dev
->visorchannel
, hdr_info
,
1037 &chipset_driverinfo
);
1038 write_vbus_bus_info(dev
->visorchannel
, hdr_info
,
1039 &clientbus_driverinfo
);
1044 debugfs_remove_recursive(dev
->debugfs_dir
);
1050 * remove_bus_instance() - remove a device instance for the visor bus itself
1051 * @dev: struct visor_device indentifying the bus to remove
1054 remove_bus_instance(struct visor_device
*dev
)
1057 * Note that this will result in the release method for
1058 * dev->dev being called, which will call
1059 * visorbus_release_busdevice(). This has something to do with
1060 * the put_device() done in device_unregister(), but I have never
1061 * successfully been able to trace thru the code to see where/how
1062 * release() gets called. But I know it does.
1064 if (dev
->visorchannel
) {
1065 visorchannel_destroy(dev
->visorchannel
);
1066 dev
->visorchannel
= NULL
;
1068 kfree(dev
->vbus_hdr_info
);
1069 list_del(&dev
->list_all
);
1070 device_unregister(&dev
->device
);
1074 * remove_all_visor_devices() - remove all child visor bus device instances
1077 remove_all_visor_devices(void)
1079 struct list_head
*listentry
, *listtmp
;
1081 list_for_each_safe(listentry
, listtmp
, &list_all_device_instances
) {
1082 struct visor_device
*dev
= list_entry(listentry
,
1083 struct visor_device
,
1085 remove_visor_device(dev
);
1090 chipset_bus_create(struct visor_device
*dev
)
1093 u32 bus_no
= dev
->chipset_bus_no
;
1095 POSTCODE_LINUX(BUS_CREATE_ENTRY_PC
, 0, bus_no
, DIAG_SEVERITY_PRINT
);
1096 err
= create_bus_instance(dev
);
1097 POSTCODE_LINUX(BUS_CREATE_EXIT_PC
, 0, bus_no
, DIAG_SEVERITY_PRINT
);
1100 POSTCODE_LINUX(BUS_CREATE_FAILURE_PC
, 0, bus_no
,
1105 bus_create_response(dev
, err
);
1111 chipset_bus_destroy(struct visor_device
*dev
)
1113 remove_bus_instance(dev
);
1114 bus_destroy_response(dev
, 0);
1118 chipset_device_create(struct visor_device
*dev_info
)
1121 u32 bus_no
= dev_info
->chipset_bus_no
;
1122 u32 dev_no
= dev_info
->chipset_dev_no
;
1124 POSTCODE_LINUX(DEVICE_CREATE_ENTRY_PC
, dev_no
, bus_no
,
1125 DIAG_SEVERITY_PRINT
);
1127 err
= create_visor_device(dev_info
);
1129 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC
, dev_no
, bus_no
,
1134 POSTCODE_LINUX(DEVICE_CREATE_SUCCESS_PC
, dev_no
, bus_no
,
1135 DIAG_SEVERITY_PRINT
);
1137 device_create_response(dev_info
, err
);
1143 chipset_device_destroy(struct visor_device
*dev_info
)
1145 remove_visor_device(dev_info
);
1147 device_destroy_response(dev_info
, 0);
1151 * pause_state_change_complete() - the callback function to be called by a
1152 * visorbus function driver when a
1153 * pending "pause device" operation has
1155 * @dev: struct visor_device identifying the paused device
1156 * @status: 0 iff the pause state change completed successfully, otherwise
1157 * a negative errno value indicating the reason for failure
1160 pause_state_change_complete(struct visor_device
*dev
, int status
)
1165 dev
->pausing
= false;
1167 device_pause_response(dev
, status
);
1171 * resume_state_change_complete() - the callback function to be called by a
1172 * visorbus function driver when a
1173 * pending "resume device" operation has
1175 * @dev: struct visor_device identifying the resumed device
1176 * @status: 0 iff the resume state change completed successfully, otherwise
1177 * a negative errno value indicating the reason for failure
1180 resume_state_change_complete(struct visor_device
*dev
, int status
)
1185 dev
->resuming
= false;
1188 * Notify the chipset driver that the resume is complete,
1189 * which will presumably want to send some sort of response to
1192 device_resume_response(dev
, status
);
1196 * initiate_chipset_device_pause_resume() - start a pause or resume operation
1197 * for a visor device
1198 * @dev: struct visor_device identifying the device being paused or resumed
1199 * @is_pause: true to indicate pause operation, false to indicate resume
1201 * Tell the subordinate function driver for a specific device to pause
1202 * or resume that device. Success/failure result is returned asynchronously
1203 * via a callback function; see pause_state_change_complete() and
1204 * resume_state_change_complete().
1207 initiate_chipset_device_pause_resume(struct visor_device
*dev
, bool is_pause
)
1210 struct visor_driver
*drv
= NULL
;
1212 drv
= to_visor_driver(dev
->device
.driver
);
1216 if (dev
->pausing
|| dev
->resuming
)
1223 dev
->pausing
= true;
1224 err
= drv
->pause(dev
, pause_state_change_complete
);
1226 /* The vbus_dev_info structure in the channel was been
1227 * cleared, make sure it is valid.
1229 fix_vbus_dev_info(dev
);
1233 dev
->resuming
= true;
1234 err
= drv
->resume(dev
, resume_state_change_complete
);
1241 * chipset_device_pause() - start a pause operation for a visor device
1242 * @dev_info: struct visor_device identifying the device being paused
1244 * Tell the subordinate function driver for a specific device to pause
1245 * that device. Success/failure result is returned asynchronously
1246 * via a callback function; see pause_state_change_complete().
1249 chipset_device_pause(struct visor_device
*dev_info
)
1253 err
= initiate_chipset_device_pause_resume(dev_info
, true);
1256 dev_info
->pausing
= false;
1264 * chipset_device_resume() - start a resume operation for a visor device
1265 * @dev_info: struct visor_device identifying the device being resumed
1267 * Tell the subordinate function driver for a specific device to resume
1268 * that device. Success/failure result is returned asynchronously
1269 * via a callback function; see resume_state_change_complete().
1272 chipset_device_resume(struct visor_device
*dev_info
)
1276 err
= initiate_chipset_device_pause_resume(dev_info
, false);
1279 dev_info
->resuming
= false;
1291 POSTCODE_LINUX(DRIVER_ENTRY_PC
, 0, 0, DIAG_SEVERITY_PRINT
);
1293 visorbus_debugfs_dir
= debugfs_create_dir("visorbus", NULL
);
1294 if (!visorbus_debugfs_dir
)
1297 bus_device_info_init(&clientbus_driverinfo
, "clientbus", "visorbus");
1299 err
= bus_register(&visorbus_type
);
1301 POSTCODE_LINUX(BUS_CREATE_ENTRY_PC
, 0, 0, DIAG_SEVERITY_ERR
);
1306 bus_device_info_init(&chipset_driverinfo
, "chipset", "visorchipset");
1311 POSTCODE_LINUX(CHIPSET_INIT_FAILURE_PC
, 0, err
, DIAG_SEVERITY_ERR
);
1318 struct list_head
*listentry
, *listtmp
;
1320 remove_all_visor_devices();
1322 list_for_each_safe(listentry
, listtmp
, &list_all_bus_instances
) {
1323 struct visor_device
*dev
= list_entry(listentry
,
1324 struct visor_device
,
1326 remove_bus_instance(dev
);
1329 bus_unregister(&visorbus_type
);
1330 initialized
= false;
1331 debugfs_remove_recursive(visorbus_debugfs_dir
);