summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/msm/msm_prop.h
blob: 1430551700c7375fcae07ae89be18b2fe53d1a94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef _MSM_PROP_H_
#define _MSM_PROP_H_

#include <linux/list.h>
#include "msm_drv.h"

#define MSM_PROP_STATE_CACHE_SIZE	2

/**
 * struct msm_property_data - opaque structure for tracking per
 *                            drm-object per property stuff
 * @default_value: Default property value for this drm object
 * @dirty_node: Linked list node to track if property is dirty or not
 * @force_dirty: Always dirty property on incoming sets, rather than checking
 *               for modified values
 */
struct msm_property_data {
	uint64_t default_value;
	struct list_head dirty_node;
	bool force_dirty;
};

/**
 * struct msm_property_info: Structure for property/state helper functions
 * @base: Pointer to base drm object (plane/crtc/etc.)
 * @dev: Pointer to drm device object
 * @property_array: Pointer to array for storing created property objects
 * @property_data: Pointer to array for storing private property data
 * @property_count: Total number of properties
 * @blob_count: Total number of blob properties, should be <= count
 * @install_request: Total number of property 'install' requests
 * @install_count: Total number of successful 'install' requests
 * @recent_idx: Index of property most recently accessed by set/get
 * @dirty_list: List of all properties that have been 'atomic_set' but not
 *              yet cleared with 'msm_property_pop_dirty'
 * @is_active: Whether or not drm component properties are 'active'
 * @state_cache: Cache of local states, to prevent alloc/free thrashing
 * @state_size: Size of local state structures
 * @state_cache_size: Number of state structures currently stored in state_cache
 * @property_lock: Mutex to protect local variables
 */
struct msm_property_info {
	struct drm_mode_object *base;
	struct drm_device *dev;

	struct drm_property **property_array;
	struct msm_property_data *property_data;
	uint32_t property_count;
	uint32_t blob_count;
	uint32_t install_request;
	uint32_t install_count;

	int32_t recent_idx;

	struct list_head dirty_list;
	bool is_active;

	void *state_cache[MSM_PROP_STATE_CACHE_SIZE];
	uint32_t state_size;
	int32_t state_cache_size;
	struct mutex property_lock;
};

/**
 * msm_property_get_default - query default value of a property
 * @info: Pointer to property info container struct
 * @property_idx: Property index
 * Returns: Default value for specified property
 */
static inline
uint64_t msm_property_get_default(struct msm_property_info *info,
		uint32_t property_idx)
{
	uint64_t rc = 0;

	if (!info)
		return 0;

	mutex_lock(&info->property_lock);
	if (property_idx < info->property_count)
		rc = info->property_data[property_idx].default_value;
	mutex_unlock(&info->property_lock);

	return rc;
}

/**
 * msm_property_set_is_active - set overall 'active' status for all properties
 * @info: Pointer to property info container struct
 * @is_active: New 'is active' status
 */
static inline
void msm_property_set_is_active(struct msm_property_info *info, bool is_active)
{
	if (info) {
		mutex_lock(&info->property_lock);
		info->is_active = is_active;
		mutex_unlock(&info->property_lock);
	}
}

/**
 * msm_property_get_is_active - query property 'is active' status
 * @info: Pointer to property info container struct
 * Returns: Current 'is active's status
 */
static inline
bool msm_property_get_is_active(struct msm_property_info *info)
{
	bool rc = false;

	if (info) {
		mutex_lock(&info->property_lock);
		rc = info->is_active;
		mutex_unlock(&info->property_lock);
	}

	return rc;
}

/**
 * msm_property_pop_dirty - determine next dirty property and clear
 *                          its dirty flag
 * @info: Pointer to property info container struct
 * Returns: Valid msm property index on success,
 *          -EAGAIN if no dirty properties are available
 *          Property indicies returned from this function are similar
 *          to those returned by the msm_property_index function.
 */
int msm_property_pop_dirty(struct msm_property_info *info);

/**
 * msm_property_init - initialize property info structure
 * @info: Pointer to property info container struct
 * @base: Pointer to base drm object (plane/crtc/etc.)
 * @dev: Pointer to drm device object
 * @property_array: Pointer to array for storing created property objects
 * @property_data: Pointer to array for storing private property data
 * @property_count: Total number of properties
 * @blob_count: Total number of blob properties, should be <= count
 * @state_size: Size of local state object
 */
void msm_property_init(struct msm_property_info *info,
		struct drm_mode_object *base,
		struct drm_device *dev,
		struct drm_property **property_array,
		struct msm_property_data *property_data,
		uint32_t property_count,
		uint32_t blob_count,
		uint32_t state_size);

/**
 * msm_property_destroy - destroy helper info structure
 *
 * @info: Pointer to property info container struct
 */
void msm_property_destroy(struct msm_property_info *info);

/**
 * msm_property_install_range - install standard drm range property
 * @info: Pointer to property info container struct
 * @name: Property name
 * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
 * @min: Min property value
 * @max: Max property value
 * @init: Default Property value
 * @property_idx: Property index
 */
void msm_property_install_range(struct msm_property_info *info,
		const char *name,
		int flags,
		uint64_t min,
		uint64_t max,
		uint64_t init,
		uint32_t property_idx);

/**
 * msm_property_install_volatile_range - install drm range property
 *	This function is similar to msm_property_install_range, but assumes
 *	that the property is meant for holding user pointers or descriptors
 *	that may reference volatile data without having an updated value.
 * @info: Pointer to property info container struct
 * @name: Property name
 * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
 * @min: Min property value
 * @max: Max property value
 * @init: Default Property value
 * @property_idx: Property index
 */
void msm_property_install_volatile_range(struct msm_property_info *info,
		const char *name,
		int flags,
		uint64_t min,
		uint64_t max,
		uint64_t init,
		uint32_t property_idx);

/**
 * msm_property_install_signed_range - install signed drm range property
 * @info: Pointer to property info container struct
 * @name: Property name
 * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
 * @min: Min property value
 * @max: Max property value
 * @init: Default Property value
 * @property_idx: Property index
 */
void msm_property_install_signed_range(struct msm_property_info *info,
		const char *name,
		int flags,
		int64_t min,
		int64_t max,
		int64_t init,
		uint32_t property_idx);

/**
 * msm_property_install_volatile_signed_range - install signed range property
 *	This function is similar to msm_property_install_range, but assumes
 *	that the property is meant for holding user pointers or descriptors
 *	that may reference volatile data without having an updated value.
 * @info: Pointer to property info container struct
 * @name: Property name
 * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
 * @min: Min property value
 * @max: Max property value
 * @init: Default Property value
 * @property_idx: Property index
 */
void msm_property_install_volatile_signed_range(struct msm_property_info *info,
		const char *name,
		int flags,
		int64_t min,
		int64_t max,
		int64_t init,
		uint32_t property_idx);

/**
 * msm_property_install_rotation - install standard drm rotation property
 * @info: Pointer to property info container struct
 * @supported_rotations: Bitmask of supported rotation values (see
 *                       drm_mode_create_rotation_property for more details)
 * @property_idx: Property index
 */
void msm_property_install_rotation(struct msm_property_info *info,
		unsigned int supported_rotations,
		uint32_t property_idx);

/**
 * msm_property_install_enum - install standard drm enum/bitmask property
 * @info: Pointer to property info container struct
 * @name: Property name
 * @flags: Other property type flags, e.g. DRM_MODE_PROP_IMMUTABLE
 * @is_bitmask: Set to non-zero to create a bitmask property, rather than an
 *              enumeration one
 * @values: Array of allowable enumeration/bitmask values
 * @num_values: Size of values array
 * @property_idx: Property index
 */
void msm_property_install_enum(struct msm_property_info *info,
		const char *name,
		int flags,
		int is_bitmask,
		const struct drm_prop_enum_list *values,
		int num_values,
		uint32_t property_idx);

/**
 * msm_property_install_blob - install standard drm blob property
 * @info: Pointer to property info container struct
 * @name: Property name
 * @flags: Extra flags for property creation
 * @property_idx: Property index
 */
void msm_property_install_blob(struct msm_property_info *info,
		const char *name,
		int flags,
		uint32_t property_idx);

/**
 * msm_property_install_get_status - query overal status of property additions
 * @info: Pointer to property info container struct
 * Returns: Zero if previous property install calls were all successful
 */
int msm_property_install_get_status(struct msm_property_info *info);

/**
 * msm_property_index - determine property index from drm_property ptr
 * @info: Pointer to property info container struct
 * @property: Incoming property pointer
 * Returns: Valid property index, or -EINVAL on error
 */
int msm_property_index(struct msm_property_info *info,
		struct drm_property *property);

/**
 * msm_property_atomic_set - helper function for atomic property set callback
 * @info: Pointer to property info container struct
 * @property_values: Pointer to property values cache array
 * @property_blobs: Pointer to property blobs cache array
 * @property: Incoming property pointer
 * @val: Incoming property value
 * Returns: Zero on success
 */
int msm_property_atomic_set(struct msm_property_info *info,
		uint64_t *property_values,
		struct drm_property_blob **property_blobs,
		struct drm_property *property,
		uint64_t val);

/**
 * msm_property_atomic_get - helper function for atomic property get callback
 * @info: Pointer to property info container struct
 * @property_values: Pointer to property values cache array
 * @property_blobs: Pointer to property blobs cache array
 * @property: Incoming property pointer
 * @val: Pointer to variable for receiving property value
 * Returns: Zero on success
 */
int msm_property_atomic_get(struct msm_property_info *info,
		uint64_t *property_values,
		struct drm_property_blob **property_blobs,
		struct drm_property *property,
		uint64_t *val);

/**
 * msm_property_alloc_state - helper function for allocating local state objects
 * @info: Pointer to property info container struct
 */
void *msm_property_alloc_state(struct msm_property_info *info);

/**
 * msm_property_reset_state - helper function for state reset callback
 * @info: Pointer to property info container struct
 * @state: Pointer to local state structure
 * @property_values: Pointer to property values cache array
 * @property_blobs: Pointer to property blobs cache array
 */
void msm_property_reset_state(struct msm_property_info *info,
		void *state,
		uint64_t *property_values,
		struct drm_property_blob **property_blobs);

/**
 * msm_property_duplicate_state - helper function for duplicate state cb
 * @info: Pointer to property info container struct
 * @old_state: Pointer to original state structure
 * @state: Pointer to newly created state structure
 * @property_values: Pointer to property values cache array
 * @property_blobs: Pointer to property blobs cache array
 */
void msm_property_duplicate_state(struct msm_property_info *info,
		void *old_state,
		void *state,
		uint64_t *property_values,
		struct drm_property_blob **property_blobs);

/**
 * msm_property_destroy_state - helper function for destroy state cb
 * @info: Pointer to property info container struct
 * @state: Pointer to local state structure
 * @property_values: Pointer to property values cache array
 * @property_blobs: Pointer to property blobs cache array
 */
void msm_property_destroy_state(struct msm_property_info *info,
		void *state,
		uint64_t *property_values,
		struct drm_property_blob **property_blobs);

/**
 * msm_property_get_blob - obtain cached data pointer for drm blob property
 * @info: Pointer to property info container struct
 * @property_blobs: Pointer to property blobs cache array
 * @byte_len: Optional pointer to variable for accepting blob size
 * @property_idx: Property index
 * Returns: Pointer to blob data
 */
void *msm_property_get_blob(struct msm_property_info *info,
		struct drm_property_blob **property_blobs,
		size_t *byte_len,
		uint32_t property_idx);

/**
 * msm_property_set_blob - update blob property on a drm object
 * This function updates the blob property value of the given drm object. Its
 * intended use is to update blob properties that have been created with the
 * DRM_MODE_PROP_IMMUTABLE flag set.
 * @info: Pointer to property info container struct
 * @blob_reference: Reference to a pointer that holds the created data blob
 * @blob_data: Pointer to blob data
 * @byte_len: Length of blob data, in bytes
 * @property_idx: Property index
 * Returns: Zero on success
 */
int msm_property_set_blob(struct msm_property_info *info,
		struct drm_property_blob **blob_reference,
		void *blob_data,
		size_t byte_len,
		uint32_t property_idx);

/**
 * msm_property_set_property - update property on a drm object
 * This function updates the property value of the given drm object. Its
 * intended use is to update properties that have been created with the
 * DRM_MODE_PROP_IMMUTABLE flag set.
 * Note: This function cannot be called on a blob.
 * @info: Pointer to property info container struct
 * @property_values: Pointer to property values cache array
 * @property_idx: Property index
 * @val: value of the property to set
 * Returns: Zero on success
 */
int msm_property_set_property(struct msm_property_info *info,
		uint64_t *property_values,
		uint32_t property_idx,
		uint64_t val);

#endif /* _MSM_PROP_H_ */