comparison src/video/fbcon-1.3/SDL_fbvideo.c @ 3159:2632b7453516 gsoc2009_ps3

Added framebuffer mapping.
author Martin Lowinski <martin@goldtopf.org>
date Thu, 12 Nov 2009 21:44:14 +0000
parents 30f3b987fec3
children
comparison
equal deleted inserted replaced
3158:30f3b987fec3 3159:2632b7453516
52 52
53 #define FBVID_DRIVER_NAME "fbcon" 53 #define FBVID_DRIVER_NAME "fbcon"
54 54
55 /* Initialization/Query functions */ 55 /* Initialization/Query functions */
56 static int FB_VideoInit(_THIS); 56 static int FB_VideoInit(_THIS);
57 static int FB_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
58 static void FB_VideoQuit(_THIS); 57 static void FB_VideoQuit(_THIS);
58
59 static int
60 SDL_getpagesize(void)
61 {
62 #ifdef HAVE_GETPAGESIZE
63 return getpagesize();
64 #elif defined(PAGE_SIZE)
65 return PAGE_SIZE;
66 #else
67 #error Can not determine system page size.
68 /* this is what it USED to be in Linux... */
69 return 4096;
70 #endif
71 }
72
73
74 /* Small wrapper for mmap() so we can play nicely with no-mmu hosts
75 * (non-mmu hosts disallow the MAP_SHARED flag) */
76 static void *
77 do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
78 {
79 void *ret;
80 ret = mmap(start, length, prot, flags, fd, offset);
81 if (ret == (char *) -1 && (flags & MAP_SHARED)) {
82 ret = mmap(start, length, prot,
83 (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
84 }
85 return ret;
86 }
59 87
60 /* bootstrap functions */ 88 /* bootstrap functions */
61 static int 89 static int
62 FB_Available(void) 90 FB_Available(void)
63 { 91 {
131 159
132 deprintf(1, "-FB_CreateDevice()\n"); 160 deprintf(1, "-FB_CreateDevice()\n");
133 return device; 161 return device;
134 } 162 }
135 163
136 VideoBootStrap FB_bootstrap = { 164 VideoBootStrap FBCON_bootstrap = {
137 FBVID_DRIVER_NAME, "Linux framebuffer video driver", 165 FBVID_DRIVER_NAME, "Linux framebuffer video driver",
138 FB_Available, FB_CreateDevice 166 FB_Available, FB_CreateDevice
139 }; 167 };
140 168
141 int 169 int
144 deprintf(1, "+FB_VideoInit()\n"); 172 deprintf(1, "+FB_VideoInit()\n");
145 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 173 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
146 SDL_DisplayMode mode; 174 SDL_DisplayMode mode;
147 struct fb_fix_screeninfo finfo; 175 struct fb_fix_screeninfo finfo;
148 const char *SDL_fbdev; 176 const char *SDL_fbdev;
177 const int pagesize = SDL_getpagesize();
149 178
150 /* Initialize the library */ 179 /* Initialize the library */
151 SDL_fbdev = SDL_getenv("SDL_FBDEV"); 180 SDL_fbdev = SDL_getenv("SDL_FBDEV");
152 if (SDL_fbdev == NULL) { 181 if (SDL_fbdev == NULL) {
153 SDL_fbdev = "/dev/fb0"; 182 SDL_fbdev = "/dev/fb0";
154 } 183 }
184 /* Open the device */
155 data->console_fd = open(SDL_fbdev, O_RDWR, 0); 185 data->console_fd = open(SDL_fbdev, O_RDWR, 0);
156 if (data->console_fd < 0) { 186 if (data->console_fd < 0) {
157 SDL_SetError("Unable to open %s", SDL_fbdev); 187 SDL_SetError("Unable to open %s", SDL_fbdev);
158 return -1; 188 return -1;
159 } 189 }
168 #endif 198 #endif
169 199
170 /* Get the type of video hardware */ 200 /* Get the type of video hardware */
171 if (ioctl(data->console_fd, FBIOGET_FSCREENINFO, &finfo) < 0) { 201 if (ioctl(data->console_fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
172 SDL_SetError("Couldn't get console hardware info"); 202 SDL_SetError("Couldn't get console hardware info");
203 FB_VideoQuit(_this);
204 return -1;
205 }
206
207 switch (finfo.visual) {
208 case FB_VISUAL_TRUECOLOR:
209 case FB_VISUAL_PSEUDOCOLOR:
210 case FB_VISUAL_STATIC_PSEUDOCOLOR:
211 case FB_VISUAL_DIRECTCOLOR:
212 break;
213 default:
214 SDL_SetError("Unsupported console hardware");
215 FB_VideoQuit(_this);
216 return -1;
217 }
218
219 /* Check if the user wants to disable hardware acceleration
220 * FIXME: Maybe better in fbrenderer? */
221 {
222 const char *fb_accel;
223 fb_accel = SDL_getenv("SDL_FBACCEL");
224 if (fb_accel) {
225 finfo.accel = SDL_atoi(fb_accel);
226 }
227 }
228
229 /* Memory map the device, compensating for buggy PPC mmap() */
230 data->mapped_offset = (((long) finfo.smem_start) -
231 (((long) finfo.smem_start) & ~(pagesize - 1)));
232 data->mapped_memlen = finfo.smem_len + data->mapped_offset;
233 data->mapped_mem = (char*) do_mmap(NULL, data->mapped_memlen,
234 PROT_READ | PROT_WRITE, MAP_SHARED, data->console_fd, 0);
235 if (data->mapped_mem == (char *) -1) {
236 SDL_SetError("Unable to memory map the video hardware");
237 data->mapped_mem = NULL;
173 FB_VideoQuit(_this); 238 FB_VideoQuit(_this);
174 return -1; 239 return -1;
175 } 240 }
176 241
177 /* Use a fake 32-bpp desktop mode */ 242 /* Use a fake 32-bpp desktop mode */
189 /* We're done! */ 254 /* We're done! */
190 deprintf(1, "-FB_VideoInit()\n"); 255 deprintf(1, "-FB_VideoInit()\n");
191 return 0; 256 return 0;
192 } 257 }
193 258
194 static int
195 FB_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
196 {
197 deprintf(1, "+FB_SetDisplayMode()\n");
198 deprintf(1, "-FB_SetDisplayMode()\n");
199 return 0;
200 }
201
202 void 259 void
203 FB_VideoQuit(_THIS) 260 FB_VideoQuit(_THIS)
204 { 261 {
205 deprintf(1, "+FB_VideoQuit()\n"); 262 deprintf(1, "+FB_VideoQuit()\n");
263 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
264
265 /* Clear the lock mutex */
266 if (data->hw_lock) {
267 SDL_DestroyMutex(data->hw_lock);
268 data->hw_lock = NULL;
269 }
270
271 /* Close console and input file descriptors */
272 if (data->console_fd > 0) {
273 /* Unmap the video framebuffer and I/O registers */
274 if (data->mapped_mem) {
275 munmap(data->mapped_mem, data->mapped_memlen);
276 data->mapped_mem = NULL;
277 }
278
279 /* We're all done with the framebuffer */
280 close(data->console_fd);
281 data->console_fd = -1;
282 }
283
206 deprintf(1, "-FB_VideoQuit()\n"); 284 deprintf(1, "-FB_VideoQuit()\n");
207 } 285 }
208 286