Greg Kroah-Hartman | b79c0f4 | 2017-11-07 14:58:47 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 2 | /* |
Benjamin Romer | 6f14cc1 | 2015-07-16 12:40:48 -0400 | [diff] [blame] | 3 | * Copyright � 2010 - 2015 UNISYS CORPORATION |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 4 | * All rights reserved. |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
David Kershner | b71d87b | 2017-09-27 13:14:31 -0400 | [diff] [blame] | 7 | #include <linux/ctype.h> |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 8 | #include <linux/debugfs.h> |
David Kershner | eb6eb1e | 2017-09-27 13:14:29 -0400 | [diff] [blame] | 9 | #include <linux/module.h> |
| 10 | #include <linux/slab.h> |
David Kershner | 93d3ad9 | 2017-12-07 12:11:07 -0500 | [diff] [blame] | 11 | #include <linux/visorbus.h> |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 12 | #include <linux/uuid.h> |
| 13 | |
Prarit Bhargava | c79b28f | 2015-05-05 18:36:15 -0400 | [diff] [blame] | 14 | #include "visorbus_private.h" |
Prarit Bhargava | 4b78000 | 2015-05-05 18:36:10 -0400 | [diff] [blame] | 15 | |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 16 | static const guid_t visor_vbus_channel_guid = VISOR_VBUS_CHANNEL_GUID; |
| 17 | |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 18 | /* Display string that is guaranteed to be no longer the 99 characters */ |
Erik Arfvidson | 38d56c2 | 2016-04-13 12:07:07 -0400 | [diff] [blame] | 19 | #define LINESIZE 99 |
David Binder | ffcdb10 | 2017-03-17 11:27:18 -0400 | [diff] [blame] | 20 | #define POLLJIFFIES_NORMALCHANNEL 10 |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 21 | |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 22 | /* stores whether bus_registration was successful */ |
| 23 | static bool initialized; |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 24 | static struct dentry *visorbus_debugfs_dir; |
Benjamin Romer | 6155a3c | 2015-09-04 12:01:32 -0400 | [diff] [blame] | 25 | |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 26 | /* |
Prarit Bhargava | 59fd2c8 | 2015-07-24 12:06:53 -0400 | [diff] [blame] | 27 | * DEVICE type attributes |
| 28 | * |
| 29 | * The modalias file will contain the guid of the device. |
| 30 | */ |
| 31 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, |
| 32 | char *buf) |
| 33 | { |
| 34 | struct visor_device *vdev; |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 35 | const guid_t *guid; |
Prarit Bhargava | 59fd2c8 | 2015-07-24 12:06:53 -0400 | [diff] [blame] | 36 | |
| 37 | vdev = to_visor_device(dev); |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 38 | guid = visorchannel_get_guid(vdev->visorchannel); |
| 39 | return sprintf(buf, "visorbus:%pUl\n", guid); |
Prarit Bhargava | 59fd2c8 | 2015-07-24 12:06:53 -0400 | [diff] [blame] | 40 | } |
| 41 | static DEVICE_ATTR_RO(modalias); |
| 42 | |
| 43 | static struct attribute *visorbus_dev_attrs[] = { |
| 44 | &dev_attr_modalias.attr, |
| 45 | NULL, |
| 46 | }; |
| 47 | |
David Kershner | aa5ebde | 2017-08-22 13:27:36 -0400 | [diff] [blame] | 48 | ATTRIBUTE_GROUPS(visorbus_dev); |
Prarit Bhargava | 59fd2c8 | 2015-07-24 12:06:53 -0400 | [diff] [blame] | 49 | |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 50 | /* filled in with info about parent chipset driver when we register with it */ |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 51 | static struct visor_vbus_deviceinfo chipset_driverinfo; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 52 | /* filled in with info about this driver, wrt it servicing client busses */ |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 53 | static struct visor_vbus_deviceinfo clientbus_driverinfo; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 54 | |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 55 | /* list of visor_device structs, linked via .list_all */ |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 56 | static LIST_HEAD(list_all_bus_instances); |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 57 | /* list of visor_device structs, linked via .list_all */ |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 58 | static LIST_HEAD(list_all_device_instances); |
| 59 | |
Sameer Wadgaonkar | 403043c | 2017-07-17 16:17:02 -0400 | [diff] [blame] | 60 | /* |
| 61 | * Generic function useful for validating any type of channel when it is |
| 62 | * received by the client that will be accessing the channel. |
| 63 | * Note that <logCtx> is only needed for callers in the EFI environment, and |
| 64 | * is used to pass the EFI_DIAG_CAPTURE_PROTOCOL needed to log messages. |
| 65 | */ |
David Kershner | 5f50a34 | 2017-09-27 13:14:22 -0400 | [diff] [blame] | 66 | int visor_check_channel(struct channel_header *ch, struct device *dev, |
| 67 | const guid_t *expected_guid, char *chname, |
| 68 | u64 expected_min_bytes, u32 expected_version, |
Sameer Wadgaonkar | 403043c | 2017-07-17 16:17:02 -0400 | [diff] [blame] | 69 | u64 expected_signature) |
| 70 | { |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 71 | if (!guid_is_null(expected_guid)) { |
Sameer Wadgaonkar | 403043c | 2017-07-17 16:17:02 -0400 | [diff] [blame] | 72 | /* caller wants us to verify type GUID */ |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 73 | if (!guid_equal(&ch->chtype, expected_guid)) { |
Sameer Wadgaonkar | e25201d | 2017-08-30 13:36:35 -0400 | [diff] [blame] | 74 | dev_err(dev, "Channel mismatch on channel=%s(%pUL) field=type expected=%pUL actual=%pUL\n", |
| 75 | chname, expected_guid, expected_guid, |
| 76 | &ch->chtype); |
Sameer Wadgaonkar | 403043c | 2017-07-17 16:17:02 -0400 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | } |
| 80 | /* verify channel size */ |
| 81 | if (expected_min_bytes > 0) { |
| 82 | if (ch->size < expected_min_bytes) { |
Sameer Wadgaonkar | e25201d | 2017-08-30 13:36:35 -0400 | [diff] [blame] | 83 | dev_err(dev, "Channel mismatch on channel=%s(%pUL) field=size expected=0x%-8.8Lx actual=0x%-8.8Lx\n", |
| 84 | chname, expected_guid, |
| 85 | (unsigned long long)expected_min_bytes, |
| 86 | ch->size); |
Sameer Wadgaonkar | 403043c | 2017-07-17 16:17:02 -0400 | [diff] [blame] | 87 | return 0; |
| 88 | } |
| 89 | } |
| 90 | /* verify channel version */ |
| 91 | if (expected_version > 0) { |
| 92 | if (ch->version_id != expected_version) { |
Sameer Wadgaonkar | e25201d | 2017-08-30 13:36:35 -0400 | [diff] [blame] | 93 | dev_err(dev, "Channel mismatch on channel=%s(%pUL) field=version expected=0x%-8.8lx actual=0x%-8.8x\n", |
| 94 | chname, expected_guid, |
| 95 | (unsigned long)expected_version, |
| 96 | ch->version_id); |
Sameer Wadgaonkar | 403043c | 2017-07-17 16:17:02 -0400 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | } |
| 100 | /* verify channel signature */ |
| 101 | if (expected_signature > 0) { |
| 102 | if (ch->signature != expected_signature) { |
Sameer Wadgaonkar | e25201d | 2017-08-30 13:36:35 -0400 | [diff] [blame] | 103 | dev_err(dev, "Channel mismatch on channel=%s(%pUL) field=signature expected=0x%-8.8Lx actual=0x%-8.8Lx\n", |
| 104 | chname, expected_guid, expected_signature, |
| 105 | ch->signature); |
Sameer Wadgaonkar | 403043c | 2017-07-17 16:17:02 -0400 | [diff] [blame] | 106 | return 0; |
| 107 | } |
| 108 | } |
| 109 | return 1; |
| 110 | } |
Sameer Wadgaonkar | 403043c | 2017-07-17 16:17:02 -0400 | [diff] [blame] | 111 | |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 112 | static int visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 113 | { |
Prarit Bhargava | 59fd2c8 | 2015-07-24 12:06:53 -0400 | [diff] [blame] | 114 | struct visor_device *dev; |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 115 | const guid_t *guid; |
Prarit Bhargava | 59fd2c8 | 2015-07-24 12:06:53 -0400 | [diff] [blame] | 116 | |
| 117 | dev = to_visor_device(xdev); |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 118 | guid = visorchannel_get_guid(dev->visorchannel); |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 119 | return add_uevent_var(env, "MODALIAS=visorbus:%pUl", guid); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 120 | } |
| 121 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 122 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 123 | * visorbus_match() - called automatically upon adding a visor_device |
| 124 | * (device_add), or adding a visor_driver |
| 125 | * (visorbus_register_visor_driver) |
| 126 | * @xdev: struct device for the device being matched |
| 127 | * @xdrv: struct device_driver for driver to match device against |
| 128 | * |
| 129 | * Return: 1 iff the provided driver can control the specified device |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 130 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 131 | static int visorbus_match(struct device *xdev, struct device_driver *xdrv) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 132 | { |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 133 | const guid_t *channel_type; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 134 | int i; |
| 135 | struct visor_device *dev; |
| 136 | struct visor_driver *drv; |
Sameer Wadgaonkar | cb3b5dc | 2017-09-27 13:14:43 -0400 | [diff] [blame] | 137 | struct visorchannel *chan; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 138 | |
| 139 | dev = to_visor_device(xdev); |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 140 | channel_type = visorchannel_get_guid(dev->visorchannel); |
David Binder | d4e8a22 | 2017-07-17 16:16:43 -0400 | [diff] [blame] | 141 | drv = to_visor_driver(xdrv); |
Sameer Wadgaonkar | cb3b5dc | 2017-09-27 13:14:43 -0400 | [diff] [blame] | 142 | chan = dev->visorchannel; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 143 | if (!drv->channel_types) |
David Kershner | 8e33f48 | 2016-03-12 21:27:11 -0500 | [diff] [blame] | 144 | return 0; |
David Kershner | 425eaf4 | 2017-08-30 13:36:32 -0400 | [diff] [blame] | 145 | for (i = 0; !guid_is_null(&drv->channel_types[i].guid); i++) |
Sameer Wadgaonkar | cb3b5dc | 2017-09-27 13:14:43 -0400 | [diff] [blame] | 146 | if (guid_equal(&drv->channel_types[i].guid, channel_type) && |
| 147 | visor_check_channel(visorchannel_get_header(chan), |
| 148 | xdev, |
| 149 | &drv->channel_types[i].guid, |
| 150 | (char *)drv->channel_types[i].name, |
| 151 | drv->channel_types[i].min_bytes, |
| 152 | drv->channel_types[i].version, |
| 153 | VISOR_CHANNEL_SIGNATURE)) |
David Kershner | 8e33f48 | 2016-03-12 21:27:11 -0500 | [diff] [blame] | 154 | return i + 1; |
David Kershner | 8e33f48 | 2016-03-12 21:27:11 -0500 | [diff] [blame] | 155 | return 0; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 156 | } |
| 157 | |
David Kershner | 7993b40 | 2016-09-19 17:09:35 -0400 | [diff] [blame] | 158 | /* |
| 159 | * This describes the TYPE of bus. |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 160 | * (Don't confuse this with an INSTANCE of the bus.) |
David Kershner | 7993b40 | 2016-09-19 17:09:35 -0400 | [diff] [blame] | 161 | */ |
David Kershner | 69a4d1e | 2017-09-27 13:14:36 -0400 | [diff] [blame] | 162 | static struct bus_type visorbus_type = { |
David Kershner | 7993b40 | 2016-09-19 17:09:35 -0400 | [diff] [blame] | 163 | .name = "visorbus", |
| 164 | .match = visorbus_match, |
| 165 | .uevent = visorbus_uevent, |
| 166 | .dev_groups = visorbus_dev_groups, |
David Kershner | 7993b40 | 2016-09-19 17:09:35 -0400 | [diff] [blame] | 167 | }; |
| 168 | |
David Kershner | 69a4d1e | 2017-09-27 13:14:36 -0400 | [diff] [blame] | 169 | struct visor_busdev { |
| 170 | u32 bus_no; |
| 171 | u32 dev_no; |
| 172 | }; |
| 173 | |
Suzuki K Poulose | 418e3ea | 2019-06-14 18:53:59 +0100 | [diff] [blame] | 174 | static int match_visorbus_dev_by_id(struct device *dev, const void *data) |
David Kershner | 69a4d1e | 2017-09-27 13:14:36 -0400 | [diff] [blame] | 175 | { |
| 176 | struct visor_device *vdev = to_visor_device(dev); |
Suzuki K Poulose | 418e3ea | 2019-06-14 18:53:59 +0100 | [diff] [blame] | 177 | const struct visor_busdev *id = data; |
David Kershner | 69a4d1e | 2017-09-27 13:14:36 -0400 | [diff] [blame] | 178 | |
David Kershner | 614b083 | 2017-09-27 13:14:48 -0400 | [diff] [blame] | 179 | if (vdev->chipset_bus_no == id->bus_no && |
| 180 | vdev->chipset_dev_no == id->dev_no) |
David Kershner | 69a4d1e | 2017-09-27 13:14:36 -0400 | [diff] [blame] | 181 | return 1; |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no, |
| 186 | struct visor_device *from) |
| 187 | { |
| 188 | struct device *dev; |
| 189 | struct device *dev_start = NULL; |
| 190 | struct visor_busdev id = { |
| 191 | .bus_no = bus_no, |
| 192 | .dev_no = dev_no |
| 193 | }; |
| 194 | |
| 195 | if (from) |
| 196 | dev_start = &from->device; |
| 197 | dev = bus_find_device(&visorbus_type, dev_start, (void *)&id, |
| 198 | match_visorbus_dev_by_id); |
| 199 | if (!dev) |
| 200 | return NULL; |
| 201 | return to_visor_device(dev); |
| 202 | } |
| 203 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 204 | /* |
David Binder | ce4617e | 2017-02-21 12:53:21 -0500 | [diff] [blame] | 205 | * visorbus_release_busdevice() - called when device_unregister() is called for |
| 206 | * the bus device instance, after all other tasks |
| 207 | * involved with destroying the dev are complete |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 208 | * @xdev: struct device for the bus being released |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 209 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 210 | static void visorbus_release_busdevice(struct device *xdev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 211 | { |
Don Zickus | 343506b | 2015-06-04 09:22:37 -0400 | [diff] [blame] | 212 | struct visor_device *dev = dev_get_drvdata(xdev); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 213 | |
David Kershner | 1c21800 | 2017-09-27 13:14:21 -0400 | [diff] [blame] | 214 | debugfs_remove(dev->debugfs_bus_info); |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 215 | debugfs_remove_recursive(dev->debugfs_dir); |
David Kershner | ae54a28 | 2017-09-27 13:14:17 -0400 | [diff] [blame] | 216 | visorchannel_destroy(dev->visorchannel); |
Don Zickus | 343506b | 2015-06-04 09:22:37 -0400 | [diff] [blame] | 217 | kfree(dev); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 218 | } |
| 219 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 220 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 221 | * visorbus_release_device() - called when device_unregister() is called for |
| 222 | * each child device instance |
| 223 | * @xdev: struct device for the visor device being released |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 224 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 225 | static void visorbus_release_device(struct device *xdev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 226 | { |
| 227 | struct visor_device *dev = to_visor_device(xdev); |
| 228 | |
Sameer Wadgaonkar | d72e1a1 | 2017-07-17 16:16:56 -0400 | [diff] [blame] | 229 | visorchannel_destroy(dev->visorchannel); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 230 | kfree(dev); |
| 231 | } |
| 232 | |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 233 | /* |
David Kershner | 7915a3c | 2017-09-27 13:14:13 -0400 | [diff] [blame] | 234 | * BUS specific channel attributes to appear under |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 235 | * /sys/bus/visorbus<x>/dev<y>/channel |
| 236 | */ |
| 237 | |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 238 | static ssize_t physaddr_show(struct device *dev, struct device_attribute *attr, |
| 239 | char *buf) |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 240 | { |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 241 | struct visor_device *vdev = to_visor_device(dev); |
| 242 | |
David Binder | 7a41385 | 2017-01-03 16:01:16 -0500 | [diff] [blame] | 243 | return sprintf(buf, "0x%llx\n", |
| 244 | visorchannel_get_physaddr(vdev->visorchannel)); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 245 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 246 | static DEVICE_ATTR_RO(physaddr); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 247 | |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 248 | static ssize_t nbytes_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 | |
David Binder | 7a41385 | 2017-01-03 16:01:16 -0500 | [diff] [blame] | 253 | return sprintf(buf, "0x%lx\n", |
David Kershner | da56cb0 | 2017-09-27 13:14:39 -0400 | [diff] [blame] | 254 | visorchannel_get_nbytes(vdev->visorchannel)); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 255 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 256 | static DEVICE_ATTR_RO(nbytes); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 257 | |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 258 | static ssize_t clientpartition_show(struct device *dev, |
| 259 | struct device_attribute *attr, char *buf) |
| 260 | { |
| 261 | struct visor_device *vdev = to_visor_device(dev); |
| 262 | |
David Binder | 7a41385 | 2017-01-03 16:01:16 -0500 | [diff] [blame] | 263 | return sprintf(buf, "0x%llx\n", |
| 264 | visorchannel_get_clientpartition(vdev->visorchannel)); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 265 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 266 | static DEVICE_ATTR_RO(clientpartition); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 267 | |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 268 | static ssize_t typeguid_show(struct device *dev, struct device_attribute *attr, |
| 269 | char *buf) |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 270 | { |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 271 | struct visor_device *vdev = to_visor_device(dev); |
Erik Arfvidson | 38d56c2 | 2016-04-13 12:07:07 -0400 | [diff] [blame] | 272 | char typeid[LINESIZE]; |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 273 | |
David Binder | 7a41385 | 2017-01-03 16:01:16 -0500 | [diff] [blame] | 274 | return sprintf(buf, "%s\n", |
| 275 | visorchannel_id(vdev->visorchannel, typeid)); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 276 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 277 | static DEVICE_ATTR_RO(typeguid); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 278 | |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 279 | static ssize_t zoneguid_show(struct device *dev, struct device_attribute *attr, |
| 280 | char *buf) |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 281 | { |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 282 | struct visor_device *vdev = to_visor_device(dev); |
Erik Arfvidson | 38d56c2 | 2016-04-13 12:07:07 -0400 | [diff] [blame] | 283 | char zoneid[LINESIZE]; |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 284 | |
David Binder | 7a41385 | 2017-01-03 16:01:16 -0500 | [diff] [blame] | 285 | return sprintf(buf, "%s\n", |
| 286 | visorchannel_zoneid(vdev->visorchannel, zoneid)); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 287 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 288 | static DEVICE_ATTR_RO(zoneguid); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 289 | |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 290 | static ssize_t typename_show(struct device *dev, struct device_attribute *attr, |
| 291 | char *buf) |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 292 | { |
| 293 | int i = 0; |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 294 | struct bus_type *xbus = dev->bus; |
| 295 | struct device_driver *xdrv = dev->driver; |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 296 | struct visor_driver *drv = NULL; |
| 297 | |
Sameer Wadgaonkar | a3276bf | 2017-07-17 16:16:58 -0400 | [diff] [blame] | 298 | if (!xdrv) |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 299 | return 0; |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 300 | i = xbus->match(dev, xdrv); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 301 | if (!i) |
| 302 | return 0; |
| 303 | drv = to_visor_driver(xdrv); |
David Binder | 7a41385 | 2017-01-03 16:01:16 -0500 | [diff] [blame] | 304 | return sprintf(buf, "%s\n", drv->channel_types[i - 1].name); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 305 | } |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 306 | static DEVICE_ATTR_RO(typename); |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 307 | |
| 308 | static struct attribute *channel_attrs[] = { |
Zachary Dremann | b372fee | 2017-06-30 15:43:24 -0400 | [diff] [blame] | 309 | &dev_attr_physaddr.attr, |
| 310 | &dev_attr_nbytes.attr, |
| 311 | &dev_attr_clientpartition.attr, |
| 312 | &dev_attr_typeguid.attr, |
| 313 | &dev_attr_zoneguid.attr, |
| 314 | &dev_attr_typename.attr, |
| 315 | NULL |
Don Zickus | 7957316 | 2015-05-13 13:22:17 -0400 | [diff] [blame] | 316 | }; |
| 317 | |
David Kershner | aa5ebde | 2017-08-22 13:27:36 -0400 | [diff] [blame] | 318 | ATTRIBUTE_GROUPS(channel); |
Prarit Bhargava | 826b6a0 | 2015-05-05 18:36:06 -0400 | [diff] [blame] | 319 | |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 320 | /* |
| 321 | * BUS instance attributes |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 322 | * |
| 323 | * define & implement display of bus attributes under |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 324 | * /sys/bus/visorbus/devices/visorbus<n>. |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 325 | */ |
Don Zickus | d181dd0 | 2015-05-13 13:22:13 -0400 | [diff] [blame] | 326 | static ssize_t partition_handle_show(struct device *dev, |
David Kershner | 5f50a34 | 2017-09-27 13:14:22 -0400 | [diff] [blame] | 327 | struct device_attribute *attr, char *buf) |
Erik Arfvidson | 7b9de71 | 2017-06-30 15:43:26 -0400 | [diff] [blame] | 328 | { |
Don Zickus | 5ecbd5d | 2015-05-13 13:22:23 -0400 | [diff] [blame] | 329 | struct visor_device *vdev = to_visor_device(dev); |
| 330 | u64 handle = visorchannel_get_clientpartition(vdev->visorchannel); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 331 | |
David Binder | 7a41385 | 2017-01-03 16:01:16 -0500 | [diff] [blame] | 332 | return sprintf(buf, "0x%llx\n", handle); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 333 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 334 | static DEVICE_ATTR_RO(partition_handle); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 335 | |
Don Zickus | d181dd0 | 2015-05-13 13:22:13 -0400 | [diff] [blame] | 336 | static ssize_t partition_guid_show(struct device *dev, |
David Kershner | 5f50a34 | 2017-09-27 13:14:22 -0400 | [diff] [blame] | 337 | struct device_attribute *attr, char *buf) |
Erik Arfvidson | 7b9de71 | 2017-06-30 15:43:26 -0400 | [diff] [blame] | 338 | { |
Don Zickus | 5ecbd5d | 2015-05-13 13:22:23 -0400 | [diff] [blame] | 339 | struct visor_device *vdev = to_visor_device(dev); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 340 | |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 341 | return sprintf(buf, "{%pUb}\n", &vdev->partition_guid); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 342 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 343 | static DEVICE_ATTR_RO(partition_guid); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 344 | |
Don Zickus | d181dd0 | 2015-05-13 13:22:13 -0400 | [diff] [blame] | 345 | static ssize_t partition_name_show(struct device *dev, |
David Kershner | 5f50a34 | 2017-09-27 13:14:22 -0400 | [diff] [blame] | 346 | struct device_attribute *attr, char *buf) |
Erik Arfvidson | 7b9de71 | 2017-06-30 15:43:26 -0400 | [diff] [blame] | 347 | { |
Don Zickus | 5ecbd5d | 2015-05-13 13:22:23 -0400 | [diff] [blame] | 348 | struct visor_device *vdev = to_visor_device(dev); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 349 | |
David Binder | 7a41385 | 2017-01-03 16:01:16 -0500 | [diff] [blame] | 350 | return sprintf(buf, "%s\n", vdev->name); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 351 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 352 | static DEVICE_ATTR_RO(partition_name); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 353 | |
Don Zickus | d181dd0 | 2015-05-13 13:22:13 -0400 | [diff] [blame] | 354 | static ssize_t channel_addr_show(struct device *dev, |
David Kershner | 5f50a34 | 2017-09-27 13:14:22 -0400 | [diff] [blame] | 355 | struct device_attribute *attr, char *buf) |
Erik Arfvidson | 7b9de71 | 2017-06-30 15:43:26 -0400 | [diff] [blame] | 356 | { |
Don Zickus | 5ecbd5d | 2015-05-13 13:22:23 -0400 | [diff] [blame] | 357 | struct visor_device *vdev = to_visor_device(dev); |
| 358 | u64 addr = visorchannel_get_physaddr(vdev->visorchannel); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 359 | |
David Binder | 7a41385 | 2017-01-03 16:01:16 -0500 | [diff] [blame] | 360 | return sprintf(buf, "0x%llx\n", addr); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 361 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 362 | static DEVICE_ATTR_RO(channel_addr); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 363 | |
Don Zickus | d181dd0 | 2015-05-13 13:22:13 -0400 | [diff] [blame] | 364 | static ssize_t channel_bytes_show(struct device *dev, |
David Kershner | 5f50a34 | 2017-09-27 13:14:22 -0400 | [diff] [blame] | 365 | struct device_attribute *attr, char *buf) |
Erik Arfvidson | 7b9de71 | 2017-06-30 15:43:26 -0400 | [diff] [blame] | 366 | { |
Don Zickus | 5ecbd5d | 2015-05-13 13:22:23 -0400 | [diff] [blame] | 367 | struct visor_device *vdev = to_visor_device(dev); |
| 368 | u64 nbytes = visorchannel_get_nbytes(vdev->visorchannel); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 369 | |
David Binder | 7a41385 | 2017-01-03 16:01:16 -0500 | [diff] [blame] | 370 | return sprintf(buf, "0x%llx\n", nbytes); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 371 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 372 | static DEVICE_ATTR_RO(channel_bytes); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 373 | |
Don Zickus | d181dd0 | 2015-05-13 13:22:13 -0400 | [diff] [blame] | 374 | static ssize_t channel_id_show(struct device *dev, |
David Kershner | 5f50a34 | 2017-09-27 13:14:22 -0400 | [diff] [blame] | 375 | struct device_attribute *attr, char *buf) |
Erik Arfvidson | 7b9de71 | 2017-06-30 15:43:26 -0400 | [diff] [blame] | 376 | { |
Don Zickus | 5ecbd5d | 2015-05-13 13:22:23 -0400 | [diff] [blame] | 377 | struct visor_device *vdev = to_visor_device(dev); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 378 | int len = 0; |
| 379 | |
David Binder | bf8d0e9 | 2017-03-17 11:27:03 -0400 | [diff] [blame] | 380 | visorchannel_id(vdev->visorchannel, buf); |
| 381 | len = strlen(buf); |
| 382 | buf[len++] = '\n'; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 383 | return len; |
| 384 | } |
Tim Sell | a25280b | 2016-11-03 11:44:15 -0400 | [diff] [blame] | 385 | static DEVICE_ATTR_RO(channel_id); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 386 | |
David Kershner | aa5ebde | 2017-08-22 13:27:36 -0400 | [diff] [blame] | 387 | static struct attribute *visorbus_attrs[] = { |
Zachary Dremann | b372fee | 2017-06-30 15:43:24 -0400 | [diff] [blame] | 388 | &dev_attr_partition_handle.attr, |
| 389 | &dev_attr_partition_guid.attr, |
| 390 | &dev_attr_partition_name.attr, |
| 391 | &dev_attr_channel_addr.attr, |
| 392 | &dev_attr_channel_bytes.attr, |
| 393 | &dev_attr_channel_id.attr, |
| 394 | NULL |
Don Zickus | d181dd0 | 2015-05-13 13:22:13 -0400 | [diff] [blame] | 395 | }; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 396 | |
David Kershner | aa5ebde | 2017-08-22 13:27:36 -0400 | [diff] [blame] | 397 | ATTRIBUTE_GROUPS(visorbus); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 398 | |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 399 | /* |
| 400 | * BUS debugfs entries |
| 401 | * |
| 402 | * define & implement display of debugfs attributes under |
| 403 | * /sys/kernel/debug/visorbus/visorbus<n>. |
| 404 | */ |
David Binder | d4e8a22 | 2017-07-17 16:16:43 -0400 | [diff] [blame] | 405 | |
David Kershner | 738561a | 2017-03-28 09:34:40 -0400 | [diff] [blame] | 406 | /* |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 407 | * vbuschannel_print_devinfo() - format a struct visor_vbus_deviceinfo |
David Kershner | 738561a | 2017-03-28 09:34:40 -0400 | [diff] [blame] | 408 | * and write it to a seq_file |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 409 | * @devinfo: the struct visor_vbus_deviceinfo to format |
David Kershner | 738561a | 2017-03-28 09:34:40 -0400 | [diff] [blame] | 410 | * @seq: seq_file to write to |
| 411 | * @devix: the device index to be included in the output data, or -1 if no |
| 412 | * device index is to be included |
| 413 | * |
| 414 | * Reads @devInfo, and writes it in human-readable notation to @seq. |
| 415 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 416 | static void vbuschannel_print_devinfo(struct visor_vbus_deviceinfo *devinfo, |
| 417 | struct seq_file *seq, int devix) |
David Kershner | 738561a | 2017-03-28 09:34:40 -0400 | [diff] [blame] | 418 | { |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 419 | /* uninitialized vbus device entry */ |
David Kershner | 738561a | 2017-03-28 09:34:40 -0400 | [diff] [blame] | 420 | if (!isprint(devinfo->devtype[0])) |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 421 | return; |
David Kershner | 738561a | 2017-03-28 09:34:40 -0400 | [diff] [blame] | 422 | if (devix >= 0) |
| 423 | seq_printf(seq, "[%d]", devix); |
| 424 | else |
| 425 | /* vbus device entry is for bus or chipset */ |
| 426 | seq_puts(seq, " "); |
David Kershner | 738561a | 2017-03-28 09:34:40 -0400 | [diff] [blame] | 427 | /* |
| 428 | * Note: because the s-Par back-end is free to scribble in this area, |
| 429 | * we never assume '\0'-termination. |
| 430 | */ |
| 431 | seq_printf(seq, "%-*.*s ", (int)sizeof(devinfo->devtype), |
| 432 | (int)sizeof(devinfo->devtype), devinfo->devtype); |
| 433 | seq_printf(seq, "%-*.*s ", (int)sizeof(devinfo->drvname), |
| 434 | (int)sizeof(devinfo->drvname), devinfo->drvname); |
| 435 | seq_printf(seq, "%.*s\n", (int)sizeof(devinfo->infostrs), |
| 436 | devinfo->infostrs); |
| 437 | } |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 438 | |
David Kershner | 1c21800 | 2017-09-27 13:14:21 -0400 | [diff] [blame] | 439 | static int bus_info_debugfs_show(struct seq_file *seq, void *v) |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 440 | { |
David Binder | d4e8a22 | 2017-07-17 16:16:43 -0400 | [diff] [blame] | 441 | int i = 0; |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 442 | unsigned long off; |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 443 | struct visor_vbus_deviceinfo dev_info; |
David Binder | d4e8a22 | 2017-07-17 16:16:43 -0400 | [diff] [blame] | 444 | struct visor_device *vdev = seq->private; |
| 445 | struct visorchannel *channel = vdev->visorchannel; |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 446 | |
| 447 | if (!channel) |
| 448 | return 0; |
| 449 | |
| 450 | seq_printf(seq, |
David Kershner | 453ca193 | 2017-09-27 13:14:23 -0400 | [diff] [blame] | 451 | "Client device/driver info for %s partition (vbus #%u):\n", |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 452 | ((vdev->name) ? (char *)(vdev->name) : ""), |
| 453 | vdev->chipset_bus_no); |
| 454 | if (visorchannel_read(channel, |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 455 | offsetof(struct visor_vbus_channel, chp_info), |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 456 | &dev_info, sizeof(dev_info)) >= 0) |
| 457 | vbuschannel_print_devinfo(&dev_info, seq, -1); |
| 458 | if (visorchannel_read(channel, |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 459 | offsetof(struct visor_vbus_channel, bus_info), |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 460 | &dev_info, sizeof(dev_info)) >= 0) |
| 461 | vbuschannel_print_devinfo(&dev_info, seq, -1); |
David Binder | d4e8a22 | 2017-07-17 16:16:43 -0400 | [diff] [blame] | 462 | |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 463 | off = offsetof(struct visor_vbus_channel, dev_info); |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 464 | while (off + sizeof(dev_info) <= visorchannel_get_nbytes(channel)) { |
| 465 | if (visorchannel_read(channel, off, &dev_info, |
| 466 | sizeof(dev_info)) >= 0) |
| 467 | vbuschannel_print_devinfo(&dev_info, seq, i); |
| 468 | off += sizeof(dev_info); |
| 469 | i++; |
| 470 | } |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 471 | return 0; |
| 472 | } |
| 473 | |
David Kershner | 1c21800 | 2017-09-27 13:14:21 -0400 | [diff] [blame] | 474 | static int bus_info_debugfs_open(struct inode *inode, struct file *file) |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 475 | { |
David Kershner | 1c21800 | 2017-09-27 13:14:21 -0400 | [diff] [blame] | 476 | return single_open(file, bus_info_debugfs_show, inode->i_private); |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 477 | } |
| 478 | |
David Kershner | 1c21800 | 2017-09-27 13:14:21 -0400 | [diff] [blame] | 479 | static const struct file_operations bus_info_debugfs_fops = { |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 480 | .owner = THIS_MODULE, |
David Kershner | 1c21800 | 2017-09-27 13:14:21 -0400 | [diff] [blame] | 481 | .open = bus_info_debugfs_open, |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 482 | .read = seq_read, |
| 483 | .llseek = seq_lseek, |
| 484 | .release = single_release, |
| 485 | }; |
| 486 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 487 | static void dev_periodic_work(struct timer_list *t) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 488 | { |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 489 | struct visor_device *dev = from_timer(dev, t, timer); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 490 | struct visor_driver *drv = to_visor_driver(dev->device.driver); |
| 491 | |
Tim Sell | 396e36c | 2017-01-09 13:02:22 -0500 | [diff] [blame] | 492 | drv->channel_interrupt(dev); |
Tim Sell | 9ebab64 | 2016-06-10 21:48:08 -0400 | [diff] [blame] | 493 | mod_timer(&dev->timer, jiffies + POLLJIFFIES_NORMALCHANNEL); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 494 | } |
| 495 | |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 496 | static int dev_start_periodic_work(struct visor_device *dev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 497 | { |
Tim Sell | 9ebab64 | 2016-06-10 21:48:08 -0400 | [diff] [blame] | 498 | if (dev->being_removed || dev->timer_active) |
David Kershner | b90194d | 2017-03-28 09:34:43 -0400 | [diff] [blame] | 499 | return -EINVAL; |
David Kershner | 4e95347 | 2017-09-27 13:14:27 -0400 | [diff] [blame] | 500 | |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 501 | /* now up by at least 2 */ |
| 502 | get_device(&dev->device); |
Tim Sell | 9ebab64 | 2016-06-10 21:48:08 -0400 | [diff] [blame] | 503 | dev->timer.expires = jiffies + POLLJIFFIES_NORMALCHANNEL; |
| 504 | add_timer(&dev->timer); |
| 505 | dev->timer_active = true; |
David Kershner | b90194d | 2017-03-28 09:34:43 -0400 | [diff] [blame] | 506 | return 0; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 507 | } |
| 508 | |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 509 | static void dev_stop_periodic_work(struct visor_device *dev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 510 | { |
Tim Sell | 9ebab64 | 2016-06-10 21:48:08 -0400 | [diff] [blame] | 511 | if (!dev->timer_active) |
| 512 | return; |
David Kershner | 4e95347 | 2017-09-27 13:14:27 -0400 | [diff] [blame] | 513 | |
Tim Sell | 9ebab64 | 2016-06-10 21:48:08 -0400 | [diff] [blame] | 514 | del_timer_sync(&dev->timer); |
| 515 | dev->timer_active = false; |
| 516 | put_device(&dev->device); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 517 | } |
| 518 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 519 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 520 | * visordriver_remove_device() - handle visor device going away |
| 521 | * @xdev: struct device for the visor device being removed |
| 522 | * |
| 523 | * This is called when device_unregister() is called for each child device |
| 524 | * instance, to notify the appropriate visorbus function driver that the device |
| 525 | * is going away, and to decrease the reference count of the device. |
| 526 | * |
| 527 | * Return: 0 iff successful |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 528 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 529 | static int visordriver_remove_device(struct device *xdev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 530 | { |
David Kershner | 7f91228 | 2017-09-27 13:14:28 -0400 | [diff] [blame] | 531 | struct visor_device *dev = to_visor_device(xdev); |
| 532 | struct visor_driver *drv = to_visor_driver(xdev->driver); |
David Binder | d4e8a22 | 2017-07-17 16:16:43 -0400 | [diff] [blame] | 533 | |
Bryan Thompson | d505855 | 2016-06-10 21:48:10 -0400 | [diff] [blame] | 534 | mutex_lock(&dev->visordriver_callback_lock); |
Prarit Bhargava | 779d075 | 2015-05-05 18:37:01 -0400 | [diff] [blame] | 535 | dev->being_removed = true; |
Sameer Wadgaonkar | c2d00b2 | 2017-07-17 16:16:59 -0400 | [diff] [blame] | 536 | drv->remove(dev); |
Bryan Thompson | d505855 | 2016-06-10 21:48:10 -0400 | [diff] [blame] | 537 | mutex_unlock(&dev->visordriver_callback_lock); |
David Binder | d4e8a22 | 2017-07-17 16:16:43 -0400 | [diff] [blame] | 538 | dev_stop_periodic_work(dev); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 539 | put_device(&dev->device); |
Abdul Hussain | df7f46e | 2015-06-11 10:03:49 +0000 | [diff] [blame] | 540 | return 0; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 541 | } |
| 542 | |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 543 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 544 | * visorbus_unregister_visor_driver() - unregisters the provided driver |
| 545 | * @drv: the driver to unregister |
| 546 | * |
| 547 | * A visor function driver calls this function to unregister the driver, |
| 548 | * i.e., within its module_exit function. |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 549 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 550 | void visorbus_unregister_visor_driver(struct visor_driver *drv) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 551 | { |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 552 | driver_unregister(&drv->driver); |
| 553 | } |
| 554 | EXPORT_SYMBOL_GPL(visorbus_unregister_visor_driver); |
| 555 | |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 556 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 557 | * visorbus_read_channel() - reads from the designated channel into |
| 558 | * the provided buffer |
| 559 | * @dev: the device whose channel is read from |
| 560 | * @offset: the offset into the channel at which reading starts |
| 561 | * @dest: the destination buffer that is written into from the channel |
| 562 | * @nbytes: the number of bytes to read from the channel |
| 563 | * |
David Kershner | 7915a3c | 2017-09-27 13:14:13 -0400 | [diff] [blame] | 564 | * If receiving a message, use the visorchannel_signalremove() function instead. |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 565 | * |
| 566 | * Return: integer indicating success (zero) or failure (non-zero) |
| 567 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 568 | int visorbus_read_channel(struct visor_device *dev, unsigned long offset, |
| 569 | void *dest, unsigned long nbytes) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 570 | { |
| 571 | return visorchannel_read(dev->visorchannel, offset, dest, nbytes); |
| 572 | } |
| 573 | EXPORT_SYMBOL_GPL(visorbus_read_channel); |
| 574 | |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 575 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 576 | * visorbus_write_channel() - writes the provided buffer into the designated |
| 577 | * channel |
| 578 | * @dev: the device whose channel is written to |
| 579 | * @offset: the offset into the channel at which writing starts |
| 580 | * @src: the source buffer that is written into the channel |
| 581 | * @nbytes: the number of bytes to write into the channel |
| 582 | * |
David Kershner | 7915a3c | 2017-09-27 13:14:13 -0400 | [diff] [blame] | 583 | * If sending a message, use the visorchannel_signalinsert() function instead. |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 584 | * |
| 585 | * Return: integer indicating success (zero) or failure (non-zero) |
| 586 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 587 | int visorbus_write_channel(struct visor_device *dev, unsigned long offset, |
| 588 | void *src, unsigned long nbytes) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 589 | { |
| 590 | return visorchannel_write(dev->visorchannel, offset, src, nbytes); |
| 591 | } |
| 592 | EXPORT_SYMBOL_GPL(visorbus_write_channel); |
| 593 | |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 594 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 595 | * visorbus_enable_channel_interrupts() - enables interrupts on the |
| 596 | * designated device |
| 597 | * @dev: the device on which to enable interrupts |
| 598 | * |
| 599 | * Currently we don't yet have a real interrupt, so for now we just call the |
| 600 | * interrupt function periodically via a timer. |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 601 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 602 | int visorbus_enable_channel_interrupts(struct visor_device *dev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 603 | { |
Tim Sell | 396e36c | 2017-01-09 13:02:22 -0500 | [diff] [blame] | 604 | struct visor_driver *drv = to_visor_driver(dev->device.driver); |
| 605 | |
| 606 | if (!drv->channel_interrupt) { |
| 607 | dev_err(&dev->device, "%s no interrupt function!\n", __func__); |
David Kershner | 5dca9b2 | 2017-03-28 09:34:44 -0400 | [diff] [blame] | 608 | return -ENOENT; |
Tim Sell | 396e36c | 2017-01-09 13:02:22 -0500 | [diff] [blame] | 609 | } |
| 610 | |
David Kershner | 5dca9b2 | 2017-03-28 09:34:44 -0400 | [diff] [blame] | 611 | return dev_start_periodic_work(dev); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 612 | } |
| 613 | EXPORT_SYMBOL_GPL(visorbus_enable_channel_interrupts); |
| 614 | |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 615 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 616 | * visorbus_disable_channel_interrupts() - disables interrupts on the |
| 617 | * designated device |
| 618 | * @dev: the device on which to disable interrupts |
| 619 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 620 | void visorbus_disable_channel_interrupts(struct visor_device *dev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 621 | { |
| 622 | dev_stop_periodic_work(dev); |
| 623 | } |
| 624 | EXPORT_SYMBOL_GPL(visorbus_disable_channel_interrupts); |
| 625 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 626 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 627 | * create_visor_device() - create visor device as a result of receiving the |
| 628 | * controlvm device_create message for a new device |
| 629 | * @dev: a freshly-zeroed struct visor_device, containing only filled-in values |
| 630 | * for chipset_bus_no and chipset_dev_no, that will be initialized |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 631 | * |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 632 | * This is how everything starts from the device end. |
| 633 | * This function is called when a channel first appears via a ControlVM |
David Kershner | 7915a3c | 2017-09-27 13:14:13 -0400 | [diff] [blame] | 634 | * message. In response, this function allocates a visor_device to correspond |
| 635 | * to the new channel, and attempts to connect it the appropriate * driver. If |
| 636 | * the appropriate driver is found, the visor_driver.probe() function for that |
| 637 | * driver will be called, and will be passed the new * visor_device that we |
| 638 | * just created. |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 639 | * |
| 640 | * It's ok if the appropriate driver is not yet loaded, because in that case |
| 641 | * the new device struct will just stick around in the bus' list of devices. |
| 642 | * When the appropriate driver calls visorbus_register_visor_driver(), the |
David Kershner | 7915a3c | 2017-09-27 13:14:13 -0400 | [diff] [blame] | 643 | * visor_driver.probe() for the new driver will be called with the new device. |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 644 | * |
| 645 | * Return: 0 if successful, otherwise the negative value returned by |
| 646 | * device_add() indicating the reason for failure |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 647 | */ |
Sameer Wadgaonkar | 51c0f81 | 2017-08-22 13:27:34 -0400 | [diff] [blame] | 648 | int create_visor_device(struct visor_device *dev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 649 | { |
David Kershner | 0b2acf3 | 2016-03-12 21:27:12 -0500 | [diff] [blame] | 650 | int err; |
Don Zickus | a298bc0 | 2015-06-04 09:22:42 -0400 | [diff] [blame] | 651 | u32 chipset_bus_no = dev->chipset_bus_no; |
| 652 | u32 chipset_dev_no = dev->chipset_dev_no; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 653 | |
Bryan Thompson | d505855 | 2016-06-10 21:48:10 -0400 | [diff] [blame] | 654 | mutex_init(&dev->visordriver_callback_lock); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 655 | dev->device.bus = &visorbus_type; |
David Kershner | aa5ebde | 2017-08-22 13:27:36 -0400 | [diff] [blame] | 656 | dev->device.groups = channel_groups; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 657 | device_initialize(&dev->device); |
| 658 | dev->device.release = visorbus_release_device; |
| 659 | /* keep a reference just for us (now 2) */ |
| 660 | get_device(&dev->device); |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 661 | timer_setup(&dev->timer, dev_periodic_work, 0); |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 662 | /* |
David Kershner | 7915a3c | 2017-09-27 13:14:13 -0400 | [diff] [blame] | 663 | * bus_id must be a unique name with respect to this bus TYPE (NOT bus |
| 664 | * instance). That's why we need to include the bus number within the |
| 665 | * name. |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 666 | */ |
David Kershner | e0d210a | 2017-03-28 09:34:50 -0400 | [diff] [blame] | 667 | err = dev_set_name(&dev->device, "vbus%u:dev%u", |
| 668 | chipset_bus_no, chipset_dev_no); |
| 669 | if (err) |
| 670 | goto err_put; |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 671 | /* |
| 672 | * device_add does this: |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 673 | * bus_add_device(dev) |
| 674 | * ->device_attach(dev) |
| 675 | * ->for each driver drv registered on the bus that dev is on |
| 676 | * if (dev.drv) ** device already has a driver ** |
| 677 | * ** not sure we could ever get here... ** |
| 678 | * else |
| 679 | * if (bus.match(dev,drv)) [visorbus_match] |
| 680 | * dev.drv = drv |
| 681 | * if (!drv.probe(dev)) [visordriver_probe_device] |
| 682 | * dev.drv = NULL |
| 683 | * |
David Kershner | 7915a3c | 2017-09-27 13:14:13 -0400 | [diff] [blame] | 684 | * Note that device_add does NOT fail if no driver failed to claim the |
| 685 | * device. The device will be linked onto bus_type.klist_devices |
| 686 | * regardless (use bus_for_each_dev). |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 687 | */ |
David Kershner | 0b2acf3 | 2016-03-12 21:27:12 -0500 | [diff] [blame] | 688 | err = device_add(&dev->device); |
David Kershner | ebdc1b8 | 2017-04-18 16:55:09 -0400 | [diff] [blame] | 689 | if (err < 0) |
David Kershner | 0b2acf3 | 2016-03-12 21:27:12 -0500 | [diff] [blame] | 690 | goto err_put; |
Don Zickus | a298bc0 | 2015-06-04 09:22:42 -0400 | [diff] [blame] | 691 | list_add_tail(&dev->list_all, &list_all_device_instances); |
Sameer Wadgaonkar | 51c0f81 | 2017-08-22 13:27:34 -0400 | [diff] [blame] | 692 | dev->state.created = 1; |
| 693 | visorbus_response(dev, err, CONTROLVM_DEVICE_CREATE); |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 694 | /* success: reference kept via unmatched get_device() */ |
| 695 | return 0; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 696 | |
David Kershner | 0b2acf3 | 2016-03-12 21:27:12 -0500 | [diff] [blame] | 697 | err_put: |
Don Zickus | a298bc0 | 2015-06-04 09:22:42 -0400 | [diff] [blame] | 698 | put_device(&dev->device); |
David Kershner | ebdc1b8 | 2017-04-18 16:55:09 -0400 | [diff] [blame] | 699 | dev_err(&dev->device, "Creating visor device failed. %d\n", err); |
David Kershner | 0b2acf3 | 2016-03-12 21:27:12 -0500 | [diff] [blame] | 700 | return err; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 701 | } |
| 702 | |
Sameer Wadgaonkar | b74856b | 2017-08-22 13:27:35 -0400 | [diff] [blame] | 703 | void remove_visor_device(struct visor_device *dev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 704 | { |
| 705 | list_del(&dev->list_all); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 706 | put_device(&dev->device); |
David Kershner | fd9e450 | 2017-09-27 13:14:16 -0400 | [diff] [blame] | 707 | if (dev->pending_msg_hdr) |
| 708 | visorbus_response(dev, 0, CONTROLVM_DEVICE_DESTROY); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 709 | device_unregister(&dev->device); |
| 710 | } |
| 711 | |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 712 | static int get_vbus_header_info(struct visorchannel *chan, |
Sameer Wadgaonkar | e25201d | 2017-08-30 13:36:35 -0400 | [diff] [blame] | 713 | struct device *dev, |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 714 | struct visor_vbus_headerinfo *hdr_info) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 715 | { |
David Kershner | 711c67f | 2017-03-28 09:34:51 -0400 | [diff] [blame] | 716 | int err; |
| 717 | |
Sameer Wadgaonkar | 315dfc8 | 2017-05-19 16:17:54 -0400 | [diff] [blame] | 718 | if (!visor_check_channel(visorchannel_get_header(chan), |
Sameer Wadgaonkar | e25201d | 2017-08-30 13:36:35 -0400 | [diff] [blame] | 719 | dev, |
Andy Shevchenko | b32c5cb | 2017-08-22 13:26:54 -0400 | [diff] [blame] | 720 | &visor_vbus_channel_guid, |
Sameer Wadgaonkar | 315dfc8 | 2017-05-19 16:17:54 -0400 | [diff] [blame] | 721 | "vbus", |
| 722 | sizeof(struct visor_vbus_channel), |
| 723 | VISOR_VBUS_CHANNEL_VERSIONID, |
Alex Curtin | e9b9275 | 2017-07-17 16:16:51 -0400 | [diff] [blame] | 724 | VISOR_CHANNEL_SIGNATURE)) |
Benjamin Romer | f748f64 | 2016-02-23 10:01:50 -0500 | [diff] [blame] | 725 | return -EINVAL; |
| 726 | |
David Kershner | 711c67f | 2017-03-28 09:34:51 -0400 | [diff] [blame] | 727 | err = visorchannel_read(chan, sizeof(struct channel_header), hdr_info, |
| 728 | sizeof(*hdr_info)); |
| 729 | if (err < 0) |
| 730 | return err; |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 731 | if (hdr_info->struct_bytes < sizeof(struct visor_vbus_headerinfo)) |
Benjamin Romer | f748f64 | 2016-02-23 10:01:50 -0500 | [diff] [blame] | 732 | return -EINVAL; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 733 | if (hdr_info->device_info_struct_bytes < |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 734 | sizeof(struct visor_vbus_deviceinfo)) |
Benjamin Romer | f748f64 | 2016-02-23 10:01:50 -0500 | [diff] [blame] | 735 | return -EINVAL; |
Benjamin Romer | f748f64 | 2016-02-23 10:01:50 -0500 | [diff] [blame] | 736 | return 0; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 737 | } |
| 738 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 739 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 740 | * write_vbus_chp_info() - write the contents of <info> to the struct |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 741 | * visor_vbus_channel.chp_info |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 742 | * @chan: indentifies the s-Par channel that will be updated |
| 743 | * @hdr_info: used to find appropriate channel offset to write data |
| 744 | * @info: contains the information to write |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 745 | * |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 746 | * Writes chipset info into the channel memory to be used for diagnostic |
| 747 | * purposes. |
| 748 | * |
| 749 | * Returns no value since this is debug information and not needed for |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 750 | * device functionality. |
Gavin O'Leary | 4811789 | 2015-11-09 20:12:00 -0800 | [diff] [blame] | 751 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 752 | static void write_vbus_chp_info(struct visorchannel *chan, |
| 753 | struct visor_vbus_headerinfo *hdr_info, |
| 754 | struct visor_vbus_deviceinfo *info) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 755 | { |
David Kershner | 5d1a7fd | 2017-09-27 13:14:19 -0400 | [diff] [blame] | 756 | int off; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 757 | |
| 758 | if (hdr_info->chp_info_offset == 0) |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 759 | return; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 760 | |
David Kershner | 5d1a7fd | 2017-09-27 13:14:19 -0400 | [diff] [blame] | 761 | off = sizeof(struct channel_header) + hdr_info->chp_info_offset; |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 762 | visorchannel_write(chan, off, info, sizeof(*info)); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 763 | } |
| 764 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 765 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 766 | * write_vbus_bus_info() - write the contents of <info> to the struct |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 767 | * visor_vbus_channel.bus_info |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 768 | * @chan: indentifies the s-Par channel that will be updated |
| 769 | * @hdr_info: used to find appropriate channel offset to write data |
| 770 | * @info: contains the information to write |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 771 | * |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 772 | * Writes bus info into the channel memory to be used for diagnostic |
| 773 | * purposes. |
| 774 | * |
| 775 | * Returns no value since this is debug information and not needed for |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 776 | * device functionality. |
Gavin O'Leary | 4811789 | 2015-11-09 20:12:00 -0800 | [diff] [blame] | 777 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 778 | static void write_vbus_bus_info(struct visorchannel *chan, |
| 779 | struct visor_vbus_headerinfo *hdr_info, |
| 780 | struct visor_vbus_deviceinfo *info) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 781 | { |
David Kershner | 5d1a7fd | 2017-09-27 13:14:19 -0400 | [diff] [blame] | 782 | int off; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 783 | |
| 784 | if (hdr_info->bus_info_offset == 0) |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 785 | return; |
David Kershner | 4e95347 | 2017-09-27 13:14:27 -0400 | [diff] [blame] | 786 | |
David Kershner | 5d1a7fd | 2017-09-27 13:14:19 -0400 | [diff] [blame] | 787 | off = sizeof(struct channel_header) + hdr_info->bus_info_offset; |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 788 | visorchannel_write(chan, off, info, sizeof(*info)); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 789 | } |
| 790 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 791 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 792 | * write_vbus_dev_info() - write the contents of <info> to the struct |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 793 | * visor_vbus_channel.dev_info[<devix>] |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 794 | * @chan: indentifies the s-Par channel that will be updated |
| 795 | * @hdr_info: used to find appropriate channel offset to write data |
| 796 | * @info: contains the information to write |
| 797 | * @devix: the relative device number (0..n-1) of the device on the bus |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 798 | * |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 799 | * Writes device info into the channel memory to be used for diagnostic |
| 800 | * purposes. |
| 801 | * |
| 802 | * Returns no value since this is debug information and not needed for |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 803 | * device functionality. |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 804 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 805 | static void write_vbus_dev_info(struct visorchannel *chan, |
| 806 | struct visor_vbus_headerinfo *hdr_info, |
| 807 | struct visor_vbus_deviceinfo *info, |
| 808 | unsigned int devix) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 809 | { |
David Kershner | 5d1a7fd | 2017-09-27 13:14:19 -0400 | [diff] [blame] | 810 | int off; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 811 | |
| 812 | if (hdr_info->dev_info_offset == 0) |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 813 | return; |
David Kershner | 5d1a7fd | 2017-09-27 13:14:19 -0400 | [diff] [blame] | 814 | off = (sizeof(struct channel_header) + hdr_info->dev_info_offset) + |
| 815 | (hdr_info->device_info_struct_bytes * devix); |
Erik Arfvidson | ff13cf3 | 2016-06-10 21:47:59 -0400 | [diff] [blame] | 816 | visorchannel_write(chan, off, info, sizeof(*info)); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 817 | } |
| 818 | |
David Kershner | b5577d7 | 2017-03-28 09:34:28 -0400 | [diff] [blame] | 819 | static void bus_device_info_init( |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 820 | struct visor_vbus_deviceinfo *bus_device_info_ptr, |
David Kershner | b5577d7 | 2017-03-28 09:34:28 -0400 | [diff] [blame] | 821 | const char *dev_type, const char *drv_name) |
| 822 | { |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 823 | memset(bus_device_info_ptr, 0, sizeof(struct visor_vbus_deviceinfo)); |
David Kershner | b5577d7 | 2017-03-28 09:34:28 -0400 | [diff] [blame] | 824 | snprintf(bus_device_info_ptr->devtype, |
| 825 | sizeof(bus_device_info_ptr->devtype), |
| 826 | "%s", (dev_type) ? dev_type : "unknownType"); |
| 827 | snprintf(bus_device_info_ptr->drvname, |
| 828 | sizeof(bus_device_info_ptr->drvname), |
| 829 | "%s", (drv_name) ? drv_name : "unknownDriver"); |
| 830 | snprintf(bus_device_info_ptr->infostrs, |
| 831 | sizeof(bus_device_info_ptr->infostrs), "kernel ver. %s", |
| 832 | utsname()->release); |
| 833 | } |
| 834 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 835 | /* |
Erik Arfvidson | e3b2ed6 | 2017-07-17 16:17:07 -0400 | [diff] [blame] | 836 | * publish_vbus_dev_info() - for a child device just created on a client bus, |
| 837 | * fill in information about the driver that is |
| 838 | * controlling this device into the appropriate slot |
| 839 | * within the vbus channel of the bus instance |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 840 | * @visordev: struct visor_device for the desired device |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 841 | */ |
Erik Arfvidson | e3b2ed6 | 2017-07-17 16:17:07 -0400 | [diff] [blame] | 842 | static void publish_vbus_dev_info(struct visor_device *visordev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 843 | { |
| 844 | int i; |
Don Zickus | d32517e | 2015-06-04 09:22:41 -0400 | [diff] [blame] | 845 | struct visor_device *bdev; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 846 | struct visor_driver *visordrv; |
Tim Sell | f7a34ff | 2016-09-27 14:42:21 -0400 | [diff] [blame] | 847 | u32 bus_no = visordev->chipset_bus_no; |
| 848 | u32 dev_no = visordev->chipset_dev_no; |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 849 | struct visor_vbus_deviceinfo dev_info; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 850 | const char *chan_type_name = NULL; |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 851 | struct visor_vbus_headerinfo *hdr_info; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 852 | |
| 853 | if (!visordev->device.driver) |
Christophe JAILLET | 216c3e2 | 2015-07-13 20:52:26 +0200 | [diff] [blame] | 854 | return; |
Don Zickus | d32517e | 2015-06-04 09:22:41 -0400 | [diff] [blame] | 855 | bdev = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL); |
| 856 | if (!bdev) |
| 857 | return; |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 858 | hdr_info = (struct visor_vbus_headerinfo *)bdev->vbus_hdr_info; |
Tim Sell | 5990b39 | 2016-09-27 14:42:22 -0400 | [diff] [blame] | 859 | if (!hdr_info) |
| 860 | return; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 861 | visordrv = to_visor_driver(visordev->device.driver); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 862 | |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 863 | /* |
| 864 | * Within the list of device types (by GUID) that the driver |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 865 | * says it supports, find out which one of those types matches |
| 866 | * the type of this device, so that we can include the device |
| 867 | * type name |
| 868 | */ |
| 869 | for (i = 0; visordrv->channel_types[i].name; i++) { |
David Kershner | 5d48942 | 2017-09-27 13:14:14 -0400 | [diff] [blame] | 870 | if (guid_equal(&visordrv->channel_types[i].guid, |
| 871 | &visordev->channel_type_guid)) { |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 872 | chan_type_name = visordrv->channel_types[i].name; |
| 873 | break; |
| 874 | } |
| 875 | } |
Jon Frisch | e82ed63 | 2016-09-26 11:03:41 -0400 | [diff] [blame] | 876 | bus_device_info_init(&dev_info, chan_type_name, visordrv->name); |
Don Zickus | d32517e | 2015-06-04 09:22:41 -0400 | [diff] [blame] | 877 | write_vbus_dev_info(bdev->visorchannel, hdr_info, &dev_info, dev_no); |
Don Zickus | d32517e | 2015-06-04 09:22:41 -0400 | [diff] [blame] | 878 | write_vbus_chp_info(bdev->visorchannel, hdr_info, &chipset_driverinfo); |
| 879 | write_vbus_bus_info(bdev->visorchannel, hdr_info, |
| 880 | &clientbus_driverinfo); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 881 | } |
| 882 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 883 | /* |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 884 | * visordriver_probe_device() - handle new visor device coming online |
| 885 | * @xdev: struct device for the visor device being probed |
| 886 | * |
| 887 | * This is called automatically upon adding a visor_device (device_add), or |
| 888 | * adding a visor_driver (visorbus_register_visor_driver), but only after |
| 889 | * visorbus_match() has returned 1 to indicate a successful match between |
| 890 | * driver and device. |
| 891 | * |
| 892 | * If successful, a reference to the device will be held onto via get_device(). |
| 893 | * |
| 894 | * Return: 0 if successful, meaning the function driver's probe() function |
| 895 | * was successful with this device, otherwise a negative errno |
| 896 | * value indicating failure reason |
| 897 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 898 | static int visordriver_probe_device(struct device *xdev) |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 899 | { |
David Kershner | 61f38f9 | 2017-09-27 13:14:20 -0400 | [diff] [blame] | 900 | int err; |
David Kershner | 7f91228 | 2017-09-27 13:14:28 -0400 | [diff] [blame] | 901 | struct visor_driver *drv = to_visor_driver(xdev->driver); |
| 902 | struct visor_device *dev = to_visor_device(xdev); |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 903 | |
| 904 | mutex_lock(&dev->visordriver_callback_lock); |
| 905 | dev->being_removed = false; |
David Kershner | 61f38f9 | 2017-09-27 13:14:20 -0400 | [diff] [blame] | 906 | err = drv->probe(dev); |
| 907 | if (err) { |
| 908 | mutex_unlock(&dev->visordriver_callback_lock); |
| 909 | return err; |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 910 | } |
David Kershner | 61f38f9 | 2017-09-27 13:14:20 -0400 | [diff] [blame] | 911 | /* success: reference kept via unmatched get_device() */ |
| 912 | get_device(&dev->device); |
| 913 | publish_vbus_dev_info(dev); |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 914 | mutex_unlock(&dev->visordriver_callback_lock); |
David Kershner | 61f38f9 | 2017-09-27 13:14:20 -0400 | [diff] [blame] | 915 | return 0; |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 916 | } |
| 917 | |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 918 | /* |
David Kershner | 7915a3c | 2017-09-27 13:14:13 -0400 | [diff] [blame] | 919 | * visorbus_register_visor_driver() - registers the provided visor driver for |
| 920 | * handling one or more visor device |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 921 | * types (channel_types) |
| 922 | * @drv: the driver to register |
| 923 | * |
David Kershner | 7915a3c | 2017-09-27 13:14:13 -0400 | [diff] [blame] | 924 | * A visor function driver calls this function to register the driver. The |
| 925 | * caller MUST fill in the following fields within the #drv structure: |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 926 | * name, version, owner, channel_types, probe, remove |
| 927 | * |
| 928 | * Here's how the whole Linux bus / driver / device model works. |
| 929 | * |
| 930 | * At system start-up, the visorbus kernel module is loaded, which registers |
| 931 | * visorbus_type as a bus type, using bus_register(). |
| 932 | * |
| 933 | * All kernel modules that support particular device types on a |
| 934 | * visorbus bus are loaded. Each of these kernel modules calls |
| 935 | * visorbus_register_visor_driver() in their init functions, passing a |
| 936 | * visor_driver struct. visorbus_register_visor_driver() in turn calls |
| 937 | * register_driver(&visor_driver.driver). This .driver member is |
| 938 | * initialized with generic methods (like probe), whose sole responsibility |
| 939 | * is to act as a broker for the real methods, which are within the |
| 940 | * visor_driver struct. (This is the way the subclass behavior is |
| 941 | * implemented, since visor_driver is essentially a subclass of the |
| 942 | * generic driver.) Whenever a driver_register() happens, core bus code in |
| 943 | * the kernel does (see device_attach() in drivers/base/dd.c): |
| 944 | * |
| 945 | * for each dev associated with the bus (the bus that driver is on) that |
| 946 | * does not yet have a driver |
| 947 | * if bus.match(dev,newdriver) == yes_matched ** .match specified |
| 948 | * ** during bus_register(). |
| 949 | * newdriver.probe(dev) ** for visor drivers, this will call |
| 950 | * ** the generic driver.probe implemented in visorbus.c, |
| 951 | * ** which in turn calls the probe specified within the |
| 952 | * ** struct visor_driver (which was specified by the |
| 953 | * ** actual device driver as part of |
| 954 | * ** visorbus_register_visor_driver()). |
| 955 | * |
| 956 | * The above dance also happens when a new device appears. |
| 957 | * So the question is, how are devices created within the system? |
| 958 | * Basically, just call device_add(dev). See pci_bus_add_devices(). |
| 959 | * pci_scan_device() shows an example of how to build a device struct. It |
| 960 | * returns the newly-created struct to pci_scan_single_device(), who adds it |
| 961 | * to the list of devices at PCIBUS.devices. That list of devices is what |
| 962 | * is traversed by pci_bus_add_devices(). |
| 963 | * |
| 964 | * Return: integer indicating success (zero) or failure (non-zero) |
| 965 | */ |
| 966 | int visorbus_register_visor_driver(struct visor_driver *drv) |
| 967 | { |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 968 | /* can't register on a nonexistent bus */ |
David Kershner | b0512fa | 2017-03-31 14:20:12 -0400 | [diff] [blame] | 969 | if (!initialized) |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 970 | return -ENODEV; |
Sameer Wadgaonkar | c2d00b2 | 2017-07-17 16:16:59 -0400 | [diff] [blame] | 971 | if (!drv->probe) |
Sameer Wadgaonkar | 3459e83 | 2017-08-30 13:36:10 -0400 | [diff] [blame] | 972 | return -EINVAL; |
Sameer Wadgaonkar | c2d00b2 | 2017-07-17 16:16:59 -0400 | [diff] [blame] | 973 | if (!drv->remove) |
Sameer Wadgaonkar | 3459e83 | 2017-08-30 13:36:10 -0400 | [diff] [blame] | 974 | return -EINVAL; |
Sameer Wadgaonkar | c2d00b2 | 2017-07-17 16:16:59 -0400 | [diff] [blame] | 975 | if (!drv->pause) |
Sameer Wadgaonkar | 3459e83 | 2017-08-30 13:36:10 -0400 | [diff] [blame] | 976 | return -EINVAL; |
Sameer Wadgaonkar | c2d00b2 | 2017-07-17 16:16:59 -0400 | [diff] [blame] | 977 | if (!drv->resume) |
Sameer Wadgaonkar | 3459e83 | 2017-08-30 13:36:10 -0400 | [diff] [blame] | 978 | return -EINVAL; |
Sameer Wadgaonkar | c2d00b2 | 2017-07-17 16:16:59 -0400 | [diff] [blame] | 979 | |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 980 | drv->driver.name = drv->name; |
| 981 | drv->driver.bus = &visorbus_type; |
| 982 | drv->driver.probe = visordriver_probe_device; |
| 983 | drv->driver.remove = visordriver_remove_device; |
| 984 | drv->driver.owner = drv->owner; |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 985 | /* |
| 986 | * driver_register does this: |
| 987 | * bus_add_driver(drv) |
| 988 | * ->if (drv.bus) ** (bus_type) ** |
| 989 | * driver_attach(drv) |
| 990 | * for each dev with bus type of drv.bus |
| 991 | * if (!dev.drv) ** no driver assigned yet ** |
| 992 | * if (bus.match(dev,drv)) [visorbus_match] |
| 993 | * dev.drv = drv |
| 994 | * if (!drv.probe(dev)) [visordriver_probe_device] |
| 995 | * dev.drv = NULL |
| 996 | */ |
David Kershner | 293deb2 | 2017-03-28 09:34:52 -0400 | [diff] [blame] | 997 | return driver_register(&drv->driver); |
David Kershner | 7a0ee69 | 2016-09-19 17:09:36 -0400 | [diff] [blame] | 998 | } |
| 999 | EXPORT_SYMBOL_GPL(visorbus_register_visor_driver); |
| 1000 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 1001 | /* |
Sameer Wadgaonkar | 9e78fd3 | 2017-05-19 16:17:39 -0400 | [diff] [blame] | 1002 | * visorbus_create_instance() - create a device instance for the visorbus itself |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 1003 | * @dev: struct visor_device indicating the bus instance |
| 1004 | * |
| 1005 | * Return: 0 for success, otherwise negative errno value indicating reason for |
| 1006 | * failure |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1007 | */ |
David Kershner | fdf5b9a | 2017-08-22 13:27:24 -0400 | [diff] [blame] | 1008 | int visorbus_create_instance(struct visor_device *dev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1009 | { |
Don Zickus | d32517e | 2015-06-04 09:22:41 -0400 | [diff] [blame] | 1010 | int id = dev->chipset_bus_no; |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 1011 | int err; |
Sameer Wadgaonkar | 55c71eb | 2017-05-19 16:17:45 -0400 | [diff] [blame] | 1012 | struct visor_vbus_headerinfo *hdr_info; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1013 | |
Don Zickus | 7726f81 | 2015-06-01 13:00:28 -0400 | [diff] [blame] | 1014 | hdr_info = kzalloc(sizeof(*hdr_info), GFP_KERNEL); |
Benjamin Romer | c2c667d | 2016-02-23 10:01:52 -0500 | [diff] [blame] | 1015 | if (!hdr_info) |
| 1016 | return -ENOMEM; |
Don Zickus | 343506b | 2015-06-04 09:22:37 -0400 | [diff] [blame] | 1017 | dev_set_name(&dev->device, "visorbus%d", id); |
| 1018 | dev->device.bus = &visorbus_type; |
| 1019 | dev->device.groups = visorbus_groups; |
| 1020 | dev->device.release = visorbus_release_busdevice; |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 1021 | dev->debugfs_dir = debugfs_create_dir(dev_name(&dev->device), |
| 1022 | visorbus_debugfs_dir); |
David Kershner | 1c21800 | 2017-09-27 13:14:21 -0400 | [diff] [blame] | 1023 | dev->debugfs_bus_info = debugfs_create_file("client_bus_info", 0440, |
| 1024 | dev->debugfs_dir, dev, |
| 1025 | &bus_info_debugfs_fops); |
David Kershner | 362f87f | 2017-03-28 09:34:45 -0400 | [diff] [blame] | 1026 | dev_set_drvdata(&dev->device, dev); |
Sameer Wadgaonkar | e25201d | 2017-08-30 13:36:35 -0400 | [diff] [blame] | 1027 | err = get_vbus_header_info(dev->visorchannel, &dev->device, hdr_info); |
David Kershner | 362f87f | 2017-03-28 09:34:45 -0400 | [diff] [blame] | 1028 | if (err < 0) |
| 1029 | goto err_debugfs_dir; |
David Kershner | 362f87f | 2017-03-28 09:34:45 -0400 | [diff] [blame] | 1030 | err = device_register(&dev->device); |
David Kershner | 450333f | 2017-04-18 16:55:11 -0400 | [diff] [blame] | 1031 | if (err < 0) |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 1032 | goto err_debugfs_dir; |
Don Zickus | 343506b | 2015-06-04 09:22:37 -0400 | [diff] [blame] | 1033 | list_add_tail(&dev->list_all, &list_all_bus_instances); |
David Kershner | fdf5b9a | 2017-08-22 13:27:24 -0400 | [diff] [blame] | 1034 | dev->state.created = 1; |
David Kershner | 362f87f | 2017-03-28 09:34:45 -0400 | [diff] [blame] | 1035 | dev->vbus_hdr_info = (void *)hdr_info; |
David Kershner | 9f1d28f | 2017-09-27 13:14:18 -0400 | [diff] [blame] | 1036 | write_vbus_chp_info(dev->visorchannel, hdr_info, &chipset_driverinfo); |
| 1037 | write_vbus_bus_info(dev->visorchannel, hdr_info, &clientbus_driverinfo); |
David Kershner | fdf5b9a | 2017-08-22 13:27:24 -0400 | [diff] [blame] | 1038 | visorbus_response(dev, err, CONTROLVM_BUS_CREATE); |
David Kershner | 362f87f | 2017-03-28 09:34:45 -0400 | [diff] [blame] | 1039 | return 0; |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 1040 | |
| 1041 | err_debugfs_dir: |
| 1042 | debugfs_remove_recursive(dev->debugfs_dir); |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 1043 | kfree(hdr_info); |
Zachary Dremann | 23d01c4 | 2017-07-17 16:16:41 -0400 | [diff] [blame] | 1044 | dev_err(&dev->device, "%s failed: %d\n", __func__, err); |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 1045 | return err; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1046 | } |
| 1047 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 1048 | /* |
Sameer Wadgaonkar | 9e78fd3 | 2017-05-19 16:17:39 -0400 | [diff] [blame] | 1049 | * visorbus_remove_instance() - remove a device instance for the visorbus itself |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 1050 | * @dev: struct visor_device indentifying the bus to remove |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1051 | */ |
Sameer Wadgaonkar | a7093ba | 2017-08-22 13:27:33 -0400 | [diff] [blame] | 1052 | void visorbus_remove_instance(struct visor_device *dev) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1053 | { |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 1054 | /* |
| 1055 | * Note that this will result in the release method for |
Don Zickus | 343506b | 2015-06-04 09:22:37 -0400 | [diff] [blame] | 1056 | * dev->dev being called, which will call |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1057 | * visorbus_release_busdevice(). This has something to do with |
| 1058 | * the put_device() done in device_unregister(), but I have never |
| 1059 | * successfully been able to trace thru the code to see where/how |
| 1060 | * release() gets called. But I know it does. |
| 1061 | */ |
Don Zickus | 343506b | 2015-06-04 09:22:37 -0400 | [diff] [blame] | 1062 | kfree(dev->vbus_hdr_info); |
| 1063 | list_del(&dev->list_all); |
David Kershner | ae54a28 | 2017-09-27 13:14:17 -0400 | [diff] [blame] | 1064 | if (dev->pending_msg_hdr) |
| 1065 | visorbus_response(dev, 0, CONTROLVM_BUS_DESTROY); |
Don Zickus | 343506b | 2015-06-04 09:22:37 -0400 | [diff] [blame] | 1066 | device_unregister(&dev->device); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1067 | } |
| 1068 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 1069 | /* |
Sameer Wadgaonkar | 9e78fd3 | 2017-05-19 16:17:39 -0400 | [diff] [blame] | 1070 | * remove_all_visor_devices() - remove all child visorbus device instances |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1071 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 1072 | static void remove_all_visor_devices(void) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1073 | { |
| 1074 | struct list_head *listentry, *listtmp; |
| 1075 | |
| 1076 | list_for_each_safe(listentry, listtmp, &list_all_device_instances) { |
David Kershner | 17e4bdd | 2017-09-27 13:14:15 -0400 | [diff] [blame] | 1077 | struct visor_device *dev; |
| 1078 | |
| 1079 | dev = list_entry(listentry, struct visor_device, list_all); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1080 | remove_visor_device(dev); |
| 1081 | } |
| 1082 | } |
| 1083 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 1084 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 1085 | * pause_state_change_complete() - the callback function to be called by a |
| 1086 | * visorbus function driver when a |
| 1087 | * pending "pause device" operation has |
| 1088 | * completed |
| 1089 | * @dev: struct visor_device identifying the paused device |
| 1090 | * @status: 0 iff the pause state change completed successfully, otherwise |
| 1091 | * a negative errno value indicating the reason for failure |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1092 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 1093 | static void pause_state_change_complete(struct visor_device *dev, int status) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1094 | { |
| 1095 | if (!dev->pausing) |
Christophe JAILLET | 216c3e2 | 2015-07-13 20:52:26 +0200 | [diff] [blame] | 1096 | return; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1097 | |
Prarit Bhargava | 779d075 | 2015-05-05 18:37:01 -0400 | [diff] [blame] | 1098 | dev->pausing = false; |
Sameer Wadgaonkar | 722e73d | 2017-08-22 13:27:04 -0400 | [diff] [blame] | 1099 | visorbus_device_changestate_response(dev, status, |
| 1100 | segment_state_standby); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 1103 | /* |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 1104 | * resume_state_change_complete() - the callback function to be called by a |
| 1105 | * visorbus function driver when a |
| 1106 | * pending "resume device" operation has |
| 1107 | * completed |
| 1108 | * @dev: struct visor_device identifying the resumed device |
| 1109 | * @status: 0 iff the resume state change completed successfully, otherwise |
| 1110 | * a negative errno value indicating the reason for failure |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1111 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 1112 | static void resume_state_change_complete(struct visor_device *dev, int status) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1113 | { |
| 1114 | if (!dev->resuming) |
Christophe JAILLET | 216c3e2 | 2015-07-13 20:52:26 +0200 | [diff] [blame] | 1115 | return; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1116 | |
Prarit Bhargava | 779d075 | 2015-05-05 18:37:01 -0400 | [diff] [blame] | 1117 | dev->resuming = false; |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 1118 | /* |
| 1119 | * Notify the chipset driver that the resume is complete, |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1120 | * which will presumably want to send some sort of response to |
Gavin O'Leary | 4811789 | 2015-11-09 20:12:00 -0800 | [diff] [blame] | 1121 | * the initiator. |
| 1122 | */ |
Sameer Wadgaonkar | 722e73d | 2017-08-22 13:27:04 -0400 | [diff] [blame] | 1123 | visorbus_device_changestate_response(dev, status, |
| 1124 | segment_state_running); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1125 | } |
| 1126 | |
David Binder | b84be59 | 2017-02-21 12:53:24 -0500 | [diff] [blame] | 1127 | /* |
Sameer Wadgaonkar | 451072e | 2017-05-19 16:17:42 -0400 | [diff] [blame] | 1128 | * visorchipset_initiate_device_pause_resume() - start a pause or resume |
| 1129 | * operation for a visor device |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 1130 | * @dev: struct visor_device identifying the device being paused or resumed |
| 1131 | * @is_pause: true to indicate pause operation, false to indicate resume |
| 1132 | * |
| 1133 | * Tell the subordinate function driver for a specific device to pause |
| 1134 | * or resume that device. Success/failure result is returned asynchronously |
| 1135 | * via a callback function; see pause_state_change_complete() and |
| 1136 | * resume_state_change_complete(). |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1137 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 1138 | static int visorchipset_initiate_device_pause_resume(struct visor_device *dev, |
| 1139 | bool is_pause) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1140 | { |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1141 | int err; |
David Kershner | 473659d | 2017-09-27 13:14:24 -0400 | [diff] [blame] | 1142 | struct visor_driver *drv; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1143 | |
David Kershner | 68f4f76 | 2017-08-30 13:36:17 -0400 | [diff] [blame] | 1144 | /* If no driver associated with the device nothing to pause/resume */ |
| 1145 | if (!dev->device.driver) |
| 1146 | return 0; |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1147 | if (dev->pausing || dev->resuming) |
| 1148 | return -EBUSY; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1149 | |
David Kershner | 68f4f76 | 2017-08-30 13:36:17 -0400 | [diff] [blame] | 1150 | drv = to_visor_driver(dev->device.driver); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1151 | if (is_pause) { |
Prarit Bhargava | 779d075 | 2015-05-05 18:37:01 -0400 | [diff] [blame] | 1152 | dev->pausing = true; |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1153 | err = drv->pause(dev, pause_state_change_complete); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1154 | } else { |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 1155 | /* |
| 1156 | * The vbus_dev_info structure in the channel was been cleared, |
| 1157 | * make sure it is valid. |
Gavin O'Leary | 4811789 | 2015-11-09 20:12:00 -0800 | [diff] [blame] | 1158 | */ |
Erik Arfvidson | e3b2ed6 | 2017-07-17 16:17:07 -0400 | [diff] [blame] | 1159 | publish_vbus_dev_info(dev); |
Prarit Bhargava | 779d075 | 2015-05-05 18:37:01 -0400 | [diff] [blame] | 1160 | dev->resuming = true; |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1161 | err = drv->resume(dev, resume_state_change_complete); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1162 | } |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1163 | return err; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1164 | } |
| 1165 | |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 1166 | /* |
Sameer Wadgaonkar | c0b4413 | 2017-05-19 16:17:41 -0400 | [diff] [blame] | 1167 | * visorchipset_device_pause() - start a pause operation for a visor device |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 1168 | * @dev_info: struct visor_device identifying the device being paused |
| 1169 | * |
| 1170 | * Tell the subordinate function driver for a specific device to pause |
| 1171 | * that device. Success/failure result is returned asynchronously |
| 1172 | * via a callback function; see pause_state_change_complete(). |
| 1173 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 1174 | int visorchipset_device_pause(struct visor_device *dev_info) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1175 | { |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1176 | int err; |
| 1177 | |
Sameer Wadgaonkar | 451072e | 2017-05-19 16:17:42 -0400 | [diff] [blame] | 1178 | err = visorchipset_initiate_device_pause_resume(dev_info, true); |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1179 | if (err < 0) { |
| 1180 | dev_info->pausing = false; |
David Kershner | b4a8e6a | 2017-03-28 09:34:54 -0400 | [diff] [blame] | 1181 | return err; |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1182 | } |
David Kershner | b4a8e6a | 2017-03-28 09:34:54 -0400 | [diff] [blame] | 1183 | return 0; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1184 | } |
| 1185 | |
Sameer Wadgaonkar | 060b293 | 2017-06-30 15:43:05 -0400 | [diff] [blame] | 1186 | /* |
Sameer Wadgaonkar | c0b4413 | 2017-05-19 16:17:41 -0400 | [diff] [blame] | 1187 | * visorchipset_device_resume() - start a resume operation for a visor device |
David Binder | 3fd1b3b | 2016-06-10 21:48:16 -0400 | [diff] [blame] | 1188 | * @dev_info: struct visor_device identifying the device being resumed |
| 1189 | * |
| 1190 | * Tell the subordinate function driver for a specific device to resume |
| 1191 | * that device. Success/failure result is returned asynchronously |
| 1192 | * via a callback function; see resume_state_change_complete(). |
| 1193 | */ |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 1194 | int visorchipset_device_resume(struct visor_device *dev_info) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1195 | { |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1196 | int err; |
| 1197 | |
Sameer Wadgaonkar | 451072e | 2017-05-19 16:17:42 -0400 | [diff] [blame] | 1198 | err = visorchipset_initiate_device_pause_resume(dev_info, false); |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1199 | if (err < 0) { |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1200 | dev_info->resuming = false; |
David Kershner | b4a8e6a | 2017-03-28 09:34:54 -0400 | [diff] [blame] | 1201 | return err; |
David Kershner | 15d9ce9 | 2017-03-28 09:34:53 -0400 | [diff] [blame] | 1202 | } |
David Kershner | b4a8e6a | 2017-03-28 09:34:54 -0400 | [diff] [blame] | 1203 | return 0; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1204 | } |
| 1205 | |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 1206 | int visorbus_init(void) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1207 | { |
David Kershner | 78af1ae | 2016-03-12 21:27:10 -0500 | [diff] [blame] | 1208 | int err; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1209 | |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 1210 | visorbus_debugfs_dir = debugfs_create_dir("visorbus", NULL); |
Jon Frisch | e82ed63 | 2016-09-26 11:03:41 -0400 | [diff] [blame] | 1211 | bus_device_info_init(&clientbus_driverinfo, "clientbus", "visorbus"); |
David Kershner | 5b6f9b9 | 2017-03-28 09:34:46 -0400 | [diff] [blame] | 1212 | err = bus_register(&visorbus_type); |
David Kershner | 804aab3 | 2017-04-18 16:55:15 -0400 | [diff] [blame] | 1213 | if (err < 0) |
| 1214 | return err; |
David Kershner | b0512fa | 2017-03-31 14:20:12 -0400 | [diff] [blame] | 1215 | initialized = true; |
Jon Frisch | e82ed63 | 2016-09-26 11:03:41 -0400 | [diff] [blame] | 1216 | bus_device_info_init(&chipset_driverinfo, "chipset", "visorchipset"); |
David Kershner | 78af1ae | 2016-03-12 21:27:10 -0500 | [diff] [blame] | 1217 | return 0; |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1218 | } |
| 1219 | |
Sameer Wadgaonkar | baf9b70 | 2017-07-17 16:16:57 -0400 | [diff] [blame] | 1220 | void visorbus_exit(void) |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1221 | { |
| 1222 | struct list_head *listentry, *listtmp; |
| 1223 | |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1224 | remove_all_visor_devices(); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1225 | list_for_each_safe(listentry, listtmp, &list_all_bus_instances) { |
David Kershner | 17e4bdd | 2017-09-27 13:14:15 -0400 | [diff] [blame] | 1226 | struct visor_device *dev; |
| 1227 | |
| 1228 | dev = list_entry(listentry, struct visor_device, list_all); |
Sameer Wadgaonkar | 9e78fd3 | 2017-05-19 16:17:39 -0400 | [diff] [blame] | 1229 | visorbus_remove_instance(dev); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1230 | } |
David Kershner | 5b6f9b9 | 2017-03-28 09:34:46 -0400 | [diff] [blame] | 1231 | bus_unregister(&visorbus_type); |
David Kershner | b0512fa | 2017-03-31 14:20:12 -0400 | [diff] [blame] | 1232 | initialized = false; |
Tim Sell | 8217bec | 2016-11-03 11:44:16 -0400 | [diff] [blame] | 1233 | debugfs_remove_recursive(visorbus_debugfs_dir); |
Erik Arfvidson | 3703987cd | 2015-05-05 18:36:00 -0400 | [diff] [blame] | 1234 | } |