comparison old/framebuffer/fb_info.c @ 977:eb704fa22d05 akira

add frame buffer utitilties
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 01 Oct 2010 22:01:53 +0900
parents
children
comparison
equal deleted inserted replaced
973:537d7aa24575 977:eb704fa22d05
1 // fbinfo.c
2 //
3 // Copyright (c) 2006, Mike Acton <macton@cellperformance.com>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6 // documentation files (the "Software"), to deal in the Software without restriction, including without
7 // limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8 // the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
9 // conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in all copies or substantial
12 // portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16 // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
17 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
18 // OR OTHER DEALINGS IN THE SOFTWARE.
19
20 #include <stdio.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <stdint.h>
24 #include <sys/ioctl.h>
25 #include <linux/fb.h>
26 #include <asm/ps3fb.h>
27
28 int
29 main( void )
30 {
31 const int fb_file = open( "/dev/fb0", O_RDWR );
32 const int open_fb_error = (fb_file >> ((sizeof(int)*8)-1));
33
34 if ( open_fb_error < 0 )
35 {
36 printf("Could not open /dev/fb0. Check permissions\n");
37 return (-1);
38 }
39
40 struct fb_vblank vblank;
41
42 int get_vblank_error = ioctl(fb_file, FBIOGET_VBLANK, (unsigned long)&vblank);
43
44 if ( get_vblank_error == -1 )
45 {
46 printf("Warning: FBIOGET_VBLANK Failed\n");
47 }
48 else
49 {
50 printf("FBIOGET_VBLANK:\n");
51 printf(" flags:\n");
52 printf(" FB_VBLANK_VBLANKING : %s\n",(vblank.flags&FB_VBLANK_VBLANKING) ?"TRUE":"FALSE");
53 printf(" FB_VBLANK_HBLANKING : %s\n",(vblank.flags&FB_VBLANK_HBLANKING) ?"TRUE":"FALSE");
54 printf(" FB_VBLANK_HAVE_VBLANK : %s\n",(vblank.flags&FB_VBLANK_HAVE_VBLANK)?"TRUE":"FALSE");
55 printf(" FB_VBLANK_HAVE_HBLANK : %s\n",(vblank.flags&FB_VBLANK_HAVE_HBLANK)?"TRUE":"FALSE");
56 printf(" FB_VBLANK_HAVE_COUNT : %s\n",(vblank.flags&FB_VBLANK_HAVE_COUNT) ?"TRUE":"FALSE");
57 printf(" FB_VBLANK_HAVE_VCOUNT : %s\n",(vblank.flags&FB_VBLANK_HAVE_VCOUNT)?"TRUE":"FALSE");
58 printf(" FB_VBLANK_HAVE_HCOUNT : %s\n",(vblank.flags&FB_VBLANK_HAVE_HCOUNT)?"TRUE":"FALSE");
59 printf(" FB_VBLANK_VSYNCING : %s\n",(vblank.flags&FB_VBLANK_VSYNCING) ?"TRUE":"FALSE");
60 printf(" FB_VBLANK_HAVE_VSYNC : %s\n",(vblank.flags&FB_VBLANK_HAVE_VSYNC) ?"TRUE":"FALSE");
61 printf(" count : %d\n", vblank.count );
62 printf(" vcount : %d\n", vblank.vcount );
63 printf(" hcount : %d\n", vblank.hcount );
64 }
65 printf("-------------------------------------\n");
66
67 struct fb_fix_screeninfo fscreeninfo;
68
69 int get_fscreeninfo_error = ioctl(fb_file, FBIOGET_FSCREENINFO, (unsigned long)&fscreeninfo);
70
71 if ( get_fscreeninfo_error == -1 )
72 {
73 printf("Warning: FBIOGET_FSCREENINFO Failed\n");
74 }
75 else
76 {
77 printf("FBIOGET_FSCREENINFO:\n");
78 printf(" id : \"" "%c%c%c%c" "%c%c%c%c" "%c%c%c%c" "%c%c%c%c" "\"\n",
79 fscreeninfo.id[0], fscreeninfo.id[1], fscreeninfo.id[2], fscreeninfo.id[3],
80 fscreeninfo.id[4], fscreeninfo.id[5], fscreeninfo.id[6], fscreeninfo.id[7],
81 fscreeninfo.id[8], fscreeninfo.id[9], fscreeninfo.id[10], fscreeninfo.id[11],
82 fscreeninfo.id[12], fscreeninfo.id[13], fscreeninfo.id[14], fscreeninfo.id[15] );
83 if ( sizeof(unsigned long) == 4 )
84 {
85 printf(" smem_start : 0x%08x\n", (unsigned int)fscreeninfo.smem_start);
86 }
87 else if ( sizeof(unsigned long) == 8 )
88 {
89 union UL64 { uint32_t u32[2]; uint64_t u64; } smem_start = {.u64=fscreeninfo.smem_start};
90 printf(" smem_start : 0x%08x_%08x\n",smem_start.u32[1],smem_start.u32[0]);
91 }
92 else
93 {
94 printf("WTF! sizeof(unsigned long) = %d\n",sizeof(unsigned long));
95 }
96 printf(" smem_len : %u\n", fscreeninfo.smem_len);
97 printf(" type : ");
98 switch (fscreeninfo.type)
99 {
100 case FB_TYPE_PACKED_PIXELS: printf("FB_TYPE_PACKED_PIXELS (0)\n"); break;
101 case FB_TYPE_PLANES: printf("FB_TYPE_PLANES (1)\n"); break;
102 case FB_TYPE_INTERLEAVED_PLANES: printf("FB_TYPE_INTERLEAVED_PLANES (2)\n"); break;
103 case FB_TYPE_TEXT: printf("FB_TYPE_TEXT (3)\n"); break;
104 case FB_TYPE_VGA_PLANES: printf("FB_TYPE_VGA_PLANES (4)\n"); break;
105 default: printf("UNKNOWN (See /usr/include/linux/fb.h)\n");
106 }
107 printf(" type_aux : ");
108 if ( fscreeninfo.type == FB_TYPE_TEXT )
109 {
110 switch (fscreeninfo.type_aux)
111 {
112 case FB_AUX_TEXT_MDA: printf("FB_AUX_TEXT_MDA (0)\n"); break;
113 case FB_AUX_TEXT_CGA: printf("FB_AUX_TEXT_CGA (1)\n"); break;
114 case FB_AUX_TEXT_S3_MMIO: printf("FB_AUX_TEXT_S3_MMIO (2)\n"); break;
115 case FB_AUX_TEXT_MGA_STEP16: printf("FB_AUX_TEXT_MGA_STEP16 (3)\n"); break;
116 case FB_AUX_TEXT_MGA_STEP8: printf("FB_AUX_TEXT_MGA_STEP8 (4)\n"); break;
117 default: printf("UNKNOWN (See /usr/include/linux/fb.h)\n");
118 }
119 }
120 else if ( fscreeninfo.type == FB_TYPE_INTERLEAVED_PLANES )
121 {
122 switch (fscreeninfo.type_aux)
123 {
124 case FB_AUX_VGA_PLANES_VGA4: printf("FB_AUX_VGA_PLANES_VGA4 (0)\n"); break;
125 case FB_AUX_VGA_PLANES_CFB4: printf("FB_AUX_VGA_PLANES_CFB4 (1)\n"); break;
126 case FB_AUX_VGA_PLANES_CFB8: printf("FB_AUX_VGA_PLANES_CFB8 (2)\n"); break;
127 default: printf("UNKNOWN (See /usr/include/linux/fb.h)\n");
128 }
129 }
130 else
131 {
132 printf("N/A\n");
133 }
134
135 printf(" visual : ");
136 switch (fscreeninfo.visual)
137 {
138 case FB_VISUAL_MONO01: printf("FB_VISUAL_MONO01 (0)\n"); break;
139 case FB_VISUAL_MONO10: printf("FB_VISUAL_MONO10 (1)\n"); break;
140 case FB_VISUAL_TRUECOLOR: printf("FB_VISUAL_TRUECOLOR (2)\n"); break;
141 case FB_VISUAL_PSEUDOCOLOR: printf("FB_VISUAL_PSEUDOCOLOR (3)\n"); break;
142 case FB_VISUAL_DIRECTCOLOR: printf("FB_VISUAL_DIRECTCOLOR (4)\n"); break;
143 case FB_VISUAL_STATIC_PSEUDOCOLOR: printf("FB_VISUAL_STATIC_PSEUDOCOLOR (5)\n"); break;
144 default: printf("UNKNOWN (See /usr/include/linux/fb.h)\n");
145 }
146
147 printf(" xpanstep : %u\n", fscreeninfo.xpanstep);
148 printf(" ypanstep : %u\n", fscreeninfo.ypanstep);
149 printf(" ywrapstep : %u\n", fscreeninfo.ywrapstep);
150 printf(" line_length : %u\n", fscreeninfo.line_length);
151 if ( sizeof(unsigned long) == 4 )
152 {
153 printf(" mmio_start : 0x%08x\n", (unsigned int)fscreeninfo.mmio_start);
154 }
155 else if ( sizeof(unsigned long) == 8 )
156 {
157 union UL64 { uint32_t u32[2]; uint64_t u64; } mmio_start = {.u64=fscreeninfo.mmio_start};
158 printf(" mmio_start : 0x%08x_%08x\n",mmio_start.u32[1],mmio_start.u32[0]);
159 }
160 else
161 {
162 printf("WTF! sizeof(unsigned long) = %d\n",sizeof(unsigned long));
163 }
164 printf(" mmio_len : %u\n", fscreeninfo.mmio_len);
165 printf(" accel : ");
166 switch (fscreeninfo.accel)
167 {
168 case FB_ACCEL_NONE: printf("FB_ACCEL_NONE (0)\n"); break;
169 case FB_ACCEL_ATARIBLITT: printf("FB_ACCEL_ATARIBLITT (1)\n"); break;
170 case FB_ACCEL_AMIGABLITT: printf("FB_ACCEL_AMIGABLITT (2)\n"); break;
171 case FB_ACCEL_S3_TRIO64: printf("FB_ACCEL_S3_TRIO64 (3)\n"); break;
172 case FB_ACCEL_NCR_77C32BLT: printf("FB_ACCEL_NCR_77C32BLT (4)\n"); break;
173 case FB_ACCEL_S3_VIRGE: printf("FB_ACCEL_S3_VIRGE (5)\n"); break;
174 case FB_ACCEL_ATI_MACH64GX: printf("FB_ACCEL_ATI_MACH64GX (6)\n"); break;
175 case FB_ACCEL_DEC_TGA: printf("FB_ACCEL_DEC_TGA (7)\n"); break;
176 case FB_ACCEL_ATI_MACH64CT: printf("FB_ACCEL_ATI_MACH64CT (8)\n"); break;
177 case FB_ACCEL_ATI_MACH64VT: printf("FB_ACCEL_ATI_MACH64VT (9)\n"); break;
178 case FB_ACCEL_ATI_MACH64GT: printf("FB_ACCEL_ATI_MACH64GT (10)\n"); break;
179 case FB_ACCEL_SUN_CREATOR: printf("FB_ACCEL_SUN_CREATOR (11)\n"); break;
180 case FB_ACCEL_SUN_CGSIX: printf("FB_ACCEL_SUN_CGSIX (12)\n"); break;
181 case FB_ACCEL_SUN_LEO: printf("FB_ACCEL_SUN_LEO (13)\n"); break;
182 case FB_ACCEL_IMS_TWINTURBO: printf("FB_ACCEL_IMS_TWINTURBO (14)\n"); break;
183 case FB_ACCEL_3DLABS_PERMEDIA2: printf("FB_ACCEL_3DLABS_PERMEDIA2 (15)\n"); break;
184 case FB_ACCEL_MATROX_MGA2064W: printf("FB_ACCEL_MATROX_MGA2064W (16)\n"); break;
185 case FB_ACCEL_MATROX_MGA1064SG: printf("FB_ACCEL_MATROX_MGA1064SG (17)\n"); break;
186 case FB_ACCEL_MATROX_MGA2164W: printf("FB_ACCEL_MATROX_MGA2164W (18)\n"); break;
187 case FB_ACCEL_MATROX_MGA2164W_AGP: printf("FB_ACCEL_MATROX_MGA2164W_AGP (19)\n"); break;
188 case FB_ACCEL_MATROX_MGAG100: printf("FB_ACCEL_MATROX_MGAG100 (20)\n"); break;
189 case FB_ACCEL_MATROX_MGAG200: printf("FB_ACCEL_MATROX_MGAG200 (21)\n"); break;
190 case FB_ACCEL_SUN_CG14: printf("FB_ACCEL_SUN_CG14 (22)\n"); break;
191 case FB_ACCEL_SUN_BWTWO: printf("FB_ACCEL_SUN_BWTWO (23)\n"); break;
192 case FB_ACCEL_SUN_CGTHREE: printf("FB_ACCEL_SUN_CGTHREE (24)\n"); break;
193 case FB_ACCEL_SUN_TCX: printf("FB_ACCEL_SUN_TCX (25)\n"); break;
194 case FB_ACCEL_MATROX_MGAG400: printf("FB_ACCEL_MATROX_MGAG400 (26)\n"); break;
195 case FB_ACCEL_NV3: printf("FB_ACCEL_NV3 (27)\n"); break;
196 case FB_ACCEL_NV4: printf("FB_ACCEL_NV4 (28)\n"); break;
197 case FB_ACCEL_NV5: printf("FB_ACCEL_NV5 (29)\n"); break;
198 case FB_ACCEL_CT_6555x: printf("FB_ACCEL_CT_6555x (30)\n"); break;
199 case FB_ACCEL_3DFX_BANSHEE: printf("FB_ACCEL_3DFX_BANSHEE (31)\n"); break;
200 case FB_ACCEL_ATI_RAGE128: printf("FB_ACCEL_ATI_RAGE128 (32)\n"); break;
201 case FB_ACCEL_IGS_CYBER2000: printf("FB_ACCEL_IGS_CYBER2000 (33)\n"); break;
202 case FB_ACCEL_IGS_CYBER2010: printf("FB_ACCEL_IGS_CYBER2010 (34)\n"); break;
203 case FB_ACCEL_IGS_CYBER5000: printf("FB_ACCEL_IGS_CYBER5000 (35)\n"); break;
204 case FB_ACCEL_SIS_GLAMOUR: printf("FB_ACCEL_SIS_GLAMOUR (36)\n"); break;
205 default: printf("UNKNOWN (See /usr/include/linux/fb.h)\n");
206 }
207 }
208 printf("-------------------------------------\n");
209
210 struct ps3fb_ioctl_res res;
211
212 int ps3_screeninfo_error = ioctl(fb_file, PS3FB_IOCTL_SCREENINFO, (unsigned long)&res);
213
214 if ( ps3_screeninfo_error == -1 )
215 {
216 printf("Warning: PS3FB_IOCTL_SCREENINFO Failed\n");
217 }
218 else
219 {
220 printf("PS3FB_IOCTL_SCREENINFO:\n");
221 printf(" xres : %u\n",res.xres);
222 printf(" yres : %u\n",res.yres);
223 printf(" xoff : %u\n",res.xoff);
224 printf(" yoff : %u\n",res.yoff);
225 printf(" num_frames : %u\n",res.num_frames);
226 }
227 printf("-------------------------------------\n");
228
229 int close_fb_error = close( fb_file );
230
231 if ( close_fb_error == -1 )
232 {
233 printf("Warning: Could not close file handle used for /dev/fb0\n");
234 }
235
236 return (0);
237 }
238