1 1.1 riastrad /* $NetBSD: drm_property.h,v 1.2 2021/12/18 23:45:46 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright (c) 2016 Intel Corporation 5 1.1 riastrad * 6 1.1 riastrad * Permission to use, copy, modify, distribute, and sell this software and its 7 1.1 riastrad * documentation for any purpose is hereby granted without fee, provided that 8 1.1 riastrad * the above copyright notice appear in all copies and that both that copyright 9 1.1 riastrad * notice and this permission notice appear in supporting documentation, and 10 1.1 riastrad * that the name of the copyright holders not be used in advertising or 11 1.1 riastrad * publicity pertaining to distribution of the software without specific, 12 1.1 riastrad * written prior permission. The copyright holders make no representations 13 1.1 riastrad * about the suitability of this software for any purpose. It is provided "as 14 1.1 riastrad * is" without express or implied warranty. 15 1.1 riastrad * 16 1.1 riastrad * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 17 1.1 riastrad * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 18 1.1 riastrad * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 19 1.1 riastrad * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 20 1.1 riastrad * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 21 1.1 riastrad * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 22 1.1 riastrad * OF THIS SOFTWARE. 23 1.1 riastrad */ 24 1.1 riastrad 25 1.1 riastrad #ifndef __DRM_PROPERTY_H__ 26 1.1 riastrad #define __DRM_PROPERTY_H__ 27 1.1 riastrad 28 1.1 riastrad #include <linux/list.h> 29 1.1 riastrad #include <linux/ctype.h> 30 1.1 riastrad #include <drm/drm_mode_object.h> 31 1.1 riastrad 32 1.1 riastrad #include <uapi/drm/drm_mode.h> 33 1.1 riastrad 34 1.1 riastrad /** 35 1.1 riastrad * struct drm_property_enum - symbolic values for enumerations 36 1.1 riastrad * @value: numeric property value for this enum entry 37 1.1 riastrad * @head: list of enum values, linked to &drm_property.enum_list 38 1.1 riastrad * @name: symbolic name for the enum 39 1.1 riastrad * 40 1.1 riastrad * For enumeration and bitmask properties this structure stores the symbolic 41 1.1 riastrad * decoding for each value. This is used for example for the rotation property. 42 1.1 riastrad */ 43 1.1 riastrad struct drm_property_enum { 44 1.1 riastrad uint64_t value; 45 1.1 riastrad struct list_head head; 46 1.1 riastrad char name[DRM_PROP_NAME_LEN]; 47 1.1 riastrad }; 48 1.1 riastrad 49 1.1 riastrad /** 50 1.1 riastrad * struct drm_property - modeset object property 51 1.1 riastrad * 52 1.1 riastrad * This structure represent a modeset object property. It combines both the name 53 1.1 riastrad * of the property with the set of permissible values. This means that when a 54 1.1 riastrad * driver wants to use a property with the same name on different objects, but 55 1.1 riastrad * with different value ranges, then it must create property for each one. An 56 1.1 riastrad * example would be rotation of &drm_plane, when e.g. the primary plane cannot 57 1.1 riastrad * be rotated. But if both the name and the value range match, then the same 58 1.1 riastrad * property structure can be instantiated multiple times for the same object. 59 1.1 riastrad * Userspace must be able to cope with this and cannot assume that the same 60 1.1 riastrad * symbolic property will have the same modeset object ID on all modeset 61 1.1 riastrad * objects. 62 1.1 riastrad * 63 1.1 riastrad * Properties are created by one of the special functions, as explained in 64 1.1 riastrad * detail in the @flags structure member. 65 1.1 riastrad * 66 1.1 riastrad * To actually expose a property it must be attached to each object using 67 1.1 riastrad * drm_object_attach_property(). Currently properties can only be attached to 68 1.1 riastrad * &drm_connector, &drm_crtc and &drm_plane. 69 1.1 riastrad * 70 1.1 riastrad * Properties are also used as the generic metadatatransport for the atomic 71 1.1 riastrad * IOCTL. Everything that was set directly in structures in the legacy modeset 72 1.1 riastrad * IOCTLs (like the plane source or destination windows, or e.g. the links to 73 1.1 riastrad * the CRTC) is exposed as a property with the DRM_MODE_PROP_ATOMIC flag set. 74 1.1 riastrad */ 75 1.1 riastrad struct drm_property { 76 1.1 riastrad /** 77 1.1 riastrad * @head: per-device list of properties, for cleanup. 78 1.1 riastrad */ 79 1.1 riastrad struct list_head head; 80 1.1 riastrad 81 1.1 riastrad /** 82 1.1 riastrad * @base: base KMS object 83 1.1 riastrad */ 84 1.1 riastrad struct drm_mode_object base; 85 1.1 riastrad 86 1.1 riastrad /** 87 1.1 riastrad * @flags: 88 1.1 riastrad * 89 1.1 riastrad * Property flags and type. A property needs to be one of the following 90 1.1 riastrad * types: 91 1.1 riastrad * 92 1.1 riastrad * DRM_MODE_PROP_RANGE 93 1.1 riastrad * Range properties report their minimum and maximum admissible unsigned values. 94 1.1 riastrad * The KMS core verifies that values set by application fit in that 95 1.1 riastrad * range. The range is unsigned. Range properties are created using 96 1.1 riastrad * drm_property_create_range(). 97 1.1 riastrad * 98 1.1 riastrad * DRM_MODE_PROP_SIGNED_RANGE 99 1.1 riastrad * Range properties report their minimum and maximum admissible unsigned values. 100 1.1 riastrad * The KMS core verifies that values set by application fit in that 101 1.1 riastrad * range. The range is signed. Range properties are created using 102 1.1 riastrad * drm_property_create_signed_range(). 103 1.1 riastrad * 104 1.1 riastrad * DRM_MODE_PROP_ENUM 105 1.1 riastrad * Enumerated properties take a numerical value that ranges from 0 to 106 1.1 riastrad * the number of enumerated values defined by the property minus one, 107 1.1 riastrad * and associate a free-formed string name to each value. Applications 108 1.1 riastrad * can retrieve the list of defined value-name pairs and use the 109 1.1 riastrad * numerical value to get and set property instance values. Enum 110 1.1 riastrad * properties are created using drm_property_create_enum(). 111 1.1 riastrad * 112 1.1 riastrad * DRM_MODE_PROP_BITMASK 113 1.1 riastrad * Bitmask properties are enumeration properties that additionally 114 1.1 riastrad * restrict all enumerated values to the 0..63 range. Bitmask property 115 1.1 riastrad * instance values combine one or more of the enumerated bits defined 116 1.1 riastrad * by the property. Bitmask properties are created using 117 1.1 riastrad * drm_property_create_bitmask(). 118 1.1 riastrad * 119 1.1 riastrad * DRM_MODE_PROB_OBJECT 120 1.1 riastrad * Object properties are used to link modeset objects. This is used 121 1.1 riastrad * extensively in the atomic support to create the display pipeline, 122 1.1 riastrad * by linking &drm_framebuffer to &drm_plane, &drm_plane to 123 1.1 riastrad * &drm_crtc and &drm_connector to &drm_crtc. An object property can 124 1.1 riastrad * only link to a specific type of &drm_mode_object, this limit is 125 1.1 riastrad * enforced by the core. Object properties are created using 126 1.1 riastrad * drm_property_create_object(). 127 1.1 riastrad * 128 1.1 riastrad * Object properties work like blob properties, but in a more 129 1.1 riastrad * general fashion. They are limited to atomic drivers and must have 130 1.1 riastrad * the DRM_MODE_PROP_ATOMIC flag set. 131 1.1 riastrad * 132 1.1 riastrad * DRM_MODE_PROP_BLOB 133 1.1 riastrad * Blob properties store a binary blob without any format restriction. 134 1.1 riastrad * The binary blobs are created as KMS standalone objects, and blob 135 1.1 riastrad * property instance values store the ID of their associated blob 136 1.1 riastrad * object. Blob properties are created by calling 137 1.1 riastrad * drm_property_create() with DRM_MODE_PROP_BLOB as the type. 138 1.1 riastrad * 139 1.1 riastrad * Actual blob objects to contain blob data are created using 140 1.1 riastrad * drm_property_create_blob(), or through the corresponding IOCTL. 141 1.1 riastrad * 142 1.1 riastrad * Besides the built-in limit to only accept blob objects blob 143 1.1 riastrad * properties work exactly like object properties. The only reasons 144 1.1 riastrad * blob properties exist is backwards compatibility with existing 145 1.1 riastrad * userspace. 146 1.1 riastrad * 147 1.1 riastrad * In addition a property can have any combination of the below flags: 148 1.1 riastrad * 149 1.1 riastrad * DRM_MODE_PROP_ATOMIC 150 1.1 riastrad * Set for properties which encode atomic modeset state. Such 151 1.1 riastrad * properties are not exposed to legacy userspace. 152 1.1 riastrad * 153 1.1 riastrad * DRM_MODE_PROP_IMMUTABLE 154 1.1 riastrad * Set for properties whose values cannot be changed by 155 1.1 riastrad * userspace. The kernel is allowed to update the value of these 156 1.1 riastrad * properties. This is generally used to expose probe state to 157 1.1 riastrad * userspace, e.g. the EDID, or the connector path property on DP 158 1.1 riastrad * MST sinks. Kernel can update the value of an immutable property 159 1.1 riastrad * by calling drm_object_property_set_value(). 160 1.1 riastrad */ 161 1.1 riastrad uint32_t flags; 162 1.1 riastrad 163 1.1 riastrad /** 164 1.1 riastrad * @name: symbolic name of the properties 165 1.1 riastrad */ 166 1.1 riastrad char name[DRM_PROP_NAME_LEN]; 167 1.1 riastrad 168 1.1 riastrad /** 169 1.1 riastrad * @num_values: size of the @values array. 170 1.1 riastrad */ 171 1.1 riastrad uint32_t num_values; 172 1.1 riastrad 173 1.1 riastrad /** 174 1.1 riastrad * @values: 175 1.1 riastrad * 176 1.1 riastrad * Array with limits and values for the property. The 177 1.1 riastrad * interpretation of these limits is dependent upon the type per @flags. 178 1.1 riastrad */ 179 1.1 riastrad uint64_t *values; 180 1.1 riastrad 181 1.1 riastrad /** 182 1.1 riastrad * @dev: DRM device 183 1.1 riastrad */ 184 1.1 riastrad struct drm_device *dev; 185 1.1 riastrad 186 1.1 riastrad /** 187 1.1 riastrad * @enum_list: 188 1.1 riastrad * 189 1.1 riastrad * List of &drm_prop_enum_list structures with the symbolic names for 190 1.1 riastrad * enum and bitmask values. 191 1.1 riastrad */ 192 1.1 riastrad struct list_head enum_list; 193 1.1 riastrad }; 194 1.1 riastrad 195 1.1 riastrad /** 196 1.1 riastrad * struct drm_property_blob - Blob data for &drm_property 197 1.1 riastrad * @base: base KMS object 198 1.1 riastrad * @dev: DRM device 199 1.1 riastrad * @head_global: entry on the global blob list in 200 1.1 riastrad * &drm_mode_config.property_blob_list. 201 1.1 riastrad * @head_file: entry on the per-file blob list in &drm_file.blobs list. 202 1.1 riastrad * @length: size of the blob in bytes, invariant over the lifetime of the object 203 1.1 riastrad * @data: actual data, embedded at the end of this structure 204 1.1 riastrad * 205 1.1 riastrad * Blobs are used to store bigger values than what fits directly into the 64 206 1.1 riastrad * bits available for a &drm_property. 207 1.1 riastrad * 208 1.1 riastrad * Blobs are reference counted using drm_property_blob_get() and 209 1.1 riastrad * drm_property_blob_put(). They are created using drm_property_create_blob(). 210 1.1 riastrad */ 211 1.1 riastrad struct drm_property_blob { 212 1.1 riastrad struct drm_mode_object base; 213 1.1 riastrad struct drm_device *dev; 214 1.1 riastrad struct list_head head_global; 215 1.1 riastrad struct list_head head_file; 216 1.1 riastrad size_t length; 217 1.1 riastrad void *data; 218 1.1 riastrad }; 219 1.1 riastrad 220 1.1 riastrad struct drm_prop_enum_list { 221 1.1 riastrad int type; 222 1.1 riastrad const char *name; 223 1.1 riastrad }; 224 1.1 riastrad 225 1.1 riastrad #define obj_to_property(x) container_of(x, struct drm_property, base) 226 1.1 riastrad #define obj_to_blob(x) container_of(x, struct drm_property_blob, base) 227 1.1 riastrad 228 1.1 riastrad /** 229 1.1 riastrad * drm_property_type_is - check the type of a property 230 1.1 riastrad * @property: property to check 231 1.1 riastrad * @type: property type to compare with 232 1.1 riastrad * 233 1.1 riastrad * This is a helper function becauase the uapi encoding of property types is 234 1.1 riastrad * a bit special for historical reasons. 235 1.1 riastrad */ 236 1.1 riastrad static inline bool drm_property_type_is(struct drm_property *property, 237 1.1 riastrad uint32_t type) 238 1.1 riastrad { 239 1.1 riastrad /* instanceof for props.. handles extended type vs original types: */ 240 1.1 riastrad if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) 241 1.1 riastrad return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type; 242 1.1 riastrad return property->flags & type; 243 1.1 riastrad } 244 1.1 riastrad 245 1.1 riastrad struct drm_property *drm_property_create(struct drm_device *dev, 246 1.1 riastrad u32 flags, const char *name, 247 1.1 riastrad int num_values); 248 1.1 riastrad struct drm_property *drm_property_create_enum(struct drm_device *dev, 249 1.1 riastrad u32 flags, const char *name, 250 1.1 riastrad const struct drm_prop_enum_list *props, 251 1.1 riastrad int num_values); 252 1.1 riastrad struct drm_property *drm_property_create_bitmask(struct drm_device *dev, 253 1.1 riastrad u32 flags, const char *name, 254 1.1 riastrad const struct drm_prop_enum_list *props, 255 1.1 riastrad int num_props, 256 1.1 riastrad uint64_t supported_bits); 257 1.1 riastrad struct drm_property *drm_property_create_range(struct drm_device *dev, 258 1.1 riastrad u32 flags, const char *name, 259 1.1 riastrad uint64_t min, uint64_t max); 260 1.1 riastrad struct drm_property *drm_property_create_signed_range(struct drm_device *dev, 261 1.1 riastrad u32 flags, const char *name, 262 1.1 riastrad int64_t min, int64_t max); 263 1.1 riastrad struct drm_property *drm_property_create_object(struct drm_device *dev, 264 1.1 riastrad u32 flags, const char *name, 265 1.1 riastrad uint32_t type); 266 1.1 riastrad struct drm_property *drm_property_create_bool(struct drm_device *dev, 267 1.1 riastrad u32 flags, const char *name); 268 1.1 riastrad int drm_property_add_enum(struct drm_property *property, 269 1.1 riastrad uint64_t value, const char *name); 270 1.1 riastrad void drm_property_destroy(struct drm_device *dev, struct drm_property *property); 271 1.1 riastrad 272 1.1 riastrad struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, 273 1.1 riastrad size_t length, 274 1.1 riastrad const void *data); 275 1.1 riastrad struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev, 276 1.1 riastrad uint32_t id); 277 1.1 riastrad int drm_property_replace_global_blob(struct drm_device *dev, 278 1.1 riastrad struct drm_property_blob **replace, 279 1.1 riastrad size_t length, 280 1.1 riastrad const void *data, 281 1.1 riastrad struct drm_mode_object *obj_holds_id, 282 1.1 riastrad struct drm_property *prop_holds_id); 283 1.1 riastrad bool drm_property_replace_blob(struct drm_property_blob **blob, 284 1.1 riastrad struct drm_property_blob *new_blob); 285 1.1 riastrad struct drm_property_blob *drm_property_blob_get(struct drm_property_blob *blob); 286 1.1 riastrad void drm_property_blob_put(struct drm_property_blob *blob); 287 1.1 riastrad 288 1.1 riastrad /** 289 1.1 riastrad * drm_property_find - find property object 290 1.1 riastrad * @dev: DRM device 291 1.1 riastrad * @file_priv: drm file to check for lease against. 292 1.1 riastrad * @id: property object id 293 1.1 riastrad * 294 1.1 riastrad * This function looks up the property object specified by id and returns it. 295 1.1 riastrad */ 296 1.1 riastrad static inline struct drm_property *drm_property_find(struct drm_device *dev, 297 1.1 riastrad struct drm_file *file_priv, 298 1.1 riastrad uint32_t id) 299 1.1 riastrad { 300 1.1 riastrad struct drm_mode_object *mo; 301 1.1 riastrad mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PROPERTY); 302 1.1 riastrad return mo ? obj_to_property(mo) : NULL; 303 1.1 riastrad } 304 1.1 riastrad 305 1.1 riastrad #endif 306