blob: a767b4a30a6d37704c136c862eabee5417550bb7 [file] [log] [blame]
Daniel Vetter7520a272016-08-15 16:07:02 +02001/*
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>
27struct drm_object_properties;
Daniel Vetter52217192016-08-12 22:48:50 +020028struct drm_property;
Daniel Vetter199e4e92016-08-31 18:09:05 +020029struct drm_device;
Daniel Vetter7520a272016-08-15 16:07:02 +020030
Daniel Vettera2511a52016-08-29 10:27:53 +020031/**
32 * struct drm_mode_object - base structure for modeset objects
33 * @id: userspace visible identifier
34 * @type: type of the object, one of DRM_MODE_OBJECT\_\*
35 * @properties: properties attached to this object, including values
36 * @refcount: reference count for objects which with dynamic lifetime
37 * @free_cb: free function callback, only set for objects with dynamic lifetime
38 *
39 * Base structure for modeset objects visible to userspace. Objects can be
40 * looked up using drm_mode_object_find(). Besides basic uapi interface
41 * properties like @id and @type it provides two services:
42 *
43 * - It tracks attached properties and their values. This is used by &drm_crtc,
44 * &drm_plane and &drm_connector. Properties are attached by calling
45 * drm_object_attach_property() before the object is visible to userspace.
46 *
47 * - For objects with dynamic lifetimes (as indicated by a non-NULL @free_cb) it
Thierry Reding020a2182017-02-28 15:46:38 +010048 * provides reference counting through drm_mode_object_get() and
49 * drm_mode_object_put(). This is used by &drm_framebuffer, &drm_connector
50 * and &drm_property_blob. These objects provide specialized reference
51 * counting wrappers.
Daniel Vettera2511a52016-08-29 10:27:53 +020052 */
Daniel Vetter7520a272016-08-15 16:07:02 +020053struct drm_mode_object {
54 uint32_t id;
55 uint32_t type;
56 struct drm_object_properties *properties;
57 struct kref refcount;
58 void (*free_cb)(struct kref *kref);
59};
60
Daniel Vetter52217192016-08-12 22:48:50 +020061#define DRM_OBJECT_MAX_PROPERTY 24
Daniel Vettera2511a52016-08-29 10:27:53 +020062/**
63 * struct drm_object_properties - property tracking for &drm_mode_object
64 */
Daniel Vetter52217192016-08-12 22:48:50 +020065struct drm_object_properties {
Daniel Vettera2511a52016-08-29 10:27:53 +020066 /**
67 * @count: number of valid properties, must be less than or equal to
68 * DRM_OBJECT_MAX_PROPERTY.
69 */
70
Daniel Vetterf094d882016-08-29 10:27:52 +020071 int count;
Daniel Vettera2511a52016-08-29 10:27:53 +020072 /**
73 * @properties: Array of pointers to &drm_property.
74 *
75 * NOTE: if we ever start dynamically destroying properties (ie.
Daniel Vetter52217192016-08-12 22:48:50 +020076 * not at drm_mode_config_cleanup() time), then we'd have to do
77 * a better job of detaching property from mode objects to avoid
78 * dangling property pointers:
79 */
80 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
Daniel Vettera2511a52016-08-29 10:27:53 +020081
82 /**
83 * @values: Array to store the property values, matching @properties. Do
84 * not read/write values directly, but use
85 * drm_object_property_get_value() and drm_object_property_set_value().
86 *
87 * Note that atomic drivers do not store mutable properties in this
88 * array, but only the decoded values in the corresponding state
Daniel Vetterd5745282017-01-25 07:26:45 +010089 * structure. The decoding is done using the &drm_crtc.atomic_get_property and
90 * &drm_crtc.atomic_set_property hooks for &struct drm_crtc. For
91 * &struct drm_plane the hooks are &drm_plane_funcs.atomic_get_property and
92 * &drm_plane_funcs.atomic_set_property. And for &struct drm_connector
93 * the hooks are &drm_connector_funcs.atomic_get_property and
94 * &drm_connector_funcs.atomic_set_property .
95 *
96 * Hence atomic drivers should not use drm_object_property_set_value()
97 * and drm_object_property_get_value() on mutable objects, i.e. those
Daniel Vettera2511a52016-08-29 10:27:53 +020098 * without the DRM_MODE_PROP_IMMUTABLE flag set.
Daniel Vetter52217192016-08-12 22:48:50 +020099 */
100 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
101};
102
103/* Avoid boilerplate. I'm tired of typing. */
104#define DRM_ENUM_NAME_FN(fnname, list) \
105 const char *fnname(int val) \
106 { \
107 int i; \
108 for (i = 0; i < ARRAY_SIZE(list); i++) { \
109 if (list[i].type == val) \
110 return list[i].name; \
111 } \
112 return "(unknown)"; \
113 }
114
Daniel Vetter7520a272016-08-15 16:07:02 +0200115struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
116 uint32_t id, uint32_t type);
Thierry Reding020a2182017-02-28 15:46:38 +0100117void drm_mode_object_get(struct drm_mode_object *obj);
118void drm_mode_object_put(struct drm_mode_object *obj);
119
120/**
121 * drm_mode_object_reference - acquire a mode object reference
122 * @obj: DRM mode object
123 *
124 * This is a compatibility alias for drm_mode_object_get() and should not be
125 * used by new code.
126 */
127static inline void drm_mode_object_reference(struct drm_mode_object *obj)
128{
129 drm_mode_object_get(obj);
130}
131
132/**
133 * drm_mode_object_unreference - release a mode object reference
134 * @obj: DRM mode object
135 *
136 * This is a compatibility alias for drm_mode_object_put() and should not be
137 * used by new code.
138 */
139static inline void drm_mode_object_unreference(struct drm_mode_object *obj)
140{
141 drm_mode_object_put(obj);
142}
Daniel Vetter7520a272016-08-15 16:07:02 +0200143
Daniel Vetter949619f2016-08-29 10:27:51 +0200144int drm_object_property_set_value(struct drm_mode_object *obj,
145 struct drm_property *property,
146 uint64_t val);
147int drm_object_property_get_value(struct drm_mode_object *obj,
148 struct drm_property *property,
149 uint64_t *value);
150
151void drm_object_attach_property(struct drm_mode_object *obj,
152 struct drm_property *property,
153 uint64_t init_val);
Daniel Vetter7520a272016-08-15 16:07:02 +0200154#endif