ahci: Minor cleanup.

This commit is contained in:
Axel Dörfler
2013-11-07 19:05:31 +01:00
parent fd88486a31
commit 930cb4206b
2 changed files with 55 additions and 49 deletions
@@ -1,4 +1,5 @@
/* /*
* Copyright 2008-2013 Haiku, Inc. All rights reserved.
* Copyright 2007-2009, Marcus Overhagen. All rights reserved. * Copyright 2007-2009, Marcus Overhagen. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -79,9 +80,10 @@ AHCIPort::Init1()
char* virtAddr; char* virtAddr;
phys_addr_t physAddr; phys_addr_t physAddr;
char name[32];
snprintf(name, sizeof(name), "AHCI port %d", fIndex);
fArea = alloc_mem((void **)&virtAddr, &physAddr, size, 0, fArea = alloc_mem((void**)&virtAddr, &physAddr, size, 0, name);
"some AHCI port");
if (fArea < B_OK) { if (fArea < B_OK) {
TRACE("failed allocating memory for port %d\n", fIndex); TRACE("failed allocating memory for port %d\n", fIndex);
return fArea; return fArea;
@@ -303,8 +305,8 @@ AHCIPort::PostReset()
if (!fTestUnitReadyActive) { if (!fTestUnitReadyActive) {
TRACE("device signature 0x%08" B_PRIx32 " (%s)\n", fRegs->sig, TRACE("device signature 0x%08" B_PRIx32 " (%s)\n", fRegs->sig,
(fRegs->sig == 0xeb140101) ? "ATAPI" : (fRegs->sig == 0x00000101) ? fRegs->sig == 0xeb140101 ? "ATAPI" : fRegs->sig == 0x00000101
"ATA" : "unknown"); ? "ATA" : "unknown");
} }
return B_OK; return B_OK;
@@ -341,9 +343,9 @@ AHCIPort::Interrupt()
uint32 ci = fRegs->ci; uint32 ci = fRegs->ci;
RWTRACE("[%lld] %ld AHCIPort::Interrupt port %d, fCommandsActive 0x%08" B_PRIx32 ", " RWTRACE("[%lld] %ld AHCIPort::Interrupt port %d, fCommandsActive 0x%08"
"is 0x%08" B_PRIx32 ", ci 0x%08" B_PRIx32 "\n", system_time(), find_thread(NULL), B_PRIx32 ", is 0x%08" B_PRIx32 ", ci 0x%08" B_PRIx32 "\n",
fIndex, fCommandsActive, is, ci); system_time(), find_thread(NULL), fIndex, fCommandsActive, is, ci);
acquire_spinlock(&fSpinlock); acquire_spinlock(&fSpinlock);
if ((fCommandsActive & 1) && !(ci & 1)) { if ((fCommandsActive & 1) && !(ci & 1)) {
@@ -560,7 +562,8 @@ AHCIPort::ScsiInquiry(scsi_ccb *request)
ASSERT(sizeof(ataData) == 512); ASSERT(sizeof(ataData) == 512);
if (cmd->evpd || cmd->page_code || request->data_length < sizeof(scsiData)) { if (cmd->evpd || cmd->page_code
|| request->data_length < sizeof(scsiData)) {
TRACE("invalid request\n"); TRACE("invalid request\n");
request->subsys_status = SCSI_REQ_ABORTED; request->subsys_status = SCSI_REQ_ABORTED;
gSCSI->finished(request, 1); gSCSI->finished(request, 1);
@@ -689,7 +692,8 @@ AHCIPort::ScsiReadCapacity(scsi_ccb *request)
{ {
TRACE("AHCIPort::ScsiReadCapacity port %d\n", fIndex); TRACE("AHCIPort::ScsiReadCapacity port %d\n", fIndex);
const scsi_cmd_read_capacity *cmd = (const scsi_cmd_read_capacity *)request->cdb; const scsi_cmd_read_capacity* cmd
= (const scsi_cmd_read_capacity*)request->cdb;
scsi_res_read_capacity scsiData; scsi_res_read_capacity scsiData;
if (cmd->pmi || cmd->lba || request->data_length < sizeof(scsiData)) { if (cmd->pmi || cmd->lba || request->data_length < sizeof(scsiData)) {
@@ -725,7 +729,6 @@ AHCIPort::ScsiReadCapacity16(scsi_ccb *request)
{ {
TRACE("AHCIPort::ScsiReadCapacity16 port %d\n", fIndex); TRACE("AHCIPort::ScsiReadCapacity16 port %d\n", fIndex);
//const scsi_cmd_read_capacity_long *cmd = (const scsi_cmd_read_capacity_long *)request->cdb;
scsi_res_read_capacity_long scsiData; scsi_res_read_capacity_long scsiData;
TRACE("SectorSize %" B_PRIu32 ", SectorCount 0x%" B_PRIx64 "\n", TRACE("SectorSize %" B_PRIu32 ", SectorCount 0x%" B_PRIx64 "\n",
@@ -813,8 +816,7 @@ AHCIPort::ScsiUnmap(scsi_ccb* request, scsi_unmap_parameter_list* unmapBlocks)
} }
uint32 lbaRangesSize = lbaRangeCount * sizeof(uint64); uint32 lbaRangesSize = lbaRangeCount * sizeof(uint64);
uint64* lbaRanges uint64* lbaRanges = (uint64*)malloc(lbaRangesSize);
= (uint64*)malloc(lbaRangesSize);
if (lbaRanges == NULL) { if (lbaRanges == NULL) {
TRACE("out of memory when allocating %" B_PRIu32 " unmap ranges\n", TRACE("out of memory when allocating %" B_PRIu32 " unmap ranges\n",
lbaRangeCount); lbaRangeCount);
@@ -1156,5 +1158,6 @@ AHCIPort::ScsiGetRestrictions(bool *isATAPI, bool *noAutoSense,
*noAutoSense = fIsATAPI; // emulated auto sense for ATA, but not ATAPI *noAutoSense = fIsATAPI; // emulated auto sense for ATA, but not ATAPI
*maxBlocks = fUse48BitCommands ? 65536 : 256; *maxBlocks = fUse48BitCommands ? 65536 : 256;
TRACE("AHCIPort::ScsiGetRestrictions port %d: isATAPI %d, noAutoSense %d, " TRACE("AHCIPort::ScsiGetRestrictions port %d: isATAPI %d, noAutoSense %d, "
"maxBlocks %" B_PRIu32 "\n", fIndex, *isATAPI, *noAutoSense, *maxBlocks); "maxBlocks %" B_PRIu32 "\n", fIndex, *isATAPI, *noAutoSense,
*maxBlocks);
} }
@@ -59,6 +59,7 @@ sata_request::set_ata_cmd(uint8 command)
memset(fFis, 0, sizeof(fFis)); memset(fFis, 0, sizeof(fFis));
fFis[0] = FIS_TYPE_REGISTER_HOST_TO_DEVICE; fFis[0] = FIS_TYPE_REGISTER_HOST_TO_DEVICE;
fFis[1] = 0x80; fFis[1] = 0x80;
// This is a command
fFis[2] = command; fFis[2] = command;
} }
@@ -71,6 +72,7 @@ sata_request::set_ata28_cmd(uint8 command, uint32 lba, uint8 sectorCount)
fFis[5] = (lba >> 8) & 0xff; fFis[5] = (lba >> 8) & 0xff;
fFis[6] = (lba >> 16) & 0xff; fFis[6] = (lba >> 16) & 0xff;
fFis[7] = 0x40 | ((lba >> 24) & 0x0f); fFis[7] = 0x40 | ((lba >> 24) & 0x0f);
// device
fFis[12] = sectorCount & 0xff; fFis[12] = sectorCount & 0xff;
} }
@@ -83,6 +85,7 @@ sata_request::set_ata48_cmd(uint8 command, uint64 lba, uint16 sectorCount)
fFis[5] = (lba >> 8) & 0xff; fFis[5] = (lba >> 8) & 0xff;
fFis[6] = (lba >> 16) & 0xff; fFis[6] = (lba >> 16) & 0xff;
fFis[7] = 0x40; fFis[7] = 0x40;
// device
fFis[8] = (lba >> 24) & 0xff; fFis[8] = (lba >> 24) & 0xff;
fFis[9] = (lba >> 32) & 0xff; fFis[9] = (lba >> 32) & 0xff;
fFis[10] = (lba >> 40) & 0xff; fFis[10] = (lba >> 40) & 0xff;