Index: soft/giet_vm/giet_drivers/hba_driver.c
===================================================================
--- soft/giet_vm/giet_drivers/hba_driver.c	(revision 258)
+++ soft/giet_vm/giet_drivers/hba_driver.c	(revision 289)
@@ -77,4 +77,5 @@
 #include <ctx_handler.h>
 #include <mmc_driver.h>
+#include <hba_driver.h>
 #include <vmem.h>
 
@@ -124,11 +125,11 @@
 {
     volatile unsigned int* hba_address;
-    hba_address = (unsigned int*)(&seg_hba_base) + (HBA_SPAN*channel);
+    hba_address = (unsigned int*)(&seg_ioc_base) + (HBA_SPAN*channel);
 
     if( channel >= NB_HBA_CHANNELS )
     {
-        _get_lock(&_tty_put_lock);
+        _tty_get_lock( 0 );
         _puts("\n[GIET ERROR] in _hba_get_status() : illegal channel\n");
-        _release_lock(&_tty_put_lock);
+        _tty_release_lock( 0 );
         return 1;
     }
@@ -146,11 +147,11 @@
 {
     volatile unsigned int* hba_address;
-    hba_address = (unsigned int*)(&seg_hba_base) + (HBA_SPAN*channel);
+    hba_address = (unsigned int*)(&seg_ioc_base) + (HBA_SPAN*channel);
 
     if( channel >= NB_HBA_CHANNELS )
     {   
-        _get_lock(&_tty_put_lock);
+        _tty_get_lock( 0 );
         _puts("\n[GIET ERROR] in _hba_reset_status() : illegal channel\n");
-        _release_lock(&_tty_put_lock);
+        _tty_release_lock( 0 );
         return 1;
     }
@@ -191,13 +192,12 @@
     hba_cmd_table_t*   cmd_table;      // command table pointer
 
-    // TODO The block size must be obtained from the hardware...
-    block_size = 512;
+    block_size = _hba_get_block_size();
 
     // check buffer alignment
     if( buf_vaddr & (block_size-1) )
     {
-        _get_lock(&_tty_put_lock);
+        _tty_get_lock( 0 );
         _puts("\n[GIET ERROR] in _hba_set_cmd() : user buffer not block aligned\n");
-        _release_lock(&_tty_put_lock);
+        _tty_release_lock( 0 );
         return 1;
     }
@@ -207,12 +207,12 @@
     if ( channel_id == 0xFFFFFFFF )
     {
-        _get_lock(&_tty_put_lock);
+        _tty_get_lock( 0 );
         _puts("\n[GIET ERROR] in _hba_set_cmd() : no HBA channel allocated\n");
-        _release_lock(&_tty_put_lock);
+        _tty_release_lock( 0 );
         return 1;
     }
 
     // get hba device address
-    hba_address = (unsigned int*)(&seg_hba_base) + (HBA_SPAN * channel_id);
+    hba_address = (unsigned int*)(&seg_ioc_base) + (HBA_SPAN * channel_id);
 
     // get command list status
@@ -223,9 +223,9 @@
     if( pxci & (1<<cmd_id ) ) 
     {
-        _get_lock(&_tty_put_lock);
+        _tty_get_lock( 0 );
         _puts("\n[GIET ERROR] in _hba_set_cmd() : command list full in channel \n");
         _putd( channel_id );
         _puts("\n");
-        _release_lock(&_tty_put_lock);
+        _tty_release_lock( 0 );
         return 1;
     }
@@ -262,21 +262,21 @@
         if ( ko )
         {
-            _get_lock(&_tty_put_lock);
+            _tty_get_lock( 0 );
             _puts("[GIET ERROR] in _hba_set_cmd() : user buffer unmapped\n");
-            _release_lock(&_tty_put_lock);
+            _tty_release_lock( 0 );
             return 1;
         }
         if ((flags & PTE_U) == 0)
         {
-            _get_lock(&_tty_put_lock);
+            _tty_get_lock( 0 );
             _puts("[GIET ERROR] in _hba_set_cmd() : user buffer not in user space\n");
-            _release_lock(&_tty_put_lock);
+            _tty_release_lock( 0 );
             return 1;
         }
         if (((flags & PTE_W) == 0 ) && (is_read == 0) )
         {
-            _get_lock(&_tty_put_lock);
+            _tty_get_lock( 0 );
             _puts("[GIET ERROR] in _hba_set_cmd() : user buffer not writable\n");
-            _release_lock(&_tty_put_lock);
+            _tty_release_lock( 0 );
             return 1;
         }
@@ -285,7 +285,7 @@
         if( buf_id > 245 )
         {
-            _get_lock(&_tty_put_lock);
+            _tty_get_lock( 0 );
             _puts("[GIET ERROR] in _hba_set_cmd() : max number of buffers is 248\n");
-            _release_lock(&_tty_put_lock);
+            _tty_release_lock( 0 );
             return 1;
         }
@@ -415,5 +415,6 @@
 // Returns 0 if success, > 0 if error.
 ///////////////////////////////////////////////////////////////////
-unsigned int _hba_write( unsigned int  lba,
+unsigned int _hba_write( unsigned int  mode,
+                         unsigned int  lba,
                          void*         buffer, 
                          unsigned int  count )
@@ -427,5 +428,6 @@
 // Returns 0 if success, > 0 if error.
 ///////////////////////////////////////////////////////////////////
-unsigned int _hba_read( unsigned int  lba, 
+unsigned int _hba_read( unsigned int  mode,
+                        unsigned int  lba, 
                         void*         buffer, 
                         unsigned int  count )
@@ -434,5 +436,5 @@
 }
 //////////////////////////////////////////////////////////////////
-// This function initializes for a given channel (k)
+// This function initializes for a given channel
 // - the HBA hardware registers,
 // - the command list pointer,
@@ -440,5 +442,5 @@
 // - the command tables physical addresses array,
 //////////////////////////////////////////////////////////////////
-void _hba_init( unsigned int k )  // k == channel_index
+unsigned int _hba_init( unsigned int channel )
 {
     unsigned int ppn;
@@ -452,8 +454,8 @@
 
     // HBA registers
-    unsigned int*  hba_address = (unsigned int*)(&seg_hba_base) + (HBA_SPAN*k);
-    hba_address = (unsigned int*)&seg_hba_base + HBA_SPAN * k;
-
-    hba_address[HBA_PXCLB]  = (unsigned int)(&hba_cmd_list[k]);
+    unsigned int*  hba_address;
+    hba_address = (unsigned int*)&seg_ioc_base + HBA_SPAN * channel;
+
+    hba_address[HBA_PXCLB]  = (unsigned int)(&hba_cmd_list[channel]);
     hba_address[HBA_PXCLBU] = 0;
     hba_address[HBA_PXIE]   = 0x40000001;
@@ -463,8 +465,8 @@
 
     // command list pointer       
-    hba_cmd_slot[k] = 0;
+    hba_cmd_slot[channel] = 0;
 
     // Command list physical addresse
-    vbase = (unsigned int)(&hba_cmd_list[k]);
+    vbase = (unsigned int)(&hba_cmd_list[channel]);
     fail = _v2p_translate( (page_table_t*)pt,
                            vbase>>12,
@@ -473,15 +475,15 @@
     if ( fail )
     {
-        _get_lock(&_tty_put_lock);
+        _tty_get_lock( 0 );
         _puts("[GIET ERROR] in _hba_init() : command list unmapped\n");
-        _release_lock(&_tty_put_lock);
-        _exit();
-    }
-    hba_cmd_list_paddr[k] = ((paddr_t)ppn) | (vbase & 0xFFF);
+        _tty_release_lock( 0 );
+        return 1;
+    }
+    hba_cmd_list_paddr[channel] = ((paddr_t)ppn) | (vbase & 0xFFF);
 
     // Command tables physical addresses
     for( c=0 ; c<32 ; c++ )
     {
-        vbase = (unsigned int)(&hba_cmd_table[k][c]);
+        vbase = (unsigned int)(&hba_cmd_table[channel][c]);
         fail = _v2p_translate( (page_table_t*)pt,
                                vbase>>12,
@@ -490,13 +492,24 @@
         if ( fail )
         {
-            _get_lock(&_tty_put_lock);
+            _tty_get_lock( 0 );
             _puts("[GIET ERROR] in _hba_init() : command table unmapped\n");
-            _release_lock(&_tty_put_lock);
-            _exit();
-        }
-        hba_cmd_table_paddr[k][c] = ((paddr_t)ppn) | (vbase & 0xFFF);
-    }
+            _tty_release_lock( 0 );
+            return 1;
+        }
+        hba_cmd_table_paddr[channel][c] = ((paddr_t)ppn) | (vbase & 0xFFF);
+    }
+
+    return 0;
 }
 
+///////////////////////////////////////////////////////////////////////////////
+//     _hba_get_block_size()
+// This function returns the block_size of HBA controller
+///////////////////////////////////////////////////////////////////////////////
+unsigned int _hba_get_block_size()
+{
+    // TODO The block size must be obtained from the hardware...
+    return 512;
+}
 
 
