• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 Red Hat <mjg@redhat.com>
3  *
4  * This file is subject to the terms and conditions of the GNU General
5  * Public License version 2. See the file COPYING in the main
6  * directory of this archive for more details.
7  *
8  * Authors: Matthew Garrett
9  *          Dave Airlie
10  */
11 #include <linux/module.h>
12 #include <linux/console.h>
13 #include <drm/drmP.h>
14 
15 #include "cirrus_drv.h"
16 
17 int cirrus_modeset = -1;
18 
19 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
20 module_param_named(modeset, cirrus_modeset, int, 0400);
21 
22 /*
23  * This is the generic driver code. This binds the driver to the drm core,
24  * which then performs further device association and calls our graphics init
25  * functions
26  */
27 
28 static struct drm_driver driver;
29 
30 /* only bind to the cirrus chip in qemu */
31 static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
32 	{ PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, 0x1af4, 0x1100, 0,
33 	  0, 0 },
34 	{0,}
35 };
36 
37 
cirrus_kick_out_firmware_fb(struct pci_dev * pdev)38 static int cirrus_kick_out_firmware_fb(struct pci_dev *pdev)
39 {
40 	struct apertures_struct *ap;
41 	bool primary = false;
42 
43 	ap = alloc_apertures(1);
44 	if (!ap)
45 		return -ENOMEM;
46 
47 	ap->ranges[0].base = pci_resource_start(pdev, 0);
48 	ap->ranges[0].size = pci_resource_len(pdev, 0);
49 
50 #ifdef CONFIG_X86
51 	primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
52 #endif
53 	remove_conflicting_framebuffers(ap, "cirrusdrmfb", primary);
54 	kfree(ap);
55 
56 	return 0;
57 }
58 
cirrus_pci_probe(struct pci_dev * pdev,const struct pci_device_id * ent)59 static int cirrus_pci_probe(struct pci_dev *pdev,
60 			    const struct pci_device_id *ent)
61 {
62 	int ret;
63 
64 	ret = cirrus_kick_out_firmware_fb(pdev);
65 	if (ret)
66 		return ret;
67 
68 	return drm_get_pci_dev(pdev, ent, &driver);
69 }
70 
cirrus_pci_remove(struct pci_dev * pdev)71 static void cirrus_pci_remove(struct pci_dev *pdev)
72 {
73 	struct drm_device *dev = pci_get_drvdata(pdev);
74 
75 	drm_put_dev(dev);
76 }
77 
78 static const struct file_operations cirrus_driver_fops = {
79 	.owner = THIS_MODULE,
80 	.open = drm_open,
81 	.release = drm_release,
82 	.unlocked_ioctl = drm_ioctl,
83 	.mmap = cirrus_mmap,
84 	.poll = drm_poll,
85 #ifdef CONFIG_COMPAT
86 	.compat_ioctl = drm_compat_ioctl,
87 #endif
88 	.fasync = drm_fasync,
89 };
90 static struct drm_driver driver = {
91 	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_USE_MTRR,
92 	.load = cirrus_driver_load,
93 	.unload = cirrus_driver_unload,
94 	.fops = &cirrus_driver_fops,
95 	.name = DRIVER_NAME,
96 	.desc = DRIVER_DESC,
97 	.date = DRIVER_DATE,
98 	.major = DRIVER_MAJOR,
99 	.minor = DRIVER_MINOR,
100 	.patchlevel = DRIVER_PATCHLEVEL,
101 	.gem_init_object = cirrus_gem_init_object,
102 	.gem_free_object = cirrus_gem_free_object,
103 	.dumb_create = cirrus_dumb_create,
104 	.dumb_map_offset = cirrus_dumb_mmap_offset,
105 	.dumb_destroy = cirrus_dumb_destroy,
106 };
107 
108 static struct pci_driver cirrus_pci_driver = {
109 	.name = DRIVER_NAME,
110 	.id_table = pciidlist,
111 	.probe = cirrus_pci_probe,
112 	.remove = cirrus_pci_remove,
113 };
114 
cirrus_init(void)115 static int __init cirrus_init(void)
116 {
117 #ifdef CONFIG_VGA_CONSOLE
118 	if (vgacon_text_force() && cirrus_modeset == -1)
119 		return -EINVAL;
120 #endif
121 
122 	if (cirrus_modeset == 0)
123 		return -EINVAL;
124 	return drm_pci_init(&driver, &cirrus_pci_driver);
125 }
126 
cirrus_exit(void)127 static void __exit cirrus_exit(void)
128 {
129 	drm_pci_exit(&driver, &cirrus_pci_driver);
130 }
131 
132 module_init(cirrus_init);
133 module_exit(cirrus_exit);
134 
135 MODULE_DEVICE_TABLE(pci, pciidlist);
136 MODULE_AUTHOR(DRIVER_AUTHOR);
137 MODULE_DESCRIPTION(DRIVER_DESC);
138 MODULE_LICENSE("GPL");
139