intel_atomic.c 7.1 KB

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