Dave Airlie | dc5698e | 2013-09-09 10:02:56 +1000 | [diff] [blame] | 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 | |
| 28 | #include "virtgpu_drv.h" |
| 29 | |
| 30 | int drm_virtio_set_busid(struct drm_device *dev, struct drm_master *master) |
| 31 | { |
| 32 | struct pci_dev *pdev = dev->pdev; |
| 33 | |
| 34 | if (pdev) { |
| 35 | return drm_pci_set_busid(dev, master); |
| 36 | } |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev) |
| 41 | { |
| 42 | struct drm_device *dev; |
| 43 | int ret; |
| 44 | |
| 45 | dev = drm_dev_alloc(driver, &vdev->dev); |
| 46 | if (!dev) |
| 47 | return -ENOMEM; |
| 48 | dev->virtdev = vdev; |
| 49 | vdev->priv = dev; |
| 50 | |
| 51 | if (strcmp(vdev->dev.parent->bus->name, "pci") == 0) { |
| 52 | struct pci_dev *pdev = to_pci_dev(vdev->dev.parent); |
| 53 | bool vga = (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; |
| 54 | |
| 55 | if (vga) { |
| 56 | /* |
| 57 | * Need to make sure we don't have two drivers |
| 58 | * for the same hardware here. Some day we |
| 59 | * will simply kick out the firmware |
| 60 | * (vesa/efi) framebuffer. |
| 61 | * |
| 62 | * Virtual hardware specs for virtio-vga are |
| 63 | * not finalized yet, therefore we can't add |
| 64 | * code for that yet. |
| 65 | * |
| 66 | * So ignore the device for the time being, |
| 67 | * and suggest to the user use the device |
| 68 | * variant without vga compatibility mode. |
| 69 | */ |
| 70 | DRM_ERROR("virtio-vga not (yet) supported\n"); |
| 71 | DRM_ERROR("please use virtio-gpu-pci instead\n"); |
| 72 | ret = -ENODEV; |
| 73 | goto err_free; |
| 74 | } |
| 75 | dev->pdev = pdev; |
| 76 | } |
| 77 | |
| 78 | ret = drm_dev_register(dev, 0); |
| 79 | if (ret) |
| 80 | goto err_free; |
| 81 | |
| 82 | DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", driver->name, |
| 83 | driver->major, driver->minor, driver->patchlevel, |
| 84 | driver->date, dev->primary->index); |
| 85 | |
| 86 | return 0; |
| 87 | |
| 88 | err_free: |
| 89 | drm_dev_unref(dev); |
| 90 | return ret; |
| 91 | } |