hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/gpu/drm/ast/ast_drv.c
....@@ -25,11 +25,17 @@
2525 /*
2626 * Authors: Dave Airlie <airlied@redhat.com>
2727 */
28
-#include <linux/module.h>
29
-#include <linux/console.h>
3028
31
-#include <drm/drmP.h>
29
+#include <linux/console.h>
30
+#include <linux/module.h>
31
+#include <linux/pci.h>
32
+
33
+#include <drm/drm_atomic_helper.h>
3234 #include <drm/drm_crtc_helper.h>
35
+#include <drm/drm_drv.h>
36
+#include <drm/drm_fb_helper.h>
37
+#include <drm/drm_gem_vram_helper.h>
38
+#include <drm/drm_probe_helper.h>
3339
3440 #include "ast_drv.h"
3541
....@@ -38,9 +44,33 @@
3844 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
3945 module_param_named(modeset, ast_modeset, int, 0400);
4046
41
-#define PCI_VENDOR_ASPEED 0x1a03
47
+/*
48
+ * DRM driver
49
+ */
4250
43
-static struct drm_driver driver;
51
+DEFINE_DRM_GEM_FOPS(ast_fops);
52
+
53
+static struct drm_driver ast_driver = {
54
+ .driver_features = DRIVER_ATOMIC |
55
+ DRIVER_GEM |
56
+ DRIVER_MODESET,
57
+
58
+ .fops = &ast_fops,
59
+ .name = DRIVER_NAME,
60
+ .desc = DRIVER_DESC,
61
+ .date = DRIVER_DATE,
62
+ .major = DRIVER_MAJOR,
63
+ .minor = DRIVER_MINOR,
64
+ .patchlevel = DRIVER_PATCHLEVEL,
65
+
66
+ DRM_GEM_VRAM_DRIVER
67
+};
68
+
69
+/*
70
+ * PCI driver
71
+ */
72
+
73
+#define PCI_VENDOR_ASPEED 0x1a03
4474
4575 #define AST_VGA_DEVICE(id, info) { \
4676 .class = PCI_BASE_CLASS_DISPLAY << 16, \
....@@ -51,14 +81,13 @@
5181 .subdevice = PCI_ANY_ID, \
5282 .driver_data = (unsigned long) info }
5383
54
-static const struct pci_device_id pciidlist[] = {
84
+static const struct pci_device_id ast_pciidlist[] = {
5585 AST_VGA_DEVICE(PCI_CHIP_AST2000, NULL),
5686 AST_VGA_DEVICE(PCI_CHIP_AST2100, NULL),
57
- /* AST_VGA_DEVICE(PCI_CHIP_AST1180, NULL), - don't bind to 1180 for now */
5887 {0, 0, 0},
5988 };
6089
61
-MODULE_DEVICE_TABLE(pci, pciidlist);
90
+MODULE_DEVICE_TABLE(pci, ast_pciidlist);
6291
6392 static void ast_kick_out_firmware_fb(struct pci_dev *pdev)
6493 {
....@@ -81,46 +110,54 @@
81110
82111 static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
83112 {
113
+ struct ast_private *ast;
114
+ struct drm_device *dev;
115
+ int ret;
116
+
84117 ast_kick_out_firmware_fb(pdev);
85118
86
- return drm_get_pci_dev(pdev, ent, &driver);
119
+ ret = pcim_enable_device(pdev);
120
+ if (ret)
121
+ return ret;
122
+
123
+ ast = ast_device_create(&ast_driver, pdev, ent->driver_data);
124
+ if (IS_ERR(ast))
125
+ return PTR_ERR(ast);
126
+ dev = &ast->base;
127
+
128
+ ret = drm_dev_register(dev, ent->driver_data);
129
+ if (ret)
130
+ return ret;
131
+
132
+ drm_fbdev_generic_setup(dev, 32);
133
+
134
+ return 0;
87135 }
88136
89
-static void
90
-ast_pci_remove(struct pci_dev *pdev)
137
+static void ast_pci_remove(struct pci_dev *pdev)
91138 {
92139 struct drm_device *dev = pci_get_drvdata(pdev);
93140
94
- drm_put_dev(dev);
141
+ drm_dev_unregister(dev);
142
+ drm_atomic_helper_shutdown(dev);
95143 }
96
-
97
-
98144
99145 static int ast_drm_freeze(struct drm_device *dev)
100146 {
101
- drm_kms_helper_poll_disable(dev);
147
+ int error;
102148
149
+ error = drm_mode_config_helper_suspend(dev);
150
+ if (error)
151
+ return error;
103152 pci_save_state(dev->pdev);
104
-
105
- console_lock();
106
- ast_fbdev_set_suspend(dev, 1);
107
- console_unlock();
108153 return 0;
109154 }
110155
111156 static int ast_drm_thaw(struct drm_device *dev)
112157 {
113
- int error = 0;
114
-
115158 ast_post_gpu(dev);
116159
117
- drm_mode_config_reset(dev);
118
- drm_helper_resume_force_mode(dev);
119
-
120
- console_lock();
121
- ast_fbdev_set_suspend(dev, 0);
122
- console_unlock();
123
- return error;
160
+ return drm_mode_config_helper_resume(dev);
124161 }
125162
126163 static int ast_drm_resume(struct drm_device *dev)
....@@ -133,8 +170,6 @@
133170 ret = ast_drm_thaw(dev);
134171 if (ret)
135172 return ret;
136
-
137
- drm_kms_helper_poll_enable(dev);
138173 return 0;
139174 }
140175
....@@ -152,6 +187,7 @@
152187 pci_set_power_state(pdev, PCI_D3hot);
153188 return 0;
154189 }
190
+
155191 static int ast_pm_resume(struct device *dev)
156192 {
157193 struct pci_dev *pdev = to_pci_dev(dev);
....@@ -163,11 +199,7 @@
163199 {
164200 struct pci_dev *pdev = to_pci_dev(dev);
165201 struct drm_device *ddev = pci_get_drvdata(pdev);
166
-
167
- if (!ddev || !ddev->dev_private)
168
- return -ENODEV;
169202 return ast_drm_freeze(ddev);
170
-
171203 }
172204
173205 static int ast_pm_thaw(struct device *dev)
....@@ -196,41 +228,10 @@
196228
197229 static struct pci_driver ast_pci_driver = {
198230 .name = DRIVER_NAME,
199
- .id_table = pciidlist,
231
+ .id_table = ast_pciidlist,
200232 .probe = ast_pci_probe,
201233 .remove = ast_pci_remove,
202234 .driver.pm = &ast_pm_ops,
203
-};
204
-
205
-static const struct file_operations ast_fops = {
206
- .owner = THIS_MODULE,
207
- .open = drm_open,
208
- .release = drm_release,
209
- .unlocked_ioctl = drm_ioctl,
210
- .mmap = ast_mmap,
211
- .poll = drm_poll,
212
- .compat_ioctl = drm_compat_ioctl,
213
- .read = drm_read,
214
-};
215
-
216
-static struct drm_driver driver = {
217
- .driver_features = DRIVER_MODESET | DRIVER_GEM,
218
-
219
- .load = ast_driver_load,
220
- .unload = ast_driver_unload,
221
-
222
- .fops = &ast_fops,
223
- .name = DRIVER_NAME,
224
- .desc = DRIVER_DESC,
225
- .date = DRIVER_DATE,
226
- .major = DRIVER_MAJOR,
227
- .minor = DRIVER_MINOR,
228
- .patchlevel = DRIVER_PATCHLEVEL,
229
-
230
- .gem_free_object_unlocked = ast_gem_free_object,
231
- .dumb_create = ast_dumb_create,
232
- .dumb_map_offset = ast_dumb_mmap_offset,
233
-
234235 };
235236
236237 static int __init ast_init(void)
....@@ -253,4 +254,3 @@
253254 MODULE_AUTHOR(DRIVER_AUTHOR);
254255 MODULE_DESCRIPTION(DRIVER_DESC);
255256 MODULE_LICENSE("GPL and additional rights");
256
-