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