drm/i915: copy staged scaler state from drm state to crtc->config.
[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{
132 int ret;
133 int i;
134
135 if (async) {
136 DRM_DEBUG_KMS("i915 does not yet support async commit\n");
137 return -EINVAL;
138 }
139
140 ret = drm_atomic_helper_prepare_planes(dev, state);
141 if (ret)
142 return ret;
143
144 /* Point of no return */
145
146 /*
147 * FIXME: The proper sequence here will eventually be:
148 *
149 * drm_atomic_helper_swap_state(dev, state)
1af434a9 150 * drm_atomic_helper_commit_modeset_disables(dev, state);
5ee67f1c 151 * drm_atomic_helper_commit_planes(dev, state);
1af434a9 152 * drm_atomic_helper_commit_modeset_enables(dev, state);
5ee67f1c
MR
153 * drm_atomic_helper_wait_for_vblanks(dev, state);
154 * drm_atomic_helper_cleanup_planes(dev, state);
155 * drm_atomic_state_free(state);
156 *
157 * once we have full atomic modeset. For now, just manually update
158 * plane states to avoid clobbering good states with dummy states
159 * while nuclear pageflipping.
160 */
161 for (i = 0; i < dev->mode_config.num_total_plane; i++) {
162 struct drm_plane *plane = state->planes[i];
163
164 if (!plane)
165 continue;
166
167 plane->state->state = state;
168 swap(state->plane_states[i], plane->state);
169 plane->state->state = NULL;
170 }
f76f35dc
CK
171
172 /* swap crtc_state */
173 for (i = 0; i < dev->mode_config.num_crtc; i++) {
174 struct drm_crtc *crtc = state->crtcs[i];
175 if (!crtc) {
176 continue;
177 }
178
179 to_intel_crtc(crtc)->config->scaler_state =
180 to_intel_crtc_state(state->crtc_states[i])->scaler_state;
181 }
182
5ee67f1c
MR
183 drm_atomic_helper_commit_planes(dev, state);
184 drm_atomic_helper_wait_for_vblanks(dev, state);
185 drm_atomic_helper_cleanup_planes(dev, state);
186 drm_atomic_state_free(state);
187
188 return 0;
189}
2545e4a6
MR
190
191/**
192 * intel_connector_atomic_get_property - fetch connector property value
193 * @connector: connector to fetch property for
194 * @state: state containing the property value
195 * @property: property to look up
196 * @val: pointer to write property value into
197 *
198 * The DRM core does not store shadow copies of properties for
199 * atomic-capable drivers. This entrypoint is used to fetch
200 * the current value of a driver-specific connector property.
201 */
202int
203intel_connector_atomic_get_property(struct drm_connector *connector,
204 const struct drm_connector_state *state,
205 struct drm_property *property,
206 uint64_t *val)
207{
208 int i;
209
210 /*
211 * TODO: We only have atomic modeset for planes at the moment, so the
212 * crtc/connector code isn't quite ready yet. Until it's ready,
213 * continue to look up all property values in the DRM's shadow copy
214 * in obj->properties->values[].
215 *
216 * When the crtc/connector state work matures, this function should
217 * be updated to read the values out of the state structure instead.
218 */
219 for (i = 0; i < connector->base.properties->count; i++) {
220 if (connector->base.properties->properties[i] == property) {
221 *val = connector->base.properties->values[i];
222 return 0;
223 }
224 }
225
226 return -EINVAL;
227}
1356837e
MR
228
229/*
230 * intel_crtc_duplicate_state - duplicate crtc state
231 * @crtc: drm crtc
232 *
233 * Allocates and returns a copy of the crtc state (both common and
234 * Intel-specific) for the specified crtc.
235 *
236 * Returns: The newly allocated crtc state, or NULL on failure.
237 */
238struct drm_crtc_state *
239intel_crtc_duplicate_state(struct drm_crtc *crtc)
240{
241 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
a91572f3 242 struct intel_crtc_state *crtc_state;
1356837e
MR
243
244 if (WARN_ON(!intel_crtc->config))
a91572f3
ACO
245 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
246 else
247 crtc_state = kmemdup(intel_crtc->config,
248 sizeof(*intel_crtc->config), GFP_KERNEL);
1356837e 249
a91572f3
ACO
250 if (crtc_state)
251 crtc_state->base.crtc = crtc;
252
253 return &crtc_state->base;
1356837e
MR
254}
255
256/**
257 * intel_crtc_destroy_state - destroy crtc state
258 * @crtc: drm crtc
259 *
260 * Destroys the crtc state (both common and Intel-specific) for the
261 * specified crtc.
262 */
263void
264intel_crtc_destroy_state(struct drm_crtc *crtc,
265 struct drm_crtc_state *state)
266{
267 drm_atomic_helper_crtc_destroy_state(crtc, state);
268}
d03c93d4
CK
269
270/**
271 * intel_atomic_setup_scalers() - setup scalers for crtc per staged requests
272 * @dev: DRM device
273 * @crtc: intel crtc
274 * @crtc_state: incoming crtc_state to validate and setup scalers
275 *
276 * This function sets up scalers based on staged scaling requests for
277 * a @crtc and its planes. It is called from crtc level check path. If request
278 * is a supportable request, it attaches scalers to requested planes and crtc.
279 *
280 * This function takes into account the current scaler(s) in use by any planes
281 * not being part of this atomic state
282 *
283 * Returns:
284 * 0 - scalers were setup succesfully
285 * error code - otherwise
286 */
287int intel_atomic_setup_scalers(struct drm_device *dev,
288 struct intel_crtc *intel_crtc,
289 struct intel_crtc_state *crtc_state)
290{
291 struct drm_plane *plane = NULL;
292 struct intel_plane *intel_plane;
293 struct intel_plane_state *plane_state = NULL;
294 struct intel_crtc_scaler_state *scaler_state;
295 struct drm_atomic_state *drm_state;
296 int num_scalers_need;
297 int i, j;
298
299 if (INTEL_INFO(dev)->gen < 9 || !intel_crtc || !crtc_state)
300 return 0;
301
302 scaler_state = &crtc_state->scaler_state;
303 drm_state = crtc_state->base.state;
304
305 num_scalers_need = hweight32(scaler_state->scaler_users);
306 DRM_DEBUG_KMS("crtc_state = %p need = %d avail = %d scaler_users = 0x%x\n",
307 crtc_state, num_scalers_need, intel_crtc->num_scalers,
308 scaler_state->scaler_users);
309
310 /*
311 * High level flow:
312 * - staged scaler requests are already in scaler_state->scaler_users
313 * - check whether staged scaling requests can be supported
314 * - add planes using scalers that aren't in current transaction
315 * - assign scalers to requested users
316 * - as part of plane commit, scalers will be committed
317 * (i.e., either attached or detached) to respective planes in hw
318 * - as part of crtc_commit, scaler will be either attached or detached
319 * to crtc in hw
320 */
321
322 /* fail if required scalers > available scalers */
323 if (num_scalers_need > intel_crtc->num_scalers){
324 DRM_DEBUG_KMS("Too many scaling requests %d > %d\n",
325 num_scalers_need, intel_crtc->num_scalers);
326 return -EINVAL;
327 }
328
329 /* walkthrough scaler_users bits and start assigning scalers */
330 for (i = 0; i < sizeof(scaler_state->scaler_users) * 8; i++) {
331 int *scaler_id;
332
333 /* skip if scaler not required */
334 if (!(scaler_state->scaler_users & (1 << i)))
335 continue;
336
337 if (i == SKL_CRTC_INDEX) {
338 /* panel fitter case: assign as a crtc scaler */
339 scaler_id = &scaler_state->scaler_id;
340 } else {
341 if (!drm_state)
342 continue;
343
344 /* plane scaler case: assign as a plane scaler */
345 /* find the plane that set the bit as scaler_user */
346 plane = drm_state->planes[i];
347
348 /*
349 * to enable/disable hq mode, add planes that are using scaler
350 * into this transaction
351 */
352 if (!plane) {
353 struct drm_plane_state *state;
354 plane = drm_plane_from_index(dev, i);
355 state = drm_atomic_get_plane_state(drm_state, plane);
356 if (IS_ERR(state)) {
357 DRM_DEBUG_KMS("Failed to add [PLANE:%d] to drm_state\n",
358 plane->base.id);
359 return PTR_ERR(state);
360 }
361 }
362
363 intel_plane = to_intel_plane(plane);
364
365 /* plane on different crtc cannot be a scaler user of this crtc */
366 if (WARN_ON(intel_plane->pipe != intel_crtc->pipe)) {
367 continue;
368 }
369
370 plane_state = to_intel_plane_state(drm_state->plane_states[i]);
371 scaler_id = &plane_state->scaler_id;
372 }
373
374 if (*scaler_id < 0) {
375 /* find a free scaler */
376 for (j = 0; j < intel_crtc->num_scalers; j++) {
377 if (!scaler_state->scalers[j].in_use) {
378 scaler_state->scalers[j].in_use = 1;
379 *scaler_id = scaler_state->scalers[j].id;
380 DRM_DEBUG_KMS("Attached scaler id %u.%u to %s:%d\n",
381 intel_crtc->pipe,
382 i == SKL_CRTC_INDEX ? scaler_state->scaler_id :
383 plane_state->scaler_id,
384 i == SKL_CRTC_INDEX ? "CRTC" : "PLANE",
385 i == SKL_CRTC_INDEX ? intel_crtc->base.base.id :
386 plane->base.id);
387 break;
388 }
389 }
390 }
391
392 if (WARN_ON(*scaler_id < 0)) {
393 DRM_DEBUG_KMS("Cannot find scaler for %s:%d\n",
394 i == SKL_CRTC_INDEX ? "CRTC" : "PLANE",
395 i == SKL_CRTC_INDEX ? intel_crtc->base.base.id:plane->base.id);
396 continue;
397 }
398
399 /* set scaler mode */
400 if (num_scalers_need == 1 && intel_crtc->pipe != PIPE_C) {
401 /*
402 * when only 1 scaler is in use on either pipe A or B,
403 * scaler 0 operates in high quality (HQ) mode.
404 * In this case use scaler 0 to take advantage of HQ mode
405 */
406 *scaler_id = 0;
407 scaler_state->scalers[0].in_use = 1;
408 scaler_state->scalers[0].mode = PS_SCALER_MODE_HQ;
409 scaler_state->scalers[1].in_use = 0;
410 } else {
411 scaler_state->scalers[*scaler_id].mode = PS_SCALER_MODE_DYN;
412 }
413 }
414
415 return 0;
416}
This page took 0.0573900000000001 seconds and 5 git commands to generate.