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

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