forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/gpu/drm/qxl/qxl_drv.c
....@@ -28,13 +28,19 @@
2828 * Alon Levy <alevy@redhat.com>
2929 */
3030
31
-#include <linux/module.h>
32
-#include <linux/console.h>
33
-
34
-#include <drm/drmP.h>
35
-#include <drm/drm.h>
36
-#include <drm/drm_crtc_helper.h>
3731 #include "qxl_drv.h"
32
+#include <linux/console.h>
33
+#include <linux/module.h>
34
+#include <linux/pci.h>
35
+
36
+#include <drm/drm.h>
37
+#include <drm/drm_atomic_helper.h>
38
+#include <drm/drm_drv.h>
39
+#include <drm/drm_file.h>
40
+#include <drm/drm_modeset_helper.h>
41
+#include <drm/drm_prime.h>
42
+#include <drm/drm_probe_helper.h>
43
+
3844 #include "qxl_object.h"
3945
4046 static const struct pci_device_id pciidlist[] = {
....@@ -58,6 +64,11 @@
5864 static struct drm_driver qxl_driver;
5965 static struct pci_driver qxl_pci_driver;
6066
67
+static bool is_vga(struct pci_dev *pdev)
68
+{
69
+ return pdev->class == PCI_CLASS_DISPLAY_VGA << 8;
70
+}
71
+
6172 static int
6273 qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
6374 {
....@@ -70,17 +81,32 @@
7081 return -EINVAL; /* TODO: ENODEV ? */
7182 }
7283
73
- qdev = kzalloc(sizeof(struct qxl_device), GFP_KERNEL);
74
- if (!qdev)
84
+ qdev = devm_drm_dev_alloc(&pdev->dev, &qxl_driver,
85
+ struct qxl_device, ddev);
86
+ if (IS_ERR(qdev)) {
87
+ pr_err("Unable to init drm dev");
7588 return -ENOMEM;
89
+ }
7690
7791 ret = pci_enable_device(pdev);
7892 if (ret)
79
- goto free_dev;
93
+ return ret;
8094
81
- ret = qxl_device_init(qdev, &qxl_driver, pdev);
95
+ ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "qxl");
8296 if (ret)
8397 goto disable_pci;
98
+
99
+ if (is_vga(pdev) && pdev->revision < 5) {
100
+ ret = vga_get_interruptible(pdev, VGA_RSRC_LEGACY_IO);
101
+ if (ret) {
102
+ DRM_ERROR("can't get legacy vga ioports\n");
103
+ goto disable_pci;
104
+ }
105
+ }
106
+
107
+ ret = qxl_device_init(qdev, pdev);
108
+ if (ret)
109
+ goto put_vga;
84110
85111 ret = qxl_modeset_init(qdev);
86112 if (ret)
....@@ -93,49 +119,52 @@
93119 if (ret)
94120 goto modeset_cleanup;
95121
122
+ drm_fbdev_generic_setup(&qdev->ddev, 32);
96123 return 0;
97124
98125 modeset_cleanup:
99126 qxl_modeset_fini(qdev);
100127 unload:
101128 qxl_device_fini(qdev);
129
+put_vga:
130
+ if (is_vga(pdev) && pdev->revision < 5)
131
+ vga_put(pdev, VGA_RSRC_LEGACY_IO);
102132 disable_pci:
103133 pci_disable_device(pdev);
104
-free_dev:
105
- kfree(qdev);
134
+
106135 return ret;
136
+}
137
+
138
+static void qxl_drm_release(struct drm_device *dev)
139
+{
140
+ struct qxl_device *qdev = to_qxl(dev);
141
+
142
+ /*
143
+ * TODO: qxl_device_fini() call should be in qxl_pci_remove(),
144
+ * reodering qxl_modeset_fini() + qxl_device_fini() calls is
145
+ * non-trivial though.
146
+ */
147
+ qxl_modeset_fini(qdev);
148
+ qxl_device_fini(qdev);
107149 }
108150
109151 static void
110152 qxl_pci_remove(struct pci_dev *pdev)
111153 {
112154 struct drm_device *dev = pci_get_drvdata(pdev);
113
- struct qxl_device *qdev = dev->dev_private;
114155
115156 drm_dev_unregister(dev);
116
-
117
- qxl_modeset_fini(qdev);
118
- qxl_device_fini(qdev);
119
-
120
- dev->dev_private = NULL;
121
- kfree(qdev);
122
- drm_dev_unref(dev);
157
+ drm_atomic_helper_shutdown(dev);
158
+ if (is_vga(pdev) && pdev->revision < 5)
159
+ vga_put(pdev, VGA_RSRC_LEGACY_IO);
123160 }
124161
125
-static 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,
131
- .read = drm_read,
132
- .mmap = qxl_mmap,
133
-};
162
+DEFINE_DRM_GEM_FOPS(qxl_fops);
134163
135164 static int qxl_drm_freeze(struct drm_device *dev)
136165 {
137166 struct pci_dev *pdev = dev->pdev;
138
- struct qxl_device *qdev = dev->dev_private;
167
+ struct qxl_device *qdev = to_qxl(dev);
139168 int ret;
140169
141170 ret = drm_mode_config_helper_suspend(dev);
....@@ -157,7 +186,7 @@
157186
158187 static int qxl_drm_resume(struct drm_device *dev, bool thaw)
159188 {
160
- struct qxl_device *qdev = dev->dev_private;
189
+ struct qxl_device *qdev = to_qxl(dev);
161190
162191 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
163192 if (!thaw) {
....@@ -200,16 +229,14 @@
200229
201230 static int qxl_pm_thaw(struct device *dev)
202231 {
203
- struct pci_dev *pdev = to_pci_dev(dev);
204
- struct drm_device *drm_dev = pci_get_drvdata(pdev);
232
+ struct drm_device *drm_dev = dev_get_drvdata(dev);
205233
206234 return qxl_drm_resume(drm_dev, true);
207235 }
208236
209237 static int qxl_pm_freeze(struct device *dev)
210238 {
211
- struct pci_dev *pdev = to_pci_dev(dev);
212
- struct drm_device *drm_dev = pci_get_drvdata(pdev);
239
+ struct drm_device *drm_dev = dev_get_drvdata(dev);
213240
214241 return qxl_drm_freeze(drm_dev);
215242 }
....@@ -218,7 +245,7 @@
218245 {
219246 struct pci_dev *pdev = to_pci_dev(dev);
220247 struct drm_device *drm_dev = pci_get_drvdata(pdev);
221
- struct qxl_device *qdev = drm_dev->dev_private;
248
+ struct qxl_device *qdev = to_qxl(drm_dev);
222249
223250 qxl_io_reset(qdev);
224251 return qxl_drm_resume(drm_dev, false);
....@@ -241,9 +268,7 @@
241268 };
242269
243270 static struct drm_driver qxl_driver = {
244
- .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME |
245
- DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
246
- DRIVER_ATOMIC,
271
+ .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
247272
248273 .dumb_create = qxl_mode_dumb_create,
249274 .dumb_map_offset = qxl_mode_dumb_mmap,
....@@ -252,18 +277,8 @@
252277 #endif
253278 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
254279 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
255
- .gem_prime_export = drm_gem_prime_export,
256
- .gem_prime_import = drm_gem_prime_import,
257
- .gem_prime_pin = qxl_gem_prime_pin,
258
- .gem_prime_unpin = qxl_gem_prime_unpin,
259
- .gem_prime_get_sg_table = qxl_gem_prime_get_sg_table,
260280 .gem_prime_import_sg_table = qxl_gem_prime_import_sg_table,
261
- .gem_prime_vmap = qxl_gem_prime_vmap,
262
- .gem_prime_vunmap = qxl_gem_prime_vunmap,
263281 .gem_prime_mmap = qxl_gem_prime_mmap,
264
- .gem_free_object_unlocked = qxl_gem_object_free,
265
- .gem_open_object = qxl_gem_object_open,
266
- .gem_close_object = qxl_gem_object_close,
267282 .fops = &qxl_fops,
268283 .ioctls = qxl_ioctls,
269284 .irq_handler = qxl_irq_handler,
....@@ -273,6 +288,8 @@
273288 .major = 0,
274289 .minor = 1,
275290 .patchlevel = 0,
291
+
292
+ .release = qxl_drm_release,
276293 };
277294
278295 static int __init qxl_init(void)