blob: c34a3e8030e12c1cd2957c55780a11004edf967d [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>
Keith Packard2ed077e2017-03-14 22:26:41 -070027#include <drm/drm_lease.h>
Daniel Vetter7520a272016-08-15 16:07:02 +020028struct drm_object_properties;
Daniel Vetter52217192016-08-12 22:48:50 +020029struct drm_property;
Daniel Vetter199e4e92016-08-31 18:09:05 +020030struct drm_device;
Keith Packard418da172017-03-14 23:25:07 -070031struct drm_file;
Daniel Vetter7520a272016-08-15 16:07:02 +020032
Daniel Vettera2511a52016-08-29 10:27:53 +020033/**
34 * struct drm_mode_object - base structure for modeset objects
35 * @id: userspace visible identifier
36 * @type: type of the object, one of DRM_MODE_OBJECT\_\*
37 * @properties: properties attached to this object, including values
38 * @refcount: reference count for objects which with dynamic lifetime
39 * @free_cb: free function callback, only set for objects with dynamic lifetime
40 *
41 * Base structure for modeset objects visible to userspace. Objects can be
42 * looked up using drm_mode_object_find(). Besides basic uapi interface
43 * properties like @id and @type it provides two services:
44 *
45 * - It tracks attached properties and their values. This is used by &drm_crtc,
46 * &drm_plane and &drm_connector. Properties are attached by calling
47 * drm_object_attach_property() before the object is visible to userspace.
48 *
49 * - For objects with dynamic lifetimes (as indicated by a non-NULL @free_cb) it
Thierry Reding020a2182017-02-28 15:46:38 +010050 * provides reference counting through drm_mode_object_get() and
51 * drm_mode_object_put(). This is used by &drm_framebuffer, &drm_connector
52 * and &drm_property_blob. These objects provide specialized reference
53 * counting wrappers.
Daniel Vettera2511a52016-08-29 10:27:53 +020054 */
Daniel Vetter7520a272016-08-15 16:07:02 +020055struct drm_mode_object {
56 uint32_t id;
57 uint32_t type;
58 struct drm_object_properties *properties;
59 struct kref refcount;
60 void (*free_cb)(struct kref *kref);
61};
62
Daniel Vetter52217192016-08-12 22:48:50 +020063#define DRM_OBJECT_MAX_PROPERTY 24
Daniel Vettera2511a52016-08-29 10:27:53 +020064/**
65 * struct drm_object_properties - property tracking for &drm_mode_object
66 */
Daniel Vetter52217192016-08-12 22:48:50 +020067struct drm_object_properties {
Daniel Vettera2511a52016-08-29 10:27:53 +020068 /**
69 * @count: number of valid properties, must be less than or equal to
70 * DRM_OBJECT_MAX_PROPERTY.
71 */
72
Daniel Vetterf094d882016-08-29 10:27:52 +020073 int count;
Daniel Vettera2511a52016-08-29 10:27:53 +020074 /**
75 * @properties: Array of pointers to &drm_property.
76 *
77 * NOTE: if we ever start dynamically destroying properties (ie.
Daniel Vetter52217192016-08-12 22:48:50 +020078 * not at drm_mode_config_cleanup() time), then we'd have to do
79 * a better job of detaching property from mode objects to avoid
80 * dangling property pointers:
81 */
82 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
Daniel Vettera2511a52016-08-29 10:27:53 +020083
84 /**
85 * @values: Array to store the property values, matching @properties. Do
86 * not read/write values directly, but use
87 * drm_object_property_get_value() and drm_object_property_set_value().
88 *
89 * Note that atomic drivers do not store mutable properties in this
90 * array, but only the decoded values in the corresponding state
Daniel Vetterd5745282017-01-25 07:26:45 +010091 * structure. The decoding is done using the &drm_crtc.atomic_get_property and
92 * &drm_crtc.atomic_set_property hooks for &struct drm_crtc. For
93 * &struct drm_plane the hooks are &drm_plane_funcs.atomic_get_property and
94 * &drm_plane_funcs.atomic_set_property. And for &struct drm_connector
95 * the hooks are &drm_connector_funcs.atomic_get_property and
96 * &drm_connector_funcs.atomic_set_property .
97 *
98 * Hence atomic drivers should not use drm_object_property_set_value()
99 * and drm_object_property_get_value() on mutable objects, i.e. those
Daniel Vettera2511a52016-08-29 10:27:53 +0200100 * without the DRM_MODE_PROP_IMMUTABLE flag set.
Daniel Vetter52217192016-08-12 22:48:50 +0200101 */
102 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
103};
104
105/* Avoid boilerplate. I'm tired of typing. */
106#define DRM_ENUM_NAME_FN(fnname, list) \
107 const char *fnname(int val) \
108 { \
109 int i; \
110 for (i = 0; i < ARRAY_SIZE(list); i++) { \
111 if (list[i].type == val) \
112 return list[i].name; \
113 } \
114 return "(unknown)"; \
115 }
116
Daniel Vetter7520a272016-08-15 16:07:02 +0200117struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
Keith Packard418da172017-03-14 23:25:07 -0700118 struct drm_file *file_priv,
Daniel Vetter7520a272016-08-15 16:07:02 +0200119 uint32_t id, uint32_t type);
Thierry Reding020a2182017-02-28 15:46:38 +0100120void drm_mode_object_get(struct drm_mode_object *obj);
121void drm_mode_object_put(struct drm_mode_object *obj);
122
Daniel Vetter949619f2016-08-29 10:27:51 +0200123int drm_object_property_set_value(struct drm_mode_object *obj,
124 struct drm_property *property,
125 uint64_t val);
126int drm_object_property_get_value(struct drm_mode_object *obj,
127 struct drm_property *property,
128 uint64_t *value);
129
130void drm_object_attach_property(struct drm_mode_object *obj,
131 struct drm_property *property,
132 uint64_t init_val);
Keith Packard62884cd2017-03-16 17:56:28 -0700133
134bool drm_mode_object_lease_required(uint32_t type);
Daniel Vetter7520a272016-08-15 16:07:02 +0200135#endif