forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/gpu/drm/bochs/bochs_drv.c
....@@ -1,24 +1,19 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
2
- * This program is free software; you can redistribute it and/or modify
3
- * it under the terms of the GNU General Public License as published by
4
- * the Free Software Foundation; either version 2 of the License, or
5
- * (at your option) any later version.
63 */
74
8
-#include <linux/mm.h>
95 #include <linux/module.h>
10
-#include <linux/slab.h>
11
-#include <drm/drm_fb_helper.h>
6
+#include <linux/pci.h>
7
+
8
+#include <drm/drm_drv.h>
9
+#include <drm/drm_atomic_helper.h>
10
+#include <drm/drm_managed.h>
1211
1312 #include "bochs.h"
1413
1514 static int bochs_modeset = -1;
1615 module_param_named(modeset, bochs_modeset, int, 0444);
1716 MODULE_PARM_DESC(modeset, "enable/disable kernel modesetting");
18
-
19
-static bool enable_fbdev = true;
20
-module_param_named(fbdev, enable_fbdev, bool, 0444);
21
-MODULE_PARM_DESC(fbdev, "register fbdev device");
2217
2318 /* ---------------------------------------------------------------------- */
2419 /* drm interface */
....@@ -27,26 +22,21 @@
2722 {
2823 struct bochs_device *bochs = dev->dev_private;
2924
30
- bochs_fbdev_fini(bochs);
31
- bochs_kms_fini(bochs);
3225 bochs_mm_fini(bochs);
33
- bochs_hw_fini(dev);
34
- kfree(bochs);
35
- dev->dev_private = NULL;
3626 }
3727
38
-static int bochs_load(struct drm_device *dev, unsigned long flags)
28
+static int bochs_load(struct drm_device *dev)
3929 {
4030 struct bochs_device *bochs;
4131 int ret;
4232
43
- bochs = kzalloc(sizeof(*bochs), GFP_KERNEL);
33
+ bochs = drmm_kzalloc(dev, sizeof(*bochs), GFP_KERNEL);
4434 if (bochs == NULL)
4535 return -ENOMEM;
4636 dev->dev_private = bochs;
4737 bochs->dev = dev;
4838
49
- ret = bochs_hw_init(dev, flags);
39
+ ret = bochs_hw_init(dev);
5040 if (ret)
5141 goto err;
5242
....@@ -58,9 +48,6 @@
5848 if (ret)
5949 goto err;
6050
61
- if (enable_fbdev)
62
- bochs_fbdev_init(bochs);
63
-
6451 return 0;
6552
6653 err:
....@@ -68,31 +55,18 @@
6855 return ret;
6956 }
7057
71
-static const struct file_operations bochs_fops = {
72
- .owner = THIS_MODULE,
73
- .open = drm_open,
74
- .release = drm_release,
75
- .unlocked_ioctl = drm_ioctl,
76
- .compat_ioctl = drm_compat_ioctl,
77
- .poll = drm_poll,
78
- .read = drm_read,
79
- .llseek = no_llseek,
80
- .mmap = bochs_mmap,
81
-};
58
+DEFINE_DRM_GEM_FOPS(bochs_fops);
8259
8360 static struct drm_driver bochs_driver = {
84
- .driver_features = DRIVER_GEM | DRIVER_MODESET,
85
- .load = bochs_load,
86
- .unload = bochs_unload,
61
+ .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
8762 .fops = &bochs_fops,
8863 .name = "bochs-drm",
8964 .desc = "bochs dispi vga interface (qemu stdvga)",
9065 .date = "20130925",
9166 .major = 1,
9267 .minor = 0,
93
- .gem_free_object_unlocked = bochs_gem_free_object,
94
- .dumb_create = bochs_dumb_create,
95
- .dumb_map_offset = bochs_dumb_mmap_offset,
68
+ DRM_GEM_VRAM_DRIVER,
69
+ .release = bochs_unload,
9670 };
9771
9872 /* ---------------------------------------------------------------------- */
....@@ -101,37 +75,16 @@
10175 #ifdef CONFIG_PM_SLEEP
10276 static int bochs_pm_suspend(struct device *dev)
10377 {
104
- struct pci_dev *pdev = to_pci_dev(dev);
105
- struct drm_device *drm_dev = pci_get_drvdata(pdev);
106
- struct bochs_device *bochs = drm_dev->dev_private;
78
+ struct drm_device *drm_dev = dev_get_drvdata(dev);
10779
108
- drm_kms_helper_poll_disable(drm_dev);
109
-
110
- if (bochs->fb.initialized) {
111
- console_lock();
112
- drm_fb_helper_set_suspend(&bochs->fb.helper, 1);
113
- console_unlock();
114
- }
115
-
116
- return 0;
80
+ return drm_mode_config_helper_suspend(drm_dev);
11781 }
11882
11983 static int bochs_pm_resume(struct device *dev)
12084 {
121
- struct pci_dev *pdev = to_pci_dev(dev);
122
- struct drm_device *drm_dev = pci_get_drvdata(pdev);
123
- struct bochs_device *bochs = drm_dev->dev_private;
85
+ struct drm_device *drm_dev = dev_get_drvdata(dev);
12486
125
- drm_helper_resume_force_mode(drm_dev);
126
-
127
- if (bochs->fb.initialized) {
128
- console_lock();
129
- drm_fb_helper_set_suspend(&bochs->fb.helper, 0);
130
- console_unlock();
131
- }
132
-
133
- drm_kms_helper_poll_enable(drm_dev);
134
- return 0;
87
+ return drm_mode_config_helper_resume(drm_dev);
13588 }
13689 #endif
13790
....@@ -143,25 +96,10 @@
14396 /* ---------------------------------------------------------------------- */
14497 /* pci interface */
14598
146
-static int bochs_kick_out_firmware_fb(struct pci_dev *pdev)
147
-{
148
- struct apertures_struct *ap;
149
-
150
- ap = alloc_apertures(1);
151
- if (!ap)
152
- return -ENOMEM;
153
-
154
- ap->ranges[0].base = pci_resource_start(pdev, 0);
155
- ap->ranges[0].size = pci_resource_len(pdev, 0);
156
- drm_fb_helper_remove_conflicting_framebuffers(ap, "bochsdrmfb", false);
157
- kfree(ap);
158
-
159
- return 0;
160
-}
161
-
16299 static int bochs_pci_probe(struct pci_dev *pdev,
163100 const struct pci_device_id *ent)
164101 {
102
+ struct drm_device *dev;
165103 unsigned long fbsize;
166104 int ret;
167105
....@@ -171,18 +109,47 @@
171109 return -ENOMEM;
172110 }
173111
174
- ret = bochs_kick_out_firmware_fb(pdev);
112
+ ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "bochsdrmfb");
175113 if (ret)
176114 return ret;
177115
178
- return drm_get_pci_dev(pdev, ent, &bochs_driver);
116
+ dev = drm_dev_alloc(&bochs_driver, &pdev->dev);
117
+ if (IS_ERR(dev))
118
+ return PTR_ERR(dev);
119
+
120
+ ret = pci_enable_device(pdev);
121
+ if (ret)
122
+ goto err_free_dev;
123
+
124
+ dev->pdev = pdev;
125
+ pci_set_drvdata(pdev, dev);
126
+
127
+ ret = bochs_load(dev);
128
+ if (ret)
129
+ goto err_free_dev;
130
+
131
+ ret = drm_dev_register(dev, 0);
132
+ if (ret)
133
+ goto err_unload;
134
+
135
+ drm_fbdev_generic_setup(dev, 32);
136
+ return ret;
137
+
138
+err_unload:
139
+ bochs_unload(dev);
140
+err_free_dev:
141
+ drm_dev_put(dev);
142
+ return ret;
179143 }
180144
181145 static void bochs_pci_remove(struct pci_dev *pdev)
182146 {
183147 struct drm_device *dev = pci_get_drvdata(pdev);
184148
185
- drm_put_dev(dev);
149
+ drm_dev_unplug(dev);
150
+ drm_atomic_helper_shutdown(dev);
151
+ bochs_hw_fini(dev);
152
+ drm_dev_put(dev);
186153 }
187154
188155 static const struct pci_device_id bochs_pci_tbl[] = {