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