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