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