5
5
* for STMicroelectronics.
6
6
* License terms: GNU General Public License (GPL), version 2
7
7
*/
8
- #include <drm/drmP.h>
9
8
10
- #include <drm/drm_atomic_helper .h>
9
+ #include <drm/drm_atomic .h>
11
10
#include <drm/drm_fb_cma_helper.h>
12
11
#include <drm/drm_gem_cma_helper.h>
13
- #include <drm/drm_plane_helper.h>
14
12
15
13
#include "sti_compositor.h"
16
14
#include "sti_cursor.h"
@@ -110,42 +108,39 @@ static void sti_cursor_init(struct sti_cursor *cursor)
110
108
(b * 5 );
111
109
}
112
110
113
- static void sti_cursor_atomic_update (struct drm_plane * drm_plane ,
114
- struct drm_plane_state * oldstate )
111
+ static int sti_cursor_atomic_check (struct drm_plane * drm_plane ,
112
+ struct drm_plane_state * state )
115
113
{
116
- struct drm_plane_state * state = drm_plane -> state ;
117
114
struct sti_plane * plane = to_sti_plane (drm_plane );
118
115
struct sti_cursor * cursor = to_sti_cursor (plane );
119
116
struct drm_crtc * crtc = state -> crtc ;
120
- struct sti_mixer * mixer = to_sti_mixer (crtc );
121
117
struct drm_framebuffer * fb = state -> fb ;
122
- struct drm_display_mode * mode = & crtc -> mode ;
123
- int dst_x = state -> crtc_x ;
124
- int dst_y = state -> crtc_y ;
125
- int dst_w = clamp_val (state -> crtc_w , 0 , mode -> crtc_hdisplay - dst_x );
126
- int dst_h = clamp_val (state -> crtc_h , 0 , mode -> crtc_vdisplay - dst_y );
118
+ struct drm_crtc_state * crtc_state ;
119
+ struct drm_display_mode * mode ;
120
+ int dst_x , dst_y , dst_w , dst_h ;
121
+ int src_w , src_h ;
122
+
123
+ /* no need for further checks if the plane is being disabled */
124
+ if (!crtc || !fb )
125
+ return 0 ;
126
+
127
+ crtc_state = drm_atomic_get_crtc_state (state -> state , crtc );
128
+ mode = & crtc_state -> mode ;
129
+ dst_x = state -> crtc_x ;
130
+ dst_y = state -> crtc_y ;
131
+ dst_w = clamp_val (state -> crtc_w , 0 , mode -> crtc_hdisplay - dst_x );
132
+ dst_h = clamp_val (state -> crtc_h , 0 , mode -> crtc_vdisplay - dst_y );
127
133
/* src_x are in 16.16 format */
128
- int src_w = state -> src_w >> 16 ;
129
- int src_h = state -> src_h >> 16 ;
130
- struct drm_gem_cma_object * cma_obj ;
131
- u32 y , x ;
132
- u32 val ;
133
-
134
- DRM_DEBUG_KMS ("CRTC:%d (%s) drm plane:%d (%s)\n" ,
135
- crtc -> base .id , sti_mixer_to_str (mixer ),
136
- drm_plane -> base .id , sti_plane_to_str (plane ));
137
- DRM_DEBUG_KMS ("(%dx%d)@(%d,%d)\n" , dst_w , dst_h , dst_x , dst_y );
138
-
139
- dev_dbg (cursor -> dev , "%s %s\n" , __func__ ,
140
- sti_plane_to_str (plane ));
134
+ src_w = state -> src_w >> 16 ;
135
+ src_h = state -> src_h >> 16 ;
141
136
142
137
if (src_w < STI_CURS_MIN_SIZE ||
143
138
src_h < STI_CURS_MIN_SIZE ||
144
139
src_w > STI_CURS_MAX_SIZE ||
145
140
src_h > STI_CURS_MAX_SIZE ) {
146
141
DRM_ERROR ("Invalid cursor size (%dx%d)\n" ,
147
142
src_w , src_h );
148
- return ;
143
+ return - EINVAL ;
149
144
}
150
145
151
146
/* If the cursor size has changed, re-allocated the pixmap */
@@ -169,16 +164,46 @@ static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
169
164
GFP_KERNEL | GFP_DMA );
170
165
if (!cursor -> pixmap .base ) {
171
166
DRM_ERROR ("Failed to allocate memory for pixmap\n" );
172
- return ;
167
+ return - EINVAL ;
173
168
}
174
169
}
175
170
176
- cma_obj = drm_fb_cma_get_gem_obj (fb , 0 );
177
- if (!cma_obj ) {
171
+ if (!drm_fb_cma_get_gem_obj (fb , 0 )) {
178
172
DRM_ERROR ("Can't get CMA GEM object for fb\n" );
179
- return ;
173
+ return - EINVAL ;
180
174
}
181
175
176
+ DRM_DEBUG_KMS ("CRTC:%d (%s) drm plane:%d (%s)\n" ,
177
+ crtc -> base .id , sti_mixer_to_str (to_sti_mixer (crtc )),
178
+ drm_plane -> base .id , sti_plane_to_str (plane ));
179
+ DRM_DEBUG_KMS ("(%dx%d)@(%d,%d)\n" , dst_w , dst_h , dst_x , dst_y );
180
+
181
+ return 0 ;
182
+ }
183
+
184
+ static void sti_cursor_atomic_update (struct drm_plane * drm_plane ,
185
+ struct drm_plane_state * oldstate )
186
+ {
187
+ struct drm_plane_state * state = drm_plane -> state ;
188
+ struct sti_plane * plane = to_sti_plane (drm_plane );
189
+ struct sti_cursor * cursor = to_sti_cursor (plane );
190
+ struct drm_crtc * crtc = state -> crtc ;
191
+ struct drm_framebuffer * fb = state -> fb ;
192
+ struct drm_display_mode * mode ;
193
+ int dst_x , dst_y ;
194
+ struct drm_gem_cma_object * cma_obj ;
195
+ u32 y , x ;
196
+ u32 val ;
197
+
198
+ if (!crtc || !fb )
199
+ return ;
200
+
201
+ mode = & crtc -> mode ;
202
+ dst_x = state -> crtc_x ;
203
+ dst_y = state -> crtc_y ;
204
+
205
+ cma_obj = drm_fb_cma_get_gem_obj (fb , 0 );
206
+
182
207
/* Convert ARGB8888 to CLUT8 */
183
208
sti_cursor_argb8888_to_clut8 (cursor , (u32 * )cma_obj -> vaddr );
184
209
@@ -212,7 +237,6 @@ static void sti_cursor_atomic_disable(struct drm_plane *drm_plane,
212
237
struct drm_plane_state * oldstate )
213
238
{
214
239
struct sti_plane * plane = to_sti_plane (drm_plane );
215
- struct sti_mixer * mixer = to_sti_mixer (drm_plane -> crtc );
216
240
217
241
if (!drm_plane -> crtc ) {
218
242
DRM_DEBUG_DRIVER ("drm plane:%d not enabled\n" ,
@@ -221,13 +245,15 @@ static void sti_cursor_atomic_disable(struct drm_plane *drm_plane,
221
245
}
222
246
223
247
DRM_DEBUG_DRIVER ("CRTC:%d (%s) drm plane:%d (%s)\n" ,
224
- drm_plane -> crtc -> base .id , sti_mixer_to_str (mixer ),
248
+ drm_plane -> crtc -> base .id ,
249
+ sti_mixer_to_str (to_sti_mixer (drm_plane -> crtc )),
225
250
drm_plane -> base .id , sti_plane_to_str (plane ));
226
251
227
252
plane -> status = STI_PLANE_DISABLING ;
228
253
}
229
254
230
255
static const struct drm_plane_helper_funcs sti_cursor_helpers_funcs = {
256
+ .atomic_check = sti_cursor_atomic_check ,
231
257
.atomic_update = sti_cursor_atomic_update ,
232
258
.atomic_disable = sti_cursor_atomic_disable ,
233
259
};
0 commit comments