]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/kw/usbehci.h
merge
[plan9front.git] / sys / src / 9 / kw / usbehci.h
1 /* override default macros from ../port/usb.h */
2 #undef  dprint
3 #undef  ddprint
4 #undef  deprint
5 #undef  ddeprint
6 #define dprint          if(ehcidebug)print
7 #define ddprint         if(ehcidebug>1)print
8 #define deprint         if(ehcidebug || ep->debug)print
9 #define ddeprint        if(ehcidebug>1 || ep->debug>1)print
10
11 typedef struct Ctlr Ctlr;
12 typedef struct Ecapio Ecapio;
13 typedef struct Eopio Eopio;
14 typedef struct Edbgio Edbgio;
15 typedef struct Isoio Isoio;
16 typedef struct Poll Poll;
17 typedef struct Qh Qh;
18 typedef struct Qtree Qtree;
19
20 #pragma incomplete Ctlr;
21 #pragma incomplete Ecapio;
22 #pragma incomplete Eopio;
23 #pragma incomplete Edbgio;
24 #pragma incomplete Isoio;
25 #pragma incomplete Poll;
26 #pragma incomplete Qh;
27 #pragma incomplete Qtree;
28
29 /*
30  * EHCI interface registers and bits
31  */
32 enum
33 {
34         Cnports         = 0xF,          /* nport bits in Ecapio parms. */
35         Cdbgportshift   = 20,           /* debug port in Ecapio parms. */
36         Cdbgportmask    = 0xF,
37         C64             = 1,            /* 64-bits, in Ecapio capparms. */
38         Ceecpshift      = 8,            /* extended capabilities ptr. in */
39         Ceecpmask       = 8,            /* the Ecapio capparms reg. */
40         Clegacy         = 1,            /* legacy support cap. id */
41         CLbiossem       = 2,            /* legacy cap. bios sem. */
42         CLossem         = 3,            /* legacy cap. os sem */
43
44         /* typed links  */
45         Lterm           = 1,
46         Litd            = 0<<1,
47         Lqh             = 1<<1,
48         Lsitd           = 2<<1,
49         Lfstn           = 3<<1,         /* we don't use these */
50
51         /* Cmd reg. */
52         Cstop           = 0x00000,      /* stop running */
53         Crun            = 0x00001,      /* start operation */
54         Chcreset        = 0x00002,      /* host controller reset */
55         Cflsmask        = 0x0000C,      /* frame list size bits */
56         Cfls1024        = 0x00000,      /* frame list size 1024 */
57         Cfls512         = 0x00004,      /* frame list size 512 frames */
58         Cfls256         = 0x00008,      /* frame list size 256 frames */
59         Cpse            = 0x00010,      /* periodic sched. enable */
60         Case            = 0x00020,      /* async sched. enable */
61         Ciasync         = 0x00040,      /* interrupt on async advance doorbell */
62         Citc1           = 0x10000,      /* interrupt threshold ctl. 1 µframe */
63         Citc4           = 0x40000,      /* same. 2 µframes */
64         /* ... */
65         Citc8           = 0x80000,      /* same. 8 µframes (can go up to 64) */
66
67         /* Sts reg. */
68         Sasyncss        = 0x08000,      /* aync schedule status */
69         Speriodss       = 0x04000,      /* periodic schedule status */
70         Srecl           = 0x02000,      /* reclamnation (empty async sched.) */
71         Shalted         = 0x01000,      /* h.c. is halted */
72         Sasync          = 0x00020,      /* interrupt on async advance */
73         Sherr           = 0x00010,      /* host system error */
74         Sfrroll         = 0x00008,      /* frame list roll over */
75         Sportchg        = 0x00004,      /* port change detect */
76         Serrintr        = 0x00002,              /* error interrupt */
77         Sintr           = 0x00001,      /* interrupt */
78         Sintrs          = 0x0003F,      /* interrupts status */
79
80         /* Intr reg. */
81         Iusb            = 0x01,         /* intr. on usb */
82         Ierr            = 0x02,         /* intr. on usb error */
83         Iportchg        = 0x04,         /* intr. on port change */
84         Ifrroll         = 0x08,         /* intr. on frlist roll over */
85         Ihcerr          = 0x10,         /* intr. on host error */
86         Iasync          = 0x20,         /* intr. on async advance enable */
87         Iall            = 0x3F,         /* all interrupts */
88
89         /* Config reg. */
90         Callmine        = 1,            /* route all ports to us */
91
92         /* Portsc reg. */
93         Pspresent       = 0x00000001,   /* device present */
94         Psstatuschg     = 0x00000002,   /* Pspresent changed */
95         Psenable        = 0x00000004,   /* device enabled */
96         Pschange        = 0x00000008,   /* Psenable changed */
97         Psresume        = 0x00000040,   /* resume detected */
98         Pssuspend       = 0x00000080,   /* port suspended */
99         Psreset         = 0x00000100,   /* port reset */
100         Pspower         = 0x00001000,   /* port power on */
101         Psowner         = 0x00002000,   /* port owned by companion */
102         Pslinemask      = 0x00000C00,   /* line status bits */
103         Pslow           = 0x00000400,   /* low speed device */
104
105         /* Debug port csw reg. */
106         Cowner  = 0x40000000,           /* port owned by ehci */
107         Cenable = 0x10000000,           /* debug port enabled */
108         Cdone   = 0x00010000,           /* request is done */
109         Cbusy   = 0x00000400,           /* port in use by a driver */
110         Cerrmask= 0x00000380,           /* error code bits */
111         Chwerr  = 0x00000100,           /* hardware error */
112         Cterr   = 0x00000080,           /* transaction error */
113         Cfailed = 0x00000040,           /* transaction did fail */
114         Cgo     = 0x00000020,           /* execute the transaction */
115         Cwrite  = 0x00000010,           /* request is a write */
116         Clen    = 0x0000000F,           /* data len */
117
118         /* Debug port pid reg. */
119         Prpidshift      = 16,           /* received pid */
120         Prpidmask       = 0xFF,
121         Pspidshift      = 8,            /* sent pid */
122         Pspidmask       = 0xFF,
123         Ptokshift       = 0,            /* token pid */
124         Ptokmask        = 0xFF,
125
126         Ptoggle         = 0x00008800,   /* to update toggles */
127         Ptogglemask     = 0x0000FF00,
128
129         /* Debug port addr reg. */
130         Adevshift       = 8,            /* device address */
131         Adevmask        = 0x7F,
132         Aepshift        = 0,            /* endpoint number */
133         Aepmask         = 0xF,
134 };
135
136 /*
137  * Capability registers (hw)
138  */
139 struct Ecapio
140 {
141         ulong   cap;            /* 00 controller capability register */
142         ulong   parms;          /* 04 structural parameters register */
143         ulong   capparms;       /* 08 capability parameters */
144         ulong   portroute;      /* 0c not on the CS5536 */
145 };
146
147 /*
148  * Debug port registers (hw)
149  */
150 struct Edbgio
151 {
152         ulong   csw;            /* control and status */
153         ulong   pid;            /* USB pid */
154         uchar   data[8];        /* data buffer */
155         ulong   addr;           /* device and endpoint addresses */
156 };
157
158 struct Poll
159 {
160         Lock;
161         Rendez;
162         int     must;
163         int     does;
164 };
165
166 struct Ctlr
167 {
168         Rendez;                 /* for waiting to async advance doorbell */
169         Lock;                   /* for ilock. qh lists and basic ctlr I/O */
170         QLock   portlck;        /* for port resets/enable... (and doorbell) */
171         int     active;         /* in use or not */
172         Ecapio* capio;          /* Capability i/o regs */
173         Eopio*  opio;           /* Operational i/o regs */
174
175         void*   (*tdalloc)(ulong,int,ulong);
176         void*   (*dmaalloc)(ulong);
177         void    (*dmafree)(void*);
178         void    (*dmaflush)(int,void*,ulong len);
179
180         int     nframes;        /* 1024, 512, or 256 frames in the list */
181         ulong*  frames;         /* periodic frame list (hw) */
182         Qh*     qhs;            /* async Qh circular list for bulk/ctl */
183         Qtree*  tree;           /* tree of Qhs for the periodic list */
184         int     ntree;          /* number of dummy qhs in tree */
185         Qh*     intrqhs;                /* list of (not dummy) qhs in tree  */
186         Isoio*  iso;            /* list of active Iso I/O */
187         ulong   load;
188         ulong   isoload;
189         int     nintr;          /* number of interrupts attended */
190         int     ntdintr;        /* number of intrs. with something to do */
191         int     nqhintr;        /* number of async td intrs. */
192         int     nisointr;       /* number of periodic td intrs. */
193         int     nreqs;
194         Poll    poll;
195 };
196
197 /*
198  * Kirkwood-specific stuff
199  */
200
201 /*
202  * Operational registers (hw)
203  */
204 struct Eopio
205 {
206         ulong   cmd;            /* 00 command */
207         ulong   sts;            /* 04 status */
208         ulong   intr;           /* 08 interrupt enable */
209         ulong   frno;           /* 0c frame index */
210         ulong   seg;            /* 10 bits 63:32 of EHCI datastructs (unused) */
211         ulong   frbase;         /* 14 frame list base addr, 4096-byte boundary */
212         ulong   link;           /* 18 link for async list */
213         uchar   d2c[0x40-0x1c]; /* 1c dummy */
214         ulong   config;         /* 40 1: all ports default-routed to this HC */
215         ulong   portsc[1];      /* 44 Port status and control, one per port */
216
217         /*
218          * these are present on the Kirkwood USB controller.
219          * are they standard now?  Marvell doesn't document them publically.
220          */
221         uchar   _pad0[0x64-0x48];
222         ulong   otgsc;
223         ulong   usbmode;
224         ulong   epsetupsts;
225         ulong   epprime;
226         ulong   epflush;
227         ulong   epsts;
228         ulong   epcompl;
229         ulong   epctl[6];
230
231         /* freescale registers */
232         uchar   _pad1[0x2c0-0x98];
233         ulong   snoop1;
234         ulong   snoop2;
235         ulong   agecntthresh;
236         ulong   prictl;         /* priority control */
237         ulong   sictl;          /* system interface control */
238
239         uchar   _pad2[0x3c0-0x2d4];
240         ulong   ctl;
241 };
242
243 extern int ehcidebug;
244
245 void    ehcilinkage(Hci *hp);
246 void    ehcimeminit(Ctlr *ctlr);
247 void    ehcirun(Ctlr *ctlr, int on);