Changeset 23 for trunk/kernel/devices/dev_mmc.c
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/devices/dev_mmc.c
r14 r23 43 43 // get implementation from device descriptor 44 44 uint32_t impl = chdev->impl; 45 46 // set chdev name 47 snprintf( chdev->name , 16 , "mmc_%x" , local_cxy ); 45 48 46 49 // set driver specific fields in device descriptor and call driver init function … … 65 68 66 69 ///////////////////////////////////////////////////////////////////////////// 67 // This static function makes some checking, takes the lock granting 68 // exclusive access to MMC peripheral, call the driver to execute the command 70 // This static function is called by all MMC device functions. 71 // It makes some checking, takes the lock granting exclusive 72 // access to MMC peripheral, call the driver to execute the command 69 73 // registered in the calling thread descriptor, and releases the lock. 70 74 ///////////////////////////////////////////////////////////////////////////// 71 static void dev_mmc_access( thread_t * this ) 72 { 73 mmc_dmsg("\n[INFO] %s enters for thread %x in process %x : command = %d\n", 74 __FUNCTION__ , this->trdid , this->process->pid , this->command.mmc.type ); 75 76 // get extended pointer on MMC device 77 xptr_t dev_xp = this->command.mmc.dev_xp; 78 79 assert( (dev_xp != XPTR_NULL) , __FUNCTION__ , "undefined MMC device descriptor" ); 75 static error_t dev_mmc_access( thread_t * this ) 76 { 77 // get extended pointer on MMC device descriptor 78 xptr_t dev_xp = this->command.mmc.dev_xp; 79 80 assert( (dev_xp != XPTR_NULL) , __FUNCTION__ , "target MMC device undefined" ); 80 81 81 82 // get MMC device cluster identifier & local pointer … … 95 96 remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); 96 97 97 mmc_dmsg("\n[INFO] %s completes for thread %x in process %x / error = %d\n",98 __FUNCTION__ , this->trdid , this->process->pid , this->dev.ioc.error );98 // return operation status 99 return this->command.mmc.error; 99 100 100 101 } // end dev_mmc_access() 101 102 102 ///////////////////////////////////////// ///103 error_t dev_mmc_inval( paddr_t buf_paddr,103 ///////////////////////////////////////// 104 error_t dev_mmc_inval( xptr_t buf_xp, 104 105 uint32_t buf_size ) 105 106 { 106 // get calling thread local pointer 107 thread_t * this = CURRENT_THREAD; 108 109 // get target cluster from paddr 110 cxy_t cxy = CXY_FROM_PADDR( buf_paddr ); 111 112 assert( ((buf_paddr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) , __FUNCTION__ , 107 error_t error; 108 109 // get calling thread local pointer 110 thread_t * this = CURRENT_THREAD; 111 112 mmc_dmsg("\n[INFO] %s enters for thread %x in process %x / buf_xp = %l\n", 113 __FUNCTION__ , this->trdid , this->process->pid , buf_xp ); 114 115 // get buffer cluster and local pointer 116 cxy_t buf_cxy = GET_CXY( buf_xp ); 117 void * buf_ptr = GET_PTR( buf_xp ); 118 119 assert( (((intptr_t)buf_ptr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) , __FUNCTION__ , 113 120 "buffer not aligned on cache line" ); 114 121 115 // get extended pointer on MMC device descriptor 116 xptr_t dev_xp = chdev_dir.mmc[cxy]; 117 118 // store command arguments in thread descriptor 119 this->command.mmc.dev_xp = dev_xp; 122 // get buffer physical address 123 paddr_t buf_paddr; 124 error = vmm_v2p_translate( CONFIG_KERNEL_IDENTITY_MAP , buf_ptr , &buf_paddr ); 125 126 assert( (error == 0) , __FUNCTION__ , "cannot get buffer paddr" ); 127 128 // store command arguments in thread descriptor 129 this->command.mmc.dev_xp = chdev_dir.mmc[buf_cxy]; 120 130 this->command.mmc.type = MMC_CC_INVAL; 121 131 this->command.mmc.buf_paddr = buf_paddr; 122 132 this->command.mmc.buf_size = buf_size; 123 133 124 // execute operation 125 dev_mmc_access( this ); 126 127 // return operation status 128 return this->command.mmc.error; 129 } 130 131 ///////////////////////////////////// 132 error_t dev_mmc_sync( paddr_t buf_paddr, 134 // call MMC driver 135 error = dev_mmc_access( this ); 136 137 mmc_dmsg("\n[INFO] %s completes for thread %x in process %x / error = %d\n", 138 __FUNCTION__ , this->trdid , this->process->pid , error ); 139 140 return error; 141 } 142 143 //////////////////////////////////////// 144 error_t dev_mmc_sync( xptr_t buf_xp, 133 145 uint32_t buf_size ) 134 146 { 135 // get calling thread local pointer 136 thread_t * this = CURRENT_THREAD; 137 138 // get target cluster from paddr 139 cxy_t cxy = CXY_FROM_PADDR( buf_paddr ); 140 141 assert( ((buf_paddr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) , __FUNCTION__ , 147 error_t error; 148 149 // get calling thread local pointer 150 thread_t * this = CURRENT_THREAD; 151 152 mmc_dmsg("\n[INFO] %s enters for thread %x in process %x / buf_xp = %l\n", 153 __FUNCTION__ , this->trdid , this->process->pid , buf_xp ); 154 155 // get buffer cluster and local pointer 156 cxy_t buf_cxy = GET_CXY( buf_xp ); 157 void * buf_ptr = GET_PTR( buf_xp ); 158 159 assert( (((intptr_t)buf_ptr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) , __FUNCTION__ , 142 160 "buffer not aligned on cache line" ); 143 161 144 // store command arguments in thread descriptor 145 this->command.mmc.dev_xp = chdev_dir.mmc[cxy]; 162 // get buffer physical address 163 paddr_t buf_paddr; 164 error = vmm_v2p_translate( CONFIG_KERNEL_IDENTITY_MAP , buf_ptr , &buf_paddr ); 165 166 assert( (error == 0) , __FUNCTION__ , "cannot get buffer paddr" ); 167 168 // store command arguments in thread descriptor 169 this->command.mmc.dev_xp = chdev_dir.mmc[buf_cxy]; 146 170 this->command.mmc.type = MMC_CC_SYNC; 147 171 this->command.mmc.buf_paddr = buf_paddr; 148 172 this->command.mmc.buf_size = buf_size; 149 173 150 // execute operation 151 dev_mmc_access( this ); 152 153 // return operation status 154 return this->command.mmc.error; 155 } 174 // call MMC driver 175 error = dev_mmc_access( this ); 176 177 mmc_dmsg("\n[INFO] %s completes for thread %x in process %x / error = %d\n", 178 __FUNCTION__ , this->trdid , this->process->pid , error ); 179 180 return error; 181 } 156 182 157 183 ///////////////////////////////////////// … … 170 196 171 197 // execute operation 172 dev_mmc_access( this ); 173 174 // return operation status 175 return this->command.mmc.error; 198 return dev_mmc_access( this ); 176 199 } 177 200 … … 191 214 192 215 // execute operation 193 dev_mmc_access( this ); 194 195 // return operation status 196 return this->command.mmc.error; 216 return dev_mmc_access( this ); 197 217 } 198 218 … … 212 232 213 233 // execute operation 214 dev_mmc_access( this ); 215 216 // return operation status 217 return this->command.mmc.error; 218 } 219 234 return dev_mmc_access( this ); 235 } 236
Note: See TracChangeset
for help on using the changeset viewer.