1 /* 2 * Copyright 2007-2008, Marcus Overhagen. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _AHCI_PORT_H 6 #define _AHCI_PORT_H 7 8 #include "ahci_defs.h" 9 10 class AHCIController; 11 class sata_request; 12 13 class AHCIPort { 14 public: 15 AHCIPort(AHCIController *controller, int index); 16 ~AHCIPort(); 17 18 status_t Init1(); 19 status_t Init2(); 20 void Uninit(); 21 22 void Interrupt(); 23 void InterruptErrorHandler(uint32 is); 24 25 26 void ScsiExecuteRequest(scsi_ccb *request); 27 uchar ScsiAbortRequest(scsi_ccb *request); 28 uchar ScsiTerminateRequest(scsi_ccb *request); 29 uchar ScsiResetDevice(); 30 void ScsiGetRestrictions(bool *isATAPI, bool *noAutoSense, uint32 *maxBlocks); 31 32 private: 33 void ScsiTestUnitReady(scsi_ccb *request); 34 void ScsiInquiry(scsi_ccb *request); 35 void ScsiReadCapacity(scsi_ccb *request); 36 void ScsiReadCapacity16(scsi_ccb *request); 37 void ScsiReadWrite(scsi_ccb *request, uint64 lba, size_t sectorCount, bool isWrite); 38 void ScsiSynchronizeCache(scsi_ccb *request); 39 void ScsiUnmap(scsi_ccb* request, 40 struct scsi_unmap_parameter_list* unmapBlocks); 41 42 void ExecuteSataRequest(sata_request *request, bool isWrite = false); 43 44 void ResetDevice(); 45 status_t ResetPort(bool forceDeviceReset = false); 46 status_t PostReset(); 47 void FlushPostedWrites(); 48 void DumpD2HFis(); 49 50 void StartTransfer(); 51 status_t WaitForTransfer(int *tfd, bigtime_t timeout); 52 void FinishTransfer(); 53 54 55 // uint8 * SetCommandFis(volatile command_list_entry *cmd, volatile fis *fis, const void *data, size_t dataSize); 56 status_t FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, const void *data, size_t dataSize); 57 status_t FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, const physical_entry *sgTable, int sgCount, size_t dataSize); 58 59 private: 60 AHCIController* fController; 61 int fIndex; 62 volatile ahci_port * fRegs; 63 area_id fArea; 64 spinlock fSpinlock; 65 volatile uint32 fCommandsActive; 66 sem_id fRequestSem; 67 sem_id fResponseSem; 68 bool fDevicePresent; 69 bool fUse48BitCommands; 70 uint32 fSectorSize; 71 uint64 fSectorCount; 72 bool fIsATAPI; 73 bool fTestUnitReadyActive; 74 bool fResetPort; 75 bool fError; 76 bool fTrimSupported; 77 uint32 fMaxTrimRangeBlocks; 78 79 volatile fis * fFIS; 80 volatile command_list_entry * fCommandList; 81 volatile command_table * fCommandTable; 82 volatile prd * fPRDTable; 83 }; 84 85 inline void 86 AHCIPort::FlushPostedWrites() 87 { 88 volatile uint32 dummy = fRegs->cmd; 89 dummy = dummy; 90 } 91 #endif // _AHCI_PORT_H 92