0e127224209a33c5061e2b0ee043f6cdd1ed763c
[ppcskel.git] / usb / core / core.h
1 /*
2  * Copyright (c) 2007, Benedikt Sauter <sauter@ixbat.de>
3  * All rights reserved.
4  *
5  * Short descripton of file:
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without 
9  * modification, are permitted provided that the following conditions 
10  * are met:
11  *
12  *       * Redistributions of source code must retain the above copyright 
13  *               notice, this list of conditions and the following disclaimer.
14  *       * Redistributions in binary form must reproduce the above 
15  *               copyright notice, this list of conditions and the following 
16  *               disclaimer in the documentation and/or other materials provided 
17  *               with the distribution.
18  *       * Neither the name of the FH Augsburg nor the names of its 
19  *               contributors may be used to endorse or promote products derived 
20  *               from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #ifndef _CORE_H_
36 #define _CORE_H_
37
38 #include "../../types.h"
39 #include "../lib/list.h"
40
41
42 #include "../../bootmii_ppc.h"
43 inline static void wait_ms(int ms)
44 {
45         int i=0;
46         for(;i<ms;i++)
47                 udelay(1000);
48 }
49
50 /**
51  * Main datastructure of the usbstack, which have to be instanced
52  * in the main application.
53  */
54
55 typedef struct usb_device_t usb_device;
56 struct usb_device_t {
57         u8  address;
58         u8  fullspeed;
59         u8  bMaxPacketSize0;
60         u8  bDeviceClass;
61         u8  bDeviceSubClass;
62         u8  bDeviceProtocoll;
63         u32 idVendor;
64         u32 idProduct;
65         u32 bcdDevice;
66         u8  bNumConfigurations;
67
68         u8 epSize[16];
69         u8 epTogl[16];
70
71         usb_device *next;
72 };
73
74
75 typedef struct usb_endpoint_t usb_endpoint;
76 struct usb_endpoint_t {
77         u8 type;
78         u8 size;
79         u8 togl;
80         usb_endpoint *next;
81 };
82
83
84
85
86 typedef struct usb_transfer_descriptor_ep_t usb_transfer_descriptor_ep;
87 struct usb_transfer_descriptor_ep_t {
88         usb_transfer_descriptor_ep *next;
89         u8 device_address;
90         u8 endpoint;
91         struct usb_transfer_descriptor_t *start;
92 };
93
94 /**
95  * USB Driver data structure
96  */
97 typedef struct usb_driver_t usb_driver;
98 struct usb_driver_t {
99         char* name;
100         void (*probe)(void);
101         void (*check)(void);
102         void * data;
103         usb_driver *next;
104 };
105
106
107 /**
108  * I/O Request Block
109  */
110
111 typedef struct usb_irp_t usb_irp;
112 struct usb_irp_t {
113         //u8 devaddress;
114         usb_device * dev;
115         u8 endpoint;                            /* ep -> bit 7 is for direction 1=from  dev to host */
116         u8 epsize;
117         u8 type;                                /* control, interrupt, bulk or isochron */
118
119         char * buffer;
120         u16 len;
121
122         //list * td_list;
123         u16 timeout;
124 };
125
126
127 /**
128  * usb transfer descriptor
129  */
130 typedef struct usb_transfer_descriptor_t usb_transfer_descriptor;
131 struct usb_transfer_descriptor_t {
132         u8 devaddress;
133         u8 endpoint;
134         
135         // TODO: zusammenfassen!
136         u8 pid;
137         u8 iso;
138         u8 togl;        
139         
140         char * buffer;
141         u16 actlen;
142         
143         u8 state;
144         usb_transfer_descriptor *next;
145 };
146
147 //typedef struct usb_core_t usb_core;
148 struct usb_core_t {
149         u8 nextaddress;
150         void (*stdout)(char * arg); 
151         // driver list
152         list * drivers;
153         list * devices;
154 } core;
155
156 void usb_init();
157 void usb_periodic();
158 u8 usb_next_address();
159
160
161 usb_device * usb_add_device();
162 u8 usb_remove_device(usb_device *dev);
163 u8 usb_register_driver(usb_driver *driver);
164 void usb_probe_driver();
165
166
167
168 usb_irp * usb_get_irp();
169 u8 usb_remove_irp(usb_irp *irp);
170 u16 usb_submit_irp(usb_irp *irp);
171
172
173 usb_transfer_descriptor * usb_create_transfer_descriptor(usb_irp *irp);
174
175
176 #define USB_IRP_WAITING         1
177
178
179 #define USB_TRANSFER_DESCR_NONE 1
180 #define USB_TRANSFER_DESCR_SEND 2
181
182 #endif  //_CORE_H_