blob: d2d4ad1918ac34b998558fc08b997b720e773209 [file] [log] [blame]
Dave Airlie785b93e2009-08-28 15:46:53 +10001/*
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
Dave Airlie4abe3522010-03-30 05:34:18 +000033struct drm_fb_helper;
34
Jesse Barnes1a7aba72010-08-05 09:22:31 -050035#include <linux/kgdb.h>
36
Dave Airlieb0ee9e72014-10-20 16:31:53 +100037struct drm_fb_offset {
38 int x, y;
39};
40
Dave Airlie785b93e2009-08-28 15:46:53 +100041struct drm_fb_helper_crtc {
Dave Airlie785b93e2009-08-28 15:46:53 +100042 struct drm_mode_set mode_set;
Dave Airlie8be48d92010-03-30 05:34:14 +000043 struct drm_display_mode *desired_mode;
Dave Airlieb0ee9e72014-10-20 16:31:53 +100044 int x, y;
Dave Airlie785b93e2009-08-28 15:46:53 +100045};
46
Rob Clarkb7b5ee52015-03-11 10:23:08 -040047/**
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 */
Dave Airlie38651672010-03-30 05:34:13 +000066struct 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
Daniel Vetter207fd322013-01-20 22:13:14 +010075/**
76 * struct drm_fb_helper_funcs - driver callbacks for the fbdev emulation library
Daniel Vetter207fd322013-01-20 22:13:14 +010077 *
78 * Driver callbacks used by the fbdev emulation helper library.
79 */
Dave Airlie4abe3522010-03-30 05:34:18 +000080struct drm_fb_helper_funcs {
Daniel Vetter264d6972015-12-04 09:45:42 +010081 /**
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 */
Dave Airlie4abe3522010-03-30 05:34:18 +000094 void (*gamma_set)(struct drm_crtc *crtc, u16 red, u16 green,
95 u16 blue, int regno);
Daniel Vetter264d6972015-12-04 09:45:42 +010096 /**
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 */
Dave Airlie4abe3522010-03-30 05:34:18 +0000110 void (*gamma_get)(struct drm_crtc *crtc, u16 *red, u16 *green,
111 u16 *blue, int regno);
112
Daniel Vetter264d6972015-12-04 09:45:42 +0100113 /**
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 */
Dave Airlie4abe3522010-03-30 05:34:18 +0000127 int (*fb_probe)(struct drm_fb_helper *helper,
128 struct drm_fb_helper_surface_size *sizes);
Daniel Vetter264d6972015-12-04 09:45:42 +0100129
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 */
Jesse Barnes11e17a02013-02-19 13:31:39 -0800147 bool (*initial_config)(struct drm_fb_helper *fb_helper,
148 struct drm_fb_helper_crtc **crtcs,
149 struct drm_display_mode **modes,
Dave Airlieb0ee9e72014-10-20 16:31:53 +1000150 struct drm_fb_offset *offsets,
Jesse Barnes11e17a02013-02-19 13:31:39 -0800151 bool *enabled, int width, int height);
Dave Airlie4abe3522010-03-30 05:34:18 +0000152};
153
Dave Airlied50ba252009-09-23 14:44:08 +1000154struct drm_fb_helper_connector {
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000155 struct drm_connector *connector;
Dave Airlied50ba252009-09-23 14:44:08 +1000156};
157
Rob Clark9685cd92015-08-25 15:35:57 -0400158/**
Daniel Vetter264d6972015-12-04 09:45:42 +0100159 * struct drm_fb_helper - main structure to emulate fbdev on top of KMS
160 * @fb: Scanout framebuffer object
161 * @dev: DRM device
Rob Clark9685cd92015-08-25 15:35:57 -0400162 * @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
Daniel Vetter264d6972015-12-04 09:45:42 +0100166 * @connector_info: array of per-connector information
Rob Clark9685cd92015-08-25 15:35:57 -0400167 * @funcs: driver callbacks for fb helper
168 * @fbdev: emulated fbdev device info struct
169 * @pseudo_palette: fake palette of 16 colors
Daniel Vetter264d6972015-12-04 09:45:42 +0100170 *
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.
Rob Clark9685cd92015-08-25 15:35:57 -0400175 */
Dave Airlie785b93e2009-08-28 15:46:53 +1000176struct drm_fb_helper {
177 struct drm_framebuffer *fb;
178 struct drm_device *dev;
Dave Airlie785b93e2009-08-28 15:46:53 +1000179 int crtc_count;
180 struct drm_fb_helper_crtc *crtc_info;
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000181 int connector_count;
Dave Airlie65c2a892014-06-05 14:01:30 +1000182 int connector_info_alloc_count;
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000183 struct drm_fb_helper_connector **connector_info;
Thierry Reding3a493872014-06-27 17:19:23 +0200184 const struct drm_fb_helper_funcs *funcs;
Dave Airlie38651672010-03-30 05:34:13 +0000185 struct fb_info *fbdev;
186 u32 pseudo_palette[17];
Daniel Vetter264d6972015-12-04 09:45:42 +0100187
188 /**
189 * @kernel_fb_list:
190 *
191 * Entry on the global kernel_fb_helper_list, used for kgdb entry/exit.
192 */
Dave Airlie785b93e2009-08-28 15:46:53 +1000193 struct list_head kernel_fb_list;
Dave Airlie8be48d92010-03-30 05:34:14 +0000194
Daniel Vetter264d6972015-12-04 09:45:42 +0100195 /**
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 */
Dave Airlie4abe3522010-03-30 05:34:18 +0000202 bool delayed_hotplug;
Rob Clarkbbb1e522015-08-25 15:35:58 -0400203
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;
Dave Airlie785b93e2009-08-28 15:46:53 +1000214};
215
Archit Tanejaa03fdcb2015-08-05 12:28:57 +0530216#ifdef CONFIG_DRM_FBDEV_EMULATION
Thierry Reding10a23102014-06-27 17:19:24 +0200217void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
218 const struct drm_fb_helper_funcs *funcs);
Dave Airlie4abe3522010-03-30 05:34:18 +0000219int drm_fb_helper_init(struct drm_device *dev,
220 struct drm_fb_helper *helper, int crtc_count,
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000221 int max_conn);
Dave Airlie4abe3522010-03-30 05:34:18 +0000222void drm_fb_helper_fini(struct drm_fb_helper *helper);
Dave Airlie785b93e2009-08-28 15:46:53 +1000223int drm_fb_helper_blank(int blank, struct fb_info *info);
224int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
225 struct fb_info *info);
226int drm_fb_helper_set_par(struct fb_info *info);
227int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
228 struct fb_info *info);
Dave Airlie785b93e2009-08-28 15:46:53 +1000229
Daniel Vetterb7bdf0a82015-08-25 17:20:28 +0200230int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper);
Archit Tanejab8017d62015-07-22 14:57:56 +0530231
232struct fb_info *drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper);
233void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper);
234void drm_fb_helper_release_fbi(struct drm_fb_helper *fb_helper);
Dave Airlie38651672010-03-30 05:34:13 +0000235void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
Dave Airlie785b93e2009-08-28 15:46:53 +1000236 uint32_t fb_width, uint32_t fb_height);
Dave Airlie3632ef82011-01-15 09:27:00 +1000237void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
238 uint32_t depth);
239
Archit Taneja47074ab2015-07-22 14:57:57 +0530240void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper);
241
Archit Tanejacbb1a822015-07-31 16:21:41 +0530242ssize_t drm_fb_helper_sys_read(struct fb_info *info, char __user *buf,
243 size_t count, loff_t *ppos);
244ssize_t drm_fb_helper_sys_write(struct fb_info *info, const char __user *buf,
245 size_t count, loff_t *ppos);
246
Archit Taneja742547b2015-07-31 16:21:42 +0530247void drm_fb_helper_sys_fillrect(struct fb_info *info,
248 const struct fb_fillrect *rect);
249void drm_fb_helper_sys_copyarea(struct fb_info *info,
250 const struct fb_copyarea *area);
251void drm_fb_helper_sys_imageblit(struct fb_info *info,
252 const struct fb_image *image);
253
254void drm_fb_helper_cfb_fillrect(struct fb_info *info,
255 const struct fb_fillrect *rect);
256void drm_fb_helper_cfb_copyarea(struct fb_info *info,
257 const struct fb_copyarea *area);
258void drm_fb_helper_cfb_imageblit(struct fb_info *info,
259 const struct fb_image *image);
260
Archit Tanejafdefa582015-07-31 16:21:43 +0530261void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, int state);
262
Dave Airlie068143d2009-10-05 09:58:02 +1000263int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info);
Dave Airlied50ba252009-09-23 14:44:08 +1000264
Chris Wilson73943712011-04-22 11:03:57 +0100265int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper);
Thierry Reding01934c22014-12-19 11:21:32 +0100266int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel);
Dave Airlie0b4c0f32010-03-30 05:34:15 +0000267int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper);
Jesse Barnes1a7aba72010-08-05 09:22:31 -0500268int drm_fb_helper_debug_enter(struct fb_info *info);
269int drm_fb_helper_debug_leave(struct fb_info *info);
Jesse Barnes2f1046f2014-02-12 12:26:24 -0800270struct drm_display_mode *
271drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector,
272 int width, int height);
273struct drm_display_mode *
274drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
275 int width, int height);
Dave Airlie8be48d92010-03-30 05:34:14 +0000276
Dave Airlie65c2a892014-06-05 14:01:30 +1000277int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector);
278int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
279 struct drm_connector *connector);
Archit Tanejaa03fdcb2015-08-05 12:28:57 +0530280#else
281static 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
287static 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
294static inline void drm_fb_helper_fini(struct drm_fb_helper *helper)
295{
296}
297
298static inline int drm_fb_helper_blank(int blank, struct fb_info *info)
299{
300 return 0;
301}
302
303static inline int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
304 struct fb_info *info)
305{
306 return 0;
307}
308
309static inline int drm_fb_helper_set_par(struct fb_info *info)
310{
311 return 0;
312}
313
314static inline int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
315 struct fb_info *info)
316{
317 return 0;
318}
319
Daniel Vetterb7bdf0a82015-08-25 17:20:28 +0200320static inline int
Archit Tanejaa03fdcb2015-08-05 12:28:57 +0530321drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
322{
Daniel Vetterb7bdf0a82015-08-25 17:20:28 +0200323 return 0;
Archit Tanejaa03fdcb2015-08-05 12:28:57 +0530324}
325
326static inline struct fb_info *
327drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper)
328{
329 return NULL;
330}
331
332static inline void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper)
333{
334}
335static inline void drm_fb_helper_release_fbi(struct drm_fb_helper *fb_helper)
336{
337}
338
339static 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
345static inline void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
346 uint32_t depth)
347{
348}
349
350static inline int drm_fb_helper_setcmap(struct fb_cmap *cmap,
351 struct fb_info *info)
352{
353 return 0;
354}
355
356static inline void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper)
357{
358}
359
360static 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
367static 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
374static inline void drm_fb_helper_sys_fillrect(struct fb_info *info,
375 const struct fb_fillrect *rect)
376{
377}
378
379static inline void drm_fb_helper_sys_copyarea(struct fb_info *info,
380 const struct fb_copyarea *area)
381{
382}
383
384static inline void drm_fb_helper_sys_imageblit(struct fb_info *info,
385 const struct fb_image *image)
386{
387}
388
389static inline void drm_fb_helper_cfb_fillrect(struct fb_info *info,
390 const struct fb_fillrect *rect)
391{
392}
393
394static inline void drm_fb_helper_cfb_copyarea(struct fb_info *info,
395 const struct fb_copyarea *area)
396{
397}
398
399static inline void drm_fb_helper_cfb_imageblit(struct fb_info *info,
400 const struct fb_image *image)
401{
402}
403
404static inline void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper,
405 int state)
406{
407}
408
409static inline int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
410{
411 return 0;
412}
413
414static inline int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper,
415 int bpp_sel)
416{
417 return 0;
418}
419
420static inline int
421drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
422{
423 return 0;
424}
425
426static inline int drm_fb_helper_debug_enter(struct fb_info *info)
427{
428 return 0;
429}
430
431static inline int drm_fb_helper_debug_leave(struct fb_info *info)
432{
433 return 0;
434}
435
436static inline struct drm_display_mode *
437drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector,
438 int width, int height)
439{
440 return NULL;
441}
442
443static inline struct drm_display_mode *
444drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
445 int width, int height)
446{
447 return NULL;
448}
449
450static inline int
451drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper,
452 struct drm_connector *connector)
453{
454 return 0;
455}
456
457static inline int
458drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
459 struct drm_connector *connector)
460{
461 return 0;
462}
463#endif
Dave Airlie785b93e2009-08-28 15:46:53 +1000464#endif