]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/staging/unisys/visorbus/visorbus_main.c
staging: unisys: visorbus: Remove gotos in visorbus_match
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / unisys / visorbus / visorbus_main.c
CommitLineData
3703987c
EA
1/* visorbus_main.c
2 *
6f14cc18 3 * Copyright � 2010 - 2015 UNISYS CORPORATION
3703987c
EA
4 * All rights reserved.
5 *
6f14cc18
BR
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.
3703987c
EA
9 *
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
14 * details.
15 */
16
17#include <linux/uuid.h>
18
4b78000e 19#include "visorbus.h"
c79b28f7 20#include "visorbus_private.h"
4b78000e 21#include "version.h"
3703987c
EA
22#include "periodic_work.h"
23#include "vbuschannel.h"
24#include "guestlinuxdebug.h"
0f41c727 25#include "vmcallinterface.h"
4b78000e 26
c79b28f7
PB
27#define MYDRVNAME "visorbus"
28
4b78000e 29/* module parameters */
f6758e79
DF
30static int visorbus_debug;
31static int visorbus_forcematch;
32static int visorbus_forcenomatch;
f6758e79 33static int visorbus_debugref;
4b78000e
PB
34#define SERIALLOOPBACKCHANADDR (100 * 1024 * 1024)
35
3703987c
EA
36#define CURRENT_FILE_PC VISOR_BUS_PC_visorbus_main_c
37#define POLLJIFFIES_TESTWORK 100
38#define POLLJIFFIES_NORMALCHANNEL 10
39
6155a3cf
BR
40static int busreg_rc = -ENODEV; /* stores the result from bus registration */
41
3703987c
EA
42static int visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env);
43static int visorbus_match(struct device *xdev, struct device_driver *xdrv);
44static void fix_vbus_dev_info(struct visor_device *visordev);
45
68b04f1f
DZ
46/* BUS type attributes
47 *
48 * define & implement display of bus attributes under
49 * /sys/bus/visorbus.
50 *
51 */
52
53static ssize_t version_show(struct bus_type *bus, char *buf)
54{
55 return snprintf(buf, PAGE_SIZE, "%s\n", VERSION);
56}
57
58static BUS_ATTR_RO(version);
59
60static struct attribute *visorbus_bus_attrs[] = {
61 &bus_attr_version.attr,
62 NULL,
63};
64
65static const struct attribute_group visorbus_bus_group = {
66 .attrs = visorbus_bus_attrs,
67};
68
f6758e79 69static const struct attribute_group *visorbus_bus_groups[] = {
68b04f1f
DZ
70 &visorbus_bus_group,
71 NULL,
72};
73
59fd2c8b
PB
74/*
75 * DEVICE type attributes
76 *
77 * The modalias file will contain the guid of the device.
78 */
79static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
80 char *buf)
81{
82 struct visor_device *vdev;
83 uuid_le guid;
84
85 vdev = to_visor_device(dev);
86 guid = visorchannel_get_uuid(vdev->visorchannel);
87 return snprintf(buf, PAGE_SIZE, "visorbus:%pUl\n", &guid);
88}
89static DEVICE_ATTR_RO(modalias);
90
91static struct attribute *visorbus_dev_attrs[] = {
92 &dev_attr_modalias.attr,
93 NULL,
94};
95
96/* sysfs example for bridge-only sysfs files using device_type's */
97static const struct attribute_group visorbus_dev_group = {
98 .attrs = visorbus_dev_attrs,
99};
100
cf7281c9 101static const struct attribute_group *visorbus_dev_groups[] = {
59fd2c8b
PB
102 &visorbus_dev_group,
103 NULL,
104};
105
3703987c
EA
106/** This describes the TYPE of bus.
107 * (Don't confuse this with an INSTANCE of the bus.)
108 */
1fb3016e 109struct bus_type visorbus_type = {
3703987c
EA
110 .name = "visorbus",
111 .match = visorbus_match,
112 .uevent = visorbus_uevent,
59fd2c8b 113 .dev_groups = visorbus_dev_groups,
68b04f1f 114 .bus_groups = visorbus_bus_groups,
3703987c
EA
115};
116
117static struct delayed_work periodic_work;
118
119/* YES, we need 2 workqueues.
120 * The reason is, workitems on the test queue may need to cancel
121 * workitems on the other queue. You will be in for trouble if you try to
122 * do this with workitems queued on the same workqueue.
123 */
124static struct workqueue_struct *periodic_test_workqueue;
125static struct workqueue_struct *periodic_dev_workqueue;
126static long long bus_count; /** number of bus instances */
3703987c
EA
127 /** ever-increasing */
128
d32517e3
DZ
129static void chipset_bus_create(struct visor_device *bus_info);
130static void chipset_bus_destroy(struct visor_device *bus_info);
a298bc0b
DZ
131static void chipset_device_create(struct visor_device *dev_info);
132static void chipset_device_destroy(struct visor_device *dev_info);
133static void chipset_device_pause(struct visor_device *dev_info);
134static void chipset_device_resume(struct visor_device *dev_info);
3703987c
EA
135
136/** These functions are implemented herein, and are called by the chipset
137 * driver to notify us about specific events.
138 */
139static struct visorchipset_busdev_notifiers chipset_notifiers = {
140 .bus_create = chipset_bus_create,
141 .bus_destroy = chipset_bus_destroy,
142 .device_create = chipset_device_create,
143 .device_destroy = chipset_device_destroy,
144 .device_pause = chipset_device_pause,
145 .device_resume = chipset_device_resume,
146};
147
148/** These functions are implemented in the chipset driver, and we call them
149 * herein when we want to acknowledge a specific event.
150 */
151static struct visorchipset_busdev_responders chipset_responders;
152
153/* filled in with info about parent chipset driver when we register with it */
154static struct ultra_vbus_deviceinfo chipset_driverinfo;
155/* filled in with info about this driver, wrt it servicing client busses */
156static struct ultra_vbus_deviceinfo clientbus_driverinfo;
157
343506bf 158/** list of visor_device structs, linked via .list_all */
3703987c
EA
159static LIST_HEAD(list_all_bus_instances);
160/** list of visor_device structs, linked via .list_all */
161static LIST_HEAD(list_all_device_instances);
162
163static int
164visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env)
165{
59fd2c8b
PB
166 struct visor_device *dev;
167 uuid_le guid;
168
169 dev = to_visor_device(xdev);
170 guid = visorchannel_get_uuid(dev->visorchannel);
171
172 if (add_uevent_var(env, "MODALIAS=visorbus:%pUl", &guid))
3703987c
EA
173 return -ENOMEM;
174 return 0;
175}
176
177/* This is called automatically upon adding a visor_device (device_add), or
178 * adding a visor_driver (visorbus_register_visor_driver), and returns 1 iff the
179 * provided driver can control the specified device.
180 */
181static int
182visorbus_match(struct device *xdev, struct device_driver *xdrv)
183{
184 uuid_le channel_type;
3703987c
EA
185 int i;
186 struct visor_device *dev;
187 struct visor_driver *drv;
188
189 dev = to_visor_device(xdev);
190 drv = to_visor_driver(xdrv);
191 channel_type = visorchannel_get_uuid(dev->visorchannel);
3703987c 192
8e33f48c
DK
193 if (visorbus_forcematch)
194 return 1;
195 if (visorbus_forcenomatch)
196 return 0;
3703987c 197 if (!drv->channel_types)
8e33f48c
DK
198 return 0;
199
3703987c
EA
200 for (i = 0;
201 (uuid_le_cmp(drv->channel_types[i].guid, NULL_UUID_LE) != 0) ||
202 (drv->channel_types[i].name);
203 i++)
204 if (uuid_le_cmp(drv->channel_types[i].guid,
8e33f48c
DK
205 channel_type) == 0)
206 return i + 1;
207
208 return 0;
3703987c
EA
209}
210
211/** This is called when device_unregister() is called for the bus device
212 * instance, after all other tasks involved with destroying the device
213 * are complete.
214 */
215static void
216visorbus_release_busdevice(struct device *xdev)
217{
343506bf 218 struct visor_device *dev = dev_get_drvdata(xdev);
3703987c 219
343506bf 220 kfree(dev);
3703987c
EA
221}
222
223/** This is called when device_unregister() is called for each child
224 * device instance.
225 */
226static void
227visorbus_release_device(struct device *xdev)
228{
229 struct visor_device *dev = to_visor_device(xdev);
230
231 if (dev->periodic_work) {
232 visor_periodic_work_destroy(dev->periodic_work);
233 dev->periodic_work = NULL;
234 }
235 if (dev->visorchannel) {
236 visorchannel_destroy(dev->visorchannel);
237 dev->visorchannel = NULL;
238 }
239 kfree(dev);
240}
241
826b6a0f
PB
242/* begin implementation of specific channel attributes to appear under
243* /sys/bus/visorbus<x>/dev<y>/channel
244*/
79573162
DZ
245static ssize_t physaddr_show(struct device *dev, struct device_attribute *attr,
246 char *buf)
826b6a0f 247{
79573162
DZ
248 struct visor_device *vdev = to_visor_device(dev);
249
250 if (!vdev->visorchannel)
826b6a0f
PB
251 return 0;
252 return snprintf(buf, PAGE_SIZE, "0x%Lx\n",
79573162 253 visorchannel_get_physaddr(vdev->visorchannel));
826b6a0f
PB
254}
255
79573162
DZ
256static ssize_t nbytes_show(struct device *dev, struct device_attribute *attr,
257 char *buf)
826b6a0f 258{
79573162
DZ
259 struct visor_device *vdev = to_visor_device(dev);
260
261 if (!vdev->visorchannel)
826b6a0f
PB
262 return 0;
263 return snprintf(buf, PAGE_SIZE, "0x%lx\n",
79573162 264 visorchannel_get_nbytes(vdev->visorchannel));
826b6a0f
PB
265}
266
79573162
DZ
267static ssize_t clientpartition_show(struct device *dev,
268 struct device_attribute *attr, char *buf)
269{
270 struct visor_device *vdev = to_visor_device(dev);
271
272 if (!vdev->visorchannel)
826b6a0f
PB
273 return 0;
274 return snprintf(buf, PAGE_SIZE, "0x%Lx\n",
79573162 275 visorchannel_get_clientpartition(vdev->visorchannel));
826b6a0f
PB
276}
277
79573162
DZ
278static ssize_t typeguid_show(struct device *dev, struct device_attribute *attr,
279 char *buf)
826b6a0f 280{
79573162 281 struct visor_device *vdev = to_visor_device(dev);
826b6a0f
PB
282 char s[99];
283
79573162 284 if (!vdev->visorchannel)
826b6a0f
PB
285 return 0;
286 return snprintf(buf, PAGE_SIZE, "%s\n",
79573162 287 visorchannel_id(vdev->visorchannel, s));
826b6a0f
PB
288}
289
79573162
DZ
290static ssize_t zoneguid_show(struct device *dev, struct device_attribute *attr,
291 char *buf)
826b6a0f 292{
79573162 293 struct visor_device *vdev = to_visor_device(dev);
826b6a0f
PB
294 char s[99];
295
79573162 296 if (!vdev->visorchannel)
826b6a0f
PB
297 return 0;
298 return snprintf(buf, PAGE_SIZE, "%s\n",
79573162 299 visorchannel_zoneid(vdev->visorchannel, s));
826b6a0f
PB
300}
301
79573162
DZ
302static ssize_t typename_show(struct device *dev, struct device_attribute *attr,
303 char *buf)
826b6a0f 304{
79573162 305 struct visor_device *vdev = to_visor_device(dev);
826b6a0f 306 int i = 0;
79573162
DZ
307 struct bus_type *xbus = dev->bus;
308 struct device_driver *xdrv = dev->driver;
826b6a0f
PB
309 struct visor_driver *drv = NULL;
310
79573162 311 if (!vdev->visorchannel || !xbus || !xdrv)
826b6a0f 312 return 0;
79573162 313 i = xbus->match(dev, xdrv);
826b6a0f
PB
314 if (!i)
315 return 0;
316 drv = to_visor_driver(xdrv);
317 return snprintf(buf, PAGE_SIZE, "%s\n", drv->channel_types[i - 1].name);
318}
319
79573162
DZ
320static DEVICE_ATTR_RO(physaddr);
321static DEVICE_ATTR_RO(nbytes);
322static DEVICE_ATTR_RO(clientpartition);
323static DEVICE_ATTR_RO(typeguid);
324static DEVICE_ATTR_RO(zoneguid);
325static DEVICE_ATTR_RO(typename);
79573162
DZ
326
327static struct attribute *channel_attrs[] = {
328 &dev_attr_physaddr.attr,
329 &dev_attr_nbytes.attr,
330 &dev_attr_clientpartition.attr,
331 &dev_attr_typeguid.attr,
332 &dev_attr_zoneguid.attr,
333 &dev_attr_typename.attr,
fd012d0d 334 NULL
826b6a0f
PB
335};
336
79573162
DZ
337static struct attribute_group channel_attr_grp = {
338 .name = "channel",
339 .attrs = channel_attrs,
826b6a0f
PB
340};
341
59fd2c8b 342static const struct attribute_group *visorbus_channel_groups[] = {
79573162
DZ
343 &channel_attr_grp,
344 NULL
826b6a0f
PB
345};
346
79573162 347/* end implementation of specific channel attributes */
826b6a0f 348
3703987c
EA
349/* BUS instance attributes
350 *
351 * define & implement display of bus attributes under
352 * /sys/bus/visorbus/busses/visorbus<n>.
353 *
354 * This is a bit hoaky because the kernel does not yet have the infrastructure
355 * to separate bus INSTANCE attributes from bus TYPE attributes...
356 * so we roll our own. See businst.c / businst.h.
357 *
358 */
359
d181dd03
DZ
360static ssize_t partition_handle_show(struct device *dev,
361 struct device_attribute *attr,
362 char *buf) {
5ecbd5d4
DZ
363 struct visor_device *vdev = to_visor_device(dev);
364 u64 handle = visorchannel_get_clientpartition(vdev->visorchannel);
3703987c 365
5ecbd5d4 366 return snprintf(buf, PAGE_SIZE, "0x%Lx\n", handle);
3703987c
EA
367}
368
d181dd03
DZ
369static ssize_t partition_guid_show(struct device *dev,
370 struct device_attribute *attr,
371 char *buf) {
5ecbd5d4 372 struct visor_device *vdev = to_visor_device(dev);
3703987c 373
5ecbd5d4 374 return snprintf(buf, PAGE_SIZE, "{%pUb}\n", &vdev->partition_uuid);
3703987c
EA
375}
376
d181dd03
DZ
377static ssize_t partition_name_show(struct device *dev,
378 struct device_attribute *attr,
379 char *buf) {
5ecbd5d4 380 struct visor_device *vdev = to_visor_device(dev);
3703987c 381
5ecbd5d4 382 return snprintf(buf, PAGE_SIZE, "%s\n", vdev->name);
3703987c
EA
383}
384
d181dd03
DZ
385static ssize_t channel_addr_show(struct device *dev,
386 struct device_attribute *attr,
387 char *buf) {
5ecbd5d4
DZ
388 struct visor_device *vdev = to_visor_device(dev);
389 u64 addr = visorchannel_get_physaddr(vdev->visorchannel);
3703987c 390
5ecbd5d4 391 return snprintf(buf, PAGE_SIZE, "0x%Lx\n", addr);
3703987c
EA
392}
393
d181dd03
DZ
394static ssize_t channel_bytes_show(struct device *dev,
395 struct device_attribute *attr,
396 char *buf) {
5ecbd5d4
DZ
397 struct visor_device *vdev = to_visor_device(dev);
398 u64 nbytes = visorchannel_get_nbytes(vdev->visorchannel);
3703987c 399
5ecbd5d4 400 return snprintf(buf, PAGE_SIZE, "0x%Lx\n", nbytes);
3703987c
EA
401}
402
d181dd03
DZ
403static ssize_t channel_id_show(struct device *dev,
404 struct device_attribute *attr,
405 char *buf) {
5ecbd5d4 406 struct visor_device *vdev = to_visor_device(dev);
3703987c
EA
407 int len = 0;
408
5ecbd5d4
DZ
409 if (vdev->visorchannel) {
410 visorchannel_id(vdev->visorchannel, buf);
3703987c
EA
411 len = strlen(buf);
412 buf[len++] = '\n';
413 }
414 return len;
415}
416
d181dd03
DZ
417static ssize_t client_bus_info_show(struct device *dev,
418 struct device_attribute *attr,
419 char *buf) {
5ecbd5d4
DZ
420 struct visor_device *vdev = to_visor_device(dev);
421 struct visorchannel *channel = vdev->visorchannel;
422
3703987c
EA
423 int i, x, remain = PAGE_SIZE;
424 unsigned long off;
425 char *p = buf;
426 u8 *partition_name;
427 struct ultra_vbus_deviceinfo dev_info;
428
429 partition_name = "";
5ecbd5d4
DZ
430 if (channel) {
431 if (vdev->name)
432 partition_name = vdev->name;
3703987c 433 x = snprintf(p, remain,
65bd6e46 434 "Client device / client driver info for %s partition (vbus #%d):\n",
5ecbd5d4 435 partition_name, vdev->chipset_dev_no);
3703987c
EA
436 p += x;
437 remain -= x;
5ecbd5d4 438 x = visorchannel_read(channel,
3703987c
EA
439 offsetof(struct
440 spar_vbus_channel_protocol,
441 chp_info),
442 &dev_info, sizeof(dev_info));
443 if (x >= 0) {
444 x = vbuschannel_devinfo_to_string(&dev_info, p,
445 remain, -1);
446 p += x;
447 remain -= x;
448 }
5ecbd5d4 449 x = visorchannel_read(channel,
3703987c
EA
450 offsetof(struct
451 spar_vbus_channel_protocol,
452 bus_info),
453 &dev_info, sizeof(dev_info));
454 if (x >= 0) {
455 x = vbuschannel_devinfo_to_string(&dev_info, p,
456 remain, -1);
457 p += x;
458 remain -= x;
459 }
460 off = offsetof(struct spar_vbus_channel_protocol, dev_info);
461 i = 0;
462 while (off + sizeof(dev_info) <=
5ecbd5d4
DZ
463 visorchannel_get_nbytes(channel)) {
464 x = visorchannel_read(channel,
3703987c
EA
465 off, &dev_info, sizeof(dev_info));
466 if (x >= 0) {
467 x = vbuschannel_devinfo_to_string
468 (&dev_info, p, remain, i);
469 p += x;
470 remain -= x;
471 }
472 off += sizeof(dev_info);
473 i++;
474 }
475 }
476 return PAGE_SIZE - remain;
477}
478
d181dd03
DZ
479static DEVICE_ATTR_RO(partition_handle);
480static DEVICE_ATTR_RO(partition_guid);
481static DEVICE_ATTR_RO(partition_name);
482static DEVICE_ATTR_RO(channel_addr);
483static DEVICE_ATTR_RO(channel_bytes);
484static DEVICE_ATTR_RO(channel_id);
485static DEVICE_ATTR_RO(client_bus_info);
486
487static struct attribute *dev_attrs[] = {
488 &dev_attr_partition_handle.attr,
489 &dev_attr_partition_guid.attr,
490 &dev_attr_partition_name.attr,
491 &dev_attr_channel_addr.attr,
492 &dev_attr_channel_bytes.attr,
493 &dev_attr_channel_id.attr,
494 &dev_attr_client_bus_info.attr,
495 NULL
496};
3703987c 497
d181dd03
DZ
498static struct attribute_group dev_attr_grp = {
499 .attrs = dev_attrs,
500};
3703987c 501
d181dd03
DZ
502static const struct attribute_group *visorbus_groups[] = {
503 &dev_attr_grp,
504 NULL
505};
3703987c
EA
506
507/* DRIVER attributes
508 *
509 * define & implement display of driver attributes under
510 * /sys/bus/visorbus/drivers/<drivername>.
511 *
512 */
513
514static ssize_t
515DRIVER_ATTR_version(struct device_driver *xdrv, char *buf)
516{
517 struct visor_driver *drv = to_visor_driver(xdrv);
518
519 return snprintf(buf, PAGE_SIZE, "%s\n", drv->version);
520}
521
522static int
523register_driver_attributes(struct visor_driver *drv)
524{
3703987c
EA
525 struct driver_attribute version =
526 __ATTR(version, S_IRUGO, DRIVER_ATTR_version, NULL);
527 drv->version_attr = version;
2cda64cf 528 return driver_create_file(&drv->driver, &drv->version_attr);
3703987c
EA
529}
530
531static void
532unregister_driver_attributes(struct visor_driver *drv)
533{
534 driver_remove_file(&drv->driver, &drv->version_attr);
535}
536
3703987c
EA
537static void
538dev_periodic_work(void *xdev)
539{
0df4e3e9 540 struct visor_device *dev = xdev;
3703987c
EA
541 struct visor_driver *drv = to_visor_driver(dev->device.driver);
542
543 down(&dev->visordriver_callback_lock);
544 if (drv->channel_interrupt)
545 drv->channel_interrupt(dev);
546 up(&dev->visordriver_callback_lock);
547 if (!visor_periodic_work_nextperiod(dev->periodic_work))
548 put_device(&dev->device);
549}
550
551static void
552dev_start_periodic_work(struct visor_device *dev)
553{
554 if (dev->being_removed)
555 return;
556 /* now up by at least 2 */
557 get_device(&dev->device);
558 if (!visor_periodic_work_start(dev->periodic_work))
559 put_device(&dev->device);
560}
561
562static void
563dev_stop_periodic_work(struct visor_device *dev)
564{
565 if (visor_periodic_work_stop(dev->periodic_work))
566 put_device(&dev->device);
567}
568
569/** This is called automatically upon adding a visor_device (device_add), or
570 * adding a visor_driver (visorbus_register_visor_driver), but only after
571 * visorbus_match has returned 1 to indicate a successful match between
572 * driver and device.
573 */
574static int
575visordriver_probe_device(struct device *xdev)
576{
4000622e 577 int res;
3703987c
EA
578 struct visor_driver *drv;
579 struct visor_device *dev;
580
581 drv = to_visor_driver(xdev->driver);
582 dev = to_visor_device(xdev);
4000622e
DK
583
584 if (!drv->probe)
585 return -ENODEV;
586
3703987c 587 down(&dev->visordriver_callback_lock);
779d0752 588 dev->being_removed = false;
4000622e
DK
589
590 res = drv->probe(dev);
591 if (res >= 0) {
592 /* success: reference kept via unmatched get_device() */
593 get_device(&dev->device);
594 fix_vbus_dev_info(dev);
3703987c 595 }
3703987c 596
3703987c 597 up(&dev->visordriver_callback_lock);
4000622e 598 return res;
3703987c
EA
599}
600
601/** This is called when device_unregister() is called for each child device
602 * instance, to notify the appropriate visorbus_driver that the device is
603 * going away, and to decrease the reference count of the device.
604 */
605static int
606visordriver_remove_device(struct device *xdev)
607{
3703987c
EA
608 struct visor_device *dev;
609 struct visor_driver *drv;
610
611 dev = to_visor_device(xdev);
612 drv = to_visor_driver(xdev->driver);
613 down(&dev->visordriver_callback_lock);
779d0752 614 dev->being_removed = true;
3703987c
EA
615 /*
616 * ensure that the dev->being_removed flag is set before we start the
617 * actual removal
618 */
619 wmb();
620 if (drv) {
621 if (drv->remove)
622 drv->remove(dev);
623 }
624 up(&dev->visordriver_callback_lock);
625 dev_stop_periodic_work(dev);
3703987c
EA
626
627 put_device(&dev->device);
628
df7f46e8 629 return 0;
3703987c
EA
630}
631
632/** A particular type of visor driver calls this function to register
633 * the driver. The caller MUST fill in the following fields within the
634 * #drv structure:
635 * name, version, owner, channel_types, probe, remove
636 *
637 * Here's how the whole Linux bus / driver / device model works.
638 *
639 * At system start-up, the visorbus kernel module is loaded, which registers
640 * visorbus_type as a bus type, using bus_register().
641 *
642 * All kernel modules that support particular device types on a
643 * visorbus bus are loaded. Each of these kernel modules calls
644 * visorbus_register_visor_driver() in their init functions, passing a
645 * visor_driver struct. visorbus_register_visor_driver() in turn calls
646 * register_driver(&visor_driver.driver). This .driver member is
647 * initialized with generic methods (like probe), whose sole responsibility
648 * is to act as a broker for the real methods, which are within the
649 * visor_driver struct. (This is the way the subclass behavior is
650 * implemented, since visor_driver is essentially a subclass of the
651 * generic driver.) Whenever a driver_register() happens, core bus code in
652 * the kernel does (see device_attach() in drivers/base/dd.c):
653 *
654 * for each dev associated with the bus (the bus that driver is on) that
655 * does not yet have a driver
656 * if bus.match(dev,newdriver) == yes_matched ** .match specified
657 * ** during bus_register().
658 * newdriver.probe(dev) ** for visor drivers, this will call
659 * ** the generic driver.probe implemented in visorbus.c,
660 * ** which in turn calls the probe specified within the
661 * ** struct visor_driver (which was specified by the
662 * ** actual device driver as part of
663 * ** visorbus_register_visor_driver()).
664 *
665 * The above dance also happens when a new device appears.
666 * So the question is, how are devices created within the system?
667 * Basically, just call device_add(dev). See pci_bus_add_devices().
668 * pci_scan_device() shows an example of how to build a device struct. It
669 * returns the newly-created struct to pci_scan_single_device(), who adds it
670 * to the list of devices at PCIBUS.devices. That list of devices is what
671 * is traversed by pci_bus_add_devices().
672 *
673 */
674int visorbus_register_visor_driver(struct visor_driver *drv)
675{
676 int rc = 0;
677
6155a3cf
BR
678 if (busreg_rc < 0)
679 return -ENODEV; /*can't register on a nonexistent bus*/
680
3703987c
EA
681 drv->driver.name = drv->name;
682 drv->driver.bus = &visorbus_type;
683 drv->driver.probe = visordriver_probe_device;
684 drv->driver.remove = visordriver_remove_device;
685 drv->driver.owner = drv->owner;
686
687 /* driver_register does this:
688 * bus_add_driver(drv)
689 * ->if (drv.bus) ** (bus_type) **
690 * driver_attach(drv)
691 * for each dev with bus type of drv.bus
692 * if (!dev.drv) ** no driver assigned yet **
693 * if (bus.match(dev,drv)) [visorbus_match]
694 * dev.drv = drv
695 * if (!drv.probe(dev)) [visordriver_probe_device]
696 * dev.drv = NULL
697 */
698
699 rc = driver_register(&drv->driver);
700 if (rc < 0)
701 return rc;
702 rc = register_driver_attributes(drv);
418627dd
DK
703 if (rc < 0)
704 driver_unregister(&drv->driver);
3703987c
EA
705 return rc;
706}
707EXPORT_SYMBOL_GPL(visorbus_register_visor_driver);
708
709/** A particular type of visor driver calls this function to unregister
710 * the driver, i.e., within its module_exit function.
711 */
712void
713visorbus_unregister_visor_driver(struct visor_driver *drv)
714{
715 unregister_driver_attributes(drv);
716 driver_unregister(&drv->driver);
717}
718EXPORT_SYMBOL_GPL(visorbus_unregister_visor_driver);
719
720int
721visorbus_read_channel(struct visor_device *dev, unsigned long offset,
722 void *dest, unsigned long nbytes)
723{
724 return visorchannel_read(dev->visorchannel, offset, dest, nbytes);
725}
726EXPORT_SYMBOL_GPL(visorbus_read_channel);
727
728int
729visorbus_write_channel(struct visor_device *dev, unsigned long offset,
730 void *src, unsigned long nbytes)
731{
732 return visorchannel_write(dev->visorchannel, offset, src, nbytes);
733}
734EXPORT_SYMBOL_GPL(visorbus_write_channel);
735
736int
737visorbus_clear_channel(struct visor_device *dev, unsigned long offset, u8 ch,
738 unsigned long nbytes)
739{
740 return visorchannel_clear(dev->visorchannel, offset, ch, nbytes);
741}
742EXPORT_SYMBOL_GPL(visorbus_clear_channel);
743
3703987c
EA
744/** We don't really have a real interrupt, so for now we just call the
745 * interrupt function periodically...
746 */
747void
748visorbus_enable_channel_interrupts(struct visor_device *dev)
749{
750 dev_start_periodic_work(dev);
751}
752EXPORT_SYMBOL_GPL(visorbus_enable_channel_interrupts);
753
754void
755visorbus_disable_channel_interrupts(struct visor_device *dev)
756{
757 dev_stop_periodic_work(dev);
758}
759EXPORT_SYMBOL_GPL(visorbus_disable_channel_interrupts);
760
761/** This is how everything starts from the device end.
762 * This function is called when a channel first appears via a ControlVM
763 * message. In response, this function allocates a visor_device to
764 * correspond to the new channel, and attempts to connect it the appropriate
765 * driver. If the appropriate driver is found, the visor_driver.probe()
766 * function for that driver will be called, and will be passed the new
767 * visor_device that we just created.
768 *
769 * It's ok if the appropriate driver is not yet loaded, because in that case
770 * the new device struct will just stick around in the bus' list of devices.
771 * When the appropriate driver calls visorbus_register_visor_driver(), the
772 * visor_driver.probe() for the new driver will be called with the new
773 * device.
774 */
775static int
a298bc0b 776create_visor_device(struct visor_device *dev)
3703987c 777{
f99d3308 778 int rc;
a298bc0b
DZ
779 u32 chipset_bus_no = dev->chipset_bus_no;
780 u32 chipset_dev_no = dev->chipset_dev_no;
3703987c
EA
781
782 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, chipset_dev_no, chipset_bus_no,
783 POSTCODE_SEVERITY_INFO);
3703987c 784
3703987c
EA
785 sema_init(&dev->visordriver_callback_lock, 1); /* unlocked */
786 dev->device.bus = &visorbus_type;
59fd2c8b 787 dev->device.groups = visorbus_channel_groups;
3703987c
EA
788 device_initialize(&dev->device);
789 dev->device.release = visorbus_release_device;
790 /* keep a reference just for us (now 2) */
791 get_device(&dev->device);
3703987c
EA
792 dev->periodic_work =
793 visor_periodic_work_create(POLLJIFFIES_NORMALCHANNEL,
794 periodic_dev_workqueue,
795 dev_periodic_work,
796 dev, dev_name(&dev->device));
797 if (!dev->periodic_work) {
798 POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, chipset_dev_no,
799 DIAG_SEVERITY_ERR);
f99d3308 800 rc = -EINVAL;
3703987c
EA
801 goto away;
802 }
803
804 /* bus_id must be a unique name with respect to this bus TYPE
805 * (NOT bus instance). That's why we need to include the bus
806 * number within the name.
807 */
b4b598fd 808 dev_set_name(&dev->device, "vbus%u:dev%u",
3703987c
EA
809 chipset_bus_no, chipset_dev_no);
810
811 /* device_add does this:
812 * bus_add_device(dev)
813 * ->device_attach(dev)
814 * ->for each driver drv registered on the bus that dev is on
815 * if (dev.drv) ** device already has a driver **
816 * ** not sure we could ever get here... **
817 * else
818 * if (bus.match(dev,drv)) [visorbus_match]
819 * dev.drv = drv
820 * if (!drv.probe(dev)) [visordriver_probe_device]
821 * dev.drv = NULL
822 *
823 * Note that device_add does NOT fail if no driver failed to
824 * claim the device. The device will be linked onto
825 * bus_type.klist_devices regardless (use bus_for_each_dev).
826 */
827 rc = device_add(&dev->device);
828 if (rc < 0) {
829 POSTCODE_LINUX_3(DEVICE_ADD_PC, chipset_bus_no,
830 DIAG_SEVERITY_ERR);
831 goto away;
832 }
833
a298bc0b
DZ
834 list_add_tail(&dev->list_all, &list_all_device_instances);
835 return 0;
3703987c
EA
836
837away:
a298bc0b 838 put_device(&dev->device);
3703987c
EA
839 return rc;
840}
841
842static void
843remove_visor_device(struct visor_device *dev)
844{
845 list_del(&dev->list_all);
3703987c
EA
846 put_device(&dev->device);
847 device_unregister(&dev->device);
848}
849
3703987c
EA
850static int
851get_vbus_header_info(struct visorchannel *chan,
852 struct spar_vbus_headerinfo *hdr_info)
853{
3703987c 854 if (!SPAR_VBUS_CHANNEL_OK_CLIENT(visorchannel_get_header(chan)))
f748f64f
BR
855 return -EINVAL;
856
3703987c
EA
857 if (visorchannel_read(chan, sizeof(struct channel_header), hdr_info,
858 sizeof(*hdr_info)) < 0) {
f748f64f 859 return -EIO;
3703987c
EA
860 }
861 if (hdr_info->struct_bytes < sizeof(struct spar_vbus_headerinfo))
f748f64f
BR
862 return -EINVAL;
863
3703987c
EA
864 if (hdr_info->device_info_struct_bytes <
865 sizeof(struct ultra_vbus_deviceinfo)) {
f748f64f 866 return -EINVAL;
3703987c 867 }
f748f64f 868 return 0;
3703987c
EA
869}
870
871/* Write the contents of <info> to the struct
48117895
GL
872 * spar_vbus_channel_protocol.chp_info.
873 */
3703987c
EA
874
875static int
876write_vbus_chp_info(struct visorchannel *chan,
877 struct spar_vbus_headerinfo *hdr_info,
878 struct ultra_vbus_deviceinfo *info)
879{
880 int off = sizeof(struct channel_header) + hdr_info->chp_info_offset;
881
882 if (hdr_info->chp_info_offset == 0)
216c3e2c 883 return -1;
3703987c
EA
884
885 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
216c3e2c 886 return -1;
3703987c
EA
887 return 0;
888}
889
890/* Write the contents of <info> to the struct
48117895
GL
891 * spar_vbus_channel_protocol.bus_info.
892 */
3703987c
EA
893
894static int
895write_vbus_bus_info(struct visorchannel *chan,
896 struct spar_vbus_headerinfo *hdr_info,
897 struct ultra_vbus_deviceinfo *info)
898{
899 int off = sizeof(struct channel_header) + hdr_info->bus_info_offset;
900
901 if (hdr_info->bus_info_offset == 0)
216c3e2c 902 return -1;
3703987c
EA
903
904 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
216c3e2c 905 return -1;
3703987c
EA
906 return 0;
907}
908
909/* Write the contents of <info> to the
910 * struct spar_vbus_channel_protocol.dev_info[<devix>].
911 */
912static int
913write_vbus_dev_info(struct visorchannel *chan,
914 struct spar_vbus_headerinfo *hdr_info,
915 struct ultra_vbus_deviceinfo *info, int devix)
916{
917 int off =
918 (sizeof(struct channel_header) + hdr_info->dev_info_offset) +
919 (hdr_info->device_info_struct_bytes * devix);
920
921 if (hdr_info->dev_info_offset == 0)
216c3e2c 922 return -1;
3703987c
EA
923
924 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
216c3e2c 925 return -1;
3703987c
EA
926 return 0;
927}
928
929/* For a child device just created on a client bus, fill in
930 * information about the driver that is controlling this device into
931 * the the appropriate slot within the vbus channel of the bus
932 * instance.
933 */
934static void
935fix_vbus_dev_info(struct visor_device *visordev)
936{
937 int i;
d32517e3 938 struct visor_device *bdev;
3703987c
EA
939 struct visor_driver *visordrv;
940 int bus_no = visordev->chipset_bus_no;
941 int dev_no = visordev->chipset_dev_no;
942 struct ultra_vbus_deviceinfo dev_info;
943 const char *chan_type_name = NULL;
7726f813 944 struct spar_vbus_headerinfo *hdr_info;
3703987c
EA
945
946 if (!visordev->device.driver)
216c3e2c 947 return;
3703987c 948
7726f813 949 hdr_info = (struct spar_vbus_headerinfo *)visordev->vbus_hdr_info;
d32517e3
DZ
950 if (!hdr_info)
951 return;
7726f813 952
d32517e3
DZ
953 bdev = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL);
954 if (!bdev)
955 return;
3703987c 956
d32517e3 957 visordrv = to_visor_driver(visordev->device.driver);
3703987c
EA
958
959 /* Within the list of device types (by GUID) that the driver
960 * says it supports, find out which one of those types matches
961 * the type of this device, so that we can include the device
962 * type name
963 */
964 for (i = 0; visordrv->channel_types[i].name; i++) {
d5b3f1dc
EA
965 if (memcmp(&visordrv->channel_types[i].guid,
966 &visordev->channel_type_guid,
967 sizeof(visordrv->channel_types[i].guid)) == 0) {
3703987c
EA
968 chan_type_name = visordrv->channel_types[i].name;
969 break;
970 }
971 }
972
973 bus_device_info_init(&dev_info, chan_type_name,
974 visordrv->name, visordrv->version,
975 visordrv->vertag);
d32517e3 976 write_vbus_dev_info(bdev->visorchannel, hdr_info, &dev_info, dev_no);
3703987c
EA
977
978 /* Re-write bus+chipset info, because it is possible that this
979 * was previously written by our evil counterpart, virtpci.
980 */
d32517e3
DZ
981 write_vbus_chp_info(bdev->visorchannel, hdr_info, &chipset_driverinfo);
982 write_vbus_bus_info(bdev->visorchannel, hdr_info,
983 &clientbus_driverinfo);
3703987c
EA
984}
985
986/** Create a device instance for the visor bus itself.
987 */
d32517e3
DZ
988static int
989create_bus_instance(struct visor_device *dev)
3703987c 990{
d32517e3 991 int id = dev->chipset_bus_no;
7726f813 992 struct spar_vbus_headerinfo *hdr_info;
3703987c
EA
993
994 POSTCODE_LINUX_2(BUS_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
7726f813
DZ
995
996 hdr_info = kzalloc(sizeof(*hdr_info), GFP_KERNEL);
c2c667d6
BR
997 if (!hdr_info)
998 return -ENOMEM;
7726f813 999
343506bf
DZ
1000 dev_set_name(&dev->device, "visorbus%d", id);
1001 dev->device.bus = &visorbus_type;
1002 dev->device.groups = visorbus_groups;
1003 dev->device.release = visorbus_release_busdevice;
d32517e3 1004
343506bf 1005 if (device_register(&dev->device) < 0) {
3703987c
EA
1006 POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, id,
1007 POSTCODE_SEVERITY_ERR);
c2c667d6
BR
1008 kfree(hdr_info);
1009 return -ENODEV;
3703987c 1010 }
d32517e3 1011
ee983d90
DZ
1012 if (get_vbus_header_info(dev->visorchannel, hdr_info) >= 0) {
1013 dev->vbus_hdr_info = (void *)hdr_info;
1014 write_vbus_chp_info(dev->visorchannel, hdr_info,
1015 &chipset_driverinfo);
1016 write_vbus_bus_info(dev->visorchannel, hdr_info,
1017 &clientbus_driverinfo);
b32c4997 1018 } else {
ee983d90 1019 kfree(hdr_info);
3703987c 1020 }
3703987c 1021 bus_count++;
343506bf 1022 list_add_tail(&dev->list_all, &list_all_bus_instances);
343506bf 1023 dev_set_drvdata(&dev->device, dev);
d32517e3 1024 return 0;
3703987c
EA
1025}
1026
1027/** Remove a device instance for the visor bus itself.
1028 */
1029static void
343506bf 1030remove_bus_instance(struct visor_device *dev)
3703987c
EA
1031{
1032 /* Note that this will result in the release method for
343506bf 1033 * dev->dev being called, which will call
3703987c
EA
1034 * visorbus_release_busdevice(). This has something to do with
1035 * the put_device() done in device_unregister(), but I have never
1036 * successfully been able to trace thru the code to see where/how
1037 * release() gets called. But I know it does.
1038 */
3703987c 1039 bus_count--;
343506bf
DZ
1040 if (dev->visorchannel) {
1041 visorchannel_destroy(dev->visorchannel);
1042 dev->visorchannel = NULL;
3703987c 1043 }
343506bf
DZ
1044 kfree(dev->vbus_hdr_info);
1045 list_del(&dev->list_all);
1046 device_unregister(&dev->device);
3703987c
EA
1047}
1048
1049/** Create and register the one-and-only one instance of
1050 * the visor bus type (visorbus_type).
1051 */
1052static int
1053create_bus_type(void)
1054{
6155a3cf
BR
1055 busreg_rc = bus_register(&visorbus_type);
1056 return busreg_rc;
3703987c
EA
1057}
1058
1059/** Remove the one-and-only one instance of the visor bus type (visorbus_type).
1060 */
1061static void
1062remove_bus_type(void)
1063{
3703987c
EA
1064 bus_unregister(&visorbus_type);
1065}
1066
1067/** Remove all child visor bus device instances.
1068 */
1069static void
1070remove_all_visor_devices(void)
1071{
1072 struct list_head *listentry, *listtmp;
1073
1074 list_for_each_safe(listentry, listtmp, &list_all_device_instances) {
1075 struct visor_device *dev = list_entry(listentry,
1076 struct visor_device,
1077 list_all);
1078 remove_visor_device(dev);
1079 }
1080}
1081
3703987c 1082static void
d32517e3 1083chipset_bus_create(struct visor_device *dev)
3703987c 1084{
d32517e3
DZ
1085 int rc;
1086 u32 bus_no = dev->chipset_bus_no;
3703987c
EA
1087
1088 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, bus_no, POSTCODE_SEVERITY_INFO);
d32517e3 1089 rc = create_bus_instance(dev);
3703987c 1090 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus_no, POSTCODE_SEVERITY_INFO);
d32517e3
DZ
1091
1092 if (rc < 0)
3703987c
EA
1093 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no,
1094 POSTCODE_SEVERITY_ERR);
d32517e3
DZ
1095 else
1096 POSTCODE_LINUX_3(CHIPSET_INIT_SUCCESS_PC, bus_no,
1097 POSTCODE_SEVERITY_INFO);
1098
3703987c 1099 if (chipset_responders.bus_create)
d32517e3 1100 (*chipset_responders.bus_create) (dev, rc);
3703987c
EA
1101}
1102
1103static void
d32517e3 1104chipset_bus_destroy(struct visor_device *dev)
3703987c 1105{
343506bf 1106 remove_bus_instance(dev);
3703987c 1107 if (chipset_responders.bus_destroy)
d32517e3 1108 (*chipset_responders.bus_destroy)(dev, 0);
3703987c
EA
1109}
1110
1111static void
a298bc0b 1112chipset_device_create(struct visor_device *dev_info)
3703987c 1113{
7a9749be 1114 int rc;
a298bc0b
DZ
1115 u32 bus_no = dev_info->chipset_bus_no;
1116 u32 dev_no = dev_info->chipset_dev_no;
3703987c
EA
1117
1118 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no,
1119 POSTCODE_SEVERITY_INFO);
1120
a298bc0b 1121 rc = create_visor_device(dev_info);
86ea8acc
DK
1122 if (chipset_responders.device_create)
1123 chipset_responders.device_create(dev_info, rc);
1124
1125 if (rc < 0)
3703987c
EA
1126 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
1127 POSTCODE_SEVERITY_ERR);
86ea8acc
DK
1128 else
1129 POSTCODE_LINUX_4(DEVICE_CREATE_SUCCESS_PC, dev_no, bus_no,
1130 POSTCODE_SEVERITY_INFO);
3703987c
EA
1131}
1132
1133static void
a298bc0b 1134chipset_device_destroy(struct visor_device *dev_info)
3703987c 1135{
a298bc0b 1136 remove_visor_device(dev_info);
3703987c
EA
1137
1138 if (chipset_responders.device_destroy)
a298bc0b 1139 (*chipset_responders.device_destroy) (dev_info, 0);
3703987c
EA
1140}
1141
1142/* This is the callback function specified for a function driver, to
1143 * be called when a pending "pause device" operation has been
1144 * completed.
1145 */
1146static void
a298bc0b 1147pause_state_change_complete(struct visor_device *dev, int status)
3703987c
EA
1148{
1149 if (!dev->pausing)
216c3e2c 1150 return;
3703987c 1151
779d0752 1152 dev->pausing = false;
3703987c 1153 if (!chipset_responders.device_pause) /* this can never happen! */
216c3e2c 1154 return;
3703987c
EA
1155
1156 /* Notify the chipset driver that the pause is complete, which
7005c16c
EA
1157 * will presumably want to send some sort of response to the
1158 * initiator.
1159 */
a298bc0b 1160 (*chipset_responders.device_pause) (dev, status);
3703987c
EA
1161}
1162
1163/* This is the callback function specified for a function driver, to
1164 * be called when a pending "resume device" operation has been
1165 * completed.
1166 */
1167static void
a298bc0b 1168resume_state_change_complete(struct visor_device *dev, int status)
3703987c
EA
1169{
1170 if (!dev->resuming)
216c3e2c 1171 return;
3703987c 1172
779d0752 1173 dev->resuming = false;
3703987c 1174 if (!chipset_responders.device_resume) /* this can never happen! */
216c3e2c 1175 return;
3703987c
EA
1176
1177 /* Notify the chipset driver that the resume is complete,
1178 * which will presumably want to send some sort of response to
48117895
GL
1179 * the initiator.
1180 */
a298bc0b 1181 (*chipset_responders.device_resume) (dev, status);
3703987c
EA
1182}
1183
1184/* Tell the subordinate function driver for a specific device to pause
1185 * or resume that device. Result is returned asynchronously via a
1186 * callback function.
1187 */
1188static void
a298bc0b 1189initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
3703987c 1190{
03b93f08 1191 int rc;
3703987c 1192 struct visor_driver *drv = NULL;
a298bc0b 1193 void (*notify_func)(struct visor_device *dev, int response) = NULL;
3703987c
EA
1194
1195 if (is_pause)
1196 notify_func = chipset_responders.device_pause;
1197 else
1198 notify_func = chipset_responders.device_resume;
1199 if (!notify_func)
03b93f08 1200 return;
3703987c 1201
3703987c 1202 drv = to_visor_driver(dev->device.driver);
03b93f08
BR
1203 if (!drv) {
1204 (*notify_func)(dev, -ENODEV);
1205 return;
1206 }
3703987c 1207
03b93f08
BR
1208 if (dev->pausing || dev->resuming) {
1209 (*notify_func)(dev, -EBUSY);
1210 return;
1211 }
3703987c
EA
1212
1213 /* Note that even though both drv->pause() and drv->resume
1214 * specify a callback function, it is NOT necessary for us to
1215 * increment our local module usage count. Reason is, there
1216 * is already a linkage dependency between child function
1217 * drivers and visorbus, so it is already IMPOSSIBLE to unload
1218 * visorbus while child function drivers are still running.
1219 */
1220 if (is_pause) {
03b93f08
BR
1221 if (!drv->pause) {
1222 (*notify_func)(dev, -EINVAL);
1223 return;
1224 }
3703987c 1225
779d0752 1226 dev->pausing = true;
03b93f08 1227 rc = drv->pause(dev, pause_state_change_complete);
3703987c
EA
1228 } else {
1229 /* This should be done at BUS resume time, but an
1230 * existing problem prevents us from ever getting a bus
1231 * resume... This hack would fail to work should we
1232 * ever have a bus that contains NO devices, since we
48117895
GL
1233 * would never even get here in that case.
1234 */
3703987c 1235 fix_vbus_dev_info(dev);
03b93f08
BR
1236 if (!drv->resume) {
1237 (*notify_func)(dev, -EINVAL);
1238 return;
1239 }
3703987c 1240
779d0752 1241 dev->resuming = true;
03b93f08 1242 rc = drv->resume(dev, resume_state_change_complete);
3703987c 1243 }
03b93f08 1244 if (rc < 0) {
3703987c 1245 if (is_pause)
779d0752 1246 dev->pausing = false;
3703987c 1247 else
779d0752 1248 dev->resuming = false;
03b93f08 1249 (*notify_func)(dev, -EINVAL);
3703987c
EA
1250 }
1251}
1252
1253static void
a298bc0b 1254chipset_device_pause(struct visor_device *dev_info)
3703987c 1255{
b4b598fd 1256 initiate_chipset_device_pause_resume(dev_info, true);
3703987c
EA
1257}
1258
1259static void
a298bc0b 1260chipset_device_resume(struct visor_device *dev_info)
3703987c 1261{
b4b598fd 1262 initiate_chipset_device_pause_resume(dev_info, false);
3703987c
EA
1263}
1264
1265struct channel_size_info {
1266 uuid_le guid;
1267 unsigned long min_size;
1268 unsigned long max_size;
1269};
1270
55c67dca 1271int
3703987c
EA
1272visorbus_init(void)
1273{
78af1aef 1274 int err;
3703987c 1275
78af1aef 1276 POSTCODE_LINUX_3(DRIVER_ENTRY_PC, 0, POSTCODE_SEVERITY_INFO);
3703987c 1277 bus_device_info_init(&clientbus_driverinfo,
46168810 1278 "clientbus", "visorbus",
3703987c
EA
1279 VERSION, NULL);
1280
78af1aef
DK
1281 err = create_bus_type();
1282 if (err < 0) {
3703987c 1283 POSTCODE_LINUX_2(BUS_CREATE_ENTRY_PC, DIAG_SEVERITY_ERR);
78af1aef 1284 goto error;
3703987c
EA
1285 }
1286
1287 periodic_dev_workqueue = create_singlethread_workqueue("visorbus_dev");
1288 if (!periodic_dev_workqueue) {
1289 POSTCODE_LINUX_2(CREATE_WORKQUEUE_PC, DIAG_SEVERITY_ERR);
78af1aef
DK
1290 err = -ENOMEM;
1291 goto error;
3703987c
EA
1292 }
1293
1294 /* This enables us to receive notifications when devices appear for
1295 * which this service partition is to be a server for.
1296 */
4da3336c
DK
1297 visorchipset_register_busdev(&chipset_notifiers,
1298 &chipset_responders,
1299 &chipset_driverinfo);
3703987c 1300
78af1aef 1301 return 0;
3703987c 1302
78af1aef
DK
1303error:
1304 POSTCODE_LINUX_3(CHIPSET_INIT_FAILURE_PC, err, POSTCODE_SEVERITY_ERR);
1305 return err;
3703987c
EA
1306}
1307
c79b28f7 1308void
3703987c
EA
1309visorbus_exit(void)
1310{
1311 struct list_head *listentry, *listtmp;
1312
4da3336c 1313 visorchipset_register_busdev(NULL, NULL, NULL);
3703987c
EA
1314 remove_all_visor_devices();
1315
1316 flush_workqueue(periodic_dev_workqueue); /* better not be any work! */
1317 destroy_workqueue(periodic_dev_workqueue);
1318 periodic_dev_workqueue = NULL;
1319
1320 if (periodic_test_workqueue) {
1321 cancel_delayed_work(&periodic_work);
1322 flush_workqueue(periodic_test_workqueue);
1323 destroy_workqueue(periodic_test_workqueue);
1324 periodic_test_workqueue = NULL;
1325 }
1326
1327 list_for_each_safe(listentry, listtmp, &list_all_bus_instances) {
343506bf 1328 struct visor_device *dev = list_entry(listentry,
216c3e2c
CJ
1329 struct visor_device,
1330 list_all);
343506bf 1331 remove_bus_instance(dev);
3703987c
EA
1332 }
1333 remove_bus_type();
1334}
1335
1336module_param_named(debug, visorbus_debug, int, S_IRUGO);
1337MODULE_PARM_DESC(visorbus_debug, "1 to debug");
3703987c
EA
1338
1339module_param_named(forcematch, visorbus_forcematch, int, S_IRUGO);
1340MODULE_PARM_DESC(visorbus_forcematch,
1341 "1 to force a successful dev <--> drv match");
3703987c
EA
1342
1343module_param_named(forcenomatch, visorbus_forcenomatch, int, S_IRUGO);
1344MODULE_PARM_DESC(visorbus_forcenomatch,
1345 "1 to force an UNsuccessful dev <--> drv match");
3703987c 1346
3703987c
EA
1347module_param_named(debugref, visorbus_debugref, int, S_IRUGO);
1348MODULE_PARM_DESC(visorbus_debugref, "1 to debug reference counting");