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

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