2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2008 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
23 #include <grub/usbdesc.h>
24 #include <grub/usbtrans.h>
26 typedef struct grub_usb_device
*grub_usb_device_t
;
27 typedef struct grub_usb_controller
*grub_usb_controller_t
;
28 typedef struct grub_usb_controller_dev
*grub_usb_controller_dev_t
;
34 GRUB_USB_ERR_INTERNAL
,
40 GRUB_USB_ERR_BITSTUFF
,
41 GRUB_USB_ERR_UNRECOVERABLE
,
42 GRUB_USB_ERR_BADDEVICE
53 typedef int (*grub_usb_iterate_hook_t
) (grub_usb_device_t dev
, void *data
);
54 typedef int (*grub_usb_controller_iterate_hook_t
) (grub_usb_controller_t dev
,
57 /* Call HOOK with each device, until HOOK returns non-zero. */
58 int grub_usb_iterate (grub_usb_iterate_hook_t hook
, void *hook_data
);
60 grub_usb_err_t
grub_usb_device_initialize (grub_usb_device_t dev
);
62 grub_usb_err_t
grub_usb_get_descriptor (grub_usb_device_t dev
,
63 grub_uint8_t type
, grub_uint8_t index
,
64 grub_size_t size
, char *data
);
66 grub_usb_err_t
grub_usb_clear_halt (grub_usb_device_t dev
, int endpoint
);
69 grub_usb_err_t
grub_usb_set_configuration (grub_usb_device_t dev
,
72 void grub_usb_controller_dev_register (grub_usb_controller_dev_t usb
);
74 void grub_usb_controller_dev_unregister (grub_usb_controller_dev_t usb
);
76 int grub_usb_controller_iterate (grub_usb_controller_iterate_hook_t hook
,
80 grub_usb_err_t
grub_usb_control_msg (grub_usb_device_t dev
, grub_uint8_t reqtype
,
81 grub_uint8_t request
, grub_uint16_t value
,
82 grub_uint16_t index
, grub_size_t size
,
86 grub_usb_bulk_read (grub_usb_device_t dev
,
87 struct grub_usb_desc_endp
*endpoint
,
88 grub_size_t size
, char *data
);
90 grub_usb_bulk_write (grub_usb_device_t dev
,
91 struct grub_usb_desc_endp
*endpoint
,
92 grub_size_t size
, char *data
);
95 grub_usb_root_hub (grub_usb_controller_t controller
);
99 /* XXX: All handled by libusb for now. */
100 struct grub_usb_controller_dev
102 /* The device name. */
105 int (*iterate
) (grub_usb_controller_iterate_hook_t hook
, void *hook_data
);
107 grub_usb_err_t (*setup_transfer
) (grub_usb_controller_t dev
,
108 grub_usb_transfer_t transfer
);
110 grub_usb_err_t (*check_transfer
) (grub_usb_controller_t dev
,
111 grub_usb_transfer_t transfer
,
112 grub_size_t
*actual
);
114 grub_usb_err_t (*cancel_transfer
) (grub_usb_controller_t dev
,
115 grub_usb_transfer_t transfer
);
117 int (*hubports
) (grub_usb_controller_t dev
);
119 grub_usb_err_t (*portstatus
) (grub_usb_controller_t dev
, unsigned int port
,
120 unsigned int enable
);
122 grub_usb_speed_t (*detect_dev
) (grub_usb_controller_t dev
, int port
, int *changed
);
124 /* Per controller flag - port reset pending, don't do another reset */
125 grub_uint64_t pending_reset
;
127 /* Max. number of transfer descriptors used per one bulk transfer */
128 /* The reason is to prevent "exhausting" of TD by large bulk */
129 /* transfer - number of TD is limited in USB host driver */
130 /* Value is calculated/estimated in driver - some TDs should be */
131 /* reserved for posible concurrent control or "interrupt" transfers */
132 grub_size_t max_bulk_tds
;
134 /* The next host controller. */
135 struct grub_usb_controller_dev
*next
;
138 struct grub_usb_controller
140 /* The underlying USB Host Controller device. */
141 grub_usb_controller_dev_t dev
;
143 /* Data used by the USB Host Controller Driver. */
148 struct grub_usb_interface
150 struct grub_usb_desc_if
*descif
;
152 struct grub_usb_desc_endp
*descendp
;
154 /* A driver is handling this interface. Do we need to support multiple drivers
155 for single interface?
159 void (*detach_hook
) (struct grub_usb_device
*dev
, int config
, int interface
);
164 struct grub_usb_configuration
166 /* Configuration descriptors . */
167 struct grub_usb_desc_config
*descconf
;
169 /* Interfaces associated to this configuration. */
170 struct grub_usb_interface interf
[32];
173 struct grub_usb_hub_port
175 grub_uint64_t soft_limit_time
;
176 grub_uint64_t hard_limit_time
;
178 PORT_STATE_NORMAL
= 0,
179 PORT_STATE_WAITING_FOR_STABLE_POWER
= 1,
180 PORT_STATE_FAILED_DEVICE
= 2,
181 PORT_STATE_STABLE_POWER
= 3,
185 struct grub_usb_device
187 /* The device descriptor of this device. */
188 struct grub_usb_desc_device descdev
;
190 /* The controller the device is connected to. */
191 struct grub_usb_controller controller
;
193 /* Device configurations (after opening the device). */
194 struct grub_usb_configuration config
[8];
196 /* Device address. */
200 grub_usb_speed_t speed
;
202 /* All descriptors are read if this is set to 1. */
205 /* Data toggle values (used for bulk transfers only). */
208 /* Used by libusb wrapper. Schedulded for removal. */
211 /* Hub information. */
213 /* Array of children for a hub. */
214 grub_usb_device_t
*children
;
216 /* Number of hub ports. */
219 struct grub_usb_hub_port
*ports
;
221 grub_usb_transfer_t hub_transfer
;
223 grub_uint32_t statuschange
;
225 struct grub_usb_desc_endp
*hub_endpoint
;
227 /* EHCI Split Transfer information */
235 typedef enum grub_usb_ep_type
238 GRUB_USB_EP_ISOCHRONOUS
,
240 GRUB_USB_EP_INTERRUPT
241 } grub_usb_ep_type_t
;
243 static inline enum grub_usb_ep_type
244 grub_usb_get_ep_type (struct grub_usb_desc_endp
*ep
)
246 return ep
->attrib
& 3;
251 GRUB_USB_CLASS_NOTHERE
,
252 GRUB_USB_CLASS_AUDIO
,
253 GRUB_USB_CLASS_COMMUNICATION
,
256 GRUB_USB_CLASS_PHYSICAL
,
257 GRUB_USB_CLASS_IMAGE
,
258 GRUB_USB_CLASS_PRINTER
,
259 GRUB_USB_CLASS_MASS_STORAGE
,
261 GRUB_USB_CLASS_DATA_INTERFACE
,
262 GRUB_USB_CLASS_SMART_CARD
,
263 GRUB_USB_CLASS_CONTENT_SECURITY
,
265 } grub_usb_classes_t
;
269 GRUB_USBMS_SUBCLASS_BULK
= 0x06,
270 /* Experimental support for non-pure SCSI devices */
271 GRUB_USBMS_SUBCLASS_RBC
= 0x01,
272 GRUB_USBMS_SUBCLASS_MMC2
= 0x02,
273 GRUB_USBMS_SUBCLASS_UFI
= 0x04,
274 GRUB_USBMS_SUBCLASS_SFF8070
= 0x05
275 } grub_usbms_subclass_t
;
279 GRUB_USBMS_PROTOCOL_BULK
= 0x50,
280 /* Experimental support for Control/Bulk/Interrupt (CBI) devices */
281 GRUB_USBMS_PROTOCOL_CBI
= 0x00, /* CBI with interrupt */
282 GRUB_USBMS_PROTOCOL_CB
= 0x01 /* CBI wthout interrupt */
283 } grub_usbms_protocol_t
;
285 static inline struct grub_usb_desc_if
*
286 grub_usb_get_config_interface (struct grub_usb_desc_config
*config
)
288 struct grub_usb_desc_if
*interf
;
290 interf
= (struct grub_usb_desc_if
*) (sizeof (*config
) + (char *) config
);
294 typedef int (*grub_usb_attach_hook_class
) (grub_usb_device_t usbdev
,
295 int configno
, int interfno
);
297 struct grub_usb_attach_desc
299 struct grub_usb_attach_desc
*next
;
300 struct grub_usb_attach_desc
**prev
;
302 grub_usb_attach_hook_class hook
;
305 void grub_usb_register_attach_hook_class (struct grub_usb_attach_desc
*desc
);
306 void grub_usb_unregister_attach_hook_class (struct grub_usb_attach_desc
*desc
);
308 void grub_usb_poll_devices (int wait_for_completion
);
310 void grub_usb_device_attach (grub_usb_device_t dev
);
312 grub_usb_bulk_read_extended (grub_usb_device_t dev
,
313 struct grub_usb_desc_endp
*endpoint
,
314 grub_size_t size
, char *data
,
315 int timeout
, grub_size_t
*actual
);
317 grub_usb_bulk_read_background (grub_usb_device_t dev
,
318 struct grub_usb_desc_endp
*endpoint
,
319 grub_size_t size
, void *data
);
321 grub_usb_check_transfer (grub_usb_transfer_t trans
, grub_size_t
*actual
);
323 grub_usb_cancel_transfer (grub_usb_transfer_t trans
);
325 #endif /* GRUB_USB_H */