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