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 23 #ifndef __DRM_MODESET_H__ 24 #define __DRM_MODESET_H__ 25 26 #include <linux/kref.h> 27 struct drm_object_properties; 28 struct drm_property; 29 struct drm_device; 30 31 /** 32 * struct drm_mode_object - base structure for modeset objects 33 * @id: userspace visible identifier 34 * @type: type of the object, one of DRM_MODE_OBJECT\_\* 35 * @properties: properties attached to this object, including values 36 * @refcount: reference count for objects which with dynamic lifetime 37 * @free_cb: free function callback, only set for objects with dynamic lifetime 38 * 39 * Base structure for modeset objects visible to userspace. Objects can be 40 * looked up using drm_mode_object_find(). Besides basic uapi interface 41 * properties like @id and @type it provides two services: 42 * 43 * - It tracks attached properties and their values. This is used by &drm_crtc, 44 * &drm_plane and &drm_connector. Properties are attached by calling 45 * drm_object_attach_property() before the object is visible to userspace. 46 * 47 * - For objects with dynamic lifetimes (as indicated by a non-NULL @free_cb) it 48 * provides reference counting through drm_mode_object_reference() and 49 * drm_mode_object_unreference(). This is used by &drm_framebuffer, 50 * &drm_connector and &drm_property_blob. These objects provide specialized 51 * reference counting wrappers. 52 */ 53 struct drm_mode_object { 54 uint32_t id; 55 uint32_t type; 56 struct drm_object_properties *properties; 57 struct kref refcount; 58 void (*free_cb)(struct kref *kref); 59 }; 60 61 #define DRM_OBJECT_MAX_PROPERTY 24 62 /** 63 * struct drm_object_properties - property tracking for &drm_mode_object 64 */ 65 struct drm_object_properties { 66 /** 67 * @count: number of valid properties, must be less than or equal to 68 * DRM_OBJECT_MAX_PROPERTY. 69 */ 70 71 int count; 72 /** 73 * @properties: Array of pointers to &drm_property. 74 * 75 * NOTE: if we ever start dynamically destroying properties (ie. 76 * not at drm_mode_config_cleanup() time), then we'd have to do 77 * a better job of detaching property from mode objects to avoid 78 * dangling property pointers: 79 */ 80 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY]; 81 82 /** 83 * @values: Array to store the property values, matching @properties. Do 84 * not read/write values directly, but use 85 * drm_object_property_get_value() and drm_object_property_set_value(). 86 * 87 * Note that atomic drivers do not store mutable properties in this 88 * array, but only the decoded values in the corresponding state 89 * structure. The decoding is done using the ->atomic_get_property and 90 * ->atomic_set_property hooks of the corresponding object. Hence atomic 91 * drivers should not use drm_object_property_set_value() and 92 * 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 98 /* Avoid boilerplate. I'm tired of typing. */ 99 #define DRM_ENUM_NAME_FN(fnname, list) \ 100 const char *fnname(int val) \ 101 { \ 102 int i; \ 103 for (i = 0; i < ARRAY_SIZE(list); i++) { \ 104 if (list[i].type == val) \ 105 return list[i].name; \ 106 } \ 107 return "(unknown)"; \ 108 } 109 110 struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, 111 uint32_t id, uint32_t type); 112 void drm_mode_object_reference(struct drm_mode_object *obj); 113 void drm_mode_object_unreference(struct drm_mode_object *obj); 114 115 int drm_object_property_set_value(struct drm_mode_object *obj, 116 struct drm_property *property, 117 uint64_t val); 118 int drm_object_property_get_value(struct drm_mode_object *obj, 119 struct drm_property *property, 120 uint64_t *value); 121 122 void drm_object_attach_property(struct drm_mode_object *obj, 123 struct drm_property *property, 124 uint64_t init_val); 125 #endif 126