xref: /haiku/src/add-ons/kernel/busses/usb/ohci.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2005, Jan-Rixt Van Hoye
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //-------------------------------------------------------------------------------
22 
23 
24 #ifndef OHCI_H
25 #define OHCI_H
26 
27 //	---------------------------
28 //	OHCI::	Includes
29 //	---------------------------
30 
31 #include "usb_p.h"
32 #include "ohci_software.h"
33 
34 struct pci_info;
35 struct pci_module_info;
36 class OHCIRootHub;
37 struct Endpoint;
38 struct TransferDescriptor;
39 
40 // --------------------------------
41 //	OHCI: 	The OHCI class derived
42 //			from the BusManager
43 // --------------------------------
44 
45 class OHCI : public BusManager
46 {
47 	friend class OHCIRootHub;
48 public:
49 
50 	OHCI(pci_info *info, Stack *stack);
51 	~OHCI();
52 	status_t					Start();
53 	status_t 					SubmitTransfer(Transfer *t); 	//Override from BusManager.
54 	status_t					NotifyPipeChange(Pipe *pipe,    //Override from BusManager.
55 								                 usb_change change);
56 
57 	static pci_module_info 		*pci_module; 					// Global data for the module.
58 
59 	status_t GetPortStatus(uint8 index, usb_port_status *status);
60 	status_t ClearPortFeature(uint8 index, uint16 feature);
61 	status_t SetPortFeature(uint8 index, uint16 feature);
62 
63 	uint8 PortCount() { return fNumPorts; };
64 
65 private:
66 	inline void   WriteReg(uint32 reg, uint32 value);
67 	inline uint32 ReadReg(uint32 reg);
68 
69 	// Global
70 	pci_info 					*fPcii;					// pci-info struct
71 	Stack 						*fStack;				// Pointer to the stack
72 	uint8						*fRegisters;			// Base address of the operational registers
73 	area_id						fRegisterArea;			// Area id of the
74 	// HCCA
75 	area_id						fHccaArea;
76 	struct ohci_hcca			*fHcca;					// The HCCA structure for the interupt communication
77 	Endpoint					*fInterruptEndpoints[OHCI_NO_EDS];	// The interrupt endpoint list
78 	// Dummy endpoints
79 	Endpoint					*fDummyControl;
80 	Endpoint					*fDummyBulk;
81 	Endpoint					*fDummyIsochronous;
82 	// Root Hub
83 	OHCIRootHub 				*fRootHub;				// the root hub
84 	uint8						fRootHubAddress;		// the usb address of the roothub
85 	uint8						fNumPorts;				// the number of ports
86 	// functions
87 	Endpoint					*AllocateEndpoint(); 	// allocate memory for an endpoint
88 	void						FreeEndpoint(Endpoint *end); // Free endpoint
89 	TransferDescriptor			*AllocateTransfer();    // create a NULL transfer
90 	void						FreeTransfer(TransferDescriptor *trans); // Free transfer
91 
92 	status_t					InsertEndpointForPipe(Pipe *p);
93 };
94 
95 // --------------------------------
96 //	OHCI:	The root hub of the OHCI
97 //			controller derived from
98 //			the Hub class
99 // --------------------------------
100 
101 class OHCIRootHub : public Hub
102 {
103 	public:
104 		OHCIRootHub(OHCI *ohci, int8 deviceAddress);
105 		status_t 			ProcessTransfer(Transfer *t, OHCI *ohci);
106 };
107 
108 //
109 // Endpoint: wrapper around the hardware endpoints
110 //
111 
112 struct Endpoint
113 {
114 	addr_t						physicaladdress;//Point to the physical address
115 	ohci_endpoint_descriptor	*ed;			//Logical 'endpoint'
116 	Endpoint					*next;			//Pointer to the 'next' endpoint
117 	TransferDescriptor			*head, *tail;	//Pointers to the 'head' and 'tail' transfer descriptors
118 
119 	//Utility functions
120 	void SetNext(Endpoint *end) {
121 		next = end;
122 		if (end == 0)
123 			ed->next_endpoint = 0;
124 		else
125 			ed->next_endpoint = end->physicaladdress;
126 	};
127 
128 	//Constructor (or better: initialiser)
129 	Endpoint() : physicaladdress(0), ed(0), next(0), head(0), tail(0) {};
130 };
131 
132 struct TransferDescriptor
133 {
134 	addr_t						physicaladdress;
135 	ohci_transfer_descriptor	*td;
136 };
137 
138 #endif // OHCI_H
139