Home | History | Annotate | Download | only in ps3
      1 /*
      2  * SDL - Simple DirectMedia Layer
      3  * CELL BE Support for PS3 Framebuffer
      4  * Copyright (C) 2008, 2009 International Business Machines Corporation
      5  *
      6  * This library is free software; you can redistribute it and/or modify it
      7  * under the terms of the GNU Lesser General Public License as published
      8  * by the Free Software Foundation; either version 2.1 of the License, or
      9  * (at your option) any later version.
     10  *
     11  * This library is distributed in the hope that it will be useful, but
     12  * WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Lesser General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Lesser General Public
     17  * License along with this library; if not, write to the Free Software
     18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
     19  * USA
     20  *
     21  *  Martin Lowinski  <lowinski [at] de [dot] ibm [ibm] com>
     22  *  Dirk Herrendoerfer <d.herrendoerfer [at] de [dot] ibm [dot] com>
     23  *  SPE code based on research by:
     24  *  Rene Becker
     25  *  Thimo Emmerich
     26  */
     27 
     28 #include "SDL_config.h"
     29 #include "../SDL_sysvideo.h"
     30 #include "SDL_mouse.h"
     31 #include "SDL_mutex.h"
     32 #include "spulibs/spu_common.h"
     33 
     34 #include <libspe2.h>
     35 #include <pthread.h>
     36 #include <linux/types.h>
     37 #include <linux/fb.h>
     38 #include <asm/ps3fb.h>
     39 #include <linux/vt.h>
     40 #include <termios.h>
     41 
     42 #ifndef _SDL_ps3video_h
     43 #define _SDL_ps3video_h
     44 
     45 /* Debugging
     46  * 0: No debug messages
     47  * 1: Video debug messages
     48  * 2: SPE debug messages
     49  * 3: Memory adresses
     50  */
     51 #define DEBUG_LEVEL 0
     52 
     53 #ifdef DEBUG_LEVEL
     54 #define deprintf( level, fmt, args... ) \
     55     do \
     56 { \
     57     if ( (unsigned)(level) <= DEBUG_LEVEL ) \
     58     { \
     59         fprintf( stdout, fmt, ##args ); \
     60         fflush( stdout ); \
     61     } \
     62 } while ( 0 )
     63 #else
     64 #define deprintf( level, fmt, args... )
     65 #endif
     66 
     67 /* Framebuffer device */
     68 #define PS3_DEV_FB "/dev/fb0"
     69 
     70 /* Hidden "this" pointer for the video functions */
     71 #define _THIS   SDL_VideoDevice * this
     72 
     73 /* SPU thread data */
     74 typedef struct spu_data {
     75     spe_context_ptr_t ctx;
     76     pthread_t thread;
     77     spe_program_handle_t program;
     78     char * program_name;
     79     unsigned int booted;
     80     unsigned int keepalive;
     81     unsigned int entry;
     82     int error_code;
     83     void * argp;
     84 } spu_data_t;
     85 
     86 /* Private video driver data needed for Cell support */
     87 struct SDL_PrivateVideoData
     88 {
     89     const char * const fb_dev_name; /* FB-device name */
     90     int fb_dev_fd; /* Descriptor-handle for fb_dev_name */
     91     uint8_t * frame_buffer; /* mmap'd access to fbdev */
     92 
     93     /* SPE threading stuff */
     94     spu_data_t * fb_thread_data;
     95     spu_data_t * scaler_thread_data;
     96     spu_data_t * converter_thread_data;
     97 
     98     /* screeninfo (from linux/fb.h) */
     99     struct fb_fix_screeninfo fb_finfo;
    100     struct fb_var_screeninfo fb_vinfo;
    101     struct fb_var_screeninfo fb_orig_vinfo;
    102 
    103     /* screeninfo (from asm/ps3fb.h) */
    104     struct ps3fb_ioctl_res res;
    105 
    106     unsigned int double_buffering;
    107     uint32_t real_width;      // real width of screen
    108     uint32_t real_height;     // real height of screen
    109 
    110     uint32_t s_fb_pixel_size;   // 32:  4  24:  3  16:  2  15:  2
    111     uint32_t fb_bits_per_pixel;   // 32: 32  24: 24  16: 16  15: 15
    112 
    113     uint32_t config_count;
    114 
    115     uint32_t s_input_line_length;   // precalculated: input_width * fb_pixel_size
    116     uint32_t s_bounded_input_width; // width of input (bounded by writeable width)
    117     uint32_t s_bounded_input_height;// height of input (bounded by writeable height)
    118     uint32_t s_bounded_input_width_offset;  // offset from the left side (used for centering)
    119     uint32_t s_bounded_input_height_offset; // offset from the upper side (used for centering)
    120     uint32_t s_writeable_width; // width of screen which is writeable
    121     uint32_t s_writeable_height;    // height of screen which is writeable
    122 
    123     uint8_t * s_center[2]; // where to begin writing our image (centered?)
    124     uint32_t s_center_index;
    125 
    126     volatile void * s_pixels __attribute__((aligned(128)));
    127 
    128     /* Framebuffer data */
    129     volatile struct fb_writer_parms_t * fb_parms __attribute__((aligned(128)));
    130 };
    131 
    132 #define fb_dev_name     (this->hidden->fb_dev_name)
    133 #define fb_dev_fd       (this->hidden->fb_dev_fd)
    134 #define frame_buffer       (this->hidden->frame_buffer)
    135 #define fb_thread_data      (this->hidden->fb_thread_data)
    136 #define scaler_thread_data      (this->hidden->scaler_thread_data)
    137 #define converter_thread_data      (this->hidden->converter_thread_data)
    138 #define fb_parms           (this->hidden->fb_parms)
    139 #define SDL_nummodes		(this->hidden->SDL_nummodes)
    140 #define SDL_modelist		(this->hidden->SDL_modelist)
    141 #define SDL_videomode		(this->hidden->SDL_videomode)
    142 #define fb_finfo        (this->hidden->fb_finfo)
    143 #define fb_vinfo        (this->hidden->fb_vinfo)
    144 #define fb_orig_vinfo   (this->hidden->fb_orig_vinfo)
    145 #define res             (this->hidden->res)
    146 #define double_buffering (this->hidden->double_buffering)
    147 #define real_width      (this->hidden->real_width)
    148 #define real_height     (this->hidden->real_height)
    149 #define s_fb_pixel_size   (this->hidden->s_fb_pixel_size)
    150 #define fb_bits_per_pixel (this->hidden->fb_bits_per_pixel)
    151 #define config_count (this->hidden->config_count)
    152 #define s_input_line_length (this->hidden->s_input_line_length)
    153 #define s_bounded_input_width (this->hidden->s_bounded_input_width)
    154 #define s_bounded_input_height (this->hidden->s_bounded_input_height)
    155 #define s_bounded_input_width_offset (this->hidden->s_bounded_input_width_offset)
    156 #define s_bounded_input_height_offset (this->hidden->s_bounded_input_height_offset)
    157 #define s_writeable_width (this->hidden->s_writeable_width)
    158 #define s_writeable_height (this->hidden->s_writeable_height)
    159 #define s_center          (this->hidden->s_center)
    160 #define s_center_index    (this->hidden->s_center_index)
    161 #define s_pixels           (this->hidden->s_pixels)
    162 
    163 #endif /* _SDL_ps3video_h */
    164 
    165 
    166