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 9 #include <ATAInfoBlock.h> 10 11 #include "ahci_defs.h" 12 13 14 class AHCIController; 15 class sata_request; 16 17 class AHCIPort { 18 public: 19 AHCIPort(AHCIController *controller, int index); 20 ~AHCIPort(); 21 22 status_t Init1(); 23 status_t Init2(); 24 void Uninit(); 25 26 void Interrupt(); 27 void InterruptErrorHandler(uint32 is); 28 29 30 void ScsiExecuteRequest(scsi_ccb *request); 31 uchar ScsiAbortRequest(scsi_ccb *request); 32 uchar ScsiTerminateRequest(scsi_ccb *request); 33 uchar ScsiResetDevice(); 34 void ScsiGetRestrictions(bool *isATAPI, bool *noAutoSense, uint32 *maxBlocks); 35 36 private: 37 void ScsiTestUnitReady(scsi_ccb *request); 38 void ScsiInquiry(scsi_ccb *request); 39 void ScsiVPDInquiry(scsi_ccb* request, ata_device_infoblock* ataData); 40 41 void ScsiReadCapacity(scsi_ccb *request); 42 void ScsiReadCapacity16(scsi_ccb *request); 43 void ScsiReadWrite(scsi_ccb *request, uint64 lba, size_t sectorCount, bool isWrite); 44 void ScsiSynchronizeCache(scsi_ccb *request); 45 void ScsiUnmap(scsi_ccb* request, 46 struct scsi_unmap_parameter_list* unmapBlocks); 47 48 void ExecuteSataRequest(sata_request *request, bool isWrite = false); 49 50 void ResetDevice(); 51 status_t SoftReset(); 52 status_t PortReset(); 53 status_t Probe(); 54 55 bool Enable(); 56 bool Disable(); 57 58 void FlushPostedWrites(); 59 void DumpD2HFis(); 60 void DumpHBAState(); 61 62 void StartTransfer(); 63 status_t WaitForTransfer(int *tfd, bigtime_t timeout); 64 void FinishTransfer(); 65 66 inline void _ClearErrorRegister(); 67 68 // uint8 * SetCommandFis(volatile command_list_entry *cmd, volatile fis *fis, const void *data, size_t dataSize); 69 status_t FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, const void *data, size_t dataSize); 70 status_t FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, const physical_entry *sgTable, int sgCount, size_t dataSize); 71 72 private: 73 AHCIController* fController; 74 int fIndex; 75 volatile ahci_port * fRegs; 76 area_id fArea; 77 spinlock fSpinlock; 78 volatile uint32 fCommandsActive; 79 sem_id fRequestSem; 80 sem_id fResponseSem; 81 bool fDevicePresent; 82 bool fUse48BitCommands; 83 uint32 fSectorSize; 84 uint64 fSectorCount; 85 bool fIsATAPI; 86 bool fTestUnitReadyActive; 87 bool fSoftReset; 88 bool fError; 89 bool fTrimSupported; 90 uint32 fMaxTrimRangeBlocks; 91 92 volatile fis * fFIS; 93 volatile command_list_entry * fCommandList; 94 volatile command_table * fCommandTable; 95 volatile prd * fPRDTable; 96 }; 97 98 99 inline void 100 AHCIPort::FlushPostedWrites() 101 { 102 volatile uint32 dummy = fRegs->cmd; 103 dummy = dummy; 104 } 105 106 107 #endif // _AHCI_PORT_H 108