Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1 | /* |
| 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 Dunlap | c5416d66 | 2013-12-20 10:58:15 -0800 | [diff] [blame] | 26 | #include <linux/crc32.h> |
Sam Ravnborg | c0f4b75 | 2019-06-30 08:18:58 +0200 | [diff] [blame] | 27 | #include <linux/delay.h> |
| 28 | |
Dave Airlie | ce5c207 | 2020-09-08 14:41:40 +1000 | [diff] [blame] | 29 | #include <drm/drm_drv.h> |
Gabriel Krisman Bertazi | 10a0bd8 | 2017-02-27 17:43:24 -0300 | [diff] [blame] | 30 | #include <drm/drm_atomic.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 31 | #include <drm/drm_atomic_helper.h> |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 32 | #include <drm/drm_gem_framebuffer_helper.h> |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 33 | #include <drm/drm_plane_helper.h> |
| 34 | #include <drm/drm_probe_helper.h> |
Thomas Zimmermann | 6f2bb11 | 2020-02-28 09:18:28 +0100 | [diff] [blame] | 35 | #include <drm/drm_simple_kms_helper.h> |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 36 | |
Masahiro Yamada | edaf492 | 2017-04-24 13:50:30 +0900 | [diff] [blame] | 37 | #include "qxl_drv.h" |
| 38 | #include "qxl_object.h" |
| 39 | |
Dave Airlie | 07f8d9b | 2013-07-02 06:37:13 +0100 | [diff] [blame] | 40 | static bool qxl_head_enabled(struct qxl_head *head) |
| 41 | { |
| 42 | return head->width && head->height; |
| 43 | } |
| 44 | |
Anton Vasilyev | 66e0c8a | 2018-07-27 18:30:58 +0300 | [diff] [blame] | 45 | static int qxl_alloc_client_monitors_config(struct qxl_device *qdev, |
| 46 | unsigned int count) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 47 | { |
| 48 | if (qdev->client_monitors_config && |
| 49 | count > qdev->client_monitors_config->count) { |
| 50 | kfree(qdev->client_monitors_config); |
Dave Airlie | 62c8ba7 | 2013-04-16 13:36:00 +1000 | [diff] [blame] | 51 | qdev->client_monitors_config = NULL; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 52 | } |
| 53 | if (!qdev->client_monitors_config) { |
| 54 | qdev->client_monitors_config = kzalloc( |
Gustavo A. R. Silva | d4b9dd5 | 2019-01-08 10:21:52 -0600 | [diff] [blame] | 55 | struct_size(qdev->client_monitors_config, |
| 56 | heads, count), GFP_KERNEL); |
Gerd Hoffmann | 735581a | 2018-04-20 09:19:01 +0200 | [diff] [blame] | 57 | if (!qdev->client_monitors_config) |
Anton Vasilyev | 66e0c8a | 2018-07-27 18:30:58 +0300 | [diff] [blame] | 58 | return -ENOMEM; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 59 | } |
| 60 | qdev->client_monitors_config->count = count; |
Anton Vasilyev | 66e0c8a | 2018-07-27 18:30:58 +0300 | [diff] [blame] | 61 | return 0; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 62 | } |
| 63 | |
Christophe Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 64 | enum { |
| 65 | MONITORS_CONFIG_MODIFIED, |
| 66 | MONITORS_CONFIG_UNCHANGED, |
| 67 | MONITORS_CONFIG_BAD_CRC, |
Anton Vasilyev | 66e0c8a | 2018-07-27 18:30:58 +0300 | [diff] [blame] | 68 | MONITORS_CONFIG_ERROR, |
Christophe Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 69 | }; |
| 70 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 71 | static 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 Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 76 | int status = MONITORS_CONFIG_UNCHANGED; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 77 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 78 | 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 Hoffmann | 735581a | 2018-04-20 09:19:01 +0200 | [diff] [blame] | 81 | if (crc != qdev->rom->client_monitors_config_crc) |
Christophe Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 82 | return MONITORS_CONFIG_BAD_CRC; |
Gerd Hoffmann | c50fad8 | 2017-03-01 11:12:33 +0100 | [diff] [blame] | 83 | if (!num_monitors) { |
| 84 | DRM_DEBUG_KMS("no client monitors configured\n"); |
| 85 | return status; |
| 86 | } |
Gerd Hoffmann | 21c76bd | 2019-01-18 13:20:12 +0100 | [diff] [blame] | 87 | if (num_monitors > qxl_num_crtc) { |
Dave Airlie | 5b8788c | 2013-07-01 14:14:38 +1000 | [diff] [blame] | 88 | DRM_DEBUG_KMS("client monitors list will be truncated: %d < %d\n", |
Gerd Hoffmann | 21c76bd | 2019-01-18 13:20:12 +0100 | [diff] [blame] | 89 | qxl_num_crtc, num_monitors); |
| 90 | num_monitors = qxl_num_crtc; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 91 | } else { |
| 92 | num_monitors = qdev->rom->client_monitors_config.count; |
| 93 | } |
Christophe Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 94 | if (qdev->client_monitors_config |
| 95 | && (num_monitors != qdev->client_monitors_config->count)) { |
| 96 | status = MONITORS_CONFIG_MODIFIED; |
| 97 | } |
Anton Vasilyev | 66e0c8a | 2018-07-27 18:30:58 +0300 | [diff] [blame] | 98 | if (qxl_alloc_client_monitors_config(qdev, num_monitors)) { |
| 99 | status = MONITORS_CONFIG_ERROR; |
| 100 | return status; |
| 101 | } |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 102 | /* we copy max from the client but it isn't used */ |
Gerd Hoffmann | 21c76bd | 2019-01-18 13:20:12 +0100 | [diff] [blame] | 103 | qdev->client_monitors_config->max_allowed = qxl_num_crtc; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 104 | 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 Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 109 | 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 Airlie | 07f8d9b | 2013-07-02 06:37:13 +0100 | [diff] [blame] | 137 | DRM_DEBUG_KMS("read %dx%d+%d+%d\n", client_head->width, client_head->height, |
| 138 | client_head->x, client_head->y); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 139 | } |
Christophe Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 140 | |
| 141 | return status; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 142 | } |
| 143 | |
Dave Airlie | 7dea094 | 2014-10-28 11:28:44 +1000 | [diff] [blame] | 144 | static void qxl_update_offset_props(struct qxl_device *qdev) |
| 145 | { |
Gabriel Krisman Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 146 | struct drm_device *dev = &qdev->ddev; |
Dave Airlie | 7dea094 | 2014-10-28 11:28:44 +1000 | [diff] [blame] | 147 | 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 Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 163 | void qxl_display_read_client_monitors_config(struct qxl_device *qdev) |
| 164 | { |
Gabriel Krisman Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 165 | struct drm_device *dev = &qdev->ddev; |
Sidong Yang | bbaac13 | 2020-05-24 11:26:23 +0900 | [diff] [blame] | 166 | struct drm_modeset_acquire_ctx ctx; |
| 167 | int status, retries, ret; |
Christophe Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 168 | |
Gerd Hoffmann | 9062155 | 2017-03-01 11:12:32 +0100 | [diff] [blame] | 169 | for (retries = 0; retries < 10; retries++) { |
Christophe Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 170 | status = qxl_display_copy_rom_client_monitors_config(qdev); |
Gerd Hoffmann | 9062155 | 2017-03-01 11:12:32 +0100 | [diff] [blame] | 171 | if (status != MONITORS_CONFIG_BAD_CRC) |
| 172 | break; |
| 173 | udelay(5); |
| 174 | } |
Anton Vasilyev | 66e0c8a | 2018-07-27 18:30:58 +0300 | [diff] [blame] | 175 | if (status == MONITORS_CONFIG_ERROR) { |
| 176 | DRM_DEBUG_KMS("ignoring client monitors config: error"); |
| 177 | return; |
| 178 | } |
Gerd Hoffmann | 9062155 | 2017-03-01 11:12:32 +0100 | [diff] [blame] | 179 | if (status == MONITORS_CONFIG_BAD_CRC) { |
Gerd Hoffmann | 9062155 | 2017-03-01 11:12:32 +0100 | [diff] [blame] | 180 | DRM_DEBUG_KMS("ignoring client monitors config: bad crc"); |
| 181 | return; |
Christophe Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 182 | } |
| 183 | if (status == MONITORS_CONFIG_UNCHANGED) { |
Gerd Hoffmann | 9062155 | 2017-03-01 11:12:32 +0100 | [diff] [blame] | 184 | DRM_DEBUG_KMS("ignoring client monitors config: unchanged"); |
Christophe Fergeau | 9e3b317 | 2016-11-08 10:12:08 +0100 | [diff] [blame] | 185 | return; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 186 | } |
Marc-André Lureau | 4fdb086 | 2013-10-18 16:11:29 +0200 | [diff] [blame] | 187 | |
Sidong Yang | bbaac13 | 2020-05-24 11:26:23 +0900 | [diff] [blame] | 188 | DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE, ret); |
Dave Airlie | 7dea094 | 2014-10-28 11:28:44 +1000 | [diff] [blame] | 189 | qxl_update_offset_props(qdev); |
Dave Airlie | ce5c207 | 2020-09-08 14:41:40 +1000 | [diff] [blame] | 190 | DRM_MODESET_LOCK_ALL_END(dev, ctx, ret); |
Gabriel Krisman Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 191 | if (!drm_helper_hpd_irq_event(dev)) { |
Marc-André Lureau | 4fdb086 | 2013-10-18 16:11:29 +0200 | [diff] [blame] | 192 | /* notify that the monitor configuration changed, to |
| 193 | adjust at the arbitrary resolution */ |
Gabriel Krisman Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 194 | drm_kms_helper_hotplug_event(dev); |
Marc-André Lureau | 4fdb086 | 2013-10-18 16:11:29 +0200 | [diff] [blame] | 195 | } |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 196 | } |
| 197 | |
Gerd Hoffmann | feba24d | 2019-01-18 13:20:17 +0100 | [diff] [blame] | 198 | static 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 | |
| 214 | static 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 Hoffmann | 1b04367 | 2019-01-18 13:20:18 +0100 | [diff] [blame] | 220 | static 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 Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 226 | struct qxl_device *qdev = to_qxl(dev); |
Gerd Hoffmann | 1b04367 | 2019-01-18 13:20:18 +0100 | [diff] [blame] | 227 | 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 | |
| 244 | static int qxl_add_monitors_config_modes(struct drm_connector *connector) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 245 | { |
| 246 | struct drm_device *dev = connector->dev; |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 247 | struct qxl_device *qdev = to_qxl(dev); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 248 | struct qxl_output *output = drm_connector_to_qxl_output(connector); |
| 249 | int h = output->index; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 250 | struct qxl_head *head; |
| 251 | |
Gerd Hoffmann | 2d856f94 | 2017-03-01 11:12:34 +0100 | [diff] [blame] | 252 | if (!qdev->monitors_config) |
| 253 | return 0; |
Gerd Hoffmann | 21c76bd | 2019-01-18 13:20:12 +0100 | [diff] [blame] | 254 | if (h >= qxl_num_crtc) |
Gerd Hoffmann | 2d856f94 | 2017-03-01 11:12:34 +0100 | [diff] [blame] | 255 | return 0; |
Dave Airlie | 07f8d9b | 2013-07-02 06:37:13 +0100 | [diff] [blame] | 256 | if (!qdev->client_monitors_config) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 257 | return 0; |
Gerd Hoffmann | 2d856f94 | 2017-03-01 11:12:34 +0100 | [diff] [blame] | 258 | if (h >= qdev->client_monitors_config->count) |
| 259 | return 0; |
| 260 | |
Dave Airlie | 07f8d9b | 2013-07-02 06:37:13 +0100 | [diff] [blame] | 261 | head = &qdev->client_monitors_config->heads[h]; |
Gerd Hoffmann | 2d856f94 | 2017-03-01 11:12:34 +0100 | [diff] [blame] | 262 | DRM_DEBUG_KMS("head %d is %dx%d\n", h, head->width, head->height); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 263 | |
Gerd Hoffmann | 1b04367 | 2019-01-18 13:20:18 +0100 | [diff] [blame] | 264 | return qxl_add_mode(connector, head->width, head->height, true); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 265 | } |
| 266 | |
Jonathon Jongsma | bd3e1c7 | 2015-08-20 14:04:32 -0500 | [diff] [blame] | 267 | static struct mode_size { |
| 268 | int w; |
| 269 | int h; |
Gerd Hoffmann | b5f030b | 2019-01-18 13:20:19 +0100 | [diff] [blame] | 270 | } extra_modes[] = { |
Jonathon Jongsma | bd3e1c7 | 2015-08-20 14:04:32 -0500 | [diff] [blame] | 271 | { 720, 480}, |
Jonathon Jongsma | bd3e1c7 | 2015-08-20 14:04:32 -0500 | [diff] [blame] | 272 | {1152, 768}, |
Jonathon Jongsma | bd3e1c7 | 2015-08-20 14:04:32 -0500 | [diff] [blame] | 273 | {1280, 854}, |
Jonathon Jongsma | bd3e1c7 | 2015-08-20 14:04:32 -0500 | [diff] [blame] | 274 | }; |
| 275 | |
Gerd Hoffmann | b5f030b | 2019-01-18 13:20:19 +0100 | [diff] [blame] | 276 | static int qxl_add_extra_modes(struct drm_connector *connector) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 277 | { |
Gerd Hoffmann | 1b04367 | 2019-01-18 13:20:18 +0100 | [diff] [blame] | 278 | int i, ret = 0; |
Shayenne da Luz Moura | 408799e | 2018-10-26 16:22:55 -0300 | [diff] [blame] | 279 | |
Gerd Hoffmann | b5f030b | 2019-01-18 13:20:19 +0100 | [diff] [blame] | 280 | for (i = 0; i < ARRAY_SIZE(extra_modes); i++) |
Gerd Hoffmann | 1b04367 | 2019-01-18 13:20:18 +0100 | [diff] [blame] | 281 | ret += qxl_add_mode(connector, |
Gerd Hoffmann | b5f030b | 2019-01-18 13:20:19 +0100 | [diff] [blame] | 282 | extra_modes[i].w, |
| 283 | extra_modes[i].h, |
Gerd Hoffmann | 1b04367 | 2019-01-18 13:20:18 +0100 | [diff] [blame] | 284 | false); |
| 285 | return ret; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 286 | } |
| 287 | |
Gerd Hoffmann | 998010b | 2018-04-20 09:19:02 +0200 | [diff] [blame] | 288 | static 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 Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 311 | static void qxl_crtc_update_monitors_config(struct drm_crtc *crtc, |
| 312 | const char *reason) |
| 313 | { |
| 314 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 315 | struct qxl_device *qdev = to_qxl(dev); |
Gerd Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 316 | struct qxl_crtc *qcrtc = to_qxl_crtc(crtc); |
| 317 | struct qxl_head head; |
| 318 | int oldcount, i = qcrtc->index; |
| 319 | |
Gerd Hoffmann | 1662054 | 2019-01-18 13:20:09 +0100 | [diff] [blame] | 320 | if (!qdev->primary_bo) { |
Gerd Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 321 | DRM_DEBUG_KMS("no primary surface, skip (%s)\n", reason); |
| 322 | return; |
| 323 | } |
| 324 | |
Gerd Hoffmann | 21c76bd | 2019-01-18 13:20:12 +0100 | [diff] [blame] | 325 | if (!qdev->monitors_config || qxl_num_crtc <= i) |
Gerd Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 326 | 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 Moura | 408799e | 2018-10-26 16:22:55 -0300 | [diff] [blame] | 333 | |
Gerd Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 334 | 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 Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 340 | if (qdev->primary_bo == qdev->dumb_shadow_bo) |
| 341 | head.x += qdev->dumb_heads[i].x; |
Gerd Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 342 | } 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 Hoffmann | 21c76bd | 2019-01-18 13:20:12 +0100 | [diff] [blame] | 367 | qxl_num_crtc); |
Gerd Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 368 | |
| 369 | qdev->monitors_config->heads[i] = head; |
Gerd Hoffmann | 21c76bd | 2019-01-18 13:20:12 +0100 | [diff] [blame] | 370 | qdev->monitors_config->max_allowed = qxl_num_crtc; |
Gerd Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 371 | qxl_send_monitors_config(qdev); |
| 372 | } |
| 373 | |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 374 | static void qxl_crtc_atomic_flush(struct drm_crtc *crtc, |
| 375 | struct drm_crtc_state *old_crtc_state) |
| 376 | { |
Gerd Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 377 | qxl_crtc_update_monitors_config(crtc, "flush"); |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 378 | } |
| 379 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 380 | static void qxl_crtc_destroy(struct drm_crtc *crtc) |
| 381 | { |
| 382 | struct qxl_crtc *qxl_crtc = to_qxl_crtc(crtc); |
| 383 | |
Ray Strode | 9428088 | 2017-11-27 16:50:10 -0500 | [diff] [blame] | 384 | qxl_bo_unref(&qxl_crtc->cursor_bo); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 385 | drm_crtc_cleanup(crtc); |
| 386 | kfree(qxl_crtc); |
| 387 | } |
| 388 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 389 | static const struct drm_crtc_funcs qxl_crtc_funcs = { |
Gabriel Krisman Bertazi | bc8a00d | 2017-02-27 17:43:26 -0300 | [diff] [blame] | 390 | .set_config = drm_atomic_helper_set_config, |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 391 | .destroy = qxl_crtc_destroy, |
Gabriel Krisman Bertazi | 9973c87 | 2017-02-27 17:43:27 -0300 | [diff] [blame] | 392 | .page_flip = drm_atomic_helper_page_flip, |
Gabriel Krisman Bertazi | 9ade8b9 | 2017-02-27 17:43:23 -0300 | [diff] [blame] | 393 | .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 Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 396 | }; |
| 397 | |
Dave Airlie | 6d01f1f | 2013-04-16 13:24:25 +1000 | [diff] [blame] | 398 | static int qxl_framebuffer_surface_dirty(struct drm_framebuffer *fb, |
| 399 | struct drm_file *file_priv, |
Shayenne da Luz Moura | 1b00049 | 2018-10-26 16:23:49 -0300 | [diff] [blame] | 400 | unsigned int flags, unsigned int color, |
Dave Airlie | 6d01f1f | 2013-04-16 13:24:25 +1000 | [diff] [blame] | 401 | struct drm_clip_rect *clips, |
Shayenne da Luz Moura | 1b00049 | 2018-10-26 16:23:49 -0300 | [diff] [blame] | 402 | unsigned int num_clips) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 403 | { |
| 404 | /* TODO: vmwgfx where this was cribbed from had locking. Why? */ |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 405 | struct qxl_device *qdev = to_qxl(fb->dev); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 406 | struct drm_clip_rect norect; |
| 407 | struct qxl_bo *qobj; |
Sidong Yang | bbaac13 | 2020-05-24 11:26:23 +0900 | [diff] [blame] | 408 | struct drm_modeset_acquire_ctx ctx; |
Gerd Hoffmann | 4979904 | 2019-01-18 13:20:10 +0100 | [diff] [blame] | 409 | bool is_primary; |
Sidong Yang | bbaac13 | 2020-05-24 11:26:23 +0900 | [diff] [blame] | 410 | int inc = 1, ret; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 411 | |
Sidong Yang | bbaac13 | 2020-05-24 11:26:23 +0900 | [diff] [blame] | 412 | DRM_MODESET_LOCK_ALL_BEGIN(fb->dev, ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE, ret); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 413 | |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 414 | qobj = gem_to_qxl_bo(fb->obj[0]); |
Dave Airlie | b2b4465 | 2013-05-13 12:48:40 +1000 | [diff] [blame] | 415 | /* if we aren't primary surface ignore this */ |
Gerd Hoffmann | 4979904 | 2019-01-18 13:20:10 +0100 | [diff] [blame] | 416 | is_primary = qobj->shadow ? qobj->shadow->is_primary : qobj->is_primary; |
Sidong Yang | bbaac13 | 2020-05-24 11:26:23 +0900 | [diff] [blame] | 417 | if (!is_primary) |
| 418 | goto out_lock_end; |
Dave Airlie | b2b4465 | 2013-05-13 12:48:40 +1000 | [diff] [blame] | 419 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 420 | 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 Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 431 | qxl_draw_dirty_fb(qdev, fb, qobj, flags, color, |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 432 | clips, num_clips, inc, 0); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 433 | |
Sidong Yang | bbaac13 | 2020-05-24 11:26:23 +0900 | [diff] [blame] | 434 | out_lock_end: |
Dave Airlie | ce5c207 | 2020-09-08 14:41:40 +1000 | [diff] [blame] | 435 | DRM_MODESET_LOCK_ALL_END(fb->dev, ctx, ret); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 436 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static const struct drm_framebuffer_funcs qxl_fb_funcs = { |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 441 | .destroy = drm_gem_fb_destroy, |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 442 | .dirty = qxl_framebuffer_surface_dirty, |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 443 | .create_handle = drm_gem_fb_create_handle, |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 444 | }; |
| 445 | |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 446 | static void qxl_crtc_atomic_enable(struct drm_crtc *crtc, |
| 447 | struct drm_crtc_state *old_state) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 448 | { |
Gerd Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 449 | qxl_crtc_update_monitors_config(crtc, "enable"); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 450 | } |
| 451 | |
Laurent Pinchart | 6458171 | 2017-06-30 12:36:45 +0300 | [diff] [blame] | 452 | static void qxl_crtc_atomic_disable(struct drm_crtc *crtc, |
| 453 | struct drm_crtc_state *old_state) |
Dave Airlie | 07f8d9b | 2013-07-02 06:37:13 +0100 | [diff] [blame] | 454 | { |
Gerd Hoffmann | a6d3c4d | 2018-04-20 09:19:03 +0200 | [diff] [blame] | 455 | qxl_crtc_update_monitors_config(crtc, "disable"); |
Dave Airlie | 07f8d9b | 2013-07-02 06:37:13 +0100 | [diff] [blame] | 456 | } |
| 457 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 458 | static const struct drm_crtc_helper_funcs qxl_crtc_helper_funcs = { |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 459 | .atomic_flush = qxl_crtc_atomic_flush, |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 460 | .atomic_enable = qxl_crtc_atomic_enable, |
Laurent Pinchart | 6458171 | 2017-06-30 12:36:45 +0300 | [diff] [blame] | 461 | .atomic_disable = qxl_crtc_atomic_disable, |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 462 | }; |
| 463 | |
Gerd Hoffmann | 45dfe57 | 2017-06-20 13:39:15 +0200 | [diff] [blame] | 464 | static int qxl_primary_atomic_check(struct drm_plane *plane, |
| 465 | struct drm_plane_state *state) |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 466 | { |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 467 | struct qxl_device *qdev = to_qxl(plane->dev); |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 468 | struct qxl_bo *bo; |
| 469 | |
| 470 | if (!state->crtc || !state->fb) |
| 471 | return 0; |
| 472 | |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 473 | bo = gem_to_qxl_bo(state->fb->obj[0]); |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 474 | |
Gerd Hoffmann | feba24d | 2019-01-18 13:20:17 +0100 | [diff] [blame] | 475 | return qxl_check_framebuffer(qdev, bo); |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 476 | } |
| 477 | |
Ray Strode | 9428088 | 2017-11-27 16:50:10 -0500 | [diff] [blame] | 478 | static int qxl_primary_apply_cursor(struct drm_plane *plane) |
| 479 | { |
| 480 | struct drm_device *dev = plane->dev; |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 481 | struct qxl_device *qdev = to_qxl(dev); |
Ray Strode | 9428088 | 2017-11-27 16:50:10 -0500 | [diff] [blame] | 482 | 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 Strode | 9428088 | 2017-11-27 16:50:10 -0500 | [diff] [blame] | 515 | qxl_release_fence_buffer_objects(release); |
Vasily Averin | 933db73 | 2020-04-29 12:01:24 +0300 | [diff] [blame] | 516 | qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false); |
Ray Strode | 9428088 | 2017-11-27 16:50:10 -0500 | [diff] [blame] | 517 | |
| 518 | return ret; |
| 519 | |
| 520 | out_free_release: |
| 521 | qxl_release_free(qdev, release); |
| 522 | return ret; |
| 523 | } |
| 524 | |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 525 | static void qxl_primary_atomic_update(struct drm_plane *plane, |
| 526 | struct drm_plane_state *old_state) |
| 527 | { |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 528 | struct qxl_device *qdev = to_qxl(plane->dev); |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 529 | struct qxl_bo *bo = gem_to_qxl_bo(plane->state->fb->obj[0]); |
YueHaibing | fb8cd60 | 2019-02-18 08:54:59 +0000 | [diff] [blame] | 530 | struct qxl_bo *primary; |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 531 | struct drm_clip_rect norect = { |
| 532 | .x1 = 0, |
| 533 | .y1 = 0, |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 534 | .x2 = plane->state->fb->width, |
| 535 | .y2 = plane->state->fb->height |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 536 | }; |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 537 | uint32_t dumb_shadow_offset = 0; |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 538 | |
Gerd Hoffmann | 4979904 | 2019-01-18 13:20:10 +0100 | [diff] [blame] | 539 | primary = bo->shadow ? bo->shadow : bo; |
Gerd Hoffmann | b0e07da | 2017-09-11 11:39:50 +0200 | [diff] [blame] | 540 | |
Gerd Hoffmann | 4979904 | 2019-01-18 13:20:10 +0100 | [diff] [blame] | 541 | if (!primary->is_primary) { |
| 542 | if (qdev->primary_bo) |
Gerd Hoffmann | 62676d1 | 2017-10-19 08:21:50 +0200 | [diff] [blame] | 543 | qxl_io_destroy_primary(qdev); |
Gerd Hoffmann | 4979904 | 2019-01-18 13:20:10 +0100 | [diff] [blame] | 544 | qxl_io_create_primary(qdev, primary); |
| 545 | qxl_primary_apply_cursor(plane); |
Gerd Hoffmann | b0e07da | 2017-09-11 11:39:50 +0200 | [diff] [blame] | 546 | } |
Gerd Hoffmann | 62676d1 | 2017-10-19 08:21:50 +0200 | [diff] [blame] | 547 | |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 548 | 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 Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static void qxl_primary_atomic_disable(struct drm_plane *plane, |
| 557 | struct drm_plane_state *old_state) |
| 558 | { |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 559 | struct qxl_device *qdev = to_qxl(plane->dev); |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 560 | |
Gerd Hoffmann | b0e07da | 2017-09-11 11:39:50 +0200 | [diff] [blame] | 561 | if (old_state->fb) { |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 562 | struct qxl_bo *bo = gem_to_qxl_bo(old_state->fb->obj[0]); |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 563 | |
Gerd Hoffmann | b0e07da | 2017-09-11 11:39:50 +0200 | [diff] [blame] | 564 | if (bo->is_primary) { |
| 565 | qxl_io_destroy_primary(qdev); |
| 566 | bo->is_primary = false; |
| 567 | } |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 571 | static 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 Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 575 | struct qxl_device *qdev = to_qxl(dev); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 576 | struct drm_framebuffer *fb = plane->state->fb; |
Ray Strode | 9428088 | 2017-11-27 16:50:10 -0500 | [diff] [blame] | 577 | struct qxl_crtc *qcrtc = to_qxl_crtc(plane->state->crtc); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 578 | struct qxl_release *release; |
| 579 | struct qxl_cursor_cmd *cmd; |
| 580 | struct qxl_cursor *cursor; |
| 581 | struct drm_gem_object *obj; |
Jeremy Cline | 889ad63 | 2018-06-01 16:05:32 -0400 | [diff] [blame] | 582 | struct qxl_bo *cursor_bo = NULL, *user_bo = NULL, *old_cursor_bo = NULL; |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 583 | 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 Carpenter | ee5cb7c | 2017-03-14 10:54:10 +0300 | [diff] [blame] | 590 | if (ret) |
| 591 | return; |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 592 | |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 593 | if (fb != old_state->fb) { |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 594 | obj = fb->obj[0]; |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 595 | 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 Fergeau | 0081cdf | 2018-11-20 17:20:04 +0100 | [diff] [blame] | 608 | ret = qxl_bo_pin(cursor_bo); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 609 | if (ret) |
| 610 | goto out_free_bo; |
| 611 | |
Christophe Fergeau | 0081cdf | 2018-11-20 17:20:04 +0100 | [diff] [blame] | 612 | ret = qxl_release_reserve_list(release, true); |
| 613 | if (ret) |
| 614 | goto out_unpin; |
| 615 | |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 616 | 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 Bertazi | 429030b | 2017-05-19 14:58:19 -0300 | [diff] [blame] | 634 | cmd = (struct qxl_cursor_cmd *) qxl_release_map(qdev, release); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 635 | 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 Strode | 9428088 | 2017-11-27 16:50:10 -0500 | [diff] [blame] | 639 | |
Jeremy Cline | 889ad63 | 2018-06-01 16:05:32 -0400 | [diff] [blame] | 640 | old_cursor_bo = qcrtc->cursor_bo; |
Ray Strode | 9428088 | 2017-11-27 16:50:10 -0500 | [diff] [blame] | 641 | qcrtc->cursor_bo = cursor_bo; |
| 642 | cursor_bo = NULL; |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 643 | } else { |
| 644 | |
| 645 | ret = qxl_release_reserve_list(release, true); |
| 646 | if (ret) |
| 647 | goto out_free_release; |
| 648 | |
Gabriel Krisman Bertazi | 429030b | 2017-05-19 14:58:19 -0300 | [diff] [blame] | 649 | cmd = (struct qxl_cursor_cmd *) qxl_release_map(qdev, release); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 650 | 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 Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 657 | qxl_release_fence_buffer_objects(release); |
Vasily Averin | 933db73 | 2020-04-29 12:01:24 +0300 | [diff] [blame] | 658 | qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 659 | |
Christophe Fergeau | 0081cdf | 2018-11-20 17:20:04 +0100 | [diff] [blame] | 660 | if (old_cursor_bo != NULL) |
| 661 | qxl_bo_unpin(old_cursor_bo); |
Christophe Fergeau | 76a57db | 2018-11-20 17:20:02 +0100 | [diff] [blame] | 662 | qxl_bo_unref(&old_cursor_bo); |
Ray Strode | 16c6db3 | 2017-11-27 16:50:09 -0500 | [diff] [blame] | 663 | qxl_bo_unref(&cursor_bo); |
| 664 | |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 665 | return; |
| 666 | |
| 667 | out_backoff: |
| 668 | qxl_release_backoff_reserve_list(release); |
Christophe Fergeau | 0081cdf | 2018-11-20 17:20:04 +0100 | [diff] [blame] | 669 | out_unpin: |
| 670 | qxl_bo_unpin(cursor_bo); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 671 | out_free_bo: |
| 672 | qxl_bo_unref(&cursor_bo); |
| 673 | out_kunmap: |
| 674 | qxl_bo_kunmap(user_bo); |
| 675 | out_free_release: |
| 676 | qxl_release_free(qdev, release); |
| 677 | return; |
| 678 | |
| 679 | } |
| 680 | |
Gerd Hoffmann | 45dfe57 | 2017-06-20 13:39:15 +0200 | [diff] [blame] | 681 | static void qxl_cursor_atomic_disable(struct drm_plane *plane, |
| 682 | struct drm_plane_state *old_state) |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 683 | { |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 684 | struct qxl_device *qdev = to_qxl(plane->dev); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 685 | 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 Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 705 | qxl_release_fence_buffer_objects(release); |
Vasily Averin | 933db73 | 2020-04-29 12:01:24 +0300 | [diff] [blame] | 706 | qxl_push_cursor_ring_release(qdev, release, QXL_CMD_CURSOR, false); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 707 | } |
| 708 | |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 709 | static 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 | |
| 737 | static 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 Hoffmann | 45dfe57 | 2017-06-20 13:39:15 +0200 | [diff] [blame] | 764 | static int qxl_plane_prepare_fb(struct drm_plane *plane, |
| 765 | struct drm_plane_state *new_state) |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 766 | { |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 767 | struct qxl_device *qdev = to_qxl(plane->dev); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 768 | struct drm_gem_object *obj; |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 769 | struct qxl_bo *user_bo; |
| 770 | struct qxl_surface surf; |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 771 | int ret; |
| 772 | |
| 773 | if (!new_state->fb) |
| 774 | return 0; |
| 775 | |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 776 | obj = new_state->fb->obj[0]; |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 777 | user_bo = gem_to_qxl_bo(obj); |
| 778 | |
Gerd Hoffmann | 62676d1 | 2017-10-19 08:21:50 +0200 | [diff] [blame] | 779 | if (plane->type == DRM_PLANE_TYPE_PRIMARY && |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 780 | 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 Velikov | 9c86fb1 | 2020-05-15 10:51:08 +0100 | [diff] [blame] | 788 | drm_gem_object_put |
Gerd Hoffmann | e0828d5 | 2019-08-05 16:01:05 +0200 | [diff] [blame] | 789 | (&qdev->dumb_shadow_bo->tbo.base); |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 790 | 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 Hoffmann | 62676d1 | 2017-10-19 08:21:50 +0200 | [diff] [blame] | 795 | } |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 796 | if (user_bo->shadow != qdev->dumb_shadow_bo) { |
| 797 | if (user_bo->shadow) { |
Emil Velikov | 9c86fb1 | 2020-05-15 10:51:08 +0100 | [diff] [blame] | 798 | drm_gem_object_put |
Gerd Hoffmann | e0828d5 | 2019-08-05 16:01:05 +0200 | [diff] [blame] | 799 | (&user_bo->shadow->tbo.base); |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 800 | user_bo->shadow = NULL; |
| 801 | } |
Gerd Hoffmann | e0828d5 | 2019-08-05 16:01:05 +0200 | [diff] [blame] | 802 | drm_gem_object_get(&qdev->dumb_shadow_bo->tbo.base); |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 803 | user_bo->shadow = qdev->dumb_shadow_bo; |
Gerd Hoffmann | 62676d1 | 2017-10-19 08:21:50 +0200 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | |
Christophe Fergeau | 545592f | 2018-11-20 17:20:03 +0100 | [diff] [blame] | 807 | ret = qxl_bo_pin(user_bo); |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 808 | if (ret) |
| 809 | return ret; |
| 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | |
| 814 | static 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 Hoffmann | 5f3d862 | 2017-09-18 09:41:45 +0200 | [diff] [blame] | 820 | if (!old_state->fb) { |
| 821 | /* |
| 822 | * we never executed prepare_fb, so there's nothing to |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 823 | * unpin. |
| 824 | */ |
| 825 | return; |
| 826 | } |
| 827 | |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 828 | obj = old_state->fb->obj[0]; |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 829 | user_bo = gem_to_qxl_bo(obj); |
| 830 | qxl_bo_unpin(user_bo); |
Gerd Hoffmann | 62676d1 | 2017-10-19 08:21:50 +0200 | [diff] [blame] | 831 | |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 832 | if (old_state->fb != plane->state->fb && user_bo->shadow) { |
Emil Velikov | 9c86fb1 | 2020-05-15 10:51:08 +0100 | [diff] [blame] | 833 | drm_gem_object_put(&user_bo->shadow->tbo.base); |
Gerd Hoffmann | 62676d1 | 2017-10-19 08:21:50 +0200 | [diff] [blame] | 834 | user_bo->shadow = NULL; |
| 835 | } |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | static const uint32_t qxl_cursor_plane_formats[] = { |
| 839 | DRM_FORMAT_ARGB8888, |
| 840 | }; |
| 841 | |
| 842 | static const struct drm_plane_helper_funcs qxl_cursor_helper_funcs = { |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 843 | .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 | |
| 849 | static const struct drm_plane_funcs qxl_cursor_plane_funcs = { |
Gabriel Krisman Bertazi | 472e6d4 | 2017-02-27 17:43:25 -0300 | [diff] [blame] | 850 | .update_plane = drm_atomic_helper_update_plane, |
| 851 | .disable_plane = drm_atomic_helper_disable_plane, |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 852 | .destroy = drm_primary_helper_destroy, |
Gabriel Krisman Bertazi | 9ade8b9 | 2017-02-27 17:43:23 -0300 | [diff] [blame] | 853 | .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 Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 856 | }; |
| 857 | |
Gabriel Krisman Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 858 | static const uint32_t qxl_primary_plane_formats[] = { |
| 859 | DRM_FORMAT_XRGB8888, |
| 860 | DRM_FORMAT_ARGB8888, |
| 861 | }; |
| 862 | |
Gabriel Krisman Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 863 | static 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 Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 871 | static const struct drm_plane_funcs qxl_primary_plane_funcs = { |
Gabriel Krisman Bertazi | 472e6d4 | 2017-02-27 17:43:25 -0300 | [diff] [blame] | 872 | .update_plane = drm_atomic_helper_update_plane, |
| 873 | .disable_plane = drm_atomic_helper_disable_plane, |
Gabriel Krisman Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 874 | .destroy = drm_primary_helper_destroy, |
Gabriel Krisman Bertazi | 9ade8b9 | 2017-02-27 17:43:23 -0300 | [diff] [blame] | 875 | .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 Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 878 | }; |
| 879 | |
| 880 | static 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 Bertazi | c2ff663 | 2017-02-27 17:43:20 -0300 | [diff] [blame] | 895 | helper_funcs = &primary_helper_funcs; |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 896 | } 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 Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 901 | } 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 Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame] | 911 | NULL, type, NULL); |
Gabriel Krisman Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 912 | if (err) |
| 913 | goto free_plane; |
| 914 | |
| 915 | drm_plane_helper_add(plane, helper_funcs); |
| 916 | |
| 917 | return plane; |
| 918 | |
| 919 | free_plane: |
| 920 | kfree(plane); |
| 921 | return ERR_PTR(-EINVAL); |
| 922 | } |
| 923 | |
Dave Airlie | 07f8d9b | 2013-07-02 06:37:13 +0100 | [diff] [blame] | 924 | static int qdev_crtc_init(struct drm_device *dev, int crtc_id) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 925 | { |
| 926 | struct qxl_crtc *qxl_crtc; |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 927 | struct drm_plane *primary, *cursor; |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 928 | struct qxl_device *qdev = to_qxl(dev); |
Gabriel Krisman Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 929 | int r; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 930 | |
| 931 | qxl_crtc = kzalloc(sizeof(struct qxl_crtc), GFP_KERNEL); |
| 932 | if (!qxl_crtc) |
| 933 | return -ENOMEM; |
| 934 | |
Gabriel Krisman Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 935 | 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 Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 941 | 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 Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 948 | &qxl_crtc_funcs, NULL); |
| 949 | if (r) |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 950 | goto clean_cursor; |
Gabriel Krisman Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 951 | |
Dave Airlie | 07f8d9b | 2013-07-02 06:37:13 +0100 | [diff] [blame] | 952 | qxl_crtc->index = crtc_id; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 953 | drm_crtc_helper_add(&qxl_crtc->base, &qxl_crtc_helper_funcs); |
| 954 | return 0; |
Gabriel Krisman Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 955 | |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 956 | clean_cursor: |
| 957 | drm_plane_cleanup(cursor); |
| 958 | kfree(cursor); |
Gabriel Krisman Bertazi | d3e7e42 | 2017-02-27 17:43:18 -0300 | [diff] [blame] | 959 | clean_primary: |
| 960 | drm_plane_cleanup(primary); |
| 961 | kfree(primary); |
| 962 | free_mem: |
| 963 | kfree(qxl_crtc); |
| 964 | return r; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 965 | } |
| 966 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 967 | static int qxl_conn_get_modes(struct drm_connector *connector) |
| 968 | { |
Gerd Hoffmann | 1b04367 | 2019-01-18 13:20:18 +0100 | [diff] [blame] | 969 | struct drm_device *dev = connector->dev; |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 970 | struct qxl_device *qdev = to_qxl(dev); |
Gerd Hoffmann | 1b04367 | 2019-01-18 13:20:18 +0100 | [diff] [blame] | 971 | struct qxl_output *output = drm_connector_to_qxl_output(connector); |
Shayenne da Luz Moura | 1b00049 | 2018-10-26 16:23:49 -0300 | [diff] [blame] | 972 | unsigned int pwidth = 1024; |
| 973 | unsigned int pheight = 768; |
Gerd Hoffmann | 2d856f94 | 2017-03-01 11:12:34 +0100 | [diff] [blame] | 974 | int ret = 0; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 975 | |
Gerd Hoffmann | 1b04367 | 2019-01-18 13:20:18 +0100 | [diff] [blame] | 976 | 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 Hoffmann | b5f030b | 2019-01-18 13:20:19 +0100 | [diff] [blame] | 985 | ret += drm_add_modes_noedid(connector, 8192, 8192); |
| 986 | ret += qxl_add_extra_modes(connector); |
Gerd Hoffmann | 1b04367 | 2019-01-18 13:20:18 +0100 | [diff] [blame] | 987 | ret += qxl_add_monitors_config_modes(connector); |
| 988 | drm_set_preferred_mode(connector, pwidth, pheight); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 989 | return ret; |
| 990 | } |
| 991 | |
Luc Van Oostenryck | e0d92e1 | 2018-04-24 15:15:15 +0200 | [diff] [blame] | 992 | static enum drm_mode_status qxl_conn_mode_valid(struct drm_connector *connector, |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 993 | struct drm_display_mode *mode) |
| 994 | { |
Jonathon Jongsma | bd3e1c7 | 2015-08-20 14:04:32 -0500 | [diff] [blame] | 995 | struct drm_device *ddev = connector->dev; |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 996 | struct qxl_device *qdev = to_qxl(ddev); |
Jonathon Jongsma | bd3e1c7 | 2015-08-20 14:04:32 -0500 | [diff] [blame] | 997 | |
Gerd Hoffmann | feba24d | 2019-01-18 13:20:17 +0100 | [diff] [blame] | 998 | if (qxl_check_mode(qdev, mode->hdisplay, mode->vdisplay) != 0) |
| 999 | return MODE_BAD; |
Jonathon Jongsma | bd3e1c7 | 2015-08-20 14:04:32 -0500 | [diff] [blame] | 1000 | |
Gerd Hoffmann | feba24d | 2019-01-18 13:20:17 +0100 | [diff] [blame] | 1001 | return MODE_OK; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1002 | } |
| 1003 | |
Dave Airlie | 6d01f1f | 2013-04-16 13:24:25 +1000 | [diff] [blame] | 1004 | static struct drm_encoder *qxl_best_encoder(struct drm_connector *connector) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1005 | { |
| 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 Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1013 | static 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 Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1019 | static 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 Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 1026 | struct qxl_device *qdev = to_qxl(ddev); |
Dave Airlie | 69e5d3f | 2015-09-14 10:28:34 +1000 | [diff] [blame] | 1027 | bool connected = false; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1028 | |
| 1029 | /* The first monitor is always connected */ |
Dave Airlie | 69e5d3f | 2015-09-14 10:28:34 +1000 | [diff] [blame] | 1030 | 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 Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1036 | |
Marc-André Lureau | 5cab51c | 2013-10-18 16:11:33 +0200 | [diff] [blame] | 1037 | DRM_DEBUG("#%d connected: %d\n", output->index, connected); |
Marc-André Lureau | 5cab51c | 2013-10-18 16:11:33 +0200 | [diff] [blame] | 1038 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1039 | return connected ? connector_status_connected |
| 1040 | : connector_status_disconnected; |
| 1041 | } |
| 1042 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1043 | static void qxl_conn_destroy(struct drm_connector *connector) |
| 1044 | { |
| 1045 | struct qxl_output *qxl_output = |
| 1046 | drm_connector_to_qxl_output(connector); |
| 1047 | |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1048 | drm_connector_unregister(connector); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1049 | drm_connector_cleanup(connector); |
| 1050 | kfree(qxl_output); |
| 1051 | } |
| 1052 | |
| 1053 | static const struct drm_connector_funcs qxl_connector_funcs = { |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1054 | .detect = qxl_conn_detect, |
Ville Syrjälä | 6af3e65 | 2015-12-03 23:14:14 +0200 | [diff] [blame] | 1055 | .fill_modes = drm_helper_probe_single_connector_modes, |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1056 | .destroy = qxl_conn_destroy, |
Gabriel Krisman Bertazi | 9ade8b9 | 2017-02-27 17:43:23 -0300 | [diff] [blame] | 1057 | .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 Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1060 | }; |
| 1061 | |
Dave Airlie | 4695b03 | 2013-10-11 11:05:00 +1000 | [diff] [blame] | 1062 | static 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 Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 1068 | drm_property_create_range(&qdev->ddev, DRM_MODE_PROP_IMMUTABLE, |
Dave Airlie | 4695b03 | 2013-10-11 11:05:00 +1000 | [diff] [blame] | 1069 | "hotplug_mode_update", 0, 1); |
| 1070 | |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
Dave Airlie | 6d01f1f | 2013-04-16 13:24:25 +1000 | [diff] [blame] | 1074 | static int qdev_output_init(struct drm_device *dev, int num_output) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1075 | { |
Daniel Vetter | e304f8a | 2020-04-15 09:40:02 +0200 | [diff] [blame] | 1076 | struct qxl_device *qdev = to_qxl(dev); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1077 | struct qxl_output *qxl_output; |
| 1078 | struct drm_connector *connector; |
| 1079 | struct drm_encoder *encoder; |
Thomas Zimmermann | 6f2bb11 | 2020-02-28 09:18:28 +0100 | [diff] [blame] | 1080 | int ret; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1081 | |
| 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 Zimmermann | 6f2bb11 | 2020-02-28 09:18:28 +0100 | [diff] [blame] | 1093 | 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 Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1100 | |
Dave Airlie | 5ff91e4 | 2013-07-05 10:20:33 +1000 | [diff] [blame] | 1101 | /* we get HPD via client monitors config */ |
| 1102 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1103 | encoder->possible_crtcs = 1 << num_output; |
Daniel Vetter | cde4c44 | 2018-07-09 10:40:07 +0200 | [diff] [blame] | 1104 | drm_connector_attach_encoder(&qxl_output->base, |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1105 | &qxl_output->enc); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1106 | drm_connector_helper_add(connector, &qxl_connector_helper_funcs); |
| 1107 | |
Dave Airlie | 4695b03 | 2013-10-11 11:05:00 +1000 | [diff] [blame] | 1108 | drm_object_attach_property(&connector->base, |
| 1109 | qdev->hotplug_mode_update_property, 0); |
Dave Airlie | 7dea094 | 2014-10-28 11:28:44 +1000 | [diff] [blame] | 1110 | 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 Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1114 | return 0; |
Thomas Zimmermann | 6f2bb11 | 2020-02-28 09:18:28 +0100 | [diff] [blame] | 1115 | |
| 1116 | err_drm_connector_cleanup: |
| 1117 | drm_connector_cleanup(&qxl_output->base); |
| 1118 | kfree(qxl_output); |
| 1119 | return ret; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | static struct drm_framebuffer * |
| 1123 | qxl_user_framebuffer_create(struct drm_device *dev, |
| 1124 | struct drm_file *file_priv, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 1125 | const struct drm_mode_fb_cmd2 *mode_cmd) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1126 | { |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 1127 | return drm_gem_fb_create_with_funcs(dev, file_priv, mode_cmd, |
| 1128 | &qxl_fb_funcs); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | static const struct drm_mode_config_funcs qxl_mode_funcs = { |
| 1132 | .fb_create = qxl_user_framebuffer_create, |
Gabriel Krisman Bertazi | 472e6d4 | 2017-02-27 17:43:25 -0300 | [diff] [blame] | 1133 | .atomic_check = drm_atomic_helper_check, |
| 1134 | .atomic_commit = drm_atomic_helper_commit, |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1135 | }; |
| 1136 | |
Dave Airlie | 2bd6ce8 | 2013-07-04 14:46:46 +1000 | [diff] [blame] | 1137 | int qxl_create_monitors_object(struct qxl_device *qdev) |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1138 | { |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1139 | int ret; |
| 1140 | struct drm_gem_object *gobj; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1141 | int monitors_config_size = sizeof(struct qxl_monitors_config) + |
Gerd Hoffmann | 21c76bd | 2019-01-18 13:20:12 +0100 | [diff] [blame] | 1142 | qxl_num_crtc * sizeof(struct qxl_head); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1143 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1144 | 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 Airlie | 2bd6ce8 | 2013-07-04 14:46:46 +1000 | [diff] [blame] | 1152 | |
Christophe Fergeau | 545592f | 2018-11-20 17:20:03 +0100 | [diff] [blame] | 1153 | ret = qxl_bo_pin(qdev->monitors_config_bo); |
Dave Airlie | 2bd6ce8 | 2013-07-04 14:46:46 +1000 | [diff] [blame] | 1154 | if (ret) |
| 1155 | return ret; |
| 1156 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1157 | qxl_bo_kmap(qdev->monitors_config_bo, NULL); |
Dave Airlie | 2bd6ce8 | 2013-07-04 14:46:46 +1000 | [diff] [blame] | 1158 | |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1159 | 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 Hoffmann | 21c76bd | 2019-01-18 13:20:12 +0100 | [diff] [blame] | 1164 | qdev->dumb_heads = kcalloc(qxl_num_crtc, sizeof(qdev->dumb_heads[0]), |
| 1165 | GFP_KERNEL); |
Gerd Hoffmann | 90adda2 | 2019-01-18 13:20:11 +0100 | [diff] [blame] | 1166 | if (!qdev->dumb_heads) { |
| 1167 | qxl_destroy_monitors_object(qdev); |
| 1168 | return -ENOMEM; |
| 1169 | } |
Dave Airlie | 2bd6ce8 | 2013-07-04 14:46:46 +1000 | [diff] [blame] | 1170 | return 0; |
| 1171 | } |
| 1172 | |
| 1173 | int 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 Bertazi | 715a11f | 2017-02-27 17:43:16 -0300 | [diff] [blame] | 1181 | ret = qxl_bo_unpin(qdev->monitors_config_bo); |
Dave Airlie | 2bd6ce8 | 2013-07-04 14:46:46 +1000 | [diff] [blame] | 1182 | if (ret) |
| 1183 | return ret; |
| 1184 | |
Dave Airlie | 2bd6ce8 | 2013-07-04 14:46:46 +1000 | [diff] [blame] | 1185 | qxl_bo_unref(&qdev->monitors_config_bo); |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
| 1189 | int qxl_modeset_init(struct qxl_device *qdev) |
| 1190 | { |
| 1191 | int i; |
| 1192 | int ret; |
| 1193 | |
Gabriel Krisman Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 1194 | drm_mode_config_init(&qdev->ddev); |
Dave Airlie | 2bd6ce8 | 2013-07-04 14:46:46 +1000 | [diff] [blame] | 1195 | |
| 1196 | ret = qxl_create_monitors_object(qdev); |
| 1197 | if (ret) |
| 1198 | return ret; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1199 | |
Gabriel Krisman Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 1200 | qdev->ddev.mode_config.funcs = (void *)&qxl_mode_funcs; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1201 | |
| 1202 | /* modes will be validated against the framebuffer size */ |
Gabriel Krisman Bertazi | 1277eed | 2017-02-27 17:43:19 -0300 | [diff] [blame] | 1203 | qdev->ddev.mode_config.min_width = 0; |
| 1204 | qdev->ddev.mode_config.min_height = 0; |
Gabriel Krisman Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 1205 | qdev->ddev.mode_config.max_width = 8192; |
| 1206 | qdev->ddev.mode_config.max_height = 8192; |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1207 | |
Gabriel Krisman Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 1208 | qdev->ddev.mode_config.fb_base = qdev->vram_base; |
Dave Airlie | 4695b03 | 2013-10-11 11:05:00 +1000 | [diff] [blame] | 1209 | |
Gabriel Krisman Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 1210 | drm_mode_create_suggested_offset_properties(&qdev->ddev); |
Dave Airlie | 4695b03 | 2013-10-11 11:05:00 +1000 | [diff] [blame] | 1211 | qxl_mode_create_hotplug_mode_update_property(qdev); |
| 1212 | |
Dave Airlie | 07f8d9b | 2013-07-02 06:37:13 +0100 | [diff] [blame] | 1213 | for (i = 0 ; i < qxl_num_crtc; ++i) { |
Gabriel Krisman Bertazi | cbdded7 | 2017-01-26 23:05:48 -0200 | [diff] [blame] | 1214 | qdev_crtc_init(&qdev->ddev, i); |
| 1215 | qdev_output_init(&qdev->ddev, i); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1216 | } |
| 1217 | |
Gerd Hoffmann | c50fad8 | 2017-03-01 11:12:33 +0100 | [diff] [blame] | 1218 | qxl_display_read_client_monitors_config(qdev); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1219 | |
Gabriel Krisman Bertazi | 9ade8b9 | 2017-02-27 17:43:23 -0300 | [diff] [blame] | 1220 | drm_mode_config_reset(&qdev->ddev); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1221 | return 0; |
| 1222 | } |
| 1223 | |
| 1224 | void qxl_modeset_fini(struct qxl_device *qdev) |
| 1225 | { |
Dave Airlie | 2bd6ce8 | 2013-07-04 14:46:46 +1000 | [diff] [blame] | 1226 | qxl_destroy_monitors_object(qdev); |
Peter Wu | bf8744e | 2018-09-10 15:21:56 +0200 | [diff] [blame] | 1227 | drm_mode_config_cleanup(&qdev->ddev); |
Dave Airlie | f64122c | 2013-02-25 14:47:55 +1000 | [diff] [blame] | 1228 | } |