- port->device_info = valloc(sizeof(struct ahci_device_info));
- ahci_parse_dev_info(port->device_info, data_in);
+ struct scsi_cdb16* cdb16 = (struct scsi_cdb16*)cmd_table->atapi_cmd;
+
+ sata_create_fis(cmd_fis, ATA_PACKET, 512 << 8, 0);
+ scsi_create_packet16(cdb16, SCSI_READ_CAPACITY_16, 0, 512);
+
+ cdb16->misc1 = 0x10; // service action
+ cmd_header->transferred_size = 0;
+ cmd_header->options |= HBA_CMDH_ATAPI;
+
+ port->regs[HBA_RPxCI] = (1 << slot);
+ wait_until(!(port->regs[HBA_RPxCI] & (1 << slot)));
+
+ if ((port->regs[HBA_RPxTFD] & HBA_PxTFD_ERR)) {
+ // 有错误
+ sata_read_error(port);
+ goto fail;
+ }
+
+ scsi_parse_capacity(port->device, (uint32_t*)data_in);
+
+done:
+ // reset interrupt status and unmask D2HR interrupt
+ port->regs[HBA_RPxIS] = -1;
+ port->regs[HBA_RPxIE] |= HBA_PxINTR_DHR;
+ achi_register_ops(port);