1 /* 2 * Copyright 2008, Marcus Overhagen. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _SATA_REQUEST_H 6 #define _SATA_REQUEST_H 7 8 9 #include "ahci_defs.h" 10 #include "scsi_cmds.h" 11 12 13 class sata_request { 14 public: 15 sata_request(); 16 sata_request(scsi_ccb* ccb); 17 ~sata_request(); 18 19 void SetData(void* data, size_t dataSize); 20 21 void SetATACommand(uint8 command); 22 void SetATA28Command(uint8 command, uint32 lba, 23 uint8 sectorCount); 24 void SetATA48Command(uint8 command, uint64 lba, 25 uint16 sectorCount); 26 void SetFeature(uint16 feature); 27 28 void SetATAPICommand(size_t transferLength); 29 bool IsATAPI(); 30 bool IsTestUnitReady(); 31 32 scsi_ccb* CCB(); 33 const void* FIS(); 34 void* Data(); 35 int Size(); 36 void Finish(int tfd, size_t bytesTransfered); 37 void Abort(); 38 39 void WaitForCompletion(); 40 int CompletionStatus(); 41 42 private: 43 scsi_ccb* fCcb; 44 uint8 fFis[20]; 45 bool fIsATAPI; 46 sem_id fCompletionSem; 47 int fCompletionStatus; 48 void* fData; 49 size_t fDataSize; 50 }; 51 52 53 inline scsi_ccb* CCB()54sata_request::CCB() 55 { 56 return fCcb; 57 } 58 59 60 inline const void* FIS()61sata_request::FIS() 62 { 63 return fFis; 64 } 65 66 67 inline bool IsATAPI()68sata_request::IsATAPI() 69 { 70 return fIsATAPI; 71 } 72 73 74 inline bool IsTestUnitReady()75sata_request::IsTestUnitReady() 76 { 77 return fIsATAPI && fCcb != NULL && fCcb->cdb[0] == SCSI_OP_TEST_UNIT_READY; 78 } 79 80 81 inline void* Data()82sata_request::Data() 83 { 84 return fData; 85 } 86 87 88 inline int Size()89sata_request::Size() 90 { 91 return fDataSize; 92 } 93 94 95 #endif /* _SATA_REQUEST_H */ 96