~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/seabios/src/hw/usb.h

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// USB functions and data.
 
2
#ifndef __USB_H
 
3
#define __USB_H
 
4
 
 
5
#include "stacks.h" // struct mutex_s
 
6
 
 
7
// Information on a USB end point.
 
8
struct usb_pipe {
 
9
    union {
 
10
        struct usb_s *cntl;
 
11
        struct usb_pipe *freenext;
 
12
    };
 
13
    u8 type;
 
14
    u8 ep;
 
15
    u8 devaddr;
 
16
    u8 speed;
 
17
    u16 maxpacket;
 
18
    u8 eptype;
 
19
};
 
20
 
 
21
// Common information for usb devices.
 
22
struct usbdevice_s {
 
23
    struct usbhub_s *hub;
 
24
    struct usb_pipe *defpipe;
 
25
    u32 port;
 
26
    struct usb_config_descriptor *config;
 
27
    struct usb_interface_descriptor *iface;
 
28
    int imax;
 
29
    u8 speed;
 
30
    u8 devaddr;
 
31
};
 
32
 
 
33
// Common information for usb controllers.
 
34
struct usb_s {
 
35
    struct usb_pipe *freelist;
 
36
    struct mutex_s resetlock;
 
37
    struct pci_device *pci;
 
38
    u8 type;
 
39
    u8 maxaddr;
 
40
};
 
41
 
 
42
// Information for enumerating USB hubs
 
43
struct usbhub_s {
 
44
    struct usbhub_op_s *op;
 
45
    struct usbdevice_s *usbdev;
 
46
    struct usb_s *cntl;
 
47
    struct mutex_s lock;
 
48
    u32 detectend;
 
49
    u32 port;
 
50
    u32 threads;
 
51
    u32 portcount;
 
52
    u32 devcount;
 
53
};
 
54
 
 
55
// Hub callback (32bit) info
 
56
struct usbhub_op_s {
 
57
    int (*detect)(struct usbhub_s *hub, u32 port);
 
58
    int (*reset)(struct usbhub_s *hub, u32 port);
 
59
    void (*disconnect)(struct usbhub_s *hub, u32 port);
 
60
};
 
61
 
 
62
#define USB_TYPE_UHCI  1
 
63
#define USB_TYPE_OHCI  2
 
64
#define USB_TYPE_EHCI  3
 
65
#define USB_TYPE_XHCI  4
 
66
 
 
67
#define USB_FULLSPEED  0
 
68
#define USB_LOWSPEED   1
 
69
#define USB_HIGHSPEED  2
 
70
#define USB_SUPERSPEED 3
 
71
 
 
72
#define USB_MAXADDR  127
 
73
 
 
74
 
 
75
/****************************************************************
 
76
 * usb structs and flags
 
77
 ****************************************************************/
 
78
 
 
79
// USB mandated timings (in ms)
 
80
#define USB_TIME_SIGATT 100
 
81
#define USB_TIME_ATTDB  100
 
82
#define USB_TIME_DRST   10
 
83
#define USB_TIME_DRSTR  50
 
84
#define USB_TIME_RSTRCY 10
 
85
 
 
86
#define USB_TIME_STATUS  50
 
87
#define USB_TIME_DATAIN  500
 
88
#define USB_TIME_COMMAND 5000
 
89
 
 
90
#define USB_TIME_SETADDR_RECOVERY 2
 
91
 
 
92
#define USB_PID_OUT                     0xe1
 
93
#define USB_PID_IN                      0x69
 
94
#define USB_PID_SETUP                   0x2d
 
95
 
 
96
#define USB_DIR_OUT                     0               /* to device */
 
97
#define USB_DIR_IN                      0x80            /* to host */
 
98
 
 
99
#define USB_TYPE_MASK                   (0x03 << 5)
 
100
#define USB_TYPE_STANDARD               (0x00 << 5)
 
101
#define USB_TYPE_CLASS                  (0x01 << 5)
 
102
#define USB_TYPE_VENDOR                 (0x02 << 5)
 
103
#define USB_TYPE_RESERVED               (0x03 << 5)
 
104
 
 
105
#define USB_RECIP_MASK                  0x1f
 
106
#define USB_RECIP_DEVICE                0x00
 
107
#define USB_RECIP_INTERFACE             0x01
 
108
#define USB_RECIP_ENDPOINT              0x02
 
109
#define USB_RECIP_OTHER                 0x03
 
110
 
 
111
#define USB_REQ_GET_STATUS              0x00
 
112
#define USB_REQ_CLEAR_FEATURE           0x01
 
113
#define USB_REQ_SET_FEATURE             0x03
 
114
#define USB_REQ_SET_ADDRESS             0x05
 
115
#define USB_REQ_GET_DESCRIPTOR          0x06
 
116
#define USB_REQ_SET_DESCRIPTOR          0x07
 
117
#define USB_REQ_GET_CONFIGURATION       0x08
 
118
#define USB_REQ_SET_CONFIGURATION       0x09
 
119
#define USB_REQ_GET_INTERFACE           0x0A
 
120
#define USB_REQ_SET_INTERFACE           0x0B
 
121
#define USB_REQ_SYNCH_FRAME             0x0C
 
122
 
 
123
struct usb_ctrlrequest {
 
124
    u8 bRequestType;
 
125
    u8 bRequest;
 
126
    u16 wValue;
 
127
    u16 wIndex;
 
128
    u16 wLength;
 
129
} PACKED;
 
130
 
 
131
#define USB_DT_DEVICE                   0x01
 
132
#define USB_DT_CONFIG                   0x02
 
133
#define USB_DT_STRING                   0x03
 
134
#define USB_DT_INTERFACE                0x04
 
135
#define USB_DT_ENDPOINT                 0x05
 
136
#define USB_DT_DEVICE_QUALIFIER         0x06
 
137
#define USB_DT_OTHER_SPEED_CONFIG       0x07
 
138
#define USB_DT_ENDPOINT_COMPANION       0x30
 
139
 
 
140
struct usb_device_descriptor {
 
141
    u8  bLength;
 
142
    u8  bDescriptorType;
 
143
 
 
144
    u16 bcdUSB;
 
145
    u8  bDeviceClass;
 
146
    u8  bDeviceSubClass;
 
147
    u8  bDeviceProtocol;
 
148
    u8  bMaxPacketSize0;
 
149
    u16 idVendor;
 
150
    u16 idProduct;
 
151
    u16 bcdDevice;
 
152
    u8  iManufacturer;
 
153
    u8  iProduct;
 
154
    u8  iSerialNumber;
 
155
    u8  bNumConfigurations;
 
156
} PACKED;
 
157
 
 
158
#define USB_CLASS_PER_INTERFACE         0       /* for DeviceClass */
 
159
#define USB_CLASS_AUDIO                 1
 
160
#define USB_CLASS_COMM                  2
 
161
#define USB_CLASS_HID                   3
 
162
#define USB_CLASS_PHYSICAL              5
 
163
#define USB_CLASS_STILL_IMAGE           6
 
164
#define USB_CLASS_PRINTER               7
 
165
#define USB_CLASS_MASS_STORAGE          8
 
166
#define USB_CLASS_HUB                   9
 
167
 
 
168
struct usb_config_descriptor {
 
169
    u8  bLength;
 
170
    u8  bDescriptorType;
 
171
 
 
172
    u16 wTotalLength;
 
173
    u8  bNumInterfaces;
 
174
    u8  bConfigurationValue;
 
175
    u8  iConfiguration;
 
176
    u8  bmAttributes;
 
177
    u8  bMaxPower;
 
178
} PACKED;
 
179
 
 
180
struct usb_interface_descriptor {
 
181
    u8  bLength;
 
182
    u8  bDescriptorType;
 
183
 
 
184
    u8  bInterfaceNumber;
 
185
    u8  bAlternateSetting;
 
186
    u8  bNumEndpoints;
 
187
    u8  bInterfaceClass;
 
188
    u8  bInterfaceSubClass;
 
189
    u8  bInterfaceProtocol;
 
190
    u8  iInterface;
 
191
} PACKED;
 
192
 
 
193
struct usb_endpoint_descriptor {
 
194
    u8  bLength;
 
195
    u8  bDescriptorType;
 
196
 
 
197
    u8  bEndpointAddress;
 
198
    u8  bmAttributes;
 
199
    u16 wMaxPacketSize;
 
200
    u8  bInterval;
 
201
} PACKED;
 
202
 
 
203
#define USB_ENDPOINT_NUMBER_MASK        0x0f    /* in bEndpointAddress */
 
204
#define USB_ENDPOINT_DIR_MASK           0x80
 
205
 
 
206
#define USB_ENDPOINT_XFERTYPE_MASK      0x03    /* in bmAttributes */
 
207
#define USB_ENDPOINT_XFER_CONTROL       0
 
208
#define USB_ENDPOINT_XFER_ISOC          1
 
209
#define USB_ENDPOINT_XFER_BULK          2
 
210
#define USB_ENDPOINT_XFER_INT           3
 
211
#define USB_ENDPOINT_MAX_ADJUSTABLE     0x80
 
212
 
 
213
#define USB_CONTROL_SETUP_SIZE          8
 
214
 
 
215
 
 
216
/****************************************************************
 
217
 * usb mass storage flags
 
218
 ****************************************************************/
 
219
 
 
220
#define US_SC_ATAPI_8020   0x02
 
221
#define US_SC_ATAPI_8070   0x05
 
222
#define US_SC_SCSI         0x06
 
223
 
 
224
#define US_PR_BULK         0x50  /* bulk-only transport */
 
225
#define US_PR_UAS          0x62  /* usb attached scsi   */
 
226
 
 
227
/****************************************************************
 
228
 * function defs
 
229
 ****************************************************************/
 
230
 
 
231
// usb.c
 
232
int usb_send_bulk(struct usb_pipe *pipe, int dir, void *data, int datasize);
 
233
int usb_poll_intr(struct usb_pipe *pipe, void *data);
 
234
int usb_32bit_pipe(struct usb_pipe *pipe_fl);
 
235
struct usb_pipe *usb_alloc_pipe(struct usbdevice_s *usbdev
 
236
                                , struct usb_endpoint_descriptor *epdesc);
 
237
void usb_free_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe);
 
238
int usb_send_default_control(struct usb_pipe *pipe
 
239
                             , const struct usb_ctrlrequest *req, void *data);
 
240
int usb_is_freelist(struct usb_s *cntl, struct usb_pipe *pipe);
 
241
void usb_add_freelist(struct usb_pipe *pipe);
 
242
struct usb_pipe *usb_get_freelist(struct usb_s *cntl, u8 eptype);
 
243
void usb_desc2pipe(struct usb_pipe *pipe, struct usbdevice_s *usbdev
 
244
                   , struct usb_endpoint_descriptor *epdesc);
 
245
int usb_get_period(struct usbdevice_s *usbdev
 
246
                   , struct usb_endpoint_descriptor *epdesc);
 
247
int usb_xfer_time(struct usb_pipe *pipe, int datalen);
 
248
struct usb_endpoint_descriptor *usb_find_desc(struct usbdevice_s *usbdev
 
249
                                              , int type, int dir);
 
250
void usb_enumerate(struct usbhub_s *hub);
 
251
void usb_setup(void);
 
252
 
 
253
#endif // usb.h