]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - drivers/gpu/drm/qxl/qxl_drv.c
Merge tag 'omap-for-v5.0/fixes-rc7-signed' of git://git.kernel.org/pub/scm/linux...
[mirror_ubuntu-eoan-kernel.git] / drivers / gpu / drm / qxl / qxl_drv.c
CommitLineData
f64122c1
DA
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
edaf492c
MY
34#include <drm/drmP.h>
35#include <drm/drm.h>
36#include <drm/drm_crtc_helper.h>
f64122c1 37#include "qxl_drv.h"
d84300bf 38#include "qxl_object.h"
f64122c1 39
9baa3c34 40static const struct pci_device_id pciidlist[] = {
f64122c1
DA
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};
47MODULE_DEVICE_TABLE(pci, pciidlist);
48
6d01f1f5 49static int qxl_modeset = -1;
07f8d9bd 50int qxl_num_crtc = 4;
f64122c1
DA
51
52MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
53module_param_named(modeset, qxl_modeset, int, 0400);
54
07f8d9bd
DA
55MODULE_PARM_DESC(num_heads, "Number of virtual crtcs to expose (default 4)");
56module_param_named(num_heads, qxl_num_crtc, int, 0400);
57
f64122c1
DA
58static struct drm_driver qxl_driver;
59static struct pci_driver qxl_pci_driver;
60
61static int
62qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
63{
2b65d567
GKB
64 struct qxl_device *qdev;
65 int ret;
66
f64122c1
DA
67 if (pdev->revision < 4) {
68 DRM_ERROR("qxl too old, doesn't support client_monitors_config,"
69 " use xf86-video-qxl in user mode");
70 return -EINVAL; /* TODO: ENODEV ? */
71 }
2b65d567 72
2b65d567 73 qdev = kzalloc(sizeof(struct qxl_device), GFP_KERNEL);
cbdded7f
GKB
74 if (!qdev)
75 return -ENOMEM;
2b65d567
GKB
76
77 ret = pci_enable_device(pdev);
78 if (ret)
cbdded7f 79 goto free_dev;
2b65d567 80
aa5b62ba 81 ret = qxl_device_init(qdev, &qxl_driver, pdev);
2b65d567
GKB
82 if (ret)
83 goto disable_pci;
84
2b65d567
GKB
85 ret = qxl_modeset_init(qdev);
86 if (ret)
64ca824e 87 goto unload;
2b65d567 88
cbdded7f 89 drm_kms_helper_poll_init(&qdev->ddev);
2b65d567
GKB
90
91 /* Complete initialization. */
cbdded7f 92 ret = drm_dev_register(&qdev->ddev, ent->driver_data);
2b65d567
GKB
93 if (ret)
94 goto modeset_cleanup;
95
96 return 0;
97
98modeset_cleanup:
99 qxl_modeset_fini(qdev);
2b65d567
GKB
100unload:
101 qxl_device_fini(qdev);
102disable_pci:
103 pci_disable_device(pdev);
cbdded7f 104free_dev:
2b65d567 105 kfree(qdev);
2b65d567 106 return ret;
f64122c1
DA
107}
108
109static void
110qxl_pci_remove(struct pci_dev *pdev)
111{
112 struct drm_device *dev = pci_get_drvdata(pdev);
6f897f51
GKB
113 struct qxl_device *qdev = dev->dev_private;
114
115 drm_dev_unregister(dev);
116
117 qxl_modeset_fini(qdev);
118 qxl_device_fini(qdev);
f64122c1 119
6f897f51
GKB
120 dev->dev_private = NULL;
121 kfree(qdev);
b0d146ac 122 drm_dev_put(dev);
f64122c1
DA
123}
124
f64122c1
DA
125static const struct file_operations qxl_fops = {
126 .owner = THIS_MODULE,
127 .open = drm_open,
128 .release = drm_release,
129 .unlocked_ioctl = drm_ioctl,
130 .poll = drm_poll,
058e9f5c 131 .read = drm_read,
f64122c1
DA
132 .mmap = qxl_mmap,
133};
134
d84300bf
DA
135static int qxl_drm_freeze(struct drm_device *dev)
136{
137 struct pci_dev *pdev = dev->pdev;
138 struct qxl_device *qdev = dev->dev_private;
7948a2b1 139 int ret;
d84300bf 140
7948a2b1
PW
141 ret = drm_mode_config_helper_suspend(dev);
142 if (ret)
143 return ret;
d84300bf
DA
144
145 qxl_destroy_monitors_object(qdev);
146 qxl_surf_evict(qdev);
147 qxl_vram_evict(qdev);
148
149 while (!qxl_check_idle(qdev->command_ring));
150 while (!qxl_check_idle(qdev->release_ring))
151 qxl_queue_garbage_collect(qdev, 1);
152
153 pci_save_state(pdev);
154
155 return 0;
156}
157
158static int qxl_drm_resume(struct drm_device *dev, bool thaw)
159{
160 struct qxl_device *qdev = dev->dev_private;
161
162 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
163 if (!thaw) {
164 qxl_reinit_memslots(qdev);
165 qxl_ring_init_hdr(qdev->release_ring);
166 }
167
168 qxl_create_monitors_object(qdev);
7948a2b1 169 return drm_mode_config_helper_resume(dev);
d84300bf
DA
170}
171
172static int qxl_pm_suspend(struct device *dev)
173{
174 struct pci_dev *pdev = to_pci_dev(dev);
175 struct drm_device *drm_dev = pci_get_drvdata(pdev);
176 int error;
177
178 error = qxl_drm_freeze(drm_dev);
179 if (error)
180 return error;
181
182 pci_disable_device(pdev);
183 pci_set_power_state(pdev, PCI_D3hot);
184 return 0;
185}
186
187static int qxl_pm_resume(struct device *dev)
188{
189 struct pci_dev *pdev = to_pci_dev(dev);
190 struct drm_device *drm_dev = pci_get_drvdata(pdev);
191
192 pci_set_power_state(pdev, PCI_D0);
193 pci_restore_state(pdev);
194 if (pci_enable_device(pdev)) {
195 return -EIO;
196 }
197
198 return qxl_drm_resume(drm_dev, false);
199}
200
201static int qxl_pm_thaw(struct device *dev)
202{
203 struct pci_dev *pdev = to_pci_dev(dev);
204 struct drm_device *drm_dev = pci_get_drvdata(pdev);
205
206 return qxl_drm_resume(drm_dev, true);
207}
208
209static int qxl_pm_freeze(struct device *dev)
210{
211 struct pci_dev *pdev = to_pci_dev(dev);
212 struct drm_device *drm_dev = pci_get_drvdata(pdev);
213
214 return qxl_drm_freeze(drm_dev);
215}
216
217static int qxl_pm_restore(struct device *dev)
218{
219 struct pci_dev *pdev = to_pci_dev(dev);
220 struct drm_device *drm_dev = pci_get_drvdata(pdev);
221 struct qxl_device *qdev = drm_dev->dev_private;
222
223 qxl_io_reset(qdev);
224 return qxl_drm_resume(drm_dev, false);
225}
226
227static const struct dev_pm_ops qxl_pm_ops = {
228 .suspend = qxl_pm_suspend,
229 .resume = qxl_pm_resume,
230 .freeze = qxl_pm_freeze,
231 .thaw = qxl_pm_thaw,
232 .poweroff = qxl_pm_freeze,
233 .restore = qxl_pm_restore,
234};
235static struct pci_driver qxl_pci_driver = {
236 .name = DRIVER_NAME,
237 .id_table = pciidlist,
238 .probe = qxl_pci_probe,
239 .remove = qxl_pci_remove,
240 .driver.pm = &qxl_pm_ops,
241};
242
f64122c1 243static struct drm_driver qxl_driver = {
47c12968 244 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
fb4fe33f
GKB
245 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
246 DRIVER_ATOMIC,
f64122c1
DA
247
248 .dumb_create = qxl_mode_dumb_create,
249 .dumb_map_offset = qxl_mode_dumb_mmap,
f64122c1
DA
250#if defined(CONFIG_DEBUG_FS)
251 .debugfs_init = qxl_debugfs_init,
f64122c1 252#endif
47c12968
AP
253 .gem_prime_export = drm_gem_prime_export,
254 .gem_prime_import = drm_gem_prime_import,
255 .gem_prime_pin = qxl_gem_prime_pin,
256 .gem_prime_unpin = qxl_gem_prime_unpin,
47c12968
AP
257 .gem_prime_vmap = qxl_gem_prime_vmap,
258 .gem_prime_vunmap = qxl_gem_prime_vunmap,
259 .gem_prime_mmap = qxl_gem_prime_mmap,
9f4eebd7 260 .gem_free_object_unlocked = qxl_gem_object_free,
f64122c1
DA
261 .gem_open_object = qxl_gem_object_open,
262 .gem_close_object = qxl_gem_object_close,
263 .fops = &qxl_fops,
264 .ioctls = qxl_ioctls,
265 .irq_handler = qxl_irq_handler,
266 .name = DRIVER_NAME,
267 .desc = DRIVER_DESC,
268 .date = DRIVER_DATE,
269 .major = 0,
270 .minor = 1,
271 .patchlevel = 0,
272};
273
274static int __init qxl_init(void)
275{
f64122c1
DA
276 if (vgacon_text_force() && qxl_modeset == -1)
277 return -EINVAL;
f64122c1
DA
278
279 if (qxl_modeset == 0)
280 return -EINVAL;
281 qxl_driver.num_ioctls = qxl_max_ioctls;
10631d72 282 return pci_register_driver(&qxl_pci_driver);
f64122c1
DA
283}
284
285static void __exit qxl_exit(void)
286{
10631d72 287 pci_unregister_driver(&qxl_pci_driver);
f64122c1
DA
288}
289
290module_init(qxl_init);
291module_exit(qxl_exit);
292
293MODULE_AUTHOR(DRIVER_AUTHOR);
294MODULE_DESCRIPTION(DRIVER_DESC);
295MODULE_LICENSE("GPL and additional rights");