1 1.5 riastrad /* $NetBSD: intel_atomic.c,v 1.5 2021/12/19 12:24:36 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2015 Intel Corporation 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice (including the next 14 1.1 riastrad * paragraph) shall be included in all copies or substantial portions of the 15 1.1 riastrad * Software. 16 1.1 riastrad * 17 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 1.1 riastrad * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 1.1 riastrad * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 1.1 riastrad * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 1.1 riastrad * DEALINGS IN THE SOFTWARE. 24 1.1 riastrad */ 25 1.1 riastrad 26 1.1 riastrad /** 27 1.1 riastrad * DOC: atomic modeset support 28 1.1 riastrad * 29 1.1 riastrad * The functions here implement the state management and hardware programming 30 1.1 riastrad * dispatch required by the atomic modeset infrastructure. 31 1.1 riastrad * See intel_atomic_plane.c for the plane-specific atomic functionality. 32 1.1 riastrad */ 33 1.1 riastrad 34 1.1 riastrad #include <sys/cdefs.h> 35 1.5 riastrad __KERNEL_RCSID(0, "$NetBSD: intel_atomic.c,v 1.5 2021/12/19 12:24:36 riastradh Exp $"); 36 1.1 riastrad 37 1.1 riastrad #include <drm/drm_atomic.h> 38 1.1 riastrad #include <drm/drm_atomic_helper.h> 39 1.1 riastrad #include <drm/drm_fourcc.h> 40 1.1 riastrad #include <drm/drm_plane_helper.h> 41 1.1 riastrad 42 1.1 riastrad #include "intel_atomic.h" 43 1.1 riastrad #include "intel_display_types.h" 44 1.1 riastrad #include "intel_hdcp.h" 45 1.1 riastrad #include "intel_psr.h" 46 1.1 riastrad #include "intel_sprite.h" 47 1.1 riastrad 48 1.1 riastrad /** 49 1.1 riastrad * intel_digital_connector_atomic_get_property - hook for connector->atomic_get_property. 50 1.1 riastrad * @connector: Connector to get the property for. 51 1.1 riastrad * @state: Connector state to retrieve the property from. 52 1.1 riastrad * @property: Property to retrieve. 53 1.1 riastrad * @val: Return value for the property. 54 1.1 riastrad * 55 1.1 riastrad * Returns the atomic property value for a digital connector. 56 1.1 riastrad */ 57 1.1 riastrad int intel_digital_connector_atomic_get_property(struct drm_connector *connector, 58 1.1 riastrad const struct drm_connector_state *state, 59 1.1 riastrad struct drm_property *property, 60 1.1 riastrad u64 *val) 61 1.1 riastrad { 62 1.1 riastrad struct drm_device *dev = connector->dev; 63 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 64 1.3 riastrad const struct intel_digital_connector_state *intel_conn_state = 65 1.3 riastrad const_container_of(state, struct intel_digital_connector_state, base); 66 1.1 riastrad 67 1.1 riastrad if (property == dev_priv->force_audio_property) 68 1.1 riastrad *val = intel_conn_state->force_audio; 69 1.1 riastrad else if (property == dev_priv->broadcast_rgb_property) 70 1.1 riastrad *val = intel_conn_state->broadcast_rgb; 71 1.1 riastrad else { 72 1.1 riastrad DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n", 73 1.1 riastrad property->base.id, property->name); 74 1.1 riastrad return -EINVAL; 75 1.1 riastrad } 76 1.1 riastrad 77 1.1 riastrad return 0; 78 1.1 riastrad } 79 1.1 riastrad 80 1.1 riastrad /** 81 1.1 riastrad * intel_digital_connector_atomic_set_property - hook for connector->atomic_set_property. 82 1.1 riastrad * @connector: Connector to set the property for. 83 1.1 riastrad * @state: Connector state to set the property on. 84 1.1 riastrad * @property: Property to set. 85 1.1 riastrad * @val: New value for the property. 86 1.1 riastrad * 87 1.1 riastrad * Sets the atomic property value for a digital connector. 88 1.1 riastrad */ 89 1.1 riastrad int intel_digital_connector_atomic_set_property(struct drm_connector *connector, 90 1.1 riastrad struct drm_connector_state *state, 91 1.1 riastrad struct drm_property *property, 92 1.1 riastrad u64 val) 93 1.1 riastrad { 94 1.1 riastrad struct drm_device *dev = connector->dev; 95 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 96 1.1 riastrad struct intel_digital_connector_state *intel_conn_state = 97 1.1 riastrad to_intel_digital_connector_state(state); 98 1.1 riastrad 99 1.1 riastrad if (property == dev_priv->force_audio_property) { 100 1.1 riastrad intel_conn_state->force_audio = val; 101 1.1 riastrad return 0; 102 1.1 riastrad } 103 1.1 riastrad 104 1.1 riastrad if (property == dev_priv->broadcast_rgb_property) { 105 1.1 riastrad intel_conn_state->broadcast_rgb = val; 106 1.1 riastrad return 0; 107 1.1 riastrad } 108 1.1 riastrad 109 1.1 riastrad DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n", 110 1.1 riastrad property->base.id, property->name); 111 1.1 riastrad return -EINVAL; 112 1.1 riastrad } 113 1.1 riastrad 114 1.1 riastrad static bool blob_equal(const struct drm_property_blob *a, 115 1.1 riastrad const struct drm_property_blob *b) 116 1.1 riastrad { 117 1.1 riastrad if (a && b) 118 1.1 riastrad return a->length == b->length && 119 1.1 riastrad !memcmp(a->data, b->data, a->length); 120 1.1 riastrad 121 1.1 riastrad return !a == !b; 122 1.1 riastrad } 123 1.1 riastrad 124 1.1 riastrad int intel_digital_connector_atomic_check(struct drm_connector *conn, 125 1.1 riastrad struct drm_atomic_state *state) 126 1.1 riastrad { 127 1.1 riastrad struct drm_connector_state *new_state = 128 1.1 riastrad drm_atomic_get_new_connector_state(state, conn); 129 1.1 riastrad struct intel_digital_connector_state *new_conn_state = 130 1.1 riastrad to_intel_digital_connector_state(new_state); 131 1.1 riastrad struct drm_connector_state *old_state = 132 1.1 riastrad drm_atomic_get_old_connector_state(state, conn); 133 1.1 riastrad struct intel_digital_connector_state *old_conn_state = 134 1.1 riastrad to_intel_digital_connector_state(old_state); 135 1.1 riastrad struct drm_crtc_state *crtc_state; 136 1.1 riastrad 137 1.1 riastrad intel_hdcp_atomic_check(conn, old_state, new_state); 138 1.1 riastrad intel_psr_atomic_check(conn, old_state, new_state); 139 1.1 riastrad 140 1.1 riastrad if (!new_state->crtc) 141 1.1 riastrad return 0; 142 1.1 riastrad 143 1.1 riastrad crtc_state = drm_atomic_get_new_crtc_state(state, new_state->crtc); 144 1.1 riastrad 145 1.1 riastrad /* 146 1.1 riastrad * These properties are handled by fastset, and might not end 147 1.1 riastrad * up in a modeset. 148 1.1 riastrad */ 149 1.1 riastrad if (new_conn_state->force_audio != old_conn_state->force_audio || 150 1.1 riastrad new_conn_state->broadcast_rgb != old_conn_state->broadcast_rgb || 151 1.1 riastrad new_conn_state->base.colorspace != old_conn_state->base.colorspace || 152 1.1 riastrad new_conn_state->base.picture_aspect_ratio != old_conn_state->base.picture_aspect_ratio || 153 1.1 riastrad new_conn_state->base.content_type != old_conn_state->base.content_type || 154 1.1 riastrad new_conn_state->base.scaling_mode != old_conn_state->base.scaling_mode || 155 1.1 riastrad !blob_equal(new_conn_state->base.hdr_output_metadata, 156 1.1 riastrad old_conn_state->base.hdr_output_metadata)) 157 1.1 riastrad crtc_state->mode_changed = true; 158 1.1 riastrad 159 1.1 riastrad return 0; 160 1.1 riastrad } 161 1.1 riastrad 162 1.1 riastrad /** 163 1.1 riastrad * intel_digital_connector_duplicate_state - duplicate connector state 164 1.1 riastrad * @connector: digital connector 165 1.1 riastrad * 166 1.1 riastrad * Allocates and returns a copy of the connector state (both common and 167 1.1 riastrad * digital connector specific) for the specified connector. 168 1.1 riastrad * 169 1.1 riastrad * Returns: The newly allocated connector state, or NULL on failure. 170 1.1 riastrad */ 171 1.1 riastrad struct drm_connector_state * 172 1.1 riastrad intel_digital_connector_duplicate_state(struct drm_connector *connector) 173 1.1 riastrad { 174 1.1 riastrad struct intel_digital_connector_state *state; 175 1.1 riastrad 176 1.1 riastrad state = kmemdup(connector->state, sizeof(*state), GFP_KERNEL); 177 1.1 riastrad if (!state) 178 1.1 riastrad return NULL; 179 1.1 riastrad 180 1.1 riastrad __drm_atomic_helper_connector_duplicate_state(connector, &state->base); 181 1.1 riastrad return &state->base; 182 1.1 riastrad } 183 1.1 riastrad 184 1.1 riastrad /** 185 1.1 riastrad * intel_connector_needs_modeset - check if connector needs a modeset 186 1.1 riastrad */ 187 1.1 riastrad bool 188 1.1 riastrad intel_connector_needs_modeset(struct intel_atomic_state *state, 189 1.1 riastrad struct drm_connector *connector) 190 1.1 riastrad { 191 1.1 riastrad const struct drm_connector_state *old_conn_state, *new_conn_state; 192 1.1 riastrad 193 1.1 riastrad old_conn_state = drm_atomic_get_old_connector_state(&state->base, connector); 194 1.1 riastrad new_conn_state = drm_atomic_get_new_connector_state(&state->base, connector); 195 1.1 riastrad 196 1.1 riastrad return old_conn_state->crtc != new_conn_state->crtc || 197 1.1 riastrad (new_conn_state->crtc && 198 1.1 riastrad drm_atomic_crtc_needs_modeset(drm_atomic_get_new_crtc_state(&state->base, 199 1.1 riastrad new_conn_state->crtc))); 200 1.1 riastrad } 201 1.1 riastrad 202 1.1 riastrad struct intel_digital_connector_state * 203 1.1 riastrad intel_atomic_get_digital_connector_state(struct intel_atomic_state *state, 204 1.1 riastrad struct intel_connector *connector) 205 1.1 riastrad { 206 1.1 riastrad struct drm_connector_state *conn_state; 207 1.1 riastrad 208 1.1 riastrad conn_state = drm_atomic_get_connector_state(&state->base, 209 1.1 riastrad &connector->base); 210 1.1 riastrad if (IS_ERR(conn_state)) 211 1.1 riastrad return ERR_CAST(conn_state); 212 1.1 riastrad 213 1.1 riastrad return to_intel_digital_connector_state(conn_state); 214 1.1 riastrad } 215 1.1 riastrad 216 1.1 riastrad /** 217 1.1 riastrad * intel_crtc_duplicate_state - duplicate crtc state 218 1.1 riastrad * @crtc: drm crtc 219 1.1 riastrad * 220 1.1 riastrad * Allocates and returns a copy of the crtc state (both common and 221 1.1 riastrad * Intel-specific) for the specified crtc. 222 1.1 riastrad * 223 1.1 riastrad * Returns: The newly allocated crtc state, or NULL on failure. 224 1.1 riastrad */ 225 1.1 riastrad struct drm_crtc_state * 226 1.1 riastrad intel_crtc_duplicate_state(struct drm_crtc *crtc) 227 1.1 riastrad { 228 1.1 riastrad const struct intel_crtc_state *old_crtc_state = to_intel_crtc_state(crtc->state); 229 1.1 riastrad struct intel_crtc_state *crtc_state; 230 1.1 riastrad 231 1.1 riastrad crtc_state = kmemdup(old_crtc_state, sizeof(*crtc_state), GFP_KERNEL); 232 1.1 riastrad if (!crtc_state) 233 1.1 riastrad return NULL; 234 1.1 riastrad 235 1.1 riastrad __drm_atomic_helper_crtc_duplicate_state(crtc, &crtc_state->uapi); 236 1.1 riastrad 237 1.1 riastrad /* copy color blobs */ 238 1.1 riastrad if (crtc_state->hw.degamma_lut) 239 1.1 riastrad drm_property_blob_get(crtc_state->hw.degamma_lut); 240 1.1 riastrad if (crtc_state->hw.ctm) 241 1.1 riastrad drm_property_blob_get(crtc_state->hw.ctm); 242 1.1 riastrad if (crtc_state->hw.gamma_lut) 243 1.1 riastrad drm_property_blob_get(crtc_state->hw.gamma_lut); 244 1.1 riastrad 245 1.1 riastrad crtc_state->update_pipe = false; 246 1.1 riastrad crtc_state->disable_lp_wm = false; 247 1.1 riastrad crtc_state->disable_cxsr = false; 248 1.1 riastrad crtc_state->update_wm_pre = false; 249 1.1 riastrad crtc_state->update_wm_post = false; 250 1.1 riastrad crtc_state->fifo_changed = false; 251 1.1 riastrad crtc_state->preload_luts = false; 252 1.1 riastrad crtc_state->wm.need_postvbl_update = false; 253 1.1 riastrad crtc_state->fb_bits = 0; 254 1.1 riastrad crtc_state->update_planes = 0; 255 1.1 riastrad 256 1.1 riastrad return &crtc_state->uapi; 257 1.1 riastrad } 258 1.1 riastrad 259 1.1 riastrad static void intel_crtc_put_color_blobs(struct intel_crtc_state *crtc_state) 260 1.1 riastrad { 261 1.1 riastrad drm_property_blob_put(crtc_state->hw.degamma_lut); 262 1.1 riastrad drm_property_blob_put(crtc_state->hw.gamma_lut); 263 1.1 riastrad drm_property_blob_put(crtc_state->hw.ctm); 264 1.1 riastrad } 265 1.1 riastrad 266 1.1 riastrad void intel_crtc_free_hw_state(struct intel_crtc_state *crtc_state) 267 1.1 riastrad { 268 1.1 riastrad intel_crtc_put_color_blobs(crtc_state); 269 1.1 riastrad } 270 1.1 riastrad 271 1.1 riastrad void intel_crtc_copy_color_blobs(struct intel_crtc_state *crtc_state) 272 1.1 riastrad { 273 1.1 riastrad drm_property_replace_blob(&crtc_state->hw.degamma_lut, 274 1.1 riastrad crtc_state->uapi.degamma_lut); 275 1.1 riastrad drm_property_replace_blob(&crtc_state->hw.gamma_lut, 276 1.1 riastrad crtc_state->uapi.gamma_lut); 277 1.1 riastrad drm_property_replace_blob(&crtc_state->hw.ctm, 278 1.1 riastrad crtc_state->uapi.ctm); 279 1.1 riastrad } 280 1.1 riastrad 281 1.1 riastrad /** 282 1.1 riastrad * intel_crtc_destroy_state - destroy crtc state 283 1.1 riastrad * @crtc: drm crtc 284 1.1 riastrad * @state: the state to destroy 285 1.1 riastrad * 286 1.1 riastrad * Destroys the crtc state (both common and Intel-specific) for the 287 1.1 riastrad * specified crtc. 288 1.1 riastrad */ 289 1.1 riastrad void 290 1.1 riastrad intel_crtc_destroy_state(struct drm_crtc *crtc, 291 1.1 riastrad struct drm_crtc_state *state) 292 1.1 riastrad { 293 1.1 riastrad struct intel_crtc_state *crtc_state = to_intel_crtc_state(state); 294 1.1 riastrad 295 1.1 riastrad __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi); 296 1.1 riastrad intel_crtc_free_hw_state(crtc_state); 297 1.1 riastrad kfree(crtc_state); 298 1.1 riastrad } 299 1.1 riastrad 300 1.1 riastrad static void intel_atomic_setup_scaler(struct intel_crtc_scaler_state *scaler_state, 301 1.1 riastrad int num_scalers_need, struct intel_crtc *intel_crtc, 302 1.1 riastrad const char *name, int idx, 303 1.1 riastrad struct intel_plane_state *plane_state, 304 1.1 riastrad int *scaler_id) 305 1.1 riastrad { 306 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); 307 1.1 riastrad int j; 308 1.1 riastrad u32 mode; 309 1.1 riastrad 310 1.1 riastrad if (*scaler_id < 0) { 311 1.1 riastrad /* find a free scaler */ 312 1.1 riastrad for (j = 0; j < intel_crtc->num_scalers; j++) { 313 1.1 riastrad if (scaler_state->scalers[j].in_use) 314 1.1 riastrad continue; 315 1.1 riastrad 316 1.1 riastrad *scaler_id = j; 317 1.1 riastrad scaler_state->scalers[*scaler_id].in_use = 1; 318 1.1 riastrad break; 319 1.1 riastrad } 320 1.1 riastrad } 321 1.1 riastrad 322 1.1 riastrad if (WARN(*scaler_id < 0, "Cannot find scaler for %s:%d\n", name, idx)) 323 1.1 riastrad return; 324 1.1 riastrad 325 1.1 riastrad /* set scaler mode */ 326 1.1 riastrad if (plane_state && plane_state->hw.fb && 327 1.1 riastrad plane_state->hw.fb->format->is_yuv && 328 1.1 riastrad plane_state->hw.fb->format->num_planes > 1) { 329 1.1 riastrad struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); 330 1.1 riastrad if (IS_GEN(dev_priv, 9) && 331 1.1 riastrad !IS_GEMINILAKE(dev_priv)) { 332 1.1 riastrad mode = SKL_PS_SCALER_MODE_NV12; 333 1.1 riastrad } else if (icl_is_hdr_plane(dev_priv, plane->id)) { 334 1.1 riastrad /* 335 1.1 riastrad * On gen11+'s HDR planes we only use the scaler for 336 1.1 riastrad * scaling. They have a dedicated chroma upsampler, so 337 1.1 riastrad * we don't need the scaler to upsample the UV plane. 338 1.1 riastrad */ 339 1.1 riastrad mode = PS_SCALER_MODE_NORMAL; 340 1.1 riastrad } else { 341 1.1 riastrad struct intel_plane *linked = 342 1.1 riastrad plane_state->planar_linked_plane; 343 1.1 riastrad 344 1.1 riastrad mode = PS_SCALER_MODE_PLANAR; 345 1.1 riastrad 346 1.1 riastrad if (linked) 347 1.1 riastrad mode |= PS_PLANE_Y_SEL(linked->id); 348 1.1 riastrad } 349 1.1 riastrad } else if (INTEL_GEN(dev_priv) > 9 || IS_GEMINILAKE(dev_priv)) { 350 1.1 riastrad mode = PS_SCALER_MODE_NORMAL; 351 1.1 riastrad } else if (num_scalers_need == 1 && intel_crtc->num_scalers > 1) { 352 1.1 riastrad /* 353 1.1 riastrad * when only 1 scaler is in use on a pipe with 2 scalers 354 1.1 riastrad * scaler 0 operates in high quality (HQ) mode. 355 1.1 riastrad * In this case use scaler 0 to take advantage of HQ mode 356 1.1 riastrad */ 357 1.1 riastrad scaler_state->scalers[*scaler_id].in_use = 0; 358 1.1 riastrad *scaler_id = 0; 359 1.1 riastrad scaler_state->scalers[0].in_use = 1; 360 1.1 riastrad mode = SKL_PS_SCALER_MODE_HQ; 361 1.1 riastrad } else { 362 1.1 riastrad mode = SKL_PS_SCALER_MODE_DYN; 363 1.1 riastrad } 364 1.1 riastrad 365 1.1 riastrad DRM_DEBUG_KMS("Attached scaler id %u.%u to %s:%d\n", 366 1.1 riastrad intel_crtc->pipe, *scaler_id, name, idx); 367 1.1 riastrad scaler_state->scalers[*scaler_id].mode = mode; 368 1.1 riastrad } 369 1.1 riastrad 370 1.1 riastrad /** 371 1.1 riastrad * intel_atomic_setup_scalers() - setup scalers for crtc per staged requests 372 1.1 riastrad * @dev_priv: i915 device 373 1.1 riastrad * @intel_crtc: intel crtc 374 1.1 riastrad * @crtc_state: incoming crtc_state to validate and setup scalers 375 1.1 riastrad * 376 1.1 riastrad * This function sets up scalers based on staged scaling requests for 377 1.1 riastrad * a @crtc and its planes. It is called from crtc level check path. If request 378 1.1 riastrad * is a supportable request, it attaches scalers to requested planes and crtc. 379 1.1 riastrad * 380 1.1 riastrad * This function takes into account the current scaler(s) in use by any planes 381 1.1 riastrad * not being part of this atomic state 382 1.1 riastrad * 383 1.1 riastrad * Returns: 384 1.1 riastrad * 0 - scalers were setup succesfully 385 1.1 riastrad * error code - otherwise 386 1.1 riastrad */ 387 1.1 riastrad int intel_atomic_setup_scalers(struct drm_i915_private *dev_priv, 388 1.1 riastrad struct intel_crtc *intel_crtc, 389 1.1 riastrad struct intel_crtc_state *crtc_state) 390 1.1 riastrad { 391 1.1 riastrad struct drm_plane *plane = NULL; 392 1.1 riastrad struct intel_plane *intel_plane; 393 1.1 riastrad struct intel_plane_state *plane_state = NULL; 394 1.1 riastrad struct intel_crtc_scaler_state *scaler_state = 395 1.1 riastrad &crtc_state->scaler_state; 396 1.1 riastrad struct drm_atomic_state *drm_state = crtc_state->uapi.state; 397 1.1 riastrad struct intel_atomic_state *intel_state = to_intel_atomic_state(drm_state); 398 1.1 riastrad int num_scalers_need; 399 1.1 riastrad int i; 400 1.1 riastrad 401 1.1 riastrad num_scalers_need = hweight32(scaler_state->scaler_users); 402 1.1 riastrad 403 1.1 riastrad /* 404 1.1 riastrad * High level flow: 405 1.1 riastrad * - staged scaler requests are already in scaler_state->scaler_users 406 1.1 riastrad * - check whether staged scaling requests can be supported 407 1.1 riastrad * - add planes using scalers that aren't in current transaction 408 1.1 riastrad * - assign scalers to requested users 409 1.1 riastrad * - as part of plane commit, scalers will be committed 410 1.1 riastrad * (i.e., either attached or detached) to respective planes in hw 411 1.1 riastrad * - as part of crtc_commit, scaler will be either attached or detached 412 1.1 riastrad * to crtc in hw 413 1.1 riastrad */ 414 1.1 riastrad 415 1.1 riastrad /* fail if required scalers > available scalers */ 416 1.1 riastrad if (num_scalers_need > intel_crtc->num_scalers){ 417 1.1 riastrad DRM_DEBUG_KMS("Too many scaling requests %d > %d\n", 418 1.1 riastrad num_scalers_need, intel_crtc->num_scalers); 419 1.1 riastrad return -EINVAL; 420 1.1 riastrad } 421 1.1 riastrad 422 1.1 riastrad /* walkthrough scaler_users bits and start assigning scalers */ 423 1.1 riastrad for (i = 0; i < sizeof(scaler_state->scaler_users) * 8; i++) { 424 1.1 riastrad int *scaler_id; 425 1.1 riastrad const char *name; 426 1.1 riastrad int idx; 427 1.1 riastrad 428 1.1 riastrad /* skip if scaler not required */ 429 1.5 riastrad if (!(scaler_state->scaler_users & (1 << i))) 430 1.1 riastrad continue; 431 1.1 riastrad 432 1.1 riastrad if (i == SKL_CRTC_INDEX) { 433 1.1 riastrad name = "CRTC"; 434 1.1 riastrad idx = intel_crtc->base.base.id; 435 1.1 riastrad 436 1.1 riastrad /* panel fitter case: assign as a crtc scaler */ 437 1.1 riastrad scaler_id = &scaler_state->scaler_id; 438 1.1 riastrad } else { 439 1.1 riastrad name = "PLANE"; 440 1.1 riastrad 441 1.1 riastrad /* plane scaler case: assign as a plane scaler */ 442 1.1 riastrad /* find the plane that set the bit as scaler_user */ 443 1.1 riastrad plane = drm_state->planes[i].ptr; 444 1.1 riastrad 445 1.1 riastrad /* 446 1.1 riastrad * to enable/disable hq mode, add planes that are using scaler 447 1.1 riastrad * into this transaction 448 1.1 riastrad */ 449 1.1 riastrad if (!plane) { 450 1.1 riastrad struct drm_plane_state *state; 451 1.1 riastrad 452 1.1 riastrad /* 453 1.1 riastrad * GLK+ scalers don't have a HQ mode so it 454 1.1 riastrad * isn't necessary to change between HQ and dyn mode 455 1.1 riastrad * on those platforms. 456 1.1 riastrad */ 457 1.1 riastrad if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) 458 1.1 riastrad continue; 459 1.1 riastrad 460 1.1 riastrad plane = drm_plane_from_index(&dev_priv->drm, i); 461 1.1 riastrad state = drm_atomic_get_plane_state(drm_state, plane); 462 1.1 riastrad if (IS_ERR(state)) { 463 1.1 riastrad DRM_DEBUG_KMS("Failed to add [PLANE:%d] to drm_state\n", 464 1.1 riastrad plane->base.id); 465 1.1 riastrad return PTR_ERR(state); 466 1.1 riastrad } 467 1.1 riastrad } 468 1.1 riastrad 469 1.1 riastrad intel_plane = to_intel_plane(plane); 470 1.1 riastrad idx = plane->base.id; 471 1.1 riastrad 472 1.1 riastrad /* plane on different crtc cannot be a scaler user of this crtc */ 473 1.1 riastrad if (WARN_ON(intel_plane->pipe != intel_crtc->pipe)) 474 1.1 riastrad continue; 475 1.1 riastrad 476 1.1 riastrad plane_state = intel_atomic_get_new_plane_state(intel_state, 477 1.1 riastrad intel_plane); 478 1.1 riastrad scaler_id = &plane_state->scaler_id; 479 1.1 riastrad } 480 1.1 riastrad 481 1.1 riastrad intel_atomic_setup_scaler(scaler_state, num_scalers_need, 482 1.1 riastrad intel_crtc, name, idx, 483 1.1 riastrad plane_state, scaler_id); 484 1.1 riastrad } 485 1.1 riastrad 486 1.1 riastrad return 0; 487 1.1 riastrad } 488 1.1 riastrad 489 1.1 riastrad struct drm_atomic_state * 490 1.1 riastrad intel_atomic_state_alloc(struct drm_device *dev) 491 1.1 riastrad { 492 1.1 riastrad struct intel_atomic_state *state = kzalloc(sizeof(*state), GFP_KERNEL); 493 1.1 riastrad 494 1.1 riastrad if (!state || drm_atomic_state_init(dev, &state->base) < 0) { 495 1.1 riastrad kfree(state); 496 1.1 riastrad return NULL; 497 1.1 riastrad } 498 1.1 riastrad 499 1.4 riastrad i915_sw_fence_init(&state->commit_ready, intel_atomic_commit_ready); 500 1.4 riastrad 501 1.1 riastrad return &state->base; 502 1.1 riastrad } 503 1.1 riastrad 504 1.1 riastrad void intel_atomic_state_clear(struct drm_atomic_state *s) 505 1.1 riastrad { 506 1.1 riastrad struct intel_atomic_state *state = to_intel_atomic_state(s); 507 1.1 riastrad drm_atomic_state_default_clear(&state->base); 508 1.1 riastrad state->dpll_set = state->modeset = false; 509 1.1 riastrad state->global_state_changed = false; 510 1.1 riastrad state->active_pipes = 0; 511 1.1 riastrad memset(&state->min_cdclk, 0, sizeof(state->min_cdclk)); 512 1.1 riastrad memset(&state->min_voltage_level, 0, sizeof(state->min_voltage_level)); 513 1.1 riastrad memset(&state->cdclk.logical, 0, sizeof(state->cdclk.logical)); 514 1.1 riastrad memset(&state->cdclk.actual, 0, sizeof(state->cdclk.actual)); 515 1.1 riastrad state->cdclk.pipe = INVALID_PIPE; 516 1.1 riastrad } 517 1.1 riastrad 518 1.1 riastrad struct intel_crtc_state * 519 1.1 riastrad intel_atomic_get_crtc_state(struct drm_atomic_state *state, 520 1.1 riastrad struct intel_crtc *crtc) 521 1.1 riastrad { 522 1.1 riastrad struct drm_crtc_state *crtc_state; 523 1.1 riastrad crtc_state = drm_atomic_get_crtc_state(state, &crtc->base); 524 1.1 riastrad if (IS_ERR(crtc_state)) 525 1.1 riastrad return ERR_CAST(crtc_state); 526 1.1 riastrad 527 1.1 riastrad return to_intel_crtc_state(crtc_state); 528 1.1 riastrad } 529 1.1 riastrad 530 1.1 riastrad int intel_atomic_lock_global_state(struct intel_atomic_state *state) 531 1.1 riastrad { 532 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(state->base.dev); 533 1.1 riastrad struct intel_crtc *crtc; 534 1.1 riastrad 535 1.1 riastrad state->global_state_changed = true; 536 1.1 riastrad 537 1.1 riastrad for_each_intel_crtc(&dev_priv->drm, crtc) { 538 1.1 riastrad int ret; 539 1.1 riastrad 540 1.1 riastrad ret = drm_modeset_lock(&crtc->base.mutex, 541 1.1 riastrad state->base.acquire_ctx); 542 1.1 riastrad if (ret) 543 1.1 riastrad return ret; 544 1.1 riastrad } 545 1.1 riastrad 546 1.1 riastrad return 0; 547 1.1 riastrad } 548 1.1 riastrad 549 1.1 riastrad int intel_atomic_serialize_global_state(struct intel_atomic_state *state) 550 1.1 riastrad { 551 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(state->base.dev); 552 1.1 riastrad struct intel_crtc *crtc; 553 1.1 riastrad 554 1.1 riastrad state->global_state_changed = true; 555 1.1 riastrad 556 1.1 riastrad for_each_intel_crtc(&dev_priv->drm, crtc) { 557 1.1 riastrad struct intel_crtc_state *crtc_state; 558 1.1 riastrad 559 1.1 riastrad crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 560 1.1 riastrad if (IS_ERR(crtc_state)) 561 1.1 riastrad return PTR_ERR(crtc_state); 562 1.1 riastrad } 563 1.1 riastrad 564 1.1 riastrad return 0; 565 1.1 riastrad } 566