2 * Copyright (C) 2015 Red Hat, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include <linux/pci.h>
27 #include <drm/drm_fb_helper.h>
29 #include "virtgpu_drv.h"
31 int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)
33 struct drm_device *dev;
36 dev = drm_dev_alloc(driver, &vdev->dev);
41 if (strcmp(vdev->dev.parent->bus->name, "pci") == 0) {
42 struct pci_dev *pdev = to_pci_dev(vdev->dev.parent);
43 const char *pname = dev_name(&pdev->dev);
44 bool vga = (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
47 DRM_INFO("pci: %s detected at %s\n",
48 vga ? "virtio-vga" : "virtio-gpu-pci",
52 drm_fb_helper_remove_conflicting_pci_framebuffers(pdev,
57 * Normally the drm_dev_set_unique() call is done by core DRM.
58 * The following comment covers, why virtio cannot rely on it.
60 * Unlike the other virtual GPU drivers, virtio abstracts the
61 * underlying bus type by using struct virtio_device.
63 * Hence the dev_is_pci() check, used in core DRM, will fail
64 * and the unique returned will be the virtio_device "virtio0",
65 * while a "pci:..." one is required.
67 * A few other ideas were considered:
68 * - Extend the dev_is_pci() check [in drm_set_busid] to
70 * Seems like a bigger hack than what we have already.
72 * - Point drm_device::dev to the parent of the virtio_device
74 * * Using the wrong device for i2c, framebuffer_alloc and
77 * * Helpers such as DRM_DEV_ERROR, dev_info, drm_printer,
78 * will print the wrong information.
80 * We could address the latter issues, by introducing
81 * drm_device::bus_dev, ... which would be used solely for this.
83 * So for the moment keep things as-is, with a bulky comment
84 * for the next person who feels like removing this
85 * drm_dev_set_unique() quirk.
87 snprintf(unique, sizeof(unique), "pci:%s", pname);
88 ret = drm_dev_set_unique(dev, unique);
94 ret = drm_dev_register(dev, 0);