Modules/USB - Bugfixes
[tpg/acess2.git] / Modules / USB / UHCI / uhci.h
1 /*
2  * AcessOS Version 1
3  * USB Stack
4  * - Universal Host Controller Interface
5  */
6 #ifndef _UHCI_H_
7 #define _UHCI_H_
8
9 // === TYPES ===
10 typedef struct sUHCI_Controller tUHCI_Controller;
11 typedef struct sUHCI_TD tUHCI_TD;
12 typedef struct sUHCI_QH tUHCI_QH;
13
14 // === STRUCTURES ===
15 struct sUHCI_Controller
16 {
17         /**
18          * \brief PCI Device ID
19          */
20         Uint16  PciId;
21         
22         /**
23          * \brief IO Base Address
24          */
25         Uint16  IOBase;
26         
27         /**
28          * \brief IRQ Number assigned to the device
29          */
30          int    IRQNum;
31
32         /**
33          * \brief Number of the last frame to be cleaned
34          */
35          int    LastCleanedFrame;
36         
37         /**
38          * \brief Frame list
39          * 
40          * 31:4 - Frame Pointer
41          * 3:2 - Reserved
42          * 1 - QH/TD Selector
43          * 0 - Terminate (Empty Pointer)
44          */
45         Uint32  *FrameList;
46         
47         /**
48          * \brief Physical Address of the Frame List
49          */
50         tPAddr  PhysFrameList;
51
52         tUSBHub *RootHub;
53 };
54
55 struct sUHCI_TD
56 {
57         /**
58          * \brief Next Entry in list
59          * 
60          * 31:4 - Address
61          * 3 - Reserved
62          * 2 - Depth/Breadth Select
63          * 1 - QH/TD Select
64          * 0 - Terminate (Last in List)
65          */
66         Uint32  Link;
67         
68         /**
69          * \brief Control and Status Field
70          * 
71          * 31:30 - Reserved
72          * 29 - Short Packet Detect (Input Only)
73          * 28:27 - Number of Errors Allowed
74          * 26 - Low Speed Device (Communicating with a low speed device)
75          * 25 - Isynchonious Select
76          * 24 - Interrupt on Completion (IOC)
77          * 23:16 - Status
78          *     23 - Active
79          *     22 - Stalled
80          *     21 - Data Buffer Error
81          *     20 - Babble Detected
82          *     19 - NAK Detected
83          *     18 - CRC/Timout Error
84          *     17 - Bitstuff Error
85          *     16 - Reserved
86          * 15:11 - Reserved
87          * 10:0 - Actual Length (Number of bytes transfered)
88          */
89         Uint32  Control;
90         
91         /**
92          * \brief Packet Header
93          * 
94          * 31:21 - Maximum Length (0=1, Max 0x4FF, 0x7FF=0)
95          * 20 - Reserved
96          * 19 - Data Toggle
97          * 18:15 - Endpoint
98          * 14:8 - Device Address
99          * 7:0 - PID (Packet Identifcation) - Only 96, E1, 2D allowed
100          *
101          * 0x96 = Data IN
102          * 0xE1 = Data Out
103          * 0x2D = Setup
104          */
105         Uint32  Token;
106         
107         /**
108          * \brief Pointer to the data to send
109          */
110         Uint32  BufferPointer;
111
112         struct
113         {
114                 tUSBHostCb      Callback;
115                 void    *CallbackPtr;
116                 void    *DataPtr;
117                  int    bCopyData;
118         } _info;
119 } __attribute__((aligned(16)));
120
121 struct sUHCI_QH
122 {
123         /**
124          * \brief Next Entry in list
125          * 
126          * 31:4 - Address
127          * 3:2 - Reserved
128          * 1 - QH/TD Select
129          * 0 - Terminate (Last in List)
130          */
131         Uint32  Next;
132
133         
134         /**
135          * \brief Next Entry in list
136          * 
137          * 31:4 - Address
138          * 3:2 - Reserved
139          * 1 - QH/TD Select
140          * 0 - Terminate (Last in List)
141          */
142         Uint32  Child;
143 };
144
145 // === ENUMERATIONS ===
146 enum eUHCI_IOPorts {
147         /**
148          * \brief USB Command Register
149          * 
150          * 15:8 - Reserved
151          * 7 - Maximum Packet Size selector (1: 64 bytes, 0: 32 bytes)
152          * 6 - Configure Flag (No Hardware Effect)
153          * 5 - Software Debug (Don't think it will be needed)
154          * 4 - Force Global Resume
155          * 3 - Enter Global Suspend Mode
156          * 2 - Global Reset (Resets all devices on the bus)
157          * 1 - Host Controller Reset (Reset just the controller)
158          * 0 - Run/Stop
159          */
160         USBCMD  = 0x00,
161         /**
162          * \brief USB Status Register
163          * 
164          * 15:6 - Reserved
165          * 5 - HC Halted, set to 1 when USBCMD:RS is set to 0
166          * 4 - Host Controller Process Error (Errors related to the bus)
167          * 3 - Host System Error (Errors related to the OS/PCI Bus)
168          * 2 - Resume Detect (Set if a RESUME command is sent to the Controller)
169          * 1 - USB Error Interrupt
170          * 0 - USB Interrupts (Set if a transaction with the IOC bit set is completed)
171          */
172         USBSTS  = 0x02,
173         /**
174          * \brief USB Interrupt Enable Register
175          * 
176          * 15:4 - Reserved
177          * 3 - Short Packet Interrupt Enable
178          * 2 - Interrupt on Complete (IOC) Enable
179          * 1 - Resume Interrupt Enable
180          * 0 - Timout / CRC Error Interrupt Enable
181          */
182         USBINTR = 0x04,
183         /**
184          * \brief Frame Number (Index into the Frame List)
185          * 
186          * 15:11 - Reserved
187          * 10:0 - Index (Incremented each approx 1ms)
188          */
189         FRNUM   = 0x06,
190         /**
191          * \brief Frame List Base Address
192          * 
193          * 31:12 - Pysical Address >> 12
194          * 11:0 - Reserved (Set to Zero)
195          */
196         FLBASEADD = 0x08,       // 32-bit
197         /**
198          * \brief Start-of-frame Modify Register
199          * \note 8-bits only
200          * 
201          * Sets the size of a frame
202          * Frequency = (11936+n)/12000 kHz
203          * 
204          * 7 - Reserved
205          * 6:0 -
206          */
207         SOFMOD = 0x0C,  // 8bit
208         /**
209          * \brief Port Status and Controll Register (Port 1)
210          * 
211          * 15:13 - Reserved
212          * 12 - Suspend
213          * 11:10 - Reserved
214          * 9 - Port Reset
215          * 8 - Low Speed Device Attached
216          * 5:4 - Line Status
217          * 3 - Port Enable/Disable Change - Used for detecting device removal
218          * 2 - Port Enable/Disable
219          * 1 - Connect Status Change
220          * 0 - Current Connect Status
221          */
222         PORTSC1 = 0x10,
223         /**
224          * \brief Port Status and Controll Register (Port 2)
225          * 
226          * See ::PORTSC1
227          */
228         PORTSC2 = 0x12
229 };
230
231 #endif

UCC git Repository :: git.ucc.asn.au