d2d4ad1918ac34b998558fc08b997b720e773209
[deliverable/linux.git] / include / drm / drm_fb_helper.h
1 /*
2 * Copyright (c) 2006-2009 Red Hat Inc.
3 * Copyright (c) 2006-2008 Intel Corporation
4 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
5 *
6 * DRM framebuffer helper functions
7 *
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that copyright
11 * notice and this permission notice appear in supporting documentation, and
12 * that the name of the copyright holders not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission. The copyright holders make no representations
15 * about the suitability of this software for any purpose. It is provided "as
16 * is" without express or implied warranty.
17 *
18 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 * OF THIS SOFTWARE.
25 *
26 * Authors:
27 * Dave Airlie <airlied@linux.ie>
28 * Jesse Barnes <jesse.barnes@intel.com>
29 */
30 #ifndef DRM_FB_HELPER_H
31 #define DRM_FB_HELPER_H
32
33 struct drm_fb_helper;
34
35 #include <linux/kgdb.h>
36
37 struct drm_fb_offset {
38 int x, y;
39 };
40
41 struct drm_fb_helper_crtc {
42 struct drm_mode_set mode_set;
43 struct drm_display_mode *desired_mode;
44 int x, y;
45 };
46
47 /**
48 * struct drm_fb_helper_surface_size - describes fbdev size and scanout surface size
49 * @fb_width: fbdev width
50 * @fb_height: fbdev height
51 * @surface_width: scanout buffer width
52 * @surface_height: scanout buffer height
53 * @surface_bpp: scanout buffer bpp
54 * @surface_depth: scanout buffer depth
55 *
56 * Note that the scanout surface width/height may be larger than the fbdev
57 * width/height. In case of multiple displays, the scanout surface is sized
58 * according to the largest width/height (so it is large enough for all CRTCs
59 * to scanout). But the fbdev width/height is sized to the minimum width/
60 * height of all the displays. This ensures that fbcon fits on the smallest
61 * of the attached displays.
62 *
63 * So what is passed to drm_fb_helper_fill_var() should be fb_width/fb_height,
64 * rather than the surface size.
65 */
66 struct drm_fb_helper_surface_size {
67 u32 fb_width;
68 u32 fb_height;
69 u32 surface_width;
70 u32 surface_height;
71 u32 surface_bpp;
72 u32 surface_depth;
73 };
74
75 /**
76 * struct drm_fb_helper_funcs - driver callbacks for the fbdev emulation library
77 *
78 * Driver callbacks used by the fbdev emulation helper library.
79 */
80 struct drm_fb_helper_funcs {
81 /**
82 * @gamma_set:
83 *
84 * Set the given gamma LUT register on the given CRTC.
85 *
86 * This callback is optional.
87 *
88 * FIXME:
89 *
90 * This callback is functionally redundant with the core gamma table
91 * support and simply exists because the fbdev hasn't yet been
92 * refactored to use the core gamma table interfaces.
93 */
94 void (*gamma_set)(struct drm_crtc *crtc, u16 red, u16 green,
95 u16 blue, int regno);
96 /**
97 * @gamma_get:
98 *
99 * Read the given gamma LUT register on the given CRTC, used to save the
100 * current LUT when force-restoring the fbdev for e.g. kdbg.
101 *
102 * This callback is optional.
103 *
104 * FIXME:
105 *
106 * This callback is functionally redundant with the core gamma table
107 * support and simply exists because the fbdev hasn't yet been
108 * refactored to use the core gamma table interfaces.
109 */
110 void (*gamma_get)(struct drm_crtc *crtc, u16 *red, u16 *green,
111 u16 *blue, int regno);
112
113 /**
114 * @fb_probe:
115 *
116 * Driver callback to allocate and initialize the fbdev info structure.
117 * Furthermore it also needs to allocate the DRM framebuffer used to
118 * back the fbdev.
119 *
120 * This callback is mandatory.
121 *
122 * RETURNS:
123 *
124 * The driver should return 0 on success and a negative error code on
125 * failure.
126 */
127 int (*fb_probe)(struct drm_fb_helper *helper,
128 struct drm_fb_helper_surface_size *sizes);
129
130 /**
131 * @initial_config:
132 *
133 * Driver callback to setup an initial fbdev display configuration.
134 * Drivers can use this callback to tell the fbdev emulation what the
135 * preferred initial configuration is. This is useful to implement
136 * smooth booting where the fbdev (and subsequently all userspace) never
137 * changes the mode, but always inherits the existing configuration.
138 *
139 * This callback is optional.
140 *
141 * RETURNS:
142 *
143 * The driver should return true if a suitable initial configuration has
144 * been filled out and false when the fbdev helper should fall back to
145 * the default probing logic.
146 */
147 bool (*initial_config)(struct drm_fb_helper *fb_helper,
148 struct drm_fb_helper_crtc **crtcs,
149 struct drm_display_mode **modes,
150 struct drm_fb_offset *offsets,
151 bool *enabled, int width, int height);
152 };
153
154 struct drm_fb_helper_connector {
155 struct drm_connector *connector;
156 };
157
158 /**
159 * struct drm_fb_helper - main structure to emulate fbdev on top of KMS
160 * @fb: Scanout framebuffer object
161 * @dev: DRM device
162 * @crtc_count: number of possible CRTCs
163 * @crtc_info: per-CRTC helper state (mode, x/y offset, etc)
164 * @connector_count: number of connected connectors
165 * @connector_info_alloc_count: size of connector_info
166 * @connector_info: array of per-connector information
167 * @funcs: driver callbacks for fb helper
168 * @fbdev: emulated fbdev device info struct
169 * @pseudo_palette: fake palette of 16 colors
170 *
171 * This is the main structure used by the fbdev helpers. Drivers supporting
172 * fbdev emulation should embedded this into their overall driver structure.
173 * Drivers must also fill out a struct &drm_fb_helper_funcs with a few
174 * operations.
175 */
176 struct drm_fb_helper {
177 struct drm_framebuffer *fb;
178 struct drm_device *dev;
179 int crtc_count;
180 struct drm_fb_helper_crtc *crtc_info;
181 int connector_count;
182 int connector_info_alloc_count;
183 struct drm_fb_helper_connector **connector_info;
184 const struct drm_fb_helper_funcs *funcs;
185 struct fb_info *fbdev;
186 u32 pseudo_palette[17];
187
188 /**
189 * @kernel_fb_list:
190 *
191 * Entry on the global kernel_fb_helper_list, used for kgdb entry/exit.
192 */
193 struct list_head kernel_fb_list;
194
195 /**
196 * @delayed_hotplug:
197 *
198 * A hotplug was received while fbdev wasn't in control of the DRM
199 * device, i.e. another KMS master was active. The output configuration
200 * needs to be reprobe when fbdev is in control again.
201 */
202 bool delayed_hotplug;
203
204 /**
205 * @atomic:
206 *
207 * Use atomic updates for restore_fbdev_mode(), etc. This defaults to
208 * true if driver has DRIVER_ATOMIC feature flag, but drivers can
209 * override it to true after drm_fb_helper_init() if they support atomic
210 * modeset but do not yet advertise DRIVER_ATOMIC (note that fb-helper
211 * does not require ASYNC commits).
212 */
213 bool atomic;
214 };
215
216 #ifdef CONFIG_DRM_FBDEV_EMULATION
217 void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
218 const struct drm_fb_helper_funcs *funcs);
219 int drm_fb_helper_init(struct drm_device *dev,
220 struct drm_fb_helper *helper, int crtc_count,
221 int max_conn);
222 void drm_fb_helper_fini(struct drm_fb_helper *helper);
223 int drm_fb_helper_blank(int blank, struct fb_info *info);
224 int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
225 struct fb_info *info);
226 int drm_fb_helper_set_par(struct fb_info *info);
227 int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
228 struct fb_info *info);
229
230 int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper);
231
232 struct fb_info *drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper);
233 void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper);
234 void drm_fb_helper_release_fbi(struct drm_fb_helper *fb_helper);
235 void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
236 uint32_t fb_width, uint32_t fb_height);
237 void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
238 uint32_t depth);
239
240 void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper);
241
242 ssize_t drm_fb_helper_sys_read(struct fb_info *info, char __user *buf,
243 size_t count, loff_t *ppos);
244 ssize_t drm_fb_helper_sys_write(struct fb_info *info, const char __user *buf,
245 size_t count, loff_t *ppos);
246
247 void drm_fb_helper_sys_fillrect(struct fb_info *info,
248 const struct fb_fillrect *rect);
249 void drm_fb_helper_sys_copyarea(struct fb_info *info,
250 const struct fb_copyarea *area);
251 void drm_fb_helper_sys_imageblit(struct fb_info *info,
252 const struct fb_image *image);
253
254 void drm_fb_helper_cfb_fillrect(struct fb_info *info,
255 const struct fb_fillrect *rect);
256 void drm_fb_helper_cfb_copyarea(struct fb_info *info,
257 const struct fb_copyarea *area);
258 void drm_fb_helper_cfb_imageblit(struct fb_info *info,
259 const struct fb_image *image);
260
261 void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, int state);
262
263 int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info);
264
265 int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper);
266 int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel);
267 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper);
268 int drm_fb_helper_debug_enter(struct fb_info *info);
269 int drm_fb_helper_debug_leave(struct fb_info *info);
270 struct drm_display_mode *
271 drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector,
272 int width, int height);
273 struct drm_display_mode *
274 drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
275 int width, int height);
276
277 int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector);
278 int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
279 struct drm_connector *connector);
280 #else
281 static inline void drm_fb_helper_prepare(struct drm_device *dev,
282 struct drm_fb_helper *helper,
283 const struct drm_fb_helper_funcs *funcs)
284 {
285 }
286
287 static inline int drm_fb_helper_init(struct drm_device *dev,
288 struct drm_fb_helper *helper, int crtc_count,
289 int max_conn)
290 {
291 return 0;
292 }
293
294 static inline void drm_fb_helper_fini(struct drm_fb_helper *helper)
295 {
296 }
297
298 static inline int drm_fb_helper_blank(int blank, struct fb_info *info)
299 {
300 return 0;
301 }
302
303 static inline int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
304 struct fb_info *info)
305 {
306 return 0;
307 }
308
309 static inline int drm_fb_helper_set_par(struct fb_info *info)
310 {
311 return 0;
312 }
313
314 static inline int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
315 struct fb_info *info)
316 {
317 return 0;
318 }
319
320 static inline int
321 drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
322 {
323 return 0;
324 }
325
326 static inline struct fb_info *
327 drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper)
328 {
329 return NULL;
330 }
331
332 static inline void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper)
333 {
334 }
335 static inline void drm_fb_helper_release_fbi(struct drm_fb_helper *fb_helper)
336 {
337 }
338
339 static inline void drm_fb_helper_fill_var(struct fb_info *info,
340 struct drm_fb_helper *fb_helper,
341 uint32_t fb_width, uint32_t fb_height)
342 {
343 }
344
345 static inline void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
346 uint32_t depth)
347 {
348 }
349
350 static inline int drm_fb_helper_setcmap(struct fb_cmap *cmap,
351 struct fb_info *info)
352 {
353 return 0;
354 }
355
356 static inline void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper)
357 {
358 }
359
360 static inline ssize_t drm_fb_helper_sys_read(struct fb_info *info,
361 char __user *buf, size_t count,
362 loff_t *ppos)
363 {
364 return -ENODEV;
365 }
366
367 static inline ssize_t drm_fb_helper_sys_write(struct fb_info *info,
368 const char __user *buf,
369 size_t count, loff_t *ppos)
370 {
371 return -ENODEV;
372 }
373
374 static inline void drm_fb_helper_sys_fillrect(struct fb_info *info,
375 const struct fb_fillrect *rect)
376 {
377 }
378
379 static inline void drm_fb_helper_sys_copyarea(struct fb_info *info,
380 const struct fb_copyarea *area)
381 {
382 }
383
384 static inline void drm_fb_helper_sys_imageblit(struct fb_info *info,
385 const struct fb_image *image)
386 {
387 }
388
389 static inline void drm_fb_helper_cfb_fillrect(struct fb_info *info,
390 const struct fb_fillrect *rect)
391 {
392 }
393
394 static inline void drm_fb_helper_cfb_copyarea(struct fb_info *info,
395 const struct fb_copyarea *area)
396 {
397 }
398
399 static inline void drm_fb_helper_cfb_imageblit(struct fb_info *info,
400 const struct fb_image *image)
401 {
402 }
403
404 static inline void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper,
405 int state)
406 {
407 }
408
409 static inline int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
410 {
411 return 0;
412 }
413
414 static inline int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper,
415 int bpp_sel)
416 {
417 return 0;
418 }
419
420 static inline int
421 drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
422 {
423 return 0;
424 }
425
426 static inline int drm_fb_helper_debug_enter(struct fb_info *info)
427 {
428 return 0;
429 }
430
431 static inline int drm_fb_helper_debug_leave(struct fb_info *info)
432 {
433 return 0;
434 }
435
436 static inline struct drm_display_mode *
437 drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector,
438 int width, int height)
439 {
440 return NULL;
441 }
442
443 static inline struct drm_display_mode *
444 drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
445 int width, int height)
446 {
447 return NULL;
448 }
449
450 static inline int
451 drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper,
452 struct drm_connector *connector)
453 {
454 return 0;
455 }
456
457 static inline int
458 drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
459 struct drm_connector *connector)
460 {
461 return 0;
462 }
463 #endif
464 #endif
This page took 0.074009 seconds and 4 git commands to generate.