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