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 fbcon_par; 22 struct file; 23 struct i2c_adapter; 24 struct inode; 25 struct lcd_device; 26 struct module; 27 struct notifier_block; 28 struct page; 29 struct videomode; 30 struct vm_area_struct; 31 32 /* Definitions below are used in the parsed monitor specs */ 33 #define FB_DPMS_ACTIVE_OFF 1 34 #define FB_DPMS_SUSPEND 2 35 #define FB_DPMS_STANDBY 4 36 37 #define FB_DISP_DDI 1 38 #define FB_DISP_ANA_700_300 2 39 #define FB_DISP_ANA_714_286 4 40 #define FB_DISP_ANA_1000_400 8 41 #define FB_DISP_ANA_700_000 16 42 43 #define FB_DISP_MONO 32 44 #define FB_DISP_RGB 64 45 #define FB_DISP_MULTI 128 46 #define FB_DISP_UNKNOWN 256 47 48 #define FB_SIGNAL_NONE 0 49 #define FB_SIGNAL_BLANK_BLANK 1 50 #define FB_SIGNAL_SEPARATE 2 51 #define FB_SIGNAL_COMPOSITE 4 52 #define FB_SIGNAL_SYNC_ON_GREEN 8 53 #define FB_SIGNAL_SERRATION_ON 16 54 55 #define FB_MISC_PRIM_COLOR 1 56 #define FB_MISC_1ST_DETAIL 2 /* First Detailed Timing is preferred */ 57 #define FB_MISC_HDMI 4 58 struct fb_chroma { 59 __u32 redx; /* in fraction of 1024 */ 60 __u32 greenx; 61 __u32 bluex; 62 __u32 whitex; 63 __u32 redy; 64 __u32 greeny; 65 __u32 bluey; 66 __u32 whitey; 67 }; 68 69 struct fb_monspecs { 70 struct fb_chroma chroma; 71 struct fb_videomode *modedb; /* mode database */ 72 __u8 manufacturer[4]; /* Manufacturer */ 73 __u8 monitor[14]; /* Monitor String */ 74 __u8 serial_no[14]; /* Serial Number */ 75 __u8 ascii[14]; /* ? */ 76 __u32 modedb_len; /* mode database length */ 77 __u32 model; /* Monitor Model */ 78 __u32 serial; /* Serial Number - Integer */ 79 __u32 year; /* Year manufactured */ 80 __u32 week; /* Week Manufactured */ 81 __u32 hfmin; /* hfreq lower limit (Hz) */ 82 __u32 hfmax; /* hfreq upper limit (Hz) */ 83 __u32 dclkmin; /* pixelclock lower limit (Hz) */ 84 __u32 dclkmax; /* pixelclock upper limit (Hz) */ 85 __u16 input; /* display type - see FB_DISP_* */ 86 __u16 dpms; /* DPMS support - see FB_DPMS_ */ 87 __u16 signal; /* Signal Type - see FB_SIGNAL_* */ 88 __u16 vfmin; /* vfreq lower limit (Hz) */ 89 __u16 vfmax; /* vfreq upper limit (Hz) */ 90 __u16 gamma; /* Gamma - in fractions of 100 */ 91 __u16 gtf : 1; /* supports GTF */ 92 __u16 misc; /* Misc flags - see FB_MISC_* */ 93 __u8 version; /* EDID version... */ 94 __u8 revision; /* ...and revision */ 95 __u8 max_x; /* Maximum horizontal size (cm) */ 96 __u8 max_y; /* Maximum vertical size (cm) */ 97 }; 98 99 struct fb_cmap_user { 100 __u32 start; /* First entry */ 101 __u32 len; /* Number of entries */ 102 __u16 __user *red; /* Red values */ 103 __u16 __user *green; 104 __u16 __user *blue; 105 __u16 __user *transp; /* transparency, can be NULL */ 106 }; 107 108 struct fb_image_user { 109 __u32 dx; /* Where to place image */ 110 __u32 dy; 111 __u32 width; /* Size of image */ 112 __u32 height; 113 __u32 fg_color; /* Only used when a mono bitmap */ 114 __u32 bg_color; 115 __u8 depth; /* Depth of the image */ 116 const char __user *data; /* Pointer to image data */ 117 struct fb_cmap_user cmap; /* color map info */ 118 }; 119 120 struct fb_cursor_user { 121 __u16 set; /* what to set */ 122 __u16 enable; /* cursor on/off */ 123 __u16 rop; /* bitop operation */ 124 const char __user *mask; /* cursor mask bits */ 125 struct fbcurpos hot; /* cursor hot spot */ 126 struct fb_image_user image; /* Cursor image */ 127 }; 128 129 /* 130 * Register/unregister for framebuffer events 131 */ 132 133 #ifdef CONFIG_GUMSTIX_AM200EPD 134 /* only used by mach-pxa/am200epd.c */ 135 #define FB_EVENT_FB_REGISTERED 0x05 136 #define FB_EVENT_FB_UNREGISTERED 0x06 137 #endif 138 139 struct fb_event { 140 struct fb_info *info; 141 void *data; 142 }; 143 144 /* Enough for the VT console needs, see its max_font_width/height */ 145 #define FB_MAX_BLIT_WIDTH 64 146 #define FB_MAX_BLIT_HEIGHT 128 147 148 struct fb_blit_caps { 149 DECLARE_BITMAP(x, FB_MAX_BLIT_WIDTH); 150 DECLARE_BITMAP(y, FB_MAX_BLIT_HEIGHT); 151 u32 len; 152 u32 flags; 153 }; 154 155 #ifdef CONFIG_FB_NOTIFY 156 extern int fb_register_client(struct notifier_block *nb); 157 extern int fb_unregister_client(struct notifier_block *nb); 158 extern int fb_notifier_call_chain(unsigned long val, void *v); 159 #else 160 static inline int fb_register_client(struct notifier_block *nb) 161 { 162 return 0; 163 }; 164 165 static inline int fb_unregister_client(struct notifier_block *nb) 166 { 167 return 0; 168 }; 169 170 static inline int fb_notifier_call_chain(unsigned long val, void *v) 171 { 172 return 0; 173 }; 174 #endif 175 176 /* 177 * Pixmap structure definition 178 * 179 * The purpose of this structure is to translate data 180 * from the hardware independent format of fbdev to what 181 * format the hardware needs. 182 */ 183 184 #define FB_PIXMAP_DEFAULT 1 /* used internally by fbcon */ 185 #define FB_PIXMAP_SYSTEM 2 /* memory is in system RAM */ 186 #define FB_PIXMAP_IO 4 /* memory is iomapped */ 187 #define FB_PIXMAP_SYNC 256 /* set if GPU can DMA */ 188 189 struct fb_pixmap { 190 u8 *addr; /* pointer to memory */ 191 u32 size; /* size of buffer in bytes */ 192 u32 offset; /* current offset to buffer */ 193 u32 buf_align; /* byte alignment of each bitmap */ 194 u32 scan_align; /* alignment per scanline */ 195 u32 access_align; /* alignment per read/write (bits) */ 196 u32 flags; /* see FB_PIXMAP_* */ 197 /* supported bit block dimensions */ 198 /* Format: test_bit(width - 1, blit_x) */ 199 /* test_bit(height - 1, blit_y) */ 200 /* if zero, will be set to full (all) */ 201 DECLARE_BITMAP(blit_x, FB_MAX_BLIT_WIDTH); 202 DECLARE_BITMAP(blit_y, FB_MAX_BLIT_HEIGHT); 203 /* access methods */ 204 void (*writeio)(struct fb_info *info, void __iomem *dst, void *src, unsigned int size); 205 void (*readio) (struct fb_info *info, void *dst, void __iomem *src, unsigned int size); 206 }; 207 208 #ifdef CONFIG_FB_DEFERRED_IO 209 struct fb_deferred_io_pageref { 210 struct page *page; 211 unsigned long offset; 212 /* private */ 213 struct list_head list; 214 }; 215 216 struct fb_deferred_io { 217 /* delay between mkwrite and deferred handler */ 218 unsigned long delay; 219 bool sort_pagereflist; /* sort pagelist by offset */ 220 /* callback */ 221 struct page *(*get_page)(struct fb_info *info, unsigned long offset); 222 void (*deferred_io)(struct fb_info *info, struct list_head *pagelist); 223 }; 224 225 struct fb_deferred_io_state; 226 #endif 227 228 /* 229 * Frame buffer operations 230 * 231 * LOCKING NOTE: those functions must _ALL_ be called with the console 232 * semaphore held, this is the only suitable locking mechanism we have 233 * in 2.6. Some may be called at interrupt time at this point though. 234 * 235 * The exception to this is the debug related hooks. Putting the fb 236 * into a debug state (e.g. flipping to the kernel console) and restoring 237 * it must be done in a lock-free manner, so low level drivers should 238 * keep track of the initial console (if applicable) and may need to 239 * perform direct, unlocked hardware writes in these hooks. 240 */ 241 242 struct fb_ops { 243 /* open/release and usage marking */ 244 struct module *owner; 245 int (*fb_open)(struct fb_info *info, int user); 246 int (*fb_release)(struct fb_info *info, int user); 247 248 /* For framebuffers with strange non linear layouts or that do not 249 * work with normal memory mapped access 250 */ 251 ssize_t (*fb_read)(struct fb_info *info, char __user *buf, 252 size_t count, loff_t *ppos); 253 ssize_t (*fb_write)(struct fb_info *info, const char __user *buf, 254 size_t count, loff_t *ppos); 255 256 /* checks var and eventually tweaks it to something supported, 257 * DO NOT MODIFY PAR */ 258 int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info); 259 260 /* set the video mode according to info->var */ 261 int (*fb_set_par)(struct fb_info *info); 262 263 /* set color register */ 264 int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green, 265 unsigned blue, unsigned transp, struct fb_info *info); 266 267 /* set color registers in batch */ 268 int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info); 269 270 /* blank display */ 271 int (*fb_blank)(int blank, struct fb_info *info); 272 273 /* pan display */ 274 int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info); 275 276 /* Draws a rectangle */ 277 void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect); 278 /* Copy data from area to another */ 279 void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region); 280 /* Draws a image to the display */ 281 void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image); 282 283 /* Draws cursor */ 284 int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor); 285 286 /* wait for blit idle, optional */ 287 int (*fb_sync)(struct fb_info *info); 288 289 /* perform fb specific ioctl (optional) */ 290 int (*fb_ioctl)(struct fb_info *info, unsigned int cmd, 291 unsigned long arg); 292 293 /* Handle 32bit compat ioctl (optional) */ 294 int (*fb_compat_ioctl)(struct fb_info *info, unsigned cmd, 295 unsigned long arg); 296 297 /* perform fb specific mmap */ 298 int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma); 299 300 /* get capability given var */ 301 void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps, 302 struct fb_var_screeninfo *var); 303 304 /* teardown any resources to do with this framebuffer */ 305 void (*fb_destroy)(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 int blank; /* current blanking; see FB_BLANK_ constants */ 465 466 #if IS_ENABLED(CONFIG_FB_BACKLIGHT) 467 /* assigned backlight device */ 468 /* set before framebuffer registration, 469 remove after unregister */ 470 struct backlight_device *bl_dev; 471 472 /* Backlight level curve */ 473 struct mutex bl_curve_mutex; 474 u8 bl_curve[FB_BACKLIGHT_LEVELS]; 475 #endif 476 477 /* 478 * Assigned LCD device; set before framebuffer 479 * registration, remove after unregister 480 */ 481 struct lcd_device *lcd_dev; 482 483 #ifdef CONFIG_FB_DEFERRED_IO 484 struct delayed_work deferred_work; 485 struct fb_deferred_io *fbdefio; 486 struct fb_deferred_io_state *fbdefio_state; 487 #endif 488 489 const struct fb_ops *fbops; 490 struct device *device; /* This is the parent */ 491 #if defined(CONFIG_FB_DEVICE) 492 struct device *dev; /* This is this fb device */ 493 #endif 494 #ifdef CONFIG_FB_TILEBLITTING 495 struct fb_tile_ops *tileops; /* Tile Blitting */ 496 #endif 497 union { 498 char __iomem *screen_base; /* Virtual address */ 499 char *screen_buffer; 500 }; 501 unsigned long screen_size; /* Amount of ioremapped VRAM or 0 */ 502 void *pseudo_palette; /* Fake palette of 16 colors */ 503 #define FBINFO_STATE_RUNNING 0 504 #define FBINFO_STATE_SUSPENDED 1 505 u32 state; /* Hardware state i.e suspend */ 506 struct fbcon_par *fbcon_par; /* fbcon use-only private area */ 507 /* From here on everything is device dependent */ 508 void *par; 509 510 bool skip_vt_switch; /* no VT switch on suspend/resume required */ 511 bool skip_panic; /* Do not write to the fb after a panic */ 512 }; 513 514 /* This will go away 515 * fbset currently hacks in FB_ACCELF_TEXT into var.accel_flags 516 * when it wants to turn the acceleration engine on. This is 517 * really a separate operation, and should be modified via sysfs. 518 * But for now, we leave it broken with the following define 519 */ 520 #define STUPID_ACCELF_TEXT_SHIT 521 522 #define FB_LEFT_POS(p, bpp) (fb_be_math(p) ? (32 - (bpp)) : 0) 523 #define FB_SHIFT_HIGH(p, val, bits) (fb_be_math(p) ? (val) >> (bits) : \ 524 (val) << (bits)) 525 #define FB_SHIFT_LOW(p, val, bits) (fb_be_math(p) ? (val) << (bits) : \ 526 (val) >> (bits)) 527 528 /* 529 * `Generic' versions of the frame buffer device operations 530 */ 531 532 extern int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var); 533 extern int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var); 534 extern int fb_blank(struct fb_info *info, int blank); 535 536 /* 537 * Helpers for framebuffers in I/O memory 538 */ 539 540 extern void cfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect); 541 extern void cfb_copyarea(struct fb_info *info, const struct fb_copyarea *area); 542 extern void cfb_imageblit(struct fb_info *info, const struct fb_image *image); 543 extern ssize_t fb_io_read(struct fb_info *info, char __user *buf, 544 size_t count, loff_t *ppos); 545 extern ssize_t fb_io_write(struct fb_info *info, const char __user *buf, 546 size_t count, loff_t *ppos); 547 int fb_io_mmap(struct fb_info *info, struct vm_area_struct *vma); 548 549 #define __FB_DEFAULT_IOMEM_OPS_RDWR \ 550 .fb_read = fb_io_read, \ 551 .fb_write = fb_io_write 552 553 #define __FB_DEFAULT_IOMEM_OPS_DRAW \ 554 .fb_fillrect = cfb_fillrect, \ 555 .fb_copyarea = cfb_copyarea, \ 556 .fb_imageblit = cfb_imageblit 557 558 #define __FB_DEFAULT_IOMEM_OPS_MMAP \ 559 .fb_mmap = fb_io_mmap 560 561 #define FB_DEFAULT_IOMEM_OPS \ 562 __FB_DEFAULT_IOMEM_OPS_RDWR, \ 563 __FB_DEFAULT_IOMEM_OPS_DRAW, \ 564 __FB_DEFAULT_IOMEM_OPS_MMAP 565 566 /* 567 * Helpers for framebuffers in system memory 568 */ 569 570 extern void sys_fillrect(struct fb_info *info, const struct fb_fillrect *rect); 571 extern void sys_copyarea(struct fb_info *info, const struct fb_copyarea *area); 572 extern void sys_imageblit(struct fb_info *info, const struct fb_image *image); 573 extern ssize_t fb_sys_read(struct fb_info *info, char __user *buf, 574 size_t count, loff_t *ppos); 575 extern ssize_t fb_sys_write(struct fb_info *info, const char __user *buf, 576 size_t count, loff_t *ppos); 577 578 #define __FB_DEFAULT_SYSMEM_OPS_RDWR \ 579 .fb_read = fb_sys_read, \ 580 .fb_write = fb_sys_write 581 582 #define __FB_DEFAULT_SYSMEM_OPS_DRAW \ 583 .fb_fillrect = sys_fillrect, \ 584 .fb_copyarea = sys_copyarea, \ 585 .fb_imageblit = sys_imageblit 586 587 /* 588 * Helpers for framebuffers in DMA-able memory 589 */ 590 591 #define __FB_DEFAULT_DMAMEM_OPS_RDWR \ 592 .fb_read = fb_sys_read, \ 593 .fb_write = fb_sys_write 594 595 #define __FB_DEFAULT_DMAMEM_OPS_DRAW \ 596 .fb_fillrect = sys_fillrect, \ 597 .fb_copyarea = sys_copyarea, \ 598 .fb_imageblit = sys_imageblit 599 600 /* fbmem.c */ 601 extern int register_framebuffer(struct fb_info *fb_info); 602 extern void unregister_framebuffer(struct fb_info *fb_info); 603 extern int devm_register_framebuffer(struct device *dev, struct fb_info *fb_info); 604 extern char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size); 605 void fb_pad_unaligned_buffer(u8 *dst, u32 d_pitch, const u8 *src, u32 idx, u32 height, 606 u32 shift_high, u32 shift_low, u32 mod); 607 void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, const u8 *src, u32 s_pitch, u32 height); 608 extern void fb_set_suspend(struct fb_info *info, int state); 609 extern int fb_get_color_depth(struct fb_var_screeninfo *var, 610 struct fb_fix_screeninfo *fix); 611 extern int fb_get_options(const char *name, char **option); 612 extern int fb_new_modelist(struct fb_info *info); 613 614 static inline void lock_fb_info(struct fb_info *info) 615 { 616 mutex_lock(&info->lock); 617 } 618 619 static inline void unlock_fb_info(struct fb_info *info) 620 { 621 mutex_unlock(&info->lock); 622 } 623 624 static inline struct device *dev_of_fbinfo(const struct fb_info *info) 625 { 626 #ifdef CONFIG_FB_DEVICE 627 return info->dev; 628 #else 629 return NULL; 630 #endif 631 } 632 633 static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, const u8 *src, u32 s_pitch, 634 u32 height) 635 { 636 u32 i, j; 637 638 d_pitch -= s_pitch; 639 640 for (i = height; i--; ) { 641 /* s_pitch is a few bytes at the most, memcpy is suboptimal */ 642 for (j = 0; j < s_pitch; j++) 643 *dst++ = *src++; 644 dst += d_pitch; 645 } 646 } 647 648 /* fb_defio.c */ 649 int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma); 650 extern int fb_deferred_io_init(struct fb_info *info); 651 extern void fb_deferred_io_open(struct fb_info *info, 652 struct inode *inode, 653 struct file *file); 654 extern void fb_deferred_io_release(struct fb_info *info); 655 extern void fb_deferred_io_cleanup(struct fb_info *info); 656 extern int fb_deferred_io_fsync(struct file *file, loff_t start, 657 loff_t end, int datasync); 658 659 /* 660 * Generate callbacks for deferred I/O 661 */ 662 663 #define __FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, __mode) \ 664 static ssize_t __prefix ## _defio_read(struct fb_info *info, char __user *buf, \ 665 size_t count, loff_t *ppos) \ 666 { \ 667 return fb_ ## __mode ## _read(info, buf, count, ppos); \ 668 } \ 669 static ssize_t __prefix ## _defio_write(struct fb_info *info, const char __user *buf, \ 670 size_t count, loff_t *ppos) \ 671 { \ 672 unsigned long offset = *ppos; \ 673 ssize_t ret = fb_ ## __mode ## _write(info, buf, count, ppos); \ 674 if (ret > 0) \ 675 __damage_range(info, offset, ret); \ 676 return ret; \ 677 } 678 679 #define __FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, __mode) \ 680 static void __prefix ## _defio_fillrect(struct fb_info *info, \ 681 const struct fb_fillrect *rect) \ 682 { \ 683 __mode ## _fillrect(info, rect); \ 684 __damage_area(info, rect->dx, rect->dy, rect->width, rect->height); \ 685 } \ 686 static void __prefix ## _defio_copyarea(struct fb_info *info, \ 687 const struct fb_copyarea *area) \ 688 { \ 689 __mode ## _copyarea(info, area); \ 690 __damage_area(info, area->dx, area->dy, area->width, area->height); \ 691 } \ 692 static void __prefix ## _defio_imageblit(struct fb_info *info, \ 693 const struct fb_image *image) \ 694 { \ 695 __mode ## _imageblit(info, image); \ 696 __damage_area(info, image->dx, image->dy, image->width, image->height); \ 697 } 698 699 #define FB_GEN_DEFAULT_DEFERRED_IOMEM_OPS(__prefix, __damage_range, __damage_area) \ 700 __FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, io) \ 701 __FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, cfb) 702 703 #define FB_GEN_DEFAULT_DEFERRED_SYSMEM_OPS(__prefix, __damage_range, __damage_area) \ 704 __FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, sys) \ 705 __FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, sys) 706 707 #define FB_GEN_DEFAULT_DEFERRED_DMAMEM_OPS(__prefix, __damage_range, __damage_area) \ 708 __FB_GEN_DEFAULT_DEFERRED_OPS_RDWR(__prefix, __damage_range, sys) \ 709 __FB_GEN_DEFAULT_DEFERRED_OPS_DRAW(__prefix, __damage_area, sys) 710 711 /* 712 * Initializes struct fb_ops for deferred I/O. 713 */ 714 715 #define __FB_DEFAULT_DEFERRED_OPS_RDWR(__prefix) \ 716 .fb_read = __prefix ## _defio_read, \ 717 .fb_write = __prefix ## _defio_write 718 719 #define __FB_DEFAULT_DEFERRED_OPS_DRAW(__prefix) \ 720 .fb_fillrect = __prefix ## _defio_fillrect, \ 721 .fb_copyarea = __prefix ## _defio_copyarea, \ 722 .fb_imageblit = __prefix ## _defio_imageblit 723 724 #define __FB_DEFAULT_DEFERRED_OPS_MMAP(__prefix) \ 725 .fb_mmap = fb_deferred_io_mmap 726 727 #define FB_DEFAULT_DEFERRED_OPS(__prefix) \ 728 __FB_DEFAULT_DEFERRED_OPS_RDWR(__prefix), \ 729 __FB_DEFAULT_DEFERRED_OPS_DRAW(__prefix), \ 730 __FB_DEFAULT_DEFERRED_OPS_MMAP(__prefix) 731 732 static inline bool fb_be_math(struct fb_info *info) 733 { 734 #ifdef CONFIG_FB_FOREIGN_ENDIAN 735 #if defined(CONFIG_FB_BOTH_ENDIAN) 736 return info->flags & FBINFO_BE_MATH; 737 #elif defined(CONFIG_FB_BIG_ENDIAN) 738 return true; 739 #elif defined(CONFIG_FB_LITTLE_ENDIAN) 740 return false; 741 #endif /* CONFIG_FB_BOTH_ENDIAN */ 742 #else 743 #ifdef __BIG_ENDIAN 744 return true; 745 #else 746 return false; 747 #endif /* __BIG_ENDIAN */ 748 #endif /* CONFIG_FB_FOREIGN_ENDIAN */ 749 } 750 751 extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev); 752 extern void framebuffer_release(struct fb_info *info); 753 extern void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max); 754 755 #if IS_ENABLED(CONFIG_FB_BACKLIGHT) 756 struct backlight_device *fb_bl_device(struct fb_info *info); 757 void fb_bl_notify_blank(struct fb_info *info, int old_blank); 758 #else 759 static inline struct backlight_device *fb_bl_device(struct fb_info *info) 760 { 761 return NULL; 762 } 763 764 static inline void fb_bl_notify_blank(struct fb_info *info, int old_blank) 765 { } 766 #endif 767 768 static inline struct lcd_device *fb_lcd_device(struct fb_info *info) 769 { 770 return info->lcd_dev; 771 } 772 773 /* fbmon.c */ 774 #define FB_MAXTIMINGS 0 775 #define FB_VSYNCTIMINGS 1 776 #define FB_HSYNCTIMINGS 2 777 #define FB_DCLKTIMINGS 3 778 #define FB_IGNOREMON 0x100 779 780 #define FB_MODE_IS_UNKNOWN 0 781 #define FB_MODE_IS_DETAILED 1 782 #define FB_MODE_IS_STANDARD 2 783 #define FB_MODE_IS_VESA 4 784 #define FB_MODE_IS_CALCULATED 8 785 #define FB_MODE_IS_FIRST 16 786 #define FB_MODE_IS_FROM_VAR 32 787 788 extern int fbmon_dpms(const struct fb_info *fb_info); 789 extern int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, 790 struct fb_info *info); 791 extern int fb_validate_mode(const struct fb_var_screeninfo *var, 792 struct fb_info *info); 793 extern int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var); 794 extern const unsigned char *fb_firmware_edid(struct device *device); 795 extern void fb_edid_to_monspecs(unsigned char *edid, 796 struct fb_monspecs *specs); 797 extern void fb_destroy_modedb(struct fb_videomode *modedb); 798 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb); 799 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter); 800 801 extern int of_get_fb_videomode(struct device_node *np, 802 struct fb_videomode *fb, 803 int index); 804 extern int fb_videomode_from_videomode(const struct videomode *vm, 805 struct fb_videomode *fbmode); 806 807 /* modedb.c */ 808 #define VESA_MODEDB_SIZE 43 809 #define DMT_SIZE 0x50 810 811 extern void fb_var_to_videomode(struct fb_videomode *mode, 812 const struct fb_var_screeninfo *var); 813 extern void fb_videomode_to_var(struct fb_var_screeninfo *var, 814 const struct fb_videomode *mode); 815 extern int fb_mode_is_equal(const struct fb_videomode *mode1, 816 const struct fb_videomode *mode2); 817 extern int fb_add_videomode(const struct fb_videomode *mode, 818 struct list_head *head); 819 extern void fb_delete_videomode(const struct fb_videomode *mode, 820 struct list_head *head); 821 extern const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var, 822 struct list_head *head); 823 extern const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var, 824 struct list_head *head); 825 extern const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode, 826 struct list_head *head); 827 extern void fb_destroy_modelist(struct list_head *head); 828 extern void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num, 829 struct list_head *head); 830 extern const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs, 831 struct list_head *head); 832 833 /* fbcmap.c */ 834 extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp); 835 extern int fb_alloc_cmap_gfp(struct fb_cmap *cmap, int len, int transp, gfp_t flags); 836 extern void fb_dealloc_cmap(struct fb_cmap *cmap); 837 extern int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to); 838 extern int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to); 839 extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info); 840 extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info); 841 extern const struct fb_cmap *fb_default_cmap(int len); 842 extern void fb_invert_cmaps(void); 843 844 struct fb_videomode { 845 const char *name; /* optional */ 846 u32 refresh; /* optional */ 847 u32 xres; 848 u32 yres; 849 u32 pixclock; 850 u32 left_margin; 851 u32 right_margin; 852 u32 upper_margin; 853 u32 lower_margin; 854 u32 hsync_len; 855 u32 vsync_len; 856 u32 sync; 857 u32 vmode; 858 u32 flag; 859 }; 860 861 struct dmt_videomode { 862 u32 dmt_id; 863 u32 std_2byte_code; 864 u32 cvt_3byte_code; 865 const struct fb_videomode *mode; 866 }; 867 868 extern const struct fb_videomode vesa_modes[]; 869 extern const struct dmt_videomode dmt_modes[]; 870 871 struct fb_modelist { 872 struct list_head list; 873 struct fb_videomode mode; 874 }; 875 876 extern int fb_find_mode(struct fb_var_screeninfo *var, 877 struct fb_info *info, const char *mode_option, 878 const struct fb_videomode *db, 879 unsigned int dbsize, 880 const struct fb_videomode *default_mode, 881 unsigned int default_bpp); 882 883 bool fb_modesetting_disabled(const char *drvname); 884 885 /* 886 * Convenience logging macros 887 */ 888 889 #define fb_err(fb_info, fmt, ...) \ 890 pr_err("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__) 891 #define fb_notice(info, fmt, ...) \ 892 pr_notice("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__) 893 #define fb_warn(fb_info, fmt, ...) \ 894 pr_warn("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__) 895 #define fb_info(fb_info, fmt, ...) \ 896 pr_info("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__) 897 #define fb_dbg(fb_info, fmt, ...) \ 898 pr_debug("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__) 899 900 #define fb_warn_once(fb_info, fmt, ...) \ 901 pr_warn_once("fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__) 902 903 #define fb_WARN_ONCE(fb_info, condition, fmt, ...) \ 904 WARN_ONCE(condition, "fb%d: " fmt, (fb_info)->node, ##__VA_ARGS__) 905 #define fb_WARN_ON_ONCE(fb_info, x) \ 906 fb_WARN_ONCE(fb_info, (x), "%s", "fb_WARN_ON_ONCE(" __stringify(x) ")") 907 908 #endif /* _LINUX_FB_H */ 909