2 * Copyright (c) 2006-2009 Red Hat Inc.
3 * Copyright (c) 2006-2008 Intel Corporation
4 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
6 * DRM framebuffer helper functions
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.
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
27 * Dave Airlie <airlied@linux.ie>
28 * Jesse Barnes <jesse.barnes@intel.com>
30 #ifndef DRM_FB_HELPER_H
31 #define DRM_FB_HELPER_H
35 #include <linux/kgdb.h>
37 struct drm_fb_offset
{
41 struct drm_fb_helper_crtc
{
42 struct drm_mode_set mode_set
;
43 struct drm_display_mode
*desired_mode
;
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
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.
63 * So what is passed to drm_fb_helper_fill_var() should be fb_width/fb_height,
64 * rather than the surface size.
66 struct drm_fb_helper_surface_size
{
76 * struct drm_fb_helper_funcs - driver callbacks for the fbdev emulation library
78 * Driver callbacks used by the fbdev emulation helper library.
80 struct drm_fb_helper_funcs
{
84 * Set the given gamma LUT register on the given CRTC.
86 * This callback is optional.
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.
94 void (*gamma_set
)(struct drm_crtc
*crtc
, u16 red
, u16 green
,
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.
102 * This callback is optional.
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.
110 void (*gamma_get
)(struct drm_crtc
*crtc
, u16
*red
, u16
*green
,
111 u16
*blue
, int regno
);
116 * Driver callback to allocate and initialize the fbdev info structure.
117 * Furthermore it also needs to allocate the DRM framebuffer used to
120 * This callback is mandatory.
124 * The driver should return 0 on success and a negative error code on
127 int (*fb_probe
)(struct drm_fb_helper
*helper
,
128 struct drm_fb_helper_surface_size
*sizes
);
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.
139 * This callback is optional.
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.
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
);
154 struct drm_fb_helper_connector
{
155 struct drm_connector
*connector
;
159 * struct drm_fb_helper - main structure to emulate fbdev on top of KMS
160 * @fb: Scanout framebuffer object
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
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
176 struct drm_fb_helper
{
177 struct drm_framebuffer
*fb
;
178 struct drm_device
*dev
;
180 struct drm_fb_helper_crtc
*crtc_info
;
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];
191 * Entry on the global kernel_fb_helper_list, used for kgdb entry/exit.
193 struct list_head kernel_fb_list
;
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.
202 bool delayed_hotplug
;
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).
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
,
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
);
230 int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper
*fb_helper
);
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
,
240 void drm_fb_helper_unlink_fbi(struct drm_fb_helper
*fb_helper
);
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
);
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
);
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
);
261 void drm_fb_helper_set_suspend(struct drm_fb_helper
*fb_helper
, int state
);
263 int drm_fb_helper_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
);
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
);
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
);
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
)
287 static inline int drm_fb_helper_init(struct drm_device
*dev
,
288 struct drm_fb_helper
*helper
, int crtc_count
,
294 static inline void drm_fb_helper_fini(struct drm_fb_helper
*helper
)
298 static inline int drm_fb_helper_blank(int blank
, struct fb_info
*info
)
303 static inline int drm_fb_helper_pan_display(struct fb_var_screeninfo
*var
,
304 struct fb_info
*info
)
309 static inline int drm_fb_helper_set_par(struct fb_info
*info
)
314 static inline int drm_fb_helper_check_var(struct fb_var_screeninfo
*var
,
315 struct fb_info
*info
)
321 drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper
*fb_helper
)
326 static inline struct fb_info
*
327 drm_fb_helper_alloc_fbi(struct drm_fb_helper
*fb_helper
)
332 static inline void drm_fb_helper_unregister_fbi(struct drm_fb_helper
*fb_helper
)
335 static inline void drm_fb_helper_release_fbi(struct drm_fb_helper
*fb_helper
)
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
)
345 static inline void drm_fb_helper_fill_fix(struct fb_info
*info
, uint32_t pitch
,
350 static inline int drm_fb_helper_setcmap(struct fb_cmap
*cmap
,
351 struct fb_info
*info
)
356 static inline void drm_fb_helper_unlink_fbi(struct drm_fb_helper
*fb_helper
)
360 static inline ssize_t
drm_fb_helper_sys_read(struct fb_info
*info
,
361 char __user
*buf
, size_t count
,
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
)
374 static inline void drm_fb_helper_sys_fillrect(struct fb_info
*info
,
375 const struct fb_fillrect
*rect
)
379 static inline void drm_fb_helper_sys_copyarea(struct fb_info
*info
,
380 const struct fb_copyarea
*area
)
384 static inline void drm_fb_helper_sys_imageblit(struct fb_info
*info
,
385 const struct fb_image
*image
)
389 static inline void drm_fb_helper_cfb_fillrect(struct fb_info
*info
,
390 const struct fb_fillrect
*rect
)
394 static inline void drm_fb_helper_cfb_copyarea(struct fb_info
*info
,
395 const struct fb_copyarea
*area
)
399 static inline void drm_fb_helper_cfb_imageblit(struct fb_info
*info
,
400 const struct fb_image
*image
)
404 static inline void drm_fb_helper_set_suspend(struct drm_fb_helper
*fb_helper
,
409 static inline int drm_fb_helper_hotplug_event(struct drm_fb_helper
*fb_helper
)
414 static inline int drm_fb_helper_initial_config(struct drm_fb_helper
*fb_helper
,
421 drm_fb_helper_single_add_all_connectors(struct drm_fb_helper
*fb_helper
)
426 static inline int drm_fb_helper_debug_enter(struct fb_info
*info
)
431 static inline int drm_fb_helper_debug_leave(struct fb_info
*info
)
436 static inline struct drm_display_mode
*
437 drm_has_preferred_mode(struct drm_fb_helper_connector
*fb_connector
,
438 int width
, int height
)
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
)
451 drm_fb_helper_add_one_connector(struct drm_fb_helper
*fb_helper
,
452 struct drm_connector
*connector
)
458 drm_fb_helper_remove_one_connector(struct drm_fb_helper
*fb_helper
,
459 struct drm_connector
*connector
)