1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
|
/* OpenCP Module Player
* copyright (c) '94-'10 Niklas Beisert <nbeisert@physik.tu-muenchen.de>
*
* Curses console driver
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* revision history: (please note changes here)
* -ss040615 Stian Skjelstad <stian@nixia.no>
* -first release
* -doj040914 Dirk Jagdmann <doj@cubic.org>
* -trust the framebuffers smem_len
* -ss040918 Stian Skjelstad <stian@nixia.no>
* -devfs/kernel 2.6 framebuffer names
*/
#define _CONSOLE_DRIVER
#include "config.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/fb.h>
#include "types.h"
#include "poutput-fb.h"
#include "boot/console.h"
#include "poutput.h"
#include "pfonts.h"
static struct fb_fix_screeninfo fix;
static struct fb_var_screeninfo orgmode;
static struct fb_var_screeninfo lowres;
static struct fb_var_screeninfo highres;
static struct fb_cmap colormap;
static uint16_t red[256]= {0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, 0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff};
static uint16_t green[256]={0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa, 0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff};
static uint16_t blue[256]= {0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff};
static int fd;
static char *fbmem;
static int get_static_info(void)
{
if (ioctl(fd, FBIOGET_FSCREENINFO, &fix))
{
perror("fb: ioctl(1, FBIOGET_FSCREENINFO, &fix)");
return -1;
}
return 0;
}
static void show_cursor(void)
{
#ifdef FBIOGET_CURSORSTATE
struct fb_cursorstate cur;
if (ioctl(fd, FBIOGET_CURSORSTATE, &cur, sizeof(cur)))
{
perror("fb: ioctl(1, FBIOGET_CURSORSTATE, &cursor)");
return;
}
cur.mode=FB_CURSOR_FLASH;
if (ioctl(fd, FBIOPUT_CURSORSTATE, &cur, sizeof(cur)))
{
perror("fb: ioctl(1, FBIOPUT_CURSORSTATE, &cursor)");
return;
}
#endif
}
static void hide_cursor(void)
{
#ifdef FBIOGET_CURSORSTATE
struct fb_cursorstate cur;
if (ioctl(fd, FBIOGET_CURSORSTATE, &cur))
{
perror("fb: ioctl(1, FBIOGET_CURSORSTATE, &cursor)");
return;
}
cur.mode=FB_CURSOR_OFF;
if (ioctl(fd, FBIOPUT_CURSORSTATE, &cur))
{
perror("fb: ioctl(1, FBIOGET_CURSORSTATE, &cursor)");
return;
}
#endif
}
static int test_mode(struct fb_var_screeninfo *info)
{
int old;
old=info->activate;
info->activate=FB_ACTIVATE_TEST;
if (ioctl(fd, FBIOPUT_VSCREENINFO, info))
{
perror("fb: ioctl(1, FBIOPUT_VSCREENINFO, info)");
info->activate=old;
return -1;
}
info->activate=old;
return 0;
}
static void __gupdatepal(unsigned char color, unsigned char _red, unsigned char _green, unsigned char _blue)
{
red[color]=_red<<10;
green[color]=_green<<10;
blue[color]=_blue<<10;
}
static void __gflushpal(void)
{
if (ioctl(fd, FBIOPUTCMAP, &colormap))
perror("fb: ioctl(fb, FBIOGETCMAP, &colormap)");
}
static int __plSetGraphMode(int high)
{
/*
struct fb_fix_screeninfo fix2;
*/
#ifdef DEBUG_FRAMEBUFFER
if (high==-1)
fprintf(stderr, "fb: set normale mode\n");
else if (high)
fprintf(stderr, "fb: set 1024x768\n");
else
fprintf(stderr, "fb: set 640x480\n");
#endif
if (high==-1)
{
plVidMem=0;
ioctl(fd, FBIOPUT_VSCREENINFO, &orgmode);
return 0;
}
if (high)
{
if (!highres.xres)
return -1;
plScrMode=101;
plScrWidth=128;
plScrHeight=60;
ioctl(fd, FBIOPUT_VSCREENINFO, &highres);
plScrLineBytes=1024; /* not good, but my framebuffer bugs to much */
} else {
if (!lowres.xres)
return -1;
plScrMode=100;
plScrWidth=80;
plScrHeight=60;
ioctl(fd, FBIOPUT_VSCREENINFO, &lowres);
plScrLineBytes=640; /* not good, but my framebuffer bugs to much */
}
plVidMem=fbmem;
memset(fbmem, 0, fix.smem_len);
colormap.start=0;
colormap.len=256;
colormap.red=red;
colormap.green=green;
colormap.blue=blue;
/* Since some framebuffer-drivers fails give out the current palette with the bits scaled correct, we can't really
* use the FBIOGETCMAP. That sucks!
if (ioctl(fd, FBIOGETCMAP, &colormap))
perror("fb: ioctl(fb, FBIOGETCMAP, &colormap)");
* And tridentfb atleast is broken when reporting fix.line_length... hehe.. FUCK that driver!!!!
if (ioctl(fd, FBIOGET_FSCREENINFO, &fix2))
perror("fb: ioctl(1, FBIOGET_FSCREENINFO, &fix)");
fix2.line_length=fix.line_length;
fprintf(stderr, "DEBUG LINES: current %d, org %d, new %d\n", plScrLineBytes, fix.line_length, fix2.line_length);
plScrLineBytes=fix2.line_length;
*/
return 0;
}
int fb_init(int minor)
{
struct fb_var_screeninfo var2;
char *temp;
memset(&lowres, 0, sizeof(lowres));
memset(&lowres, 0, sizeof(highres));
if ((temp=getenv("FRAMEBUFFER")))
{
if ((fd=open(temp, O_RDWR))<0)
{
perror("fb: open($FRAMEBUFFER)");
return -1;
}
} else {
if ((fd=open("/dev/fb", O_RDWR))<0)
{
perror("fb: open(/dev/fb)");
if ((fd=open("/dev/fb/0", O_RDWR))<0)
{
perror("fb: open(/dev/fb/0)");
return -1;
}
}
}
if (get_static_info())
{
close(fd);
fd=-1;
return -1;
}
plScrLineBytes=fix.line_length;
#ifdef VERBOSE_FRAMEBUFFER
fprintf(stderr, "fb: FIX SCREEN INFO\n");
fprintf(stderr, "fb: id=%s\n", fix.id);
fprintf(stderr, "fb: smem_start=0x%08lx\n", fix.smem_start);
fprintf(stderr, "fb: smem_len=0x%08x\n", fix.smem_len);
fprintf(stderr, "fb: stype=");
switch (fix.type)
{
case FB_TYPE_PACKED_PIXELS:
fprintf(stderr, "Packed Pixels\n");
break;
case FB_TYPE_PLANES:
fprintf(stderr, "Non interleaved planes\n");
break;
case FB_TYPE_INTERLEAVED_PLANES:
fprintf(stderr, "Interleaved planes\n");
break;
case FB_TYPE_TEXT:
fprintf(stderr, "Text/attributes\nfb: type_aux=");
switch (fix.type_aux)
{
case FB_AUX_TEXT_MDA:
fprintf(stderr, "Monochrome text\n");
break;
case FB_AUX_TEXT_CGA:
fprintf(stderr, "CGA/EGA/VGA Color text\n");
break;
case FB_AUX_TEXT_S3_MMIO:
fprintf(stderr, "S3 MMIO fasttext\n");
break;
case FB_AUX_TEXT_MGA_STEP16:
fprintf(stderr, "MGA Millenium I: text, attr, 14 reserved bytes\n");
break;
case FB_AUX_TEXT_MGA_STEP8:
fprintf(stderr, "other MGAs: text, attr, 6 reserved bytes\n");
break;
default:
fprintf(stderr, "Unknown\n");
}
break;
case FB_TYPE_VGA_PLANES:
fprintf(stderr, "EGA/VGA planes\nfb: type_aux=");
switch (fix.type_aux)
{
case FB_AUX_VGA_PLANES_VGA4:
fprintf(stderr, "16 color planes (EGA/VGA)\n");
break;
case FB_AUX_VGA_PLANES_CFB4:
fprintf(stderr, "CFB4 in planes (VGA)\n");
break;
case FB_AUX_VGA_PLANES_CFB8:
fprintf(stderr, "CFB8 in planes (VGA)\n");
break;
default:
fprintf(stderr, "Unknown\n");
}
break;
default:
fprintf(stderr, "Unknown\n");
break;
}
fprintf(stderr, "fb: visual=");
switch (fix.visual)
{
case FB_VISUAL_MONO01:
fprintf(stderr, "Monochr. 1=Black 0=White\n");
break;
case FB_VISUAL_MONO10:
fprintf(stderr, "Monochr. 1=White 0=Black\n");
break;
case FB_VISUAL_TRUECOLOR:
fprintf(stderr, "True color\n");
break;
case FB_VISUAL_PSEUDOCOLOR:
fprintf(stderr, "Pseudo color (like atari)\n");
break;
case FB_VISUAL_DIRECTCOLOR:
fprintf(stderr, "Direct color\n");
break;
case FB_VISUAL_STATIC_PSEUDOCOLOR:
fprintf(stderr, "Pseudo color readonly\n");
break;
default:
fprintf(stderr, "Unknown\n");
}
fprintf(stderr, "fb: xpanstep=");
if (fix.xpanstep)
fprintf(stderr, "%d\n", fix.xpanstep);
else
fprintf(stderr, "Not supported\n");
fprintf(stderr, "fb: ypanstep=");
if (fix.ypanstep)
fprintf(stderr, "%d\n", fix.ypanstep);
else
fprintf(stderr, "Not supported\n");
fprintf(stderr, "fb: ywrapstep=");
if (fix.ywrapstep)
fprintf(stderr, "%d\n", fix.ywrapstep);
else
fprintf(stderr, "Not supported\n");
fprintf(stderr, "fb: line_length=%d\n", fix.line_length);
fprintf(stderr, "fb: mmio_start=0x%08lx\n", fix.mmio_start);
fprintf(stderr, "fb: mmio_len=0x%08x\n", fix.mmio_len);
fprintf(stderr, "fb: accel=%d\n", fix.accel);
fprintf(stderr, "fb: reserved0=0x%04x reserved1=0x%04x reserved2=0x%04x\n", fix.reserved[0], fix.reserved[1], fix.reserved[2]);
#endif
if (ioctl(fd, FBIOGET_VSCREENINFO, &orgmode))
{
perror("fb: ioctl(1, FBIOGET_VSCREENINFO, &orgmode)");
close(fd);
fd=-1;
return -1;
}
orgmode.activate=FB_ACTIVATE_NOW;
#if VERBOSE_FRAMEBUFFER
fprintf(stderr, "VAR SCREEN INFO\n");
fprintf(stderr, "xres=%d\n", orgmode.xres);
fprintf(stderr, "yres=%d\n", orgmode.yres);
fprintf(stderr, "xres_virtual=%d\n", orgmode.xres_virtual);
fprintf(stderr, "yres_virtual=%d\n", orgmode.yres_virtual);
fprintf(stderr, "xoffset=%d\n", orgmode.xoffset);
fprintf(stderr, "yoffsett=%d\n", orgmode.yoffset);
fprintf(stderr, "bits_per_pixel=%d\n", orgmode.bits_per_pixel);
fprintf(stderr, "grayscale=%d\n", orgmode.grayscale);
/* R, G, B, Alpha goes here */
fprintf(stderr, "nonstd=%d\n", orgmode.nonstd);
fprintf(stderr, "(activate=%d)\n", orgmode.activate);
/* height / width goes here */
/* accel flags goes here */
#endif
var2.xres=var2.xres_virtual=640;
var2.yres=var2.yres_virtual=480;
var2.xoffset=var2.yoffset=0;
var2.bits_per_pixel=8;
var2.grayscale=0;
var2.nonstd=0;
var2.height=orgmode.height;
var2.width=orgmode.width;
var2.accel_flags=0;
var2.pixclock=32052;
var2.left_margin=128;
var2.right_margin=24;
var2.upper_margin=28;
var2.lower_margin=9;
var2.hsync_len=40;
var2.vsync_len=3;
var2.sync=orgmode.sync;
var2.vmode=0;
if (test_mode(&var2))
{
memcpy(&var2, &orgmode, sizeof(orgmode));
var2.activate=FB_ACTIVATE_TEST;
} else {
var2.activate=FB_ACTIVATE_NOW;
}
if ((var2.xres==640)&&(var2.yres==480))
{
fprintf(stderr, "fb: 640x480 is available\n");
memcpy(&lowres, &var2, sizeof(var2));
} else
fprintf(stderr, "fb: 640x480 is not available\n");
var2.xres=var2.xres_virtual=1024;
var2.yres=var2.yres_virtual=768;
var2.xoffset=var2.yoffset=0;
var2.bits_per_pixel=8;
var2.grayscale=0;
var2.nonstd=0;
var2.height=orgmode.height;
var2.width=orgmode.width;
var2.accel_flags=0;
var2.pixclock=15385;
var2.left_margin=160;
var2.right_margin=24;
var2.upper_margin=29;
var2.lower_margin=3;
var2.hsync_len=136;
var2.vsync_len=6;
var2.sync=orgmode.sync;
var2.vmode=0;
if (test_mode(&var2))
{
memcpy(&var2, &orgmode, sizeof(orgmode));
var2.activate=FB_ACTIVATE_TEST;
} else {
var2.activate=FB_ACTIVATE_NOW;
}
if ((var2.xres==1024)&&(var2.yres==768))
{
fprintf(stderr, "fb: 1024x768 is available\n");
memcpy(&highres, &var2, sizeof(var2));
} else
fprintf(stderr, "fb: 1024x768 is not available\n");
if ((!highres.xres)&&(!lowres.xres))
{
close(fd);
fd=-1;
return -1;
}
if ((fbmem=mmap(0, fix.smem_len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0))==MAP_FAILED)
{
perror("fb: mmap()");
close(fd);
fd=-1;
return -1;
}
_plSetGraphMode=__plSetGraphMode;
_gdrawstr=generic_gdrawstr;
_gdrawchar8=generic_gdrawchar8;
_gdrawchar8p=generic_gdrawchar8p;
_gdrawchar8t=generic_gdrawchar8t;
_gdrawcharp=generic_gdrawcharp;
_gdrawchar=generic_gdrawchar;
_gupdatestr=generic_gupdatestr;
_gupdatepal=__gupdatepal;
_gflushpal=__gflushpal;
hide_cursor();
plVidType=vidVESA;
return 0;
}
void fb_done(void)
{
show_cursor();
munmap(fbmem, fix.smem_len);
if (fd<0)
return;
ioctl(fd, FBIOPUT_VSCREENINFO, &orgmode);
close(fd);
fd=-1;
}
|