hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/gpu/drm/virtio/virtgpu_display.c
....@@ -25,10 +25,14 @@
2525 * OTHER DEALINGS IN THE SOFTWARE.
2626 */
2727
28
-#include "virtgpu_drv.h"
29
-#include <drm/drm_crtc_helper.h>
3028 #include <drm/drm_atomic_helper.h>
29
+#include <drm/drm_damage_helper.h>
30
+#include <drm/drm_fourcc.h>
3131 #include <drm/drm_gem_framebuffer_helper.h>
32
+#include <drm/drm_probe_helper.h>
33
+#include <drm/drm_simple_kms_helper.h>
34
+
35
+#include "virtgpu_drv.h"
3236
3337 #define XRES_MIN 32
3438 #define YRES_MIN 32
....@@ -38,6 +42,9 @@
3842
3943 #define XRES_MAX 8192
4044 #define YRES_MAX 8192
45
+
46
+#define drm_connector_to_virtio_gpu_output(x) \
47
+ container_of(x, struct virtio_gpu_output, conn)
4148
4249 static const struct drm_crtc_funcs virtio_gpu_crtc_funcs = {
4350 .set_config = drm_atomic_helper_set_config,
....@@ -49,26 +56,13 @@
4956 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
5057 };
5158
52
-static int
53
-virtio_gpu_framebuffer_surface_dirty(struct drm_framebuffer *fb,
54
- struct drm_file *file_priv,
55
- unsigned int flags, unsigned int color,
56
- struct drm_clip_rect *clips,
57
- unsigned int num_clips)
58
-{
59
- struct virtio_gpu_framebuffer *virtio_gpu_fb
60
- = to_virtio_gpu_framebuffer(fb);
61
-
62
- return virtio_gpu_surface_dirty(virtio_gpu_fb, clips, num_clips);
63
-}
64
-
6559 static const struct drm_framebuffer_funcs virtio_gpu_fb_funcs = {
6660 .create_handle = drm_gem_fb_create_handle,
6761 .destroy = drm_gem_fb_destroy,
68
- .dirty = virtio_gpu_framebuffer_surface_dirty,
62
+ .dirty = drm_atomic_helper_dirtyfb,
6963 };
7064
71
-int
65
+static int
7266 virtio_gpu_framebuffer_init(struct drm_device *dev,
7367 struct virtio_gpu_framebuffer *vgfb,
7468 const struct drm_mode_fb_cmd2 *mode_cmd,
....@@ -85,10 +79,6 @@
8579 vgfb->base.obj[0] = NULL;
8680 return ret;
8781 }
88
-
89
- spin_lock_init(&vgfb->dirty_lock);
90
- vgfb->x1 = vgfb->y1 = INT_MAX;
91
- vgfb->x2 = vgfb->y2 = 0;
9282 return 0;
9383 }
9484
....@@ -101,14 +91,12 @@
10191 virtio_gpu_cmd_set_scanout(vgdev, output->index, 0,
10292 crtc->mode.hdisplay,
10393 crtc->mode.vdisplay, 0, 0);
94
+ virtio_gpu_notify(vgdev);
10495 }
10596
10697 static void virtio_gpu_crtc_atomic_enable(struct drm_crtc *crtc,
10798 struct drm_crtc_state *old_state)
10899 {
109
- struct virtio_gpu_output *output = drm_crtc_to_virtio_gpu_output(crtc);
110
-
111
- output->enabled = true;
112100 }
113101
114102 static void virtio_gpu_crtc_atomic_disable(struct drm_crtc *crtc,
....@@ -119,7 +107,7 @@
119107 struct virtio_gpu_output *output = drm_crtc_to_virtio_gpu_output(crtc);
120108
121109 virtio_gpu_cmd_set_scanout(vgdev, output->index, 0, 0, 0, 0, 0);
122
- output->enabled = false;
110
+ virtio_gpu_notify(vgdev);
123111 }
124112
125113 static int virtio_gpu_crtc_atomic_check(struct drm_crtc *crtc,
....@@ -131,13 +119,17 @@
131119 static void virtio_gpu_crtc_atomic_flush(struct drm_crtc *crtc,
132120 struct drm_crtc_state *old_state)
133121 {
134
- unsigned long flags;
122
+ struct virtio_gpu_output *output = drm_crtc_to_virtio_gpu_output(crtc);
135123
136
- spin_lock_irqsave(&crtc->dev->event_lock, flags);
137
- if (crtc->state->event)
138
- drm_crtc_send_vblank_event(crtc, crtc->state->event);
139
- crtc->state->event = NULL;
140
- spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
124
+ /*
125
+ * virtio-gpu can't do modeset and plane update operations
126
+ * independent from each other. So the actual modeset happens
127
+ * in the plane update callback, and here we just check
128
+ * whenever we must force the modeset.
129
+ */
130
+ if (drm_atomic_crtc_needs_modeset(crtc->state)) {
131
+ output->needs_modeset = true;
132
+ }
141133 }
142134
143135 static const struct drm_crtc_helper_funcs virtio_gpu_crtc_helper_funcs = {
....@@ -180,13 +172,13 @@
180172 count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
181173
182174 if (width == 0 || height == 0) {
183
- width = XRES_DEF;
184
- height = YRES_DEF;
185175 drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
186176 } else {
187177 DRM_DEBUG("add mode: %dx%d\n", width, height);
188178 mode = drm_cvt_mode(connector->dev, width, height, 60,
189179 false, false, false);
180
+ if (!mode)
181
+ return count;
190182 mode->type |= DRM_MODE_TYPE_PREFERRED;
191183 drm_mode_probed_add(connector, mode);
192184 count++;
....@@ -256,10 +248,6 @@
256248 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
257249 };
258250
259
-static const struct drm_encoder_funcs virtio_gpu_enc_funcs = {
260
- .destroy = drm_encoder_cleanup,
261
-};
262
-
263251 static int vgdev_output_init(struct virtio_gpu_device *vgdev, int index)
264252 {
265253 struct drm_device *dev = vgdev->ddev;
....@@ -292,8 +280,7 @@
292280 if (vgdev->has_edid)
293281 drm_connector_attach_edid_property(connector);
294282
295
- drm_encoder_init(dev, encoder, &virtio_gpu_enc_funcs,
296
- DRM_MODE_ENCODER_VIRTUAL, NULL);
283
+ drm_simple_encoder_init(dev, encoder, DRM_MODE_ENCODER_VIRTUAL);
297284 drm_encoder_helper_add(encoder, &virtio_gpu_enc_helper_funcs);
298285 encoder->possible_crtcs = 1 << index;
299286
....@@ -323,30 +310,12 @@
323310 ret = virtio_gpu_framebuffer_init(dev, virtio_gpu_fb, mode_cmd, obj);
324311 if (ret) {
325312 kfree(virtio_gpu_fb);
326
- drm_gem_object_put_unlocked(obj);
313
+ drm_gem_object_put(obj);
327314 return NULL;
328315 }
329316
330317 return &virtio_gpu_fb->base;
331318 }
332
-
333
-static void vgdev_atomic_commit_tail(struct drm_atomic_state *state)
334
-{
335
- struct drm_device *dev = state->dev;
336
-
337
- drm_atomic_helper_commit_modeset_disables(dev, state);
338
- drm_atomic_helper_commit_modeset_enables(dev, state);
339
- drm_atomic_helper_commit_planes(dev, state, 0);
340
-
341
- drm_atomic_helper_commit_hw_done(state);
342
-
343
- drm_atomic_helper_wait_for_vblanks(dev, state);
344
- drm_atomic_helper_cleanup_planes(dev, state);
345
-}
346
-
347
-static const struct drm_mode_config_helper_funcs virtio_mode_config_helpers = {
348
- .atomic_commit_tail = vgdev_atomic_commit_tail,
349
-};
350319
351320 static const struct drm_mode_config_funcs virtio_gpu_mode_funcs = {
352321 .fb_create = virtio_gpu_user_framebuffer_create,
....@@ -354,13 +323,15 @@
354323 .atomic_commit = drm_atomic_helper_commit,
355324 };
356325
357
-void virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev)
326
+int virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev)
358327 {
359
- int i;
328
+ int i, ret;
360329
361
- drm_mode_config_init(vgdev->ddev);
330
+ ret = drmm_mode_config_init(vgdev->ddev);
331
+ if (ret)
332
+ return ret;
333
+
362334 vgdev->ddev->mode_config.funcs = &virtio_gpu_mode_funcs;
363
- vgdev->ddev->mode_config.helper_private = &virtio_mode_config_helpers;
364335
365336 /* modes will be validated against the framebuffer size */
366337 vgdev->ddev->mode_config.min_width = XRES_MIN;
....@@ -372,6 +343,7 @@
372343 vgdev_output_init(vgdev, i);
373344
374345 drm_mode_config_reset(vgdev->ddev);
346
+ return 0;
375347 }
376348
377349 void virtio_gpu_modeset_fini(struct virtio_gpu_device *vgdev)
....@@ -380,6 +352,4 @@
380352
381353 for (i = 0 ; i < vgdev->num_scanouts; ++i)
382354 kfree(vgdev->outputs[i].edid);
383
- drm_atomic_helper_shutdown(vgdev->ddev);
384
- drm_mode_config_cleanup(vgdev->ddev);
385355 }