blob: b4ea6762e4ef018ae60e31a6912994605fc71cc7 [file] [log] [blame]
Matt Roper5ee67f12015-01-21 16:35:44 -08001/*
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;
51 int ret;
52 int i;
53 bool not_nuclear = false;
54
55 /*
56 * FIXME: At the moment, we only support "nuclear pageflip" on a
57 * single CRTC. Cross-crtc updates will be added later.
58 */
59 for (i = 0; i < nplanes; i++) {
60 struct intel_plane *plane = to_intel_plane(state->planes[i]);
61 if (!plane)
62 continue;
63
64 if (nuclear_pipe == INVALID_PIPE) {
65 nuclear_pipe = plane->pipe;
66 } else if (nuclear_pipe != plane->pipe) {
67 DRM_DEBUG_KMS("i915 only support atomic plane operations on a single CRTC at the moment\n");
68 return -EINVAL;
69 }
70 }
71
72 /*
73 * FIXME: We only handle planes for now; make sure there are no CRTC's
74 * or connectors involved.
75 */
76 state->allow_modeset = false;
77 for (i = 0; i < ncrtcs; i++) {
78 struct intel_crtc *crtc = to_intel_crtc(state->crtcs[i]);
Matt Roperf1e2dae2015-04-09 10:48:38 -070079 if (crtc)
80 memset(&crtc->atomic, 0, sizeof(crtc->atomic));
Matt Roper5ee67f12015-01-21 16:35:44 -080081 if (crtc && crtc->pipe != nuclear_pipe)
82 not_nuclear = true;
83 }
84 for (i = 0; i < nconnectors; i++)
85 if (state->connectors[i] != NULL)
86 not_nuclear = true;
87
88 if (not_nuclear) {
89 DRM_DEBUG_KMS("i915 only supports atomic plane operations at the moment\n");
90 return -EINVAL;
91 }
92
93 ret = drm_atomic_helper_check_planes(dev, state);
94 if (ret)
95 return ret;
96
97 return ret;
98}
99
100
101/**
102 * intel_atomic_commit - commit validated state object
103 * @dev: DRM device
104 * @state: the top-level driver state object
105 * @async: asynchronous commit
106 *
107 * This function commits a top-level state object that has been validated
108 * with drm_atomic_helper_check().
109 *
110 * FIXME: Atomic modeset support for i915 is not yet complete. At the moment
111 * we can only handle plane-related operations and do not yet support
112 * asynchronous commit.
113 *
114 * RETURNS
115 * Zero for success or -errno.
116 */
117int intel_atomic_commit(struct drm_device *dev,
118 struct drm_atomic_state *state,
119 bool async)
120{
121 int ret;
122 int i;
123
124 if (async) {
125 DRM_DEBUG_KMS("i915 does not yet support async commit\n");
126 return -EINVAL;
127 }
128
129 ret = drm_atomic_helper_prepare_planes(dev, state);
130 if (ret)
131 return ret;
132
133 /* Point of no return */
134
135 /*
136 * FIXME: The proper sequence here will eventually be:
137 *
138 * drm_atomic_helper_swap_state(dev, state)
Daniel Vetter1af434a2015-02-22 12:24:19 +0100139 * drm_atomic_helper_commit_modeset_disables(dev, state);
Matt Roper5ee67f12015-01-21 16:35:44 -0800140 * drm_atomic_helper_commit_planes(dev, state);
Daniel Vetter1af434a2015-02-22 12:24:19 +0100141 * drm_atomic_helper_commit_modeset_enables(dev, state);
Matt Roper5ee67f12015-01-21 16:35:44 -0800142 * drm_atomic_helper_wait_for_vblanks(dev, state);
143 * drm_atomic_helper_cleanup_planes(dev, state);
144 * drm_atomic_state_free(state);
145 *
146 * once we have full atomic modeset. For now, just manually update
147 * plane states to avoid clobbering good states with dummy states
148 * while nuclear pageflipping.
149 */
150 for (i = 0; i < dev->mode_config.num_total_plane; i++) {
151 struct drm_plane *plane = state->planes[i];
152
153 if (!plane)
154 continue;
155
156 plane->state->state = state;
157 swap(state->plane_states[i], plane->state);
158 plane->state->state = NULL;
159 }
160 drm_atomic_helper_commit_planes(dev, state);
161 drm_atomic_helper_wait_for_vblanks(dev, state);
162 drm_atomic_helper_cleanup_planes(dev, state);
163 drm_atomic_state_free(state);
164
165 return 0;
166}
Matt Roper2545e4a2015-01-22 16:51:27 -0800167
168/**
169 * intel_connector_atomic_get_property - fetch connector property value
170 * @connector: connector to fetch property for
171 * @state: state containing the property value
172 * @property: property to look up
173 * @val: pointer to write property value into
174 *
175 * The DRM core does not store shadow copies of properties for
176 * atomic-capable drivers. This entrypoint is used to fetch
177 * the current value of a driver-specific connector property.
178 */
179int
180intel_connector_atomic_get_property(struct drm_connector *connector,
181 const struct drm_connector_state *state,
182 struct drm_property *property,
183 uint64_t *val)
184{
185 int i;
186
187 /*
188 * TODO: We only have atomic modeset for planes at the moment, so the
189 * crtc/connector code isn't quite ready yet. Until it's ready,
190 * continue to look up all property values in the DRM's shadow copy
191 * in obj->properties->values[].
192 *
193 * When the crtc/connector state work matures, this function should
194 * be updated to read the values out of the state structure instead.
195 */
196 for (i = 0; i < connector->base.properties->count; i++) {
197 if (connector->base.properties->properties[i] == property) {
198 *val = connector->base.properties->values[i];
199 return 0;
200 }
201 }
202
203 return -EINVAL;
204}
Matt Roper13568372015-01-21 16:35:47 -0800205
206/*
207 * intel_crtc_duplicate_state - duplicate crtc state
208 * @crtc: drm crtc
209 *
210 * Allocates and returns a copy of the crtc state (both common and
211 * Intel-specific) for the specified crtc.
212 *
213 * Returns: The newly allocated crtc state, or NULL on failure.
214 */
215struct drm_crtc_state *
216intel_crtc_duplicate_state(struct drm_crtc *crtc)
217{
218 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ander Conselvan de Oliveiraa91572f2015-03-03 15:21:55 +0200219 struct intel_crtc_state *crtc_state;
Matt Roper13568372015-01-21 16:35:47 -0800220
221 if (WARN_ON(!intel_crtc->config))
Ander Conselvan de Oliveiraa91572f2015-03-03 15:21:55 +0200222 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
223 else
224 crtc_state = kmemdup(intel_crtc->config,
225 sizeof(*intel_crtc->config), GFP_KERNEL);
Matt Roper13568372015-01-21 16:35:47 -0800226
Ander Conselvan de Oliveiraa91572f2015-03-03 15:21:55 +0200227 if (crtc_state)
228 crtc_state->base.crtc = crtc;
229
230 return &crtc_state->base;
Matt Roper13568372015-01-21 16:35:47 -0800231}
232
233/**
234 * intel_crtc_destroy_state - destroy crtc state
235 * @crtc: drm crtc
236 *
237 * Destroys the crtc state (both common and Intel-specific) for the
238 * specified crtc.
239 */
240void
241intel_crtc_destroy_state(struct drm_crtc *crtc,
242 struct drm_crtc_state *state)
243{
244 drm_atomic_helper_crtc_destroy_state(crtc, state);
245}