Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 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 | |
Matt Roper | 2545e4a | 2015-01-22 16:51:27 -0800 | [diff] [blame] | 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 | */ |
| 49 | int |
| 50 | intel_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 | } |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 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 | */ |
| 85 | struct drm_crtc_state * |
| 86 | intel_crtc_duplicate_state(struct drm_crtc *crtc) |
| 87 | { |
Ander Conselvan de Oliveira | a91572f | 2015-03-03 15:21:55 +0200 | [diff] [blame] | 88 | struct intel_crtc_state *crtc_state; |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 89 | |
Maarten Lankhorst | f2a066f | 2015-09-10 16:08:03 +0200 | [diff] [blame] | 90 | crtc_state = kmemdup(crtc->state, sizeof(*crtc_state), GFP_KERNEL); |
Ander Conselvan de Oliveira | f0c6057 | 2015-04-21 17:12:58 +0300 | [diff] [blame] | 91 | if (!crtc_state) |
| 92 | return NULL; |
| 93 | |
| 94 | __drm_atomic_helper_crtc_duplicate_state(crtc, &crtc_state->base); |
| 95 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 96 | crtc_state->update_pipe = false; |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 97 | crtc_state->disable_lp_wm = false; |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 98 | crtc_state->disable_cxsr = false; |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 99 | crtc_state->update_wm_pre = false; |
| 100 | crtc_state->update_wm_post = false; |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 101 | crtc_state->fb_changed = false; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 102 | crtc_state->wm.need_postvbl_update = false; |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 103 | crtc_state->fb_bits = 0; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 104 | |
Ander Conselvan de Oliveira | a91572f | 2015-03-03 15:21:55 +0200 | [diff] [blame] | 105 | return &crtc_state->base; |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
| 109 | * intel_crtc_destroy_state - destroy crtc state |
| 110 | * @crtc: drm crtc |
| 111 | * |
| 112 | * Destroys the crtc state (both common and Intel-specific) for the |
| 113 | * specified crtc. |
| 114 | */ |
| 115 | void |
| 116 | intel_crtc_destroy_state(struct drm_crtc *crtc, |
| 117 | struct drm_crtc_state *state) |
| 118 | { |
| 119 | drm_atomic_helper_crtc_destroy_state(crtc, state); |
| 120 | } |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * intel_atomic_setup_scalers() - setup scalers for crtc per staged requests |
| 124 | * @dev: DRM device |
| 125 | * @crtc: intel crtc |
| 126 | * @crtc_state: incoming crtc_state to validate and setup scalers |
| 127 | * |
| 128 | * This function sets up scalers based on staged scaling requests for |
| 129 | * a @crtc and its planes. It is called from crtc level check path. If request |
| 130 | * is a supportable request, it attaches scalers to requested planes and crtc. |
| 131 | * |
| 132 | * This function takes into account the current scaler(s) in use by any planes |
| 133 | * not being part of this atomic state |
| 134 | * |
| 135 | * Returns: |
| 136 | * 0 - scalers were setup succesfully |
| 137 | * error code - otherwise |
| 138 | */ |
| 139 | int intel_atomic_setup_scalers(struct drm_device *dev, |
| 140 | struct intel_crtc *intel_crtc, |
| 141 | struct intel_crtc_state *crtc_state) |
| 142 | { |
| 143 | struct drm_plane *plane = NULL; |
| 144 | struct intel_plane *intel_plane; |
| 145 | struct intel_plane_state *plane_state = NULL; |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 146 | struct intel_crtc_scaler_state *scaler_state = |
| 147 | &crtc_state->scaler_state; |
| 148 | struct drm_atomic_state *drm_state = crtc_state->base.state; |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 149 | int num_scalers_need; |
| 150 | int i, j; |
| 151 | |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 152 | num_scalers_need = hweight32(scaler_state->scaler_users); |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * High level flow: |
| 156 | * - staged scaler requests are already in scaler_state->scaler_users |
| 157 | * - check whether staged scaling requests can be supported |
| 158 | * - add planes using scalers that aren't in current transaction |
| 159 | * - assign scalers to requested users |
| 160 | * - as part of plane commit, scalers will be committed |
| 161 | * (i.e., either attached or detached) to respective planes in hw |
| 162 | * - as part of crtc_commit, scaler will be either attached or detached |
| 163 | * to crtc in hw |
| 164 | */ |
| 165 | |
| 166 | /* fail if required scalers > available scalers */ |
| 167 | if (num_scalers_need > intel_crtc->num_scalers){ |
| 168 | DRM_DEBUG_KMS("Too many scaling requests %d > %d\n", |
| 169 | num_scalers_need, intel_crtc->num_scalers); |
| 170 | return -EINVAL; |
| 171 | } |
| 172 | |
| 173 | /* walkthrough scaler_users bits and start assigning scalers */ |
| 174 | for (i = 0; i < sizeof(scaler_state->scaler_users) * 8; i++) { |
| 175 | int *scaler_id; |
Maarten Lankhorst | 133b0d1 | 2015-06-15 12:33:39 +0200 | [diff] [blame] | 176 | const char *name; |
| 177 | int idx; |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 178 | |
| 179 | /* skip if scaler not required */ |
| 180 | if (!(scaler_state->scaler_users & (1 << i))) |
| 181 | continue; |
| 182 | |
| 183 | if (i == SKL_CRTC_INDEX) { |
Maarten Lankhorst | 133b0d1 | 2015-06-15 12:33:39 +0200 | [diff] [blame] | 184 | name = "CRTC"; |
| 185 | idx = intel_crtc->base.base.id; |
| 186 | |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 187 | /* panel fitter case: assign as a crtc scaler */ |
| 188 | scaler_id = &scaler_state->scaler_id; |
| 189 | } else { |
Maarten Lankhorst | 133b0d1 | 2015-06-15 12:33:39 +0200 | [diff] [blame] | 190 | name = "PLANE"; |
Maarten Lankhorst | 133b0d1 | 2015-06-15 12:33:39 +0200 | [diff] [blame] | 191 | |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 192 | /* plane scaler case: assign as a plane scaler */ |
| 193 | /* find the plane that set the bit as scaler_user */ |
Daniel Vetter | b8b5342 | 2016-06-02 00:06:33 +0200 | [diff] [blame] | 194 | plane = drm_state->planes[i].ptr; |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 195 | |
| 196 | /* |
| 197 | * to enable/disable hq mode, add planes that are using scaler |
| 198 | * into this transaction |
| 199 | */ |
| 200 | if (!plane) { |
| 201 | struct drm_plane_state *state; |
| 202 | plane = drm_plane_from_index(dev, i); |
| 203 | state = drm_atomic_get_plane_state(drm_state, plane); |
| 204 | if (IS_ERR(state)) { |
| 205 | DRM_DEBUG_KMS("Failed to add [PLANE:%d] to drm_state\n", |
| 206 | plane->base.id); |
| 207 | return PTR_ERR(state); |
| 208 | } |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 209 | |
| 210 | /* |
| 211 | * the plane is added after plane checks are run, |
| 212 | * but since this plane is unchanged just do the |
| 213 | * minimum required validation. |
| 214 | */ |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 215 | crtc_state->base.planes_changed = true; |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | intel_plane = to_intel_plane(plane); |
Matt Roper | c07a2d1 | 2015-07-06 09:19:24 -0700 | [diff] [blame] | 219 | idx = plane->base.id; |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 220 | |
| 221 | /* plane on different crtc cannot be a scaler user of this crtc */ |
| 222 | if (WARN_ON(intel_plane->pipe != intel_crtc->pipe)) { |
| 223 | continue; |
| 224 | } |
| 225 | |
Daniel Vetter | 831655e | 2016-06-02 00:06:25 +0200 | [diff] [blame] | 226 | plane_state = intel_atomic_get_existing_plane_state(drm_state, |
| 227 | intel_plane); |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 228 | scaler_id = &plane_state->scaler_id; |
| 229 | } |
| 230 | |
| 231 | if (*scaler_id < 0) { |
| 232 | /* find a free scaler */ |
| 233 | for (j = 0; j < intel_crtc->num_scalers; j++) { |
| 234 | if (!scaler_state->scalers[j].in_use) { |
| 235 | scaler_state->scalers[j].in_use = 1; |
Maarten Lankhorst | 133b0d1 | 2015-06-15 12:33:39 +0200 | [diff] [blame] | 236 | *scaler_id = j; |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 237 | DRM_DEBUG_KMS("Attached scaler id %u.%u to %s:%d\n", |
Maarten Lankhorst | 133b0d1 | 2015-06-15 12:33:39 +0200 | [diff] [blame] | 238 | intel_crtc->pipe, *scaler_id, name, idx); |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 239 | break; |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | if (WARN_ON(*scaler_id < 0)) { |
Maarten Lankhorst | 133b0d1 | 2015-06-15 12:33:39 +0200 | [diff] [blame] | 245 | DRM_DEBUG_KMS("Cannot find scaler for %s:%d\n", name, idx); |
Chandra Konduru | d03c93d | 2015-04-09 16:42:46 -0700 | [diff] [blame] | 246 | continue; |
| 247 | } |
| 248 | |
| 249 | /* set scaler mode */ |
| 250 | if (num_scalers_need == 1 && intel_crtc->pipe != PIPE_C) { |
| 251 | /* |
| 252 | * when only 1 scaler is in use on either pipe A or B, |
| 253 | * scaler 0 operates in high quality (HQ) mode. |
| 254 | * In this case use scaler 0 to take advantage of HQ mode |
| 255 | */ |
| 256 | *scaler_id = 0; |
| 257 | scaler_state->scalers[0].in_use = 1; |
| 258 | scaler_state->scalers[0].mode = PS_SCALER_MODE_HQ; |
| 259 | scaler_state->scalers[1].in_use = 0; |
| 260 | } else { |
| 261 | scaler_state->scalers[*scaler_id].mode = PS_SCALER_MODE_DYN; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | return 0; |
| 266 | } |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 267 | |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 268 | struct drm_atomic_state * |
| 269 | intel_atomic_state_alloc(struct drm_device *dev) |
| 270 | { |
| 271 | struct intel_atomic_state *state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 272 | |
| 273 | if (!state || drm_atomic_state_init(dev, &state->base) < 0) { |
| 274 | kfree(state); |
| 275 | return NULL; |
| 276 | } |
| 277 | |
| 278 | return &state->base; |
| 279 | } |
| 280 | |
| 281 | void intel_atomic_state_clear(struct drm_atomic_state *s) |
| 282 | { |
| 283 | struct intel_atomic_state *state = to_intel_atomic_state(s); |
| 284 | drm_atomic_state_default_clear(&state->base); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 285 | state->dpll_set = state->modeset = false; |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 286 | } |