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