Changeset 573e3b2 in rtems for c/src/lib


Ignore:
Timestamp:
Aug 21, 2009, 6:35:28 PM (11 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 5, master
Children:
4d06315
Parents:
a3a6fae
Message:

2009-08-21 Roxana Leontie <roxana.leontie@…>

  • pc386/console/fb_vga.c: added read/write functionality; added thread safety to prevent multiple open() operations of the frame buffer device.
Location:
c/src/lib/libbsp/i386/pc386
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/i386/pc386/ChangeLog

    ra3a6fae r573e3b2  
     12009-08-21      Roxana Leontie <roxana.leontie@gmail.com>
     2
     3        * pc386/console/fb_vga.c: added read/write functionality; added thread
     4        safety to prevent multiple open() operations of the frame buffer device.
     5
    162009-08-21      Joel Sherrill <joel.sherrill@OARcorp.com>
    27
  • c/src/lib/libbsp/i386/pc386/console/fb_vga.c

    ra3a6fae r573e3b2  
    33 *
    44 * MODULE DESCRIPTION:
    5  * This module implements the micro FB driver for "Bare VGA". It uses the
    6  * routines for "bare hardware" that comes with MicroWindows.
     5 * This module implements FB driver for "Bare VGA". It uses the
     6 * routines for "bare hardware" found in vgainit.c.
    77 *
    88 *  $Id$
     
    1414#include <errno.h>
    1515#include <sys/types.h>
     16#include <pthread.h>
    1617
    1718#include <bsp.h>
     
    2122#include <rtems/fb.h>
    2223
    23 /* these routines are defined in the microwindows code. This
    24    driver is here more as an example of how to implement and
    25    use the micro FB interface
    26 */
     24/* these routines are defined in vgainit.c.*/
    2725extern void ega_hwinit( void );
    2826extern void ega_hwterm( void );
     27
     28/* mutex attribure */
     29pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    2930
    3031/* screen information for the VGA driver */
     
    4546};
    4647
     48
    4749static uint16_t red16[] = {
    4850   0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa,
     
    5860};
    5961
     62/* Functionality to support multiple VGA frame buffers can be added easily,
     63 * but is not supported at this moment because there is no need for two or
     64 * more "classic" VGA adapters.  Multiple frame buffer drivers may be
     65 * implemented and If we had implement it they would be named as "/dev/fb0",
     66 * "/dev/fb1", "/dev/fb2" and so on.
     67 */
    6068/*
    6169 * fbvga device driver INITIALIZE entry point.
     
    7684  status = rtems_io_register_name ("/dev/fb0", major, 0);
    7785  if (status != RTEMS_SUCCESSFUL) {
    78     printk("Error registering FBVGA device!\n");
     86    printk("Error registering /dev/fb0 FBVGA framebuffer device!\n");
    7987    rtems_fatal_error_occurred( status );
    8088  }
    81 
     89 
    8290  return RTEMS_SUCCESSFUL;
    8391}
     
    92100)
    93101{
    94   ega_hwinit();
    95   printk( "FBVGA open called.\n" );
    96 
    97   return RTEMS_SUCCESSFUL;
     102  if (pthread_mutex_trylock(&mutex)== 0){
     103      /* restore previous state.  for VGA this means return to text mode.
     104       * leave out if graphics hardware has been initialized in
     105       * frame_buffer_initialize()
     106       */
     107      ega_hwinit();
     108      printk( "FBVGA open called.\n" );     
     109      return RTEMS_SUCCESSFUL;
     110  }
     111 
     112  return RTEMS_UNSATISFIED;
    98113}
    99114
     
    107122)
    108123{
    109   ega_hwterm();
    110   printk( "FBVGA close called.\n" );
    111 
    112   return RTEMS_SUCCESSFUL;
     124  if (pthread_mutex_unlock(&mutex) == 0){
     125    /* restore previous state.  for VGA this means return to text mode.
     126     * leave out if graphics hardware has been initialized in
     127     * frame_buffer_initialize() */
     128    ega_hwterm();
     129    printk( "FBVGA close called.\n" );
     130    return RTEMS_SUCCESSFUL;
     131  }
     132
     133  return RTEMS_UNSATISFIED;
    113134}
    114135
    115136/*
    116137 * fbvga device driver READ entry point.
    117  * Read characters from the PS/2 mouse.
    118138 */
    119139rtems_device_driver frame_buffer_read(
     
    123143)
    124144{
     145  /*printk( "FBVGA read called.\n" );*/
    125146  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
    126 
    127   printk( "FBVGA read called.\n" );
    128 
    129   rw_args->bytes_moved = 0;
    130 
    131   return RTEMS_SUCCESSFUL;
     147  if ( (rw_args->offset >= fb_fix.smem_len) || (rw_args->count < 0) ){
     148     return RTEMS_UNSATISFIED;
     149  }
     150  else
     151  {
     152        /*partial reading*/
     153        if ( (rw_args->offset + rw_args->count) > fb_fix.smem_len ){
     154           rw_args->count = fb_fix.smem_len - rw_args->offset;
     155           memcpy(rw_args->buffer, (const void *) (rw_args->offset + fb_fix.smem_start), rw_args->count);
     156           rw_args->bytes_moved = rw_args->count;
     157           return RTEMS_SUCCESSFUL;
     158        }
     159        /*best reading case*/
     160        else{
     161           memcpy(rw_args->buffer, (const void *) (rw_args->offset + fb_fix.smem_start), rw_args->count);
     162           rw_args->bytes_moved = rw_args->count;
     163           return RTEMS_SUCCESSFUL;
     164        }
     165   }     
    132166}
    133167
    134168/*
    135169 * frame_buffer device driver WRITE entry point.
    136  * Write characters to the PS/2 mouse.
    137170 */
    138171rtems_device_driver frame_buffer_write(
     
    142175)
    143176{
     177  /*printk( "FBVGA write called.\n" );*/
    144178  rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
    145 
    146   printk( "FBVGA write called.\n" );
    147   rw_args->bytes_moved = 0;
    148   return RTEMS_SUCCESSFUL;
     179  if ( (rw_args->offset >= fb_fix.smem_len) || (rw_args->count < 0) ){
     180     return RTEMS_UNSATISFIED;
     181  }
     182  else
     183  {
     184        /*partial writing*/
     185        if ( (rw_args->offset + rw_args->count) > fb_fix.smem_len ){
     186           rw_args->count = fb_fix.smem_len - rw_args->offset;
     187           memcpy( (void *) (rw_args->offset + fb_fix.smem_start), rw_args->buffer, rw_args->count);
     188           rw_args->bytes_moved = rw_args->count;
     189           return RTEMS_SUCCESSFUL;
     190        }
     191        /* best writing case*/
     192        else{
     193           memcpy( (void *) (rw_args->offset + fb_fix.smem_start), rw_args->buffer, rw_args->count);
     194           rw_args->bytes_moved = rw_args->count;
     195           return RTEMS_SUCCESSFUL;
     196        }
     197   }         
    149198}
    150199
     
    157206static int get_var_screen_info( struct fb_var_screeninfo *info )
    158207{
    159   *info = fb_var;
     208  *info =  fb_var;
    160209  return 0;
    161210}
     
    207256  switch( args->command ) {
    208257    case FBIOGET_FSCREENINFO:
    209       args->ioctl_return =  get_fix_screen_info( args->buffer );
     258      args->ioctl_return =  get_fix_screen_info( ( struct fb_fix_screeninfo * ) args->buffer );
    210259      break;
    211260    case FBIOGET_VSCREENINFO:
    212       args->ioctl_return =  get_var_screen_info( args->buffer );
     261      args->ioctl_return =  get_var_screen_info( ( struct fb_var_screeninfo * ) args->buffer );
    213262      break;
    214263    case FBIOPUT_VSCREENINFO:
    215264      /* not implemented yet*/
    216       break;
     265      args->ioctl_return = -1;
     266      return RTEMS_UNSATISFIED;
    217267    case FBIOGETCMAP:
    218       args->ioctl_return =  get_palette( args->buffer );
     268      args->ioctl_return =  get_palette( ( struct fb_cmap * ) args->buffer );
    219269      break;
    220270    case FBIOPUTCMAP:
    221       args->ioctl_return =  set_palette( args->buffer );
     271      args->ioctl_return =  set_palette( ( struct fb_cmap * ) args->buffer );
    222272      break;
    223273
Note: See TracChangeset for help on using the changeset viewer.