Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1 | /* vim: set ts=8 sw=8 tw=78 ai noexpandtab */ |
| 2 | /* qxl_drv.c -- QXL driver -*- linux-c -*- |
| 3 | * |
| 4 | * Copyright 2011 Red Hat, Inc. |
| 5 | * All Rights Reserved. |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the next |
| 15 | * paragraph) shall be included in all copies or substantial portions of the |
| 16 | * Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 22 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 24 | * OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | * Authors: |
| 27 | * Dave Airlie <airlie@redhat.com> |
| 28 | * Alon Levy <alevy@redhat.com> |
| 29 | */ |
| 30 | |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/console.h> |
| 33 | |
| 34 | #include "drmP.h" |
| 35 | #include "drm/drm.h" |
| 36 | |
| 37 | #include "qxl_drv.h" |
| 38 | |
| 39 | extern int qxl_max_ioctls; |
| 40 | static DEFINE_PCI_DEVICE_TABLE(pciidlist) = { |
| 41 | { 0x1b36, 0x100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, |
| 42 | 0xffff00, 0 }, |
| 43 | { 0x1b36, 0x100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_OTHER << 8, |
| 44 | 0xffff00, 0 }, |
| 45 | { 0, 0, 0 }, |
| 46 | }; |
| 47 | MODULE_DEVICE_TABLE(pci, pciidlist); |
| 48 | |
Dave Airlie | 6d01f1f | 2013-04-16 13:24:25 +1000 | [diff] [blame^] | 49 | static int qxl_modeset = -1; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 50 | |
| 51 | MODULE_PARM_DESC(modeset, "Disable/Enable modesetting"); |
| 52 | module_param_named(modeset, qxl_modeset, int, 0400); |
| 53 | |
| 54 | static struct drm_driver qxl_driver; |
| 55 | static struct pci_driver qxl_pci_driver; |
| 56 | |
| 57 | static int |
| 58 | qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 59 | { |
| 60 | if (pdev->revision < 4) { |
| 61 | DRM_ERROR("qxl too old, doesn't support client_monitors_config," |
| 62 | " use xf86-video-qxl in user mode"); |
| 63 | return -EINVAL; /* TODO: ENODEV ? */ |
| 64 | } |
| 65 | return drm_get_pci_dev(pdev, ent, &qxl_driver); |
| 66 | } |
| 67 | |
| 68 | static void |
| 69 | qxl_pci_remove(struct pci_dev *pdev) |
| 70 | { |
| 71 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 72 | |
| 73 | drm_put_dev(dev); |
| 74 | } |
| 75 | |
| 76 | static struct pci_driver qxl_pci_driver = { |
| 77 | .name = DRIVER_NAME, |
| 78 | .id_table = pciidlist, |
| 79 | .probe = qxl_pci_probe, |
| 80 | .remove = qxl_pci_remove, |
| 81 | }; |
| 82 | |
| 83 | static const struct file_operations qxl_fops = { |
| 84 | .owner = THIS_MODULE, |
| 85 | .open = drm_open, |
| 86 | .release = drm_release, |
| 87 | .unlocked_ioctl = drm_ioctl, |
| 88 | .poll = drm_poll, |
| 89 | .fasync = drm_fasync, |
| 90 | .mmap = qxl_mmap, |
| 91 | }; |
| 92 | |
| 93 | static struct drm_driver qxl_driver = { |
| 94 | .driver_features = DRIVER_GEM | DRIVER_MODESET | |
| 95 | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED, |
| 96 | .dev_priv_size = 0, |
| 97 | .load = qxl_driver_load, |
| 98 | .unload = qxl_driver_unload, |
| 99 | |
| 100 | .dumb_create = qxl_mode_dumb_create, |
| 101 | .dumb_map_offset = qxl_mode_dumb_mmap, |
| 102 | .dumb_destroy = qxl_mode_dumb_destroy, |
| 103 | #if defined(CONFIG_DEBUG_FS) |
| 104 | .debugfs_init = qxl_debugfs_init, |
| 105 | .debugfs_cleanup = qxl_debugfs_takedown, |
| 106 | #endif |
| 107 | .gem_init_object = qxl_gem_object_init, |
| 108 | .gem_free_object = qxl_gem_object_free, |
| 109 | .gem_open_object = qxl_gem_object_open, |
| 110 | .gem_close_object = qxl_gem_object_close, |
| 111 | .fops = &qxl_fops, |
| 112 | .ioctls = qxl_ioctls, |
| 113 | .irq_handler = qxl_irq_handler, |
| 114 | .name = DRIVER_NAME, |
| 115 | .desc = DRIVER_DESC, |
| 116 | .date = DRIVER_DATE, |
| 117 | .major = 0, |
| 118 | .minor = 1, |
| 119 | .patchlevel = 0, |
| 120 | }; |
| 121 | |
| 122 | static int __init qxl_init(void) |
| 123 | { |
| 124 | #ifdef CONFIG_VGA_CONSOLE |
| 125 | if (vgacon_text_force() && qxl_modeset == -1) |
| 126 | return -EINVAL; |
| 127 | #endif |
| 128 | |
| 129 | if (qxl_modeset == 0) |
| 130 | return -EINVAL; |
| 131 | qxl_driver.num_ioctls = qxl_max_ioctls; |
| 132 | return drm_pci_init(&qxl_driver, &qxl_pci_driver); |
| 133 | } |
| 134 | |
| 135 | static void __exit qxl_exit(void) |
| 136 | { |
| 137 | drm_pci_exit(&qxl_driver, &qxl_pci_driver); |
| 138 | } |
| 139 | |
| 140 | module_init(qxl_init); |
| 141 | module_exit(qxl_exit); |
| 142 | |
| 143 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 144 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 145 | MODULE_LICENSE("GPL and additional rights"); |