Changeset bb0eab1 in mainline
- Timestamp:
- 2011-02-01T07:27:32Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- aa893e0
- Parents:
- 0d247f5
- Location:
- uspace/srv/bd/ata_bd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/ata_bd/ata_bd.c
r0d247f5 rbb0eab1 56 56 #include <as.h> 57 57 #include <fibril_synch.h> 58 #include <stdint.h> 58 59 #include <str.h> 59 60 #include <devmap.h> … … 62 63 #include <errno.h> 63 64 #include <bool.h> 65 #include <byteorder.h> 64 66 #include <task.h> 65 67 #include <macros.h> … … 368 370 identify_data_t idata; 369 371 uint8_t model[40]; 370 uint8_t inq_buf[36];372 ata_inquiry_data_t inq_data; 371 373 uint16_t w; 372 374 uint8_t c; … … 471 473 if (d->dev_type == ata_pkt_dev) { 472 474 /* Send inquiry. */ 473 rc = ata_pcmd_inquiry(0, inq_buf, 36);475 rc = ata_pcmd_inquiry(0, &inq_data, sizeof(inq_data)); 474 476 if (rc != EOK) { 475 477 printf("Device inquiry failed.\n"); … … 479 481 480 482 /* Check device type. */ 481 if ( (inq_buf[0] & 0x1f) != 0x05)483 if (INQUIRY_PDEV_TYPE(inq_data.pdev_type) != PDEV_TYPE_CDROM) 482 484 printf("Warning: Peripheral device type is not CD-ROM.\n"); 483 484 /* XXX Test some reading */485 uint8_t rdbuf[4096];486 rc = ata_pcmd_read_12(0, 0, 1, rdbuf, 4096);487 if (rc != EOK) {488 printf("read(12) failed\n");489 } else {490 printf("read(12) succeeded\n");491 }492 485 493 486 /* Assume 2k block size for now. */ … … 714 707 data_size = (uint16_t) pio_read_8(&cmd->cylinder_low) + 715 708 ((uint16_t) pio_read_8(&cmd->cylinder_high) << 8); 716 printf("data_size = %u\n", data_size);717 709 718 710 /* Check whether data fits into output buffer. */ … … 749 741 static int ata_pcmd_inquiry(int dev_idx, void *obuf, size_t obuf_size) 750 742 { 751 uint8_t cp[12];743 ata_pcmd_inquiry_t cp; 752 744 int rc; 753 745 754 memset(cp, 0, 12); 755 cp[0] = 0x12; /* Inquiry */ 756 cp[4] = min(obuf_size, 0xff); /* Allocation length */ 757 758 rc = ata_cmd_packet(0, cp, 12, obuf, obuf_size); 746 memset(&cp, 0, sizeof(cp)); 747 748 cp.opcode = PCMD_INQUIRY; 749 cp.alloc_len = min(obuf_size, 0xff); /* Allocation length */ 750 751 rc = ata_cmd_packet(0, &cp, sizeof(cp), obuf, obuf_size); 759 752 if (rc != EOK) 760 753 return rc; … … 766 759 void *obuf, size_t obuf_size) 767 760 { 768 uint8_t cp[12];761 ata_pcmd_read_12_t cp; 769 762 int rc; 770 763 771 if (ba > 0xffffffff)764 if (ba > UINT32_MAX) 772 765 return EINVAL; 773 766 774 memset(cp, 0, 12); 775 cp[0] = 0xa8; /* Read(12) */ 776 cp[2] = (ba >> 24) & 0xff; 777 cp[3] = (ba >> 16) & 0xff; 778 cp[4] = (ba >> 8) & 0xff; 779 cp[5] = ba & 0xff; 780 781 cp[6] = (cnt >> 24) & 0xff; 782 cp[7] = (cnt >> 16) & 0xff; 783 cp[8] = (cnt >> 8) & 0xff; 784 cp[9] = cnt & 0xff; 785 786 rc = ata_cmd_packet(0, cp, 12, obuf, obuf_size); 767 memset(&cp, 0, sizeof(cp)); 768 769 cp.opcode = PCMD_READ_12; 770 cp.ba = host2uint32_t_be(ba); 771 cp.nblocks = host2uint32_t_be(cnt); 772 773 rc = ata_cmd_packet(0, &cp, sizeof(cp), obuf, obuf_size); 787 774 if (rc != EOK) 788 775 return rc; -
uspace/srv/bd/ata_bd/ata_hw.h
r0d247f5 rbb0eab1 241 241 }; 242 242 243 /** ATA packet command codes. */ 244 enum ata_pkt_command { 245 PCMD_INQUIRY = 0x12, 246 PCMD_READ_12 = 0xa8 247 }; 248 249 /** ATAPI Inquiry command */ 250 typedef struct { 251 uint8_t opcode; /**< Operation code (PCMD_INQUIRY) */ 252 uint8_t _res0; 253 uint8_t _res1; 254 uint8_t _res2; 255 uint8_t alloc_len; /**< Allocation length */ 256 uint8_t _res3; 257 uint8_t _res4; 258 uint8_t _res5; 259 uint32_t _res6; 260 } __attribute__ ((packed)) ata_pcmd_inquiry_t; 261 262 /** ATAPI Read(12) command */ 263 typedef struct { 264 uint8_t opcode; /**< Operation code (PCMD_READ_12) */ 265 uint8_t _res0; 266 uint32_t ba; /**< Starting block address */ 267 uint32_t nblocks; /**< Number of blocks to transfer */ 268 uint8_t _res1; 269 uint8_t _res2; 270 } __attribute__ ((packed)) ata_pcmd_read_12_t; 271 272 /** Data returned from Inquiry command (mandatory part) */ 273 typedef struct { 274 uint8_t pdev_type; /** Reserved, Peripheral device type */ 275 uint8_t rmb; /** RMB, Reserved */ 276 uint8_t std_version; /** ISO version, ECMA version, ANSI version */ 277 uint8_t atapi_ver_rdf; /** ATAPI version, Response data format */ 278 uint8_t additional_len; /** Additional length */ 279 uint8_t _res0; 280 uint8_t _res1; 281 uint8_t _res2; 282 uint8_t vendor_id[8]; /** Vendor ID */ 283 uint8_t product_id[8]; /** Product ID */ 284 uint8_t product_rev[4]; /** Product revision level */ 285 } ata_inquiry_data_t; 286 287 /** Extract value of ata_inquiry_data_t.pdev_type */ 288 #define INQUIRY_PDEV_TYPE(val) ((val) & 0x1f) 289 290 /** Values for ata_inquiry_data_t.pdev_type */ 291 enum ata_pdev_type { 292 PDEV_TYPE_CDROM = 0x05 293 }; 294 243 295 #endif 244 296
Note:
See TracChangeset
for help on using the changeset viewer.