Index: trunk/kernel/devices/dev_mmc.c
===================================================================
--- trunk/kernel/devices/dev_mmc.c	(revision 1)
+++ trunk/kernel/devices/dev_mmc.c	(revision 3)
@@ -26,4 +26,5 @@
 #include <soclib_mmc.h>
 #include <printk.h>
+#include <chdev.h>
 #include <thread.h>
 #include <dev_mmc.h>
@@ -33,32 +34,24 @@
 /////////////////////////////////////////////////////////////////////////////////////////
 
-extern devices_directory_t  devices_dir;         // allocated in kernel_init.c
-
-extern devices_input_irq_t  devices_input_irq;   // allocated in kernel_init.c
-
-//////////////////////////////////
-void dev_mmc_init( xptr_t dev_xp )
-{
-    // get MMC device descriptor cluster and local pointer
-    cxy_t      dev_cxy = GET_CXY( dev_xp );
-    device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );
-
+extern chdev_directory_t  chdev_dir;         // allocated in kernel_init.c
+
+extern chdev_icu_input_t  chdev_icu_input;   // allocated in kernel_init.c
+
+////////////////////////////////////
+void dev_mmc_init( chdev_t * chdev )
+{
     // get implementation from device descriptor
-    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
-
-    // set driver specific fields in device descriptor
-    // and call driver init function
+    uint32_t  impl = chdev->impl;
+
+    // set driver specific fields in device descriptor and call driver init function
     if( impl == IMPL_MMC_TSR )
     {
-        hal_remote_spt( XPTR( dev_cxy , &dev_ptr->cmd ) , &soclib_mmc_command );
-        hal_remote_spt( XPTR( dev_cxy , &dev_ptr->isr ) , &soclib_mmc_isr );
-        hal_remote_memcpy( XPTR( dev_cxy , &dev_ptr->name ),
-                           XPTR( local_cxy , "MMC_TSR" ) , 16 );
-        soclib_mmc_init( dev_xp );
+        chdev->cmd = &soclib_mmc_cmd;
+        chdev->isr = &soclib_mmc_isr;
+        soclib_mmc_init( chdev );
     }
     else
     {
-        printk("\n[PANIC] in %s: undefined MMC device implementation\n", __FUNCTION__ );
-        hal_core_sleep();
+        assert( false , __FUNCTION__ , "undefined MMC device implementation" );
     }
 }  // end dev_mmc_init()
@@ -72,20 +65,14 @@
 {
     mmc_dmsg("\n[INFO] %s enters for thread %x in process %x : command = %d\n", 
-                 __FUNCTION__ , this->trdid , this->process->pid , this->dev.mmc.type );
+                 __FUNCTION__ , this->trdid , this->process->pid , this->command.mmc.type );
 
     // get extended pointer on MMC device
-    xptr_t  dev_xp  = this->dev.mmc.dev_xp;
-
-    if ( dev_xp == XPTR_NULL )
-    {
-        printk("\n[PANIC] in %s : undefined MMC device descriptor "
-               "in cluster %x for thread %x in process %x\n",
-               __FUNCTION__ , local_cxy , this->trdid , this->process->pid );
-        hal_core_sleep();
-    }
+    xptr_t  dev_xp  = this->command.mmc.dev_xp;
+
+    assert( (dev_xp != XPTR_NULL) , __FUNCTION__ , "undefined MMC device descriptor" );
 
     // get MMC device cluster identifier & local pointer
-    cxy_t      dev_cxy = GET_CXY( dev_xp );
-    device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );
+    cxy_t     dev_cxy = GET_CXY( dev_xp );
+    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
 
     // get driver command function pointer from MMC device descriptor
@@ -116,26 +103,21 @@
     cxy_t cxy = CXY_FROM_PADDR( buf_paddr );
 
-    if ( buf_paddr & (CONFIG_CACHE_LINE_SIZE -1) )
-    {
-        printk("\n[PANIC] in %s : buffer not aligned on cache line "
-               "for thread %x / target cluster %x\n",
-               __FUNCTION__ , this->trdid , cxy );
-        hal_core_sleep();
-    }
+    assert( ((buf_paddr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) , __FUNCTION__ ,
+             "buffer not aligned on cache line" );
 
     // get extended pointer on MMC device descriptor
-    xptr_t  dev_xp = devices_dir.mmc[cxy];
-
-    // store command arguments in thread descriptor
-    this->dev.mmc.dev_xp    = dev_xp;
-    this->dev.mmc.type      = MMC_CC_INVAL;
-    this->dev.mmc.buf_paddr = buf_paddr;
-    this->dev.mmc.buf_size  = buf_size;
-
-    // execute operation
-    dev_mmc_access( this ); 
-
-    // return operation status
-    return this->dev.mmc.error;  
+    xptr_t  dev_xp = chdev_dir.mmc[cxy];
+
+    // store command arguments in thread descriptor
+    this->command.mmc.dev_xp    = dev_xp;
+    this->command.mmc.type      = MMC_CC_INVAL;
+    this->command.mmc.buf_paddr = buf_paddr;
+    this->command.mmc.buf_size  = buf_size;
+
+    // execute operation
+    dev_mmc_access( this ); 
+
+    // return operation status
+    return this->command.mmc.error;  
 }  
 
@@ -150,23 +132,18 @@
     cxy_t cxy = CXY_FROM_PADDR( buf_paddr );
 
-    if ( buf_paddr & (CONFIG_CACHE_LINE_SIZE -1) )
-    {
-        printk("\n[PANIC] in %s : buffer not aligned on cache line "
-               "for thread %x / target cluster %x\n",
-               __FUNCTION__ , this->trdid , cxy );
-        hal_core_sleep();
-    }
-
-    // store command arguments in thread descriptor
-    this->dev.mmc.dev_xp    = devices_dir.mmc[cxy];
-    this->dev.mmc.type      = MMC_CC_SYNC;
-    this->dev.mmc.buf_paddr = buf_paddr;
-    this->dev.mmc.buf_size  = buf_size;
-
-    // execute operation
-    dev_mmc_access( this ); 
-
-    // return operation status
-    return this->dev.mmc.error;  
+    assert( ((buf_paddr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) , __FUNCTION__ ,
+             "buffer not aligned on cache line" );
+
+    // store command arguments in thread descriptor
+    this->command.mmc.dev_xp    = chdev_dir.mmc[cxy];
+    this->command.mmc.type      = MMC_CC_SYNC;
+    this->command.mmc.buf_paddr = buf_paddr;
+    this->command.mmc.buf_size  = buf_size;
+
+    // execute operation
+    dev_mmc_access( this ); 
+
+    // return operation status
+    return this->command.mmc.error;  
 }  
 
@@ -180,14 +157,14 @@
 
     // store command arguments in thread descriptor
-    this->dev.mmc.dev_xp    = devices_dir.mmc[cxy];
-    this->dev.mmc.type      = MMC_SET_ERROR;
-    this->dev.mmc.reg_index = index;
-    this->dev.mmc.reg_ptr   = &wdata;
-
-    // execute operation
-    dev_mmc_access( this ); 
-
-    // return operation status
-    return this->dev.mmc.error;  
+    this->command.mmc.dev_xp    = chdev_dir.mmc[cxy];
+    this->command.mmc.type      = MMC_SET_ERROR;
+    this->command.mmc.reg_index = index;
+    this->command.mmc.reg_ptr   = &wdata;
+
+    // execute operation
+    dev_mmc_access( this ); 
+
+    // return operation status
+    return this->command.mmc.error;  
 }
                         
@@ -201,14 +178,14 @@
 
     // store command arguments in thread descriptor
-    this->dev.mmc.dev_xp    = devices_dir.mmc[cxy];
-    this->dev.mmc.type      = MMC_GET_ERROR;
-    this->dev.mmc.reg_index = index;
-    this->dev.mmc.reg_ptr   = rdata;
-
-    // execute operation
-    dev_mmc_access( this ); 
-
-    // return operation status
-    return this->dev.mmc.error;  
+    this->command.mmc.dev_xp    = chdev_dir.mmc[cxy];
+    this->command.mmc.type      = MMC_GET_ERROR;
+    this->command.mmc.reg_index = index;
+    this->command.mmc.reg_ptr   = rdata;
+
+    // execute operation
+    dev_mmc_access( this ); 
+
+    // return operation status
+    return this->command.mmc.error;  
 }
                         
@@ -222,14 +199,14 @@
 
     // store command arguments in thread descriptor
-    this->dev.mmc.dev_xp    = devices_dir.mmc[cxy];
-    this->dev.mmc.type      = MMC_GET_INSTRU;
-    this->dev.mmc.reg_index = index;
-    this->dev.mmc.reg_ptr   = rdata;
-
-    // execute operation
-    dev_mmc_access( this ); 
-
-    // return operation status
-    return this->dev.mmc.error;  
+    this->command.mmc.dev_xp    = chdev_dir.mmc[cxy];
+    this->command.mmc.type      = MMC_GET_INSTRU;
+    this->command.mmc.reg_index = index;
+    this->command.mmc.reg_ptr   = rdata;
+
+    // execute operation
+    dev_mmc_access( this ); 
+
+    // return operation status
+    return this->command.mmc.error;  
 }
 
