intel_atomic.c 7.0 KB

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