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