source: rtems/c/src/lib/libbsp/i386/pc386/console/fb_vga.c @ 364e8918

4.115
Last change on this file since 364e8918 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Copyright (c) 2000 - Rosimildo da Silva ( rdasilva@connecttel.com )
3 *
4 * MODULE DESCRIPTION:
5 * This module implements FB driver for "Bare VGA". It uses the
6 * routines for "bare hardware" found in vgainit.c.
7 *
8 */
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <errno.h>
13#include <sys/types.h>
14#include <pthread.h>
15
16#include <bsp.h>
17#include <bsp/irq.h>
18#include <rtems/libio.h>
19
20#include <rtems/fb.h>
21
22/* these routines are defined in vgainit.c.*/
23extern void ega_hwinit( void );
24extern void ega_hwterm( void );
25
26/* mutex attribure */
27pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
28
29/* screen information for the VGA driver */
30static struct fb_var_screeninfo fb_var =
31{
32  .xres                = 640,
33  .yres                = 480,
34  .bits_per_pixel      = 4
35};
36
37static struct fb_fix_screeninfo fb_fix =
38{
39  .smem_start          = (volatile char *)0xA0000,     /* buffer pointer    */
40  .smem_len            = 0x10000,                      /* buffer size       */
41  .type                = FB_TYPE_VGA_PLANES,           /* type of dsplay    */
42  .visual              = FB_VISUAL_PSEUDOCOLOR,        /* color scheme used */
43  .line_length         = 80                            /* chars per line    */
44};
45
46
47static uint16_t red16[] = {
48   0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa,
49   0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff
50};
51static uint16_t green16[] = {
52   0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa,
53   0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff
54};
55static uint16_t blue16[] = {
56   0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa,
57   0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff
58};
59
60/* Functionality to support multiple VGA frame buffers can be added easily,
61 * but is not supported at this moment because there is no need for two or
62 * more "classic" VGA adapters.  Multiple frame buffer drivers may be
63 * implemented and If we had implement it they would be named as "/dev/fb0",
64 * "/dev/fb1", "/dev/fb2" and so on.
65 */
66/*
67 * fbvga device driver INITIALIZE entry point.
68 */
69rtems_device_driver frame_buffer_initialize(
70  rtems_device_major_number  major,
71  rtems_device_minor_number  minor,
72  void                      *arg
73)
74{
75  rtems_status_code status;
76
77  printk( "FBVGA -- driver initializing..\n" );
78
79  /*
80   * Register the device
81   */
82  status = rtems_io_register_name ("/dev/fb0", major, 0);
83  if (status != RTEMS_SUCCESSFUL) {
84    printk("Error registering /dev/fb0 FBVGA framebuffer device!\n");
85    rtems_fatal_error_occurred( status );
86  }
87
88  return RTEMS_SUCCESSFUL;
89}
90
91/*
92 * fbvga device driver OPEN entry point
93 */
94rtems_device_driver frame_buffer_open(
95  rtems_device_major_number  major,
96  rtems_device_minor_number  minor,
97  void                      *arg
98)
99{
100  if (pthread_mutex_trylock(&mutex)== 0){
101      /* restore previous state.  for VGA this means return to text mode.
102       * leave out if graphics hardware has been initialized in
103       * frame_buffer_initialize()
104       */
105      ega_hwinit();
106      printk( "FBVGA open called.\n" );
107      return RTEMS_SUCCESSFUL;
108  }
109
110  return RTEMS_UNSATISFIED;
111}
112
113/*
114 * fbvga device driver CLOSE entry point
115 */
116rtems_device_driver frame_buffer_close(
117  rtems_device_major_number  major,
118  rtems_device_minor_number  minor,
119  void                      *arg
120)
121{
122  if (pthread_mutex_unlock(&mutex) == 0){
123    /* restore previous state.  for VGA this means return to text mode.
124     * leave out if graphics hardware has been initialized in
125     * frame_buffer_initialize() */
126    ega_hwterm();
127    printk( "FBVGA close called.\n" );
128    return RTEMS_SUCCESSFUL;
129  }
130
131  return RTEMS_UNSATISFIED;
132}
133
134/*
135 * fbvga device driver READ entry point.
136 */
137rtems_device_driver frame_buffer_read(
138  rtems_device_major_number  major,
139  rtems_device_minor_number  minor,
140  void                      *arg
141)
142{
143  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
144  rw_args->bytes_moved = ((rw_args->offset + rw_args->count) > fb_fix.smem_len ) ? (fb_fix.smem_len - rw_args->offset) : rw_args->count;
145  memcpy(rw_args->buffer, (const void *) (fb_fix.smem_start + rw_args->offset), rw_args->bytes_moved);
146  return RTEMS_SUCCESSFUL;
147}
148
149/*
150 * frame_buffer device driver WRITE entry point.
151 */
152rtems_device_driver frame_buffer_write(
153  rtems_device_major_number  major,
154  rtems_device_minor_number  minor,
155  void                      *arg
156)
157{
158  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
159  rw_args->bytes_moved = ((rw_args->offset + rw_args->count) > fb_fix.smem_len ) ? (fb_fix.smem_len - rw_args->offset) : rw_args->count;
160  memcpy( (void *) (fb_fix.smem_start + rw_args->offset), rw_args->buffer, rw_args->bytes_moved);
161  return RTEMS_SUCCESSFUL;
162}
163
164static int get_fix_screen_info( struct fb_fix_screeninfo *info )
165{
166  *info = fb_fix;
167  return 0;
168}
169
170static int get_var_screen_info( struct fb_var_screeninfo *info )
171{
172  *info =  fb_var;
173  return 0;
174}
175
176static int get_palette( struct fb_cmap *cmap )
177{
178  uint32_t i;
179
180  if ( cmap->start + cmap->len >= 16 )
181    return 1;
182
183  for( i = 0; i < cmap->len; i++ ) {
184    cmap->red[ cmap->start + i ]   = red16[ cmap->start + i ];
185    cmap->green[ cmap->start + i ] = green16[ cmap->start + i ];
186    cmap->blue[ cmap->start + i ]  = blue16[ cmap->start + i ];
187  }
188  return 0;
189}
190
191static int set_palette( struct fb_cmap *cmap )
192{
193  uint32_t i;
194
195  if ( cmap->start + cmap->len >= 16 )
196    return 1;
197
198  for( i = 0; i < cmap->len; i++ ) {
199    red16[ cmap->start + i ] = cmap->red[ cmap->start + i ];
200    green16[ cmap->start + i ] = cmap->green[ cmap->start + i ];
201    blue16[ cmap->start + i ] = cmap->blue[ cmap->start + i ];
202  }
203  return 0;
204}
205
206/*
207 * IOCTL entry point -- This method is called to carry
208 * all services of this interface.
209 */
210rtems_device_driver frame_buffer_control(
211  rtems_device_major_number  major,
212  rtems_device_minor_number  minor,
213  void                      *arg
214)
215{
216  rtems_libio_ioctl_args_t *args = arg;
217
218  printk( "FBVGA ioctl called, cmd=%x\n", args->command  );
219
220  switch( args->command ) {
221    case FBIOGET_FSCREENINFO:
222      args->ioctl_return =  get_fix_screen_info( ( struct fb_fix_screeninfo * ) args->buffer );
223      break;
224    case FBIOGET_VSCREENINFO:
225      args->ioctl_return =  get_var_screen_info( ( struct fb_var_screeninfo * ) args->buffer );
226      break;
227    case FBIOPUT_VSCREENINFO:
228      /* not implemented yet*/
229      args->ioctl_return = -1;
230      return RTEMS_UNSATISFIED;
231    case FBIOGETCMAP:
232      args->ioctl_return =  get_palette( ( struct fb_cmap * ) args->buffer );
233      break;
234    case FBIOPUTCMAP:
235      args->ioctl_return =  set_palette( ( struct fb_cmap * ) args->buffer );
236      break;
237
238    default:
239     args->ioctl_return = 0;
240     break;
241  }
242  return RTEMS_SUCCESSFUL;
243}
Note: See TracBrowser for help on using the repository browser.