Merge remote-tracking branch 'airlied/drm-next' into drm-intel-next-queued
[deliverable/linux.git] / drivers / gpu / drm / i915 / intel_atomic.c
CommitLineData
5ee67f1c
MR
1/*
2 * Copyright © 2015 Intel Corporation
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 (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
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.
22 */
23
24/**
25 * DOC: atomic modeset support
26 *
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.
30 */
31
32#include <drm/drmP.h>
33#include <drm/drm_atomic.h>
34#include <drm/drm_atomic_helper.h>
35#include <drm/drm_plane_helper.h>
36#include "intel_drv.h"
37
2545e4a6
MR
38/**
39 * intel_connector_atomic_get_property - fetch connector property value
40 * @connector: connector to fetch property for
41 * @state: state containing the property value
42 * @property: property to look up
43 * @val: pointer to write property value into
44 *
45 * The DRM core does not store shadow copies of properties for
46 * atomic-capable drivers. This entrypoint is used to fetch
47 * the current value of a driver-specific connector property.
48 */
49int
50intel_connector_atomic_get_property(struct drm_connector *connector,
51 const struct drm_connector_state *state,
52 struct drm_property *property,
53 uint64_t *val)
54{
55 int i;
56
57 /*
58 * TODO: We only have atomic modeset for planes at the moment, so the
59 * crtc/connector code isn't quite ready yet. Until it's ready,
60 * continue to look up all property values in the DRM's shadow copy
61 * in obj->properties->values[].
62 *
63 * When the crtc/connector state work matures, this function should
64 * be updated to read the values out of the state structure instead.
65 */
66 for (i = 0; i < connector->base.properties->count; i++) {
67 if (connector->base.properties->properties[i] == property) {
68 *val = connector->base.properties->values[i];
69 return 0;
70 }
71 }
72
73 return -EINVAL;
74}
1356837e
MR
75
76/*
77 * intel_crtc_duplicate_state - duplicate crtc state
78 * @crtc: drm crtc
79 *
80 * Allocates and returns a copy of the crtc state (both common and
81 * Intel-specific) for the specified crtc.
82 *
83 * Returns: The newly allocated crtc state, or NULL on failure.
84 */
85struct drm_crtc_state *
86intel_crtc_duplicate_state(struct drm_crtc *crtc)
87{
a91572f3 88 struct intel_crtc_state *crtc_state;
1356837e 89
f2a066f3 90 crtc_state = kmemdup(crtc->state, sizeof(*crtc_state), GFP_KERNEL);
f0c60574
ACO
91 if (!crtc_state)
92 return NULL;
93
94 __drm_atomic_helper_crtc_duplicate_state(crtc, &crtc_state->base);
95
bfd16b2a 96 crtc_state->update_pipe = false;
d21fbe87 97 crtc_state->disable_lp_wm = false;
ab1d3a0e 98 crtc_state->disable_cxsr = false;
caed361d
VS
99 crtc_state->update_wm_pre = false;
100 crtc_state->update_wm_post = false;
e8861675 101 crtc_state->fb_changed = false;
ed4a6a7c 102 crtc_state->wm.need_postvbl_update = false;
bfd16b2a 103
a91572f3 104 return &crtc_state->base;
1356837e
MR
105}
106
107/**
108 * intel_crtc_destroy_state - destroy crtc state
109 * @crtc: drm crtc
110 *
111 * Destroys the crtc state (both common and Intel-specific) for the
112 * specified crtc.
113 */
114void
115intel_crtc_destroy_state(struct drm_crtc *crtc,
116 struct drm_crtc_state *state)
117{
118 drm_atomic_helper_crtc_destroy_state(crtc, state);
119}
d03c93d4
CK
120
121/**
122 * intel_atomic_setup_scalers() - setup scalers for crtc per staged requests
123 * @dev: DRM device
124 * @crtc: intel crtc
125 * @crtc_state: incoming crtc_state to validate and setup scalers
126 *
127 * This function sets up scalers based on staged scaling requests for
128 * a @crtc and its planes. It is called from crtc level check path. If request
129 * is a supportable request, it attaches scalers to requested planes and crtc.
130 *
131 * This function takes into account the current scaler(s) in use by any planes
132 * not being part of this atomic state
133 *
134 * Returns:
135 * 0 - scalers were setup succesfully
136 * error code - otherwise
137 */
138int intel_atomic_setup_scalers(struct drm_device *dev,
139 struct intel_crtc *intel_crtc,
140 struct intel_crtc_state *crtc_state)
141{
142 struct drm_plane *plane = NULL;
143 struct intel_plane *intel_plane;
144 struct intel_plane_state *plane_state = NULL;
e435d6e5
ML
145 struct intel_crtc_scaler_state *scaler_state =
146 &crtc_state->scaler_state;
147 struct drm_atomic_state *drm_state = crtc_state->base.state;
d03c93d4
CK
148 int num_scalers_need;
149 int i, j;
150
d03c93d4 151 num_scalers_need = hweight32(scaler_state->scaler_users);
d03c93d4
CK
152
153 /*
154 * High level flow:
155 * - staged scaler requests are already in scaler_state->scaler_users
156 * - check whether staged scaling requests can be supported
157 * - add planes using scalers that aren't in current transaction
158 * - assign scalers to requested users
159 * - as part of plane commit, scalers will be committed
160 * (i.e., either attached or detached) to respective planes in hw
161 * - as part of crtc_commit, scaler will be either attached or detached
162 * to crtc in hw
163 */
164
165 /* fail if required scalers > available scalers */
166 if (num_scalers_need > intel_crtc->num_scalers){
167 DRM_DEBUG_KMS("Too many scaling requests %d > %d\n",
168 num_scalers_need, intel_crtc->num_scalers);
169 return -EINVAL;
170 }
171
172 /* walkthrough scaler_users bits and start assigning scalers */
173 for (i = 0; i < sizeof(scaler_state->scaler_users) * 8; i++) {
174 int *scaler_id;
133b0d12
ML
175 const char *name;
176 int idx;
d03c93d4
CK
177
178 /* skip if scaler not required */
179 if (!(scaler_state->scaler_users & (1 << i)))
180 continue;
181
182 if (i == SKL_CRTC_INDEX) {
133b0d12
ML
183 name = "CRTC";
184 idx = intel_crtc->base.base.id;
185
d03c93d4
CK
186 /* panel fitter case: assign as a crtc scaler */
187 scaler_id = &scaler_state->scaler_id;
188 } else {
133b0d12 189 name = "PLANE";
133b0d12 190
d03c93d4
CK
191 /* plane scaler case: assign as a plane scaler */
192 /* find the plane that set the bit as scaler_user */
193 plane = drm_state->planes[i];
194
195 /*
196 * to enable/disable hq mode, add planes that are using scaler
197 * into this transaction
198 */
199 if (!plane) {
200 struct drm_plane_state *state;
201 plane = drm_plane_from_index(dev, i);
202 state = drm_atomic_get_plane_state(drm_state, plane);
203 if (IS_ERR(state)) {
204 DRM_DEBUG_KMS("Failed to add [PLANE:%d] to drm_state\n",
205 plane->base.id);
206 return PTR_ERR(state);
207 }
cf5a15be
ML
208
209 /*
210 * the plane is added after plane checks are run,
211 * but since this plane is unchanged just do the
212 * minimum required validation.
213 */
cf5a15be 214 crtc_state->base.planes_changed = true;
d03c93d4
CK
215 }
216
217 intel_plane = to_intel_plane(plane);
c07a2d11 218 idx = plane->base.id;
d03c93d4
CK
219
220 /* plane on different crtc cannot be a scaler user of this crtc */
221 if (WARN_ON(intel_plane->pipe != intel_crtc->pipe)) {
222 continue;
223 }
224
225 plane_state = to_intel_plane_state(drm_state->plane_states[i]);
226 scaler_id = &plane_state->scaler_id;
227 }
228
229 if (*scaler_id < 0) {
230 /* find a free scaler */
231 for (j = 0; j < intel_crtc->num_scalers; j++) {
232 if (!scaler_state->scalers[j].in_use) {
233 scaler_state->scalers[j].in_use = 1;
133b0d12 234 *scaler_id = j;
d03c93d4 235 DRM_DEBUG_KMS("Attached scaler id %u.%u to %s:%d\n",
133b0d12 236 intel_crtc->pipe, *scaler_id, name, idx);
d03c93d4
CK
237 break;
238 }
239 }
240 }
241
242 if (WARN_ON(*scaler_id < 0)) {
133b0d12 243 DRM_DEBUG_KMS("Cannot find scaler for %s:%d\n", name, idx);
d03c93d4
CK
244 continue;
245 }
246
247 /* set scaler mode */
248 if (num_scalers_need == 1 && intel_crtc->pipe != PIPE_C) {
249 /*
250 * when only 1 scaler is in use on either pipe A or B,
251 * scaler 0 operates in high quality (HQ) mode.
252 * In this case use scaler 0 to take advantage of HQ mode
253 */
254 *scaler_id = 0;
255 scaler_state->scalers[0].in_use = 1;
256 scaler_state->scalers[0].mode = PS_SCALER_MODE_HQ;
257 scaler_state->scalers[1].in_use = 0;
258 } else {
259 scaler_state->scalers[*scaler_id].mode = PS_SCALER_MODE_DYN;
260 }
261 }
262
263 return 0;
264}
de419ab6 265
f7217905 266static void
de419ab6
ML
267intel_atomic_duplicate_dpll_state(struct drm_i915_private *dev_priv,
268 struct intel_shared_dpll_config *shared_dpll)
269{
270 enum intel_dpll_id i;
271
272 /* Copy shared dpll state */
273 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
274 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
275
276 shared_dpll[i] = pll->config;
277 }
278}
279
280struct intel_shared_dpll_config *
281intel_atomic_get_shared_dpll_state(struct drm_atomic_state *s)
282{
283 struct intel_atomic_state *state = to_intel_atomic_state(s);
284
285 WARN_ON(!drm_modeset_is_locked(&s->dev->mode_config.connection_mutex));
286
287 if (!state->dpll_set) {
288 state->dpll_set = true;
289
290 intel_atomic_duplicate_dpll_state(to_i915(s->dev),
291 state->shared_dpll);
292 }
293
294 return state->shared_dpll;
295}
296
297struct drm_atomic_state *
298intel_atomic_state_alloc(struct drm_device *dev)
299{
300 struct intel_atomic_state *state = kzalloc(sizeof(*state), GFP_KERNEL);
301
302 if (!state || drm_atomic_state_init(dev, &state->base) < 0) {
303 kfree(state);
304 return NULL;
305 }
306
307 return &state->base;
308}
309
310void intel_atomic_state_clear(struct drm_atomic_state *s)
311{
312 struct intel_atomic_state *state = to_intel_atomic_state(s);
313 drm_atomic_state_default_clear(&state->base);
565602d7 314 state->dpll_set = state->modeset = false;
de419ab6 315}
This page took 0.584311 seconds and 5 git commands to generate.