18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2016 Intel Corporation 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, distribute, and sell this software and its 58c2ecf20Sopenharmony_ci * documentation for any purpose is hereby granted without fee, provided that 68c2ecf20Sopenharmony_ci * the above copyright notice appear in all copies and that both that copyright 78c2ecf20Sopenharmony_ci * notice and this permission notice appear in supporting documentation, and 88c2ecf20Sopenharmony_ci * that the name of the copyright holders not be used in advertising or 98c2ecf20Sopenharmony_ci * publicity pertaining to distribution of the software without specific, 108c2ecf20Sopenharmony_ci * written prior permission. The copyright holders make no representations 118c2ecf20Sopenharmony_ci * about the suitability of this software for any purpose. It is provided "as 128c2ecf20Sopenharmony_ci * is" without express or implied warranty. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 158c2ecf20Sopenharmony_ci * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 168c2ecf20Sopenharmony_ci * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 178c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 188c2ecf20Sopenharmony_ci * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 198c2ecf20Sopenharmony_ci * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 208c2ecf20Sopenharmony_ci * OF THIS SOFTWARE. 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#ifndef __DRM_MODESET_H__ 248c2ecf20Sopenharmony_ci#define __DRM_MODESET_H__ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#include <linux/kref.h> 278c2ecf20Sopenharmony_ci#include <drm/drm_lease.h> 288c2ecf20Sopenharmony_cistruct drm_object_properties; 298c2ecf20Sopenharmony_cistruct drm_property; 308c2ecf20Sopenharmony_cistruct drm_device; 318c2ecf20Sopenharmony_cistruct drm_file; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/** 348c2ecf20Sopenharmony_ci * struct drm_mode_object - base structure for modeset objects 358c2ecf20Sopenharmony_ci * @id: userspace visible identifier 368c2ecf20Sopenharmony_ci * @type: type of the object, one of DRM_MODE_OBJECT\_\* 378c2ecf20Sopenharmony_ci * @properties: properties attached to this object, including values 388c2ecf20Sopenharmony_ci * @refcount: reference count for objects which with dynamic lifetime 398c2ecf20Sopenharmony_ci * @free_cb: free function callback, only set for objects with dynamic lifetime 408c2ecf20Sopenharmony_ci * 418c2ecf20Sopenharmony_ci * Base structure for modeset objects visible to userspace. Objects can be 428c2ecf20Sopenharmony_ci * looked up using drm_mode_object_find(). Besides basic uapi interface 438c2ecf20Sopenharmony_ci * properties like @id and @type it provides two services: 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * - It tracks attached properties and their values. This is used by &drm_crtc, 468c2ecf20Sopenharmony_ci * &drm_plane and &drm_connector. Properties are attached by calling 478c2ecf20Sopenharmony_ci * drm_object_attach_property() before the object is visible to userspace. 488c2ecf20Sopenharmony_ci * 498c2ecf20Sopenharmony_ci * - For objects with dynamic lifetimes (as indicated by a non-NULL @free_cb) it 508c2ecf20Sopenharmony_ci * provides reference counting through drm_mode_object_get() and 518c2ecf20Sopenharmony_ci * drm_mode_object_put(). This is used by &drm_framebuffer, &drm_connector 528c2ecf20Sopenharmony_ci * and &drm_property_blob. These objects provide specialized reference 538c2ecf20Sopenharmony_ci * counting wrappers. 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_cistruct drm_mode_object { 568c2ecf20Sopenharmony_ci uint32_t id; 578c2ecf20Sopenharmony_ci uint32_t type; 588c2ecf20Sopenharmony_ci struct drm_object_properties *properties; 598c2ecf20Sopenharmony_ci struct kref refcount; 608c2ecf20Sopenharmony_ci void (*free_cb)(struct kref *kref); 618c2ecf20Sopenharmony_ci}; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define DRM_OBJECT_MAX_PROPERTY 24 648c2ecf20Sopenharmony_ci/** 658c2ecf20Sopenharmony_ci * struct drm_object_properties - property tracking for &drm_mode_object 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_cistruct drm_object_properties { 688c2ecf20Sopenharmony_ci /** 698c2ecf20Sopenharmony_ci * @count: number of valid properties, must be less than or equal to 708c2ecf20Sopenharmony_ci * DRM_OBJECT_MAX_PROPERTY. 718c2ecf20Sopenharmony_ci */ 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci int count; 748c2ecf20Sopenharmony_ci /** 758c2ecf20Sopenharmony_ci * @properties: Array of pointers to &drm_property. 768c2ecf20Sopenharmony_ci * 778c2ecf20Sopenharmony_ci * NOTE: if we ever start dynamically destroying properties (ie. 788c2ecf20Sopenharmony_ci * not at drm_mode_config_cleanup() time), then we'd have to do 798c2ecf20Sopenharmony_ci * a better job of detaching property from mode objects to avoid 808c2ecf20Sopenharmony_ci * dangling property pointers: 818c2ecf20Sopenharmony_ci */ 828c2ecf20Sopenharmony_ci struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY]; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci /** 858c2ecf20Sopenharmony_ci * @values: Array to store the property values, matching @properties. Do 868c2ecf20Sopenharmony_ci * not read/write values directly, but use 878c2ecf20Sopenharmony_ci * drm_object_property_get_value() and drm_object_property_set_value(). 888c2ecf20Sopenharmony_ci * 898c2ecf20Sopenharmony_ci * Note that atomic drivers do not store mutable properties in this 908c2ecf20Sopenharmony_ci * array, but only the decoded values in the corresponding state 918c2ecf20Sopenharmony_ci * structure. The decoding is done using the &drm_crtc.atomic_get_property and 928c2ecf20Sopenharmony_ci * &drm_crtc.atomic_set_property hooks for &struct drm_crtc. For 938c2ecf20Sopenharmony_ci * &struct drm_plane the hooks are &drm_plane_funcs.atomic_get_property and 948c2ecf20Sopenharmony_ci * &drm_plane_funcs.atomic_set_property. And for &struct drm_connector 958c2ecf20Sopenharmony_ci * the hooks are &drm_connector_funcs.atomic_get_property and 968c2ecf20Sopenharmony_ci * &drm_connector_funcs.atomic_set_property . 978c2ecf20Sopenharmony_ci * 988c2ecf20Sopenharmony_ci * Hence atomic drivers should not use drm_object_property_set_value() 998c2ecf20Sopenharmony_ci * and drm_object_property_get_value() on mutable objects, i.e. those 1008c2ecf20Sopenharmony_ci * without the DRM_MODE_PROP_IMMUTABLE flag set. 1018c2ecf20Sopenharmony_ci */ 1028c2ecf20Sopenharmony_ci uint64_t values[DRM_OBJECT_MAX_PROPERTY]; 1038c2ecf20Sopenharmony_ci}; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/* Avoid boilerplate. I'm tired of typing. */ 1068c2ecf20Sopenharmony_ci#define DRM_ENUM_NAME_FN(fnname, list) \ 1078c2ecf20Sopenharmony_ci const char *fnname(int val) \ 1088c2ecf20Sopenharmony_ci { \ 1098c2ecf20Sopenharmony_ci int i; \ 1108c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(list); i++) { \ 1118c2ecf20Sopenharmony_ci if (list[i].type == val) \ 1128c2ecf20Sopenharmony_ci return list[i].name; \ 1138c2ecf20Sopenharmony_ci } \ 1148c2ecf20Sopenharmony_ci return "(unknown)"; \ 1158c2ecf20Sopenharmony_ci } 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cistruct drm_mode_object *drm_mode_object_find(struct drm_device *dev, 1188c2ecf20Sopenharmony_ci struct drm_file *file_priv, 1198c2ecf20Sopenharmony_ci uint32_t id, uint32_t type); 1208c2ecf20Sopenharmony_civoid drm_mode_object_get(struct drm_mode_object *obj); 1218c2ecf20Sopenharmony_civoid drm_mode_object_put(struct drm_mode_object *obj); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ciint drm_object_property_set_value(struct drm_mode_object *obj, 1248c2ecf20Sopenharmony_ci struct drm_property *property, 1258c2ecf20Sopenharmony_ci uint64_t val); 1268c2ecf20Sopenharmony_ciint drm_object_property_get_value(struct drm_mode_object *obj, 1278c2ecf20Sopenharmony_ci struct drm_property *property, 1288c2ecf20Sopenharmony_ci uint64_t *value); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_civoid drm_object_attach_property(struct drm_mode_object *obj, 1318c2ecf20Sopenharmony_ci struct drm_property *property, 1328c2ecf20Sopenharmony_ci uint64_t init_val); 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cibool drm_mode_object_lease_required(uint32_t type); 1358c2ecf20Sopenharmony_ci#endif 136