blob: 48230a5e12f262b67d28d87adc713f462e8ec5fc [file] [log] [blame]
Rusty Russellec3d41c2007-10-22 11:03:36 +10001#include <linux/virtio.h>
2#include <linux/spinlock.h>
3#include <linux/virtio_config.h>
Paul Gortmakerb5a2c4f2011-07-03 16:20:30 -04004#include <linux/module.h>
Asias He90e03202012-05-03 10:20:51 +08005#include <linux/idr.h>
Michael S. Tsirkinb6098c32014-12-04 18:49:58 +02006#include <uapi/linux/virtio_ids.h>
Rusty Russellec3d41c2007-10-22 11:03:36 +10007
Rusty Russellb769f572008-05-30 15:09:42 -05008/* Unique numbering for virtio devices. */
Asias He90e03202012-05-03 10:20:51 +08009static DEFINE_IDA(virtio_index_ida);
Rusty Russellb769f572008-05-30 15:09:42 -050010
Rusty Russellec3d41c2007-10-22 11:03:36 +100011static ssize_t device_show(struct device *_d,
12 struct device_attribute *attr, char *buf)
13{
Wanlong Gao9bffdca2012-12-11 11:04:50 +103014 struct virtio_device *dev = dev_to_virtio(_d);
Stephen Hemmingerbe6528b2010-11-09 22:20:29 -080015 return sprintf(buf, "0x%04x\n", dev->id.device);
Rusty Russellec3d41c2007-10-22 11:03:36 +100016}
Greg Kroah-Hartman3736dab2013-10-07 18:27:39 -070017static DEVICE_ATTR_RO(device);
18
Rusty Russellec3d41c2007-10-22 11:03:36 +100019static ssize_t vendor_show(struct device *_d,
20 struct device_attribute *attr, char *buf)
21{
Wanlong Gao9bffdca2012-12-11 11:04:50 +103022 struct virtio_device *dev = dev_to_virtio(_d);
Stephen Hemmingerbe6528b2010-11-09 22:20:29 -080023 return sprintf(buf, "0x%04x\n", dev->id.vendor);
Rusty Russellec3d41c2007-10-22 11:03:36 +100024}
Greg Kroah-Hartman3736dab2013-10-07 18:27:39 -070025static DEVICE_ATTR_RO(vendor);
26
Rusty Russellec3d41c2007-10-22 11:03:36 +100027static ssize_t status_show(struct device *_d,
28 struct device_attribute *attr, char *buf)
29{
Wanlong Gao9bffdca2012-12-11 11:04:50 +103030 struct virtio_device *dev = dev_to_virtio(_d);
Stephen Hemmingerbe6528b2010-11-09 22:20:29 -080031 return sprintf(buf, "0x%08x\n", dev->config->get_status(dev));
Rusty Russellec3d41c2007-10-22 11:03:36 +100032}
Greg Kroah-Hartman3736dab2013-10-07 18:27:39 -070033static DEVICE_ATTR_RO(status);
34
Rusty Russellb01d9f22007-10-22 11:03:39 +100035static ssize_t modalias_show(struct device *_d,
36 struct device_attribute *attr, char *buf)
37{
Wanlong Gao9bffdca2012-12-11 11:04:50 +103038 struct virtio_device *dev = dev_to_virtio(_d);
Rusty Russellb01d9f22007-10-22 11:03:39 +100039 return sprintf(buf, "virtio:d%08Xv%08X\n",
40 dev->id.device, dev->id.vendor);
41}
Greg Kroah-Hartman3736dab2013-10-07 18:27:39 -070042static DEVICE_ATTR_RO(modalias);
43
Rusty Russella9289282009-06-12 22:16:37 -060044static ssize_t features_show(struct device *_d,
45 struct device_attribute *attr, char *buf)
46{
Wanlong Gao9bffdca2012-12-11 11:04:50 +103047 struct virtio_device *dev = dev_to_virtio(_d);
Rusty Russella9289282009-06-12 22:16:37 -060048 unsigned int i;
49 ssize_t len = 0;
50
51 /* We actually represent this as a bitstring, as it could be
52 * arbitrary length in future. */
Michael S. Tsirkine16e12b2014-10-07 16:39:42 +020053 for (i = 0; i < sizeof(dev->features)*8; i++)
Rusty Russella9289282009-06-12 22:16:37 -060054 len += sprintf(buf+len, "%c",
Michael S. Tsirkine16e12b2014-10-07 16:39:42 +020055 __virtio_test_bit(dev, i) ? '1' : '0');
Rusty Russella9289282009-06-12 22:16:37 -060056 len += sprintf(buf+len, "\n");
57 return len;
58}
Greg Kroah-Hartman3736dab2013-10-07 18:27:39 -070059static DEVICE_ATTR_RO(features);
60
61static struct attribute *virtio_dev_attrs[] = {
62 &dev_attr_device.attr,
63 &dev_attr_vendor.attr,
64 &dev_attr_status.attr,
65 &dev_attr_modalias.attr,
66 &dev_attr_features.attr,
67 NULL,
Rusty Russellec3d41c2007-10-22 11:03:36 +100068};
Greg Kroah-Hartman3736dab2013-10-07 18:27:39 -070069ATTRIBUTE_GROUPS(virtio_dev);
Rusty Russellec3d41c2007-10-22 11:03:36 +100070
71static inline int virtio_id_match(const struct virtio_device *dev,
72 const struct virtio_device_id *id)
73{
Christian Borntraegere3353852009-05-26 15:46:10 +020074 if (id->device != dev->id.device && id->device != VIRTIO_DEV_ANY_ID)
Rusty Russellec3d41c2007-10-22 11:03:36 +100075 return 0;
76
Christian Borntraegerc89e8012009-05-26 15:46:09 +020077 return id->vendor == VIRTIO_DEV_ANY_ID || id->vendor == dev->id.vendor;
Rusty Russellec3d41c2007-10-22 11:03:36 +100078}
79
80/* This looks through all the IDs a driver claims to support. If any of them
81 * match, we return 1 and the kernel will call virtio_dev_probe(). */
82static int virtio_dev_match(struct device *_dv, struct device_driver *_dr)
83{
84 unsigned int i;
Wanlong Gao9bffdca2012-12-11 11:04:50 +103085 struct virtio_device *dev = dev_to_virtio(_dv);
Rusty Russellec3d41c2007-10-22 11:03:36 +100086 const struct virtio_device_id *ids;
87
Wanlong Gao9a2bdcc2012-12-10 16:38:33 +080088 ids = drv_to_virtio(_dr)->id_table;
Rusty Russellec3d41c2007-10-22 11:03:36 +100089 for (i = 0; ids[i].device; i++)
90 if (virtio_id_match(dev, &ids[i]))
91 return 1;
92 return 0;
93}
94
Rusty Russellb01d9f22007-10-22 11:03:39 +100095static int virtio_uevent(struct device *_dv, struct kobj_uevent_env *env)
96{
Wanlong Gao9bffdca2012-12-11 11:04:50 +103097 struct virtio_device *dev = dev_to_virtio(_dv);
Rusty Russellb01d9f22007-10-22 11:03:39 +100098
99 return add_uevent_var(env, "MODALIAS=virtio:d%08Xv%08X",
100 dev->id.device, dev->id.vendor);
101}
102
Rusty Russellc45a6812008-05-02 21:50:50 -0500103void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
104 unsigned int fbit)
105{
106 unsigned int i;
Wanlong Gao9a2bdcc2012-12-10 16:38:33 +0800107 struct virtio_driver *drv = drv_to_virtio(vdev->dev.driver);
Rusty Russellc45a6812008-05-02 21:50:50 -0500108
109 for (i = 0; i < drv->feature_table_size; i++)
110 if (drv->feature_table[i] == fbit)
111 return;
Michael S. Tsirkinb3bb62d2014-10-23 18:07:47 +0300112
113 if (drv->feature_table_legacy) {
114 for (i = 0; i < drv->feature_table_size_legacy; i++)
115 if (drv->feature_table_legacy[i] == fbit)
116 return;
117 }
118
Rusty Russellc45a6812008-05-02 21:50:50 -0500119 BUG();
120}
121EXPORT_SYMBOL_GPL(virtio_check_driver_offered_feature);
122
Michael S. Tsirkin22b70502014-10-15 10:21:55 +1030123static void __virtio_config_changed(struct virtio_device *dev)
124{
125 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
126
127 if (!dev->config_enabled)
128 dev->config_change_pending = true;
129 else if (drv && drv->config_changed)
130 drv->config_changed(dev);
131}
132
133void virtio_config_changed(struct virtio_device *dev)
134{
135 unsigned long flags;
136
137 spin_lock_irqsave(&dev->config_lock, flags);
138 __virtio_config_changed(dev);
139 spin_unlock_irqrestore(&dev->config_lock, flags);
140}
141EXPORT_SYMBOL_GPL(virtio_config_changed);
142
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800143void virtio_config_disable(struct virtio_device *dev)
Michael S. Tsirkin22b70502014-10-15 10:21:55 +1030144{
145 spin_lock_irq(&dev->config_lock);
146 dev->config_enabled = false;
147 spin_unlock_irq(&dev->config_lock);
148}
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800149EXPORT_SYMBOL_GPL(virtio_config_disable);
Michael S. Tsirkin22b70502014-10-15 10:21:55 +1030150
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800151void virtio_config_enable(struct virtio_device *dev)
Michael S. Tsirkin22b70502014-10-15 10:21:55 +1030152{
153 spin_lock_irq(&dev->config_lock);
154 dev->config_enabled = true;
155 if (dev->config_change_pending)
156 __virtio_config_changed(dev);
157 dev->config_change_pending = false;
158 spin_unlock_irq(&dev->config_lock);
159}
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800160EXPORT_SYMBOL_GPL(virtio_config_enable);
Michael S. Tsirkin22b70502014-10-15 10:21:55 +1030161
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800162void virtio_add_status(struct virtio_device *dev, unsigned int status)
163{
164 dev->config->set_status(dev, dev->config->get_status(dev) | status);
165}
166EXPORT_SYMBOL_GPL(virtio_add_status);
167
168int virtio_finalize_features(struct virtio_device *dev)
Michael S. Tsirkin30683a82014-12-11 13:37:13 +0200169{
170 int ret = dev->config->finalize_features(dev);
171 unsigned status;
172
173 if (ret)
174 return ret;
175
176 if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
177 return 0;
178
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800179 virtio_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
Michael S. Tsirkin30683a82014-12-11 13:37:13 +0200180 status = dev->config->get_status(dev);
181 if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
182 dev_err(&dev->dev, "virtio: device refuses features: %x\n",
183 status);
184 return -ENODEV;
185 }
186 return 0;
187}
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800188EXPORT_SYMBOL_GPL(virtio_finalize_features);
Michael S. Tsirkin30683a82014-12-11 13:37:13 +0200189
Rusty Russellec3d41c2007-10-22 11:03:36 +1000190static int virtio_dev_probe(struct device *_d)
191{
Rusty Russellc45a6812008-05-02 21:50:50 -0500192 int err, i;
Wanlong Gao9bffdca2012-12-11 11:04:50 +1030193 struct virtio_device *dev = dev_to_virtio(_d);
Wanlong Gao9a2bdcc2012-12-10 16:38:33 +0800194 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200195 u64 device_features;
Michael S. Tsirkinc1026592014-10-23 17:57:30 +0300196 u64 driver_features;
Michael S. Tsirkinb3bb62d2014-10-23 18:07:47 +0300197 u64 driver_features_legacy;
Rusty Russellec3d41c2007-10-22 11:03:36 +1000198
Rusty Russellc45a6812008-05-02 21:50:50 -0500199 /* We have a driver! */
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800200 virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER);
Rusty Russellc45a6812008-05-02 21:50:50 -0500201
202 /* Figure out what features the device supports. */
203 device_features = dev->config->get_features(dev);
204
Michael S. Tsirkinc1026592014-10-23 17:57:30 +0300205 /* Figure out what features the driver supports. */
206 driver_features = 0;
Rusty Russellc45a6812008-05-02 21:50:50 -0500207 for (i = 0; i < drv->feature_table_size; i++) {
208 unsigned int f = drv->feature_table[i];
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200209 BUG_ON(f >= 64);
Michael S. Tsirkinc1026592014-10-23 17:57:30 +0300210 driver_features |= (1ULL << f);
Rusty Russellc45a6812008-05-02 21:50:50 -0500211 }
212
Michael S. Tsirkinb3bb62d2014-10-23 18:07:47 +0300213 /* Some drivers have a separate feature table for virtio v1.0 */
214 if (drv->feature_table_legacy) {
215 driver_features_legacy = 0;
216 for (i = 0; i < drv->feature_table_size_legacy; i++) {
217 unsigned int f = drv->feature_table_legacy[i];
218 BUG_ON(f >= 64);
219 driver_features_legacy |= (1ULL << f);
220 }
221 } else {
222 driver_features_legacy = driver_features;
223 }
224
Michael S. Tsirkin747ae342014-12-01 15:52:40 +0200225 if (device_features & (1ULL << VIRTIO_F_VERSION_1))
Michael S. Tsirkinb3bb62d2014-10-23 18:07:47 +0300226 dev->features = driver_features & device_features;
227 else
228 dev->features = driver_features_legacy & device_features;
Michael S. Tsirkinc1026592014-10-23 17:57:30 +0300229
Rusty Russellc6248962008-07-25 12:06:07 -0500230 /* Transport features always preserved to pass to finalize_features. */
Rusty Russelldd7c7bc2008-07-25 12:06:07 -0500231 for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++)
Michael S. Tsirkind0254772014-10-07 16:39:43 +0200232 if (device_features & (1ULL << i))
Michael S. Tsirkine16e12b2014-10-07 16:39:42 +0200233 __virtio_set_bit(dev, i);
Rusty Russelldd7c7bc2008-07-25 12:06:07 -0500234
Michael S. Tsirkin404123c2017-03-29 19:06:20 +0300235 if (drv->validate) {
236 err = drv->validate(dev);
237 if (err)
238 goto err;
239 }
240
Michael S. Tsirkin30683a82014-12-11 13:37:13 +0200241 err = virtio_finalize_features(dev);
Michael S. Tsirkin5c609a52014-12-04 20:20:27 +0200242 if (err)
243 goto err;
Rusty Russellef688e12009-06-12 22:16:35 -0600244
Michael S. Tsirkincb3f6d92014-10-22 17:41:38 +0300245 err = drv->probe(dev);
246 if (err)
247 goto err;
248
Rusty Russell5b40a7d2015-02-17 16:12:44 +1030249 /* If probe didn't do it, mark device DRIVER_OK ourselves. */
250 if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
251 virtio_device_ready(dev);
252
Michael S. Tsirkincb3f6d92014-10-22 17:41:38 +0300253 if (drv->scan)
254 drv->scan(dev);
255
256 virtio_config_enable(dev);
257
258 return 0;
259err:
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800260 virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
Rusty Russellec3d41c2007-10-22 11:03:36 +1000261 return err;
Michael S. Tsirkincb3f6d92014-10-22 17:41:38 +0300262
Rusty Russellec3d41c2007-10-22 11:03:36 +1000263}
264
Rusty Russell74b25532007-11-19 11:20:42 -0500265static int virtio_dev_remove(struct device *_d)
266{
Wanlong Gao9bffdca2012-12-11 11:04:50 +1030267 struct virtio_device *dev = dev_to_virtio(_d);
Wanlong Gao9a2bdcc2012-12-10 16:38:33 +0800268 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
Rusty Russell74b25532007-11-19 11:20:42 -0500269
Michael S. Tsirkin22b70502014-10-15 10:21:55 +1030270 virtio_config_disable(dev);
271
Rusty Russell74b25532007-11-19 11:20:42 -0500272 drv->remove(dev);
Rusty Russell6e5aa7e2008-02-04 23:50:03 -0500273
274 /* Driver should have reset device. */
Michael S. Tsirkin5543a6a2012-09-28 15:05:16 +0930275 WARN_ON_ONCE(dev->config->get_status(dev));
Rusty Russell6e5aa7e2008-02-04 23:50:03 -0500276
277 /* Acknowledge the device's existence again. */
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800278 virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
Rusty Russell74b25532007-11-19 11:20:42 -0500279 return 0;
280}
281
Mark McLoughline962fa662008-06-13 13:46:40 +0100282static struct bus_type virtio_bus = {
283 .name = "virtio",
284 .match = virtio_dev_match,
Greg Kroah-Hartman3736dab2013-10-07 18:27:39 -0700285 .dev_groups = virtio_dev_groups,
Mark McLoughline962fa662008-06-13 13:46:40 +0100286 .uevent = virtio_uevent,
287 .probe = virtio_dev_probe,
288 .remove = virtio_dev_remove,
289};
290
Rusty Russellec3d41c2007-10-22 11:03:36 +1000291int register_virtio_driver(struct virtio_driver *driver)
292{
Rusty Russellc45a6812008-05-02 21:50:50 -0500293 /* Catch this early. */
294 BUG_ON(driver->feature_table_size && !driver->feature_table);
Rusty Russellec3d41c2007-10-22 11:03:36 +1000295 driver->driver.bus = &virtio_bus;
Rusty Russellec3d41c2007-10-22 11:03:36 +1000296 return driver_register(&driver->driver);
297}
298EXPORT_SYMBOL_GPL(register_virtio_driver);
299
300void unregister_virtio_driver(struct virtio_driver *driver)
301{
302 driver_unregister(&driver->driver);
303}
304EXPORT_SYMBOL_GPL(unregister_virtio_driver);
305
306int register_virtio_device(struct virtio_device *dev)
307{
308 int err;
309
310 dev->dev.bus = &virtio_bus;
Rusty Russellb769f572008-05-30 15:09:42 -0500311
312 /* Assign a unique device index and hence name. */
Asias He90e03202012-05-03 10:20:51 +0800313 err = ida_simple_get(&virtio_index_ida, 0, 0, GFP_KERNEL);
314 if (err < 0)
315 goto out;
316
317 dev->index = err;
Kay Sievers99e0b6c2008-12-30 09:25:56 -0600318 dev_set_name(&dev->dev, "virtio%u", dev->index);
Rusty Russellec3d41c2007-10-22 11:03:36 +1000319
Michael S. Tsirkin22b70502014-10-15 10:21:55 +1030320 spin_lock_init(&dev->config_lock);
321 dev->config_enabled = false;
322 dev->config_change_pending = false;
323
Rusty Russell6e5aa7e2008-02-04 23:50:03 -0500324 /* We always start by resetting the device, in case a previous
325 * driver messed it up. This also tests that code path a little. */
326 dev->config->reset(dev);
327
Rusty Russellec3d41c2007-10-22 11:03:36 +1000328 /* Acknowledge that we've seen the device. */
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800329 virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
Rusty Russellec3d41c2007-10-22 11:03:36 +1000330
Rusty Russell9499f5e2009-06-12 22:16:35 -0600331 INIT_LIST_HEAD(&dev->vqs);
332
Rusty Russellec3d41c2007-10-22 11:03:36 +1000333 /* device_register() causes the bus infrastructure to look for a
334 * matching driver. */
335 err = device_register(&dev->dev);
Asias He90e03202012-05-03 10:20:51 +0800336out:
Rusty Russellec3d41c2007-10-22 11:03:36 +1000337 if (err)
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800338 virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
Rusty Russellec3d41c2007-10-22 11:03:36 +1000339 return err;
340}
341EXPORT_SYMBOL_GPL(register_virtio_device);
342
343void unregister_virtio_device(struct virtio_device *dev)
344{
Cornelia Huck237242b2012-11-09 14:54:12 +1030345 int index = dev->index; /* save for after device release */
346
Rusty Russellec3d41c2007-10-22 11:03:36 +1000347 device_unregister(&dev->dev);
Cornelia Huck237242b2012-11-09 14:54:12 +1030348 ida_simple_remove(&virtio_index_ida, index);
Rusty Russellec3d41c2007-10-22 11:03:36 +1000349}
350EXPORT_SYMBOL_GPL(unregister_virtio_device);
351
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030352#ifdef CONFIG_PM_SLEEP
353int virtio_device_freeze(struct virtio_device *dev)
354{
355 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
356
Michael S. Tsirkin22b70502014-10-15 10:21:55 +1030357 virtio_config_disable(dev);
358
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030359 dev->failed = dev->config->get_status(dev) & VIRTIO_CONFIG_S_FAILED;
360
361 if (drv && drv->freeze)
362 return drv->freeze(dev);
363
364 return 0;
365}
366EXPORT_SYMBOL_GPL(virtio_device_freeze);
367
368int virtio_device_restore(struct virtio_device *dev)
369{
370 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
Michael S. Tsirkin5c609a52014-12-04 20:20:27 +0200371 int ret;
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030372
373 /* We always start by resetting the device, in case a previous
374 * driver messed it up. */
375 dev->config->reset(dev);
376
377 /* Acknowledge that we've seen the device. */
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800378 virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030379
380 /* Maybe driver failed before freeze.
381 * Restore the failed status, for debugging. */
382 if (dev->failed)
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800383 virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030384
385 if (!drv)
386 return 0;
387
388 /* We have a driver! */
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800389 virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER);
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030390
Michael S. Tsirkin30683a82014-12-11 13:37:13 +0200391 ret = virtio_finalize_features(dev);
Michael S. Tsirkin5c609a52014-12-04 20:20:27 +0200392 if (ret)
393 goto err;
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030394
395 if (drv->restore) {
Michael S. Tsirkin5c609a52014-12-04 20:20:27 +0200396 ret = drv->restore(dev);
397 if (ret)
398 goto err;
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030399 }
400
401 /* Finally, tell the device we're all set */
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800402 virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030403
Michael S. Tsirkin22b70502014-10-15 10:21:55 +1030404 virtio_config_enable(dev);
405
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030406 return 0;
Michael S. Tsirkin5c609a52014-12-04 20:20:27 +0200407
408err:
John Fastabend9fe7bfc2017-02-02 19:16:01 -0800409 virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
Michael S. Tsirkin5c609a52014-12-04 20:20:27 +0200410 return ret;
Michael S. Tsirkinc6716ba2014-10-14 10:40:35 +1030411}
412EXPORT_SYMBOL_GPL(virtio_device_restore);
413#endif
414
Rusty Russellec3d41c2007-10-22 11:03:36 +1000415static int virtio_init(void)
416{
417 if (bus_register(&virtio_bus) != 0)
418 panic("virtio bus registration failed");
419 return 0;
420}
Rusty Russellc6fd4702008-02-04 23:50:05 -0500421
422static void __exit virtio_exit(void)
423{
424 bus_unregister(&virtio_bus);
Suman Annac13f99b2015-09-16 19:29:17 -0500425 ida_destroy(&virtio_index_ida);
Rusty Russellc6fd4702008-02-04 23:50:05 -0500426}
Rusty Russellec3d41c2007-10-22 11:03:36 +1000427core_initcall(virtio_init);
Rusty Russellc6fd4702008-02-04 23:50:05 -0500428module_exit(virtio_exit);
429
430MODULE_LICENSE("GPL");