Subversion Repositories Kolibri OS

Rev

Rev 1600 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1600 Rev 1605
1
typedef struct list_head  list_t;
1
typedef struct list_head  list_t;
2
 
2
 
3
 
3
 
4
typedef struct {
4
typedef struct {
5
  int     available;          /**< Count of available items in this slab. */
5
  int     available;          /**< Count of available items in this slab. */
6
  void   *start;              /**< Start address of first item. */
6
  void   *start;              /**< Start address of first item. */
7
  addr_t  nextavail;          /**< The index of next available item. */
7
  addr_t  nextavail;          /**< The index of next available item. */
8
  addr_t  dma;
8
  addr_t  dma;
9
} slab_t;
9
} slab_t;
10
 
10
 
11
 
11
 
12
#define USB_CLASS_AUDIO                    1
12
#define USB_CLASS_AUDIO                    1
13
#define USB_CLASS_COMM                     2
13
#define USB_CLASS_COMM                     2
14
#define USB_CLASS_HID                      3
14
#define USB_CLASS_HID                      3
15
#define USB_CLASS_PHYSICAL                 5
15
#define USB_CLASS_PHYSICAL                 5
16
#define USB_CLASS_STILL_IMAGE              6
16
#define USB_CLASS_STILL_IMAGE              6
17
#define USB_CLASS_PRINTER                  7
17
#define USB_CLASS_PRINTER                  7
18
#define USB_CLASS_MASS_STORAGE             8
18
#define USB_CLASS_MASS_STORAGE             8
19
#define USB_CLASS_HUB                      9
19
#define USB_CLASS_HUB                      9
20
#define USB_CLASS_CDC_DATA              0x0a
20
#define USB_CLASS_CDC_DATA              0x0a
21
#define USB_CLASS_CSCID                 0x0b    /* chip+ smart card */
21
#define USB_CLASS_CSCID                 0x0b    /* chip+ smart card */
22
#define USB_CLASS_CONTENT_SEC           0x0d    /* content security */
22
#define USB_CLASS_CONTENT_SEC           0x0d    /* content security */
23
#define USB_CLASS_VIDEO                 0x0e
23
#define USB_CLASS_VIDEO                 0x0e
24
#define USB_CLASS_WIRELESS_CONTROLLER	0xe0
24
#define USB_CLASS_WIRELESS_CONTROLLER	0xe0
25
#define USB_CLASS_MISC                  0xef
25
#define USB_CLASS_MISC                  0xef
26
#define USB_CLASS_APP_SPEC              0xfe
26
#define USB_CLASS_APP_SPEC              0xfe
27
#define USB_CLASS_VENDOR_SPEC           0xff
27
#define USB_CLASS_VENDOR_SPEC           0xff
28
 
28
 
29
 
29
 
30
typedef struct
30
typedef struct
31
{
31
{
32
    addr_t  qlink;
32
    addr_t  qlink;
33
    addr_t  qelem;
33
    addr_t  qelem;
34
 
34
 
35
    addr_t  dma;
35
    addr_t  dma;
36
    u32_t   r1;
36
    u32_t   r1;
37
 
37
 
38
}qh_t __attribute__((aligned(16)));
38
}qh_t __attribute__((aligned(16)));
39
 
39
 
-
 
40
 
-
 
41
#define UHCI_NUM_SKELQH 11
-
 
42
 
-
 
43
#define SKEL_ISO        1
-
 
44
#define SKEL_ASYNC      9
-
 
45
 
-
 
46
/*
-
 
47
#define     QH_1    0
-
 
48
#define     QH_2    1
-
 
49
#define     QH_4    2
-
 
50
#define     QH_8    3
-
 
51
#define     QH_16   4
-
 
52
#define     QH_32   5
-
 
53
#define     QH_64   6
-
 
54
*/
-
 
55
 
-
 
56
 
40
typedef struct
57
typedef struct
41
{
58
{
42
    list_t  list;
59
    list_t  list;
43
 
60
 
44
    addr_t  iobase;
61
    addr_t  iobase;
45
 
62
 
46
    u32_t   *frame_base;
63
    u32_t   *frame_base;
47
    count_t frame_number;
64
    count_t frame_number;
48
    addr_t  frame_dma;
65
    addr_t  frame_dma;
49
 
66
 
50
    qh_t   *qh1;
67
    qh_t   *qh[UHCI_NUM_SKELQH];
51
 
68
 
52
    u32_t  *data;
69
    u32_t  *data;
53
    addr_t  data_dma;
70
    addr_t  data_dma;
54
 
71
 
55
    u32_t   port_map;
72
    u32_t   port_map;
56
 
73
 
57
    int     numports;
74
    int     numports;
58
 
75
 
59
    u32_t   pciId;
76
    u32_t   pciId;
60
    PCITAG  PciTag;
77
    PCITAG  PciTag;
61
    addr_t  ioBase[6];
78
    addr_t  ioBase[6];
62
    addr_t  memBase[6];
79
    addr_t  memBase[6];
63
    size_t  memSize[6];
80
    size_t  memSize[6];
64
    u32_t   memType[6];
81
    u32_t   memType[6];
65
}hc_t;
82
    u32_t   irq_line;
-
 
83
}hc_t;
66
 
84
 
67
typedef struct tag_td
85
typedef struct tag_td
68
{
86
{
69
	/* Hardware fields */
87
	/* Hardware fields */
70
    addr_t   link;
88
    addr_t   link;
71
    u32_t    status;
89
    u32_t    status;
72
    u32_t    token;
90
    u32_t    token;
73
    addr_t   buffer;
91
    addr_t   buffer;
74
 
92
 
75
	/* Software fields */
93
	/* Software fields */
76
    addr_t   dma;
94
    addr_t   dma;
77
 
95
 
78
    struct   tag_td *bk;
96
    struct   tag_td *bk;
79
 
97
 
80
  //  struct list_head list;
98
  //  struct list_head list;
81
 
99
 
82
  //  int frame;          /* for iso: what frame? */
100
  //  int frame;          /* for iso: what frame? */
83
  //  struct list_head fl_list;
101
  //  struct list_head fl_list;
84
 
102
 
85
    u32_t    reserved[2];
103
    u32_t    reserved[2];
86
} td_t __attribute__((aligned(16)));
104
} td_t __attribute__((aligned(16)));
87
 
105
 
88
#define TD_CTRL_SPD         (1 << 29)   /* Short Packet Detect */
106
#define TD_CTRL_SPD         (1 << 29)   /* Short Packet Detect */
89
#define TD_CTRL_C_ERR_MASK	(3 << 27)	/* Error Counter bits */
107
#define TD_CTRL_C_ERR_MASK	(3 << 27)	/* Error Counter bits */
90
#define TD_CTRL_C_ERR_SHIFT	27
108
#define TD_CTRL_C_ERR_SHIFT	27
91
#define TD_CTRL_LS          (1 << 26)   /* Low Speed Device */
109
#define TD_CTRL_LS          (1 << 26)   /* Low Speed Device */
92
#define TD_CTRL_IOS         (1 << 25)   /* Isochronous Select */
110
#define TD_CTRL_IOS         (1 << 25)   /* Isochronous Select */
93
#define TD_CTRL_IOC         (1 << 24)   /* Interrupt on Complete */
111
#define TD_CTRL_IOC         (1 << 24)   /* Interrupt on Complete */
94
#define TD_CTRL_ACTIVE		(1 << 23)	/* TD Active */
112
#define TD_CTRL_ACTIVE		(1 << 23)	/* TD Active */
95
#define TD_CTRL_STALLED		(1 << 22)	/* TD Stalled */
113
#define TD_CTRL_STALLED		(1 << 22)	/* TD Stalled */
96
#define TD_CTRL_DBUFERR		(1 << 21)	/* Data Buffer Error */
114
#define TD_CTRL_DBUFERR		(1 << 21)	/* Data Buffer Error */
97
#define TD_CTRL_BABBLE		(1 << 20)	/* Babble Detected */
115
#define TD_CTRL_BABBLE		(1 << 20)	/* Babble Detected */
98
#define TD_CTRL_NAK         (1 << 19)   /* NAK Received */
116
#define TD_CTRL_NAK         (1 << 19)   /* NAK Received */
99
#define TD_CTRL_CRCTIMEO	(1 << 18)	/* CRC/Time Out Error */
117
#define TD_CTRL_CRCTIMEO	(1 << 18)	/* CRC/Time Out Error */
100
#define TD_CTRL_BITSTUFF    (1 << 17)   /* Bit Stuff Error */
118
#define TD_CTRL_BITSTUFF    (1 << 17)   /* Bit Stuff Error */
101
 
119
 
102
#define TD_ANY_ERROR   (TD_CTRL_STALLED | TD_CTRL_DBUFERR  | \
120
#define TD_ANY_ERROR   (TD_CTRL_STALLED | TD_CTRL_DBUFERR  | \
103
                        TD_CTRL_BABBLE  | TD_CTRL_CRCTIMEO | \
121
                        TD_CTRL_BABBLE  | TD_CTRL_CRCTIMEO | \
104
                        TD_CTRL_BITSTUFF)
122
                        TD_CTRL_BITSTUFF)
105
 
123
 
106
typedef struct __attribute__ ((packed))
124
typedef struct __attribute__ ((packed))
107
{
125
{
108
    u8_t    bLength;
126
    u8_t    bLength;
109
    u8_t    bDescriptorType;
127
    u8_t    bDescriptorType;
110
    u16_t   bcdUSB;
128
    u16_t   bcdUSB;
111
 
129
 
112
    u8_t    bDeviceClass;
130
    u8_t    bDeviceClass;
113
    u8_t    bDeviceSubClass;
131
    u8_t    bDeviceSubClass;
114
    u8_t    bDeviceProtocol;
132
    u8_t    bDeviceProtocol;
115
    u8_t    bMaxPacketSize0;
133
    u8_t    bMaxPacketSize0;
116
 
134
 
117
    u16_t   idVendor;
135
    u16_t   idVendor;
118
    u16_t   idProduct;
136
    u16_t   idProduct;
119
    u16_t   bcdDevice;
137
    u16_t   bcdDevice;
120
 
138
 
121
    u8_t    iManufacturer;
139
    u8_t    iManufacturer;
122
    u8_t    iProduct;
140
    u8_t    iProduct;
123
    u8_t    iSerialNumber;
141
    u8_t    iSerialNumber;
124
    u8_t    bNumConfigurations;
142
    u8_t    bNumConfigurations;
125
}dev_descr_t;
143
}dev_descr_t;
126
 
144
 
127
typedef struct  __attribute__ ((packed))
145
typedef struct  __attribute__ ((packed))
128
{
146
{
129
    u8_t    bLength;
147
    u8_t    bLength;
130
    u8_t    bDescriptorType;
148
    u8_t    bDescriptorType;
131
    u16_t   wTotalLength;
149
    u16_t   wTotalLength;
132
    u8_t    bNumInterfaces;
150
    u8_t    bNumInterfaces;
133
    u8_t    bConfigurationValue;
151
    u8_t    bConfigurationValue;
134
    u8_t    iConfiguration;
152
    u8_t    iConfiguration;
135
    u8_t    bmAttributes;
153
    u8_t    bmAttributes;
136
    u8_t    bMaxPower;
154
    u8_t    bMaxPower;
137
}conf_descr_t;
155
}conf_descr_t;
138
 
156
 
139
typedef struct __attribute__ ((packed))
157
typedef struct __attribute__ ((packed))
140
{
158
{
141
    u8_t    bLength;
159
    u8_t    bLength;
142
    u8_t    bDescriptorType;
160
    u8_t    bDescriptorType;
143
    u8_t    bInterfaceNumber;
161
    u8_t    bInterfaceNumber;
144
    u8_t    bAlternateSetting;
162
    u8_t    bAlternateSetting;
145
    u8_t    bNumEndpoints;
163
    u8_t    bNumEndpoints;
146
    u8_t    bInterfaceClass;
164
    u8_t    bInterfaceClass;
147
    u8_t    bInterfaceSubClass;
165
    u8_t    bInterfaceSubClass;
148
    u8_t    bInterfaceProtocol;
166
    u8_t    bInterfaceProtocol;
149
    u8_t    iInterface;
167
    u8_t    iInterface;
150
}interface_descr_t ;
168
}interface_descr_t ;
151
 
169
 
152
typedef struct __attribute__ ((packed))
170
typedef struct __attribute__ ((packed))
153
{
171
{
154
    u8_t    bLength;
172
    u8_t    bLength;
155
    u8_t    bDescriptorType;
173
    u8_t    bDescriptorType;
156
 
174
 
157
    u8_t    bEndpointAddress;
175
    u8_t    bEndpointAddress;
158
    u8_t    bmAttributes;
176
    u8_t    bmAttributes;
159
    u16_t   wMaxPacketSize;
177
    u16_t   wMaxPacketSize;
160
    u8_t    bInterval;
178
    u8_t    bInterval;
161
 
179
 
162
	/* NOTE:  these two are _only_ in audio endpoints. */
180
	/* NOTE:  these two are _only_ in audio endpoints. */
163
	/* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
181
	/* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
164
    u8_t    bRefresh;
182
    u8_t    bRefresh;
165
    u8_t    bSynchAddress;
183
    u8_t    bSynchAddress;
166
}endpoint_descr_t;
184
}endpoint_descr_t;
167
 
185
 
168
typedef struct
186
typedef struct
169
{
187
{
170
    addr_t  address;
188
    addr_t  address;
171
    addr_t  size;
189
    addr_t  size;
172
    u32_t   toggle;
190
    u32_t   toggle;
173
 
191
 
174
}endp_t;
192
}endp_t;
175
 
193
 
176
typedef struct __attribute__ ((packed))
194
typedef struct __attribute__ ((packed))
177
{
195
{
178
    u8_t    bRequestType;
196
    u8_t    bRequestType;
179
    u8_t    bRequest;
197
    u8_t    bRequest;
180
    u16_t   wValue;
198
    u16_t   wValue;
181
    u16_t   wIndex;
199
    u16_t   wIndex;
182
    u16_t   wLength;
200
    u16_t   wLength;
183
}ctrl_request_t;
201
}ctrl_request_t;
184
 
202
 
185
 
203
 
186
typedef struct
204
typedef struct
187
{
205
{
188
    list_t  list;
206
    list_t  list;
189
    u32_t   id;
207
    u32_t   id;
190
 
208
 
191
    hc_t   *host;
209
    hc_t   *host;
192
 
210
 
193
    u32_t   speed;
211
    u32_t   speed;
194
    addr_t  addr;
212
    addr_t  addr;
195
 
213
 
196
    addr_t  ep0_size;
214
    addr_t  ep0_size;
197
 
215
 
198
    endp_t  enp;
216
    endp_t  enp;
199
 
217
 
200
    u32_t   status;
218
    u32_t   status;
201
    int     port;
219
    int     port;
202
 
220
 
203
    dev_descr_t   dev_descr;
221
    dev_descr_t   dev_descr;
204
    conf_descr_t  *conf;
222
    conf_descr_t  *conf;
205
}udev_t;
223
}udev_t;
206
 
224
 
207
typedef struct   tag_request
225
typedef struct   tag_request
208
{
226
{
209
    list_t        list;
227
    list_t        list;
210
    td_t         *td_head;
228
    td_t         *td_head;
211
    td_t         *td_tail;
229
    td_t         *td_tail;
212
    addr_t        data;
230
    addr_t        data;
213
    size_t        size;
231
    size_t        size;
214
    udev_t       *dev;
232
    udev_t       *dev;
215
    u32_t         type;
233
    u32_t         type;
216
    bool        (*handler)(udev_t *dev, struct   tag_request *rq);
234
    int           qnum;
-
 
235
    bool        (*handler)(udev_t *dev, struct   tag_request *rq);
217
}request_t;
236
}request_t;
218
 
237
 
219
 
238
 
220
#define  DMA(val) GetPgAddr(val)|(((addr_t)(val))&0xFFF)
239
#define  DMA(val) GetPgAddr(val)|(((addr_t)(val))&0xFFF)
221
 
240
 
222
#define  TOKEN( size, toggle, ep, addr, pid) \
241
#define  TOKEN( size, toggle, ep, addr, pid) \
223
         ( (((size)-1)<<21)|(toggle)|(((ep)&0xF)<<15)|((addr)<<8)|(pid))
242
         ( (((size)-1)<<21)|(toggle)|(((ep)&0xF)<<15)|((addr)<<8)|(pid))
224
 
243
 
225
bool FindUSBControllers();
244
bool FindUSBControllers();
226
 
245
 
227
bool ctrl_request(udev_t *dev, void *req, u32_t dir,
246
bool ctrl_request(udev_t *dev, void *req, u32_t dir,
228
                  void *data, size_t req_size);
247
                  void *data, size_t req_size);
229
 
248
 
230
bool set_address(udev_t *dev);
249
bool set_address(udev_t *dev);
231
 
250
 
232
bool init_device(udev_t *dev);
251
bool init_device(udev_t *dev);
233
 
252
 
234
bool init_hid(udev_t *dev);
253
bool init_hid(udev_t *dev);
235
 
254
 
236
struct boot_packet
255
struct boot_packet
237
{
256
{
238
    u8_t  buttons;
257
    u8_t  buttons;
239
    char  x;
258
    char  x;
240
    char  y;
259
    char  y;
241
    char  z;
260
    char  z;
242
}__attribute__ ((packed));
261
}__attribute__ ((packed));
243
 
262
 
244
#define DOUT   0xE1
263
#define DOUT   0xE1
245
#define DIN    0x69
264
#define DIN    0x69
246
 
265
 
247
#define DATA0  (0<<19)
266
#define DATA0  (0<<19)
248
#define DATA1  (1<<19)
267
#define DATA1  (1<<19)
249
#define>
268
 
-
 
269
 
-
 
270
 
-
 
271
static inline u32_t __bsf(u32_t val)
-
 
272
{
-
 
273
    asm("bsf %1,%0"
-
 
274
        :"=r" (val)
-
 
275
        :"rm" (val));
-
 
276
    return val;
-
 
277
}
-
 
278
 
250
#define>
279
 
251
 
280
 
252
bool>
281
static>
253
 
282
 
254
bool>
283
 
255
 
284
 
256
bool>
285
static>
257
 
286
#define>
258
bool>
287
#define>
259
 
288
 
260
bool>
289
bool>
261
 
290
 
262
bool>
291
bool>
-
 
292
 
-
 
293
bool>
-
 
294
 
-
 
295
bool>
-
 
296
 
-
 
297
bool>
-
 
298
 
-
 
299
bool>