LibXenon
Bare-metal Xbox 360 homebrew library
Loading...
Searching...
No Matches
ehci.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 Kwiirk
3 * Original Copyright (c) 2001-2002 by David Brownell
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
20#ifndef __LINUX_EHCI_HCD_H
21#define __LINUX_EHCI_HCD_H
23#include "ehci_types.h"
24
25/* definitions used for the EHCI driver */
27/*
28 * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to
29 * __leXX (normally) or __beXX (given EHCI_BIG_ENDIAN_DESC), depending on
30 * the host controller implementation.
31 *
32 * To facilitate the strongest possible byte-order checking from "sparse"
33 * and so on, we use __leXX unless that's not practical.
34 */
35#ifdef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
36typedef __u32 __bitwise __hc32;
37typedef __u16 __bitwise __hc16;
38#else
39#define __hc32 __le32
40#define __hc16 __le16
41#endif
42
43struct ehci_hcd;
44
45#define EHCI_MAX_ROOT_PORTS 8 /* see HCS_N_PORTS */
46#define EHCI_MAX_QTD 8
47#include "usb.h"
48
51 int id;
52 int port;
53 int fd;
55 int busy;
56};
57#define ep_bit(ep) (((ep)&0xf)+(((ep)>>7)?16:0))
58#define get_toggle(dev,ep) (((dev)->toggles>>ep_bit(ep))&1)
59#define set_toggle(dev,ep,v) (dev)->toggles = ((dev)->toggles &(~(1<<ep_bit(ep)))) | ((v)<<ep_bit(ep))
60
61struct ehci_urb {
64
69
73};
74
75struct ehci_hcd { /* one per controller */
76 /* glue to PCI and HCD framework */
81 void *device;
82 __u32 hcs_params; /* cached register copy */
83
84 /* async schedule support */
85 struct ehci_qh *async; // the head never gets a qtd inside.
87
90 unsigned long next_statechange;
92
93 /* HW need periodic table initialised even if we dont use it @todo:is it really true? */
94#define DEFAULT_I_TDPS 1024 /* some HCs can do less */
95 __hc32 *periodic; /* hw periodic table */
97
99 struct ehci_device devices[EHCI_MAX_ROOT_PORTS]; /* the attached device list per port */
100 void *ctrl_buffer; /* pre allocated buffer for control messages */
101
103};
104/*-------------------------------------------------------------------------*/
105
106#include "ehci_defs.h"
107
108/*-------------------------------------------------------------------------*/
109#define QTD_NEXT( dma) cpu_to_hc32( (u32)dma)
110
111/*
112 * EHCI Specification 0.95 Section 3.5
113 * QTD: describe data transfer components (buffer, direction, ...)
114 * See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
115 *
116 * These are associated only with "QH" (Queue Head) structures,
117 * used with control, bulk, and interrupt transfers.
118 */
119struct ehci_qtd {
120 /* first part defined by EHCI spec */
121 __hc32 hw_next; /* see EHCI 3.5.1 */
122 __hc32 hw_alt_next; /* see EHCI 3.5.2 */
123 __hc32 hw_token; /* see EHCI 3.5.3 */
124#define QTD_TOGGLE (1 << 31) /* data toggle */
125#define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
126#define QTD_IOC (1 << 15) /* interrupt on complete */
127#define QTD_CERR(tok) (((tok)>>10) & 0x3)
128#define QTD_PID(tok) (((tok)>>8) & 0x3)
129#define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */
130#define QTD_STS_HALT (1 << 6) /* halted on error */
131#define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */
132#define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */
133#define QTD_STS_XACT (1 << 3) /* device gave illegal response */
134#define QTD_STS_MMF (1 << 2) /* incomplete split transaction */
135#define QTD_STS_STS (1 << 1) /* split transaction state */
136#define QTD_STS_PING (1 << 0) /* issue PING? */
137
138#define ACTIVE_BIT(ehci) cpu_to_hc32( QTD_STS_ACTIVE)
139#define HALT_BIT(ehci) cpu_to_hc32( QTD_STS_HALT)
140#define STATUS_BIT(ehci) cpu_to_hc32( QTD_STS_STS)
141
142 __hc32 hw_buf [5]; /* see EHCI 3.5.4 */
143 __hc32 hw_buf_hi [5]; /* Appendix B */
144
145 /* the rest is HCD-private */
146 dma_addr_t qtd_dma; /* qtd address */
147 struct ehci_qtd *next; /* sw qtd list */
148 struct ehci_urb *urb; /* qtd's urb */
149 size_t length; /* length of buffer */
150} __attribute__((aligned(32)));
151
152/* mask NakCnt+T in qh->hw_alt_next */
153#define QTD_MASK(ehci) cpu_to_hc32 ( ~0x1f)
154
155#define IS_SHORT_READ(token) (QTD_LENGTH (token) != 0 && QTD_PID (token) == 1)
156
157/*-------------------------------------------------------------------------*/
158
159/* type tag from {qh,itd,sitd,fstn}->hw_next */
160#define Q_NEXT_TYPE(dma) ((dma) & cpu_to_hc32( 3 << 1))
161
162/*
163 * Now the following defines are not converted using the
164 * __constant_cpu_to_le32() macro anymore, since we have to support
165 * "dynamic" switching between be and le support, so that the driver
166 * can be used on one system with SoC EHCI controller using big-endian
167 * descriptors as well as a normal little-endian PCI EHCI controller.
168 */
169/* values for that type tag */
170#define Q_TYPE_ITD (0 << 1)
171#define Q_TYPE_QH (1 << 1)
172#define Q_TYPE_SITD (2 << 1)
173#define Q_TYPE_FSTN (3 << 1)
174
175/* next async queue entry, or pointer to interrupt/periodic QH */
176#define QH_NEXT(dma) (cpu_to_hc32( (((u32)dma)&~0x01f)|Q_TYPE_QH))
177
178/* for periodic/async schedules and qtd lists, mark end of list */
179#define EHCI_LIST_END() cpu_to_hc32( 1) /* "null pointer" to hw */
180
181/*
182 * Entries in periodic shadow table are pointers to one of four kinds
183 * of data structure. That's dictated by the hardware; a type tag is
184 * encoded in the low bits of the hardware's periodic schedule. Use
185 * Q_NEXT_TYPE to get the tag.
186 *
187 * For entries in the async schedule, the type tag always says "qh".
188 */
190 struct ehci_qh *qh; /* Q_TYPE_QH */
191 struct ehci_itd *itd; /* Q_TYPE_ITD */
192 struct ehci_sitd *sitd; /* Q_TYPE_SITD */
193 struct ehci_fstn *fstn; /* Q_TYPE_FSTN */
194 __hc32 *hw_next; /* (all types) */
195 void *ptr;
197
198/*-------------------------------------------------------------------------*/
199
200/*
201 * EHCI Specification 0.95 Section 3.6
202 * QH: describes control/bulk/interrupt endpoints
203 * See Fig 3-7 "Queue Head Structure Layout".
204 *
205 * These appear in both the async and (for interrupt) periodic schedules.
206 */
207
208struct ehci_qh {
209 /* first part defined by EHCI spec */
210 __hc32 hw_next; /* see EHCI 3.6.1 */
211 __hc32 hw_info1; /* see EHCI 3.6.2 */
212#define QH_HEAD 0x00008000
213 __hc32 hw_info2; /* see EHCI 3.6.2 */
214#define QH_SMASK 0x000000ff
215#define QH_CMASK 0x0000ff00
216#define QH_HUBADDR 0x007f0000
217#define QH_HUBPORT 0x3f800000
218#define QH_MULT 0xc0000000
219 __hc32 hw_current; /* qtd list - see EHCI 3.6.4 */
220
221 /* qtd overlay (hardware parts of a struct ehci_qtd) */
227
228 /* the rest is HCD-private */
229 dma_addr_t qh_dma; /* address of qh */
230 struct ehci_qtd *qtd_head; /* sw qtd list */
231
232 struct ehci_hcd *ehci;
233
234#define NO_FRAME ((unsigned short)~0) /* pick new start */
235} __attribute__((aligned(32)));
236
237/*-------------------------------------------------------------------------*/
238
239
240
241/*-------------------------------------------------------------------------*/
242
243/* cpu to ehci */
244#define cpu_to_hc32(b) cpu_to_le32(b)
245#define hc32_to_cpu(b) le32_to_cpu(b)
246#define hc32_to_cpup(b) le32_to_cpu(*(b))
247
248/*-------------------------------------------------------------------------*/
249
250/* os specific functions */
251void*ehci_maligned(int size, int alignement, int crossing);
253dma_addr_t ehci_dma_map_to(void *buf, size_t len);
254dma_addr_t ehci_dma_map_from(void *buf, size_t len);
255dma_addr_t ehci_dma_map_bidir(void *buf, size_t len);
256void ehci_dma_unmap_to(dma_addr_t buf, size_t len);
257void ehci_dma_unmap_from(dma_addr_t buf, size_t len);
258void ehci_dma_unmap_bidir(dma_addr_t buf, size_t len);
259void ehci_usleep(int time);
260void ehci_msleep(int time);
261
262
263/* extern API */
264
265s32 ehci_control_message(struct ehci_hcd * ehci, struct ehci_device *dev, u8 bmRequestType, u8 bmRequest, u16 wValue, u16 wIndex, u16 wLength, void *buf);
266s32 ehci_bulk_message(struct ehci_hcd * ehci, struct ehci_device *dev, u8 bEndpoint, u16 wLength, void *rpData);
267int ehci_discover(struct ehci_hcd * ehci);
268int ehci_get_device_list(struct ehci_hcd * ehci, u8 maxdev, u8 b0, u8*num, u16*buf);
269
270int ehci_reset_port2(struct ehci_hcd * ehci, int port);
271
272extern int ehci_open_device(struct ehci_hcd * ehci, int vid, int pid, int fd);
273extern int ehci_close_device(struct ehci_device *dev);
274extern void * ehci_fd_to_dev(struct ehci_hcd * ehci, int fd);
275extern int ehci_release_ports(struct ehci_hcd * ehci);
276
277/* UMS API */
278
279s32 USBStorage_Init(void);
280//s32 USBStorage_Get_Capacity(u32*sector_size);
281s32 USBStorage_Read_Sectors(int device, u32 sector, u32 numSectors, void *buffer);
282s32 USBStorage_Read_Stress(u32 sector, u32 numSectors, void *buffer);
283s32 USBStorage_Write_Sectors(int device, u32 sector, u32 numSectors, const void *buffer);
284
285#ifndef DEBUG
286#define STUB_DEBUG_FILES
287#endif /* DEBUG */
288
289/*-------------------------------------------------------------------------*/
290
291#endif /* __LINUX_EHCI_HCD_H */
#define __hc32
Definition: ehci.h:39
int ehci_release_ports(struct ehci_hcd *ehci)
Definition: ehci.c:998
s32 ehci_control_message(struct ehci_hcd *ehci, struct ehci_device *dev, u8 bmRequestType, u8 bmRequest, u16 wValue, u16 wIndex, u16 wLength, void *buf)
Definition: ehci.c:651
#define EHCI_MAX_ROOT_PORTS
Definition: ehci.h:45
dma_addr_t ehci_dma_map_bidir(void *buf, size_t len)
Definition: usb_os.c:84
s32 USBStorage_Read_Stress(u32 sector, u32 numSectors, void *buffer)
int ehci_open_device(struct ehci_hcd *ehci, int vid, int pid, int fd)
Definition: ehci.c:1013
void * ehci_fd_to_dev(struct ehci_hcd *ehci, int fd)
Definition: ehci.c:1034
int ehci_close_device(struct ehci_device *dev)
Definition: ehci.c:1028
dma_addr_t ehci_dma_map_to(void *buf, size_t len)
Definition: usb_os.c:72
void ehci_dma_unmap_bidir(dma_addr_t buf, size_t len)
Definition: usb_os.c:100
#define EHCI_MAX_QTD
Definition: ehci.h:46
dma_addr_t ehci_dma_map_from(void *buf, size_t len)
Definition: usb_os.c:78
s32 USBStorage_Init(void)
Definition: usbstorage.c:1215
int ehci_reset_port2(struct ehci_hcd *ehci, int port)
Definition: ehci.c:966
s32 USBStorage_Write_Sectors(int device, u32 sector, u32 numSectors, const void *buffer)
Definition: usbstorage.c:1378
#define __hc16
Definition: ehci.h:40
void * ehci_maligned(int size, int alignement, int crossing)
Definition: usb_os.c:41
int ehci_get_device_list(struct ehci_hcd *ehci, u8 maxdev, u8 b0, u8 *num, u16 *buf)
Definition: ehci.c:1048
void ehci_msleep(int time)
Definition: usb_os.c:110
int ehci_discover(struct ehci_hcd *ehci)
Definition: ehci.c:984
void ehci_usleep(int time)
Definition: usb_os.c:105
void ehci_dma_unmap_from(dma_addr_t buf, size_t len)
Definition: usb_os.c:95
s32 USBStorage_Read_Sectors(int device, u32 sector, u32 numSectors, void *buffer)
Definition: usbstorage.c:1342
struct ehci_hcd * ehci
Definition: ehci.h:23
s32 ehci_bulk_message(struct ehci_hcd *ehci, struct ehci_device *dev, u8 bEndpoint, u16 wLength, void *rpData)
Definition: ehci.c:682
void ehci_dma_unmap_to(dma_addr_t buf, size_t len)
Definition: usb_os.c:90
dma_addr_t ehci_virt_to_dma(void *)
Definition: usb_os.c:67
union ehci_shadow __attribute__
#define __u32
Definition: ehci_types.h:10
#define dma_addr_t
Definition: ehci_types.h:12
#define __iomem
Definition: ehci_types.h:4
u32 size
Definition: iso9660.c:537
usb_devdesc desc
Definition: ehci.h:50
int busy
Definition: ehci.h:55
int fd
Definition: ehci.h:53
int port
Definition: ehci.h:52
int id
Definition: ehci.h:51
u32 toggles
Definition: ehci.h:54
Definition: ehci.h:75
void * ctrl_buffer
Definition: ehci.h:100
struct ehci_dbg_port __iomem * debug
Definition: ehci.h:80
dma_addr_t periodic_dma
Definition: ehci.h:96
void __iomem * _regs
Definition: ehci.h:77
struct ehci_qh * asyncqh
Definition: ehci.h:86
struct ehci_caps __iomem * caps
Definition: ehci.h:78
int bus_id
Definition: ehci.h:102
struct ehci_qtd * qtds[EHCI_MAX_QTD]
Definition: ehci.h:88
__u32 hcs_params
Definition: ehci.h:82
__hc32 * periodic
Definition: ehci.h:95
unsigned long next_statechange
Definition: ehci.h:90
struct ehci_device devices[EHCI_MAX_ROOT_PORTS]
Definition: ehci.h:99
struct ehci_regs __iomem * regs
Definition: ehci.h:79
struct ehci_qh * async
Definition: ehci.h:85
u8 num_port
Definition: ehci.h:98
int qtd_used
Definition: ehci.h:89
void * device
Definition: ehci.h:81
u32 command
Definition: ehci.h:91
Definition: ehci.h:208
__hc32 hw_buf[5]
Definition: ehci.h:225
__hc32 hw_token
Definition: ehci.h:224
dma_addr_t qh_dma
Definition: ehci.h:229
struct ehci_qtd * qtd_head
Definition: ehci.h:230
__hc32 hw_alt_next
Definition: ehci.h:223
__hc32 hw_info1
Definition: ehci.h:211
struct ehci_hcd * ehci
Definition: ehci.h:232
__hc32 hw_current
Definition: ehci.h:219
__hc32 hw_buf_hi[5]
Definition: ehci.h:226
__hc32 hw_next
Definition: ehci.h:210
__hc32 hw_qtd_next
Definition: ehci.h:222
__hc32 hw_info2
Definition: ehci.h:213
Definition: ehci.h:119
struct ehci_urb * urb
Definition: ehci.h:148
size_t length
Definition: ehci.h:149
__hc32 hw_token
Definition: ehci.h:123
__hc32 hw_alt_next
Definition: ehci.h:122
__hc32 hw_buf[5]
Definition: ehci.h:142
__hc32 hw_buf_hi[5]
Definition: ehci.h:143
struct ehci_qtd * next
Definition: ehci.h:147
__hc32 hw_next
Definition: ehci.h:121
dma_addr_t qtd_dma
Definition: ehci.h:146
Definition: ehci.h:61
void * transfer_buffer
Definition: ehci.h:65
dma_addr_t setup_dma
Definition: ehci.h:63
u32 transfer_buffer_length
Definition: ehci.h:67
u8 ep
Definition: ehci.h:70
u8 input
Definition: ehci.h:71
u32 maxpacket
Definition: ehci.h:72
u32 actual_length
Definition: ehci.h:68
void * setup_buffer
Definition: ehci.h:62
dma_addr_t transfer_dma
Definition: ehci.h:66
struct ehci_sitd * sitd
Definition: ehci.h:192
struct ehci_qh * qh
Definition: ehci.h:190
struct ehci_fstn * fstn
Definition: ehci.h:193
__hc32 * hw_next
Definition: ehci.h:194
struct ehci_itd * itd
Definition: ehci.h:191
void * ptr
Definition: ehci.h:195
#define pid
Definition: xenonsprs.h:6
uint8_t u8
8bit unsigned integer
Definition: xetypes.h:12
uint16_t u16
16bit unsigned integer
Definition: xetypes.h:13
int32_t s32
32bit signed integer
Definition: xetypes.h:19
uint32_t u32
32bit unsigned integer
Definition: xetypes.h:14