drm_mode_object.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright (c) 2016 Intel Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #ifndef __DRM_MODESET_H__
  23. #define __DRM_MODESET_H__
  24. #include <linux/kref.h>
  25. struct drm_object_properties;
  26. struct drm_property;
  27. struct drm_device;
  28. struct drm_file;
  29. /**
  30. * struct drm_mode_object - base structure for modeset objects
  31. * @id: userspace visible identifier
  32. * @type: type of the object, one of DRM_MODE_OBJECT\_\*
  33. * @properties: properties attached to this object, including values
  34. * @refcount: reference count for objects which with dynamic lifetime
  35. * @free_cb: free function callback, only set for objects with dynamic lifetime
  36. *
  37. * Base structure for modeset objects visible to userspace. Objects can be
  38. * looked up using drm_mode_object_find(). Besides basic uapi interface
  39. * properties like @id and @type it provides two services:
  40. *
  41. * - It tracks attached properties and their values. This is used by &drm_crtc,
  42. * &drm_plane and &drm_connector. Properties are attached by calling
  43. * drm_object_attach_property() before the object is visible to userspace.
  44. *
  45. * - For objects with dynamic lifetimes (as indicated by a non-NULL @free_cb) it
  46. * provides reference counting through drm_mode_object_get() and
  47. * drm_mode_object_put(). This is used by &drm_framebuffer, &drm_connector
  48. * and &drm_property_blob. These objects provide specialized reference
  49. * counting wrappers.
  50. */
  51. struct drm_mode_object {
  52. uint32_t id;
  53. uint32_t type;
  54. struct drm_object_properties *properties;
  55. struct kref refcount;
  56. void (*free_cb)(struct kref *kref);
  57. };
  58. #define DRM_OBJECT_MAX_PROPERTY 24
  59. /**
  60. * struct drm_object_properties - property tracking for &drm_mode_object
  61. */
  62. struct drm_object_properties {
  63. /**
  64. * @count: number of valid properties, must be less than or equal to
  65. * DRM_OBJECT_MAX_PROPERTY.
  66. */
  67. int count;
  68. /**
  69. * @properties: Array of pointers to &drm_property.
  70. *
  71. * NOTE: if we ever start dynamically destroying properties (ie.
  72. * not at drm_mode_config_cleanup() time), then we'd have to do
  73. * a better job of detaching property from mode objects to avoid
  74. * dangling property pointers:
  75. */
  76. struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
  77. /**
  78. * @values: Array to store the property values, matching @properties. Do
  79. * not read/write values directly, but use
  80. * drm_object_property_get_value() and drm_object_property_set_value().
  81. *
  82. * Note that atomic drivers do not store mutable properties in this
  83. * array, but only the decoded values in the corresponding state
  84. * structure. The decoding is done using the &drm_crtc.atomic_get_property and
  85. * &drm_crtc.atomic_set_property hooks for &struct drm_crtc. For
  86. * &struct drm_plane the hooks are &drm_plane_funcs.atomic_get_property and
  87. * &drm_plane_funcs.atomic_set_property. And for &struct drm_connector
  88. * the hooks are &drm_connector_funcs.atomic_get_property and
  89. * &drm_connector_funcs.atomic_set_property .
  90. *
  91. * Hence atomic drivers should not use drm_object_property_set_value()
  92. * and drm_object_property_get_value() on mutable objects, i.e. those
  93. * without the DRM_MODE_PROP_IMMUTABLE flag set.
  94. */
  95. uint64_t values[DRM_OBJECT_MAX_PROPERTY];
  96. };
  97. /* Avoid boilerplate. I'm tired of typing. */
  98. #define DRM_ENUM_NAME_FN(fnname, list) \
  99. const char *fnname(int val) \
  100. { \
  101. int i; \
  102. for (i = 0; i < ARRAY_SIZE(list); i++) { \
  103. if (list[i].type == val) \
  104. return list[i].name; \
  105. } \
  106. return "(unknown)"; \
  107. }
  108. struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
  109. struct drm_file *file_priv,
  110. uint32_t id, uint32_t type);
  111. void drm_mode_object_get(struct drm_mode_object *obj);
  112. void drm_mode_object_put(struct drm_mode_object *obj);
  113. /**
  114. * drm_mode_object_reference - acquire a mode object reference
  115. * @obj: DRM mode object
  116. *
  117. * This is a compatibility alias for drm_mode_object_get() and should not be
  118. * used by new code.
  119. */
  120. static inline void drm_mode_object_reference(struct drm_mode_object *obj)
  121. {
  122. drm_mode_object_get(obj);
  123. }
  124. /**
  125. * drm_mode_object_unreference - release a mode object reference
  126. * @obj: DRM mode object
  127. *
  128. * This is a compatibility alias for drm_mode_object_put() and should not be
  129. * used by new code.
  130. */
  131. static inline void drm_mode_object_unreference(struct drm_mode_object *obj)
  132. {
  133. drm_mode_object_put(obj);
  134. }
  135. int drm_object_property_set_value(struct drm_mode_object *obj,
  136. struct drm_property *property,
  137. uint64_t val);
  138. int drm_object_property_get_value(struct drm_mode_object *obj,
  139. struct drm_property *property,
  140. uint64_t *value);
  141. void drm_object_attach_property(struct drm_mode_object *obj,
  142. struct drm_property *property,
  143. uint64_t init_val);
  144. #endif