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