Changes in uspace/srv/bd/ata_bd/ata_bd.c [aa893e0:ff65e91] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/ata_bd/ata_bd.c
raa893e0 rff65e91 51 51 #include <libarch/ddi.h> 52 52 #include <ddi.h> 53 #include <ipc/ipc.h>54 53 #include <ipc/bd.h> 55 54 #include <async.h> … … 82 81 static const size_t identify_data_size = 512; 83 82 84 /** Size of the communication area. */85 static size_t comm_size;86 87 83 /** I/O base address of the command registers. */ 88 84 static uintptr_t cmd_physical; … … 106 102 static void print_syntax(void); 107 103 static int ata_bd_init(void); 108 static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall );104 static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *); 109 105 static int ata_bd_read_blocks(int disk_id, uint64_t ba, size_t cnt, 110 106 void *buf); … … 275 271 276 272 /** Block device connection handler */ 277 static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall )273 static void ata_bd_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 278 274 { 279 275 void *fs_va = NULL; … … 282 278 sysarg_t method; 283 279 devmap_handle_t dh; 284 int flags; 280 size_t comm_size; /**< Size of the communication area. */ 281 unsigned int flags; 285 282 int retval; 286 283 uint64_t ba; … … 298 295 299 296 if (disk_id < 0 || disk[disk_id].present == false) { 300 ipc_answer_0(iid, EINVAL);297 async_answer_0(iid, EINVAL); 301 298 return; 302 299 } 303 300 304 301 /* Answer the IPC_M_CONNECT_ME_TO call. */ 305 ipc_answer_0(iid, EOK);302 async_answer_0(iid, EOK); 306 303 307 304 if (!async_share_out_receive(&callid, &comm_size, &flags)) { 308 ipc_answer_0(callid, EHANGUP);305 async_answer_0(callid, EHANGUP); 309 306 return; 310 307 } … … 312 309 fs_va = as_get_mappable_page(comm_size); 313 310 if (fs_va == NULL) { 314 ipc_answer_0(callid, EHANGUP);311 async_answer_0(callid, EHANGUP); 315 312 return; 316 313 } … … 318 315 (void) async_share_out_finalize(callid, fs_va); 319 316 320 while ( 1) {317 while (true) { 321 318 callid = async_get_call(&call); 322 319 method = IPC_GET_IMETHOD(call); 320 321 if (!method) { 322 /* The other side has hung up. */ 323 async_answer_0(callid, EOK); 324 return; 325 } 326 323 327 switch (method) { 324 case IPC_M_PHONE_HUNGUP:325 /* The other side has hung up. */326 ipc_answer_0(callid, EOK);327 return;328 328 case BD_READ_BLOCKS: 329 329 ba = MERGE_LOUP32(IPC_GET_ARG1(call), … … 347 347 break; 348 348 case BD_GET_BLOCK_SIZE: 349 ipc_answer_1(callid, EOK, disk[disk_id].block_size);349 async_answer_1(callid, EOK, disk[disk_id].block_size); 350 350 continue; 351 351 case BD_GET_NUM_BLOCKS: 352 ipc_answer_2(callid, EOK, LOWER32(disk[disk_id].blocks),352 async_answer_2(callid, EOK, LOWER32(disk[disk_id].blocks), 353 353 UPPER32(disk[disk_id].blocks)); 354 354 continue; … … 357 357 break; 358 358 } 359 ipc_answer_0(callid, retval);359 async_answer_0(callid, retval); 360 360 } 361 361 } … … 373 373 uint16_t w; 374 374 uint8_t c; 375 uint16_t bc; 375 376 size_t pos, len; 376 377 int rc; … … 388 389 } else if (rc == EIO) { 389 390 /* 390 * There is something, but not a register device. 391 * It could be a packet device. 391 * There is something, but not a register device. Check to see 392 * whether the IDENTIFY command left the packet signature in 393 * the registers in case this is a packet device. 394 * 395 * According to the ATA specification, the LBA low and 396 * interrupt reason registers should be set to 0x01. However, 397 * there are many devices that do not follow this and only set 398 * the byte count registers. So, only check these. 392 399 */ 393 rc = identify_pkt_dev(disk_id, &idata); 394 if (rc == EOK) { 395 /* We have a packet device. */ 396 d->dev_type = ata_pkt_dev; 400 bc = ((uint16_t)pio_read_8(&cmd->cylinder_high) << 8) | 401 pio_read_8(&cmd->cylinder_low); 402 403 if (bc == PDEV_SIGNATURE_BC) { 404 rc = identify_pkt_dev(disk_id, &idata); 405 if (rc == EOK) { 406 /* We have a packet device. */ 407 d->dev_type = ata_pkt_dev; 408 } else { 409 return EIO; 410 } 397 411 } else { 398 412 /* Nope. Something's there, but not recognized. */ … … 404 418 } 405 419 406 printf("device caps: 0x%04x\n", idata.caps);407 420 if (d->dev_type == ata_pkt_dev) { 408 421 /* Packet device */ … … 567 580 568 581 /* 569 * This is where we would most likely expect a non-existing device to 570 * show up by not setting SR_DRDY. 582 * Do not wait for DRDY to be set in case this is a packet device. 583 * We determine whether the device is present by waiting for DRQ to be 584 * set after issuing the command. 571 585 */ 572 if (wait_status( SR_DRDY, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK)586 if (wait_status(0, ~SR_BSY, NULL, TIMEOUT_PROBE) != EOK) 573 587 return ETIMEOUT; 574 588 … … 578 592 return ETIMEOUT; 579 593 594 /* 595 * If ERR is set, this may be a packet device, so return EIO to cause 596 * the caller to check for one. 597 */ 598 if ((status & SR_ERR) != 0) { 599 return EIO; 600 } 601 602 if (wait_status(SR_DRQ, ~SR_BSY, &status, TIMEOUT_PROBE) != EOK) 603 return ETIMEOUT; 604 580 605 /* Read data from the disk buffer. */ 581 606 582 if ((status & SR_DRQ) != 0) { 583 for (i = 0; i < identify_data_size / 2; i++) { 584 data = pio_read_16(&cmd->data_port); 585 ((uint16_t *) buf)[i] = data; 586 } 587 } 588 589 if ((status & SR_ERR) != 0) { 590 return EIO; 607 for (i = 0; i < identify_data_size / 2; i++) { 608 data = pio_read_16(&cmd->data_port); 609 ((uint16_t *) buf)[i] = data; 591 610 } 592 611
Note:
See TracChangeset
for help on using the changeset viewer.