Changeset c2844735 in mainline
- Timestamp:
- 2014-08-03T15:37:06Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 251d4dd
- Parents:
- 94c49fd3
- Location:
- uspace/drv/block/ata_bd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/block/ata_bd/Makefile
r94c49fd3 rc2844735 28 28 29 29 USPACE_PREFIX = ../../.. 30 LIBS = $(LIBDRV_PREFIX)/libdrv.a 31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include 30 LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBSCSI_PREFIX)/libscsi.a 31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBSCSI_PREFIX)/include 32 32 BINARY = ata_bd 33 33 -
uspace/drv/block/ata_bd/ata_bd.c
r94c49fd3 rc2844735 54 54 #include <bd_srv.h> 55 55 #include <fibril_synch.h> 56 #include <scsi/sbc.h> 56 57 #include <stdint.h> 57 58 #include <str.h> … … 103 104 static int ata_identify_pkt_dev(disk_t *disk, void *buf); 104 105 static int ata_cmd_packet(disk_t *disk, const void *cpkt, size_t cpkt_size, 105 void *obuf, size_t obuf_size); 106 static int ata_pcmd_inquiry(disk_t *disk, void *obuf, size_t obuf_size); 106 void *obuf, size_t obuf_size, size_t *rcvd_size); 107 static int ata_pcmd_inquiry(disk_t *disk, void *obuf, size_t obuf_size, 108 size_t *rcvd_size); 107 109 static int ata_pcmd_read_12(disk_t *disk, uint64_t ba, size_t cnt, 108 110 void *obuf, size_t obuf_size); 111 static int ata_pcmd_read_capacity(disk_t *disk, uint64_t *nblocks, 112 size_t *block_size); 109 113 static int ata_pcmd_read_toc(disk_t *disk, uint8_t ses, 110 114 void *obuf, size_t obuf_size); … … 340 344 uint8_t model[40]; 341 345 ata_inquiry_data_t inq_data; 346 size_t isize; 342 347 uint16_t w; 343 348 uint8_t c; 344 349 uint16_t bc; 350 uint64_t nblocks; 351 size_t block_size; 345 352 size_t pos, len; 346 353 int rc; … … 457 464 if (d->dev_type == ata_pkt_dev) { 458 465 /* Send inquiry. */ 459 rc = ata_pcmd_inquiry(d, &inq_data, sizeof(inq_data) );460 if (rc != EOK ) {466 rc = ata_pcmd_inquiry(d, &inq_data, sizeof(inq_data), &isize); 467 if (rc != EOK || isize < sizeof(inq_data)) { 461 468 ddf_msg(LVL_ERROR, "Device inquiry failed."); 462 469 d->present = false; … … 468 475 ddf_msg(LVL_WARN, "Peripheral device type is not CD-ROM."); 469 476 470 /* Assume 2k block size for now. */ 471 d->block_size = 2048; 477 rc = ata_pcmd_read_capacity(d, &nblocks, &block_size); 478 if (rc != EOK) { 479 ddf_msg(LVL_ERROR, "Read capacity command failed."); 480 d->present = false; 481 return EIO; 482 } 483 484 d->blocks = nblocks; 485 d->block_size = block_size; 472 486 } else { 473 487 /* Assume register Read always uses 512-byte blocks. */ … … 722 736 * @param obuf Buffer for storing data read from device 723 737 * @param obuf_size Size of obuf in bytes 738 * @param rcvd_size Place to store number of bytes read or @c NULL 724 739 * 725 740 * @return EOK on success, EIO on error. 726 741 */ 727 742 static int ata_cmd_packet(disk_t *disk, const void *cpkt, size_t cpkt_size, 728 void *obuf, size_t obuf_size )743 void *obuf, size_t obuf_size, size_t *rcvd_size) 729 744 { 730 745 ata_ctrl_t *ctrl = disk->ctrl; … … 800 815 return EIO; 801 816 817 if (rcvd_size != NULL) 818 *rcvd_size = data_size; 802 819 return EOK; 803 820 } … … 811 828 * @return EOK on success, EIO on error. 812 829 */ 813 static int ata_pcmd_inquiry(disk_t *disk, void *obuf, size_t obuf_size) 830 static int ata_pcmd_inquiry(disk_t *disk, void *obuf, size_t obuf_size, 831 size_t *rcvd_size) 814 832 { 815 833 ata_pcmd_inquiry_t cp; … … 821 839 cp.alloc_len = min(obuf_size, 0xff); /* Allocation length */ 822 840 823 rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size );841 rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size, rcvd_size); 824 842 if (rc != EOK) 825 843 return rc; 844 845 return EOK; 846 } 847 848 /** Issue ATAPI read capacity(10) command. 849 * 850 * @param disk Disk 851 * @param nblocks Place to store number of blocks 852 * @param block_size Place to store block size 853 * 854 * @return EOK on success, EIO on error. 855 */ 856 static int ata_pcmd_read_capacity(disk_t *disk, uint64_t *nblocks, 857 size_t *block_size) 858 { 859 scsi_cdb_read_capacity_10_t cdb; 860 scsi_read_capacity_10_data_t data; 861 size_t rsize; 862 int rc; 863 864 memset(&cdb, 0, sizeof(cdb)); 865 cdb.op_code = SCSI_CMD_READ_CAPACITY_10; 866 867 rc = ata_cmd_packet(disk, &cdb, sizeof(cdb), &data, sizeof(data), &rsize); 868 if (rc != EOK) 869 return rc; 870 871 if (rsize != sizeof(data)) 872 return EIO; 873 874 *nblocks = uint32_t_be2host(data.last_lba) + 1; 875 *block_size = uint32_t_be2host(data.block_size); 826 876 827 877 return EOK; … … 856 906 cp.nblocks = host2uint32_t_be(cnt); 857 907 858 rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size );908 rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size, NULL); 859 909 if (rc != EOK) 860 910 return rc; … … 895 945 cp.oldformat = 0x40; /* 0x01 = multi-session mode (shifted to MSB) */ 896 946 897 rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size );947 rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size, NULL); 898 948 if (rc != EOK) 899 949 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.