1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_FB_H
3 #define _LINUX_FB_H
4
5 #include <uapi/linux/fb.h>
6
7 #define FBIO_CURSOR _IOWR('F', 0x08, struct fb_cursor_user)
8
9 #include <linux/mutex.h>
10 #include <linux/printk.h>
11 #include <linux/refcount.h>
12 #include <linux/types.h>
13 #include <linux/workqueue.h>
14
15 #include <asm/video.h>
16
17 struct backlight_device;
18 struct device;
19 struct device_node;
20 struct fb_info;
21 struct file;
22 struct i2c_adapter;
23 struct inode;
24 struct lcd_device;
25 struct module;
26 struct notifier_block;
27 struct page;
28 struct videomode;
29 struct vm_area_struct;
30
31 /* Definitions below are used in the parsed monitor specs */
32 #define FB_DPMS_ACTIVE_OFF 1
33 #define FB_DPMS_SUSPEND 2
34 #define FB_DPMS_STANDBY 4
35
36 #define FB_DISP_DDI 1
37 #define FB_DISP_ANA_700_300 2
38 #define FB_DISP_ANA_714_286 4
39 #define FB_DISP_ANA_1000_400 8
40 #define FB_DISP_ANA_700_000 16
41
42 #define FB_DISP_MONO 32
43 #define FB_DISP_RGB 64
44 #define FB_DISP_MULTI 128
45 #define FB_DISP_UNKNOWN 256
46
47 #define FB_SIGNAL_NONE 0
48 #define FB_SIGNAL_BLANK_BLANK 1
49 #define FB_SIGNAL_SEPARATE 2
50 #define FB_SIGNAL_COMPOSITE 4
51 #define FB_SIGNAL_SYNC_ON_GREEN 8
52 #define FB_SIGNAL_SERRATION_ON 16
53
54 #define FB_MISC_PRIM_COLOR 1
55 #define FB_MISC_1ST_DETAIL 2 /* First Detailed Timing is preferred */
56 #define FB_MISC_HDMI 4
57 struct fb_chroma {
58 __u32 redx; /* in fraction of 1024 */
59 __u32 greenx;
60 __u32 bluex;
61 __u32 whitex;
62 __u32 redy;
63 __u32 greeny;
64 __u32 bluey;
65 __u32 whitey;
66 };
67
68 struct fb_monspecs {
69 struct fb_chroma chroma;
70 struct fb_videomode *modedb; /* mode database */
71 __u8 manufacturer[4]; /* Manufacturer */
72 __u8 monitor[14]; /* Monitor String */
73 __u8 serial_no[14]; /* Serial Number */
74 __u8 ascii[14]; /* ? */
75 __u32 modedb_len; /* mode database length */
76 __u32 model; /* Monitor Model */
77 __u32 serial; /* Serial Number - Integer */
78 __u32 year; /* Year manufactured */
79 __u32 week; /* Week Manufactured */
80 __u32 hfmin; /* hfreq lower limit (Hz) */
81 __u32 hfmax; /* hfreq upper limit (Hz) */
82 __u32 dclkmin; /* pixelclock lower limit (Hz) */
83 __u32 dclkmax; /* pixelclock upper limit (Hz) */
84 __u16 input; /* display type - see FB_DISP_* */
85 __u16 dpms; /* DPMS support - see FB_DPMS_ */
86 __u16 signal; /* Signal Type - see FB_SIGNAL_* */
87 __u16 vfmin; /* vfreq lower limit (Hz) */
88 __u16 vfmax; /* vfreq upper limit (Hz) */
89 __u16 gamma; /* Gamma - in fractions of 100 */
90 __u16 gtf : 1; /* supports GTF */
91 __u16 misc; /* Misc flags - see FB_MISC_* */
92 __u8 version; /* EDID version... */
93 __u8 revision; /* ...and revision */
94 __u8 max_x; /* Maximum horizontal size (cm) */
95 __u8 max_y; /* Maximum vertical size (cm) */
96 };
97
98 struct fb_cmap_user {
99 __u32 start; /* First entry */
100 __u32 len; /* Number of entries */
101 __u16 __user *red; /* Red values */
102 __u16 __user *green;
103 __u16 __user *blue;
104 __u16 __user *transp; /* transparency, can be NULL */
105 };
106
107 struct fb_image_user {
108 __u32 dx; /* Where to place image */
109 __u32 dy;
110 __u32 width; /* Size of image */
111 __u32 height;
112 __u32 fg_color; /* Only used when a mono bitmap */
113 __u32 bg_color;
114 __u8 depth; /* Depth of the image */
115 const char __user *data; /* Pointer to image data */
116 struct fb_cmap_user cmap; /* color map info */
117 };
118
119 struct fb_cursor_user {
120 __u16 set; /* what to set */
121 __u16 enable; /* cursor on/off */
122 __u16 rop; /* bitop operation */
123 const char __user *mask; /* cursor mask bits */
124 struct fbcurpos hot; /* cursor hot spot */
125 struct fb_image_user image; /* Cursor image */
126 };
127
128 /*
129 * Register/unregister for framebuffer events
130 */
131
132 /* The resolution of the passed in fb_info about to change */
133 #define FB_EVENT_MODE_CHANGE 0x01
134
135 #ifdef CONFIG_GUMSTIX_AM200EPD
136 /* only used by mach-pxa/am200epd.c */
137 #define FB_EVENT_FB_REGISTERED 0x05
138 #define FB_EVENT_FB_UNREGISTERED 0x06
139 #endif
140
141 /* A display blank is requested */
142 #define FB_EVENT_BLANK 0x09
143
144 struct fb_event {
145 struct fb_info *info;
146 void *data;
147 };
148
149 /* Enough for the VT console needs, see its max_font_width/height */
150 #define FB_MAX_BLIT_WIDTH 64
151 #define FB_MAX_BLIT_HEIGHT 128
152
153 struct fb_blit_caps {
154 DECLARE_BITMAP(x, FB_MAX_BLIT_WIDTH);
155 DECLARE_BITMAP(y, FB_MAX_BLIT_HEIGHT);
156 u32 len;
157 u32 flags;
158 };
159
160 #ifdef CONFIG_FB_NOTIFY
161 extern int fb_register_client(struct notifier_block *nb);
162 extern int fb_unregister_client(struct notifier_block *nb);
163 extern int fb_notifier_call_chain(unsigned long val, void *v);
164 #else
fb_register_client(struct notifier_block * nb)165 static inline int fb_register_client(struct notifier_block *nb)
166 {
167 return 0;
168 };
169
fb_unregister_client(struct notifier_block * nb)170 static inline int fb_unregister_client(struct notifier_block *nb)
171 {
172 return 0;
173 };
174
fb_notifier_call_chain(unsigned long val,void * v)175 static inline int fb_notifier_call_chain(unsigned long val, void *v)
176 {
177 return 0;
178 };
179 #endif
180
181 /*
182 * Pixmap structure definition
183 *
184 * The purpose of this structure is to translate data
185 * from the hardware independent format of fbdev to what
186 * format the hardware needs.
187 */
188
189 #define FB_PIXMAP_DEFAULT 1 /* used internally by fbcon */
190 #define FB_PIXMAP_SYSTEM 2 /* memory is in system RAM */
191 #define FB_PIXMAP_IO 4 /* memory is iomapped */
192 #define FB_PIXMAP_SYNC 256 /* set if GPU can DMA */
193
194 struct fb_pixmap {
195 u8 *addr; /* pointer to memory */
196 u32 size; /* size of buffer in bytes */
197 u32 offset; /* current offset to buffer */
198 u32 buf_align; /* byte alignment of each bitmap */
199 u32 scan_align; /* alignment per scanline */
200 u32 access_align; /* alignment per read/write (bits) */
201 u32 flags; /* see FB_PIXMAP_* */
202 /* supported bit block dimensions */
203 /* Format: test_bit(width - 1, blit_x) */
204 /* test_bit(height - 1, blit_y) */
205 /* if zero, will be set to full (all) */
206 DECLARE_BITMAP(blit_x, FB_MAX_BLIT_WIDTH);
207 DECLARE_BITMAP(blit_y, FB_MAX_BLIT_HEIGHT);
208 /* access methods */
209 void (*writeio)(struct fb_info *info, void __iomem *dst, void *src, unsigned int size);
210 void (*readio) (struct fb_info *info, void *dst, void __iomem *src, unsigned int size);
211 };
212
213 #ifdef CONFIG_FB_DEFERRED_IO
214 struct fb_deferred_io_pageref {
215 struct page *page;
216 unsigned long offset;
217 /* private */
218 struct list_head list;
219 };
220
221 struct fb_deferred_io {
222 /* delay between mkwrite and deferred handler */
223 unsigned long delay;
224 bool sort_pagereflist; /* sort pagelist by offset */
225 int open_count; /* number of opened files; protected by fb_info lock */
226 struct mutex lock; /* mutex that protects the pageref list */
227 struct list_head pagereflist; /* list of pagerefs for touched pages */
228 /* callback */
229 struct page *(*get_page)(struct fb_info *info, unsigned long offset);
230 void (*deferred_io)(struct fb_info *info, struct list_head *pagelist);
231 };
232 #endif
233
234 /*
235 * Frame buffer operations
236 *
237 * LOCKING NOTE: those functions must _ALL_ be called with the console
238 * semaphore held, this is the only suitable locking mechanism we have
239 * in 2.6. Some may be called at interrupt time at this point though.
240 *
241 * The exception to this is the debug related hooks. Putting the fb
242 * into a debug state (e.g. flipping to the kernel console) and restoring
243 * it must be done in a lock-free manner, so low level drivers should
244 * keep track of the initial console (if applicable) and may need to
245 * perform direct, unlocked hardware writes in these hooks.
246 */
247
248 struct fb_ops {
249 /* open/release and usage marking */
250 struct module *owner;
251 int (*fb_open)(struct fb_info *info, int user);
252 int (*fb_release)(struct fb_info *info, int user);
253
254 /* For framebuffers with strange non linear layouts or that do not
255 * work with normal memory mapped access
256 */
257 ssize_t (*fb_read)(struct fb_info *info, char __user *buf,
258 size_t count, loff_t *ppos);
259 ssize_t (*fb_write)(struct fb_info *info, const char __user *buf,
260 size_t count, loff_t *ppos);
261
262 /* checks var and eventually tweaks it to something supported,
263 * DO NOT MODIFY PAR */
264 int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);
265
266 /* set the video mode according to info->var */
267 int (*fb_set_par)(struct fb_info *info);
268
269 /* set color register */
270 int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
271 unsigned blue, unsigned transp, struct fb_info *info);
272
273 /* set color registers in batch */
274 int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);
275
276 /* blank display */
277 int (*fb_blank)(int blank, struct fb_info *info);
278
279 /* pan display */
280 int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);
281
282 /* Draws a rectangle */
283 void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);
284 /* Copy data from area to another */
285 void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);
286 /* Draws a image to the display */
287 void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);
288
289 /* Draws cursor */
290 int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor);
291
292 /* wait for blit idle, optional */
293 int (*fb_sync)(struct fb_info *info);
294
295 /* perform fb specific ioctl (optional) */
296 int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,
297 unsigned long arg);
298
299 /* Handle 32bit compat ioctl (optional) */
300 int (*fb_compat_ioctl)(struct fb_info *info, unsigned cmd,
301 unsigned long arg);
302
303 /* perform fb specific mmap */
304 int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);
305
306 /* get capability given var */
307 void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps,
308 struct fb_var_screeninfo *var);
309
310 /* teardown any resources to do with this framebuffer */
311 void (*fb_destroy)(struct fb_info *info);
312
313 /* called at KDB enter and leave time to prepare the console */
314 int (*fb_debug_enter)(struct fb_info *info);
315 int (*fb_debug_leave)(struct fb_info *info);
316 };
317
318 #ifdef CONFIG_FB_TILEBLITTING
319 #define FB_TILE_CURSOR_NONE 0
320 #define FB_TILE_CURSOR_UNDERLINE 1
321 #define FB_TILE_CURSOR_LOWER_THIRD 2
322 #define FB_TILE_CURSOR_LOWER_HALF 3
323 #define FB_TILE_CURSOR_TWO_THIRDS 4
324 #define FB_TILE_CURSOR_BLOCK 5
325
326 struct fb_tilemap {
327 __u32 width; /* width of each tile in pixels */
328 __u32 height; /* height of each tile in scanlines */
329 __u32 depth; /* color depth of each tile */
330 __u32 length; /* number of tiles in the map */
331 const __u8 *data; /* actual tile map: a bitmap array, packed
332 to the nearest byte */
333 };
334
335 struct fb_tilerect {
336 __u32 sx; /* origin in the x-axis */
337 __u32 sy; /* origin in the y-axis */
338 __u32 width; /* number of tiles in the x-axis */
339 __u32 height; /* number of tiles in the y-axis */
340 __u32 index; /* what tile to use: index to tile map */
341 __u32 fg; /* foreground color */
342 __u32 bg; /* background color */
343 __u32 rop; /* raster operation */
344 };
345
346 struct fb_tilearea {
347 __u32 sx; /* source origin in the x-axis */
348 __u32 sy; /* source origin in the y-axis */
349 __u32 dx; /* destination origin in the x-axis */
350 __u32 dy; /* destination origin in the y-axis */
351 __u32 width; /* number of tiles in the x-axis */
352 __u32 height; /* number of tiles in the y-axis */
353 };
354
355 struct fb_tileblit {
356 __u32 sx; /* origin in the x-axis */
357 __u32 sy; /* origin in the y-axis */
358 __u32 width; /* number of tiles in the x-axis */
359 __u32 height; /* number of tiles in the y-axis */
360 __u32 fg; /* foreground color */
361 __u32 bg; /* background color */
362 __u32 length; /* number of tiles to draw */
363 __u32 *indices; /* array of indices to tile map */
364 };
365
366 struct fb_tilecursor {
367 __u32 sx; /* cursor position in the x-axis */
368 __u32 sy; /* cursor position in the y-axis */
369 __u32 mode; /* 0 = erase, 1 = draw */
370 __u32 shape; /* see FB_TILE_CURSOR_* */
371 __u32 fg; /* foreground color */
372 __u32 bg; /* background color */
373 };
374
375 struct fb_tile_ops {
376 /* set tile characteristics */
377 void (*fb_settile)(struct fb_info *info, struct fb_tilemap *map);
378
379 /* all dimensions from hereon are in terms of tiles */
380
381 /* move a rectangular region of tiles from one area to another*/
382 void (*fb_tilecopy)(struct fb_info *info, struct fb_tilearea *area);
383 /* fill a rectangular region with a tile */
384 void (*fb_tilefill)(struct fb_info *info, struct fb_tilerect *rect);
385 /* copy an array of tiles */
386 void (*fb_tileblit)(struct fb_info *info, struct fb_tileblit *blit);
387 /* cursor */
388 void (*fb_tilecursor)(struct fb_info *info,
389 struct fb_tilecursor *cursor);
390 /* get maximum length of the tile map */
391 int (*fb_get_tilemax)(struct fb_info *info);
392 };
393 #endif /* CONFIG_FB_TILEBLITTING */
394
395 /* FBINFO_* = fb_info.flags bit flags */
396 #define FBINFO_HWACCEL_DISABLED 0x0002
397 /* When FBINFO_HWACCEL_DISABLED is set:
398 * Hardware acceleration is turned off. Software implementations
399 * of required functions (copyarea(), fillrect(), and imageblit())
400 * takes over; acceleration engine should be in a quiescent state */
401
402 /* hints */
403 #define FBINFO_VIRTFB 0x0004 /* FB is System RAM, not device. */
404 #define FBINFO_PARTIAL_PAN_OK 0x0040 /* otw use pan only for double-buffering */
405 #define FBINFO_READS_FAST 0x0080 /* soft-copy faster than rendering */
406
407 /* hardware supported ops */
408 /* semantics: when a bit is set, it indicates that the operation is
409 * accelerated by hardware.
410 * required functions will still work even if the bit is not set.
411 * optional functions may not even exist if the flag bit is not set.
412 */
413 #define FBINFO_HWACCEL_NONE 0x0000
414 #define FBINFO_HWACCEL_COPYAREA 0x0100 /* required */
415 #define FBINFO_HWACCEL_FILLRECT 0x0200 /* required */
416 #define FBINFO_HWACCEL_IMAGEBLIT 0x0400 /* required */
417 #define FBINFO_HWACCEL_ROTATE 0x0800 /* optional */
418 #define FBINFO_HWACCEL_XPAN 0x1000 /* optional */
419 #define FBINFO_HWACCEL_YPAN 0x2000 /* optional */
420 #define FBINFO_HWACCEL_YWRAP 0x4000 /* optional */
421
422 #define FBINFO_MISC_TILEBLITTING 0x20000 /* use tile blitting */
423
424 /* A driver may set this flag to indicate that it does want a set_par to be
425 * called every time when fbcon_switch is executed. The advantage is that with
426 * this flag set you can really be sure that set_par is always called before
427 * any of the functions dependent on the correct hardware state or altering
428 * that state, even if you are using some broken X releases. The disadvantage
429 * is that it introduces unwanted delays to every console switch if set_par
430 * is slow. It is a good idea to try this flag in the drivers initialization
431 * code whenever there is a bug report related to switching between X and the
432 * framebuffer console.
433 */
434 #define FBINFO_MISC_ALWAYS_SETPAR 0x40000
435
436 /*
437 * Host and GPU endianness differ.
438 */
439 #define FBINFO_FOREIGN_ENDIAN 0x100000
440 /*
441 * Big endian math. This is the same flags as above, but with different
442 * meaning, it is set by the fb subsystem depending FOREIGN_ENDIAN flag
443 * and host endianness. Drivers should not use this flag.
444 */
445 #define FBINFO_BE_MATH 0x100000
446 /*
447 * Hide smem_start in the FBIOGET_FSCREENINFO IOCTL. This is used by modern DRM
448 * drivers to stop userspace from trying to share buffers behind the kernel's
449 * back. Instead dma-buf based buffer sharing should be used.
450 */
451 #define FBINFO_HIDE_SMEM_START 0x200000
452
453
454 struct fb_info {
455 refcount_t count;
456 int node;
457 int flags;
458 /*
459 * -1 by default, set to a FB_ROTATE_* value by the driver, if it knows
460 * a lcd is not mounted upright and fbcon should rotate to compensate.
461 */
462 int fbcon_rotate_hint;
463 struct mutex lock; /* Lock for open/release/ioctl funcs */
464 struct mutex mm_lock; /* Lock for fb_mmap and smem_* fields */
465 struct fb_var_screeninfo var; /* Current var */
466 struct fb_fix_screeninfo fix; /* Current fix */
467 struct fb_monspecs monspecs; /* Current Monitor specs */
468 struct fb_pixmap pixmap; /* Image hardware mapper */
469 struct fb_pixmap sprite; /* Cursor hardware mapper */
470 struct fb_cmap cmap; /* Current cmap */
471 struct list_head modelist; /* mode list */
472 struct fb_videomode *mode; /* current mode */
473
474 #if IS_ENABLED(CONFIG_FB_BACKLIGHT)
475 /* assigned backlight device */
476 /* set before framebuffer registration,
477 remove after unregister */
478 struct backlight_device *bl_dev;
479
480 /* Backlight level curve */
481 struct mutex bl_curve_mutex;
482 u8 bl_curve[FB_BACKLIGHT_LEVELS];
483 #endif
484
485 /*
486 * Assigned LCD device; set before framebuffer
487 * registration, remove after unregister
488 */
489 struct lcd_device *lcd_dev;
490
491 #ifdef CONFIG_FB_DEFERRED_IO
492 struct delayed_work deferred_work;
493 unsigned long npagerefs;
494 struct fb_deferred_io_pageref *pagerefs;
495 struct fb_deferred_io *fbdefio;
496 #endif
497
498 const struct fb_ops *fbops;
499 struct device *device; /* This is the parent */
500 #if defined(CONFIG_FB_DEVICE)
501 struct device *dev; /* This is this fb device */
502 #endif
503 int class_flag; /* private sysfs flags */
504 #ifdef CONFIG_FB_TILEBLITTING
505 struct fb_tile_ops *tileops; /* Tile Blitting */
506 #endif
507 union {
508 char __iomem *screen_base; /* Virtual address */
509 char *screen_buffer;
510 };
511 unsigned long screen_size; /* Amount of ioremapped VRAM or 0 */
512 void *pseudo_palette; /* Fake palette of 16 colors */
513 #define FBINFO_STATE_RUNNING 0
514 #define FBINFO_STATE_SUSPENDED 1
515 u32 state; /* Hardware state i.e suspend */
516 void *fbcon_par; /* fbcon use-only private area */
517 /* From here on everything is device dependent */
518 void *par;
519
520 bool skip_vt_switch; /* no VT switch on suspend/resume required */
521 bool skip_panic; /* Do not write to the fb after a panic */
522 };
523
524 /* This will go away
525 * fbset currently hacks in FB_ACCELF_TEXT into var.accel_flags
526 * when it wants to turn the acceleration engine on. This is
527 * really a separate operation, and should be modified via sysfs.
528 * But for now, we leave it broken with the following define
529 */
530 #define STUPID_ACCELF_TEXT_SHIT
531
532 #define FB_LEFT_POS(p, bpp) (fb_be_math(p) ? (32 - (bpp)) : 0)
533 #define FB_SHIFT_HIGH(p, val, bits) (fb_be_math(p) ? (val) >> (bits) : \
534 (val) << (bits))
535 #define FB_SHIFT_LOW(p, val, bits) (fb_be_math(p) ? (val) << (bits) : \
536 (val) >> (bits))
537
538 /*
539 * `Generic' versions of the frame buffer device operations
540 */
541
542 extern int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var);
543 extern int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var);
544 extern int fb_blank(struct fb_info *info, int blank);
545
546 /*
547 * Helpers for framebuffers in I/O memory
548 */
549
550 extern void cfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
551 extern void cfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
552 extern void cfb_imageblit(struct fb_info *info, const struct fb_image *image);
553 extern ssize_t fb_io_read(struct fb_info *info, char __user *buf,
554 size_t count, loff_t *ppos);
555 extern ssize_t fb_io_write(struct fb_info *info, const char __user *buf,
556 size_t count, loff_t *ppos);
557 int fb_io_mmap(struct fb_info *info, struct vm_area_struct *vma);
558
559 #define __FB_DEFAULT_IOMEM_OPS_RDWR \
560 .fb_read = fb_io_read, \
561 .fb_write = fb_io_write
562
563 #define __FB_DEFAULT_IOMEM_OPS_DRAW \
564 .fb_fillrect = cfb_fillrect, \
565 .fb_copyarea = cfb_copyarea, \
566 .fb_imageblit = cfb_imageblit
567
568 #define __FB_DEFAULT_IOMEM_OPS_MMAP \
569 .fb_mmap = fb_io_mmap
570
571 #define FB_DEFAULT_IOMEM_OPS \
572 __FB_DEFAULT_IOMEM_OPS_RDWR, \
573 __FB_DEFAULT_IOMEM_OPS_DRAW, \
574 __FB_DEFAULT_IOMEM_OPS_MMAP
575
576 /*
577 * Helpers for framebuffers in system memory
578 */
579
580 extern void sys_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
581 extern void sys_copyarea(struct fb_info *info, const struct fb_copyarea *area);
582 extern void sys_imageblit(struct fb_info *info, const struct fb_image *image);
583 extern ssize_t fb_sys_read(struct fb_info *info, char __user *buf,
584 size_t count, loff_t *ppos);
585 extern ssize_t fb_sys_write(struct fb_info *info, const char __user *buf,
586 size_t count, loff_t *ppos);
587
588 #define __FB_DEFAULT_SYSMEM_OPS_RDWR \
589 .fb_read = fb_sys_read, \
590 .fb_write = fb_sys_write
591
592 #define __FB_DEFAULT_SYSMEM_OPS_DRAW \
593 .fb_fillrect = sys_fillrect, \
594 .fb_copyarea = sys_copyarea, \
595 .fb_imageblit = sys_imageblit
596
597 /*
598 * Helpers for framebuffers in DMA-able memory
599 */
600
601 #define __FB_DEFAULT_DMAMEM_OPS_RDWR \
602 .fb_read = fb_sys_read, \
603 .fb_write = fb_sys_write
604
605 #define __FB_DEFAULT_DMAMEM_OPS_DRAW \
606 .fb_fillrect = sys_fillrect, \
607 .fb_copyarea = sys_copyarea, \
608 .fb_imageblit = sys_imageblit
609
610 /* fbmem.c */
611 extern int register_framebuffer(struct fb_info *fb_info);
612 extern void unregister_framebuffer(struct fb_info *fb_info);
613 extern int devm_register_framebuffer(struct device *dev, struct fb_info *fb_info);
614 extern char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size);
615 extern void fb_pad_unaligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 idx,
616 u32 height, u32 shift_high, u32 shift_low, u32 mod);
617 extern void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height);
618 extern void fb_set_suspend(struct fb_info *info, int state);
619 extern int fb_get_color_depth(struct fb_var_screeninfo *var,
620 struct fb_fix_screeninfo *fix);
621 extern int fb_get_options(const char *name, char **option);
622 extern int fb_new_modelist(struct fb_info *info);
623
lock_fb_info(struct fb_info * info)624 static inline void lock_fb_info(struct fb_info *info)
625 {
626 mutex_lock(&info->lock);
627 }
628
unlock_fb_info(struct fb_info * info)629 static inline void unlock_fb_info(struct fb_info *info)
630 {
631 mutex_unlock(&info->lock);
632 }
633
__fb_pad_aligned_buffer(u8 * dst,u32 d_pitch,u8 * src,u32 s_pitch,u32 height)634 static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch,
635 u8 *src, u32 s_pitch, u32 height)
636 {
637 u32 i, j;
638
639 d_pitch -= s_pitch;
640
641 for (i = height; i--; ) {
642 /* s_pitch is a few bytes at the most, memcpy is suboptimal */
643 for (j = 0; j < s_pitch; j++)
644 *dst++ = *src++;
645 dst += d_pitch;
646 }
647 }
648
649 /* fb_defio.c */
650 int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma);
651 extern int fb_deferred_io_init(struct fb_info *info);
652 extern void fb_deferred_io_open(struct fb_info *info,
653 struct inode *inode,
654 struct file *file);
655 extern void fb_deferred_io_release(struct fb_info *info);
656 extern void fb_deferred_io_cleanup(struct fb_info *info);
657 extern int fb_deferred_io_fsync(struct file *file, loff_t start,
658 loff_t end, int datasync);
659
660 /*
661 * Generate callbacks for deferred I/O
662 */
663
664 #define __FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, __mode) \
665 static ssize_t __prefix ## _defio_read(struct fb_info *info, char __user *buf, \
666 size_t count, loff_t *ppos) \
667 { \
668 return fb_ ## __mode ## _read(info, buf, count, ppos); \
669 } \
670 static ssize_t __prefix ## _defio_write(struct fb_info *info, const char __user *buf, \
671 size_t count, loff_t *ppos) \
672 { \
673 unsigned long offset = *ppos; \
674 ssize_t ret = fb_ ## __mode ## _write(info, buf, count, ppos); \
675 if (ret > 0) \
676 __damage_range(info, offset, ret); \
677 return ret; \
678 }
679
680 #define __FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, __mode) \
681 static void __prefix ## _defio_fillrect(struct fb_info *info, \
682 const struct fb_fillrect *rect) \
683 { \
684 __mode ## _fillrect(info, rect); \
685 __damage_area(info, rect->dx, rect->dy, rect->width, rect->height); \
686 } \
687 static void __prefix ## _defio_copyarea(struct fb_info *info, \
688 const struct fb_copyarea *area) \
689 { \
690 __mode ## _copyarea(info, area); \
691 __damage_area(info, area->dx, area->dy, area->width, area->height); \
692 } \
693 static void __prefix ## _defio_imageblit(struct fb_info *info, \
694 const struct fb_image *image) \
695 { \
696 __mode ## _imageblit(info, image); \
697 __damage_area(info, image->dx, image->dy, image->width, image->height); \
698 }
699
700 #define FB_GEN_DEFAULT_DEFERRED_IOMEM_OPS(__prefix, __damage_range, __damage_area) \
701 __FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, io) \
702 __FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, cfb)
703
704 #define FB_GEN_DEFAULT_DEFERRED_SYSMEM_OPS(__prefix, __damage_range, __damage_area) \
705 __FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, sys) \
706 __FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, sys)
707
708 #define FB_GEN_DEFAULT_DEFERRED_DMAMEM_OPS(__prefix, __damage_range, __damage_area) \
709 __FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, sys) \
710 __FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, sys)
711
712 /*
713 * Initializes struct fb_ops for deferred I/O.
714 */
715
716 #define __FB_DEFAULT_DEFERRED_OPS_RDWR(__prefix) \
717 .fb_read = __prefix ## _defio_read, \
718 .fb_write = __prefix ## _defio_write
719
720 #define __FB_DEFAULT_DEFERRED_OPS_DRAW(__prefix) \
721 .fb_fillrect = __prefix ## _defio_fillrect, \
722 .fb_copyarea = __prefix ## _defio_copyarea, \
723 .fb_imageblit = __prefix ## _defio_imageblit
724
725 #define __FB_DEFAULT_DEFERRED_OPS_MMAP(__prefix) \
726 .fb_mmap = fb_deferred_io_mmap
727
728 #define FB_DEFAULT_DEFERRED_OPS(__prefix) \
729 __FB_DEFAULT_DEFERRED_OPS_RDWR(__prefix), \
730 __FB_DEFAULT_DEFERRED_OPS_DRAW(__prefix), \
731 __FB_DEFAULT_DEFERRED_OPS_MMAP(__prefix)
732
fb_be_math(struct fb_info * info)733 static inline bool fb_be_math(struct fb_info *info)
734 {
735 #ifdef CONFIG_FB_FOREIGN_ENDIAN
736 #if defined(CONFIG_FB_BOTH_ENDIAN)
737 return info->flags & FBINFO_BE_MATH;
738 #elif defined(CONFIG_FB_BIG_ENDIAN)
739 return true;
740 #elif defined(CONFIG_FB_LITTLE_ENDIAN)
741 return false;
742 #endif /* CONFIG_FB_BOTH_ENDIAN */
743 #else
744 #ifdef __BIG_ENDIAN
745 return true;
746 #else
747 return false;
748 #endif /* __BIG_ENDIAN */
749 #endif /* CONFIG_FB_FOREIGN_ENDIAN */
750 }
751
752 extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev);
753 extern void framebuffer_release(struct fb_info *info);
754 extern void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max);
755
756 #if IS_ENABLED(CONFIG_FB_BACKLIGHT)
757 struct backlight_device *fb_bl_device(struct fb_info *info);
758 #else
fb_bl_device(struct fb_info * info)759 static inline struct backlight_device *fb_bl_device(struct fb_info *info)
760 {
761 return NULL;
762 }
763 #endif
764
fb_lcd_device(struct fb_info * info)765 static inline struct lcd_device *fb_lcd_device(struct fb_info *info)
766 {
767 return info->lcd_dev;
768 }
769
770 /* fbmon.c */
771 #define FB_MAXTIMINGS 0
772 #define FB_VSYNCTIMINGS 1
773 #define FB_HSYNCTIMINGS 2
774 #define FB_DCLKTIMINGS 3
775 #define FB_IGNOREMON 0x100
776
777 #define FB_MODE_IS_UNKNOWN 0
778 #define FB_MODE_IS_DETAILED 1
779 #define FB_MODE_IS_STANDARD 2
780 #define FB_MODE_IS_VESA 4
781 #define FB_MODE_IS_CALCULATED 8
782 #define FB_MODE_IS_FIRST 16
783 #define FB_MODE_IS_FROM_VAR 32
784
785 extern int fbmon_dpms(const struct fb_info *fb_info);
786 extern int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var,
787 struct fb_info *info);
788 extern int fb_validate_mode(const struct fb_var_screeninfo *var,
789 struct fb_info *info);
790 extern int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var);
791 extern const unsigned char *fb_firmware_edid(struct device *device);
792 extern void fb_edid_to_monspecs(unsigned char *edid,
793 struct fb_monspecs *specs);
794 extern void fb_destroy_modedb(struct fb_videomode *modedb);
795 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
796 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
797
798 extern int of_get_fb_videomode(struct device_node *np,
799 struct fb_videomode *fb,
800 int index);
801 extern int fb_videomode_from_videomode(const struct videomode *vm,
802 struct fb_videomode *fbmode);
803
804 /* modedb.c */
805 #define VESA_MODEDB_SIZE 43
806 #define DMT_SIZE 0x50
807
808 extern void fb_var_to_videomode(struct fb_videomode *mode,
809 const struct fb_var_screeninfo *var);
810 extern void fb_videomode_to_var(struct fb_var_screeninfo *var,
811 const struct fb_videomode *mode);
812 extern int fb_mode_is_equal(const struct fb_videomode *mode1,
813 const struct fb_videomode *mode2);
814 extern int fb_add_videomode(const struct fb_videomode *mode,
815 struct list_head *head);
816 extern void fb_delete_videomode(const struct fb_videomode *mode,
817 struct list_head *head);
818 extern const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var,
819 struct list_head *head);
820 extern const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var,
821 struct list_head *head);
822 extern const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
823 struct list_head *head);
824 extern void fb_destroy_modelist(struct list_head *head);
825 extern void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num,
826 struct list_head *head);
827 extern const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs,
828 struct list_head *head);
829
830 /* fbcmap.c */
831 extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp);
832 extern int fb_alloc_cmap_gfp(struct fb_cmap *cmap, int len, int transp, gfp_t flags);
833 extern void fb_dealloc_cmap(struct fb_cmap *cmap);
834 extern int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to);
835 extern int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to);
836 extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info);
837 extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info);
838 extern const struct fb_cmap *fb_default_cmap(int len);
839 extern void fb_invert_cmaps(void);
840
841 struct fb_videomode {
842 const char *name; /* optional */
843 u32 refresh; /* optional */
844 u32 xres;
845 u32 yres;
846 u32 pixclock;
847 u32 left_margin;
848 u32 right_margin;
849 u32 upper_margin;
850 u32 lower_margin;
851 u32 hsync_len;
852 u32 vsync_len;
853 u32 sync;
854 u32 vmode;
855 u32 flag;
856 };
857
858 struct dmt_videomode {
859 u32 dmt_id;
860 u32 std_2byte_code;
861 u32 cvt_3byte_code;
862 const struct fb_videomode *mode;
863 };
864
865 extern const struct fb_videomode vesa_modes[];
866 extern const struct dmt_videomode dmt_modes[];
867
868 struct fb_modelist {
869 struct list_head list;
870 struct fb_videomode mode;
871 };
872
873 extern int fb_find_mode(struct fb_var_screeninfo *var,
874 struct fb_info *info, const char *mode_option,
875 const struct fb_videomode *db,
876 unsigned int dbsize,
877 const struct fb_videomode *default_mode,
878 unsigned int default_bpp);
879
880 bool fb_modesetting_disabled(const char *drvname);
881
882 /*
883 * Convenience logging macros
884 */
885
886 #define fb_err(fb_info, fmt, ...) \
887 pr_err("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__)
888 #define fb_notice(info, fmt, ...) \
889 pr_notice("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__)
890 #define fb_warn(fb_info, fmt, ...) \
891 pr_warn("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__)
892 #define fb_info(fb_info, fmt, ...) \
893 pr_info("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__)
894 #define fb_dbg(fb_info, fmt, ...) \
895 pr_debug("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__)
896
897 #define fb_warn_once(fb_info, fmt, ...) \
898 pr_warn_once("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__)
899
900 #define fb_WARN_ONCE(fb_info, condition, fmt, ...) \
901 WARN_ONCE(condition, "fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__)
902 #define fb_WARN_ON_ONCE(fb_info, x) \
903 fb_WARN_ONCE(fb_info, (x), "%s", "fb_WARN_ON_ONCE(" __stringify(x) ")")
904
905 #endif /* _LINUX_FB_H */
906