Revert "drm/i915: Make intel_display_suspend atomic, v2."
[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
38
39/**
40 * intel_atomic_check - validate state object
41 * @dev: drm device
42 * @state: state to validate
43 */
44int intel_atomic_check(struct drm_device *dev,
45 struct drm_atomic_state *state)
46{
47 int nplanes = dev->mode_config.num_total_plane;
48 int ncrtcs = dev->mode_config.num_crtc;
49 int nconnectors = dev->mode_config.num_connector;
50 enum pipe nuclear_pipe = INVALID_PIPE;
e04fa803
CK
51 struct intel_crtc *nuclear_crtc = NULL;
52 struct intel_crtc_state *crtc_state = NULL;
5ee67f1c
MR
53 int ret;
54 int i;
55 bool not_nuclear = false;
56
57 /*
58 * FIXME: At the moment, we only support "nuclear pageflip" on a
59 * single CRTC. Cross-crtc updates will be added later.
60 */
61 for (i = 0; i < nplanes; i++) {
62 struct intel_plane *plane = to_intel_plane(state->planes[i]);
63 if (!plane)
64 continue;
65
66 if (nuclear_pipe == INVALID_PIPE) {
67 nuclear_pipe = plane->pipe;
68 } else if (nuclear_pipe != plane->pipe) {
69 DRM_DEBUG_KMS("i915 only support atomic plane operations on a single CRTC at the moment\n");
70 return -EINVAL;
71 }
72 }
73
74 /*
75 * FIXME: We only handle planes for now; make sure there are no CRTC's
76 * or connectors involved.
77 */
78 state->allow_modeset = false;
79 for (i = 0; i < ncrtcs; i++) {
80 struct intel_crtc *crtc = to_intel_crtc(state->crtcs[i]);
f1e2daea
MR
81 if (crtc)
82 memset(&crtc->atomic, 0, sizeof(crtc->atomic));
5ee67f1c
MR
83 if (crtc && crtc->pipe != nuclear_pipe)
84 not_nuclear = true;
e04fa803
CK
85 if (crtc && crtc->pipe == nuclear_pipe) {
86 nuclear_crtc = crtc;
87 crtc_state = to_intel_crtc_state(state->crtc_states[i]);
88 }
5ee67f1c
MR
89 }
90 for (i = 0; i < nconnectors; i++)
91 if (state->connectors[i] != NULL)
92 not_nuclear = true;
93
94 if (not_nuclear) {
95 DRM_DEBUG_KMS("i915 only supports atomic plane operations at the moment\n");
96 return -EINVAL;
97 }
98
99 ret = drm_atomic_helper_check_planes(dev, state);
100 if (ret)
101 return ret;
102
e04fa803
CK
103 /* FIXME: move to crtc atomic check function once it is ready */
104 ret = intel_atomic_setup_scalers(dev, nuclear_crtc, crtc_state);
105 if (ret)
106 return ret;
107
5ee67f1c
MR
108 return ret;
109}
110
111
112/**
113 * intel_atomic_commit - commit validated state object
114 * @dev: DRM device
115 * @state: the top-level driver state object
116 * @async: asynchronous commit
117 *
118 * This function commits a top-level state object that has been validated
119 * with drm_atomic_helper_check().
120 *
121 * FIXME: Atomic modeset support for i915 is not yet complete. At the moment
122 * we can only handle plane-related operations and do not yet support
123 * asynchronous commit.
124 *
125 * RETURNS
126 * Zero for success or -errno.
127 */
128int intel_atomic_commit(struct drm_device *dev,
129 struct drm_atomic_state *state,
130 bool async)
131{
61c05498
ML
132 struct drm_crtc_state *crtc_state;
133 struct drm_crtc *crtc;
5ee67f1c
MR
134 int ret;
135 int i;
136
137 if (async) {
138 DRM_DEBUG_KMS("i915 does not yet support async commit\n");
139 return -EINVAL;
140 }
141
142 ret = drm_atomic_helper_prepare_planes(dev, state);
143 if (ret)
144 return ret;
145
146 /* Point of no return */
61c05498
ML
147 drm_atomic_helper_swap_state(dev, state);
148
149 for_each_crtc_in_state(state, crtc, crtc_state, i) {
150 to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state);
151
152 if (INTEL_INFO(dev)->gen >= 9)
153 skl_detach_scalers(to_intel_crtc(crtc));
5ac1c4bc
ML
154
155 drm_atomic_helper_commit_planes_on_crtc(crtc_state);
61c05498 156 }
5ee67f1c 157
5ac1c4bc 158 /* FIXME: This function should eventually call __intel_set_mode when needed */
61c05498 159
5ee67f1c
MR
160 drm_atomic_helper_wait_for_vblanks(dev, state);
161 drm_atomic_helper_cleanup_planes(dev, state);
162 drm_atomic_state_free(state);
163
164 return 0;
165}
2545e4a6
MR
166
167/**
168 * intel_connector_atomic_get_property - fetch connector property value
169 * @connector: connector to fetch property for
170 * @state: state containing the property value
171 * @property: property to look up
172 * @val: pointer to write property value into
173 *
174 * The DRM core does not store shadow copies of properties for
175 * atomic-capable drivers. This entrypoint is used to fetch
176 * the current value of a driver-specific connector property.
177 */
178int
179intel_connector_atomic_get_property(struct drm_connector *connector,
180 const struct drm_connector_state *state,
181 struct drm_property *property,
182 uint64_t *val)
183{
184 int i;
185
186 /*
187 * TODO: We only have atomic modeset for planes at the moment, so the
188 * crtc/connector code isn't quite ready yet. Until it's ready,
189 * continue to look up all property values in the DRM's shadow copy
190 * in obj->properties->values[].
191 *
192 * When the crtc/connector state work matures, this function should
193 * be updated to read the values out of the state structure instead.
194 */
195 for (i = 0; i < connector->base.properties->count; i++) {
196 if (connector->base.properties->properties[i] == property) {
197 *val = connector->base.properties->values[i];
198 return 0;
199 }
200 }
201
202 return -EINVAL;
203}
1356837e
MR
204
205/*
206 * intel_crtc_duplicate_state - duplicate crtc state
207 * @crtc: drm crtc
208 *
209 * Allocates and returns a copy of the crtc state (both common and
210 * Intel-specific) for the specified crtc.
211 *
212 * Returns: The newly allocated crtc state, or NULL on failure.
213 */
214struct drm_crtc_state *
215intel_crtc_duplicate_state(struct drm_crtc *crtc)
216{
217 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
a91572f3 218 struct intel_crtc_state *crtc_state;
1356837e
MR
219
220 if (WARN_ON(!intel_crtc->config))
a91572f3
ACO
221 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
222 else
223 crtc_state = kmemdup(intel_crtc->config,
224 sizeof(*intel_crtc->config), GFP_KERNEL);
1356837e 225
f0c60574
ACO
226 if (!crtc_state)
227 return NULL;
228
229 __drm_atomic_helper_crtc_duplicate_state(crtc, &crtc_state->base);
230
231 crtc_state->base.crtc = crtc;
a91572f3
ACO
232
233 return &crtc_state->base;
1356837e
MR
234}
235
236/**
237 * intel_crtc_destroy_state - destroy crtc state
238 * @crtc: drm crtc
239 *
240 * Destroys the crtc state (both common and Intel-specific) for the
241 * specified crtc.
242 */
243void
244intel_crtc_destroy_state(struct drm_crtc *crtc,
245 struct drm_crtc_state *state)
246{
247 drm_atomic_helper_crtc_destroy_state(crtc, state);
248}
d03c93d4
CK
249
250/**
251 * intel_atomic_setup_scalers() - setup scalers for crtc per staged requests
252 * @dev: DRM device
253 * @crtc: intel crtc
254 * @crtc_state: incoming crtc_state to validate and setup scalers
255 *
256 * This function sets up scalers based on staged scaling requests for
257 * a @crtc and its planes. It is called from crtc level check path. If request
258 * is a supportable request, it attaches scalers to requested planes and crtc.
259 *
260 * This function takes into account the current scaler(s) in use by any planes
261 * not being part of this atomic state
262 *
263 * Returns:
264 * 0 - scalers were setup succesfully
265 * error code - otherwise
266 */
267int intel_atomic_setup_scalers(struct drm_device *dev,
268 struct intel_crtc *intel_crtc,
269 struct intel_crtc_state *crtc_state)
270{
271 struct drm_plane *plane = NULL;
272 struct intel_plane *intel_plane;
273 struct intel_plane_state *plane_state = NULL;
274 struct intel_crtc_scaler_state *scaler_state;
275 struct drm_atomic_state *drm_state;
276 int num_scalers_need;
277 int i, j;
278
279 if (INTEL_INFO(dev)->gen < 9 || !intel_crtc || !crtc_state)
280 return 0;
281
282 scaler_state = &crtc_state->scaler_state;
283 drm_state = crtc_state->base.state;
284
285 num_scalers_need = hweight32(scaler_state->scaler_users);
286 DRM_DEBUG_KMS("crtc_state = %p need = %d avail = %d scaler_users = 0x%x\n",
287 crtc_state, num_scalers_need, intel_crtc->num_scalers,
288 scaler_state->scaler_users);
289
290 /*
291 * High level flow:
292 * - staged scaler requests are already in scaler_state->scaler_users
293 * - check whether staged scaling requests can be supported
294 * - add planes using scalers that aren't in current transaction
295 * - assign scalers to requested users
296 * - as part of plane commit, scalers will be committed
297 * (i.e., either attached or detached) to respective planes in hw
298 * - as part of crtc_commit, scaler will be either attached or detached
299 * to crtc in hw
300 */
301
302 /* fail if required scalers > available scalers */
303 if (num_scalers_need > intel_crtc->num_scalers){
304 DRM_DEBUG_KMS("Too many scaling requests %d > %d\n",
305 num_scalers_need, intel_crtc->num_scalers);
306 return -EINVAL;
307 }
308
309 /* walkthrough scaler_users bits and start assigning scalers */
310 for (i = 0; i < sizeof(scaler_state->scaler_users) * 8; i++) {
311 int *scaler_id;
312
313 /* skip if scaler not required */
314 if (!(scaler_state->scaler_users & (1 << i)))
315 continue;
316
317 if (i == SKL_CRTC_INDEX) {
318 /* panel fitter case: assign as a crtc scaler */
319 scaler_id = &scaler_state->scaler_id;
320 } else {
321 if (!drm_state)
322 continue;
323
324 /* plane scaler case: assign as a plane scaler */
325 /* find the plane that set the bit as scaler_user */
326 plane = drm_state->planes[i];
327
328 /*
329 * to enable/disable hq mode, add planes that are using scaler
330 * into this transaction
331 */
332 if (!plane) {
333 struct drm_plane_state *state;
334 plane = drm_plane_from_index(dev, i);
335 state = drm_atomic_get_plane_state(drm_state, plane);
336 if (IS_ERR(state)) {
337 DRM_DEBUG_KMS("Failed to add [PLANE:%d] to drm_state\n",
338 plane->base.id);
339 return PTR_ERR(state);
340 }
341 }
342
343 intel_plane = to_intel_plane(plane);
344
345 /* plane on different crtc cannot be a scaler user of this crtc */
346 if (WARN_ON(intel_plane->pipe != intel_crtc->pipe)) {
347 continue;
348 }
349
350 plane_state = to_intel_plane_state(drm_state->plane_states[i]);
351 scaler_id = &plane_state->scaler_id;
352 }
353
354 if (*scaler_id < 0) {
355 /* find a free scaler */
356 for (j = 0; j < intel_crtc->num_scalers; j++) {
357 if (!scaler_state->scalers[j].in_use) {
358 scaler_state->scalers[j].in_use = 1;
359 *scaler_id = scaler_state->scalers[j].id;
360 DRM_DEBUG_KMS("Attached scaler id %u.%u to %s:%d\n",
361 intel_crtc->pipe,
362 i == SKL_CRTC_INDEX ? scaler_state->scaler_id :
363 plane_state->scaler_id,
364 i == SKL_CRTC_INDEX ? "CRTC" : "PLANE",
365 i == SKL_CRTC_INDEX ? intel_crtc->base.base.id :
366 plane->base.id);
367 break;
368 }
369 }
370 }
371
372 if (WARN_ON(*scaler_id < 0)) {
373 DRM_DEBUG_KMS("Cannot find scaler for %s:%d\n",
374 i == SKL_CRTC_INDEX ? "CRTC" : "PLANE",
375 i == SKL_CRTC_INDEX ? intel_crtc->base.base.id:plane->base.id);
376 continue;
377 }
378
379 /* set scaler mode */
380 if (num_scalers_need == 1 && intel_crtc->pipe != PIPE_C) {
381 /*
382 * when only 1 scaler is in use on either pipe A or B,
383 * scaler 0 operates in high quality (HQ) mode.
384 * In this case use scaler 0 to take advantage of HQ mode
385 */
386 *scaler_id = 0;
387 scaler_state->scalers[0].in_use = 1;
388 scaler_state->scalers[0].mode = PS_SCALER_MODE_HQ;
389 scaler_state->scalers[1].in_use = 0;
390 } else {
391 scaler_state->scalers[*scaler_id].mode = PS_SCALER_MODE_DYN;
392 }
393 }
394
395 return 0;
396}
de419ab6 397
37ade417 398void
de419ab6
ML
399intel_atomic_duplicate_dpll_state(struct drm_i915_private *dev_priv,
400 struct intel_shared_dpll_config *shared_dpll)
401{
402 enum intel_dpll_id i;
403
404 /* Copy shared dpll state */
405 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
406 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
407
408 shared_dpll[i] = pll->config;
409 }
410}
411
412struct intel_shared_dpll_config *
413intel_atomic_get_shared_dpll_state(struct drm_atomic_state *s)
414{
415 struct intel_atomic_state *state = to_intel_atomic_state(s);
416
417 WARN_ON(!drm_modeset_is_locked(&s->dev->mode_config.connection_mutex));
418
419 if (!state->dpll_set) {
420 state->dpll_set = true;
421
422 intel_atomic_duplicate_dpll_state(to_i915(s->dev),
423 state->shared_dpll);
424 }
425
426 return state->shared_dpll;
427}
428
429struct drm_atomic_state *
430intel_atomic_state_alloc(struct drm_device *dev)
431{
432 struct intel_atomic_state *state = kzalloc(sizeof(*state), GFP_KERNEL);
433
434 if (!state || drm_atomic_state_init(dev, &state->base) < 0) {
435 kfree(state);
436 return NULL;
437 }
438
439 return &state->base;
440}
441
442void intel_atomic_state_clear(struct drm_atomic_state *s)
443{
444 struct intel_atomic_state *state = to_intel_atomic_state(s);
445 drm_atomic_state_default_clear(&state->base);
446 state->dpll_set = false;
447}
This page took 0.068551 seconds and 5 git commands to generate.