Subversion Repositories Kolibri OS

Rev

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

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