Lines Matching refs:dev
15 struct virtio_device *dev = dev_to_virtio(_d);
16 return sprintf(buf, "0x%04x\n", dev->id.device);
23 struct virtio_device *dev = dev_to_virtio(_d);
24 return sprintf(buf, "0x%04x\n", dev->id.vendor);
31 struct virtio_device *dev = dev_to_virtio(_d);
32 return sprintf(buf, "0x%08x\n", dev->config->get_status(dev));
39 struct virtio_device *dev = dev_to_virtio(_d);
41 dev->id.device, dev->id.vendor);
48 struct virtio_device *dev = dev_to_virtio(_d);
54 for (i = 0; i < sizeof(dev->features)*8; i++)
56 __virtio_test_bit(dev, i) ? '1' : '0');
72 static inline int virtio_id_match(const struct virtio_device *dev,
75 if (id->device != dev->id.device && id->device != VIRTIO_DEV_ANY_ID)
78 return id->vendor == VIRTIO_DEV_ANY_ID || id->vendor == dev->id.vendor;
86 struct virtio_device *dev = dev_to_virtio(_dv);
91 if (virtio_id_match(dev, &ids[i]))
98 struct virtio_device *dev = dev_to_virtio(_dv);
101 dev->id.device, dev->id.vendor);
108 struct virtio_driver *drv = drv_to_virtio(vdev->dev.driver);
124 static void __virtio_config_changed(struct virtio_device *dev)
126 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
128 if (!dev->config_enabled)
129 dev->config_change_pending = true;
131 drv->config_changed(dev);
134 void virtio_config_changed(struct virtio_device *dev)
138 spin_lock_irqsave(&dev->config_lock, flags);
139 __virtio_config_changed(dev);
140 spin_unlock_irqrestore(&dev->config_lock, flags);
144 void virtio_config_disable(struct virtio_device *dev)
146 spin_lock_irq(&dev->config_lock);
147 dev->config_enabled = false;
148 spin_unlock_irq(&dev->config_lock);
152 void virtio_config_enable(struct virtio_device *dev)
154 spin_lock_irq(&dev->config_lock);
155 dev->config_enabled = true;
156 if (dev->config_change_pending)
157 __virtio_config_changed(dev);
158 dev->config_change_pending = false;
159 spin_unlock_irq(&dev->config_lock);
163 void virtio_add_status(struct virtio_device *dev, unsigned int status)
166 dev->config->set_status(dev, dev->config->get_status(dev) | status);
171 static int virtio_features_ok(struct virtio_device *dev)
180 if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
181 dev_warn(&dev->dev,
186 if (!virtio_has_feature(dev, VIRTIO_F_ACCESS_PLATFORM)) {
187 dev_warn(&dev->dev,
193 if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
196 virtio_add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
197 status = dev->config->get_status(dev);
199 dev_err(&dev->dev, "virtio: device refuses features: %x\n",
209 struct virtio_device *dev = dev_to_virtio(_d);
210 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
216 virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER);
219 device_features = dev->config->get_features(dev);
242 dev->features = driver_features & device_features;
244 dev->features = driver_features_legacy & device_features;
249 __virtio_set_bit(dev, i);
251 err = dev->config->finalize_features(dev);
256 u64 features = dev->features;
258 err = drv->validate(dev);
263 if (features != dev->features) {
264 err = dev->config->finalize_features(dev);
270 err = virtio_features_ok(dev);
274 err = drv->probe(dev);
279 if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
280 virtio_device_ready(dev);
283 drv->scan(dev);
285 virtio_config_enable(dev);
289 virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
296 struct virtio_device *dev = dev_to_virtio(_d);
297 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
299 virtio_config_disable(dev);
301 drv->remove(dev);
304 WARN_ON_ONCE(dev->config->get_status(dev));
307 virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
337 * @dev : virtio device to be registered
339 * On error, the caller must call put_device on &@dev->dev (and not kfree),
340 * as another code path may have obtained a reference to @dev.
344 int register_virtio_device(struct virtio_device *dev)
348 dev->dev.bus = &virtio_bus;
349 device_initialize(&dev->dev);
356 dev->index = err;
357 dev_set_name(&dev->dev, "virtio%u", dev->index);
359 spin_lock_init(&dev->config_lock);
360 dev->config_enabled = false;
361 dev->config_change_pending = false;
365 dev->config->reset(dev);
368 virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
370 INIT_LIST_HEAD(&dev->vqs);
371 spin_lock_init(&dev->vqs_list_lock);
377 err = device_add(&dev->dev);
379 ida_simple_remove(&virtio_index_ida, dev->index);
382 virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
387 bool is_virtio_device(struct device *dev)
389 return dev->bus == &virtio_bus;
393 void unregister_virtio_device(struct virtio_device *dev)
395 int index = dev->index; /* save for after device release */
397 device_unregister(&dev->dev);
403 int virtio_device_freeze(struct virtio_device *dev)
405 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
407 virtio_config_disable(dev);
409 dev->failed = dev->config->get_status(dev) & VIRTIO_CONFIG_S_FAILED;
412 return drv->freeze(dev);
418 int virtio_device_restore(struct virtio_device *dev)
420 struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
425 dev->config->reset(dev);
428 virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
432 if (dev->failed)
433 virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
439 virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER);
441 ret = dev->config->finalize_features(dev);
445 ret = virtio_features_ok(dev);
450 ret = drv->restore(dev);
456 virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
458 virtio_config_enable(dev);
463 virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);