]> Git Repo - linux.git/blob - drivers/gpu/drm/virtio/virtgpu_drm_bus.c
Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux.git] / drivers / gpu / drm / virtio / virtgpu_drm_bus.c
1 /*
2  * Copyright (C) 2015 Red Hat, Inc.
3  * All Rights Reserved.
4  *
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:
12  *
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.
16  *
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.
24  */
25
26 #include <linux/pci.h>
27 #include <drm/drm_fb_helper.h>
28
29 #include "virtgpu_drv.h"
30
31 int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)
32 {
33         struct drm_device *dev;
34         int ret;
35
36         dev = drm_dev_alloc(driver, &vdev->dev);
37         if (IS_ERR(dev))
38                 return PTR_ERR(dev);
39         vdev->priv = dev;
40
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;
45                 char unique[20];
46
47                 DRM_INFO("pci: %s detected at %s\n",
48                          vga ? "virtio-vga" : "virtio-gpu-pci",
49                          pname);
50                 dev->pdev = pdev;
51                 if (vga)
52                         drm_fb_helper_remove_conflicting_pci_framebuffers(pdev,
53                                                                           0,
54                                                                           "virtiodrmfb");
55
56                 snprintf(unique, sizeof(unique), "pci:%s", pname);
57                 ret = drm_dev_set_unique(dev, unique);
58                 if (ret)
59                         goto err_free;
60
61         }
62
63         ret = drm_dev_register(dev, 0);
64         if (ret)
65                 goto err_free;
66
67         return 0;
68
69 err_free:
70         drm_dev_put(dev);
71         return ret;
72 }
This page took 0.036605 seconds and 4 git commands to generate.