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