xref: /haiku/src/add-ons/kernel/busses/usb/ehci.h (revision 9ecf9d1c1d4888d341a6eac72112c72d1ae3a4cb)
1 /*
2  * Copyright 2006, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz <mmlr@mlotz.ch>
7  */
8 
9 #ifndef EHCI_H
10 #define EHCI_H
11 
12 #include "usb_p.h"
13 #include "ehci_hardware.h"
14 
15 
16 struct pci_info;
17 struct pci_module_info;
18 class EHCIRootHub;
19 
20 
21 typedef struct transfer_data_s {
22 	Transfer		*transfer;
23 	ehci_qh			*queue_head;
24 	ehci_qtd		*first_descriptor;
25 	ehci_qtd		*data_descriptor;
26 	ehci_qtd		*last_descriptor;
27 	bool			incoming;
28 	transfer_data_s	*link;
29 } transfer_data;
30 
31 
32 class EHCI : public BusManager {
33 public:
34 									EHCI(pci_info *info, Stack *stack);
35 									~EHCI();
36 
37 		status_t					Start();
38 virtual	status_t					SubmitTransfer(Transfer *transfer);
39 virtual	status_t					SubmitRequest(Transfer *transfer);
40 
41 static	status_t					AddTo(Stack *stack);
42 
43 		// Port operations for root hub
44 		status_t					ResetPort(int32 index);
45 
46 private:
47 		// Controller resets
48 		status_t					ControllerReset();
49 		status_t					LightReset();
50 
51 		// Interrupt functions
52 static	int32						InterruptHandler(void *data);
53 		int32						Interrupt();
54 
55 		// Transfer management
56 		status_t					AddPendingTransfer(Transfer *transfer,
57 										ehci_qh *queueHead,
58 										ehci_qtd *firstDescriptor,
59 										ehci_qtd *dataDescriptor,
60 										ehci_qtd *lastDescriptor,
61 										bool directionIn);
62 		status_t					CancelPendingTransfer(Transfer *transfer);
63 		status_t					CancelAllPendingTransfers();
64 
65 static	int32						FinishThread(void *data);
66 		void						FinishTransfers();
67 
68 		// Descriptor functions
69 		ehci_qtd					*CreateDescriptor(Pipe *pipe,
70 										size_t bufferSizeToAllocate);
71 		status_t					CreateDescriptorChain(Pipe *pipe,
72 										ehci_qtd **firstDescriptor,
73 										ehci_qtd **lastDescriptor,
74 										size_t bufferSizeToAllocate);
75 
76 		void						FreeDescriptor(ehci_qtd *descriptor);
77 		void						FreeDescriptorChain(ehci_qtd *topDescriptor);
78 
79 		void						LinkDescriptors(ehci_qtd *first,
80 										ehci_qtd *last);
81 
82 		size_t						WriteDescriptorChain(ehci_qtd *topDescriptor,
83 										iovec *vector, size_t vectorCount);
84 		size_t						ReadDescriptorChain(ehci_qtd *topDescriptor,
85 										iovec *vector, size_t vectorCount,
86 										uint8 *lastDataToggle);
87 		size_t						ReadActualLength(ehci_qtd *topDescriptor,
88 										uint8 *lastDataToggle);
89 
90 		// Operational register functions
91 inline	void						WriteOpReg(uint32 reg, uint32 value);
92 inline	uint32						ReadOpReg(uint32 reg);
93 
94 		// Capability register functions
95 inline	uint8						ReadCapReg8(uint32 reg);
96 inline	uint16						ReadCapReg16(uint32 reg);
97 inline	uint32						ReadCapReg32(uint32 reg);
98 
99 static	pci_module_info				*sPCIModule;
100 
101 		uint8						*fCapabilityRegisters;
102 		uint8						*fOperationalRegisters;
103 		area_id						fRegisterArea;
104 		pci_info					*fPCIInfo;
105 		Stack						*fStack;
106 
107 		// Framelist memory
108 		area_id						fPeriodicFrameListArea;
109 		addr_t						*fPeriodicFrameList;
110 
111 		// Maintain a linked list of transfers
112 		transfer_data				*fFirstTransfer;
113 		transfer_data				*fLastTransfer;
114 		bool						fFinishTransfers;
115 		thread_id					fFinishThread;
116 		bool						fStopFinishThread;
117 
118 		// Root Hub
119 		EHCIRootHub					*fRootHub;
120 		uint8						fRootHubAddress;
121 };
122 
123 
124 class EHCIRootHub : public Hub {
125 public:
126 									EHCIRootHub(EHCI *ehci, int8 deviceAddress);
127 
128 		status_t					SubmitTransfer(Transfer *transfer);
129 		void						UpdatePortStatus();
130 
131 private:
132 		usb_port_status				fPortStatus[2];
133 		EHCI						*fEHCI;
134 };
135 
136 
137 #endif // !EHCI_H
138