xref: /haiku/src/add-ons/kernel/busses/scsi/ahci/sata_request.h (revision 73ad2473e7874b3702cf5b0fdf4c81b747812ed9)
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 #include "ahci_defs.h"
9 #include "scsi_cmds.h"
10 
11 class sata_request
12 {
13 public:
14 					sata_request();
15 					sata_request(scsi_ccb *ccb);
16 					~sata_request();
17 
18 	void			set_data(void *data, size_t dataSize);
19 
20 	void			set_ata_cmd(uint8 command);
21 	void			set_ata28_cmd(uint8 command, uint32 lba, uint8 sectorCount);
22 	void			set_ata48_cmd(uint8 command, uint64 lba, uint16 sectorCount);
23 
24 	void			set_atapi_cmd(size_t transferLength);
25 	bool 			is_atapi();
26 	bool			is_test_unit_ready();
27 
28 	scsi_ccb *		ccb();
29 	const void *	fis();
30 	void *			data();
31 	int				size();
32 	void			finish(int tfd, size_t bytesTransfered);
33 	void			abort();
34 
35 	void			wait_for_completion();
36 	int				completion_status();
37 
38 private:
39 	scsi_ccb *		fCcb;
40 	uint8			fFis[20];
41 	bool			fIsATAPI;
42 	sem_id			fCompletionSem;
43 	int				fCompletionStatus;
44 	void *			fData;
45 	size_t			fDataSize;
46 };
47 
48 
49 inline scsi_ccb *
50 sata_request::ccb()
51 {
52 	return fCcb;
53 }
54 
55 
56 inline const void *
57 sata_request::fis()
58 {
59 	return fFis;
60 }
61 
62 
63 inline bool
64 sata_request::is_atapi()
65 {
66 	return fIsATAPI;
67 }
68 
69 
70 inline bool
71 sata_request::is_test_unit_ready()
72 {
73 	return fIsATAPI && fCcb != NULL && fCcb->cdb[0] == SCSI_OP_TEST_UNIT_READY;
74 }
75 
76 
77 inline void *
78 sata_request::data()
79 {
80 	return fData;
81 }
82 
83 
84 inline int
85 sata_request::size()
86 {
87 	return fDataSize;
88 }
89 
90 
91 #endif
92