blob: 6c59dd727ebb7b5ea8e3b55e4a2c7776eaae5502 [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
16#include "msm_drv.h"
17
18#define MSM_PROP_STATE_CACHE_SIZE 2
19
20/**
21 * struct msm_property_data - opaque structure for tracking per
22 * drm-object per property stuff
23 * @default_value: Default property value for this drm object
24 */
25struct msm_property_data {
26 uint64_t default_value;
27};
28
29/**
30 * struct msm_property_info: Structure for property/state helper functions
31 * @base: Pointer to base drm object (plane/crtc/etc.)
32 * @dev: Pointer to drm device object
33 * @property_array: Pointer to array for storing created property objects
34 * @property_data: Pointer to array for storing private property data
35 * @property_count: Total number of properties
36 * @blob_count: Total number of blob properties, should be <= count
37 * @install_request: Total number of property 'install' requests
38 * @install_count: Total number of successful 'install' requests
39 * @recent_idx: Index of property most recently accessed by set/get
40 * @state_cache: Cache of local states, to prevent alloc/free thrashing
41 * @state_size: Size of local state structures
42 * @state_cache_size: Number of state structures currently stored in state_cache
43 * @property_lock: Mutex to protect local variables
44 */
45struct msm_property_info {
46 struct drm_mode_object *base;
47 struct drm_device *dev;
48
49 struct drm_property **property_array;
50 struct msm_property_data *property_data;
51 uint32_t property_count;
52 uint32_t blob_count;
53 uint32_t install_request;
54 uint32_t install_count;
55
56 int32_t recent_idx;
57
58 void *state_cache[MSM_PROP_STATE_CACHE_SIZE];
59 uint32_t state_size;
60 int32_t state_cache_size;
61 struct mutex property_lock;
62};
63
64/**
65 * msm_property_get_default - query default value of a property
66 * @info: Pointer to property info container struct
67 * @property_idx: Property index
68 * Returns: Default value for specified property
69 */
70static inline
71uint64_t msm_property_get_default(struct msm_property_info *info,
72 uint32_t property_idx)
73{
74 uint64_t rc = 0;
75
76 if (!info)
77 return 0;
78
79 mutex_lock(&info->property_lock);
80 if (property_idx < info->property_count)
81 rc = info->property_data[property_idx].default_value;
82 mutex_unlock(&info->property_lock);
83
84 return rc;
85}
86
87/**
88 * msm_property_init - initialize property info structure
89 * @info: Pointer to property info container struct
90 * @base: Pointer to base drm object (plane/crtc/etc.)
91 * @dev: Pointer to drm device object
92 * @property_array: Pointer to array for storing created property objects
93 * @property_data: Pointer to array for storing private property data
94 * @property_count: Total number of properties
95 * @blob_count: Total number of blob properties, should be <= count
96 * @state_size: Size of local state object
97 */
98void msm_property_init(struct msm_property_info *info,
99 struct drm_mode_object *base,
100 struct drm_device *dev,
101 struct drm_property **property_array,
102 struct msm_property_data *property_data,
103 uint32_t property_count,
104 uint32_t blob_count,
105 uint32_t state_size);
106
107/**
108 * msm_property_destroy - destroy helper info structure
109 *
110 * @info: Pointer to property info container struct
111 */
112void msm_property_destroy(struct msm_property_info *info);
113
114/**
115 * msm_property_install_range - install standard drm range property
116 * @info: Pointer to property info container struct
117 * @name: Property name
118 * @min: Min property value
119 * @max: Max property value
120 * @init: Default property value
121 * @property_idx: Property index
122 */
123void msm_property_install_range(struct msm_property_info *info,
124 const char *name,
125 uint64_t min,
126 uint64_t max,
127 uint64_t init,
128 uint32_t property_idx);
129
130/**
131 * msm_property_install_rotation - install standard drm rotation property
132 * @info: Pointer to property info container struct
133 * @supported_rotations: Bitmask of supported rotation values (see
134 * drm_mode_create_rotation_property for more details)
135 * @property_idx: Property index
136 */
137void msm_property_install_rotation(struct msm_property_info *info,
138 unsigned int supported_rotations,
139 uint32_t property_idx);
140
141/**
142 * msm_property_install_enum - install standard drm enum/bitmask property
143 * @info: Pointer to property info container struct
144 * @name: Property name
145 * @is_bitmask: Set to non-zero to create a bitmask property, rather than an
146 * enumeration one
147 * @values: Array of allowable enumeration/bitmask values
148 * @num_values: Size of values array
149 * @property_idx: Property index
150 */
151void msm_property_install_enum(struct msm_property_info *info,
152 const char *name,
153 int is_bitmask,
154 const struct drm_prop_enum_list *values,
155 int num_values,
156 uint32_t property_idx);
157
158/**
159 * msm_property_install_blob - install standard drm blob property
160 * @info: Pointer to property info container struct
161 * @name: Property name
162 * @flags: Extra flags for property creation
163 * @property_idx: Property index
164 */
165void msm_property_install_blob(struct msm_property_info *info,
166 const char *name,
167 int flags,
168 uint32_t property_idx);
169
170/**
171 * msm_property_install_get_status - query overal status of property additions
172 * @info: Pointer to property info container struct
173 * Returns: Zero if previous property install calls were all successful
174 */
175int msm_property_install_get_status(struct msm_property_info *info);
176
177/**
178 * msm_property_index - determine property index from drm_property ptr
179 * @info: Pointer to property info container struct
180 * @property: Incoming property pointer
181 * Returns: Valid property index, or -EINVAL on error
182 */
183int msm_property_index(struct msm_property_info *info,
184 struct drm_property *property);
185
186/**
187 * msm_property_atomic_set - helper function for atomic property set callback
188 * @info: Pointer to property info container struct
189 * @property_values: Pointer to property values cache array
190 * @property_blobs: Pointer to property blobs cache array
191 * @property: Incoming property pointer
192 * @val: Incoming property value
193 * Returns: Zero on success
194 */
195int msm_property_atomic_set(struct msm_property_info *info,
196 uint64_t *property_values,
197 struct drm_property_blob **property_blobs,
198 struct drm_property *property,
199 uint64_t val);
200
201/**
202 * msm_property_atomic_get - helper function for atomic property get callback
203 * @info: Pointer to property info container struct
204 * @property_values: Pointer to property values cache array
205 * @property_blobs: Pointer to property blobs cache array
206 * @property: Incoming property pointer
207 * @val: Pointer to variable for receiving property value
208 * Returns: Zero on success
209 */
210int msm_property_atomic_get(struct msm_property_info *info,
211 uint64_t *property_values,
212 struct drm_property_blob **property_blobs,
213 struct drm_property *property,
214 uint64_t *val);
215
216/**
217 * msm_property_alloc_state - helper function for allocating local state objects
218 * @info: Pointer to property info container struct
219 */
220void *msm_property_alloc_state(struct msm_property_info *info);
221
222/**
223 * msm_property_reset_state - helper function for state reset callback
224 * @info: Pointer to property info container struct
225 * @state: Pointer to local state structure
226 * @property_values: Pointer to property values cache array
227 * @property_blobs: Pointer to property blobs cache array
228 */
229void msm_property_reset_state(struct msm_property_info *info,
230 void *state,
231 uint64_t *property_values,
232 struct drm_property_blob **property_blobs);
233
234/**
235 * msm_property_duplicate_state - helper function for duplicate state cb
236 * @info: Pointer to property info container struct
237 * @old_state: Pointer to original state structure
238 * @state: Pointer to newly created state structure
239 * @property_values: Pointer to property values cache array
240 * @property_blobs: Pointer to property blobs cache array
241 */
242void msm_property_duplicate_state(struct msm_property_info *info,
243 void *old_state,
244 void *state,
245 uint64_t *property_values,
246 struct drm_property_blob **property_blobs);
247
248/**
249 * msm_property_destroy_state - helper function for destroy state cb
250 * @info: Pointer to property info container struct
251 * @state: Pointer to local state structure
252 * @property_values: Pointer to property values cache array
253 * @property_blobs: Pointer to property blobs cache array
254 */
255void msm_property_destroy_state(struct msm_property_info *info,
256 void *state,
257 uint64_t *property_values,
258 struct drm_property_blob **property_blobs);
259
260/**
261 * msm_property_get_blob - obtain cached data pointer for drm blob property
262 * @info: Pointer to property info container struct
263 * @property_blobs: Pointer to property blobs cache array
264 * @byte_len: Optional pointer to variable for accepting blob size
265 * @property_idx: Property index
266 * Returns: Pointer to blob data
267 */
268void *msm_property_get_blob(struct msm_property_info *info,
269 struct drm_property_blob **property_blobs,
270 size_t *byte_len,
271 uint32_t property_idx);
272
273/**
274 * msm_property_set_blob - update blob property on a drm object
275 * This function updates the blob property value of the given drm object. Its
276 * intended use is to update blob properties that have been created with the
277 * DRM_MODE_PROP_IMMUTABLE flag set.
278 * @info: Pointer to property info container struct
279 * @blob_reference: Reference to a pointer that holds the created data blob
280 * @blob_data: Pointer to blob data
281 * @byte_len: Length of blob data, in bytes
282 * @property_idx: Property index
283 * Returns: Zero on success
284 */
285int msm_property_set_blob(struct msm_property_info *info,
286 struct drm_property_blob **blob_reference,
287 void *blob_data,
288 size_t byte_len,
289 uint32_t property_idx);
290
291#endif /* _MSM_PROP_H_ */
292