intel_atomic.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. * DOC: atomic modeset support
  25. *
  26. * The functions here implement the state management and hardware programming
  27. * dispatch required by the atomic modeset infrastructure.
  28. * See intel_atomic_plane.c for the plane-specific atomic functionality.
  29. */
  30. #include <drm/drmP.h>
  31. #include <drm/drm_atomic.h>
  32. #include <drm/drm_atomic_helper.h>
  33. #include <drm/drm_plane_helper.h>
  34. #include "intel_drv.h"
  35. /**
  36. * intel_connector_atomic_get_property - fetch connector property value
  37. * @connector: connector to fetch property for
  38. * @state: state containing the property value
  39. * @property: property to look up
  40. * @val: pointer to write property value into
  41. *
  42. * The DRM core does not store shadow copies of properties for
  43. * atomic-capable drivers. This entrypoint is used to fetch
  44. * the current value of a driver-specific connector property.
  45. */
  46. int
  47. intel_connector_atomic_get_property(struct drm_connector *connector,
  48. const struct drm_connector_state *state,
  49. struct drm_property *property,
  50. uint64_t *val)
  51. {
  52. int i;
  53. /*
  54. * TODO: We only have atomic modeset for planes at the moment, so the
  55. * crtc/connector code isn't quite ready yet. Until it's ready,
  56. * continue to look up all property values in the DRM's shadow copy
  57. * in obj->properties->values[].
  58. *
  59. * When the crtc/connector state work matures, this function should
  60. * be updated to read the values out of the state structure instead.
  61. */
  62. for (i = 0; i < connector->base.properties->count; i++) {
  63. if (connector->base.properties->properties[i] == property) {
  64. *val = connector->base.properties->values[i];
  65. return 0;
  66. }
  67. }
  68. return -EINVAL;
  69. }
  70. /*
  71. * intel_crtc_duplicate_state - duplicate crtc state
  72. * @crtc: drm crtc
  73. *
  74. * Allocates and returns a copy of the crtc state (both common and
  75. * Intel-specific) for the specified crtc.
  76. *
  77. * Returns: The newly allocated crtc state, or NULL on failure.
  78. */
  79. struct drm_crtc_state *
  80. intel_crtc_duplicate_state(struct drm_crtc *crtc)
  81. {
  82. struct intel_crtc_state *crtc_state;
  83. crtc_state = kmemdup(crtc->state, sizeof(*crtc_state), GFP_KERNEL);
  84. if (!crtc_state)
  85. return NULL;
  86. __drm_atomic_helper_crtc_duplicate_state(crtc, &crtc_state->base);
  87. crtc_state->update_pipe = false;
  88. crtc_state->disable_lp_wm = false;
  89. crtc_state->disable_cxsr = false;
  90. crtc_state->wm_changed = false;
  91. return &crtc_state->base;
  92. }
  93. /**
  94. * intel_crtc_destroy_state - destroy crtc state
  95. * @crtc: drm crtc
  96. *
  97. * Destroys the crtc state (both common and Intel-specific) for the
  98. * specified crtc.
  99. */
  100. void
  101. intel_crtc_destroy_state(struct drm_crtc *crtc,
  102. struct drm_crtc_state *state)
  103. {
  104. drm_atomic_helper_crtc_destroy_state(crtc, state);
  105. }
  106. /**
  107. * intel_atomic_setup_scalers() - setup scalers for crtc per staged requests
  108. * @dev: DRM device
  109. * @crtc: intel crtc
  110. * @crtc_state: incoming crtc_state to validate and setup scalers
  111. *
  112. * This function sets up scalers based on staged scaling requests for
  113. * a @crtc and its planes. It is called from crtc level check path. If request
  114. * is a supportable request, it attaches scalers to requested planes and crtc.
  115. *
  116. * This function takes into account the current scaler(s) in use by any planes
  117. * not being part of this atomic state
  118. *
  119. * Returns:
  120. * 0 - scalers were setup succesfully
  121. * error code - otherwise
  122. */
  123. int intel_atomic_setup_scalers(struct drm_device *dev,
  124. struct intel_crtc *intel_crtc,
  125. struct intel_crtc_state *crtc_state)
  126. {
  127. struct drm_plane *plane = NULL;
  128. struct intel_plane *intel_plane;
  129. struct intel_plane_state *plane_state = NULL;
  130. struct intel_crtc_scaler_state *scaler_state =
  131. &crtc_state->scaler_state;
  132. struct drm_atomic_state *drm_state = crtc_state->base.state;
  133. int num_scalers_need;
  134. int i, j;
  135. num_scalers_need = hweight32(scaler_state->scaler_users);
  136. /*
  137. * High level flow:
  138. * - staged scaler requests are already in scaler_state->scaler_users
  139. * - check whether staged scaling requests can be supported
  140. * - add planes using scalers that aren't in current transaction
  141. * - assign scalers to requested users
  142. * - as part of plane commit, scalers will be committed
  143. * (i.e., either attached or detached) to respective planes in hw
  144. * - as part of crtc_commit, scaler will be either attached or detached
  145. * to crtc in hw
  146. */
  147. /* fail if required scalers > available scalers */
  148. if (num_scalers_need > intel_crtc->num_scalers){
  149. DRM_DEBUG_KMS("Too many scaling requests %d > %d\n",
  150. num_scalers_need, intel_crtc->num_scalers);
  151. return -EINVAL;
  152. }
  153. /* walkthrough scaler_users bits and start assigning scalers */
  154. for (i = 0; i < sizeof(scaler_state->scaler_users) * 8; i++) {
  155. int *scaler_id;
  156. const char *name;
  157. int idx;
  158. /* skip if scaler not required */
  159. if (!(scaler_state->scaler_users & (1 << i)))
  160. continue;
  161. if (i == SKL_CRTC_INDEX) {
  162. name = "CRTC";
  163. idx = intel_crtc->base.base.id;
  164. /* panel fitter case: assign as a crtc scaler */
  165. scaler_id = &scaler_state->scaler_id;
  166. } else {
  167. name = "PLANE";
  168. /* plane scaler case: assign as a plane scaler */
  169. /* find the plane that set the bit as scaler_user */
  170. plane = drm_state->planes[i];
  171. /*
  172. * to enable/disable hq mode, add planes that are using scaler
  173. * into this transaction
  174. */
  175. if (!plane) {
  176. struct drm_plane_state *state;
  177. plane = drm_plane_from_index(dev, i);
  178. state = drm_atomic_get_plane_state(drm_state, plane);
  179. if (IS_ERR(state)) {
  180. DRM_DEBUG_KMS("Failed to add [PLANE:%d] to drm_state\n",
  181. plane->base.id);
  182. return PTR_ERR(state);
  183. }
  184. /*
  185. * the plane is added after plane checks are run,
  186. * but since this plane is unchanged just do the
  187. * minimum required validation.
  188. */
  189. crtc_state->base.planes_changed = true;
  190. }
  191. intel_plane = to_intel_plane(plane);
  192. idx = plane->base.id;
  193. /* plane on different crtc cannot be a scaler user of this crtc */
  194. if (WARN_ON(intel_plane->pipe != intel_crtc->pipe)) {
  195. continue;
  196. }
  197. plane_state = to_intel_plane_state(drm_state->plane_states[i]);
  198. scaler_id = &plane_state->scaler_id;
  199. }
  200. if (*scaler_id < 0) {
  201. /* find a free scaler */
  202. for (j = 0; j < intel_crtc->num_scalers; j++) {
  203. if (!scaler_state->scalers[j].in_use) {
  204. scaler_state->scalers[j].in_use = 1;
  205. *scaler_id = j;
  206. DRM_DEBUG_KMS("Attached scaler id %u.%u to %s:%d\n",
  207. intel_crtc->pipe, *scaler_id, name, idx);
  208. break;
  209. }
  210. }
  211. }
  212. if (WARN_ON(*scaler_id < 0)) {
  213. DRM_DEBUG_KMS("Cannot find scaler for %s:%d\n", name, idx);
  214. continue;
  215. }
  216. /* set scaler mode */
  217. if (num_scalers_need == 1 && intel_crtc->pipe != PIPE_C) {
  218. /*
  219. * when only 1 scaler is in use on either pipe A or B,
  220. * scaler 0 operates in high quality (HQ) mode.
  221. * In this case use scaler 0 to take advantage of HQ mode
  222. */
  223. *scaler_id = 0;
  224. scaler_state->scalers[0].in_use = 1;
  225. scaler_state->scalers[0].mode = PS_SCALER_MODE_HQ;
  226. scaler_state->scalers[1].in_use = 0;
  227. } else {
  228. scaler_state->scalers[*scaler_id].mode = PS_SCALER_MODE_DYN;
  229. }
  230. }
  231. return 0;
  232. }
  233. static void
  234. intel_atomic_duplicate_dpll_state(struct drm_i915_private *dev_priv,
  235. struct intel_shared_dpll_config *shared_dpll)
  236. {
  237. enum intel_dpll_id i;
  238. /* Copy shared dpll state */
  239. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  240. struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
  241. shared_dpll[i] = pll->config;
  242. }
  243. }
  244. struct intel_shared_dpll_config *
  245. intel_atomic_get_shared_dpll_state(struct drm_atomic_state *s)
  246. {
  247. struct intel_atomic_state *state = to_intel_atomic_state(s);
  248. WARN_ON(!drm_modeset_is_locked(&s->dev->mode_config.connection_mutex));
  249. if (!state->dpll_set) {
  250. state->dpll_set = true;
  251. intel_atomic_duplicate_dpll_state(to_i915(s->dev),
  252. state->shared_dpll);
  253. }
  254. return state->shared_dpll;
  255. }
  256. struct drm_atomic_state *
  257. intel_atomic_state_alloc(struct drm_device *dev)
  258. {
  259. struct intel_atomic_state *state = kzalloc(sizeof(*state), GFP_KERNEL);
  260. if (!state || drm_atomic_state_init(dev, &state->base) < 0) {
  261. kfree(state);
  262. return NULL;
  263. }
  264. return &state->base;
  265. }
  266. void intel_atomic_state_clear(struct drm_atomic_state *s)
  267. {
  268. struct intel_atomic_state *state = to_intel_atomic_state(s);
  269. drm_atomic_state_default_clear(&state->base);
  270. state->dpll_set = state->modeset = false;
  271. }