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

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