2 * Copyright © 2015 Intel Corporation
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:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 * DOC: atomic modeset support
27 * The functions here implement the state management and hardware programming
28 * dispatch required by the atomic modeset infrastructure.
29 * See intel_atomic_plane.c for the plane-specific atomic functionality.
32 #include <drm/drm_atomic.h>
33 #include <drm/drm_atomic_helper.h>
34 #include <drm/drm_fourcc.h>
38 #include "intel_atomic.h"
39 #include "intel_cdclk.h"
40 #include "intel_display_types.h"
41 #include "intel_global_state.h"
42 #include "intel_hdcp.h"
43 #include "intel_psr.h"
45 #include "skl_universal_plane.h"
48 * intel_digital_connector_atomic_get_property - hook for connector->atomic_get_property.
49 * @connector: Connector to get the property for.
50 * @state: Connector state to retrieve the property from.
51 * @property: Property to retrieve.
52 * @val: Return value for the property.
54 * Returns the atomic property value for a digital connector.
56 int intel_digital_connector_atomic_get_property(struct drm_connector
*connector
,
57 const struct drm_connector_state
*state
,
58 struct drm_property
*property
,
61 struct drm_device
*dev
= connector
->dev
;
62 struct drm_i915_private
*dev_priv
= to_i915(dev
);
63 struct intel_digital_connector_state
*intel_conn_state
=
64 to_intel_digital_connector_state(state
);
66 if (property
== dev_priv
->display
.properties
.force_audio
)
67 *val
= intel_conn_state
->force_audio
;
68 else if (property
== dev_priv
->display
.properties
.broadcast_rgb
)
69 *val
= intel_conn_state
->broadcast_rgb
;
71 drm_dbg_atomic(&dev_priv
->drm
,
72 "Unknown property [PROP:%d:%s]\n",
73 property
->base
.id
, property
->name
);
81 * intel_digital_connector_atomic_set_property - hook for connector->atomic_set_property.
82 * @connector: Connector to set the property for.
83 * @state: Connector state to set the property on.
84 * @property: Property to set.
85 * @val: New value for the property.
87 * Sets the atomic property value for a digital connector.
89 int intel_digital_connector_atomic_set_property(struct drm_connector
*connector
,
90 struct drm_connector_state
*state
,
91 struct drm_property
*property
,
94 struct drm_device
*dev
= connector
->dev
;
95 struct drm_i915_private
*dev_priv
= to_i915(dev
);
96 struct intel_digital_connector_state
*intel_conn_state
=
97 to_intel_digital_connector_state(state
);
99 if (property
== dev_priv
->display
.properties
.force_audio
) {
100 intel_conn_state
->force_audio
= val
;
104 if (property
== dev_priv
->display
.properties
.broadcast_rgb
) {
105 intel_conn_state
->broadcast_rgb
= val
;
109 drm_dbg_atomic(&dev_priv
->drm
, "Unknown property [PROP:%d:%s]\n",
110 property
->base
.id
, property
->name
);
114 int intel_digital_connector_atomic_check(struct drm_connector
*conn
,
115 struct drm_atomic_state
*state
)
117 struct drm_connector_state
*new_state
=
118 drm_atomic_get_new_connector_state(state
, conn
);
119 struct intel_digital_connector_state
*new_conn_state
=
120 to_intel_digital_connector_state(new_state
);
121 struct drm_connector_state
*old_state
=
122 drm_atomic_get_old_connector_state(state
, conn
);
123 struct intel_digital_connector_state
*old_conn_state
=
124 to_intel_digital_connector_state(old_state
);
125 struct drm_crtc_state
*crtc_state
;
127 intel_hdcp_atomic_check(conn
, old_state
, new_state
);
129 if (!new_state
->crtc
)
132 crtc_state
= drm_atomic_get_new_crtc_state(state
, new_state
->crtc
);
135 * These properties are handled by fastset, and might not end
138 if (new_conn_state
->force_audio
!= old_conn_state
->force_audio
||
139 new_conn_state
->broadcast_rgb
!= old_conn_state
->broadcast_rgb
||
140 new_conn_state
->base
.colorspace
!= old_conn_state
->base
.colorspace
||
141 new_conn_state
->base
.picture_aspect_ratio
!= old_conn_state
->base
.picture_aspect_ratio
||
142 new_conn_state
->base
.content_type
!= old_conn_state
->base
.content_type
||
143 new_conn_state
->base
.scaling_mode
!= old_conn_state
->base
.scaling_mode
||
144 new_conn_state
->base
.privacy_screen_sw_state
!= old_conn_state
->base
.privacy_screen_sw_state
||
145 !drm_connector_atomic_hdr_metadata_equal(old_state
, new_state
))
146 crtc_state
->mode_changed
= true;
152 * intel_digital_connector_duplicate_state - duplicate connector state
153 * @connector: digital connector
155 * Allocates and returns a copy of the connector state (both common and
156 * digital connector specific) for the specified connector.
158 * Returns: The newly allocated connector state, or NULL on failure.
160 struct drm_connector_state
*
161 intel_digital_connector_duplicate_state(struct drm_connector
*connector
)
163 struct intel_digital_connector_state
*state
;
165 state
= kmemdup(connector
->state
, sizeof(*state
), GFP_KERNEL
);
169 __drm_atomic_helper_connector_duplicate_state(connector
, &state
->base
);
174 * intel_connector_needs_modeset - check if connector needs a modeset
175 * @state: the atomic state corresponding to this modeset
176 * @connector: the connector
179 intel_connector_needs_modeset(struct intel_atomic_state
*state
,
180 struct drm_connector
*connector
)
182 const struct drm_connector_state
*old_conn_state
, *new_conn_state
;
184 old_conn_state
= drm_atomic_get_old_connector_state(&state
->base
, connector
);
185 new_conn_state
= drm_atomic_get_new_connector_state(&state
->base
, connector
);
187 return old_conn_state
->crtc
!= new_conn_state
->crtc
||
188 (new_conn_state
->crtc
&&
189 drm_atomic_crtc_needs_modeset(drm_atomic_get_new_crtc_state(&state
->base
,
190 new_conn_state
->crtc
)));
194 * intel_any_crtc_needs_modeset - check if any CRTC needs a modeset
195 * @state: the atomic state corresponding to this modeset
197 * Returns true if any CRTC in @state needs a modeset.
199 bool intel_any_crtc_needs_modeset(struct intel_atomic_state
*state
)
201 struct intel_crtc
*crtc
;
202 struct intel_crtc_state
*crtc_state
;
205 for_each_new_intel_crtc_in_state(state
, crtc
, crtc_state
, i
) {
206 if (intel_crtc_needs_modeset(crtc_state
))
213 struct intel_digital_connector_state
*
214 intel_atomic_get_digital_connector_state(struct intel_atomic_state
*state
,
215 struct intel_connector
*connector
)
217 struct drm_connector_state
*conn_state
;
219 conn_state
= drm_atomic_get_connector_state(&state
->base
,
221 if (IS_ERR(conn_state
))
222 return ERR_CAST(conn_state
);
224 return to_intel_digital_connector_state(conn_state
);
228 * intel_crtc_duplicate_state - duplicate crtc state
231 * Allocates and returns a copy of the crtc state (both common and
232 * Intel-specific) for the specified crtc.
234 * Returns: The newly allocated crtc state, or NULL on failure.
236 struct drm_crtc_state
*
237 intel_crtc_duplicate_state(struct drm_crtc
*crtc
)
239 const struct intel_crtc_state
*old_crtc_state
= to_intel_crtc_state(crtc
->state
);
240 struct intel_crtc_state
*crtc_state
;
242 crtc_state
= kmemdup(old_crtc_state
, sizeof(*crtc_state
), GFP_KERNEL
);
246 __drm_atomic_helper_crtc_duplicate_state(crtc
, &crtc_state
->uapi
);
248 /* copy color blobs */
249 if (crtc_state
->hw
.degamma_lut
)
250 drm_property_blob_get(crtc_state
->hw
.degamma_lut
);
251 if (crtc_state
->hw
.ctm
)
252 drm_property_blob_get(crtc_state
->hw
.ctm
);
253 if (crtc_state
->hw
.gamma_lut
)
254 drm_property_blob_get(crtc_state
->hw
.gamma_lut
);
256 if (crtc_state
->pre_csc_lut
)
257 drm_property_blob_get(crtc_state
->pre_csc_lut
);
258 if (crtc_state
->post_csc_lut
)
259 drm_property_blob_get(crtc_state
->post_csc_lut
);
261 crtc_state
->update_pipe
= false;
262 crtc_state
->update_m_n
= false;
263 crtc_state
->update_lrr
= false;
264 crtc_state
->disable_lp_wm
= false;
265 crtc_state
->disable_cxsr
= false;
266 crtc_state
->update_wm_pre
= false;
267 crtc_state
->update_wm_post
= false;
268 crtc_state
->fifo_changed
= false;
269 crtc_state
->preload_luts
= false;
270 crtc_state
->wm
.need_postvbl_update
= false;
271 crtc_state
->do_async_flip
= false;
272 crtc_state
->fb_bits
= 0;
273 crtc_state
->update_planes
= 0;
274 crtc_state
->dsb
= NULL
;
276 return &crtc_state
->uapi
;
279 static void intel_crtc_put_color_blobs(struct intel_crtc_state
*crtc_state
)
281 drm_property_blob_put(crtc_state
->hw
.degamma_lut
);
282 drm_property_blob_put(crtc_state
->hw
.gamma_lut
);
283 drm_property_blob_put(crtc_state
->hw
.ctm
);
285 drm_property_blob_put(crtc_state
->pre_csc_lut
);
286 drm_property_blob_put(crtc_state
->post_csc_lut
);
289 void intel_crtc_free_hw_state(struct intel_crtc_state
*crtc_state
)
291 intel_crtc_put_color_blobs(crtc_state
);
295 * intel_crtc_destroy_state - destroy crtc state
297 * @state: the state to destroy
299 * Destroys the crtc state (both common and Intel-specific) for the
303 intel_crtc_destroy_state(struct drm_crtc
*crtc
,
304 struct drm_crtc_state
*state
)
306 struct intel_crtc_state
*crtc_state
= to_intel_crtc_state(state
);
308 drm_WARN_ON(crtc
->dev
, crtc_state
->dsb
);
310 __drm_atomic_helper_crtc_destroy_state(&crtc_state
->uapi
);
311 intel_crtc_free_hw_state(crtc_state
);
315 struct drm_atomic_state
*
316 intel_atomic_state_alloc(struct drm_device
*dev
)
318 struct intel_atomic_state
*state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
320 if (!state
|| drm_atomic_state_init(dev
, &state
->base
) < 0) {
328 void intel_atomic_state_free(struct drm_atomic_state
*_state
)
330 struct intel_atomic_state
*state
= to_intel_atomic_state(_state
);
332 drm_atomic_state_default_release(&state
->base
);
333 kfree(state
->global_objs
);
337 void intel_atomic_state_clear(struct drm_atomic_state
*s
)
339 struct intel_atomic_state
*state
= to_intel_atomic_state(s
);
341 drm_atomic_state_default_clear(&state
->base
);
342 intel_atomic_clear_global_state(state
);
344 /* state->internal not reset on purpose */
346 state
->dpll_set
= state
->modeset
= false;
349 struct intel_crtc_state
*
350 intel_atomic_get_crtc_state(struct drm_atomic_state
*state
,
351 struct intel_crtc
*crtc
)
353 struct drm_crtc_state
*crtc_state
;
354 crtc_state
= drm_atomic_get_crtc_state(state
, &crtc
->base
);
355 if (IS_ERR(crtc_state
))
356 return ERR_CAST(crtc_state
);
358 return to_intel_crtc_state(crtc_state
);