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