1 #ifndef _LINUX_FB_H
2 #define _LINUX_FB_H
3 
4 #include <linux/types.h>
5 #include <linux/i2c.h>
6 #ifdef __KERNEL__
7 #include <linux/kgdb.h>
8 #endif /* __KERNEL__ */
9 
10 /* Definitions of frame buffers						*/
11 
12 #define FB_MAX			32	/* sufficient for now */
13 
14 /* ioctls
15    0x46 is 'F'								*/
16 #define FBIOGET_VSCREENINFO	0x4600
17 #define FBIOPUT_VSCREENINFO	0x4601
18 #define FBIOGET_FSCREENINFO	0x4602
19 #define FBIOGETCMAP		0x4604
20 #define FBIOPUTCMAP		0x4605
21 #define FBIOPAN_DISPLAY		0x4606
22 #ifdef __KERNEL__
23 #define FBIO_CURSOR            _IOWR('F', 0x08, struct fb_cursor_user)
24 #else
25 #define FBIO_CURSOR            _IOWR('F', 0x08, struct fb_cursor)
26 #endif
27 /* 0x4607-0x460B are defined below */
28 /* #define FBIOGET_MONITORSPEC	0x460C */
29 /* #define FBIOPUT_MONITORSPEC	0x460D */
30 /* #define FBIOSWITCH_MONIBIT	0x460E */
31 #define FBIOGET_CON2FBMAP	0x460F
32 #define FBIOPUT_CON2FBMAP	0x4610
33 #define FBIOBLANK		0x4611		/* arg: 0 or vesa level + 1 */
34 #define FBIOGET_VBLANK		_IOR('F', 0x12, struct fb_vblank)
35 #define FBIO_ALLOC              0x4613
36 #define FBIO_FREE               0x4614
37 #define FBIOGET_GLYPH           0x4615
38 #define FBIOGET_HWCINFO         0x4616
39 #define FBIOPUT_MODEINFO        0x4617
40 #define FBIOGET_DISPINFO        0x4618
41 #define FBIO_WAITFORVSYNC	_IOW('F', 0x20, __u32)
42 
43 #define FB_TYPE_PACKED_PIXELS		0	/* Packed Pixels	*/
44 #define FB_TYPE_PLANES			1	/* Non interleaved planes */
45 #define FB_TYPE_INTERLEAVED_PLANES	2	/* Interleaved planes	*/
46 #define FB_TYPE_TEXT			3	/* Text/attributes	*/
47 #define FB_TYPE_VGA_PLANES		4	/* EGA/VGA planes	*/
48 #define FB_TYPE_FOURCC			5	/* Type identified by a V4L2 FOURCC */
49 
50 #define FB_AUX_TEXT_MDA		0	/* Monochrome text */
51 #define FB_AUX_TEXT_CGA		1	/* CGA/EGA/VGA Color text */
52 #define FB_AUX_TEXT_S3_MMIO	2	/* S3 MMIO fasttext */
53 #define FB_AUX_TEXT_MGA_STEP16	3	/* MGA Millenium I: text, attr, 14 reserved bytes */
54 #define FB_AUX_TEXT_MGA_STEP8	4	/* other MGAs:      text, attr,  6 reserved bytes */
55 #define FB_AUX_TEXT_SVGA_GROUP	8	/* 8-15: SVGA tileblit compatible modes */
56 #define FB_AUX_TEXT_SVGA_MASK	7	/* lower three bits says step */
57 #define FB_AUX_TEXT_SVGA_STEP2	8	/* SVGA text mode:  text, attr */
58 #define FB_AUX_TEXT_SVGA_STEP4	9	/* SVGA text mode:  text, attr,  2 reserved bytes */
59 #define FB_AUX_TEXT_SVGA_STEP8	10	/* SVGA text mode:  text, attr,  6 reserved bytes */
60 #define FB_AUX_TEXT_SVGA_STEP16	11	/* SVGA text mode:  text, attr, 14 reserved bytes */
61 #define FB_AUX_TEXT_SVGA_LAST	15	/* reserved up to 15 */
62 
63 #define FB_AUX_VGA_PLANES_VGA4		0	/* 16 color planes (EGA/VGA) */
64 #define FB_AUX_VGA_PLANES_CFB4		1	/* CFB4 in planes (VGA) */
65 #define FB_AUX_VGA_PLANES_CFB8		2	/* CFB8 in planes (VGA) */
66 
67 #define FB_VISUAL_MONO01		0	/* Monochr. 1=Black 0=White */
68 #define FB_VISUAL_MONO10		1	/* Monochr. 1=White 0=Black */
69 #define FB_VISUAL_TRUECOLOR		2	/* True color	*/
70 #define FB_VISUAL_PSEUDOCOLOR		3	/* Pseudo color (like atari) */
71 #define FB_VISUAL_DIRECTCOLOR		4	/* Direct color */
72 #define FB_VISUAL_STATIC_PSEUDOCOLOR	5	/* Pseudo color readonly */
73 #define FB_VISUAL_FOURCC		6	/* Visual identified by a V4L2 FOURCC */
74 
75 #define FB_ACCEL_NONE		0	/* no hardware accelerator	*/
76 #define FB_ACCEL_ATARIBLITT	1	/* Atari Blitter		*/
77 #define FB_ACCEL_AMIGABLITT	2	/* Amiga Blitter                */
78 #define FB_ACCEL_S3_TRIO64	3	/* Cybervision64 (S3 Trio64)    */
79 #define FB_ACCEL_NCR_77C32BLT	4	/* RetinaZ3 (NCR 77C32BLT)      */
80 #define FB_ACCEL_S3_VIRGE	5	/* Cybervision64/3D (S3 ViRGE)	*/
81 #define FB_ACCEL_ATI_MACH64GX	6	/* ATI Mach 64GX family		*/
82 #define FB_ACCEL_DEC_TGA	7	/* DEC 21030 TGA		*/
83 #define FB_ACCEL_ATI_MACH64CT	8	/* ATI Mach 64CT family		*/
84 #define FB_ACCEL_ATI_MACH64VT	9	/* ATI Mach 64CT family VT class */
85 #define FB_ACCEL_ATI_MACH64GT	10	/* ATI Mach 64CT family GT class */
86 #define FB_ACCEL_SUN_CREATOR	11	/* Sun Creator/Creator3D	*/
87 #define FB_ACCEL_SUN_CGSIX	12	/* Sun cg6			*/
88 #define FB_ACCEL_SUN_LEO	13	/* Sun leo/zx			*/
89 #define FB_ACCEL_IMS_TWINTURBO	14	/* IMS Twin Turbo		*/
90 #define FB_ACCEL_3DLABS_PERMEDIA2 15	/* 3Dlabs Permedia 2		*/
91 #define FB_ACCEL_MATROX_MGA2064W 16	/* Matrox MGA2064W (Millenium)	*/
92 #define FB_ACCEL_MATROX_MGA1064SG 17	/* Matrox MGA1064SG (Mystique)	*/
93 #define FB_ACCEL_MATROX_MGA2164W 18	/* Matrox MGA2164W (Millenium II) */
94 #define FB_ACCEL_MATROX_MGA2164W_AGP 19	/* Matrox MGA2164W (Millenium II) */
95 #define FB_ACCEL_MATROX_MGAG100	20	/* Matrox G100 (Productiva G100) */
96 #define FB_ACCEL_MATROX_MGAG200	21	/* Matrox G200 (Myst, Mill, ...) */
97 #define FB_ACCEL_SUN_CG14	22	/* Sun cgfourteen		 */
98 #define FB_ACCEL_SUN_BWTWO	23	/* Sun bwtwo			*/
99 #define FB_ACCEL_SUN_CGTHREE	24	/* Sun cgthree			*/
100 #define FB_ACCEL_SUN_TCX	25	/* Sun tcx			*/
101 #define FB_ACCEL_MATROX_MGAG400	26	/* Matrox G400			*/
102 #define FB_ACCEL_NV3		27	/* nVidia RIVA 128              */
103 #define FB_ACCEL_NV4		28	/* nVidia RIVA TNT		*/
104 #define FB_ACCEL_NV5		29	/* nVidia RIVA TNT2		*/
105 #define FB_ACCEL_CT_6555x	30	/* C&T 6555x			*/
106 #define FB_ACCEL_3DFX_BANSHEE	31	/* 3Dfx Banshee			*/
107 #define FB_ACCEL_ATI_RAGE128	32	/* ATI Rage128 family		*/
108 #define FB_ACCEL_IGS_CYBER2000	33	/* CyberPro 2000		*/
109 #define FB_ACCEL_IGS_CYBER2010	34	/* CyberPro 2010		*/
110 #define FB_ACCEL_IGS_CYBER5000	35	/* CyberPro 5000		*/
111 #define FB_ACCEL_SIS_GLAMOUR    36	/* SiS 300/630/540              */
112 #define FB_ACCEL_3DLABS_PERMEDIA3 37	/* 3Dlabs Permedia 3		*/
113 #define FB_ACCEL_ATI_RADEON	38	/* ATI Radeon family		*/
114 #define FB_ACCEL_I810           39      /* Intel 810/815                */
115 #define FB_ACCEL_SIS_GLAMOUR_2  40	/* SiS 315, 650, 740		*/
116 #define FB_ACCEL_SIS_XABRE      41	/* SiS 330 ("Xabre")		*/
117 #define FB_ACCEL_I830           42      /* Intel 830M/845G/85x/865G     */
118 #define FB_ACCEL_NV_10          43      /* nVidia Arch 10               */
119 #define FB_ACCEL_NV_20          44      /* nVidia Arch 20               */
120 #define FB_ACCEL_NV_30          45      /* nVidia Arch 30               */
121 #define FB_ACCEL_NV_40          46      /* nVidia Arch 40               */
122 #define FB_ACCEL_XGI_VOLARI_V	47	/* XGI Volari V3XT, V5, V8      */
123 #define FB_ACCEL_XGI_VOLARI_Z	48	/* XGI Volari Z7                */
124 #define FB_ACCEL_OMAP1610	49	/* TI OMAP16xx                  */
125 #define FB_ACCEL_TRIDENT_TGUI	50	/* Trident TGUI			*/
126 #define FB_ACCEL_TRIDENT_3DIMAGE 51	/* Trident 3DImage		*/
127 #define FB_ACCEL_TRIDENT_BLADE3D 52	/* Trident Blade3D		*/
128 #define FB_ACCEL_TRIDENT_BLADEXP 53	/* Trident BladeXP		*/
129 #define FB_ACCEL_CIRRUS_ALPINE   53	/* Cirrus Logic 543x/544x/5480	*/
130 #define FB_ACCEL_NEOMAGIC_NM2070 90	/* NeoMagic NM2070              */
131 #define FB_ACCEL_NEOMAGIC_NM2090 91	/* NeoMagic NM2090              */
132 #define FB_ACCEL_NEOMAGIC_NM2093 92	/* NeoMagic NM2093              */
133 #define FB_ACCEL_NEOMAGIC_NM2097 93	/* NeoMagic NM2097              */
134 #define FB_ACCEL_NEOMAGIC_NM2160 94	/* NeoMagic NM2160              */
135 #define FB_ACCEL_NEOMAGIC_NM2200 95	/* NeoMagic NM2200              */
136 #define FB_ACCEL_NEOMAGIC_NM2230 96	/* NeoMagic NM2230              */
137 #define FB_ACCEL_NEOMAGIC_NM2360 97	/* NeoMagic NM2360              */
138 #define FB_ACCEL_NEOMAGIC_NM2380 98	/* NeoMagic NM2380              */
139 #define FB_ACCEL_PXA3XX		 99	/* PXA3xx			*/
140 
141 #define FB_ACCEL_SAVAGE4        0x80	/* S3 Savage4                   */
142 #define FB_ACCEL_SAVAGE3D       0x81	/* S3 Savage3D                  */
143 #define FB_ACCEL_SAVAGE3D_MV    0x82	/* S3 Savage3D-MV               */
144 #define FB_ACCEL_SAVAGE2000     0x83	/* S3 Savage2000                */
145 #define FB_ACCEL_SAVAGE_MX_MV   0x84	/* S3 Savage/MX-MV              */
146 #define FB_ACCEL_SAVAGE_MX      0x85	/* S3 Savage/MX                 */
147 #define FB_ACCEL_SAVAGE_IX_MV   0x86	/* S3 Savage/IX-MV              */
148 #define FB_ACCEL_SAVAGE_IX      0x87	/* S3 Savage/IX                 */
149 #define FB_ACCEL_PROSAVAGE_PM   0x88	/* S3 ProSavage PM133           */
150 #define FB_ACCEL_PROSAVAGE_KM   0x89	/* S3 ProSavage KM133           */
151 #define FB_ACCEL_S3TWISTER_P    0x8a	/* S3 Twister                   */
152 #define FB_ACCEL_S3TWISTER_K    0x8b	/* S3 TwisterK                  */
153 #define FB_ACCEL_SUPERSAVAGE    0x8c    /* S3 Supersavage               */
154 #define FB_ACCEL_PROSAVAGE_DDR  0x8d	/* S3 ProSavage DDR             */
155 #define FB_ACCEL_PROSAVAGE_DDRK 0x8e	/* S3 ProSavage DDR-K           */
156 
157 #define FB_ACCEL_PUV3_UNIGFX	0xa0	/* PKUnity-v3 Unigfx		*/
158 
159 #define FB_CAP_FOURCC		1	/* Device supports FOURCC-based formats */
160 
161 struct fb_fix_screeninfo {
162 	char id[16];			/* identification string eg "TT Builtin" */
163 	unsigned long smem_start;	/* Start of frame buffer mem */
164 					/* (physical address) */
165 	__u32 smem_len;			/* Length of frame buffer mem */
166 	__u32 type;			/* see FB_TYPE_*		*/
167 	__u32 type_aux;			/* Interleave for interleaved Planes */
168 	__u32 visual;			/* see FB_VISUAL_*		*/
169 	__u16 xpanstep;			/* zero if no hardware panning  */
170 	__u16 ypanstep;			/* zero if no hardware panning  */
171 	__u16 ywrapstep;		/* zero if no hardware ywrap    */
172 	__u32 line_length;		/* length of a line in bytes    */
173 	unsigned long mmio_start;	/* Start of Memory Mapped I/O   */
174 					/* (physical address) */
175 	__u32 mmio_len;			/* Length of Memory Mapped I/O  */
176 	__u32 accel;			/* Indicate to driver which	*/
177 					/*  specific chip/card we have	*/
178 	__u16 capabilities;		/* see FB_CAP_*			*/
179 	__u16 reserved[2];		/* Reserved for future compatibility */
180 };
181 
182 /* Interpretation of offset for color fields: All offsets are from the right,
183  * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
184  * can use the offset as right argument to <<). A pixel afterwards is a bit
185  * stream and is written to video memory as that unmodified.
186  *
187  * For pseudocolor: offset and length should be the same for all color
188  * components. Offset specifies the position of the least significant bit
189  * of the pallette index in a pixel value. Length indicates the number
190  * of available palette entries (i.e. # of entries = 1 << length).
191  */
192 struct fb_bitfield {
193 	__u32 offset;			/* beginning of bitfield	*/
194 	__u32 length;			/* length of bitfield		*/
195 	__u32 msb_right;		/* != 0 : Most significant bit is */
196 					/* right */
197 };
198 
199 #define FB_NONSTD_HAM		1	/* Hold-And-Modify (HAM)        */
200 #define FB_NONSTD_REV_PIX_IN_B	2	/* order of pixels in each byte is reversed */
201 
202 #define FB_ACTIVATE_NOW		0	/* set values immediately (or vbl)*/
203 #define FB_ACTIVATE_NXTOPEN	1	/* activate on next open	*/
204 #define FB_ACTIVATE_TEST	2	/* don't set, round up impossible */
205 #define FB_ACTIVATE_MASK       15
206 					/* values			*/
207 #define FB_ACTIVATE_VBL	       16	/* activate values on next vbl  */
208 #define FB_CHANGE_CMAP_VBL     32	/* change colormap on vbl	*/
209 #define FB_ACTIVATE_ALL	       64	/* change all VCs on this fb	*/
210 #define FB_ACTIVATE_FORCE     128	/* force apply even when no change*/
211 #define FB_ACTIVATE_INV_MODE  256       /* invalidate videomode */
212 
213 #define FB_ACCELF_TEXT		1	/* (OBSOLETE) see fb_info.flags and vc_mode */
214 
215 #define FB_SYNC_HOR_HIGH_ACT	1	/* horizontal sync high active	*/
216 #define FB_SYNC_VERT_HIGH_ACT	2	/* vertical sync high active	*/
217 #define FB_SYNC_EXT		4	/* external sync		*/
218 #define FB_SYNC_COMP_HIGH_ACT	8	/* composite sync high active   */
219 #define FB_SYNC_BROADCAST	16	/* broadcast video timings      */
220 					/* vtotal = 144d/288n/576i => PAL  */
221 					/* vtotal = 121d/242n/484i => NTSC */
222 #define FB_SYNC_ON_GREEN	32	/* sync on green */
223 
224 #define FB_VMODE_NONINTERLACED  0	/* non interlaced */
225 #define FB_VMODE_INTERLACED	1	/* interlaced	*/
226 #define FB_VMODE_DOUBLE		2	/* double scan */
227 #define FB_VMODE_ODD_FLD_FIRST	4	/* interlaced: top line first */
228 #define FB_VMODE_MASK		255
229 
230 #define FB_VMODE_YWRAP		256	/* ywrap instead of panning     */
231 #define FB_VMODE_SMOOTH_XPAN	512	/* smooth xpan possible (internally used) */
232 #define FB_VMODE_CONUPDATE	512	/* don't update x/yoffset	*/
233 
234 /*
235  * Display rotation support
236  */
237 #define FB_ROTATE_UR      0
238 #define FB_ROTATE_CW      1
239 #define FB_ROTATE_UD      2
240 #define FB_ROTATE_CCW     3
241 
242 #define PICOS2KHZ(a) (1000000000UL/(a))
243 #define KHZ2PICOS(a) (1000000000UL/(a))
244 
245 struct fb_var_screeninfo {
246 	__u32 xres;			/* visible resolution		*/
247 	__u32 yres;
248 	__u32 xres_virtual;		/* virtual resolution		*/
249 	__u32 yres_virtual;
250 	__u32 xoffset;			/* offset from virtual to visible */
251 	__u32 yoffset;			/* resolution			*/
252 
253 	__u32 bits_per_pixel;		/* guess what			*/
254 	__u32 grayscale;		/* 0 = color, 1 = grayscale,	*/
255 					/* >1 = FOURCC			*/
256 	struct fb_bitfield red;		/* bitfield in fb mem if true color, */
257 	struct fb_bitfield green;	/* else only length is significant */
258 	struct fb_bitfield blue;
259 	struct fb_bitfield transp;	/* transparency			*/
260 
261 	__u32 nonstd;			/* != 0 Non standard pixel format */
262 
263 	__u32 activate;			/* see FB_ACTIVATE_*		*/
264 
265 	__u32 height;			/* height of picture in mm    */
266 	__u32 width;			/* width of picture in mm     */
267 
268 	__u32 accel_flags;		/* (OBSOLETE) see fb_info.flags */
269 
270 	/* Timing: All values in pixclocks, except pixclock (of course) */
271 	__u32 pixclock;			/* pixel clock in ps (pico seconds) */
272 	__u32 left_margin;		/* time from sync to picture	*/
273 	__u32 right_margin;		/* time from picture to sync	*/
274 	__u32 upper_margin;		/* time from sync to picture	*/
275 	__u32 lower_margin;
276 	__u32 hsync_len;		/* length of horizontal sync	*/
277 	__u32 vsync_len;		/* length of vertical sync	*/
278 	__u32 sync;			/* see FB_SYNC_*		*/
279 	__u32 vmode;			/* see FB_VMODE_*		*/
280 	__u32 rotate;			/* angle we rotate counter clockwise */
281 	__u32 colorspace;		/* colorspace for FOURCC-based modes */
282 	__u32 reserved[4];		/* Reserved for future compatibility */
283 };
284 
285 struct fb_cmap {
286 	__u32 start;			/* First entry	*/
287 	__u32 len;			/* Number of entries */
288 	__u16 *red;			/* Red values	*/
289 	__u16 *green;
290 	__u16 *blue;
291 	__u16 *transp;			/* transparency, can be NULL */
292 };
293 
294 struct fb_con2fbmap {
295 	__u32 console;
296 	__u32 framebuffer;
297 };
298 
299 /* VESA Blanking Levels */
300 #define VESA_NO_BLANKING        0
301 #define VESA_VSYNC_SUSPEND      1
302 #define VESA_HSYNC_SUSPEND      2
303 #define VESA_POWERDOWN          3
304 
305 
306 enum {
307 	/* screen: unblanked, hsync: on,  vsync: on */
308 	FB_BLANK_UNBLANK       = VESA_NO_BLANKING,
309 
310 	/* screen: blanked,   hsync: on,  vsync: on */
311 	FB_BLANK_NORMAL        = VESA_NO_BLANKING + 1,
312 
313 	/* screen: blanked,   hsync: on,  vsync: off */
314 	FB_BLANK_VSYNC_SUSPEND = VESA_VSYNC_SUSPEND + 1,
315 
316 	/* screen: blanked,   hsync: off, vsync: on */
317 	FB_BLANK_HSYNC_SUSPEND = VESA_HSYNC_SUSPEND + 1,
318 
319 	/* screen: blanked,   hsync: off, vsync: off */
320 	FB_BLANK_POWERDOWN     = VESA_POWERDOWN + 1
321 };
322 
323 #define FB_VBLANK_VBLANKING	0x001	/* currently in a vertical blank */
324 #define FB_VBLANK_HBLANKING	0x002	/* currently in a horizontal blank */
325 #define FB_VBLANK_HAVE_VBLANK	0x004	/* vertical blanks can be detected */
326 #define FB_VBLANK_HAVE_HBLANK	0x008	/* horizontal blanks can be detected */
327 #define FB_VBLANK_HAVE_COUNT	0x010	/* global retrace counter is available */
328 #define FB_VBLANK_HAVE_VCOUNT	0x020	/* the vcount field is valid */
329 #define FB_VBLANK_HAVE_HCOUNT	0x040	/* the hcount field is valid */
330 #define FB_VBLANK_VSYNCING	0x080	/* currently in a vsync */
331 #define FB_VBLANK_HAVE_VSYNC	0x100	/* verical syncs can be detected */
332 
333 struct fb_vblank {
334 	__u32 flags;			/* FB_VBLANK flags */
335 	__u32 count;			/* counter of retraces since boot */
336 	__u32 vcount;			/* current scanline position */
337 	__u32 hcount;			/* current scandot position */
338 	__u32 reserved[4];		/* reserved for future compatibility */
339 };
340 
341 /* Internal HW accel */
342 #define ROP_COPY 0
343 #define ROP_XOR  1
344 
345 struct fb_copyarea {
346 	__u32 dx;
347 	__u32 dy;
348 	__u32 width;
349 	__u32 height;
350 	__u32 sx;
351 	__u32 sy;
352 };
353 
354 struct fb_fillrect {
355 	__u32 dx;	/* screen-relative */
356 	__u32 dy;
357 	__u32 width;
358 	__u32 height;
359 	__u32 color;
360 	__u32 rop;
361 };
362 
363 struct fb_image {
364 	__u32 dx;		/* Where to place image */
365 	__u32 dy;
366 	__u32 width;		/* Size of image */
367 	__u32 height;
368 	__u32 fg_color;		/* Only used when a mono bitmap */
369 	__u32 bg_color;
370 	__u8  depth;		/* Depth of the image */
371 	const char *data;	/* Pointer to image data */
372 	struct fb_cmap cmap;	/* color map info */
373 };
374 
375 /*
376  * hardware cursor control
377  */
378 
379 #define FB_CUR_SETIMAGE 0x01
380 #define FB_CUR_SETPOS   0x02
381 #define FB_CUR_SETHOT   0x04
382 #define FB_CUR_SETCMAP  0x08
383 #define FB_CUR_SETSHAPE 0x10
384 #define FB_CUR_SETSIZE	0x20
385 #define FB_CUR_SETALL   0xFF
386 
387 struct fbcurpos {
388 	__u16 x, y;
389 };
390 
391 struct fb_cursor {
392 	__u16 set;		/* what to set */
393 	__u16 enable;		/* cursor on/off */
394 	__u16 rop;		/* bitop operation */
395 	const char *mask;	/* cursor mask bits */
396 	struct fbcurpos hot;	/* cursor hot spot */
397 	struct fb_image	image;	/* Cursor image */
398 };
399 
400 #ifdef CONFIG_FB_BACKLIGHT
401 /* Settings for the generic backlight code */
402 #define FB_BACKLIGHT_LEVELS	128
403 #define FB_BACKLIGHT_MAX	0xFF
404 #endif
405 
406 #ifdef __KERNEL__
407 
408 #include <linux/fs.h>
409 #include <linux/init.h>
410 #include <linux/workqueue.h>
411 #include <linux/notifier.h>
412 #include <linux/list.h>
413 #include <linux/backlight.h>
414 #include <linux/slab.h>
415 #include <asm/io.h>
416 
417 struct vm_area_struct;
418 struct fb_info;
419 struct device;
420 struct file;
421 
422 /* Definitions below are used in the parsed monitor specs */
423 #define FB_DPMS_ACTIVE_OFF	1
424 #define FB_DPMS_SUSPEND		2
425 #define FB_DPMS_STANDBY		4
426 
427 #define FB_DISP_DDI		1
428 #define FB_DISP_ANA_700_300	2
429 #define FB_DISP_ANA_714_286	4
430 #define FB_DISP_ANA_1000_400	8
431 #define FB_DISP_ANA_700_000	16
432 
433 #define FB_DISP_MONO		32
434 #define FB_DISP_RGB		64
435 #define FB_DISP_MULTI		128
436 #define FB_DISP_UNKNOWN		256
437 
438 #define FB_SIGNAL_NONE		0
439 #define FB_SIGNAL_BLANK_BLANK	1
440 #define FB_SIGNAL_SEPARATE	2
441 #define FB_SIGNAL_COMPOSITE	4
442 #define FB_SIGNAL_SYNC_ON_GREEN	8
443 #define FB_SIGNAL_SERRATION_ON	16
444 
445 #define FB_MISC_PRIM_COLOR	1
446 #define FB_MISC_1ST_DETAIL	2	/* First Detailed Timing is preferred */
447 struct fb_chroma {
448 	__u32 redx;	/* in fraction of 1024 */
449 	__u32 greenx;
450 	__u32 bluex;
451 	__u32 whitex;
452 	__u32 redy;
453 	__u32 greeny;
454 	__u32 bluey;
455 	__u32 whitey;
456 };
457 
458 struct fb_monspecs {
459 	struct fb_chroma chroma;
460 	struct fb_videomode *modedb;	/* mode database */
461 	__u8  manufacturer[4];		/* Manufacturer */
462 	__u8  monitor[14];		/* Monitor String */
463 	__u8  serial_no[14];		/* Serial Number */
464 	__u8  ascii[14];		/* ? */
465 	__u32 modedb_len;		/* mode database length */
466 	__u32 model;			/* Monitor Model */
467 	__u32 serial;			/* Serial Number - Integer */
468 	__u32 year;			/* Year manufactured */
469 	__u32 week;			/* Week Manufactured */
470 	__u32 hfmin;			/* hfreq lower limit (Hz) */
471 	__u32 hfmax;			/* hfreq upper limit (Hz) */
472 	__u32 dclkmin;			/* pixelclock lower limit (Hz) */
473 	__u32 dclkmax;			/* pixelclock upper limit (Hz) */
474 	__u16 input;			/* display type - see FB_DISP_* */
475 	__u16 dpms;			/* DPMS support - see FB_DPMS_ */
476 	__u16 signal;			/* Signal Type - see FB_SIGNAL_* */
477 	__u16 vfmin;			/* vfreq lower limit (Hz) */
478 	__u16 vfmax;			/* vfreq upper limit (Hz) */
479 	__u16 gamma;			/* Gamma - in fractions of 100 */
480 	__u16 gtf	: 1;		/* supports GTF */
481 	__u16 misc;			/* Misc flags - see FB_MISC_* */
482 	__u8  version;			/* EDID version... */
483 	__u8  revision;			/* ...and revision */
484 	__u8  max_x;			/* Maximum horizontal size (cm) */
485 	__u8  max_y;			/* Maximum vertical size (cm) */
486 };
487 
488 struct fb_cmap_user {
489 	__u32 start;			/* First entry	*/
490 	__u32 len;			/* Number of entries */
491 	__u16 __user *red;		/* Red values	*/
492 	__u16 __user *green;
493 	__u16 __user *blue;
494 	__u16 __user *transp;		/* transparency, can be NULL */
495 };
496 
497 struct fb_image_user {
498 	__u32 dx;			/* Where to place image */
499 	__u32 dy;
500 	__u32 width;			/* Size of image */
501 	__u32 height;
502 	__u32 fg_color;			/* Only used when a mono bitmap */
503 	__u32 bg_color;
504 	__u8  depth;			/* Depth of the image */
505 	const char __user *data;	/* Pointer to image data */
506 	struct fb_cmap_user cmap;	/* color map info */
507 };
508 
509 struct fb_cursor_user {
510 	__u16 set;			/* what to set */
511 	__u16 enable;			/* cursor on/off */
512 	__u16 rop;			/* bitop operation */
513 	const char __user *mask;	/* cursor mask bits */
514 	struct fbcurpos hot;		/* cursor hot spot */
515 	struct fb_image_user image;	/* Cursor image */
516 };
517 
518 /*
519  * Register/unregister for framebuffer events
520  */
521 
522 /*	The resolution of the passed in fb_info about to change */
523 #define FB_EVENT_MODE_CHANGE		0x01
524 /*	The display on this fb_info is beeing suspended, no access to the
525  *	framebuffer is allowed any more after that call returns
526  */
527 #define FB_EVENT_SUSPEND		0x02
528 /*	The display on this fb_info was resumed, you can restore the display
529  *	if you own it
530  */
531 #define FB_EVENT_RESUME			0x03
532 /*      An entry from the modelist was removed */
533 #define FB_EVENT_MODE_DELETE            0x04
534 /*      A driver registered itself */
535 #define FB_EVENT_FB_REGISTERED          0x05
536 /*      A driver unregistered itself */
537 #define FB_EVENT_FB_UNREGISTERED        0x06
538 /*      CONSOLE-SPECIFIC: get console to framebuffer mapping */
539 #define FB_EVENT_GET_CONSOLE_MAP        0x07
540 /*      CONSOLE-SPECIFIC: set console to framebuffer mapping */
541 #define FB_EVENT_SET_CONSOLE_MAP        0x08
542 /*      A hardware display blank change occurred */
543 #define FB_EVENT_BLANK                  0x09
544 /*      Private modelist is to be replaced */
545 #define FB_EVENT_NEW_MODELIST           0x0A
546 /*	The resolution of the passed in fb_info about to change and
547         all vc's should be changed         */
548 #define FB_EVENT_MODE_CHANGE_ALL	0x0B
549 /*	A software display blank change occurred */
550 #define FB_EVENT_CONBLANK               0x0C
551 /*      Get drawing requirements        */
552 #define FB_EVENT_GET_REQ                0x0D
553 /*      Unbind from the console if possible */
554 #define FB_EVENT_FB_UNBIND              0x0E
555 /*      CONSOLE-SPECIFIC: remap all consoles to new fb - for vga switcheroo */
556 #define FB_EVENT_REMAP_ALL_CONSOLE      0x0F
557 
558 struct fb_event {
559 	struct fb_info *info;
560 	void *data;
561 };
562 
563 struct fb_blit_caps {
564 	u32 x;
565 	u32 y;
566 	u32 len;
567 	u32 flags;
568 };
569 
570 extern int fb_register_client(struct notifier_block *nb);
571 extern int fb_unregister_client(struct notifier_block *nb);
572 extern int fb_notifier_call_chain(unsigned long val, void *v);
573 /*
574  * Pixmap structure definition
575  *
576  * The purpose of this structure is to translate data
577  * from the hardware independent format of fbdev to what
578  * format the hardware needs.
579  */
580 
581 #define FB_PIXMAP_DEFAULT 1     /* used internally by fbcon */
582 #define FB_PIXMAP_SYSTEM  2     /* memory is in system RAM  */
583 #define FB_PIXMAP_IO      4     /* memory is iomapped       */
584 #define FB_PIXMAP_SYNC    256   /* set if GPU can DMA       */
585 
586 struct fb_pixmap {
587 	u8  *addr;		/* pointer to memory			*/
588 	u32 size;		/* size of buffer in bytes		*/
589 	u32 offset;		/* current offset to buffer		*/
590 	u32 buf_align;		/* byte alignment of each bitmap	*/
591 	u32 scan_align;		/* alignment per scanline		*/
592 	u32 access_align;	/* alignment per read/write (bits)	*/
593 	u32 flags;		/* see FB_PIXMAP_*			*/
594 	u32 blit_x;             /* supported bit block dimensions (1-32)*/
595 	u32 blit_y;             /* Format: blit_x = 1 << (width - 1)    */
596 	                        /*         blit_y = 1 << (height - 1)   */
597 	                        /* if 0, will be set to 0xffffffff (all)*/
598 	/* access methods */
599 	void (*writeio)(struct fb_info *info, void __iomem *dst, void *src, unsigned int size);
600 	void (*readio) (struct fb_info *info, void *dst, void __iomem *src, unsigned int size);
601 };
602 
603 #ifdef CONFIG_FB_DEFERRED_IO
604 struct fb_deferred_io {
605 	/* delay between mkwrite and deferred handler */
606 	unsigned long delay;
607 	struct mutex lock; /* mutex that protects the page list */
608 	struct list_head pagelist; /* list of touched pages */
609 	/* callback */
610 	void (*deferred_io)(struct fb_info *info, struct list_head *pagelist);
611 };
612 #endif
613 
614 /*
615  * Frame buffer operations
616  *
617  * LOCKING NOTE: those functions must _ALL_ be called with the console
618  * semaphore held, this is the only suitable locking mechanism we have
619  * in 2.6. Some may be called at interrupt time at this point though.
620  *
621  * The exception to this is the debug related hooks.  Putting the fb
622  * into a debug state (e.g. flipping to the kernel console) and restoring
623  * it must be done in a lock-free manner, so low level drivers should
624  * keep track of the initial console (if applicable) and may need to
625  * perform direct, unlocked hardware writes in these hooks.
626  */
627 
628 struct fb_ops {
629 	/* open/release and usage marking */
630 	struct module *owner;
631 	int (*fb_open)(struct fb_info *info, int user);
632 	int (*fb_release)(struct fb_info *info, int user);
633 
634 	/* For framebuffers with strange non linear layouts or that do not
635 	 * work with normal memory mapped access
636 	 */
637 	ssize_t (*fb_read)(struct fb_info *info, char __user *buf,
638 			   size_t count, loff_t *ppos);
639 	ssize_t (*fb_write)(struct fb_info *info, const char __user *buf,
640 			    size_t count, loff_t *ppos);
641 
642 	/* checks var and eventually tweaks it to something supported,
643 	 * DO NOT MODIFY PAR */
644 	int (*fb_check_var)(struct fb_var_screeninfo *var, struct fb_info *info);
645 
646 	/* set the video mode according to info->var */
647 	int (*fb_set_par)(struct fb_info *info);
648 
649 	/* set color register */
650 	int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
651 			    unsigned blue, unsigned transp, struct fb_info *info);
652 
653 	/* set color registers in batch */
654 	int (*fb_setcmap)(struct fb_cmap *cmap, struct fb_info *info);
655 
656 	/* blank display */
657 	int (*fb_blank)(int blank, struct fb_info *info);
658 
659 	/* pan display */
660 	int (*fb_pan_display)(struct fb_var_screeninfo *var, struct fb_info *info);
661 
662 	/* Draws a rectangle */
663 	void (*fb_fillrect) (struct fb_info *info, const struct fb_fillrect *rect);
664 	/* Copy data from area to another */
665 	void (*fb_copyarea) (struct fb_info *info, const struct fb_copyarea *region);
666 	/* Draws a image to the display */
667 	void (*fb_imageblit) (struct fb_info *info, const struct fb_image *image);
668 
669 	/* Draws cursor */
670 	int (*fb_cursor) (struct fb_info *info, struct fb_cursor *cursor);
671 
672 	/* Rotates the display */
673 	void (*fb_rotate)(struct fb_info *info, int angle);
674 
675 	/* wait for blit idle, optional */
676 	int (*fb_sync)(struct fb_info *info);
677 
678 	/* perform fb specific ioctl (optional) */
679 	int (*fb_ioctl)(struct fb_info *info, unsigned int cmd,
680 			unsigned long arg);
681 
682 	/* Handle 32bit compat ioctl (optional) */
683 	int (*fb_compat_ioctl)(struct fb_info *info, unsigned cmd,
684 			unsigned long arg);
685 
686 	/* perform fb specific mmap */
687 	int (*fb_mmap)(struct fb_info *info, struct vm_area_struct *vma);
688 
689 	/* get capability given var */
690 	void (*fb_get_caps)(struct fb_info *info, struct fb_blit_caps *caps,
691 			    struct fb_var_screeninfo *var);
692 
693 	/* teardown any resources to do with this framebuffer */
694 	void (*fb_destroy)(struct fb_info *info);
695 
696 	/* called at KDB enter and leave time to prepare the console */
697 	int (*fb_debug_enter)(struct fb_info *info);
698 	int (*fb_debug_leave)(struct fb_info *info);
699 };
700 
701 #ifdef CONFIG_FB_TILEBLITTING
702 #define FB_TILE_CURSOR_NONE        0
703 #define FB_TILE_CURSOR_UNDERLINE   1
704 #define FB_TILE_CURSOR_LOWER_THIRD 2
705 #define FB_TILE_CURSOR_LOWER_HALF  3
706 #define FB_TILE_CURSOR_TWO_THIRDS  4
707 #define FB_TILE_CURSOR_BLOCK       5
708 
709 struct fb_tilemap {
710 	__u32 width;                /* width of each tile in pixels */
711 	__u32 height;               /* height of each tile in scanlines */
712 	__u32 depth;                /* color depth of each tile */
713 	__u32 length;               /* number of tiles in the map */
714 	const __u8 *data;           /* actual tile map: a bitmap array, packed
715 				       to the nearest byte */
716 };
717 
718 struct fb_tilerect {
719 	__u32 sx;                   /* origin in the x-axis */
720 	__u32 sy;                   /* origin in the y-axis */
721 	__u32 width;                /* number of tiles in the x-axis */
722 	__u32 height;               /* number of tiles in the y-axis */
723 	__u32 index;                /* what tile to use: index to tile map */
724 	__u32 fg;                   /* foreground color */
725 	__u32 bg;                   /* background color */
726 	__u32 rop;                  /* raster operation */
727 };
728 
729 struct fb_tilearea {
730 	__u32 sx;                   /* source origin in the x-axis */
731 	__u32 sy;                   /* source origin in the y-axis */
732 	__u32 dx;                   /* destination origin in the x-axis */
733 	__u32 dy;                   /* destination origin in the y-axis */
734 	__u32 width;                /* number of tiles in the x-axis */
735 	__u32 height;               /* number of tiles in the y-axis */
736 };
737 
738 struct fb_tileblit {
739 	__u32 sx;                   /* origin in the x-axis */
740 	__u32 sy;                   /* origin in the y-axis */
741 	__u32 width;                /* number of tiles in the x-axis */
742 	__u32 height;               /* number of tiles in the y-axis */
743 	__u32 fg;                   /* foreground color */
744 	__u32 bg;                   /* background color */
745 	__u32 length;               /* number of tiles to draw */
746 	__u32 *indices;             /* array of indices to tile map */
747 };
748 
749 struct fb_tilecursor {
750 	__u32 sx;                   /* cursor position in the x-axis */
751 	__u32 sy;                   /* cursor position in the y-axis */
752 	__u32 mode;                 /* 0 = erase, 1 = draw */
753 	__u32 shape;                /* see FB_TILE_CURSOR_* */
754 	__u32 fg;                   /* foreground color */
755 	__u32 bg;                   /* background color */
756 };
757 
758 struct fb_tile_ops {
759 	/* set tile characteristics */
760 	void (*fb_settile)(struct fb_info *info, struct fb_tilemap *map);
761 
762 	/* all dimensions from hereon are in terms of tiles */
763 
764 	/* move a rectangular region of tiles from one area to another*/
765 	void (*fb_tilecopy)(struct fb_info *info, struct fb_tilearea *area);
766 	/* fill a rectangular region with a tile */
767 	void (*fb_tilefill)(struct fb_info *info, struct fb_tilerect *rect);
768 	/* copy an array of tiles */
769 	void (*fb_tileblit)(struct fb_info *info, struct fb_tileblit *blit);
770 	/* cursor */
771 	void (*fb_tilecursor)(struct fb_info *info,
772 			      struct fb_tilecursor *cursor);
773 	/* get maximum length of the tile map */
774 	int (*fb_get_tilemax)(struct fb_info *info);
775 };
776 #endif /* CONFIG_FB_TILEBLITTING */
777 
778 /* FBINFO_* = fb_info.flags bit flags */
779 #define FBINFO_MODULE		0x0001	/* Low-level driver is a module */
780 #define FBINFO_HWACCEL_DISABLED	0x0002
781 	/* When FBINFO_HWACCEL_DISABLED is set:
782 	 *  Hardware acceleration is turned off.  Software implementations
783 	 *  of required functions (copyarea(), fillrect(), and imageblit())
784 	 *  takes over; acceleration engine should be in a quiescent state */
785 
786 /* hints */
787 #define FBINFO_VIRTFB		0x0004 /* FB is System RAM, not device. */
788 #define FBINFO_PARTIAL_PAN_OK	0x0040 /* otw use pan only for double-buffering */
789 #define FBINFO_READS_FAST	0x0080 /* soft-copy faster than rendering */
790 
791 /* hardware supported ops */
792 /*  semantics: when a bit is set, it indicates that the operation is
793  *   accelerated by hardware.
794  *  required functions will still work even if the bit is not set.
795  *  optional functions may not even exist if the flag bit is not set.
796  */
797 #define FBINFO_HWACCEL_NONE		0x0000
798 #define FBINFO_HWACCEL_COPYAREA		0x0100 /* required */
799 #define FBINFO_HWACCEL_FILLRECT		0x0200 /* required */
800 #define FBINFO_HWACCEL_IMAGEBLIT	0x0400 /* required */
801 #define FBINFO_HWACCEL_ROTATE		0x0800 /* optional */
802 #define FBINFO_HWACCEL_XPAN		0x1000 /* optional */
803 #define FBINFO_HWACCEL_YPAN		0x2000 /* optional */
804 #define FBINFO_HWACCEL_YWRAP		0x4000 /* optional */
805 
806 #define FBINFO_MISC_USEREVENT          0x10000 /* event request
807 						  from userspace */
808 #define FBINFO_MISC_TILEBLITTING       0x20000 /* use tile blitting */
809 
810 /* A driver may set this flag to indicate that it does want a set_par to be
811  * called every time when fbcon_switch is executed. The advantage is that with
812  * this flag set you can really be sure that set_par is always called before
813  * any of the functions dependent on the correct hardware state or altering
814  * that state, even if you are using some broken X releases. The disadvantage
815  * is that it introduces unwanted delays to every console switch if set_par
816  * is slow. It is a good idea to try this flag in the drivers initialization
817  * code whenever there is a bug report related to switching between X and the
818  * framebuffer console.
819  */
820 #define FBINFO_MISC_ALWAYS_SETPAR   0x40000
821 
822 /* where the fb is a firmware driver, and can be replaced with a proper one */
823 #define FBINFO_MISC_FIRMWARE        0x80000
824 /*
825  * Host and GPU endianness differ.
826  */
827 #define FBINFO_FOREIGN_ENDIAN	0x100000
828 /*
829  * Big endian math. This is the same flags as above, but with different
830  * meaning, it is set by the fb subsystem depending FOREIGN_ENDIAN flag
831  * and host endianness. Drivers should not use this flag.
832  */
833 #define FBINFO_BE_MATH  0x100000
834 
835 /* report to the VT layer that this fb driver can accept forced console
836    output like oopses */
837 #define FBINFO_CAN_FORCE_OUTPUT     0x200000
838 
839 struct fb_info {
840 	atomic_t count;
841 	int node;
842 	int flags;
843 	struct mutex lock;		/* Lock for open/release/ioctl funcs */
844 	struct mutex mm_lock;		/* Lock for fb_mmap and smem_* fields */
845 	struct fb_var_screeninfo var;	/* Current var */
846 	struct fb_fix_screeninfo fix;	/* Current fix */
847 	struct fb_monspecs monspecs;	/* Current Monitor specs */
848 	struct work_struct queue;	/* Framebuffer event queue */
849 	struct fb_pixmap pixmap;	/* Image hardware mapper */
850 	struct fb_pixmap sprite;	/* Cursor hardware mapper */
851 	struct fb_cmap cmap;		/* Current cmap */
852 	struct list_head modelist;      /* mode list */
853 	struct fb_videomode *mode;	/* current mode */
854 
855 #ifdef CONFIG_FB_BACKLIGHT
856 	/* assigned backlight device */
857 	/* set before framebuffer registration,
858 	   remove after unregister */
859 	struct backlight_device *bl_dev;
860 
861 	/* Backlight level curve */
862 	struct mutex bl_curve_mutex;
863 	u8 bl_curve[FB_BACKLIGHT_LEVELS];
864 #endif
865 #ifdef CONFIG_FB_DEFERRED_IO
866 	struct delayed_work deferred_work;
867 	struct fb_deferred_io *fbdefio;
868 #endif
869 
870 	struct fb_ops *fbops;
871 	struct device *device;		/* This is the parent */
872 	struct device *dev;		/* This is this fb device */
873 	int class_flag;                    /* private sysfs flags */
874 #ifdef CONFIG_FB_TILEBLITTING
875 	struct fb_tile_ops *tileops;    /* Tile Blitting */
876 #endif
877 	char __iomem *screen_base;	/* Virtual address */
878 	unsigned long screen_size;	/* Amount of ioremapped VRAM or 0 */
879 	void *pseudo_palette;		/* Fake palette of 16 colors */
880 #define FBINFO_STATE_RUNNING	0
881 #define FBINFO_STATE_SUSPENDED	1
882 	u32 state;			/* Hardware state i.e suspend */
883 	void *fbcon_par;                /* fbcon use-only private area */
884 	/* From here on everything is device dependent */
885 	void *par;
886 	/* we need the PCI or similar aperture base/size not
887 	   smem_start/size as smem_start may just be an object
888 	   allocated inside the aperture so may not actually overlap */
889 	struct apertures_struct {
890 		unsigned int count;
891 		struct aperture {
892 			resource_size_t base;
893 			resource_size_t size;
894 		} ranges[0];
895 	} *apertures;
896 };
897 
alloc_apertures(unsigned int max_num)898 static inline struct apertures_struct *alloc_apertures(unsigned int max_num) {
899 	struct apertures_struct *a = kzalloc(sizeof(struct apertures_struct)
900 			+ max_num * sizeof(struct aperture), GFP_KERNEL);
901 	if (!a)
902 		return NULL;
903 	a->count = max_num;
904 	return a;
905 }
906 
907 #ifdef MODULE
908 #define FBINFO_DEFAULT	FBINFO_MODULE
909 #else
910 #define FBINFO_DEFAULT	0
911 #endif
912 
913 // This will go away
914 #define FBINFO_FLAG_MODULE	FBINFO_MODULE
915 #define FBINFO_FLAG_DEFAULT	FBINFO_DEFAULT
916 
917 /* This will go away
918  * fbset currently hacks in FB_ACCELF_TEXT into var.accel_flags
919  * when it wants to turn the acceleration engine on.  This is
920  * really a separate operation, and should be modified via sysfs.
921  *  But for now, we leave it broken with the following define
922  */
923 #define STUPID_ACCELF_TEXT_SHIT
924 
925 // This will go away
926 #if defined(__sparc__)
927 
928 /* We map all of our framebuffers such that big-endian accesses
929  * are what we want, so the following is sufficient.
930  */
931 
932 // This will go away
933 #define fb_readb sbus_readb
934 #define fb_readw sbus_readw
935 #define fb_readl sbus_readl
936 #define fb_readq sbus_readq
937 #define fb_writeb sbus_writeb
938 #define fb_writew sbus_writew
939 #define fb_writel sbus_writel
940 #define fb_writeq sbus_writeq
941 #define fb_memset sbus_memset_io
942 #define fb_memcpy_fromfb sbus_memcpy_fromio
943 #define fb_memcpy_tofb sbus_memcpy_toio
944 
945 #elif defined(__i386__) || defined(__alpha__) || defined(__x86_64__) || defined(__hppa__) || defined(__sh__) || defined(__powerpc__) || defined(__avr32__) || defined(__bfin__)
946 
947 #define fb_readb __raw_readb
948 #define fb_readw __raw_readw
949 #define fb_readl __raw_readl
950 #define fb_readq __raw_readq
951 #define fb_writeb __raw_writeb
952 #define fb_writew __raw_writew
953 #define fb_writel __raw_writel
954 #define fb_writeq __raw_writeq
955 #define fb_memset memset_io
956 #define fb_memcpy_fromfb memcpy_fromio
957 #define fb_memcpy_tofb memcpy_toio
958 
959 #else
960 
961 #define fb_readb(addr) (*(volatile u8 *) (addr))
962 #define fb_readw(addr) (*(volatile u16 *) (addr))
963 #define fb_readl(addr) (*(volatile u32 *) (addr))
964 #define fb_readq(addr) (*(volatile u64 *) (addr))
965 #define fb_writeb(b,addr) (*(volatile u8 *) (addr) = (b))
966 #define fb_writew(b,addr) (*(volatile u16 *) (addr) = (b))
967 #define fb_writel(b,addr) (*(volatile u32 *) (addr) = (b))
968 #define fb_writeq(b,addr) (*(volatile u64 *) (addr) = (b))
969 #define fb_memset memset
970 #define fb_memcpy_fromfb memcpy
971 #define fb_memcpy_tofb memcpy
972 
973 #endif
974 
975 #define FB_LEFT_POS(p, bpp)          (fb_be_math(p) ? (32 - (bpp)) : 0)
976 #define FB_SHIFT_HIGH(p, val, bits)  (fb_be_math(p) ? (val) >> (bits) : \
977 						      (val) << (bits))
978 #define FB_SHIFT_LOW(p, val, bits)   (fb_be_math(p) ? (val) << (bits) : \
979 						      (val) >> (bits))
980 
981     /*
982      *  `Generic' versions of the frame buffer device operations
983      */
984 
985 extern int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var);
986 extern int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var);
987 extern int fb_blank(struct fb_info *info, int blank);
988 extern void cfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
989 extern void cfb_copyarea(struct fb_info *info, const struct fb_copyarea *area);
990 extern void cfb_imageblit(struct fb_info *info, const struct fb_image *image);
991 /*
992  * Drawing operations where framebuffer is in system RAM
993  */
994 extern void sys_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
995 extern void sys_copyarea(struct fb_info *info, const struct fb_copyarea *area);
996 extern void sys_imageblit(struct fb_info *info, const struct fb_image *image);
997 extern ssize_t fb_sys_read(struct fb_info *info, char __user *buf,
998 			   size_t count, loff_t *ppos);
999 extern ssize_t fb_sys_write(struct fb_info *info, const char __user *buf,
1000 			    size_t count, loff_t *ppos);
1001 
1002 /* drivers/video/fbmem.c */
1003 extern int register_framebuffer(struct fb_info *fb_info);
1004 extern int unregister_framebuffer(struct fb_info *fb_info);
1005 extern int unlink_framebuffer(struct fb_info *fb_info);
1006 extern void remove_conflicting_framebuffers(struct apertures_struct *a,
1007 				const char *name, bool primary);
1008 extern int fb_prepare_logo(struct fb_info *fb_info, int rotate);
1009 extern int fb_show_logo(struct fb_info *fb_info, int rotate);
1010 extern char* fb_get_buffer_offset(struct fb_info *info, struct fb_pixmap *buf, u32 size);
1011 extern void fb_pad_unaligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 idx,
1012 				u32 height, u32 shift_high, u32 shift_low, u32 mod);
1013 extern void fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, u32 height);
1014 extern void fb_set_suspend(struct fb_info *info, int state);
1015 extern int fb_get_color_depth(struct fb_var_screeninfo *var,
1016 			      struct fb_fix_screeninfo *fix);
1017 extern int fb_get_options(char *name, char **option);
1018 extern int fb_new_modelist(struct fb_info *info);
1019 
1020 extern struct fb_info *registered_fb[FB_MAX];
1021 extern int num_registered_fb;
1022 extern struct class *fb_class;
1023 
1024 extern int lock_fb_info(struct fb_info *info);
1025 
unlock_fb_info(struct fb_info * info)1026 static inline void unlock_fb_info(struct fb_info *info)
1027 {
1028 	mutex_unlock(&info->lock);
1029 }
1030 
__fb_pad_aligned_buffer(u8 * dst,u32 d_pitch,u8 * src,u32 s_pitch,u32 height)1031 static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch,
1032 					   u8 *src, u32 s_pitch, u32 height)
1033 {
1034 	int i, j;
1035 
1036 	d_pitch -= s_pitch;
1037 
1038 	for (i = height; i--; ) {
1039 		/* s_pitch is a few bytes at the most, memcpy is suboptimal */
1040 		for (j = 0; j < s_pitch; j++)
1041 			*dst++ = *src++;
1042 		dst += d_pitch;
1043 	}
1044 }
1045 
1046 /* drivers/video/fb_defio.c */
1047 extern void fb_deferred_io_init(struct fb_info *info);
1048 extern void fb_deferred_io_open(struct fb_info *info,
1049 				struct inode *inode,
1050 				struct file *file);
1051 extern void fb_deferred_io_cleanup(struct fb_info *info);
1052 extern int fb_deferred_io_fsync(struct file *file, loff_t start,
1053 				loff_t end, int datasync);
1054 
fb_be_math(struct fb_info * info)1055 static inline bool fb_be_math(struct fb_info *info)
1056 {
1057 #ifdef CONFIG_FB_FOREIGN_ENDIAN
1058 #if defined(CONFIG_FB_BOTH_ENDIAN)
1059 	return info->flags & FBINFO_BE_MATH;
1060 #elif defined(CONFIG_FB_BIG_ENDIAN)
1061 	return true;
1062 #elif defined(CONFIG_FB_LITTLE_ENDIAN)
1063 	return false;
1064 #endif /* CONFIG_FB_BOTH_ENDIAN */
1065 #else
1066 #ifdef __BIG_ENDIAN
1067 	return true;
1068 #else
1069 	return false;
1070 #endif /* __BIG_ENDIAN */
1071 #endif /* CONFIG_FB_FOREIGN_ENDIAN */
1072 }
1073 
1074 /* drivers/video/fbsysfs.c */
1075 extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev);
1076 extern void framebuffer_release(struct fb_info *info);
1077 extern int fb_init_device(struct fb_info *fb_info);
1078 extern void fb_cleanup_device(struct fb_info *head);
1079 extern void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max);
1080 
1081 /* drivers/video/fbmon.c */
1082 #define FB_MAXTIMINGS		0
1083 #define FB_VSYNCTIMINGS		1
1084 #define FB_HSYNCTIMINGS		2
1085 #define FB_DCLKTIMINGS		3
1086 #define FB_IGNOREMON		0x100
1087 
1088 #define FB_MODE_IS_UNKNOWN	0
1089 #define FB_MODE_IS_DETAILED	1
1090 #define FB_MODE_IS_STANDARD	2
1091 #define FB_MODE_IS_VESA		4
1092 #define FB_MODE_IS_CALCULATED	8
1093 #define FB_MODE_IS_FIRST	16
1094 #define FB_MODE_IS_FROM_VAR     32
1095 
1096 extern int fbmon_dpms(const struct fb_info *fb_info);
1097 extern int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var,
1098 		       struct fb_info *info);
1099 extern int fb_validate_mode(const struct fb_var_screeninfo *var,
1100 			    struct fb_info *info);
1101 extern int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var);
1102 extern const unsigned char *fb_firmware_edid(struct device *device);
1103 extern void fb_edid_to_monspecs(unsigned char *edid,
1104 				struct fb_monspecs *specs);
1105 extern void fb_edid_add_monspecs(unsigned char *edid,
1106 				 struct fb_monspecs *specs);
1107 extern void fb_destroy_modedb(struct fb_videomode *modedb);
1108 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
1109 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
1110 
1111 /* drivers/video/modedb.c */
1112 #define VESA_MODEDB_SIZE 34
1113 extern void fb_var_to_videomode(struct fb_videomode *mode,
1114 				const struct fb_var_screeninfo *var);
1115 extern void fb_videomode_to_var(struct fb_var_screeninfo *var,
1116 				const struct fb_videomode *mode);
1117 extern int fb_mode_is_equal(const struct fb_videomode *mode1,
1118 			    const struct fb_videomode *mode2);
1119 extern int fb_add_videomode(const struct fb_videomode *mode,
1120 			    struct list_head *head);
1121 extern void fb_delete_videomode(const struct fb_videomode *mode,
1122 				struct list_head *head);
1123 extern const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var,
1124 						struct list_head *head);
1125 extern const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var,
1126 						    struct list_head *head);
1127 extern const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
1128 						       struct list_head *head);
1129 extern void fb_destroy_modelist(struct list_head *head);
1130 extern void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num,
1131 				     struct list_head *head);
1132 extern const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs,
1133 						       struct list_head *head);
1134 
1135 /* drivers/video/fbcmap.c */
1136 extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp);
1137 extern int fb_alloc_cmap_gfp(struct fb_cmap *cmap, int len, int transp, gfp_t flags);
1138 extern void fb_dealloc_cmap(struct fb_cmap *cmap);
1139 extern int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to);
1140 extern int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to);
1141 extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info);
1142 extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info);
1143 extern const struct fb_cmap *fb_default_cmap(int len);
1144 extern void fb_invert_cmaps(void);
1145 
1146 struct fb_videomode {
1147 	const char *name;	/* optional */
1148 	u32 refresh;		/* optional */
1149 	u32 xres;
1150 	u32 yres;
1151 	u32 pixclock;
1152 	u32 left_margin;
1153 	u32 right_margin;
1154 	u32 upper_margin;
1155 	u32 lower_margin;
1156 	u32 hsync_len;
1157 	u32 vsync_len;
1158 	u32 sync;
1159 	u32 vmode;
1160 	u32 flag;
1161 };
1162 
1163 extern const char *fb_mode_option;
1164 extern const struct fb_videomode vesa_modes[];
1165 extern const struct fb_videomode cea_modes[64];
1166 
1167 struct fb_modelist {
1168 	struct list_head list;
1169 	struct fb_videomode mode;
1170 };
1171 
1172 extern int fb_find_mode(struct fb_var_screeninfo *var,
1173 			struct fb_info *info, const char *mode_option,
1174 			const struct fb_videomode *db,
1175 			unsigned int dbsize,
1176 			const struct fb_videomode *default_mode,
1177 			unsigned int default_bpp);
1178 
1179 #endif /* __KERNEL__ */
1180 
1181 #endif /* _LINUX_FB_H */
1182