blob: 6063f3a153290d4976e17259655d9cee556c3182 [file] [log] [blame]
Dave Airlief64122c2013-02-25 14:47:55 +10001/*
2 * Copyright 2013 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Dave Airlie
23 * Alon Levy
24 */
25
Randy Dunlapc5416d662013-12-20 10:58:15 -080026#include <linux/crc32.h>
Sam Ravnborgc0f4b752019-06-30 08:18:58 +020027#include <linux/delay.h>
28
Dave Airliece5c2072020-09-08 14:41:40 +100029#include <drm/drm_drv.h>
Gabriel Krisman Bertazi10a0bd82017-02-27 17:43:24 -030030#include <drm/drm_atomic.h>
Daniel Vetterfcd70cd2019-01-17 22:03:34 +010031#include <drm/drm_atomic_helper.h>
Peter Wubf8744e2018-09-10 15:21:56 +020032#include <drm/drm_gem_framebuffer_helper.h>
Daniel Vetterfcd70cd2019-01-17 22:03:34 +010033#include <drm/drm_plane_helper.h>
34#include <drm/drm_probe_helper.h>
Thomas Zimmermann6f2bb112020-02-28 09:18:28 +010035#include <drm/drm_simple_kms_helper.h>
Dave Airlief64122c2013-02-25 14:47:55 +100036
Masahiro Yamadaedaf4922017-04-24 13:50:30 +090037#include "qxl_drv.h"
38#include "qxl_object.h"
39
Dave Airlie07f8d9b2013-07-02 06:37:13 +010040static bool qxl_head_enabled(struct qxl_head *head)
41{
42 return head->width && head->height;
43}
44
Anton Vasilyev66e0c8a2018-07-27 18:30:58 +030045static int qxl_alloc_client_monitors_config(struct qxl_device *qdev,
46 unsigned int count)
Dave Airlief64122c2013-02-25 14:47:55 +100047{
48 if (qdev->client_monitors_config &&
49 count > qdev->client_monitors_config->count) {
50 kfree(qdev->client_monitors_config);
Dave Airlie62c8ba72013-04-16 13:36:00 +100051 qdev->client_monitors_config = NULL;
Dave Airlief64122c2013-02-25 14:47:55 +100052 }
53 if (!qdev->client_monitors_config) {
54 qdev->client_monitors_config = kzalloc(
Gustavo A. R. Silvad4b9dd52019-01-08 10:21:52 -060055 struct_size(qdev->client_monitors_config,
56 heads, count), GFP_KERNEL);
Gerd Hoffmann735581a2018-04-20 09:19:01 +020057 if (!qdev->client_monitors_config)
Anton Vasilyev66e0c8a2018-07-27 18:30:58 +030058 return -ENOMEM;
Dave Airlief64122c2013-02-25 14:47:55 +100059 }
60 qdev->client_monitors_config->count = count;
Anton Vasilyev66e0c8a2018-07-27 18:30:58 +030061 return 0;
Dave Airlief64122c2013-02-25 14:47:55 +100062}
63
Christophe Fergeau9e3b3172016-11-08 10:12:08 +010064enum {
65 MONITORS_CONFIG_MODIFIED,
66 MONITORS_CONFIG_UNCHANGED,
67 MONITORS_CONFIG_BAD_CRC,
Anton Vasilyev66e0c8a2018-07-27 18:30:58 +030068 MONITORS_CONFIG_ERROR,
Christophe Fergeau9e3b3172016-11-08 10:12:08 +010069};
70
Dave Airlief64122c2013-02-25 14:47:55 +100071static int qxl_display_copy_rom_client_monitors_config(struct qxl_device *qdev)
72{
73 int i;
74 int num_monitors;
75 uint32_t crc;
Christophe Fergeau9e3b3172016-11-08 10:12:08 +010076 int status = MONITORS_CONFIG_UNCHANGED;
Dave Airlief64122c2013-02-25 14:47:55 +100077
Dave Airlief64122c2013-02-25 14:47:55 +100078 num_monitors = qdev->rom->client_monitors_config.count;
79 crc = crc32(0, (const uint8_t *)&qdev->rom->client_monitors_config,
80 sizeof(qdev->rom->client_monitors_config));
Gerd Hoffmann735581a2018-04-20 09:19:01 +020081 if (crc != qdev->rom->client_monitors_config_crc)
Christophe Fergeau9e3b3172016-11-08 10:12:08 +010082 return MONITORS_CONFIG_BAD_CRC;
Gerd Hoffmannc50fad82017-03-01 11:12:33 +010083 if (!num_monitors) {
84 DRM_DEBUG_KMS("no client monitors configured\n");
85 return status;
86 }
Gerd Hoffmann21c76bd2019-01-18 13:20:12 +010087 if (num_monitors > qxl_num_crtc) {
Dave Airlie5b8788c2013-07-01 14:14:38 +100088 DRM_DEBUG_KMS("client monitors list will be truncated: %d < %d\n",
Gerd Hoffmann21c76bd2019-01-18 13:20:12 +010089 qxl_num_crtc, num_monitors);
90 num_monitors = qxl_num_crtc;
Dave Airlief64122c2013-02-25 14:47:55 +100091 } else {
92 num_monitors = qdev->rom->client_monitors_config.count;
93 }
Christophe Fergeau9e3b3172016-11-08 10:12:08 +010094 if (qdev->client_monitors_config
95 && (num_monitors != qdev->client_monitors_config->count)) {
96 status = MONITORS_CONFIG_MODIFIED;
97 }
Anton Vasilyev66e0c8a2018-07-27 18:30:58 +030098 if (qxl_alloc_client_monitors_config(qdev, num_monitors)) {
99 status = MONITORS_CONFIG_ERROR;
100 return status;
101 }
Dave Airlief64122c2013-02-25 14:47:55 +1000102 /* we copy max from the client but it isn't used */
Gerd Hoffmann21c76bd2019-01-18 13:20:12 +0100103 qdev->client_monitors_config->max_allowed = qxl_num_crtc;
Dave Airlief64122c2013-02-25 14:47:55 +1000104 for (i = 0 ; i < qdev->client_monitors_config->count ; ++i) {
105 struct qxl_urect *c_rect =
106 &qdev->rom->client_monitors_config.heads[i];
107 struct qxl_head *client_head =
108 &qdev->client_monitors_config->heads[i];
Christophe Fergeau9e3b3172016-11-08 10:12:08 +0100109 if (client_head->x != c_rect->left) {
110 client_head->x = c_rect->left;
111 status = MONITORS_CONFIG_MODIFIED;
112 }
113 if (client_head->y != c_rect->top) {
114 client_head->y = c_rect->top;
115 status = MONITORS_CONFIG_MODIFIED;
116 }
117 if (client_head->width != c_rect->right - c_rect->left) {
118 client_head->width = c_rect->right - c_rect->left;
119 status = MONITORS_CONFIG_MODIFIED;
120 }
121 if (client_head->height != c_rect->bottom - c_rect->top) {
122 client_head->height = c_rect->bottom - c_rect->top;
123 status = MONITORS_CONFIG_MODIFIED;
124 }
125 if (client_head->surface_id != 0) {
126 client_head->surface_id = 0;
127 status = MONITORS_CONFIG_MODIFIED;
128 }
129 if (client_head->id != i) {
130 client_head->id = i;
131 status = MONITORS_CONFIG_MODIFIED;
132 }
133 if (client_head->flags != 0) {
134 client_head->flags = 0;
135 status = MONITORS_CONFIG_MODIFIED;
136 }
Dave Airlie07f8d9b2013-07-02 06:37:13 +0100137 DRM_DEBUG_KMS("read %dx%d+%d+%d\n", client_head->width, client_head->height,
138 client_head->x, client_head->y);
Dave Airlief64122c2013-02-25 14:47:55 +1000139 }
Christophe Fergeau9e3b3172016-11-08 10:12:08 +0100140
141 return status;
Dave Airlief64122c2013-02-25 14:47:55 +1000142}
143
Dave Airlie7dea0942014-10-28 11:28:44 +1000144static void qxl_update_offset_props(struct qxl_device *qdev)
145{
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -0200146 struct drm_device *dev = &qdev->ddev;
Dave Airlie7dea0942014-10-28 11:28:44 +1000147 struct drm_connector *connector;
148 struct qxl_output *output;
149 struct qxl_head *head;
150
151 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
152 output = drm_connector_to_qxl_output(connector);
153
154 head = &qdev->client_monitors_config->heads[output->index];
155
156 drm_object_property_set_value(&connector->base,
157 dev->mode_config.suggested_x_property, head->x);
158 drm_object_property_set_value(&connector->base,
159 dev->mode_config.suggested_y_property, head->y);
160 }
161}
162
Dave Airlief64122c2013-02-25 14:47:55 +1000163void qxl_display_read_client_monitors_config(struct qxl_device *qdev)
164{
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -0200165 struct drm_device *dev = &qdev->ddev;
Sidong Yangbbaac132020-05-24 11:26:23 +0900166 struct drm_modeset_acquire_ctx ctx;
167 int status, retries, ret;
Christophe Fergeau9e3b3172016-11-08 10:12:08 +0100168
Gerd Hoffmann90621552017-03-01 11:12:32 +0100169 for (retries = 0; retries < 10; retries++) {
Christophe Fergeau9e3b3172016-11-08 10:12:08 +0100170 status = qxl_display_copy_rom_client_monitors_config(qdev);
Gerd Hoffmann90621552017-03-01 11:12:32 +0100171 if (status != MONITORS_CONFIG_BAD_CRC)
172 break;
173 udelay(5);
174 }
Anton Vasilyev66e0c8a2018-07-27 18:30:58 +0300175 if (status == MONITORS_CONFIG_ERROR) {
176 DRM_DEBUG_KMS("ignoring client monitors config: error");
177 return;
178 }
Gerd Hoffmann90621552017-03-01 11:12:32 +0100179 if (status == MONITORS_CONFIG_BAD_CRC) {
Gerd Hoffmann90621552017-03-01 11:12:32 +0100180 DRM_DEBUG_KMS("ignoring client monitors config: bad crc");
181 return;
Christophe Fergeau9e3b3172016-11-08 10:12:08 +0100182 }
183 if (status == MONITORS_CONFIG_UNCHANGED) {
Gerd Hoffmann90621552017-03-01 11:12:32 +0100184 DRM_DEBUG_KMS("ignoring client monitors config: unchanged");
Christophe Fergeau9e3b3172016-11-08 10:12:08 +0100185 return;
Dave Airlief64122c2013-02-25 14:47:55 +1000186 }
Marc-André Lureau4fdb0862013-10-18 16:11:29 +0200187
Sidong Yangbbaac132020-05-24 11:26:23 +0900188 DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE, ret);
Dave Airlie7dea0942014-10-28 11:28:44 +1000189 qxl_update_offset_props(qdev);
Dave Airliece5c2072020-09-08 14:41:40 +1000190 DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -0200191 if (!drm_helper_hpd_irq_event(dev)) {
Marc-André Lureau4fdb0862013-10-18 16:11:29 +0200192 /* notify that the monitor configuration changed, to
193 adjust at the arbitrary resolution */
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -0200194 drm_kms_helper_hotplug_event(dev);
Marc-André Lureau4fdb0862013-10-18 16:11:29 +0200195 }
Dave Airlief64122c2013-02-25 14:47:55 +1000196}
197
Gerd Hoffmannfeba24d2019-01-18 13:20:17 +0100198static int qxl_check_mode(struct qxl_device *qdev,
199 unsigned int width,
200 unsigned int height)
201{
202 unsigned int stride;
203 unsigned int size;
204
205 if (check_mul_overflow(width, 4u, &stride))
206 return -EINVAL;
207 if (check_mul_overflow(stride, height, &size))
208 return -EINVAL;
209 if (size > qdev->vram_size)
210 return -ENOMEM;
211 return 0;
212}
213
214static int qxl_check_framebuffer(struct qxl_device *qdev,
215 struct qxl_bo *bo)
216{
217 return qxl_check_mode(qdev, bo->surf.width, bo->surf.height);
218}
219
Gerd Hoffmann1b043672019-01-18 13:20:18 +0100220static int qxl_add_mode(struct drm_connector *connector,
221 unsigned int width,
222 unsigned int height,
223 bool preferred)
224{
225 struct drm_device *dev = connector->dev;
Daniel Vettere304f8a2020-04-15 09:40:02 +0200226 struct qxl_device *qdev = to_qxl(dev);
Gerd Hoffmann1b043672019-01-18 13:20:18 +0100227 struct drm_display_mode *mode = NULL;
228 int rc;
229
230 rc = qxl_check_mode(qdev, width, height);
231 if (rc != 0)
232 return 0;
233
234 mode = drm_cvt_mode(dev, width, height, 60, false, false, false);
235 if (preferred)
236 mode->type |= DRM_MODE_TYPE_PREFERRED;
237 mode->hdisplay = width;
238 mode->vdisplay = height;
239 drm_mode_set_name(mode);
240 drm_mode_probed_add(connector, mode);
241 return 1;
242}
243
244static int qxl_add_monitors_config_modes(struct drm_connector *connector)
Dave Airlief64122c2013-02-25 14:47:55 +1000245{
246 struct drm_device *dev = connector->dev;
Daniel Vettere304f8a2020-04-15 09:40:02 +0200247 struct qxl_device *qdev = to_qxl(dev);
Dave Airlief64122c2013-02-25 14:47:55 +1000248 struct qxl_output *output = drm_connector_to_qxl_output(connector);
249 int h = output->index;
Dave Airlief64122c2013-02-25 14:47:55 +1000250 struct qxl_head *head;
251
Gerd Hoffmann2d856f942017-03-01 11:12:34 +0100252 if (!qdev->monitors_config)
253 return 0;
Gerd Hoffmann21c76bd2019-01-18 13:20:12 +0100254 if (h >= qxl_num_crtc)
Gerd Hoffmann2d856f942017-03-01 11:12:34 +0100255 return 0;
Dave Airlie07f8d9b2013-07-02 06:37:13 +0100256 if (!qdev->client_monitors_config)
Dave Airlief64122c2013-02-25 14:47:55 +1000257 return 0;
Gerd Hoffmann2d856f942017-03-01 11:12:34 +0100258 if (h >= qdev->client_monitors_config->count)
259 return 0;
260
Dave Airlie07f8d9b2013-07-02 06:37:13 +0100261 head = &qdev->client_monitors_config->heads[h];
Gerd Hoffmann2d856f942017-03-01 11:12:34 +0100262 DRM_DEBUG_KMS("head %d is %dx%d\n", h, head->width, head->height);
Dave Airlief64122c2013-02-25 14:47:55 +1000263
Gerd Hoffmann1b043672019-01-18 13:20:18 +0100264 return qxl_add_mode(connector, head->width, head->height, true);
Dave Airlief64122c2013-02-25 14:47:55 +1000265}
266
Jonathon Jongsmabd3e1c72015-08-20 14:04:32 -0500267static struct mode_size {
268 int w;
269 int h;
Gerd Hoffmannb5f030b2019-01-18 13:20:19 +0100270} extra_modes[] = {
Jonathon Jongsmabd3e1c72015-08-20 14:04:32 -0500271 { 720, 480},
Jonathon Jongsmabd3e1c72015-08-20 14:04:32 -0500272 {1152, 768},
Jonathon Jongsmabd3e1c72015-08-20 14:04:32 -0500273 {1280, 854},
Jonathon Jongsmabd3e1c72015-08-20 14:04:32 -0500274};
275
Gerd Hoffmannb5f030b2019-01-18 13:20:19 +0100276static int qxl_add_extra_modes(struct drm_connector *connector)
Dave Airlief64122c2013-02-25 14:47:55 +1000277{
Gerd Hoffmann1b043672019-01-18 13:20:18 +0100278 int i, ret = 0;
Shayenne da Luz Moura408799e2018-10-26 16:22:55 -0300279
Gerd Hoffmannb5f030b2019-01-18 13:20:19 +0100280 for (i = 0; i < ARRAY_SIZE(extra_modes); i++)
Gerd Hoffmann1b043672019-01-18 13:20:18 +0100281 ret += qxl_add_mode(connector,
Gerd Hoffmannb5f030b2019-01-18 13:20:19 +0100282 extra_modes[i].w,
283 extra_modes[i].h,
Gerd Hoffmann1b043672019-01-18 13:20:18 +0100284 false);
285 return ret;
Dave Airlief64122c2013-02-25 14:47:55 +1000286}
287
Gerd Hoffmann998010b2018-04-20 09:19:02 +0200288static void qxl_send_monitors_config(struct qxl_device *qdev)
289{
290 int i;
291
292 BUG_ON(!qdev->ram_header->monitors_config);
293
294 if (qdev->monitors_config->count == 0)
295 return;
296
297 for (i = 0 ; i < qdev->monitors_config->count ; ++i) {
298 struct qxl_head *head = &qdev->monitors_config->heads[i];
299
300 if (head->y > 8192 || head->x > 8192 ||
301 head->width > 8192 || head->height > 8192) {
302 DRM_ERROR("head %d wrong: %dx%d+%d+%d\n",
303 i, head->width, head->height,
304 head->x, head->y);
305 return;
306 }
307 }
308 qxl_io_monitors_config(qdev);
309}
310
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200311static void qxl_crtc_update_monitors_config(struct drm_crtc *crtc,
312 const char *reason)
313{
314 struct drm_device *dev = crtc->dev;
Daniel Vettere304f8a2020-04-15 09:40:02 +0200315 struct qxl_device *qdev = to_qxl(dev);
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200316 struct qxl_crtc *qcrtc = to_qxl_crtc(crtc);
317 struct qxl_head head;
318 int oldcount, i = qcrtc->index;
319
Gerd Hoffmann16620542019-01-18 13:20:09 +0100320 if (!qdev->primary_bo) {
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200321 DRM_DEBUG_KMS("no primary surface, skip (%s)\n", reason);
322 return;
323 }
324
Gerd Hoffmann21c76bd2019-01-18 13:20:12 +0100325 if (!qdev->monitors_config || qxl_num_crtc <= i)
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200326 return;
327
328 head.id = i;
329 head.flags = 0;
330 oldcount = qdev->monitors_config->count;
331 if (crtc->state->active) {
332 struct drm_display_mode *mode = &crtc->mode;
Shayenne da Luz Moura408799e2018-10-26 16:22:55 -0300333
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200334 head.width = mode->hdisplay;
335 head.height = mode->vdisplay;
336 head.x = crtc->x;
337 head.y = crtc->y;
338 if (qdev->monitors_config->count < i + 1)
339 qdev->monitors_config->count = i + 1;
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100340 if (qdev->primary_bo == qdev->dumb_shadow_bo)
341 head.x += qdev->dumb_heads[i].x;
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200342 } else if (i > 0) {
343 head.width = 0;
344 head.height = 0;
345 head.x = 0;
346 head.y = 0;
347 if (qdev->monitors_config->count == i + 1)
348 qdev->monitors_config->count = i;
349 } else {
350 DRM_DEBUG_KMS("inactive head 0, skip (%s)\n", reason);
351 return;
352 }
353
354 if (head.width == qdev->monitors_config->heads[i].width &&
355 head.height == qdev->monitors_config->heads[i].height &&
356 head.x == qdev->monitors_config->heads[i].x &&
357 head.y == qdev->monitors_config->heads[i].y &&
358 oldcount == qdev->monitors_config->count)
359 return;
360
361 DRM_DEBUG_KMS("head %d, %dx%d, at +%d+%d, %s (%s)\n",
362 i, head.width, head.height, head.x, head.y,
363 crtc->state->active ? "on" : "off", reason);
364 if (oldcount != qdev->monitors_config->count)
365 DRM_DEBUG_KMS("active heads %d -> %d (%d total)\n",
366 oldcount, qdev->monitors_config->count,
Gerd Hoffmann21c76bd2019-01-18 13:20:12 +0100367 qxl_num_crtc);
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200368
369 qdev->monitors_config->heads[i] = head;
Gerd Hoffmann21c76bd2019-01-18 13:20:12 +0100370 qdev->monitors_config->max_allowed = qxl_num_crtc;
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200371 qxl_send_monitors_config(qdev);
372}
373
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300374static void qxl_crtc_atomic_flush(struct drm_crtc *crtc,
375 struct drm_crtc_state *old_crtc_state)
376{
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200377 qxl_crtc_update_monitors_config(crtc, "flush");
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300378}
379
Dave Airlief64122c2013-02-25 14:47:55 +1000380static void qxl_crtc_destroy(struct drm_crtc *crtc)
381{
382 struct qxl_crtc *qxl_crtc = to_qxl_crtc(crtc);
383
Ray Strode94280882017-11-27 16:50:10 -0500384 qxl_bo_unref(&qxl_crtc->cursor_bo);
Dave Airlief64122c2013-02-25 14:47:55 +1000385 drm_crtc_cleanup(crtc);
386 kfree(qxl_crtc);
387}
388
Dave Airlief64122c2013-02-25 14:47:55 +1000389static const struct drm_crtc_funcs qxl_crtc_funcs = {
Gabriel Krisman Bertazibc8a00d2017-02-27 17:43:26 -0300390 .set_config = drm_atomic_helper_set_config,
Dave Airlief64122c2013-02-25 14:47:55 +1000391 .destroy = qxl_crtc_destroy,
Gabriel Krisman Bertazi9973c872017-02-27 17:43:27 -0300392 .page_flip = drm_atomic_helper_page_flip,
Gabriel Krisman Bertazi9ade8b92017-02-27 17:43:23 -0300393 .reset = drm_atomic_helper_crtc_reset,
394 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
395 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
Dave Airlief64122c2013-02-25 14:47:55 +1000396};
397
Dave Airlie6d01f1f2013-04-16 13:24:25 +1000398static int qxl_framebuffer_surface_dirty(struct drm_framebuffer *fb,
399 struct drm_file *file_priv,
Shayenne da Luz Moura1b000492018-10-26 16:23:49 -0300400 unsigned int flags, unsigned int color,
Dave Airlie6d01f1f2013-04-16 13:24:25 +1000401 struct drm_clip_rect *clips,
Shayenne da Luz Moura1b000492018-10-26 16:23:49 -0300402 unsigned int num_clips)
Dave Airlief64122c2013-02-25 14:47:55 +1000403{
404 /* TODO: vmwgfx where this was cribbed from had locking. Why? */
Daniel Vettere304f8a2020-04-15 09:40:02 +0200405 struct qxl_device *qdev = to_qxl(fb->dev);
Dave Airlief64122c2013-02-25 14:47:55 +1000406 struct drm_clip_rect norect;
407 struct qxl_bo *qobj;
Sidong Yangbbaac132020-05-24 11:26:23 +0900408 struct drm_modeset_acquire_ctx ctx;
Gerd Hoffmann49799042019-01-18 13:20:10 +0100409 bool is_primary;
Sidong Yangbbaac132020-05-24 11:26:23 +0900410 int inc = 1, ret;
Dave Airlief64122c2013-02-25 14:47:55 +1000411
Sidong Yangbbaac132020-05-24 11:26:23 +0900412 DRM_MODESET_LOCK_ALL_BEGIN(fb->dev, ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE, ret);
Ville Syrjälä73e9efd2013-12-04 14:13:58 +0200413
Peter Wubf8744e2018-09-10 15:21:56 +0200414 qobj = gem_to_qxl_bo(fb->obj[0]);
Dave Airlieb2b44652013-05-13 12:48:40 +1000415 /* if we aren't primary surface ignore this */
Gerd Hoffmann49799042019-01-18 13:20:10 +0100416 is_primary = qobj->shadow ? qobj->shadow->is_primary : qobj->is_primary;
Sidong Yangbbaac132020-05-24 11:26:23 +0900417 if (!is_primary)
418 goto out_lock_end;
Dave Airlieb2b44652013-05-13 12:48:40 +1000419
Dave Airlief64122c2013-02-25 14:47:55 +1000420 if (!num_clips) {
421 num_clips = 1;
422 clips = &norect;
423 norect.x1 = norect.y1 = 0;
424 norect.x2 = fb->width;
425 norect.y2 = fb->height;
426 } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) {
427 num_clips /= 2;
428 inc = 2; /* skip source rects */
429 }
430
Peter Wubf8744e2018-09-10 15:21:56 +0200431 qxl_draw_dirty_fb(qdev, fb, qobj, flags, color,
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100432 clips, num_clips, inc, 0);
Ville Syrjälä73e9efd2013-12-04 14:13:58 +0200433
Sidong Yangbbaac132020-05-24 11:26:23 +0900434out_lock_end:
Dave Airliece5c2072020-09-08 14:41:40 +1000435 DRM_MODESET_LOCK_ALL_END(fb->dev, ctx, ret);
Ville Syrjälä73e9efd2013-12-04 14:13:58 +0200436
Dave Airlief64122c2013-02-25 14:47:55 +1000437 return 0;
438}
439
440static const struct drm_framebuffer_funcs qxl_fb_funcs = {
Peter Wubf8744e2018-09-10 15:21:56 +0200441 .destroy = drm_gem_fb_destroy,
Dave Airlief64122c2013-02-25 14:47:55 +1000442 .dirty = qxl_framebuffer_surface_dirty,
Peter Wubf8744e2018-09-10 15:21:56 +0200443 .create_handle = drm_gem_fb_create_handle,
Dave Airlief64122c2013-02-25 14:47:55 +1000444};
445
Laurent Pinchart0b20a0f2017-06-30 12:36:44 +0300446static void qxl_crtc_atomic_enable(struct drm_crtc *crtc,
447 struct drm_crtc_state *old_state)
Dave Airlief64122c2013-02-25 14:47:55 +1000448{
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200449 qxl_crtc_update_monitors_config(crtc, "enable");
Dave Airlief64122c2013-02-25 14:47:55 +1000450}
451
Laurent Pinchart64581712017-06-30 12:36:45 +0300452static void qxl_crtc_atomic_disable(struct drm_crtc *crtc,
453 struct drm_crtc_state *old_state)
Dave Airlie07f8d9b2013-07-02 06:37:13 +0100454{
Gerd Hoffmanna6d3c4d2018-04-20 09:19:03 +0200455 qxl_crtc_update_monitors_config(crtc, "disable");
Dave Airlie07f8d9b2013-07-02 06:37:13 +0100456}
457
Dave Airlief64122c2013-02-25 14:47:55 +1000458static const struct drm_crtc_helper_funcs qxl_crtc_helper_funcs = {
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300459 .atomic_flush = qxl_crtc_atomic_flush,
Laurent Pinchart0b20a0f2017-06-30 12:36:44 +0300460 .atomic_enable = qxl_crtc_atomic_enable,
Laurent Pinchart64581712017-06-30 12:36:45 +0300461 .atomic_disable = qxl_crtc_atomic_disable,
Dave Airlief64122c2013-02-25 14:47:55 +1000462};
463
Gerd Hoffmann45dfe572017-06-20 13:39:15 +0200464static int qxl_primary_atomic_check(struct drm_plane *plane,
465 struct drm_plane_state *state)
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300466{
Daniel Vettere304f8a2020-04-15 09:40:02 +0200467 struct qxl_device *qdev = to_qxl(plane->dev);
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300468 struct qxl_bo *bo;
469
470 if (!state->crtc || !state->fb)
471 return 0;
472
Peter Wubf8744e2018-09-10 15:21:56 +0200473 bo = gem_to_qxl_bo(state->fb->obj[0]);
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300474
Gerd Hoffmannfeba24d2019-01-18 13:20:17 +0100475 return qxl_check_framebuffer(qdev, bo);
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300476}
477
Ray Strode94280882017-11-27 16:50:10 -0500478static int qxl_primary_apply_cursor(struct drm_plane *plane)
479{
480 struct drm_device *dev = plane->dev;
Daniel Vettere304f8a2020-04-15 09:40:02 +0200481 struct qxl_device *qdev = to_qxl(dev);
Ray Strode94280882017-11-27 16:50:10 -0500482 struct drm_framebuffer *fb = plane->state->fb;
483 struct qxl_crtc *qcrtc = to_qxl_crtc(plane->state->crtc);
484 struct qxl_cursor_cmd *cmd;
485 struct qxl_release *release;
486 int ret = 0;
487
488 if (!qcrtc->cursor_bo)
489 return 0;
490
491 ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd),
492 QXL_RELEASE_CURSOR_CMD,
493 &release, NULL);
494 if (ret)
495 return ret;
496
497 ret = qxl_release_list_add(release, qcrtc->cursor_bo);
498 if (ret)
499 goto out_free_release;
500
501 ret = qxl_release_reserve_list(release, false);
502 if (ret)
503 goto out_free_release;
504
505 cmd = (struct qxl_cursor_cmd *)qxl_release_map(qdev, release);
506 cmd->type = QXL_CURSOR_SET;
507 cmd->u.set.position.x = plane->state->crtc_x + fb->hot_x;
508 cmd->u.set.position.y = plane->state->crtc_y + fb->hot_y;
509
510 cmd->u.set.shape = qxl_bo_physical_address(qdev, qcrtc->cursor_bo, 0);
511
512 cmd->u.set.visible = 1;
513 qxl_release_unmap(qdev, release, &cmd->release_info);
514
Ray Strode94280882017-11-27 16:50:10 -0500515 qxl_release_fence_buffer_objects(release);
Vasily Averin933db732020-04-29 12:01:24 +0300516 qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false);
Ray Strode94280882017-11-27 16:50:10 -0500517
518 return ret;
519
520out_free_release:
521 qxl_release_free(qdev, release);
522 return ret;
523}
524
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300525static void qxl_primary_atomic_update(struct drm_plane *plane,
526 struct drm_plane_state *old_state)
527{
Daniel Vettere304f8a2020-04-15 09:40:02 +0200528 struct qxl_device *qdev = to_qxl(plane->dev);
Peter Wubf8744e2018-09-10 15:21:56 +0200529 struct qxl_bo *bo = gem_to_qxl_bo(plane->state->fb->obj[0]);
YueHaibingfb8cd602019-02-18 08:54:59 +0000530 struct qxl_bo *primary;
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300531 struct drm_clip_rect norect = {
532 .x1 = 0,
533 .y1 = 0,
Peter Wubf8744e2018-09-10 15:21:56 +0200534 .x2 = plane->state->fb->width,
535 .y2 = plane->state->fb->height
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300536 };
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100537 uint32_t dumb_shadow_offset = 0;
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300538
Gerd Hoffmann49799042019-01-18 13:20:10 +0100539 primary = bo->shadow ? bo->shadow : bo;
Gerd Hoffmannb0e07da2017-09-11 11:39:50 +0200540
Gerd Hoffmann49799042019-01-18 13:20:10 +0100541 if (!primary->is_primary) {
542 if (qdev->primary_bo)
Gerd Hoffmann62676d12017-10-19 08:21:50 +0200543 qxl_io_destroy_primary(qdev);
Gerd Hoffmann49799042019-01-18 13:20:10 +0100544 qxl_io_create_primary(qdev, primary);
545 qxl_primary_apply_cursor(plane);
Gerd Hoffmannb0e07da2017-09-11 11:39:50 +0200546 }
Gerd Hoffmann62676d12017-10-19 08:21:50 +0200547
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100548 if (bo->is_dumb)
549 dumb_shadow_offset =
550 qdev->dumb_heads[plane->state->crtc->index].x;
551
552 qxl_draw_dirty_fb(qdev, plane->state->fb, bo, 0, 0, &norect, 1, 1,
553 dumb_shadow_offset);
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300554}
555
556static void qxl_primary_atomic_disable(struct drm_plane *plane,
557 struct drm_plane_state *old_state)
558{
Daniel Vettere304f8a2020-04-15 09:40:02 +0200559 struct qxl_device *qdev = to_qxl(plane->dev);
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300560
Gerd Hoffmannb0e07da2017-09-11 11:39:50 +0200561 if (old_state->fb) {
Peter Wubf8744e2018-09-10 15:21:56 +0200562 struct qxl_bo *bo = gem_to_qxl_bo(old_state->fb->obj[0]);
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300563
Gerd Hoffmannb0e07da2017-09-11 11:39:50 +0200564 if (bo->is_primary) {
565 qxl_io_destroy_primary(qdev);
566 bo->is_primary = false;
567 }
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300568 }
569}
570
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300571static void qxl_cursor_atomic_update(struct drm_plane *plane,
572 struct drm_plane_state *old_state)
573{
574 struct drm_device *dev = plane->dev;
Daniel Vettere304f8a2020-04-15 09:40:02 +0200575 struct qxl_device *qdev = to_qxl(dev);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300576 struct drm_framebuffer *fb = plane->state->fb;
Ray Strode94280882017-11-27 16:50:10 -0500577 struct qxl_crtc *qcrtc = to_qxl_crtc(plane->state->crtc);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300578 struct qxl_release *release;
579 struct qxl_cursor_cmd *cmd;
580 struct qxl_cursor *cursor;
581 struct drm_gem_object *obj;
Jeremy Cline889ad632018-06-01 16:05:32 -0400582 struct qxl_bo *cursor_bo = NULL, *user_bo = NULL, *old_cursor_bo = NULL;
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300583 int ret;
584 void *user_ptr;
585 int size = 64*64*4;
586
587 ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd),
588 QXL_RELEASE_CURSOR_CMD,
589 &release, NULL);
Dan Carpenteree5cb7c2017-03-14 10:54:10 +0300590 if (ret)
591 return;
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300592
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300593 if (fb != old_state->fb) {
Peter Wubf8744e2018-09-10 15:21:56 +0200594 obj = fb->obj[0];
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300595 user_bo = gem_to_qxl_bo(obj);
596
597 /* pinning is done in the prepare/cleanup framevbuffer */
598 ret = qxl_bo_kmap(user_bo, &user_ptr);
599 if (ret)
600 goto out_free_release;
601
602 ret = qxl_alloc_bo_reserved(qdev, release,
603 sizeof(struct qxl_cursor) + size,
604 &cursor_bo);
605 if (ret)
606 goto out_kunmap;
607
Christophe Fergeau0081cdf2018-11-20 17:20:04 +0100608 ret = qxl_bo_pin(cursor_bo);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300609 if (ret)
610 goto out_free_bo;
611
Christophe Fergeau0081cdf2018-11-20 17:20:04 +0100612 ret = qxl_release_reserve_list(release, true);
613 if (ret)
614 goto out_unpin;
615
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300616 ret = qxl_bo_kmap(cursor_bo, (void **)&cursor);
617 if (ret)
618 goto out_backoff;
619
620 cursor->header.unique = 0;
621 cursor->header.type = SPICE_CURSOR_TYPE_ALPHA;
622 cursor->header.width = 64;
623 cursor->header.height = 64;
624 cursor->header.hot_spot_x = fb->hot_x;
625 cursor->header.hot_spot_y = fb->hot_y;
626 cursor->data_size = size;
627 cursor->chunk.next_chunk = 0;
628 cursor->chunk.prev_chunk = 0;
629 cursor->chunk.data_size = size;
630 memcpy(cursor->chunk.data, user_ptr, size);
631 qxl_bo_kunmap(cursor_bo);
632 qxl_bo_kunmap(user_bo);
633
Gabriel Krisman Bertazi429030b2017-05-19 14:58:19 -0300634 cmd = (struct qxl_cursor_cmd *) qxl_release_map(qdev, release);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300635 cmd->u.set.visible = 1;
636 cmd->u.set.shape = qxl_bo_physical_address(qdev,
637 cursor_bo, 0);
638 cmd->type = QXL_CURSOR_SET;
Ray Strode94280882017-11-27 16:50:10 -0500639
Jeremy Cline889ad632018-06-01 16:05:32 -0400640 old_cursor_bo = qcrtc->cursor_bo;
Ray Strode94280882017-11-27 16:50:10 -0500641 qcrtc->cursor_bo = cursor_bo;
642 cursor_bo = NULL;
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300643 } else {
644
645 ret = qxl_release_reserve_list(release, true);
646 if (ret)
647 goto out_free_release;
648
Gabriel Krisman Bertazi429030b2017-05-19 14:58:19 -0300649 cmd = (struct qxl_cursor_cmd *) qxl_release_map(qdev, release);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300650 cmd->type = QXL_CURSOR_MOVE;
651 }
652
653 cmd->u.position.x = plane->state->crtc_x + fb->hot_x;
654 cmd->u.position.y = plane->state->crtc_y + fb->hot_y;
655
656 qxl_release_unmap(qdev, release, &cmd->release_info);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300657 qxl_release_fence_buffer_objects(release);
Vasily Averin933db732020-04-29 12:01:24 +0300658 qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300659
Christophe Fergeau0081cdf2018-11-20 17:20:04 +0100660 if (old_cursor_bo != NULL)
661 qxl_bo_unpin(old_cursor_bo);
Christophe Fergeau76a57db2018-11-20 17:20:02 +0100662 qxl_bo_unref(&old_cursor_bo);
Ray Strode16c6db32017-11-27 16:50:09 -0500663 qxl_bo_unref(&cursor_bo);
664
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300665 return;
666
667out_backoff:
668 qxl_release_backoff_reserve_list(release);
Christophe Fergeau0081cdf2018-11-20 17:20:04 +0100669out_unpin:
670 qxl_bo_unpin(cursor_bo);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300671out_free_bo:
672 qxl_bo_unref(&cursor_bo);
673out_kunmap:
674 qxl_bo_kunmap(user_bo);
675out_free_release:
676 qxl_release_free(qdev, release);
677 return;
678
679}
680
Gerd Hoffmann45dfe572017-06-20 13:39:15 +0200681static void qxl_cursor_atomic_disable(struct drm_plane *plane,
682 struct drm_plane_state *old_state)
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300683{
Daniel Vettere304f8a2020-04-15 09:40:02 +0200684 struct qxl_device *qdev = to_qxl(plane->dev);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300685 struct qxl_release *release;
686 struct qxl_cursor_cmd *cmd;
687 int ret;
688
689 ret = qxl_alloc_release_reserved(qdev, sizeof(*cmd),
690 QXL_RELEASE_CURSOR_CMD,
691 &release, NULL);
692 if (ret)
693 return;
694
695 ret = qxl_release_reserve_list(release, true);
696 if (ret) {
697 qxl_release_free(qdev, release);
698 return;
699 }
700
701 cmd = (struct qxl_cursor_cmd *)qxl_release_map(qdev, release);
702 cmd->type = QXL_CURSOR_HIDE;
703 qxl_release_unmap(qdev, release, &cmd->release_info);
704
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300705 qxl_release_fence_buffer_objects(release);
Vasily Averin933db732020-04-29 12:01:24 +0300706 qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300707}
708
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100709static void qxl_update_dumb_head(struct qxl_device *qdev,
710 int index, struct qxl_bo *bo)
711{
712 uint32_t width, height;
713
714 if (index >= qdev->monitors_config->max_allowed)
715 return;
716
717 if (bo && bo->is_dumb) {
718 width = bo->surf.width;
719 height = bo->surf.height;
720 } else {
721 width = 0;
722 height = 0;
723 }
724
725 if (qdev->dumb_heads[index].width == width &&
726 qdev->dumb_heads[index].height == height)
727 return;
728
729 DRM_DEBUG("#%d: %dx%d -> %dx%d\n", index,
730 qdev->dumb_heads[index].width,
731 qdev->dumb_heads[index].height,
732 width, height);
733 qdev->dumb_heads[index].width = width;
734 qdev->dumb_heads[index].height = height;
735}
736
737static void qxl_calc_dumb_shadow(struct qxl_device *qdev,
738 struct qxl_surface *surf)
739{
740 struct qxl_head *head;
741 int i;
742
743 memset(surf, 0, sizeof(*surf));
744 for (i = 0; i < qdev->monitors_config->max_allowed; i++) {
745 head = qdev->dumb_heads + i;
746 head->x = surf->width;
747 surf->width += head->width;
748 if (surf->height < head->height)
749 surf->height = head->height;
750 }
751 if (surf->width < 64)
752 surf->width = 64;
753 if (surf->height < 64)
754 surf->height = 64;
755 surf->format = SPICE_SURFACE_FMT_32_xRGB;
756 surf->stride = surf->width * 4;
757
758 if (!qdev->dumb_shadow_bo ||
759 qdev->dumb_shadow_bo->surf.width != surf->width ||
760 qdev->dumb_shadow_bo->surf.height != surf->height)
761 DRM_DEBUG("%dx%d\n", surf->width, surf->height);
762}
763
Gerd Hoffmann45dfe572017-06-20 13:39:15 +0200764static int qxl_plane_prepare_fb(struct drm_plane *plane,
765 struct drm_plane_state *new_state)
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300766{
Daniel Vettere304f8a2020-04-15 09:40:02 +0200767 struct qxl_device *qdev = to_qxl(plane->dev);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300768 struct drm_gem_object *obj;
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100769 struct qxl_bo *user_bo;
770 struct qxl_surface surf;
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300771 int ret;
772
773 if (!new_state->fb)
774 return 0;
775
Peter Wubf8744e2018-09-10 15:21:56 +0200776 obj = new_state->fb->obj[0];
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300777 user_bo = gem_to_qxl_bo(obj);
778
Gerd Hoffmann62676d12017-10-19 08:21:50 +0200779 if (plane->type == DRM_PLANE_TYPE_PRIMARY &&
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100780 user_bo->is_dumb) {
781 qxl_update_dumb_head(qdev, new_state->crtc->index,
782 user_bo);
783 qxl_calc_dumb_shadow(qdev, &surf);
784 if (!qdev->dumb_shadow_bo ||
785 qdev->dumb_shadow_bo->surf.width != surf.width ||
786 qdev->dumb_shadow_bo->surf.height != surf.height) {
787 if (qdev->dumb_shadow_bo) {
Emil Velikov9c86fb12020-05-15 10:51:08 +0100788 drm_gem_object_put
Gerd Hoffmanne0828d52019-08-05 16:01:05 +0200789 (&qdev->dumb_shadow_bo->tbo.base);
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100790 qdev->dumb_shadow_bo = NULL;
791 }
792 qxl_bo_create(qdev, surf.height * surf.stride,
793 true, true, QXL_GEM_DOMAIN_SURFACE, &surf,
794 &qdev->dumb_shadow_bo);
Gerd Hoffmann62676d12017-10-19 08:21:50 +0200795 }
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100796 if (user_bo->shadow != qdev->dumb_shadow_bo) {
797 if (user_bo->shadow) {
Emil Velikov9c86fb12020-05-15 10:51:08 +0100798 drm_gem_object_put
Gerd Hoffmanne0828d52019-08-05 16:01:05 +0200799 (&user_bo->shadow->tbo.base);
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100800 user_bo->shadow = NULL;
801 }
Gerd Hoffmanne0828d52019-08-05 16:01:05 +0200802 drm_gem_object_get(&qdev->dumb_shadow_bo->tbo.base);
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100803 user_bo->shadow = qdev->dumb_shadow_bo;
Gerd Hoffmann62676d12017-10-19 08:21:50 +0200804 }
805 }
806
Christophe Fergeau545592f2018-11-20 17:20:03 +0100807 ret = qxl_bo_pin(user_bo);
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300808 if (ret)
809 return ret;
810
811 return 0;
812}
813
814static void qxl_plane_cleanup_fb(struct drm_plane *plane,
815 struct drm_plane_state *old_state)
816{
817 struct drm_gem_object *obj;
818 struct qxl_bo *user_bo;
819
Gerd Hoffmann5f3d8622017-09-18 09:41:45 +0200820 if (!old_state->fb) {
821 /*
822 * we never executed prepare_fb, so there's nothing to
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300823 * unpin.
824 */
825 return;
826 }
827
Peter Wubf8744e2018-09-10 15:21:56 +0200828 obj = old_state->fb->obj[0];
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300829 user_bo = gem_to_qxl_bo(obj);
830 qxl_bo_unpin(user_bo);
Gerd Hoffmann62676d12017-10-19 08:21:50 +0200831
Gerd Hoffmann90adda22019-01-18 13:20:11 +0100832 if (old_state->fb != plane->state->fb && user_bo->shadow) {
Emil Velikov9c86fb12020-05-15 10:51:08 +0100833 drm_gem_object_put(&user_bo->shadow->tbo.base);
Gerd Hoffmann62676d12017-10-19 08:21:50 +0200834 user_bo->shadow = NULL;
835 }
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300836}
837
838static const uint32_t qxl_cursor_plane_formats[] = {
839 DRM_FORMAT_ARGB8888,
840};
841
842static const struct drm_plane_helper_funcs qxl_cursor_helper_funcs = {
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300843 .atomic_update = qxl_cursor_atomic_update,
844 .atomic_disable = qxl_cursor_atomic_disable,
845 .prepare_fb = qxl_plane_prepare_fb,
846 .cleanup_fb = qxl_plane_cleanup_fb,
847};
848
849static const struct drm_plane_funcs qxl_cursor_plane_funcs = {
Gabriel Krisman Bertazi472e6d42017-02-27 17:43:25 -0300850 .update_plane = drm_atomic_helper_update_plane,
851 .disable_plane = drm_atomic_helper_disable_plane,
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300852 .destroy = drm_primary_helper_destroy,
Gabriel Krisman Bertazi9ade8b92017-02-27 17:43:23 -0300853 .reset = drm_atomic_helper_plane_reset,
854 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
855 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300856};
857
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300858static const uint32_t qxl_primary_plane_formats[] = {
859 DRM_FORMAT_XRGB8888,
860 DRM_FORMAT_ARGB8888,
861};
862
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300863static const struct drm_plane_helper_funcs primary_helper_funcs = {
864 .atomic_check = qxl_primary_atomic_check,
865 .atomic_update = qxl_primary_atomic_update,
866 .atomic_disable = qxl_primary_atomic_disable,
867 .prepare_fb = qxl_plane_prepare_fb,
868 .cleanup_fb = qxl_plane_cleanup_fb,
869};
870
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300871static const struct drm_plane_funcs qxl_primary_plane_funcs = {
Gabriel Krisman Bertazi472e6d42017-02-27 17:43:25 -0300872 .update_plane = drm_atomic_helper_update_plane,
873 .disable_plane = drm_atomic_helper_disable_plane,
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300874 .destroy = drm_primary_helper_destroy,
Gabriel Krisman Bertazi9ade8b92017-02-27 17:43:23 -0300875 .reset = drm_atomic_helper_plane_reset,
876 .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
877 .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300878};
879
880static struct drm_plane *qxl_create_plane(struct qxl_device *qdev,
881 unsigned int possible_crtcs,
882 enum drm_plane_type type)
883{
884 const struct drm_plane_helper_funcs *helper_funcs = NULL;
885 struct drm_plane *plane;
886 const struct drm_plane_funcs *funcs;
887 const uint32_t *formats;
888 int num_formats;
889 int err;
890
891 if (type == DRM_PLANE_TYPE_PRIMARY) {
892 funcs = &qxl_primary_plane_funcs;
893 formats = qxl_primary_plane_formats;
894 num_formats = ARRAY_SIZE(qxl_primary_plane_formats);
Gabriel Krisman Bertazic2ff6632017-02-27 17:43:20 -0300895 helper_funcs = &primary_helper_funcs;
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300896 } else if (type == DRM_PLANE_TYPE_CURSOR) {
897 funcs = &qxl_cursor_plane_funcs;
898 formats = qxl_cursor_plane_formats;
899 helper_funcs = &qxl_cursor_helper_funcs;
900 num_formats = ARRAY_SIZE(qxl_cursor_plane_formats);
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300901 } else {
902 return ERR_PTR(-EINVAL);
903 }
904
905 plane = kzalloc(sizeof(*plane), GFP_KERNEL);
906 if (!plane)
907 return ERR_PTR(-ENOMEM);
908
909 err = drm_universal_plane_init(&qdev->ddev, plane, possible_crtcs,
910 funcs, formats, num_formats,
Ben Widawskye6fc3b62017-07-23 20:46:38 -0700911 NULL, type, NULL);
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300912 if (err)
913 goto free_plane;
914
915 drm_plane_helper_add(plane, helper_funcs);
916
917 return plane;
918
919free_plane:
920 kfree(plane);
921 return ERR_PTR(-EINVAL);
922}
923
Dave Airlie07f8d9b2013-07-02 06:37:13 +0100924static int qdev_crtc_init(struct drm_device *dev, int crtc_id)
Dave Airlief64122c2013-02-25 14:47:55 +1000925{
926 struct qxl_crtc *qxl_crtc;
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300927 struct drm_plane *primary, *cursor;
Daniel Vettere304f8a2020-04-15 09:40:02 +0200928 struct qxl_device *qdev = to_qxl(dev);
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300929 int r;
Dave Airlief64122c2013-02-25 14:47:55 +1000930
931 qxl_crtc = kzalloc(sizeof(struct qxl_crtc), GFP_KERNEL);
932 if (!qxl_crtc)
933 return -ENOMEM;
934
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300935 primary = qxl_create_plane(qdev, 1 << crtc_id, DRM_PLANE_TYPE_PRIMARY);
936 if (IS_ERR(primary)) {
937 r = -ENOMEM;
938 goto free_mem;
939 }
940
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300941 cursor = qxl_create_plane(qdev, 1 << crtc_id, DRM_PLANE_TYPE_CURSOR);
942 if (IS_ERR(cursor)) {
943 r = -ENOMEM;
944 goto clean_primary;
945 }
946
947 r = drm_crtc_init_with_planes(dev, &qxl_crtc->base, primary, cursor,
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300948 &qxl_crtc_funcs, NULL);
949 if (r)
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300950 goto clean_cursor;
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300951
Dave Airlie07f8d9b2013-07-02 06:37:13 +0100952 qxl_crtc->index = crtc_id;
Dave Airlief64122c2013-02-25 14:47:55 +1000953 drm_crtc_helper_add(&qxl_crtc->base, &qxl_crtc_helper_funcs);
954 return 0;
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300955
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -0300956clean_cursor:
957 drm_plane_cleanup(cursor);
958 kfree(cursor);
Gabriel Krisman Bertazid3e7e422017-02-27 17:43:18 -0300959clean_primary:
960 drm_plane_cleanup(primary);
961 kfree(primary);
962free_mem:
963 kfree(qxl_crtc);
964 return r;
Dave Airlief64122c2013-02-25 14:47:55 +1000965}
966
Dave Airlief64122c2013-02-25 14:47:55 +1000967static int qxl_conn_get_modes(struct drm_connector *connector)
968{
Gerd Hoffmann1b043672019-01-18 13:20:18 +0100969 struct drm_device *dev = connector->dev;
Daniel Vettere304f8a2020-04-15 09:40:02 +0200970 struct qxl_device *qdev = to_qxl(dev);
Gerd Hoffmann1b043672019-01-18 13:20:18 +0100971 struct qxl_output *output = drm_connector_to_qxl_output(connector);
Shayenne da Luz Moura1b000492018-10-26 16:23:49 -0300972 unsigned int pwidth = 1024;
973 unsigned int pheight = 768;
Gerd Hoffmann2d856f942017-03-01 11:12:34 +0100974 int ret = 0;
Dave Airlief64122c2013-02-25 14:47:55 +1000975
Gerd Hoffmann1b043672019-01-18 13:20:18 +0100976 if (qdev->client_monitors_config) {
977 struct qxl_head *head;
978 head = &qdev->client_monitors_config->heads[output->index];
979 if (head->width)
980 pwidth = head->width;
981 if (head->height)
982 pheight = head->height;
983 }
984
Gerd Hoffmannb5f030b2019-01-18 13:20:19 +0100985 ret += drm_add_modes_noedid(connector, 8192, 8192);
986 ret += qxl_add_extra_modes(connector);
Gerd Hoffmann1b043672019-01-18 13:20:18 +0100987 ret += qxl_add_monitors_config_modes(connector);
988 drm_set_preferred_mode(connector, pwidth, pheight);
Dave Airlief64122c2013-02-25 14:47:55 +1000989 return ret;
990}
991
Luc Van Oostenrycke0d92e12018-04-24 15:15:15 +0200992static enum drm_mode_status qxl_conn_mode_valid(struct drm_connector *connector,
Dave Airlief64122c2013-02-25 14:47:55 +1000993 struct drm_display_mode *mode)
994{
Jonathon Jongsmabd3e1c72015-08-20 14:04:32 -0500995 struct drm_device *ddev = connector->dev;
Daniel Vettere304f8a2020-04-15 09:40:02 +0200996 struct qxl_device *qdev = to_qxl(ddev);
Jonathon Jongsmabd3e1c72015-08-20 14:04:32 -0500997
Gerd Hoffmannfeba24d2019-01-18 13:20:17 +0100998 if (qxl_check_mode(qdev, mode->hdisplay, mode->vdisplay) != 0)
999 return MODE_BAD;
Jonathon Jongsmabd3e1c72015-08-20 14:04:32 -05001000
Gerd Hoffmannfeba24d2019-01-18 13:20:17 +01001001 return MODE_OK;
Dave Airlief64122c2013-02-25 14:47:55 +10001002}
1003
Dave Airlie6d01f1f2013-04-16 13:24:25 +10001004static struct drm_encoder *qxl_best_encoder(struct drm_connector *connector)
Dave Airlief64122c2013-02-25 14:47:55 +10001005{
1006 struct qxl_output *qxl_output =
1007 drm_connector_to_qxl_output(connector);
1008
1009 DRM_DEBUG("\n");
1010 return &qxl_output->enc;
1011}
1012
Dave Airlief64122c2013-02-25 14:47:55 +10001013static const struct drm_connector_helper_funcs qxl_connector_helper_funcs = {
1014 .get_modes = qxl_conn_get_modes,
1015 .mode_valid = qxl_conn_mode_valid,
1016 .best_encoder = qxl_best_encoder,
1017};
1018
Dave Airlief64122c2013-02-25 14:47:55 +10001019static enum drm_connector_status qxl_conn_detect(
1020 struct drm_connector *connector,
1021 bool force)
1022{
1023 struct qxl_output *output =
1024 drm_connector_to_qxl_output(connector);
1025 struct drm_device *ddev = connector->dev;
Daniel Vettere304f8a2020-04-15 09:40:02 +02001026 struct qxl_device *qdev = to_qxl(ddev);
Dave Airlie69e5d3f2015-09-14 10:28:34 +10001027 bool connected = false;
Dave Airlief64122c2013-02-25 14:47:55 +10001028
1029 /* The first monitor is always connected */
Dave Airlie69e5d3f2015-09-14 10:28:34 +10001030 if (!qdev->client_monitors_config) {
1031 if (output->index == 0)
1032 connected = true;
1033 } else
1034 connected = qdev->client_monitors_config->count > output->index &&
1035 qxl_head_enabled(&qdev->client_monitors_config->heads[output->index]);
Dave Airlief64122c2013-02-25 14:47:55 +10001036
Marc-André Lureau5cab51c2013-10-18 16:11:33 +02001037 DRM_DEBUG("#%d connected: %d\n", output->index, connected);
Marc-André Lureau5cab51c2013-10-18 16:11:33 +02001038
Dave Airlief64122c2013-02-25 14:47:55 +10001039 return connected ? connector_status_connected
1040 : connector_status_disconnected;
1041}
1042
Dave Airlief64122c2013-02-25 14:47:55 +10001043static void qxl_conn_destroy(struct drm_connector *connector)
1044{
1045 struct qxl_output *qxl_output =
1046 drm_connector_to_qxl_output(connector);
1047
Thomas Wood34ea3d32014-05-29 16:57:41 +01001048 drm_connector_unregister(connector);
Dave Airlief64122c2013-02-25 14:47:55 +10001049 drm_connector_cleanup(connector);
1050 kfree(qxl_output);
1051}
1052
1053static const struct drm_connector_funcs qxl_connector_funcs = {
Dave Airlief64122c2013-02-25 14:47:55 +10001054 .detect = qxl_conn_detect,
Ville Syrjälä6af3e652015-12-03 23:14:14 +02001055 .fill_modes = drm_helper_probe_single_connector_modes,
Dave Airlief64122c2013-02-25 14:47:55 +10001056 .destroy = qxl_conn_destroy,
Gabriel Krisman Bertazi9ade8b92017-02-27 17:43:23 -03001057 .reset = drm_atomic_helper_connector_reset,
1058 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
1059 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Dave Airlief64122c2013-02-25 14:47:55 +10001060};
1061
Dave Airlie4695b032013-10-11 11:05:00 +10001062static int qxl_mode_create_hotplug_mode_update_property(struct qxl_device *qdev)
1063{
1064 if (qdev->hotplug_mode_update_property)
1065 return 0;
1066
1067 qdev->hotplug_mode_update_property =
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -02001068 drm_property_create_range(&qdev->ddev, DRM_MODE_PROP_IMMUTABLE,
Dave Airlie4695b032013-10-11 11:05:00 +10001069 "hotplug_mode_update", 0, 1);
1070
1071 return 0;
1072}
1073
Dave Airlie6d01f1f2013-04-16 13:24:25 +10001074static int qdev_output_init(struct drm_device *dev, int num_output)
Dave Airlief64122c2013-02-25 14:47:55 +10001075{
Daniel Vettere304f8a2020-04-15 09:40:02 +02001076 struct qxl_device *qdev = to_qxl(dev);
Dave Airlief64122c2013-02-25 14:47:55 +10001077 struct qxl_output *qxl_output;
1078 struct drm_connector *connector;
1079 struct drm_encoder *encoder;
Thomas Zimmermann6f2bb112020-02-28 09:18:28 +01001080 int ret;
Dave Airlief64122c2013-02-25 14:47:55 +10001081
1082 qxl_output = kzalloc(sizeof(struct qxl_output), GFP_KERNEL);
1083 if (!qxl_output)
1084 return -ENOMEM;
1085
1086 qxl_output->index = num_output;
1087
1088 connector = &qxl_output->base;
1089 encoder = &qxl_output->enc;
1090 drm_connector_init(dev, &qxl_output->base,
1091 &qxl_connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL);
1092
Thomas Zimmermann6f2bb112020-02-28 09:18:28 +01001093 ret = drm_simple_encoder_init(dev, &qxl_output->enc,
1094 DRM_MODE_ENCODER_VIRTUAL);
1095 if (ret) {
1096 drm_err(dev, "drm_simple_encoder_init() failed, error %d\n",
1097 ret);
1098 goto err_drm_connector_cleanup;
1099 }
Dave Airlief64122c2013-02-25 14:47:55 +10001100
Dave Airlie5ff91e42013-07-05 10:20:33 +10001101 /* we get HPD via client monitors config */
1102 connector->polled = DRM_CONNECTOR_POLL_HPD;
Dave Airlief64122c2013-02-25 14:47:55 +10001103 encoder->possible_crtcs = 1 << num_output;
Daniel Vettercde4c442018-07-09 10:40:07 +02001104 drm_connector_attach_encoder(&qxl_output->base,
Dave Airlief64122c2013-02-25 14:47:55 +10001105 &qxl_output->enc);
Dave Airlief64122c2013-02-25 14:47:55 +10001106 drm_connector_helper_add(connector, &qxl_connector_helper_funcs);
1107
Dave Airlie4695b032013-10-11 11:05:00 +10001108 drm_object_attach_property(&connector->base,
1109 qdev->hotplug_mode_update_property, 0);
Dave Airlie7dea0942014-10-28 11:28:44 +10001110 drm_object_attach_property(&connector->base,
1111 dev->mode_config.suggested_x_property, 0);
1112 drm_object_attach_property(&connector->base,
1113 dev->mode_config.suggested_y_property, 0);
Dave Airlief64122c2013-02-25 14:47:55 +10001114 return 0;
Thomas Zimmermann6f2bb112020-02-28 09:18:28 +01001115
1116err_drm_connector_cleanup:
1117 drm_connector_cleanup(&qxl_output->base);
1118 kfree(qxl_output);
1119 return ret;
Dave Airlief64122c2013-02-25 14:47:55 +10001120}
1121
1122static struct drm_framebuffer *
1123qxl_user_framebuffer_create(struct drm_device *dev,
1124 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +02001125 const struct drm_mode_fb_cmd2 *mode_cmd)
Dave Airlief64122c2013-02-25 14:47:55 +10001126{
Peter Wubf8744e2018-09-10 15:21:56 +02001127 return drm_gem_fb_create_with_funcs(dev, file_priv, mode_cmd,
1128 &qxl_fb_funcs);
Dave Airlief64122c2013-02-25 14:47:55 +10001129}
1130
1131static const struct drm_mode_config_funcs qxl_mode_funcs = {
1132 .fb_create = qxl_user_framebuffer_create,
Gabriel Krisman Bertazi472e6d42017-02-27 17:43:25 -03001133 .atomic_check = drm_atomic_helper_check,
1134 .atomic_commit = drm_atomic_helper_commit,
Dave Airlief64122c2013-02-25 14:47:55 +10001135};
1136
Dave Airlie2bd6ce82013-07-04 14:46:46 +10001137int qxl_create_monitors_object(struct qxl_device *qdev)
Dave Airlief64122c2013-02-25 14:47:55 +10001138{
Dave Airlief64122c2013-02-25 14:47:55 +10001139 int ret;
1140 struct drm_gem_object *gobj;
Dave Airlief64122c2013-02-25 14:47:55 +10001141 int monitors_config_size = sizeof(struct qxl_monitors_config) +
Gerd Hoffmann21c76bd2019-01-18 13:20:12 +01001142 qxl_num_crtc * sizeof(struct qxl_head);
Dave Airlief64122c2013-02-25 14:47:55 +10001143
Dave Airlief64122c2013-02-25 14:47:55 +10001144 ret = qxl_gem_object_create(qdev, monitors_config_size, 0,
1145 QXL_GEM_DOMAIN_VRAM,
1146 false, false, NULL, &gobj);
1147 if (ret) {
1148 DRM_ERROR("%s: failed to create gem ret=%d\n", __func__, ret);
1149 return -ENOMEM;
1150 }
1151 qdev->monitors_config_bo = gem_to_qxl_bo(gobj);
Dave Airlie2bd6ce82013-07-04 14:46:46 +10001152
Christophe Fergeau545592f2018-11-20 17:20:03 +01001153 ret = qxl_bo_pin(qdev->monitors_config_bo);
Dave Airlie2bd6ce82013-07-04 14:46:46 +10001154 if (ret)
1155 return ret;
1156
Dave Airlief64122c2013-02-25 14:47:55 +10001157 qxl_bo_kmap(qdev->monitors_config_bo, NULL);
Dave Airlie2bd6ce82013-07-04 14:46:46 +10001158
Dave Airlief64122c2013-02-25 14:47:55 +10001159 qdev->monitors_config = qdev->monitors_config_bo->kptr;
1160 qdev->ram_header->monitors_config =
1161 qxl_bo_physical_address(qdev, qdev->monitors_config_bo, 0);
1162
1163 memset(qdev->monitors_config, 0, monitors_config_size);
Gerd Hoffmann21c76bd2019-01-18 13:20:12 +01001164 qdev->dumb_heads = kcalloc(qxl_num_crtc, sizeof(qdev->dumb_heads[0]),
1165 GFP_KERNEL);
Gerd Hoffmann90adda22019-01-18 13:20:11 +01001166 if (!qdev->dumb_heads) {
1167 qxl_destroy_monitors_object(qdev);
1168 return -ENOMEM;
1169 }
Dave Airlie2bd6ce82013-07-04 14:46:46 +10001170 return 0;
1171}
1172
1173int qxl_destroy_monitors_object(struct qxl_device *qdev)
1174{
1175 int ret;
1176
1177 qdev->monitors_config = NULL;
1178 qdev->ram_header->monitors_config = 0;
1179
1180 qxl_bo_kunmap(qdev->monitors_config_bo);
Gabriel Krisman Bertazi715a11f2017-02-27 17:43:16 -03001181 ret = qxl_bo_unpin(qdev->monitors_config_bo);
Dave Airlie2bd6ce82013-07-04 14:46:46 +10001182 if (ret)
1183 return ret;
1184
Dave Airlie2bd6ce82013-07-04 14:46:46 +10001185 qxl_bo_unref(&qdev->monitors_config_bo);
1186 return 0;
1187}
1188
1189int qxl_modeset_init(struct qxl_device *qdev)
1190{
1191 int i;
1192 int ret;
1193
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -02001194 drm_mode_config_init(&qdev->ddev);
Dave Airlie2bd6ce82013-07-04 14:46:46 +10001195
1196 ret = qxl_create_monitors_object(qdev);
1197 if (ret)
1198 return ret;
Dave Airlief64122c2013-02-25 14:47:55 +10001199
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -02001200 qdev->ddev.mode_config.funcs = (void *)&qxl_mode_funcs;
Dave Airlief64122c2013-02-25 14:47:55 +10001201
1202 /* modes will be validated against the framebuffer size */
Gabriel Krisman Bertazi1277eed2017-02-27 17:43:19 -03001203 qdev->ddev.mode_config.min_width = 0;
1204 qdev->ddev.mode_config.min_height = 0;
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -02001205 qdev->ddev.mode_config.max_width = 8192;
1206 qdev->ddev.mode_config.max_height = 8192;
Dave Airlief64122c2013-02-25 14:47:55 +10001207
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -02001208 qdev->ddev.mode_config.fb_base = qdev->vram_base;
Dave Airlie4695b032013-10-11 11:05:00 +10001209
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -02001210 drm_mode_create_suggested_offset_properties(&qdev->ddev);
Dave Airlie4695b032013-10-11 11:05:00 +10001211 qxl_mode_create_hotplug_mode_update_property(qdev);
1212
Dave Airlie07f8d9b2013-07-02 06:37:13 +01001213 for (i = 0 ; i < qxl_num_crtc; ++i) {
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -02001214 qdev_crtc_init(&qdev->ddev, i);
1215 qdev_output_init(&qdev->ddev, i);
Dave Airlief64122c2013-02-25 14:47:55 +10001216 }
1217
Gerd Hoffmannc50fad82017-03-01 11:12:33 +01001218 qxl_display_read_client_monitors_config(qdev);
Dave Airlief64122c2013-02-25 14:47:55 +10001219
Gabriel Krisman Bertazi9ade8b92017-02-27 17:43:23 -03001220 drm_mode_config_reset(&qdev->ddev);
Dave Airlief64122c2013-02-25 14:47:55 +10001221 return 0;
1222}
1223
1224void qxl_modeset_fini(struct qxl_device *qdev)
1225{
Dave Airlie2bd6ce82013-07-04 14:46:46 +10001226 qxl_destroy_monitors_object(qdev);
Peter Wubf8744e2018-09-10 15:21:56 +02001227 drm_mode_config_cleanup(&qdev->ddev);
Dave Airlief64122c2013-02-25 14:47:55 +10001228}