Ignore:
Timestamp:
Oct 22, 2019, 1:48:51 PM (5 years ago)
Author:
alain
Message:

...miscelaneous...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/devices/dev_fbf.c

    r565 r647  
    11/*
    2  * dev_fbf.c - FBF (Block Device Controler) generic device API implementation.
     2 * dev_fbf.c - FBF (Frame Buffer) generic device API implementation.
    33 *
    4  * Author  Alain Greiner    (2016,2017,2018)
     4 * Author  Alain Greiner    (2016,2017,2018,2019)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2525#include <hal_kernel_types.h>
    2626#include <hal_gpt.h>
     27#include <hal_drivers.h>
    2728#include <thread.h>
    2829#include <printk.h>
     
    3738extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
    3839
     40///////////////////////////////////////////
     41char * dev_fbf_cmd_str( uint32_t cmd_type )
     42{
     43    if     ( cmd_type == FBF_READ       )  return "READ";
     44    else if( cmd_type == FBF_WRITE      )  return "WRITE";
     45    else if( cmd_type == FBF_GET_CONFIG )  return "GET_CONFIG";
     46    else                                   return "undefined";
     47}
     48
    3949////////////////////////////////////
    40 void dev_fbf_init( chdev_t  * chdev )
     50void dev_fbf_init( chdev_t  * fbf )
    4151{
    42     // set FBF chdev extension fields
    43     // TODO this should be done in the implementation
    44     // TODO specific part, as these parameters must be obtained from the hardware.
    45     chdev->ext.fbf.width  = CONFIG_FBF_WIDTH;
    46     chdev->ext.fbf.height = CONFIG_FBF_HEIGHT;
    47 
    48     // get implementation
    49     uint32_t  impl = chdev->impl;
    50 
    5152    // set chdev name
    52     strcpy( chdev->name, "fbf" );
     53    strcpy( fbf->name, "fbf" );
    5354
    5455    // call driver init function
    55     if( impl == IMPL_FBF_SCL )
    56     {
    57         printk("\n[WARNING] Soclib FBF driver not implemented yet\n");
    58     }
    59     else
    60     {
    61         assert( false , "undefined FBF device implementation" );
    62     }
     56    hal_drivers_fbf_init( fbf );
    6357
    6458}  // end dev_fbf_init()
    6559
    66 /////////////////////////////////////////
    67 void dev_fbf_get_size( uint32_t  * width,
    68                        uint32_t  * height )
     60//////////////////////////////////////////
     61void dev_fbf_get_config( uint32_t * width,
     62                         uint32_t * height,
     63                         uint32_t * type )
    6964{
    7065    // get extended pointer on FBF chdev descriptor
     
    8075    *width  = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.width ) );
    8176    *height = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.height ) );
     77    *type   = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.subsampling ) );
    8278
    83 }  // end dev_fbf_get_size()
     79}  // end dev_fbf_get_config()
    8480
    85 /////////////////////////////
    86 error_t dev_fbf_alloc( void )
     81/////////////////////////////////////////////////////
     82error_t dev_fbf_move_data( uint32_t   cmd_type,
     83                           void     * user_buffer,
     84                           uint32_t   length,
     85                           uint32_t   offset )
    8786{
    88     // get extended pointer on FBF chdev descriptor
    89     // xptr_t  dev_xp = chdev_dir.fbf[0];
     87    // get pointer on calling thread
     88    thread_t * this = CURRENT_THREAD;
    9089
    91     // assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
     90#if DEBUG_DEV_FBF
     91uint32_t   cycle = (uint32_t)hal_get_cycles();
     92if( DEBUG_DEV_FBF < cycle )
     93printk("\n[%s] thread[%x,%x] : %s / buffer %x / length %d / offset %x / cycle %d\n",
     94__FUNCTION__ , this->process->pid, this->trdid, 
     95dev_fbf_cmd_str(cmd_type), user_buffer, length, offset, cycle );
     96#endif
    9297
    93     // get FBF chdev cluster and local pointer
    94     // cxy_t     dev_cxy = GET_CXY( dev_xp );
    95     // chdev_t * dev_ptr = GET_PTR( dev_xp );
     98    // get pointers on FBF chdev
     99    xptr_t      fbf_xp  = chdev_dir.fbf[0];
     100    cxy_t       fbf_cxy = GET_CXY( fbf_xp );
     101    chdev_t   * fbf_ptr = GET_PTR( fbf_xp );
    96102
    97     // try to get FBF ownership
     103// check fbf_xp definition
     104assert( (fbf_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
    98105
    99 assert( false , "not implemented yet" );
    100 
    101 }  // end dev_fbf_alloc()
    102 
    103 /////////////////////////
    104 void dev_fbf_free( void )
    105 {
    106     // get extended pointer on FBF chdev descriptor
    107     // xptr_t  dev_xp = chdev_dir.fbf[0];
    108 
    109     // assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
    110 
    111     // get FBF chdev cluster and local pointer
    112     // cxy_t     dev_cxy = GET_CXY( dev_xp );
    113     // chdev_t * dev_ptr = (GET_PTR( dev_xp );
    114 
    115     // release FBF ownership
    116 
    117 assert( false , "not implemented yet" );
    118 
    119 }  // end dev_fbf_free()
    120 
    121 //////////////////////////////////////////////////////////////////////////////////
    122 // This static function is called by dev_fbf_read() & dev_fbf_write() functions.
    123 // It builds and registers the command in the calling thread descriptor.
    124 // Then, it registers the calling thread in the relevant DMA chdev waiting queue.
    125 // Finally it blocks on the THREAD_BLOCKED_DEV condition and deschedule.
    126 ////////////////////////////////////i/////////////////////////////////////////////
    127 static error_t dev_fbf_access( bool_t    to_fbf,
    128                                char    * buffer,
    129                                uint32_t  length,
    130                                uint32_t  offset )
    131 {
    132 
    133     // get extended pointer on FBF chdev descriptor
    134     xptr_t  fbf_xp = chdev_dir.fbf[0];
    135 
    136     assert( (fbf_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
    137 
    138     // get FBF chdev cluster and local pointer
    139     cxy_t     fbf_cxy = GET_CXY( fbf_xp );
    140     chdev_t * fbf_ptr = (chdev_t *)GET_PTR( fbf_xp );
    141 
    142     // get frame buffer base address, width and height
    143     xptr_t   base   = hal_remote_l64( XPTR( fbf_cxy , &fbf_ptr->base ) );
     106    // get frame buffer width and height
    144107    uint32_t width  = hal_remote_l32 ( XPTR( fbf_cxy , &fbf_ptr->ext.fbf.width ) );
    145108    uint32_t height = hal_remote_l32 ( XPTR( fbf_cxy , &fbf_ptr->ext.fbf.height ) );
    146109
    147     // check offset and length versus FBF size
    148     assert( ((offset + length) <= (width * height)) ,
    149     "offset %d / length %d / width %d / height %d\n", offset, length, width, height );
     110// check offset and length versus FBF size
     111assert( ((offset + length) <= (width * height)) ,
     112"offset %d / length %d / width %d / height %d\n", offset, length, width, height );
    150113
    151     // compute extended pointers on frame buffer and memory buffer
    152     xptr_t  mem_buf_xp = XPTR( local_cxy , buffer );
    153     xptr_t  fbf_buf_xp = base + offset;
     114    // register command in calling thread descriptor
     115    this->fbf_cmd.dev_xp    = fbf_xp;
     116    this->fbf_cmd.type      = cmd_type;
     117    this->fbf_cmd.buffer    = user_buffer;
     118    this->fbf_cmd.offset    = offset;
     119    this->fbf_cmd.length    = length;
    154120
    155     // register command in DMA chdev
    156     if( to_fbf )  dev_dma_remote_memcpy( fbf_buf_xp , mem_buf_xp , length );
    157     else          dev_dma_remote_memcpy( mem_buf_xp , fbf_buf_xp , length );
     121    // get driver command function
     122    dev_cmd_t * cmd = (dev_cmd_t *)hal_remote_lpt( XPTR( fbf_cxy , &fbf_ptr->cmd ) );
    158123
    159     return 0;
     124    // call driver
     125    cmd( XPTR( local_cxy , this ) );
    160126
    161 }  // end dev_fbf_access()
     127    error_t error = this->fbf_cmd.error;
    162128
    163 ////////////////////////////////////////////
    164 error_t dev_fbf_read( char         * buffer,
    165                       uint32_t       length,
    166                       uint32_t       offset )
    167 {
    168 
    169 #if DEBUG_DEV_FBF_RX
    170 uint32_t cycle = (uint32_t)hal_get_cycles();
    171 if( DEBUG_DEV_FBF_RX < cycle )
    172 printk("\n[DBG] %s : thread %x enter / process %x / vaddr %x / size %x\n",
    173 __FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
     129#if DEBUG_DEV_FBF
     130cycle = (uint32_t)hal_get_cycles();
     131if( DEBUG_DEV_FBF < cycle )
     132printk("\n[%s] thread[%x,%x] completes %s / error = %d / cycle %d\n",
     133__FUNCTION__ , this->process->pid, this->trdid, 
     134dev_fbf_cmd_str(cmd_type), error , cycle );
    174135#endif
    175136
    176     return dev_fbf_access( false , buffer , length , offset );
     137    // return I/O operation status
     138    return error;
    177139
    178 #if DEBUG_DEV_FBF_RX
    179 cycle = (uint32_t)hal_get_cycles();
    180 if( DEBUG_DEV_FBF_RX < cycle )
    181 printk("\n[DBG] %s : thread %x exit / process %x / vaddr %x / size %x\n",
    182 __FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
    183 #endif
    184 
    185 
    186 
    187 ////////////////////////////////////////////
    188 error_t dev_fbf_write( char         * buffer,
    189                        uint32_t       length,
    190                        uint32_t       offset )
    191 {
    192 
    193 #if DEBUG_DEV_FBF_TX
    194 uint32_t cycle = (uint32_t)hal_get_cycles();
    195 if( DEBUG_DEV_FBF_TX < cycle )
    196 printk("\n[DBG] %s : thread %x enter / process %x / vaddr %x / size %x\n",
    197 __FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
    198 #endif
    199 
    200     return dev_fbf_access( true , buffer , length , offset );
    201 
    202 #if DEBUG_DEV_FBF_RX
    203 cycle = (uint32_t)hal_get_cycles();
    204 if( DEBUG_DEV_FBF_RX < cycle )
    205 printk("\n[DBG] %s : thread %x exit / process %x / vaddr %x / size %x\n",
    206 __FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
    207 #endif
    208 
    209 }
     140}  // end dev_fbf_move_data()
Note: See TracChangeset for help on using the changeset viewer.