Changeset 437 for soft/giet_vm/giet_drivers/hba_driver.c
- Timestamp:
- Nov 3, 2014, 10:53:00 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_drivers/hba_driver.c
r320 r437 5 5 // Copyright (c) UPMC-LIP6 6 6 /////////////////////////////////////////////////////////////////////////////////// 7 // The hba_driver.c and hba_driver.h files are part ot the GIET-VM kernel.8 // This driver supports the SocLib VciMultiAhci component, that is a multi-channels,9 // block oriented, external storage contrÃŽler, respecting the AHCI standard.10 //11 // The SEG_IOC_BASE virtual address must be defined in the hard_config.h file.12 //////////////////////////////////////////////////////////////////////////////////13 7 // Implementation notes: 14 //15 8 // 1. In order to share code, the two _hba_read() and _hba_write() functions 16 9 // call the same _hba_set_cmd() function. 17 //18 10 // 2. All accesses to HBA registers are done by the two 19 11 // _hba_set_register() and _hba_get_register() low-level functions, … … 42 34 43 35 ////////////////////////////////////////////////////////////////// 44 // Global variables36 // Global variables 45 37 ////////////////////////////////////////////////////////////////// 46 38 … … 89 81 // buffer must be an integer number of blocks entirely contained in a single 90 82 // page frame. 91 // return 0 if success, > 0if error83 // return 0 if success, -1 if error 92 84 /////////////////////////////////////////////////////////////////////////////// 93 85 unsigned int _hba_cmd_set( unsigned int channel, // channel index … … 109 101 if( buffer & (block_size-1) ) 110 102 { 111 _p rintf("\n[GIET ERROR] in _hba_set_cmd() : user buffer not block aligned\n");112 return 1;103 _puts("\n[GIET ERROR] in _hba_set_cmd() : user buffer not block aligned\n"); 104 return -1; 113 105 } 114 106 … … 120 112 if( pxci & (1<<cmd_id ) ) 121 113 { 122 _printf("\n[GIET ERROR] in _hba_set_cmd() : command list full for channel %d\n", 123 channel ); 124 return 1; 114 _puts("\n[GIET ERROR] in _hba_set_cmd() : command list full for channel "); 115 _putd( channel ); 116 _puts("\n"); 117 return -1; 125 118 } 126 119 … … 188 181 if ( ko ) 189 182 { 190 _p rintf("[GIET ERROR] in _hba_set_cmd() : user buffer unmapped\n");191 return 1;183 _puts("[GIET ERROR] in _hba_set_cmd() : user buffer unmapped\n"); 184 return -1; 192 185 } 193 186 if ((flags & PTE_U) == 0) 194 187 { 195 _p rintf("[GIET ERROR] in _hba_set_cmd() : user buffer not in user space\n");196 return 1;188 _puts("[GIET ERROR] in _hba_set_cmd() : user buffer not in user space\n"); 189 return -1; 197 190 } 198 191 if (((flags & PTE_W) == 0 ) && (is_read == 0) ) 199 192 { 200 _p rintf("[GIET ERROR] in _hba_set_cmd() : user buffer not writable\n");201 return 1;193 _puts("[GIET ERROR] in _hba_set_cmd() : user buffer not writable\n"); 194 return -1; 202 195 } 203 196 … … 205 198 if( buf_id > 245 ) 206 199 { 207 _p rintf("[GIET ERROR] in _hba_set_cmd() : max number of buffers is 248\n");208 return 1;200 _puts("[GIET ERROR] in _hba_set_cmd() : max number of buffers is 248\n"); 201 return -1; 209 202 } 210 203 … … 218 211 cmd_table->entry[buf_id].dbc = count; 219 212 220 #if GIET_DEBUG_HBA_DRIVER221 _printf("\n- buf_index = ");222 _putd( buf_id );223 _printf(" / paddr = ");224 _putl( paddr );225 _printf(" / count = ");226 _putd( count );227 _printf("\n");228 #endif229 213 buf_id++; 230 214 } … … 237 221 cmd_table->entry[buf_id].dbc = count; 238 222 239 #if GIET_DEBUG_HBA_DRIVER240 _printf("\n- buf_index = ");241 _putd( buf_id );242 _printf(" / paddr = ");243 _putl( paddr );244 _printf(" / count = ");245 _putd( count );246 _printf("\n");247 #endif248 223 buf_id++; 249 224 } … … 257 232 cmd_table->entry[buf_id].dbc = count; 258 233 259 #if GIET_DEBUG_HBA_DRIVER260 _printf("\n- buf_index = ");261 _putd( buf_id );262 _printf(" / paddr = ");263 _putl( paddr );264 _printf(" / count = ");265 _putd( count );266 _printf("\n");267 #endif268 234 buf_id++; 269 235 … … 274 240 cmd_table->entry[buf_id].dbc = count; 275 241 276 #if GIET_DEBUG_HBA_DRIVER277 _printf("\n- buf_index = ");278 _putd( buf_id );279 _printf(" / paddr = ");280 _putl( paddr );281 _printf(" / count = ");282 _putd( count );283 _printf("\n");284 #endif285 242 buf_id++; 286 243 } … … 293 250 cmd_table->entry[buf_id].dbc = count; 294 251 295 #if GIET_DEBUG_HBA_DRIVER296 _printf("\n- buf_index = ");297 _putd( buf_id );298 _printf(" / paddr = ");299 _putl( paddr );300 _printf(" / count = ");301 _putd( count );302 _printf("\n");303 #endif304 252 buf_id++; 305 253 } … … 308 256 309 257 310 /////////////////////////////////////////////////////////////////// 311 // Register a write command in Command List and Command Table 312 // for a single physical buffer. 313 // Returns 0 if success, > 0 if error. 314 /////////////////////////////////////////////////////////////////// 315 unsigned int _hba_write( unsigned int channel, 316 unsigned int mode, 317 unsigned int lba, 318 paddr_t buffer, 319 unsigned int count ) 320 { 321 return _hba_cmd_set( channel, 322 0, // write 323 lba, 324 buffer, 325 count ); 326 } 327 328 /////////////////////////////////////////////////////////////////// 329 // Register a read command in Command List and Command Table 330 // for a single physical buffer. 331 // Returns 0 if success, > 0 if error. 332 /////////////////////////////////////////////////////////////////// 333 unsigned int _hba_read( unsigned int channel, 334 unsigned int mode, 335 unsigned int lba, 336 paddr_t buffer, 337 unsigned int count ) 338 { 339 return _hba_cmd_set( channel, 340 1, // read 341 lba, 342 buffer, 343 count ); 344 } 345 346 ////////////////////////////////////////////////////////////////// 347 // This function initializes for a given channel 348 // - the HBA hardware registers, 349 // - the command list pointer, 350 // - the command lists physical addresse, 351 // - the command tables physical addresses array, 352 ////////////////////////////////////////////////////////////////// 258 ////////////////////////////////////////////// 353 259 unsigned int _hba_init( unsigned int channel ) 354 260 { … … 381 287 if ( fail ) 382 288 { 383 _p rintf("[GIET ERROR] in _hba_init() : command list unmapped\n");384 return 1;289 _puts("[GIET ERROR] in _hba_init() : command list unmapped\n"); 290 return -1; 385 291 } 386 292 hba_cmd_list_paddr[channel] = ((paddr_t)ppn) | (vbase & 0xFFF); … … 396 302 if ( fail ) 397 303 { 398 _p rintf("[GIET ERROR] in _hba_init() : command table unmapped\n");399 return 1;304 _puts("[GIET ERROR] in _hba_init() : command table unmapped\n"); 305 return -1; 400 306 } 401 307 hba_cmd_table_paddr[channel][c] = ((paddr_t)ppn) | (vbase & 0xFFF); … … 405 311 } 406 312 407 /////////////////////////////////////////////////////////////////////////////// 408 // _hba_get_block_size() 409 // This function returns the block_size of HBA controller 410 /////////////////////////////////////////////////////////////////////////////// 313 /////////////////////////////////////////////// 314 unsigned int _hba_write( unsigned int channel, 315 unsigned int mode, 316 unsigned int lba, 317 paddr_t buffer, 318 unsigned int count ) 319 { 320 return _hba_cmd_set( channel, 321 0, // write 322 lba, 323 buffer, 324 count ); 325 } 326 327 ////////////////////////////////////////////// 328 unsigned int _hba_read( unsigned int channel, 329 unsigned int mode, 330 unsigned int lba, 331 paddr_t buffer, 332 unsigned int count ) 333 { 334 return _hba_cmd_set( channel, 335 1, // read 336 lba, 337 buffer, 338 count ); 339 } 340 341 ////////////////////////////////// 411 342 unsigned int _hba_get_block_size() 412 343 { … … 415 346 } 416 347 417 ///////////////////////////////////////////////////////////////////////////////////// 418 // This function returns the content of the HBA_PXIS register for a given channel, 419 // and reset this register to acknoledge IRQ. 420 // return 0 if success, > 0 if error 421 ///////////////////////////////////////////////////////////////////////////////////// 348 //////////////////////////////////////////////////// 422 349 unsigned int _hba_get_status( unsigned int channel ) 423 350 { … … 425 352 if( channel >= NB_IOC_CHANNELS ) 426 353 { 427 _p rintf("\n[GIET ERROR] in _hba_get_status() : illegal channel\n");354 _puts("\n[GIET ERROR] in _hba_get_status() : illegal channel\n"); 428 355 _exit(); 429 356 }
Note: See TracChangeset
for help on using the changeset viewer.