1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#ifndef DRM_FB_HELPER_H
31#define DRM_FB_HELPER_H
32
33struct drm_fb_helper;
34
35#include <drm/drm_client.h>
36#include <drm/drm_crtc.h>
37#include <drm/drm_device.h>
38#include <linux/kgdb.h>
39#include <linux/vgaarb.h>
40
41enum mode_set_atomic {
42 LEAVE_ATOMIC_MODE_SET,
43 ENTER_ATOMIC_MODE_SET,
44};
45
46struct drm_fb_offset {
47 int x, y;
48};
49
50struct drm_fb_helper_crtc {
51 struct drm_mode_set mode_set;
52 struct drm_display_mode *desired_mode;
53 int x, y;
54 int rotation;
55};
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74struct drm_fb_helper_surface_size {
75 u32 fb_width;
76 u32 fb_height;
77 u32 surface_width;
78 u32 surface_height;
79 u32 surface_bpp;
80 u32 surface_depth;
81};
82
83
84
85
86
87
88struct drm_fb_helper_funcs {
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 int (*fb_probe)(struct drm_fb_helper *helper,
104 struct drm_fb_helper_surface_size *sizes);
105};
106
107struct drm_fb_helper_connector {
108 struct drm_connector *connector;
109};
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133struct drm_fb_helper {
134
135
136
137
138
139 struct drm_client_dev client;
140
141
142
143
144
145
146 struct drm_client_buffer *buffer;
147
148 struct drm_framebuffer *fb;
149 struct drm_device *dev;
150 int crtc_count;
151 struct drm_fb_helper_crtc *crtc_info;
152 int connector_count;
153 int connector_info_alloc_count;
154
155
156
157
158
159
160 int sw_rotations;
161
162
163
164
165
166
167 struct drm_fb_helper_connector **connector_info;
168 const struct drm_fb_helper_funcs *funcs;
169 struct fb_info *fbdev;
170 u32 pseudo_palette[17];
171 struct drm_clip_rect dirty_clip;
172 spinlock_t dirty_lock;
173 struct work_struct dirty_work;
174 struct work_struct resume_work;
175
176
177
178
179
180
181
182
183
184
185
186 struct mutex lock;
187
188
189
190
191
192
193 struct list_head kernel_fb_list;
194
195
196
197
198
199
200
201
202 bool delayed_hotplug;
203
204
205
206
207
208
209
210
211
212
213
214 bool deferred_setup;
215
216
217
218
219
220
221
222
223
224
225 int preferred_bpp;
226};
227
228static inline struct drm_fb_helper *
229drm_fb_helper_from_client(struct drm_client_dev *client)
230{
231 return container_of(client, struct drm_fb_helper, client);
232}
233
234
235
236
237
238
239
240#define DRM_FB_HELPER_DEFAULT_OPS \
241 .fb_check_var = drm_fb_helper_check_var, \
242 .fb_set_par = drm_fb_helper_set_par, \
243 .fb_setcmap = drm_fb_helper_setcmap, \
244 .fb_blank = drm_fb_helper_blank, \
245 .fb_pan_display = drm_fb_helper_pan_display, \
246 .fb_debug_enter = drm_fb_helper_debug_enter, \
247 .fb_debug_leave = drm_fb_helper_debug_leave, \
248 .fb_ioctl = drm_fb_helper_ioctl
249
250#ifdef CONFIG_DRM_FBDEV_EMULATION
251void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
252 const struct drm_fb_helper_funcs *funcs);
253int drm_fb_helper_init(struct drm_device *dev,
254 struct drm_fb_helper *helper, int max_conn);
255void drm_fb_helper_fini(struct drm_fb_helper *helper);
256int drm_fb_helper_blank(int blank, struct fb_info *info);
257int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
258 struct fb_info *info);
259int drm_fb_helper_set_par(struct fb_info *info);
260int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
261 struct fb_info *info);
262
263int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper);
264
265struct fb_info *drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper);
266void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper);
267void drm_fb_helper_fill_info(struct fb_info *info,
268 struct drm_fb_helper *fb_helper,
269 struct drm_fb_helper_surface_size *sizes);
270
271void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper);
272
273void drm_fb_helper_deferred_io(struct fb_info *info,
274 struct list_head *pagelist);
275int drm_fb_helper_defio_init(struct drm_fb_helper *fb_helper);
276
277ssize_t drm_fb_helper_sys_read(struct fb_info *info, char __user *buf,
278 size_t count, loff_t *ppos);
279ssize_t drm_fb_helper_sys_write(struct fb_info *info, const char __user *buf,
280 size_t count, loff_t *ppos);
281
282void drm_fb_helper_sys_fillrect(struct fb_info *info,
283 const struct fb_fillrect *rect);
284void drm_fb_helper_sys_copyarea(struct fb_info *info,
285 const struct fb_copyarea *area);
286void drm_fb_helper_sys_imageblit(struct fb_info *info,
287 const struct fb_image *image);
288
289void drm_fb_helper_cfb_fillrect(struct fb_info *info,
290 const struct fb_fillrect *rect);
291void drm_fb_helper_cfb_copyarea(struct fb_info *info,
292 const struct fb_copyarea *area);
293void drm_fb_helper_cfb_imageblit(struct fb_info *info,
294 const struct fb_image *image);
295
296void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, bool suspend);
297void drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper,
298 bool suspend);
299
300int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info);
301
302int drm_fb_helper_ioctl(struct fb_info *info, unsigned int cmd,
303 unsigned long arg);
304
305int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper);
306int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel);
307int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper);
308int drm_fb_helper_debug_enter(struct fb_info *info);
309int drm_fb_helper_debug_leave(struct fb_info *info);
310struct drm_display_mode *
311drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector,
312 int width, int height);
313struct drm_display_mode *
314drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn);
315
316int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector);
317int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
318 struct drm_connector *connector);
319
320int drm_fb_helper_fbdev_setup(struct drm_device *dev,
321 struct drm_fb_helper *fb_helper,
322 const struct drm_fb_helper_funcs *funcs,
323 unsigned int preferred_bpp,
324 unsigned int max_conn_count);
325void drm_fb_helper_fbdev_teardown(struct drm_device *dev);
326
327void drm_fb_helper_lastclose(struct drm_device *dev);
328void drm_fb_helper_output_poll_changed(struct drm_device *dev);
329
330int drm_fb_helper_generic_probe(struct drm_fb_helper *fb_helper,
331 struct drm_fb_helper_surface_size *sizes);
332int drm_fbdev_generic_setup(struct drm_device *dev, unsigned int preferred_bpp);
333#else
334static inline void drm_fb_helper_prepare(struct drm_device *dev,
335 struct drm_fb_helper *helper,
336 const struct drm_fb_helper_funcs *funcs)
337{
338}
339
340static inline int drm_fb_helper_init(struct drm_device *dev,
341 struct drm_fb_helper *helper,
342 int max_conn)
343{
344
345 helper->dev = dev;
346 dev->fb_helper = helper;
347
348 return 0;
349}
350
351static inline void drm_fb_helper_fini(struct drm_fb_helper *helper)
352{
353 if (helper && helper->dev)
354 helper->dev->fb_helper = NULL;
355}
356
357static inline int drm_fb_helper_blank(int blank, struct fb_info *info)
358{
359 return 0;
360}
361
362static inline int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
363 struct fb_info *info)
364{
365 return 0;
366}
367
368static inline int drm_fb_helper_set_par(struct fb_info *info)
369{
370 return 0;
371}
372
373static inline int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
374 struct fb_info *info)
375{
376 return 0;
377}
378
379static inline int
380drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
381{
382 return 0;
383}
384
385static inline struct fb_info *
386drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper)
387{
388 return NULL;
389}
390
391static inline void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper)
392{
393}
394
395static inline void
396drm_fb_helper_fill_info(struct fb_info *info,
397 struct drm_fb_helper *fb_helper,
398 struct drm_fb_helper_surface_size *sizes)
399{
400}
401
402static inline int drm_fb_helper_setcmap(struct fb_cmap *cmap,
403 struct fb_info *info)
404{
405 return 0;
406}
407
408static inline int drm_fb_helper_ioctl(struct fb_info *info, unsigned int cmd,
409 unsigned long arg)
410{
411 return 0;
412}
413
414static inline void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper)
415{
416}
417
418static inline void drm_fb_helper_deferred_io(struct fb_info *info,
419 struct list_head *pagelist)
420{
421}
422
423static inline int drm_fb_helper_defio_init(struct drm_fb_helper *fb_helper)
424{
425 return -ENODEV;
426}
427
428static inline ssize_t drm_fb_helper_sys_read(struct fb_info *info,
429 char __user *buf, size_t count,
430 loff_t *ppos)
431{
432 return -ENODEV;
433}
434
435static inline ssize_t drm_fb_helper_sys_write(struct fb_info *info,
436 const char __user *buf,
437 size_t count, loff_t *ppos)
438{
439 return -ENODEV;
440}
441
442static inline void drm_fb_helper_sys_fillrect(struct fb_info *info,
443 const struct fb_fillrect *rect)
444{
445}
446
447static inline void drm_fb_helper_sys_copyarea(struct fb_info *info,
448 const struct fb_copyarea *area)
449{
450}
451
452static inline void drm_fb_helper_sys_imageblit(struct fb_info *info,
453 const struct fb_image *image)
454{
455}
456
457static inline void drm_fb_helper_cfb_fillrect(struct fb_info *info,
458 const struct fb_fillrect *rect)
459{
460}
461
462static inline void drm_fb_helper_cfb_copyarea(struct fb_info *info,
463 const struct fb_copyarea *area)
464{
465}
466
467static inline void drm_fb_helper_cfb_imageblit(struct fb_info *info,
468 const struct fb_image *image)
469{
470}
471
472static inline void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper,
473 bool suspend)
474{
475}
476
477static inline void
478drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper, bool suspend)
479{
480}
481
482static inline int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
483{
484 return 0;
485}
486
487static inline int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper,
488 int bpp_sel)
489{
490 return 0;
491}
492
493static inline int
494drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
495{
496 return 0;
497}
498
499static inline int drm_fb_helper_debug_enter(struct fb_info *info)
500{
501 return 0;
502}
503
504static inline int drm_fb_helper_debug_leave(struct fb_info *info)
505{
506 return 0;
507}
508
509static inline struct drm_display_mode *
510drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector,
511 int width, int height)
512{
513 return NULL;
514}
515
516static inline struct drm_display_mode *
517drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
518 int width, int height)
519{
520 return NULL;
521}
522
523static inline int
524drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper,
525 struct drm_connector *connector)
526{
527 return 0;
528}
529
530static inline int
531drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
532 struct drm_connector *connector)
533{
534 return 0;
535}
536
537static inline int
538drm_fb_helper_fbdev_setup(struct drm_device *dev,
539 struct drm_fb_helper *fb_helper,
540 const struct drm_fb_helper_funcs *funcs,
541 unsigned int preferred_bpp,
542 unsigned int max_conn_count)
543{
544
545 dev->fb_helper = fb_helper;
546
547 return 0;
548}
549
550static inline void drm_fb_helper_fbdev_teardown(struct drm_device *dev)
551{
552 dev->fb_helper = NULL;
553}
554
555static inline void drm_fb_helper_lastclose(struct drm_device *dev)
556{
557}
558
559static inline void drm_fb_helper_output_poll_changed(struct drm_device *dev)
560{
561}
562
563static inline int
564drm_fb_helper_generic_probe(struct drm_fb_helper *fb_helper,
565 struct drm_fb_helper_surface_size *sizes)
566{
567 return 0;
568}
569
570static inline int
571drm_fbdev_generic_setup(struct drm_device *dev, unsigned int preferred_bpp)
572{
573 return 0;
574}
575
576#endif
577
578
579
580
581
582
583
584
585
586
587
588static inline int
589drm_fb_helper_remove_conflicting_framebuffers(struct apertures_struct *a,
590 const char *name, bool primary)
591{
592#if IS_REACHABLE(CONFIG_FB)
593 return remove_conflicting_framebuffers(a, name, primary);
594#else
595 return 0;
596#endif
597}
598
599
600
601
602
603
604
605
606
607
608
609
610
611static inline int
612drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
613 int resource_id,
614 const char *name)
615{
616 int ret = 0;
617
618
619
620
621
622#if IS_REACHABLE(CONFIG_FB)
623 ret = remove_conflicting_pci_framebuffers(pdev, resource_id, name);
624#endif
625 if (ret == 0)
626 ret = vga_remove_vgacon(pdev);
627 return ret;
628}
629
630#endif
631