1 /* 2 * Copyright 2007, 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 12 class AHCIPort { 13 public: 14 AHCIPort(AHCIController *controller, int index); 15 ~AHCIPort(); 16 17 status_t Init1(); 18 status_t Init2(); 19 void Uninit(); 20 21 void Interrupt(); 22 23 24 void ScsiExecuteRequest(scsi_ccb *request); 25 uchar ScsiAbortRequest(scsi_ccb *request); 26 uchar ScsiTerminateRequest(scsi_ccb *request); 27 uchar ScsiResetDevice(); 28 29 private: 30 void ScsiTestUnitReady(scsi_ccb *request); 31 void ScsiInquiry(scsi_ccb *request); 32 void ScsiReadCapacity(scsi_ccb *request); 33 void ScsiReadWrite(scsi_ccb *request, uint64 position, size_t length, bool isWrite); 34 35 status_t ResetDevice(); 36 status_t PostResetDevice(); 37 void FlushPostedWrites(); 38 void DumpD2HFis(); 39 40 void StartTransfer(); 41 status_t WaitForTransfer(int *tfd, bigtime_t timeout); 42 void FinishTransfer(); 43 44 45 // uint8 * SetCommandFis(volatile command_list_entry *cmd, volatile fis *fis, const void *data, size_t dataSize); 46 status_t FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, const void *data, size_t dataSize); 47 status_t FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, const physical_entry *sgTable, int sgCount, size_t dataSize); 48 49 private: 50 int fIndex; 51 volatile ahci_port * fRegs; 52 area_id fArea; 53 spinlock fSpinlock; 54 volatile uint32 fCommandsActive; 55 sem_id fRequestSem; 56 sem_id fResponseSem; 57 bool fDevicePresent; 58 bool fUse48BitCommands; 59 uint32 fSectorSize; 60 uint64 fSectorCount; 61 62 volatile fis * fFIS; 63 volatile command_list_entry * fCommandList; 64 volatile command_table * fCommandTable; 65 volatile prd * fPRDTable; 66 }; 67 68 inline void 69 AHCIPort::FlushPostedWrites() 70 { 71 volatile uint32 dummy = fRegs->cmd; 72 dummy = dummy; 73 } 74 #endif // _AHCI_PORT_H 75