1 /* vim: set ts=8 sw=8 tw=78 ai noexpandtab */
2 /* qxl_drv.c -- QXL driver -*- linux-c -*-
4 * Copyright 2011 Red Hat, Inc.
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:
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
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.
27 * Dave Airlie <airlie@redhat.com>
28 * Alon Levy <alevy@redhat.com>
31 #include <linux/module.h>
32 #include <linux/console.h>
36 #include "drm_crtc_helper.h"
38 #include "qxl_object.h"
40 extern int qxl_max_ioctls
;
41 static const struct pci_device_id pciidlist
[] = {
42 { 0x1b36, 0x100, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_DISPLAY_VGA
<< 8,
44 { 0x1b36, 0x100, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_DISPLAY_OTHER
<< 8,
48 MODULE_DEVICE_TABLE(pci
, pciidlist
);
50 static int qxl_modeset
= -1;
53 MODULE_PARM_DESC(modeset
, "Disable/Enable modesetting");
54 module_param_named(modeset
, qxl_modeset
, int, 0400);
56 MODULE_PARM_DESC(num_heads
, "Number of virtual crtcs to expose (default 4)");
57 module_param_named(num_heads
, qxl_num_crtc
, int, 0400);
59 static struct drm_driver qxl_driver
;
60 static struct pci_driver qxl_pci_driver
;
63 qxl_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
65 if (pdev
->revision
< 4) {
66 DRM_ERROR("qxl too old, doesn't support client_monitors_config,"
67 " use xf86-video-qxl in user mode");
68 return -EINVAL
; /* TODO: ENODEV ? */
70 return drm_get_pci_dev(pdev
, ent
, &qxl_driver
);
74 qxl_pci_remove(struct pci_dev
*pdev
)
76 struct drm_device
*dev
= pci_get_drvdata(pdev
);
81 static const struct file_operations qxl_fops
= {
84 .release
= drm_release
,
85 .unlocked_ioctl
= drm_ioctl
,
91 static int qxl_drm_freeze(struct drm_device
*dev
)
93 struct pci_dev
*pdev
= dev
->pdev
;
94 struct qxl_device
*qdev
= dev
->dev_private
;
95 struct drm_crtc
*crtc
;
97 drm_kms_helper_poll_disable(dev
);
100 qxl_fbdev_set_suspend(qdev
, 1);
103 /* unpin the front buffers */
104 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
105 const struct drm_crtc_helper_funcs
*crtc_funcs
= crtc
->helper_private
;
107 (*crtc_funcs
->disable
)(crtc
);
110 qxl_destroy_monitors_object(qdev
);
111 qxl_surf_evict(qdev
);
112 qxl_vram_evict(qdev
);
114 while (!qxl_check_idle(qdev
->command_ring
));
115 while (!qxl_check_idle(qdev
->release_ring
))
116 qxl_queue_garbage_collect(qdev
, 1);
118 pci_save_state(pdev
);
123 static int qxl_drm_resume(struct drm_device
*dev
, bool thaw
)
125 struct qxl_device
*qdev
= dev
->dev_private
;
127 qdev
->ram_header
->int_mask
= QXL_INTERRUPT_MASK
;
129 qxl_reinit_memslots(qdev
);
130 qxl_ring_init_hdr(qdev
->release_ring
);
133 qxl_create_monitors_object(qdev
);
134 drm_helper_resume_force_mode(dev
);
137 qxl_fbdev_set_suspend(qdev
, 0);
140 drm_kms_helper_poll_enable(dev
);
144 static int qxl_pm_suspend(struct device
*dev
)
146 struct pci_dev
*pdev
= to_pci_dev(dev
);
147 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
150 error
= qxl_drm_freeze(drm_dev
);
154 pci_disable_device(pdev
);
155 pci_set_power_state(pdev
, PCI_D3hot
);
159 static int qxl_pm_resume(struct device
*dev
)
161 struct pci_dev
*pdev
= to_pci_dev(dev
);
162 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
164 pci_set_power_state(pdev
, PCI_D0
);
165 pci_restore_state(pdev
);
166 if (pci_enable_device(pdev
)) {
170 return qxl_drm_resume(drm_dev
, false);
173 static int qxl_pm_thaw(struct device
*dev
)
175 struct pci_dev
*pdev
= to_pci_dev(dev
);
176 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
178 return qxl_drm_resume(drm_dev
, true);
181 static int qxl_pm_freeze(struct device
*dev
)
183 struct pci_dev
*pdev
= to_pci_dev(dev
);
184 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
186 return qxl_drm_freeze(drm_dev
);
189 static int qxl_pm_restore(struct device
*dev
)
191 struct pci_dev
*pdev
= to_pci_dev(dev
);
192 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
193 struct qxl_device
*qdev
= drm_dev
->dev_private
;
196 return qxl_drm_resume(drm_dev
, false);
199 static u32
qxl_noop_get_vblank_counter(struct drm_device
*dev
,
205 static int qxl_noop_enable_vblank(struct drm_device
*dev
, unsigned int pipe
)
210 static void qxl_noop_disable_vblank(struct drm_device
*dev
, unsigned int pipe
)
214 static const struct dev_pm_ops qxl_pm_ops
= {
215 .suspend
= qxl_pm_suspend
,
216 .resume
= qxl_pm_resume
,
217 .freeze
= qxl_pm_freeze
,
219 .poweroff
= qxl_pm_freeze
,
220 .restore
= qxl_pm_restore
,
222 static struct pci_driver qxl_pci_driver
= {
224 .id_table
= pciidlist
,
225 .probe
= qxl_pci_probe
,
226 .remove
= qxl_pci_remove
,
227 .driver
.pm
= &qxl_pm_ops
,
230 static struct drm_driver qxl_driver
= {
231 .driver_features
= DRIVER_GEM
| DRIVER_MODESET
| DRIVER_PRIME
|
232 DRIVER_HAVE_IRQ
| DRIVER_IRQ_SHARED
,
233 .load
= qxl_driver_load
,
234 .unload
= qxl_driver_unload
,
235 .get_vblank_counter
= qxl_noop_get_vblank_counter
,
236 .enable_vblank
= qxl_noop_enable_vblank
,
237 .disable_vblank
= qxl_noop_disable_vblank
,
239 .set_busid
= drm_pci_set_busid
,
241 .dumb_create
= qxl_mode_dumb_create
,
242 .dumb_map_offset
= qxl_mode_dumb_mmap
,
243 .dumb_destroy
= drm_gem_dumb_destroy
,
244 #if defined(CONFIG_DEBUG_FS)
245 .debugfs_init
= qxl_debugfs_init
,
246 .debugfs_cleanup
= qxl_debugfs_takedown
,
248 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
249 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
250 .gem_prime_export
= drm_gem_prime_export
,
251 .gem_prime_import
= drm_gem_prime_import
,
252 .gem_prime_pin
= qxl_gem_prime_pin
,
253 .gem_prime_unpin
= qxl_gem_prime_unpin
,
254 .gem_prime_get_sg_table
= qxl_gem_prime_get_sg_table
,
255 .gem_prime_import_sg_table
= qxl_gem_prime_import_sg_table
,
256 .gem_prime_vmap
= qxl_gem_prime_vmap
,
257 .gem_prime_vunmap
= qxl_gem_prime_vunmap
,
258 .gem_prime_mmap
= qxl_gem_prime_mmap
,
259 .gem_free_object
= qxl_gem_object_free
,
260 .gem_open_object
= qxl_gem_object_open
,
261 .gem_close_object
= qxl_gem_object_close
,
263 .ioctls
= qxl_ioctls
,
264 .irq_handler
= qxl_irq_handler
,
273 static int __init
qxl_init(void)
275 #ifdef CONFIG_VGA_CONSOLE
276 if (vgacon_text_force() && qxl_modeset
== -1)
280 if (qxl_modeset
== 0)
282 qxl_driver
.num_ioctls
= qxl_max_ioctls
;
283 return drm_pci_init(&qxl_driver
, &qxl_pci_driver
);
286 static void __exit
qxl_exit(void)
288 drm_pci_exit(&qxl_driver
, &qxl_pci_driver
);
291 module_init(qxl_init
);
292 module_exit(qxl_exit
);
294 MODULE_AUTHOR(DRIVER_AUTHOR
);
295 MODULE_DESCRIPTION(DRIVER_DESC
);
296 MODULE_LICENSE("GPL and additional rights");