162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright (c) 2016 Intel Corporation 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Permission to use, copy, modify, distribute, and sell this software and its 562306a36Sopenharmony_ci * documentation for any purpose is hereby granted without fee, provided that 662306a36Sopenharmony_ci * the above copyright notice appear in all copies and that both that copyright 762306a36Sopenharmony_ci * notice and this permission notice appear in supporting documentation, and 862306a36Sopenharmony_ci * that the name of the copyright holders not be used in advertising or 962306a36Sopenharmony_ci * publicity pertaining to distribution of the software without specific, 1062306a36Sopenharmony_ci * written prior permission. The copyright holders make no representations 1162306a36Sopenharmony_ci * about the suitability of this software for any purpose. It is provided "as 1262306a36Sopenharmony_ci * is" without express or implied warranty. 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1562306a36Sopenharmony_ci * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 1662306a36Sopenharmony_ci * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 1762306a36Sopenharmony_ci * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 1862306a36Sopenharmony_ci * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 1962306a36Sopenharmony_ci * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 2062306a36Sopenharmony_ci * OF THIS SOFTWARE. 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#ifndef __DRM_MODESET_H__ 2462306a36Sopenharmony_ci#define __DRM_MODESET_H__ 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#include <linux/kref.h> 2762306a36Sopenharmony_ci#include <drm/drm_lease.h> 2862306a36Sopenharmony_cistruct drm_object_properties; 2962306a36Sopenharmony_cistruct drm_property; 3062306a36Sopenharmony_cistruct drm_device; 3162306a36Sopenharmony_cistruct drm_file; 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci/** 3462306a36Sopenharmony_ci * struct drm_mode_object - base structure for modeset objects 3562306a36Sopenharmony_ci * @id: userspace visible identifier 3662306a36Sopenharmony_ci * @type: type of the object, one of DRM_MODE_OBJECT\_\* 3762306a36Sopenharmony_ci * @properties: properties attached to this object, including values 3862306a36Sopenharmony_ci * @refcount: reference count for objects which with dynamic lifetime 3962306a36Sopenharmony_ci * @free_cb: free function callback, only set for objects with dynamic lifetime 4062306a36Sopenharmony_ci * 4162306a36Sopenharmony_ci * Base structure for modeset objects visible to userspace. Objects can be 4262306a36Sopenharmony_ci * looked up using drm_mode_object_find(). Besides basic uapi interface 4362306a36Sopenharmony_ci * properties like @id and @type it provides two services: 4462306a36Sopenharmony_ci * 4562306a36Sopenharmony_ci * - It tracks attached properties and their values. This is used by &drm_crtc, 4662306a36Sopenharmony_ci * &drm_plane and &drm_connector. Properties are attached by calling 4762306a36Sopenharmony_ci * drm_object_attach_property() before the object is visible to userspace. 4862306a36Sopenharmony_ci * 4962306a36Sopenharmony_ci * - For objects with dynamic lifetimes (as indicated by a non-NULL @free_cb) it 5062306a36Sopenharmony_ci * provides reference counting through drm_mode_object_get() and 5162306a36Sopenharmony_ci * drm_mode_object_put(). This is used by &drm_framebuffer, &drm_connector 5262306a36Sopenharmony_ci * and &drm_property_blob. These objects provide specialized reference 5362306a36Sopenharmony_ci * counting wrappers. 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_cistruct drm_mode_object { 5662306a36Sopenharmony_ci uint32_t id; 5762306a36Sopenharmony_ci uint32_t type; 5862306a36Sopenharmony_ci struct drm_object_properties *properties; 5962306a36Sopenharmony_ci struct kref refcount; 6062306a36Sopenharmony_ci void (*free_cb)(struct kref *kref); 6162306a36Sopenharmony_ci}; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#define DRM_OBJECT_MAX_PROPERTY 24 6462306a36Sopenharmony_ci/** 6562306a36Sopenharmony_ci * struct drm_object_properties - property tracking for &drm_mode_object 6662306a36Sopenharmony_ci */ 6762306a36Sopenharmony_cistruct drm_object_properties { 6862306a36Sopenharmony_ci /** 6962306a36Sopenharmony_ci * @count: number of valid properties, must be less than or equal to 7062306a36Sopenharmony_ci * DRM_OBJECT_MAX_PROPERTY. 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci int count; 7462306a36Sopenharmony_ci /** 7562306a36Sopenharmony_ci * @properties: Array of pointers to &drm_property. 7662306a36Sopenharmony_ci * 7762306a36Sopenharmony_ci * NOTE: if we ever start dynamically destroying properties (ie. 7862306a36Sopenharmony_ci * not at drm_mode_config_cleanup() time), then we'd have to do 7962306a36Sopenharmony_ci * a better job of detaching property from mode objects to avoid 8062306a36Sopenharmony_ci * dangling property pointers: 8162306a36Sopenharmony_ci */ 8262306a36Sopenharmony_ci struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY]; 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci /** 8562306a36Sopenharmony_ci * @values: Array to store the property values, matching @properties. Do 8662306a36Sopenharmony_ci * not read/write values directly, but use 8762306a36Sopenharmony_ci * drm_object_property_get_value() and drm_object_property_set_value(). 8862306a36Sopenharmony_ci * 8962306a36Sopenharmony_ci * Note that atomic drivers do not store mutable properties in this 9062306a36Sopenharmony_ci * array, but only the decoded values in the corresponding state 9162306a36Sopenharmony_ci * structure. The decoding is done using the &drm_crtc.atomic_get_property and 9262306a36Sopenharmony_ci * &drm_crtc.atomic_set_property hooks for &struct drm_crtc. For 9362306a36Sopenharmony_ci * &struct drm_plane the hooks are &drm_plane_funcs.atomic_get_property and 9462306a36Sopenharmony_ci * &drm_plane_funcs.atomic_set_property. And for &struct drm_connector 9562306a36Sopenharmony_ci * the hooks are &drm_connector_funcs.atomic_get_property and 9662306a36Sopenharmony_ci * &drm_connector_funcs.atomic_set_property . 9762306a36Sopenharmony_ci * 9862306a36Sopenharmony_ci * Hence atomic drivers should not use drm_object_property_set_value() 9962306a36Sopenharmony_ci * and drm_object_property_get_value() on mutable objects, i.e. those 10062306a36Sopenharmony_ci * without the DRM_MODE_PROP_IMMUTABLE flag set. 10162306a36Sopenharmony_ci * 10262306a36Sopenharmony_ci * For atomic drivers the default value of properties is stored in this 10362306a36Sopenharmony_ci * array, so drm_object_property_get_default_value can be used to 10462306a36Sopenharmony_ci * retrieve it. 10562306a36Sopenharmony_ci */ 10662306a36Sopenharmony_ci uint64_t values[DRM_OBJECT_MAX_PROPERTY]; 10762306a36Sopenharmony_ci}; 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci/* Avoid boilerplate. I'm tired of typing. */ 11062306a36Sopenharmony_ci#define DRM_ENUM_NAME_FN(fnname, list) \ 11162306a36Sopenharmony_ci const char *fnname(int val) \ 11262306a36Sopenharmony_ci { \ 11362306a36Sopenharmony_ci int i; \ 11462306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(list); i++) { \ 11562306a36Sopenharmony_ci if (list[i].type == val) \ 11662306a36Sopenharmony_ci return list[i].name; \ 11762306a36Sopenharmony_ci } \ 11862306a36Sopenharmony_ci return "(unknown)"; \ 11962306a36Sopenharmony_ci } 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_cistruct drm_mode_object *drm_mode_object_find(struct drm_device *dev, 12262306a36Sopenharmony_ci struct drm_file *file_priv, 12362306a36Sopenharmony_ci uint32_t id, uint32_t type); 12462306a36Sopenharmony_civoid drm_mode_object_get(struct drm_mode_object *obj); 12562306a36Sopenharmony_civoid drm_mode_object_put(struct drm_mode_object *obj); 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ciint drm_object_property_set_value(struct drm_mode_object *obj, 12862306a36Sopenharmony_ci struct drm_property *property, 12962306a36Sopenharmony_ci uint64_t val); 13062306a36Sopenharmony_ciint drm_object_property_get_value(struct drm_mode_object *obj, 13162306a36Sopenharmony_ci struct drm_property *property, 13262306a36Sopenharmony_ci uint64_t *value); 13362306a36Sopenharmony_ciint drm_object_property_get_default_value(struct drm_mode_object *obj, 13462306a36Sopenharmony_ci struct drm_property *property, 13562306a36Sopenharmony_ci uint64_t *val); 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_civoid drm_object_attach_property(struct drm_mode_object *obj, 13862306a36Sopenharmony_ci struct drm_property *property, 13962306a36Sopenharmony_ci uint64_t init_val); 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_cibool drm_mode_object_lease_required(uint32_t type); 14262306a36Sopenharmony_ci#endif 143