Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Copyright (c) 2016 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Permission to use, copy, modify, distribute, and sell this software and its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * documentation for any purpose is hereby granted without fee, provided that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * the above copyright notice appear in all copies and that both that copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * notice and this permission notice appear in supporting documentation, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * that the name of the copyright holders not be used in advertising or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * publicity pertaining to distribution of the software without specific,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * written prior permission.  The copyright holders make no representations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * about the suitability of this software for any purpose.  It is provided "as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * is" without express or implied warranty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * OF THIS SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <drm/drm_crtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <drm/drm_drv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <drm/drm_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <drm/drm_framebuffer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <drm/drm_property.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include "drm_crtc_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * DOC: overview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * Properties as represented by &drm_property are used to extend the modeset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * interface exposed to userspace. For the atomic modeset IOCTL properties are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * even the only way to transport metadata about the desired new modeset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * configuration from userspace to the kernel. Properties have a well-defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * value range, which is enforced by the drm core. See the documentation of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * flags member of &struct drm_property for an overview of the different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * property types and ranges.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * Properties don't store the current value directly, but need to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * instatiated by attaching them to a &drm_mode_object with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * drm_object_attach_property().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Property values are only 64bit. To support bigger piles of data (like gamma
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * tables, color correction matrices or large structures) a property can instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * point at a &drm_property_blob with that additional data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * Properties are defined by their symbolic name, userspace must keep a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * per-object mapping from those names to the property ID used in the atomic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * IOCTL and in the get/set property IOCTL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static bool drm_property_flags_valid(u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	u32 legacy_type = flags & DRM_MODE_PROP_LEGACY_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	u32 ext_type = flags & DRM_MODE_PROP_EXTENDED_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	/* Reject undefined/deprecated flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (flags & ~(DRM_MODE_PROP_LEGACY_TYPE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		      DRM_MODE_PROP_EXTENDED_TYPE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		      DRM_MODE_PROP_IMMUTABLE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		      DRM_MODE_PROP_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/* We want either a legacy type or an extended type, but not both */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (!legacy_type == !ext_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/* Only one legacy type at a time please */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (legacy_type && !is_power_of_2(legacy_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * drm_property_create - create a new property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * @flags: flags specifying the property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * @name: name of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * @num_values: number of pre-defined values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * This creates a new generic drm property which can then be attached to a drm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * object with drm_object_attach_property(). The returned property object must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * be freed with drm_property_destroy(), which is done automatically when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * calling drm_mode_config_cleanup().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * A pointer to the newly created property on success, NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) struct drm_property *drm_property_create(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 					 u32 flags, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 					 int num_values)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct drm_property *property = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (WARN_ON(!drm_property_flags_valid(flags)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (WARN_ON(strlen(name) >= DRM_PROP_NAME_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	property = kzalloc(sizeof(struct drm_property), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (!property)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	property->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (num_values) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		property->values = kcalloc(num_values, sizeof(uint64_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 					   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (!property->values)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	ret = drm_mode_object_add(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	property->flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	property->num_values = num_values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	INIT_LIST_HEAD(&property->enum_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	strncpy(property->name, name, DRM_PROP_NAME_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	property->name[DRM_PROP_NAME_LEN-1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	list_add_tail(&property->head, &dev->mode_config.property_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	kfree(property->values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	kfree(property);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) EXPORT_SYMBOL(drm_property_create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * drm_property_create_enum - create a new enumeration property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * @flags: flags specifying the property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * @name: name of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * @props: enumeration lists with property values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * @num_values: number of pre-defined values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * This creates a new generic drm property which can then be attached to a drm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * object with drm_object_attach_property(). The returned property object must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * be freed with drm_property_destroy(), which is done automatically when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * calling drm_mode_config_cleanup().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * Userspace is only allowed to set one of the predefined values for enumeration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * properties.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * A pointer to the newly created property on success, NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct drm_property *drm_property_create_enum(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 					      u32 flags, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 					      const struct drm_prop_enum_list *props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 					      int num_values)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct drm_property *property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	flags |= DRM_MODE_PROP_ENUM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	property = drm_property_create(dev, flags, name, num_values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (!property)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	for (i = 0; i < num_values; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		ret = drm_property_add_enum(property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 					    props[i].type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 					    props[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			drm_property_destroy(dev, property);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) EXPORT_SYMBOL(drm_property_create_enum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * drm_property_create_bitmask - create a new bitmask property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * @flags: flags specifying the property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * @name: name of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * @props: enumeration lists with property bitflags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * @num_props: size of the @props array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * @supported_bits: bitmask of all supported enumeration values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * This creates a new bitmask drm property which can then be attached to a drm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * object with drm_object_attach_property(). The returned property object must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * be freed with drm_property_destroy(), which is done automatically when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * calling drm_mode_config_cleanup().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * Compared to plain enumeration properties userspace is allowed to set any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * or'ed together combination of the predefined property bitflag values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * A pointer to the newly created property on success, NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 						 u32 flags, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 						 const struct drm_prop_enum_list *props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 						 int num_props,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 						 uint64_t supported_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct drm_property *property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	int num_values = hweight64(supported_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	flags |= DRM_MODE_PROP_BITMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	property = drm_property_create(dev, flags, name, num_values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (!property)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	for (i = 0; i < num_props; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		if (!(supported_bits & (1ULL << props[i].type)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		ret = drm_property_add_enum(property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 					    props[i].type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 					    props[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			drm_property_destroy(dev, property);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	return property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) EXPORT_SYMBOL(drm_property_create_bitmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static struct drm_property *property_create_range(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 						  u32 flags, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 						  uint64_t min, uint64_t max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	struct drm_property *property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	property = drm_property_create(dev, flags, name, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (!property)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	property->values[0] = min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	property->values[1] = max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	return property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  * drm_property_create_range - create a new unsigned ranged property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * @flags: flags specifying the property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  * @name: name of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * @min: minimum value of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * @max: maximum value of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * This creates a new generic drm property which can then be attached to a drm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * object with drm_object_attach_property(). The returned property object must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * be freed with drm_property_destroy(), which is done automatically when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * calling drm_mode_config_cleanup().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  * Userspace is allowed to set any unsigned integer value in the (min, max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  * range inclusive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  * A pointer to the newly created property on success, NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct drm_property *drm_property_create_range(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 					       u32 flags, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 					       uint64_t min, uint64_t max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return property_create_range(dev, DRM_MODE_PROP_RANGE | flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			name, min, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) EXPORT_SYMBOL(drm_property_create_range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  * drm_property_create_signed_range - create a new signed ranged property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  * @flags: flags specifying the property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  * @name: name of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * @min: minimum value of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * @max: maximum value of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  * This creates a new generic drm property which can then be attached to a drm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  * object with drm_object_attach_property(). The returned property object must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  * be freed with drm_property_destroy(), which is done automatically when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  * calling drm_mode_config_cleanup().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * Userspace is allowed to set any signed integer value in the (min, max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * range inclusive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * A pointer to the newly created property on success, NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 						      u32 flags, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 						      int64_t min, int64_t max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	return property_create_range(dev, DRM_MODE_PROP_SIGNED_RANGE | flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			name, I642U64(min), I642U64(max));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) EXPORT_SYMBOL(drm_property_create_signed_range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  * drm_property_create_object - create a new object property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  * @flags: flags specifying the property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * @name: name of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * @type: object type from DRM_MODE_OBJECT_* defines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * This creates a new generic drm property which can then be attached to a drm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * object with drm_object_attach_property(). The returned property object must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * be freed with drm_property_destroy(), which is done automatically when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * calling drm_mode_config_cleanup().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * Userspace is only allowed to set this to any property value of the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * @type. Only useful for atomic properties, which is enforced.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  * A pointer to the newly created property on success, NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct drm_property *drm_property_create_object(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 						u32 flags, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 						uint32_t type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct drm_property *property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	flags |= DRM_MODE_PROP_OBJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (WARN_ON(!(flags & DRM_MODE_PROP_ATOMIC)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	property = drm_property_create(dev, flags, name, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	if (!property)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	property->values[0] = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	return property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) EXPORT_SYMBOL(drm_property_create_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * drm_property_create_bool - create a new boolean property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * @flags: flags specifying the property type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  * @name: name of the property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  * This creates a new generic drm property which can then be attached to a drm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  * object with drm_object_attach_property(). The returned property object must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  * be freed with drm_property_destroy(), which is done automatically when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  * calling drm_mode_config_cleanup().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)  * This is implemented as a ranged property with only {0, 1} as valid values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)  * A pointer to the newly created property on success, NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct drm_property *drm_property_create_bool(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 					      u32 flags, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	return drm_property_create_range(dev, flags, name, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) EXPORT_SYMBOL(drm_property_create_bool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  * drm_property_add_enum - add a possible value to an enumeration property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  * @property: enumeration property to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)  * @value: value of the new enumeration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  * @name: symbolic name of the new enumeration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  * This functions adds enumerations to a property.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  * It's use is deprecated, drivers should use one of the more specific helpers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)  * to directly create the property with all enumerations already attached.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  * Zero on success, error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) int drm_property_add_enum(struct drm_property *property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			  uint64_t value, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	struct drm_property_enum *prop_enum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	int index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (WARN_ON(strlen(name) >= DRM_PROP_NAME_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	if (WARN_ON(!drm_property_type_is(property, DRM_MODE_PROP_ENUM) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		    !drm_property_type_is(property, DRM_MODE_PROP_BITMASK)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	 * Bitmask enum properties have the additional constraint of values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	 * from 0 to 63
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	if (WARN_ON(drm_property_type_is(property, DRM_MODE_PROP_BITMASK) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		    value > 63))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	list_for_each_entry(prop_enum, &property->enum_list, head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		if (WARN_ON(prop_enum->value == value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	if (WARN_ON(index >= property->num_values))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (!prop_enum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	prop_enum->value = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	property->values[index] = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	list_add_tail(&prop_enum->head, &property->enum_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) EXPORT_SYMBOL(drm_property_add_enum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  * drm_property_destroy - destroy a drm property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  * @property: property to destry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  * This function frees a property including any attached resources like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)  * enumeration values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) void drm_property_destroy(struct drm_device *dev, struct drm_property *property)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	struct drm_property_enum *prop_enum, *pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	list_for_each_entry_safe(prop_enum, pt, &property->enum_list, head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		list_del(&prop_enum->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		kfree(prop_enum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	if (property->num_values)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		kfree(property->values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	drm_mode_object_unregister(dev, &property->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	list_del(&property->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	kfree(property);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) EXPORT_SYMBOL(drm_property_destroy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) int drm_mode_getproperty_ioctl(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 			       void *data, struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	struct drm_mode_get_property *out_resp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	struct drm_property *property;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	int enum_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	int value_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	int i, copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	struct drm_property_enum *prop_enum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	struct drm_mode_property_enum __user *enum_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	uint64_t __user *values_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	property = drm_property_find(dev, file_priv, out_resp->prop_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	if (!property)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	out_resp->name[DRM_PROP_NAME_LEN-1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	out_resp->flags = property->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	value_count = property->num_values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	values_ptr = u64_to_user_ptr(out_resp->values_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	for (i = 0; i < value_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		if (i < out_resp->count_values &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		    put_user(property->values[i], values_ptr + i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	out_resp->count_values = value_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	copied = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	enum_ptr = u64_to_user_ptr(out_resp->enum_blob_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	    drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		list_for_each_entry(prop_enum, &property->enum_list, head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			enum_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			if (out_resp->count_enum_blobs < enum_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 			if (copy_to_user(&enum_ptr[copied].value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 					 &prop_enum->value, sizeof(uint64_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			if (copy_to_user(&enum_ptr[copied].name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 					 &prop_enum->name, DRM_PROP_NAME_LEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			copied++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		out_resp->count_enum_blobs = enum_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	 * NOTE: The idea seems to have been to use this to read all the blob
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	 * property values. But nothing ever added them to the corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	 * list, userspace always used the special-purpose get_blob ioctl to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	 * read the value for a blob property. It also doesn't make a lot of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	 * sense to return values here when everything else is just metadata for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	 * the property itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	if (drm_property_type_is(property, DRM_MODE_PROP_BLOB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		out_resp->count_enum_blobs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) static void drm_property_free_blob(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	struct drm_property_blob *blob =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		container_of(kref, struct drm_property_blob, base.refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	mutex_lock(&blob->dev->mode_config.blob_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	list_del(&blob->head_global);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	mutex_unlock(&blob->dev->mode_config.blob_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	drm_mode_object_unregister(blob->dev, &blob->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	kvfree(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)  * drm_property_create_blob - Create new blob property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)  * @dev: DRM device to create property for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)  * @length: Length to allocate for blob data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)  * @data: If specified, copies data into blob
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)  * Creates a new blob property for a specified DRM device, optionally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)  * copying data. Note that blob properties are meant to be invariant, hence the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)  * data must be filled out before the blob is used as the value of any property.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)  * New blob property with a single reference on success, or an ERR_PTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)  * value on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct drm_property_blob *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) drm_property_create_blob(struct drm_device *dev, size_t length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 			 const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	struct drm_property_blob *blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	if (!length || length > INT_MAX - sizeof(struct drm_property_blob))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	blob = kvzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	if (!blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	/* This must be explicitly initialised, so we can safely call list_del
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	 * on it in the removal handler, even if it isn't in a file list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	INIT_LIST_HEAD(&blob->head_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	blob->data = (void *)blob + sizeof(*blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	blob->length = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	blob->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	if (data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		memcpy(blob->data, data, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	ret = __drm_mode_object_add(dev, &blob->base, DRM_MODE_OBJECT_BLOB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 				    true, drm_property_free_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		kvfree(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	mutex_lock(&dev->mode_config.blob_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	list_add_tail(&blob->head_global,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	              &dev->mode_config.property_blob_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	mutex_unlock(&dev->mode_config.blob_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	return blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) EXPORT_SYMBOL(drm_property_create_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)  * drm_property_blob_put - release a blob property reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)  * @blob: DRM blob property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)  * Releases a reference to a blob property. May free the object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) void drm_property_blob_put(struct drm_property_blob *blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	if (!blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	drm_mode_object_put(&blob->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) EXPORT_SYMBOL(drm_property_blob_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) void drm_property_destroy_user_blobs(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 				     struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	struct drm_property_blob *blob, *bt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	 * When the file gets released that means no one else can access the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	 * blob list any more, so no need to grab dev->blob_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	list_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		list_del_init(&blob->head_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 		drm_property_blob_put(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)  * drm_property_blob_get - acquire blob property reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)  * @blob: DRM blob property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)  * Acquires a reference to an existing blob property. Returns @blob, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)  * allows this to be used as a shorthand in assignments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) struct drm_property_blob *drm_property_blob_get(struct drm_property_blob *blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	drm_mode_object_get(&blob->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	return blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) EXPORT_SYMBOL(drm_property_blob_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)  * drm_property_lookup_blob - look up a blob property and take a reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)  * @id: id of the blob property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)  * If successful, this takes an additional reference to the blob property.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)  * callers need to make sure to eventually unreference the returned property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)  * again, using drm_property_blob_put().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)  * Return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)  * NULL on failure, pointer to the blob on success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 					           uint32_t id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	struct drm_mode_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	struct drm_property_blob *blob = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	obj = __drm_mode_object_find(dev, NULL, id, DRM_MODE_OBJECT_BLOB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	if (obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		blob = obj_to_blob(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	return blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) EXPORT_SYMBOL(drm_property_lookup_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)  * drm_property_replace_global_blob - replace existing blob property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)  * @dev: drm device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)  * @replace: location of blob property pointer to be replaced
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)  * @length: length of data for new blob, or 0 for no data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)  * @data: content for new blob, or NULL for no data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)  * @obj_holds_id: optional object for property holding blob ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)  * @prop_holds_id: optional property holding blob ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)  * @return 0 on success or error on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)  * This function will replace a global property in the blob list, optionally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)  * updating a property which holds the ID of that property.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)  * If length is 0 or data is NULL, no new blob will be created, and the holding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)  * property, if specified, will be set to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)  * Access to the replace pointer is assumed to be protected by the caller, e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)  * by holding the relevant modesetting object lock for its parent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)  * For example, a drm_connector has a 'PATH' property, which contains the ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)  * of a blob property with the value of the MST path information. Calling this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)  * function with replace pointing to the connector's path_blob_ptr, length and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)  * data set for the new path information, obj_holds_id set to the connector's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)  * base object, and prop_holds_id set to the path property name, will perform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)  * a completely atomic update. The access to path_blob_ptr is protected by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)  * caller holding a lock on the connector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) int drm_property_replace_global_blob(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 				     struct drm_property_blob **replace,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 				     size_t length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 				     const void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 				     struct drm_mode_object *obj_holds_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 				     struct drm_property *prop_holds_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	struct drm_property_blob *new_blob = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	struct drm_property_blob *old_blob = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	WARN_ON(replace == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	old_blob = *replace;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	if (length && data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 		new_blob = drm_property_create_blob(dev, length, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		if (IS_ERR(new_blob))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 			return PTR_ERR(new_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	if (obj_holds_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		ret = drm_object_property_set_value(obj_holds_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 						    prop_holds_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 						    new_blob ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 						        new_blob->base.id : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 		if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 			goto err_created;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	drm_property_blob_put(old_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	*replace = new_blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) err_created:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	drm_property_blob_put(new_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) EXPORT_SYMBOL(drm_property_replace_global_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)  * drm_property_replace_blob - replace a blob property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)  * @blob: a pointer to the member blob to be replaced
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)  * @new_blob: the new blob to replace with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)  * Return: true if the blob was in fact replaced.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) bool drm_property_replace_blob(struct drm_property_blob **blob,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 			       struct drm_property_blob *new_blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	struct drm_property_blob *old_blob = *blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	if (old_blob == new_blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	drm_property_blob_put(old_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	if (new_blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 		drm_property_blob_get(new_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	*blob = new_blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) EXPORT_SYMBOL(drm_property_replace_blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) int drm_mode_getblob_ioctl(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 			   void *data, struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	struct drm_mode_get_blob *out_resp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	struct drm_property_blob *blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 	blob = drm_property_lookup_blob(dev, out_resp->blob_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	if (!blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 	if (out_resp->length == blob->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 		if (copy_to_user(u64_to_user_ptr(out_resp->data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 				 blob->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 				 blob->length)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 			goto unref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	out_resp->length = blob->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) unref:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 	drm_property_blob_put(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) int drm_mode_createblob_ioctl(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 			      void *data, struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	struct drm_mode_create_blob *out_resp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	struct drm_property_blob *blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	blob = drm_property_create_blob(dev, out_resp->length, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	if (IS_ERR(blob))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 		return PTR_ERR(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	if (copy_from_user(blob->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 			   u64_to_user_ptr(out_resp->data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 			   out_resp->length)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 		ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 		goto out_blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	/* Dropping the lock between create_blob and our access here is safe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 	 * as only the same file_priv can remove the blob; at this point, it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 	 * not associated with any file_priv. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	mutex_lock(&dev->mode_config.blob_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 	out_resp->blob_id = blob->base.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	list_add_tail(&blob->head_file, &file_priv->blobs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	mutex_unlock(&dev->mode_config.blob_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) out_blob:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	drm_property_blob_put(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) int drm_mode_destroyblob_ioctl(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 			       void *data, struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	struct drm_mode_destroy_blob *out_resp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	struct drm_property_blob *blob = NULL, *bt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	blob = drm_property_lookup_blob(dev, out_resp->blob_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	if (!blob)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	mutex_lock(&dev->mode_config.blob_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	/* Ensure the property was actually created by this user. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	list_for_each_entry(bt, &file_priv->blobs, head_file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		if (bt == blob) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 			found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 		ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 	/* We must drop head_file here, because we may not be the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 	 * reference on the blob. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	list_del_init(&blob->head_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	mutex_unlock(&dev->mode_config.blob_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	/* One reference from lookup, and one from the filp. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) 	drm_property_blob_put(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 	drm_property_blob_put(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	mutex_unlock(&dev->mode_config.blob_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 	drm_property_blob_put(blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) /* Some properties could refer to dynamic refcnt'd objects, or things that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)  * need special locking to handle lifetime issues (ie. to ensure the prop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)  * value doesn't become invalid part way through the property update due to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)  * race).  The value returned by reference via 'obj' should be passed back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)  * to drm_property_change_valid_put() after the property is set (and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)  * object to which the property is attached has a chance to take its own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)  * reference).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) bool drm_property_change_valid_get(struct drm_property *property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 				   uint64_t value, struct drm_mode_object **ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 	if (property->flags & DRM_MODE_PROP_IMMUTABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	*ref = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	if (drm_property_type_is(property, DRM_MODE_PROP_RANGE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 		if (value < property->values[0] || value > property->values[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 	} else if (drm_property_type_is(property, DRM_MODE_PROP_SIGNED_RANGE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 		int64_t svalue = U642I64(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 		if (svalue < U642I64(property->values[0]) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 				svalue > U642I64(property->values[1]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 	} else if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 		uint64_t valid_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 		for (i = 0; i < property->num_values; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 			valid_mask |= (1ULL << property->values[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 		return !(value & ~valid_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 	} else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) 		struct drm_property_blob *blob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 		if (value == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) 		blob = drm_property_lookup_blob(property->dev, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 		if (blob) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 			*ref = &blob->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) 	} else if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) 		/* a zero value for an object property translates to null: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) 		if (value == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) 		*ref = __drm_mode_object_find(property->dev, NULL, value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) 					      property->values[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 		return *ref != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 	for (i = 0; i < property->num_values; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) 		if (property->values[i] == value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) void drm_property_change_valid_put(struct drm_property *property,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) 		struct drm_mode_object *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) 	if (!ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) 	if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) 		drm_mode_object_put(ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) 	} else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) 		drm_property_blob_put(obj_to_blob(ref));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) }