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 struct drm_mode_object { 31 uint32_t id; 32 uint32_t type; 33 struct drm_object_properties *properties; 34 struct kref refcount; 35 void (*free_cb)(struct kref *kref); 36 }; 37 38 #define DRM_OBJECT_MAX_PROPERTY 24 39 struct drm_object_properties { 40 int count; 41 /* NOTE: if we ever start dynamically destroying properties (ie. 42 * not at drm_mode_config_cleanup() time), then we'd have to do 43 * a better job of detaching property from mode objects to avoid 44 * dangling property pointers: 45 */ 46 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY]; 47 /* do not read/write values directly, but use drm_object_property_get_value() 48 * and drm_object_property_set_value(): 49 */ 50 uint64_t values[DRM_OBJECT_MAX_PROPERTY]; 51 }; 52 53 /* Avoid boilerplate. I'm tired of typing. */ 54 #define DRM_ENUM_NAME_FN(fnname, list) \ 55 const char *fnname(int val) \ 56 { \ 57 int i; \ 58 for (i = 0; i < ARRAY_SIZE(list); i++) { \ 59 if (list[i].type == val) \ 60 return list[i].name; \ 61 } \ 62 return "(unknown)"; \ 63 } 64 65 struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, 66 uint32_t id, uint32_t type); 67 void drm_mode_object_reference(struct drm_mode_object *obj); 68 void drm_mode_object_unreference(struct drm_mode_object *obj); 69 70 int drm_object_property_set_value(struct drm_mode_object *obj, 71 struct drm_property *property, 72 uint64_t val); 73 int drm_object_property_get_value(struct drm_mode_object *obj, 74 struct drm_property *property, 75 uint64_t *value); 76 77 void drm_object_attach_property(struct drm_mode_object *obj, 78 struct drm_property *property, 79 uint64_t init_val); 80 #endif 81