xref: /haiku/src/add-ons/kernel/busses/scsi/ahci/ahci_port.h (revision 8a04709a1d4086fecf352cc079c97e394f1a4ba3)
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 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 
24 
25 	void		ScsiExecuteRequest(scsi_ccb *request);
26 	uchar		ScsiAbortRequest(scsi_ccb *request);
27 	uchar		ScsiTerminateRequest(scsi_ccb *request);
28 	uchar		ScsiResetDevice();
29 	void		ScsiGetRestrictions(bool *isATAPI, bool *noAutoSense, uint32 *maxBlocks);
30 
31 private:
32 	void		ScsiTestUnitReady(scsi_ccb *request);
33 	void		ScsiInquiry(scsi_ccb *request);
34 	void		ScsiReadCapacity(scsi_ccb *request);
35 	void		ScsiReadWrite(scsi_ccb *request, uint64 lba, size_t sectorCount, bool isWrite);
36 	void		ScsiSynchronizeCache(scsi_ccb *request);
37 
38 	void		ExecuteSataRequest(sata_request *request, bool isWrite = false);
39 
40 	status_t	ResetDevice();
41 	status_t	PostResetDevice();
42 	void		FlushPostedWrites();
43 	void		DumpD2HFis();
44 
45 	void		StartTransfer();
46 	status_t	WaitForTransfer(int *tfd, bigtime_t timeout);
47 	void		FinishTransfer();
48 
49 
50 //	uint8 *		SetCommandFis(volatile command_list_entry *cmd, volatile fis *fis, const void *data, size_t dataSize);
51 	status_t	FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, const void *data, size_t dataSize);
52 	status_t	FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, const physical_entry *sgTable, int sgCount, size_t dataSize);
53 
54 private:
55 	int						fIndex;
56 	volatile ahci_port *	fRegs;
57 	area_id					fArea;
58 	spinlock						fSpinlock;
59 	volatile uint32					fCommandsActive;
60 	sem_id							fRequestSem;
61 	sem_id							fResponseSem;
62 	bool							fDevicePresent;
63 	bool							fUse48BitCommands;
64 	uint32							fSectorSize;
65 	uint64							fSectorCount;
66 
67 	volatile fis *					fFIS;
68 	volatile command_list_entry *	fCommandList;
69 	volatile command_table *		fCommandTable;
70 	volatile prd *					fPRDTable;
71 };
72 
73 inline void
74 AHCIPort::FlushPostedWrites()
75 {
76 	volatile uint32 dummy = fRegs->cmd;
77 	dummy = dummy;
78 }
79 #endif	// _AHCI_PORT_H
80