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

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