Index: trunk/kernel/devices/dev_fbf.c
===================================================================
--- trunk/kernel/devices/dev_fbf.c	(revision 565)
+++ trunk/kernel/devices/dev_fbf.c	(revision 647)
@@ -1,6 +1,6 @@
 /*
- * dev_fbf.c - FBF (Block Device Controler) generic device API implementation.
+ * dev_fbf.c - FBF (Frame Buffer) generic device API implementation.
  * 
- * Author  Alain Greiner    (2016,2017,2018)
+ * Author  Alain Greiner    (2016,2017,2018,2019)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -25,4 +25,5 @@
 #include <hal_kernel_types.h>
 #include <hal_gpt.h>
+#include <hal_drivers.h>
 #include <thread.h>
 #include <printk.h>
@@ -37,34 +38,28 @@
 extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
 
+///////////////////////////////////////////
+char * dev_fbf_cmd_str( uint32_t cmd_type )
+{
+    if     ( cmd_type == FBF_READ       )  return "READ";
+    else if( cmd_type == FBF_WRITE      )  return "WRITE";
+    else if( cmd_type == FBF_GET_CONFIG )  return "GET_CONFIG";
+    else                                   return "undefined";
+}
+
 ////////////////////////////////////
-void dev_fbf_init( chdev_t  * chdev )
+void dev_fbf_init( chdev_t  * fbf )
 {
-    // set FBF chdev extension fields
-    // TODO this should be done in the implementation 
-    // TODO specific part, as these parameters must be obtained from the hardware.
-    chdev->ext.fbf.width  = CONFIG_FBF_WIDTH;
-    chdev->ext.fbf.height = CONFIG_FBF_HEIGHT;
-
-    // get implementation 
-    uint32_t  impl = chdev->impl;
-
     // set chdev name
-    strcpy( chdev->name, "fbf" );
+    strcpy( fbf->name, "fbf" );
 
     // call driver init function
-    if( impl == IMPL_FBF_SCL )
-    {
-        printk("\n[WARNING] Soclib FBF driver not implemented yet\n");
-    }
-    else
-    {
-        assert( false , "undefined FBF device implementation" );
-    }
+    hal_drivers_fbf_init( fbf );
 
 }  // end dev_fbf_init()
 
-/////////////////////////////////////////
-void dev_fbf_get_size( uint32_t  * width,
-                       uint32_t  * height )
+//////////////////////////////////////////
+void dev_fbf_get_config( uint32_t * width,
+                         uint32_t * height,
+                         uint32_t * type )
 {
     // get extended pointer on FBF chdev descriptor
@@ -80,130 +75,66 @@
     *width  = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.width ) );
     *height = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.height ) );
+    *type   = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->ext.fbf.subsampling ) );
 
-}  // end dev_fbf_get_size()
+}  // end dev_fbf_get_config()
 
-/////////////////////////////
-error_t dev_fbf_alloc( void )
+/////////////////////////////////////////////////////
+error_t dev_fbf_move_data( uint32_t   cmd_type,
+                           void     * user_buffer,
+                           uint32_t   length,
+                           uint32_t   offset )
 {
-    // get extended pointer on FBF chdev descriptor
-    // xptr_t  dev_xp = chdev_dir.fbf[0];
+    // get pointer on calling thread
+    thread_t * this = CURRENT_THREAD;
 
-    // assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
+#if DEBUG_DEV_FBF
+uint32_t   cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_DEV_FBF < cycle )
+printk("\n[%s] thread[%x,%x] : %s / buffer %x / length %d / offset %x / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid,  
+dev_fbf_cmd_str(cmd_type), user_buffer, length, offset, cycle );
+#endif
 
-    // get FBF chdev cluster and local pointer
-    // cxy_t     dev_cxy = GET_CXY( dev_xp );
-    // chdev_t * dev_ptr = GET_PTR( dev_xp );
+    // get pointers on FBF chdev
+    xptr_t      fbf_xp  = chdev_dir.fbf[0];
+    cxy_t       fbf_cxy = GET_CXY( fbf_xp );
+    chdev_t   * fbf_ptr = GET_PTR( fbf_xp );
 
-    // try to get FBF ownership
+// check fbf_xp definition
+assert( (fbf_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
 
-assert( false , "not implemented yet" );
-
-}  // end dev_fbf_alloc()
-
-/////////////////////////
-void dev_fbf_free( void )
-{
-    // get extended pointer on FBF chdev descriptor
-    // xptr_t  dev_xp = chdev_dir.fbf[0];
-
-    // assert( (dev_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
-
-    // get FBF chdev cluster and local pointer
-    // cxy_t     dev_cxy = GET_CXY( dev_xp );
-    // chdev_t * dev_ptr = (GET_PTR( dev_xp );
-
-    // release FBF ownership
-
-assert( false , "not implemented yet" );
-
-}  // end dev_fbf_free()
-
-//////////////////////////////////////////////////////////////////////////////////
-// This static function is called by dev_fbf_read() & dev_fbf_write() functions.
-// It builds and registers the command in the calling thread descriptor. 
-// Then, it registers the calling thread in the relevant DMA chdev waiting queue.
-// Finally it blocks on the THREAD_BLOCKED_DEV condition and deschedule.
-////////////////////////////////////i/////////////////////////////////////////////
-static error_t dev_fbf_access( bool_t    to_fbf,
-                               char    * buffer,
-                               uint32_t  length,
-                               uint32_t  offset )
-{
-
-    // get extended pointer on FBF chdev descriptor
-    xptr_t  fbf_xp = chdev_dir.fbf[0];
-
-    assert( (fbf_xp != XPTR_NULL) , "undefined FBF chdev descriptor" );
-
-    // get FBF chdev cluster and local pointer
-    cxy_t     fbf_cxy = GET_CXY( fbf_xp );
-    chdev_t * fbf_ptr = (chdev_t *)GET_PTR( fbf_xp );
-
-    // get frame buffer base address, width and height
-    xptr_t   base   = hal_remote_l64( XPTR( fbf_cxy , &fbf_ptr->base ) );
+    // get frame buffer width and height
     uint32_t width  = hal_remote_l32 ( XPTR( fbf_cxy , &fbf_ptr->ext.fbf.width ) );
     uint32_t height = hal_remote_l32 ( XPTR( fbf_cxy , &fbf_ptr->ext.fbf.height ) );
 
-    // check offset and length versus FBF size
-    assert( ((offset + length) <= (width * height)) ,
-    "offset %d / length %d / width %d / height %d\n", offset, length, width, height ); 
+// check offset and length versus FBF size
+assert( ((offset + length) <= (width * height)) ,
+"offset %d / length %d / width %d / height %d\n", offset, length, width, height ); 
 
-    // compute extended pointers on frame buffer and memory buffer
-    xptr_t  mem_buf_xp = XPTR( local_cxy , buffer );
-    xptr_t  fbf_buf_xp = base + offset;
+    // register command in calling thread descriptor
+    this->fbf_cmd.dev_xp    = fbf_xp;
+    this->fbf_cmd.type      = cmd_type;
+    this->fbf_cmd.buffer    = user_buffer;
+    this->fbf_cmd.offset    = offset;
+    this->fbf_cmd.length    = length;
 
-    // register command in DMA chdev
-    if( to_fbf )  dev_dma_remote_memcpy( fbf_buf_xp , mem_buf_xp , length );
-    else          dev_dma_remote_memcpy( mem_buf_xp , fbf_buf_xp , length );
+    // get driver command function
+    dev_cmd_t * cmd = (dev_cmd_t *)hal_remote_lpt( XPTR( fbf_cxy , &fbf_ptr->cmd ) );
 
-    return 0;
+    // call driver 
+    cmd( XPTR( local_cxy , this ) );
 
-}  // end dev_fbf_access()
+    error_t error = this->fbf_cmd.error;
 
-////////////////////////////////////////////
-error_t dev_fbf_read( char         * buffer,
-                      uint32_t       length,
-                      uint32_t       offset )
-{
-
-#if DEBUG_DEV_FBF_RX
-uint32_t cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_DEV_FBF_RX < cycle )
-printk("\n[DBG] %s : thread %x enter / process %x / vaddr %x / size %x\n", 
-__FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
+#if DEBUG_DEV_FBF
+cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_DEV_FBF < cycle )
+printk("\n[%s] thread[%x,%x] completes %s / error = %d / cycle %d\n",
+__FUNCTION__ , this->process->pid, this->trdid,  
+dev_fbf_cmd_str(cmd_type), error , cycle );
 #endif
 
-    return dev_fbf_access( false , buffer , length , offset ); 
+    // return I/O operation status
+    return error;
 
-#if DEBUG_DEV_FBF_RX
-cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_DEV_FBF_RX < cycle )
-printk("\n[DBG] %s : thread %x exit / process %x / vaddr %x / size %x\n", 
-__FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
-#endif
-
-}  
-
-////////////////////////////////////////////
-error_t dev_fbf_write( char         * buffer,
-                       uint32_t       length,
-                       uint32_t       offset )
-{
-
-#if DEBUG_DEV_FBF_TX
-uint32_t cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_DEV_FBF_TX < cycle )
-printk("\n[DBG] %s : thread %x enter / process %x / vaddr %x / size %x\n", 
-__FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
-#endif
-
-    return dev_fbf_access( true , buffer , length , offset ); 
-
-#if DEBUG_DEV_FBF_RX
-cycle = (uint32_t)hal_get_cycles();
-if( DEBUG_DEV_FBF_RX < cycle )
-printk("\n[DBG] %s : thread %x exit / process %x / vaddr %x / size %x\n", 
-__FUNCTION__ , this, this->process->pid , buffer , buf_paddr );
-#endif
-
-}
+}  // end dev_fbf_move_data()
