blob: dbe28bdf56380bf3824d7dd9ebd7788979c62588 [file] [log] [blame]
Clarence Ip7aa390f2016-05-26 21:06:54 -04001/* Copyright (c) 2016, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _MSM_PROP_H_
14#define _MSM_PROP_H_
15
Clarence Ip913624e2016-06-23 14:56:32 -040016#include <linux/list.h>
Clarence Ip7aa390f2016-05-26 21:06:54 -040017#include "msm_drv.h"
18
19#define MSM_PROP_STATE_CACHE_SIZE 2
20
21/**
22 * struct msm_property_data - opaque structure for tracking per
23 * drm-object per property stuff
24 * @default_value: Default property value for this drm object
Clarence Ip913624e2016-06-23 14:56:32 -040025 * @dirty_node: Linked list node to track if property is dirty or not
Clarence Ip5fc00c52016-09-23 15:03:34 -040026 * @force_dirty: Always dirty property on incoming sets, rather than checking
27 * for modified values
Clarence Ip7aa390f2016-05-26 21:06:54 -040028 */
29struct msm_property_data {
30 uint64_t default_value;
Clarence Ip913624e2016-06-23 14:56:32 -040031 struct list_head dirty_node;
Clarence Ip5fc00c52016-09-23 15:03:34 -040032 bool force_dirty;
Clarence Ip7aa390f2016-05-26 21:06:54 -040033};
34
35/**
36 * struct msm_property_info: Structure for property/state helper functions
37 * @base: Pointer to base drm object (plane/crtc/etc.)
38 * @dev: Pointer to drm device object
39 * @property_array: Pointer to array for storing created property objects
40 * @property_data: Pointer to array for storing private property data
41 * @property_count: Total number of properties
42 * @blob_count: Total number of blob properties, should be <= count
43 * @install_request: Total number of property 'install' requests
44 * @install_count: Total number of successful 'install' requests
45 * @recent_idx: Index of property most recently accessed by set/get
Clarence Ip913624e2016-06-23 14:56:32 -040046 * @dirty_list: List of all properties that have been 'atomic_set' but not
47 * yet cleared with 'msm_property_pop_dirty'
48 * @is_active: Whether or not drm component properties are 'active'
Clarence Ip7aa390f2016-05-26 21:06:54 -040049 * @state_cache: Cache of local states, to prevent alloc/free thrashing
50 * @state_size: Size of local state structures
51 * @state_cache_size: Number of state structures currently stored in state_cache
52 * @property_lock: Mutex to protect local variables
53 */
54struct msm_property_info {
55 struct drm_mode_object *base;
56 struct drm_device *dev;
57
58 struct drm_property **property_array;
59 struct msm_property_data *property_data;
60 uint32_t property_count;
61 uint32_t blob_count;
62 uint32_t install_request;
63 uint32_t install_count;
64
65 int32_t recent_idx;
66
Clarence Ip913624e2016-06-23 14:56:32 -040067 struct list_head dirty_list;
68 bool is_active;
69
Clarence Ip7aa390f2016-05-26 21:06:54 -040070 void *state_cache[MSM_PROP_STATE_CACHE_SIZE];
71 uint32_t state_size;
72 int32_t state_cache_size;
73 struct mutex property_lock;
74};
75
76/**
77 * msm_property_get_default - query default value of a property
78 * @info: Pointer to property info container struct
79 * @property_idx: Property index
80 * Returns: Default value for specified property
81 */
82static inline
83uint64_t msm_property_get_default(struct msm_property_info *info,
84 uint32_t property_idx)
85{
86 uint64_t rc = 0;
87
88 if (!info)
89 return 0;
90
91 mutex_lock(&info->property_lock);
92 if (property_idx < info->property_count)
93 rc = info->property_data[property_idx].default_value;
94 mutex_unlock(&info->property_lock);
95
96 return rc;
97}
98
99/**
Clarence Ip913624e2016-06-23 14:56:32 -0400100 * msm_property_set_is_active - set overall 'active' status for all properties
101 * @info: Pointer to property info container struct
102 * @is_active: New 'is active' status
103 */
104static inline
105void msm_property_set_is_active(struct msm_property_info *info, bool is_active)
106{
107 if (info) {
108 mutex_lock(&info->property_lock);
109 info->is_active = is_active;
110 mutex_unlock(&info->property_lock);
111 }
112}
113
114/**
115 * msm_property_get_is_active - query property 'is active' status
116 * @info: Pointer to property info container struct
117 * Returns: Current 'is active's status
118 */
119static inline
120bool msm_property_get_is_active(struct msm_property_info *info)
121{
122 bool rc = false;
123
124 if (info) {
125 mutex_lock(&info->property_lock);
126 rc = info->is_active;
127 mutex_unlock(&info->property_lock);
128 }
129
130 return rc;
131}
132
133/**
134 * msm_property_pop_dirty - determine next dirty property and clear
135 * its dirty flag
136 * @info: Pointer to property info container struct
137 * Returns: Valid msm property index on success,
138 * -EAGAIN if no dirty properties are available
139 * Property indicies returned from this function are similar
140 * to those returned by the msm_property_index function.
141 */
142int msm_property_pop_dirty(struct msm_property_info *info);
143
144/**
Clarence Ip7aa390f2016-05-26 21:06:54 -0400145 * msm_property_init - initialize property info structure
146 * @info: Pointer to property info container struct
147 * @base: Pointer to base drm object (plane/crtc/etc.)
148 * @dev: Pointer to drm device object
149 * @property_array: Pointer to array for storing created property objects
150 * @property_data: Pointer to array for storing private property data
151 * @property_count: Total number of properties
152 * @blob_count: Total number of blob properties, should be <= count
153 * @state_size: Size of local state object
154 */
155void msm_property_init(struct msm_property_info *info,
156 struct drm_mode_object *base,
157 struct drm_device *dev,
158 struct drm_property **property_array,
159 struct msm_property_data *property_data,
160 uint32_t property_count,
161 uint32_t blob_count,
162 uint32_t state_size);
163
164/**
165 * msm_property_destroy - destroy helper info structure
166 *
167 * @info: Pointer to property info container struct
168 */
169void msm_property_destroy(struct msm_property_info *info);
170
171/**
172 * msm_property_install_range - install standard drm range property
173 * @info: Pointer to property info container struct
174 * @name: Property name
Lloyd Atkinson38ad8c92016-07-06 10:39:32 -0400175 * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
Clarence Ip7aa390f2016-05-26 21:06:54 -0400176 * @min: Min property value
177 * @max: Max property value
Clarence Ip5fc00c52016-09-23 15:03:34 -0400178 * @init: Default Property value
Clarence Ip7aa390f2016-05-26 21:06:54 -0400179 * @property_idx: Property index
180 */
181void msm_property_install_range(struct msm_property_info *info,
182 const char *name,
Lloyd Atkinson38ad8c92016-07-06 10:39:32 -0400183 int flags,
Clarence Ip7aa390f2016-05-26 21:06:54 -0400184 uint64_t min,
185 uint64_t max,
186 uint64_t init,
187 uint32_t property_idx);
188
189/**
Clarence Ip5fc00c52016-09-23 15:03:34 -0400190 * msm_property_install_volatile_range - install drm range property
191 * This function is similar to msm_property_install_range, but assumes
192 * that the property is meant for holding user pointers or descriptors
193 * that may reference volatile data without having an updated value.
194 * @info: Pointer to property info container struct
195 * @name: Property name
196 * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
197 * @min: Min property value
198 * @max: Max property value
199 * @init: Default Property value
200 * @property_idx: Property index
201 */
202void msm_property_install_volatile_range(struct msm_property_info *info,
203 const char *name,
204 int flags,
205 uint64_t min,
206 uint64_t max,
207 uint64_t init,
208 uint32_t property_idx);
209
210/**
Clarence Ip7aa390f2016-05-26 21:06:54 -0400211 * msm_property_install_rotation - install standard drm rotation property
212 * @info: Pointer to property info container struct
213 * @supported_rotations: Bitmask of supported rotation values (see
214 * drm_mode_create_rotation_property for more details)
215 * @property_idx: Property index
216 */
217void msm_property_install_rotation(struct msm_property_info *info,
218 unsigned int supported_rotations,
219 uint32_t property_idx);
220
221/**
222 * msm_property_install_enum - install standard drm enum/bitmask property
223 * @info: Pointer to property info container struct
224 * @name: Property name
Lloyd Atkinson38ad8c92016-07-06 10:39:32 -0400225 * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
Clarence Ip7aa390f2016-05-26 21:06:54 -0400226 * @is_bitmask: Set to non-zero to create a bitmask property, rather than an
227 * enumeration one
228 * @values: Array of allowable enumeration/bitmask values
229 * @num_values: Size of values array
230 * @property_idx: Property index
231 */
232void msm_property_install_enum(struct msm_property_info *info,
233 const char *name,
Lloyd Atkinson38ad8c92016-07-06 10:39:32 -0400234 int flags,
Clarence Ip7aa390f2016-05-26 21:06:54 -0400235 int is_bitmask,
236 const struct drm_prop_enum_list *values,
237 int num_values,
238 uint32_t property_idx);
239
240/**
241 * msm_property_install_blob - install standard drm blob property
242 * @info: Pointer to property info container struct
243 * @name: Property name
244 * @flags: Extra flags for property creation
245 * @property_idx: Property index
246 */
247void msm_property_install_blob(struct msm_property_info *info,
248 const char *name,
249 int flags,
250 uint32_t property_idx);
251
252/**
253 * msm_property_install_get_status - query overal status of property additions
254 * @info: Pointer to property info container struct
255 * Returns: Zero if previous property install calls were all successful
256 */
257int msm_property_install_get_status(struct msm_property_info *info);
258
259/**
260 * msm_property_index - determine property index from drm_property ptr
261 * @info: Pointer to property info container struct
262 * @property: Incoming property pointer
263 * Returns: Valid property index, or -EINVAL on error
264 */
265int msm_property_index(struct msm_property_info *info,
266 struct drm_property *property);
267
268/**
269 * msm_property_atomic_set - helper function for atomic property set callback
270 * @info: Pointer to property info container struct
271 * @property_values: Pointer to property values cache array
272 * @property_blobs: Pointer to property blobs cache array
273 * @property: Incoming property pointer
274 * @val: Incoming property value
275 * Returns: Zero on success
276 */
277int msm_property_atomic_set(struct msm_property_info *info,
278 uint64_t *property_values,
279 struct drm_property_blob **property_blobs,
280 struct drm_property *property,
281 uint64_t val);
282
283/**
284 * msm_property_atomic_get - helper function for atomic property get callback
285 * @info: Pointer to property info container struct
286 * @property_values: Pointer to property values cache array
287 * @property_blobs: Pointer to property blobs cache array
288 * @property: Incoming property pointer
289 * @val: Pointer to variable for receiving property value
290 * Returns: Zero on success
291 */
292int msm_property_atomic_get(struct msm_property_info *info,
293 uint64_t *property_values,
294 struct drm_property_blob **property_blobs,
295 struct drm_property *property,
296 uint64_t *val);
297
298/**
299 * msm_property_alloc_state - helper function for allocating local state objects
300 * @info: Pointer to property info container struct
301 */
302void *msm_property_alloc_state(struct msm_property_info *info);
303
304/**
305 * msm_property_reset_state - helper function for state reset callback
306 * @info: Pointer to property info container struct
307 * @state: Pointer to local state structure
308 * @property_values: Pointer to property values cache array
309 * @property_blobs: Pointer to property blobs cache array
310 */
311void msm_property_reset_state(struct msm_property_info *info,
312 void *state,
313 uint64_t *property_values,
314 struct drm_property_blob **property_blobs);
315
316/**
317 * msm_property_duplicate_state - helper function for duplicate state cb
318 * @info: Pointer to property info container struct
319 * @old_state: Pointer to original state structure
320 * @state: Pointer to newly created state structure
321 * @property_values: Pointer to property values cache array
322 * @property_blobs: Pointer to property blobs cache array
323 */
324void msm_property_duplicate_state(struct msm_property_info *info,
325 void *old_state,
326 void *state,
327 uint64_t *property_values,
328 struct drm_property_blob **property_blobs);
329
330/**
331 * msm_property_destroy_state - helper function for destroy state cb
332 * @info: Pointer to property info container struct
333 * @state: Pointer to local state structure
334 * @property_values: Pointer to property values cache array
335 * @property_blobs: Pointer to property blobs cache array
336 */
337void msm_property_destroy_state(struct msm_property_info *info,
338 void *state,
339 uint64_t *property_values,
340 struct drm_property_blob **property_blobs);
341
342/**
343 * msm_property_get_blob - obtain cached data pointer for drm blob property
344 * @info: Pointer to property info container struct
345 * @property_blobs: Pointer to property blobs cache array
346 * @byte_len: Optional pointer to variable for accepting blob size
347 * @property_idx: Property index
348 * Returns: Pointer to blob data
349 */
350void *msm_property_get_blob(struct msm_property_info *info,
351 struct drm_property_blob **property_blobs,
352 size_t *byte_len,
353 uint32_t property_idx);
354
355/**
356 * msm_property_set_blob - update blob property on a drm object
357 * This function updates the blob property value of the given drm object. Its
358 * intended use is to update blob properties that have been created with the
359 * DRM_MODE_PROP_IMMUTABLE flag set.
360 * @info: Pointer to property info container struct
361 * @blob_reference: Reference to a pointer that holds the created data blob
362 * @blob_data: Pointer to blob data
363 * @byte_len: Length of blob data, in bytes
364 * @property_idx: Property index
365 * Returns: Zero on success
366 */
367int msm_property_set_blob(struct msm_property_info *info,
368 struct drm_property_blob **blob_reference,
369 void *blob_data,
370 size_t byte_len,
371 uint32_t property_idx);
372
Lloyd Atkinsonb6191972016-08-10 18:31:46 -0400373/**
374 * msm_property_set_property - update property on a drm object
375 * This function updates the property value of the given drm object. Its
376 * intended use is to update properties that have been created with the
377 * DRM_MODE_PROP_IMMUTABLE flag set.
378 * Note: This function cannot be called on a blob.
379 * @info: Pointer to property info container struct
Lloyd Atkinson13cee812016-08-16 16:10:31 -0400380 * @property_values: Pointer to property values cache array
Lloyd Atkinsonb6191972016-08-10 18:31:46 -0400381 * @property_idx: Property index
382 * @val: value of the property to set
383 * Returns: Zero on success
384 */
385int msm_property_set_property(struct msm_property_info *info,
Lloyd Atkinson13cee812016-08-16 16:10:31 -0400386 uint64_t *property_values,
Lloyd Atkinsonb6191972016-08-10 18:31:46 -0400387 uint32_t property_idx,
388 uint64_t val);
389
Clarence Ip7aa390f2016-05-26 21:06:54 -0400390#endif /* _MSM_PROP_H_ */
391