xref: /haiku/src/add-ons/kernel/bus_managers/usb/usb_private.h (revision eea5774f46bba925156498abf9cb1a1165647bf7)
1 /*
2  * Copyright 2003-2006, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz <mmlr@mlotz.ch>
7  *		Niels S. Reedijk
8  */
9 #ifndef _USB_PRIVATE_H
10 #define _USB_PRIVATE_H
11 
12 
13 #include <device_manager.h>
14 #include <bus/USB.h>
15 
16 #include "usbspec_private.h"
17 #include <lock.h>
18 #include <util/Vector.h>
19 
20 // include vm.h before iovec_support.h for generic_memcpy, which is used by the bus drivers.
21 #include <vm/vm.h>
22 #include <util/iovec_support.h>
23 
24 
25 #define TRACE_OUTPUT(x, y, z...) \
26 	{ \
27 		dprintf("usb %s%s %" B_PRId32 ": ", y, (x)->TypeName(), (x)->USBID()); \
28 		dprintf(z); \
29 	}
30 
31 //#define TRACE_USB
32 #ifdef TRACE_USB
33 #define TRACE(x...)					TRACE_OUTPUT(this, "", x)
34 #define TRACE_STATIC(x, y...)		TRACE_OUTPUT(x, "", y)
35 #define TRACE_MODULE(x...)			dprintf("usb " USB_MODULE_NAME ": " x)
36 #else
37 #define TRACE(x...)					/* nothing */
38 #define TRACE_STATIC(x, y...)		/* nothing */
39 #define TRACE_MODULE(x...)			/* nothing */
40 #endif
41 
42 #define TRACE_ALWAYS(x...)			TRACE_OUTPUT(this, "", x)
43 #define TRACE_ERROR(x...)			TRACE_OUTPUT(this, "error ", x)
44 #define TRACE_MODULE_ALWAYS(x...)	dprintf("usb " USB_MODULE_NAME ": " x)
45 #define TRACE_MODULE_ERROR(x...)	dprintf("usb " USB_MODULE_NAME ": " x)
46 
47 extern device_manager_info *gDeviceManager;
48 
49 
50 class Hub;
51 class Stack;
52 class Device;
53 class Transfer;
54 class BusManager;
55 class Pipe;
56 class ControlPipe;
57 class Object;
58 class PhysicalMemoryAllocator;
59 
60 
61 struct usb_host_controller_info {
62 	module_info info;
63 	status_t (*control)(uint32 op, void *data, size_t length);
64 	status_t (*add_to)(Stack *stack);
65 };
66 
67 
68 struct usb_driver_cookie {
69 	usb_id device;
70 	void *cookie;
71 	usb_driver_cookie *link;
72 };
73 
74 
75 struct usb_driver_info {
76 	const char *driver_name;
77 	usb_support_descriptor *support_descriptors;
78 	uint32 support_descriptor_count;
79 	const char *republish_driver_name;
80 	usb_notify_hooks notify_hooks;
81 	usb_driver_cookie *cookies;
82 	usb_driver_info *link;
83 };
84 
85 
86 struct change_item {
87 	bool added;
88 	Device *device;
89 	change_item *link;
90 };
91 
92 
93 struct rescan_item {
94 	const char *name;
95 	rescan_item *link;
96 };
97 
98 
99 typedef enum {
100 	USB_SPEED_LOWSPEED = 0,
101 	USB_SPEED_FULLSPEED,
102 	USB_SPEED_HIGHSPEED,
103 	USB_SPEED_SUPERSPEED,
104 	USB_SPEED_SUPERSPEEDPLUS,
105 	USB_SPEED_MAX = USB_SPEED_SUPERSPEEDPLUS
106 } usb_speed;
107 
108 
109 typedef enum {
110 	USB_CHANGE_CREATED = 0,
111 	USB_CHANGE_DESTROYED,
112 	USB_CHANGE_PIPE_POLICY_CHANGED
113 } usb_change;
114 
115 
116 #define USB_OBJECT_NONE					0x00000000
117 #define USB_OBJECT_PIPE					0x00000001
118 #define USB_OBJECT_CONTROL_PIPE			0x00000002
119 #define USB_OBJECT_INTERRUPT_PIPE		0x00000004
120 #define USB_OBJECT_BULK_PIPE			0x00000008
121 #define USB_OBJECT_ISO_PIPE				0x00000010
122 #define USB_OBJECT_INTERFACE			0x00000020
123 #define USB_OBJECT_DEVICE				0x00000040
124 #define USB_OBJECT_HUB					0x00000080
125 
126 
127 class Stack {
128 public:
129 										Stack();
130 										~Stack();
131 
132 		status_t						InitCheck();
133 
134 		bool							Lock();
135 		void							Unlock();
136 
137 		usb_id							GetUSBID(Object *object);
138 		void							PutUSBID(Object *object);
139 
140 		// This sets the object as busy; the caller must set it un-busy.
141 		Object *						GetObject(usb_id id);
142 
143 		// only for the kernel debugger
144 		Object *						GetObjectNoLock(usb_id id) const;
145 
146 		void							AddBusManager(BusManager *bus);
147 		int32							IndexOfBusManager(BusManager *bus) const;
148 		BusManager *					BusManagerAt(int32 index) const;
149 
150 		status_t						AllocateChunk(void **logicalAddress,
151 											phys_addr_t *physicalAddress,
152 											size_t size);
153 		status_t						FreeChunk(void *logicalAddress,
154 											phys_addr_t physicalAddress,
155 											size_t size);
156 
157 		area_id							AllocateArea(void **logicalAddress,
158 											phys_addr_t *physicalAddress,
159 											size_t size, const char *name);
160 
161 		void							NotifyDeviceChange(Device *device,
162 											rescan_item **rescanList,
163 											bool added);
164 		void							RescanDrivers(rescan_item *rescanItem);
165 
166 		// USB API
167 		status_t						RegisterDriver(const char *driverName,
168 											const usb_support_descriptor *
169 												descriptors,
170 											size_t descriptorCount,
171 											const char *republishDriverName);
172 
173 		status_t						InstallNotify(const char *driverName,
174 											const usb_notify_hooks *hooks);
175 		status_t						UninstallNotify(const char *driverName);
176 
177 		usb_id							USBID() const { return 0; }
178 		const char *					TypeName() const { return "stack"; }
179 
180 		void							Explore();
181 
182 private:
183 static	int32							ExploreThread(void *data);
184 
185 		Vector<BusManager *>			fBusManagers;
186 		thread_id						fExploreThread;
187 		sem_id							fExploreSem;
188 
189 		mutex							fStackLock;
190 		mutex							fExploreLock;
191 		PhysicalMemoryAllocator *		fAllocator;
192 
193 		uint32							fObjectIndex;
194 		uint32							fObjectMaxCount;
195 		Object **						fObjectArray;
196 
197 		usb_driver_info *				fDriverList;
198 };
199 
200 
201 /*
202  * This class manages a bus. It is created by the Stack object
203  * after a host controller gives positive feedback on whether the hardware
204  * is found.
205  */
206 class BusManager {
207 public:
208 										BusManager(Stack *stack, device_node* node);
209 virtual									~BusManager();
210 
211 virtual	status_t						InitCheck();
212 
213 		bool							Lock();
214 		void							Unlock();
215 
216 		int8							AllocateAddress();
217 		void							FreeAddress(int8 address);
218 
219 virtual	Device *						AllocateDevice(Hub *parent,
220 											int8 hubAddress, uint8 hubPort,
221 											usb_speed speed);
222 virtual void							FreeDevice(Device *device);
223 
224 virtual	status_t						Start();
225 virtual	status_t						Stop();
226 
227 virtual	status_t						StartDebugTransfer(Transfer *transfer);
228 virtual	status_t						CheckDebugTransfer(Transfer *transfer);
229 virtual	void							CancelDebugTransfer(Transfer *transfer);
230 
231 virtual	status_t						SubmitTransfer(Transfer *transfer);
232 virtual	status_t						CancelQueuedTransfers(Pipe *pipe,
233 											bool force);
234 
235 virtual	status_t						NotifyPipeChange(Pipe *pipe,
236 											usb_change change);
237 
238 		Object *						RootObject() const
239 											{ return fRootObject; }
240 
241 		Hub *							GetRootHub() const { return fRootHub; }
242 		void							SetRootHub(Hub *hub) { fRootHub = hub; }
243 
244 virtual	const char *					TypeName() const = 0;
245 
246 		device_node *					Node() const
247 											{ return fNode; }
248 protected:
249 		usb_id							USBID() const { return fStackIndex; }
250 
251 protected:
252 		bool							fInitOK;
253 
254 private:
255 		ControlPipe *					_GetDefaultPipe(usb_speed);
256 
257 		mutex							fLock;
258 
259 		bool							fDeviceMap[128];
260 		int8							fDeviceIndex;
261 
262 		Stack *							fStack;
263 		ControlPipe *					fDefaultPipes[USB_SPEED_MAX + 1];
264 		Hub *							fRootHub;
265 		Object *						fRootObject;
266 
267 		usb_id							fStackIndex;
268 
269 		device_node*					fNode;
270 };
271 
272 
273 class Object {
274 public:
275 										Object(Stack *stack, BusManager *bus);
276 										Object(Object *parent);
277 virtual									~Object();
278 
279 		Object *						Parent() const { return fParent; }
280 
281 		BusManager *					GetBusManager() const
282 											{ return fBusManager; }
283 		Stack *							GetStack() const { return fStack; }
284 
285 		usb_id							USBID() const { return fUSBID; }
286 		void							SetBusy(bool busy)
287 											{ atomic_add(&fBusy, busy ? 1 : -1); }
288 
289 virtual	uint32							Type() const { return USB_OBJECT_NONE; }
290 virtual	const char *					TypeName() const { return "object"; }
291 
292 		// Convenience functions for standard requests
293 virtual	status_t						SetFeature(uint16 selector);
294 virtual	status_t						ClearFeature(uint16 selector);
295 virtual	status_t						GetStatus(uint16 *status);
296 
297 protected:
298 		void							PutUSBID(bool waitForUnbusy = true);
299 		void							WaitForUnbusy();
300 
301 private:
302 		Object *						fParent;
303 		BusManager *					fBusManager;
304 		Stack *							fStack;
305 		usb_id							fUSBID;
306 		int32							fBusy;
307 };
308 
309 
310 /*
311  * The Pipe class is the communication management between the hardware and
312  * the stack. It creates packets, manages these and performs callbacks.
313  */
314 class Pipe : public Object {
315 public:
316 		enum pipeDirection { In, Out, Default };
317 
318 										Pipe(Object *parent);
319 virtual									~Pipe();
320 
321 virtual	void							InitCommon(int8 deviceAddress,
322 											uint8 endpointAddress,
323 											usb_speed speed,
324 											pipeDirection direction,
325 											size_t maxPacketSize,
326 											uint8 interval,
327 											int8 hubAddress, uint8 hubPort);
328 virtual void							InitSuperSpeed(uint8 maxBurst,
329 											uint16 bytesPerInterval);
330 
331 virtual	uint32							Type() const { return USB_OBJECT_PIPE; }
332 virtual	const char *					TypeName() const { return "pipe"; }
333 
334 		int8							DeviceAddress() const
335 											{ return fDeviceAddress; }
336 		usb_speed						Speed() const { return fSpeed; }
337 		pipeDirection					Direction() const { return fDirection; }
338 		uint8							EndpointAddress() const
339 											{ return fEndpointAddress; }
340 		size_t							MaxPacketSize() const
341 											{ return fMaxPacketSize; }
342 		uint8							Interval() const { return fInterval; }
343 
344 		// SuperSpeed-only parameters
345 		uint8							MaxBurst() const
346 											{ return fMaxBurst; }
347 		uint16							BytesPerInterval() const
348 											{ return fBytesPerInterval; }
349 
350 		// Hub port being the one-based logical port number on the hub
351 		void							SetHubInfo(int8 address, uint8 port);
352 		int8							HubAddress() const
353 											{ return fHubAddress; }
354 		uint8							HubPort() const { return fHubPort; }
355 
356 virtual	bool							DataToggle() const
357 											{ return fDataToggle; }
358 virtual	void							SetDataToggle(bool toggle)
359 											{ fDataToggle = toggle; }
360 
361 		status_t						SubmitTransfer(Transfer *transfer);
362 virtual	status_t						CancelQueuedTransfers(bool force);
363 
364 		void							SetControllerCookie(void *cookie)
365 											{ fControllerCookie = cookie; }
366 		void *							ControllerCookie() const
367 											{ return fControllerCookie; }
368 
369 		// Convenience functions for standard requests
370 virtual	status_t						SetFeature(uint16 selector);
371 virtual	status_t						ClearFeature(uint16 selector);
372 virtual	status_t						GetStatus(uint16 *status);
373 
374 protected:
375 		friend class					Device;
376 
377 private:
378 		int8							fDeviceAddress;
379 		uint8							fEndpointAddress;
380 		pipeDirection					fDirection;
381 		usb_speed						fSpeed;
382 		size_t							fMaxPacketSize;
383 		uint8							fInterval;
384 		uint8							fMaxBurst;
385 		uint16							fBytesPerInterval;
386 		int8							fHubAddress;
387 		uint8							fHubPort;
388 		bool							fDataToggle;
389 		void *							fControllerCookie;
390 };
391 
392 
393 class ControlPipe : public Pipe {
394 public:
395 										ControlPipe(Object *parent);
396 virtual									~ControlPipe();
397 
398 virtual	void							InitCommon(int8 deviceAddress,
399 											uint8 endpointAddress,
400 											usb_speed speed,
401 											pipeDirection direction,
402 											size_t maxPacketSize,
403 											uint8 interval,
404 											int8 hubAddress, uint8 hubPort);
405 
406 virtual	uint32							Type() const { return USB_OBJECT_PIPE
407 											| USB_OBJECT_CONTROL_PIPE; }
408 virtual	const char *					TypeName() const
409 											{ return "control pipe"; }
410 
411 										// The data toggle is not relevant
412 										// for control transfers, as they are
413 										// always enclosed by a setup and
414 										// status packet. The toggle always
415 										// starts at 1.
416 virtual	bool							DataToggle() const { return true; }
417 virtual	void							SetDataToggle(bool toggle) {}
418 
419 		status_t						SendRequest(uint8 requestType,
420 											uint8 request, uint16 value,
421 											uint16 index, uint16 length,
422 											void *data, size_t dataLength,
423 											size_t *actualLength);
424 static	void							SendRequestCallback(void *cookie,
425 											status_t status, void *data,
426 											size_t actualLength);
427 
428 		status_t						QueueRequest(uint8 requestType,
429 											uint8 request, uint16 value,
430 											uint16 index, uint16 length,
431 											void *data, size_t dataLength,
432 											usb_callback_func callback,
433 											void *callbackCookie);
434 
435 virtual	status_t						CancelQueuedTransfers(bool force);
436 
437 private:
438 		mutex							fSendRequestLock;
439 		sem_id							fNotifySem;
440 		status_t						fTransferStatus;
441 		size_t							fActualLength;
442 };
443 
444 
445 class InterruptPipe : public Pipe {
446 public:
447 										InterruptPipe(Object *parent);
448 
449 virtual	uint32							Type() const { return USB_OBJECT_PIPE
450 											| USB_OBJECT_INTERRUPT_PIPE; }
451 virtual	const char *					TypeName() const
452 											{ return "interrupt pipe"; }
453 
454 		status_t						QueueInterrupt(void *data,
455 											size_t dataLength,
456 											usb_callback_func callback,
457 											void *callbackCookie);
458 };
459 
460 
461 class BulkPipe : public Pipe {
462 public:
463 										BulkPipe(Object *parent);
464 
465 virtual	void							InitCommon(int8 deviceAddress,
466 											uint8 endpointAddress,
467 											usb_speed speed,
468 											pipeDirection direction,
469 											size_t maxPacketSize,
470 											uint8 interval,
471 											int8 hubAddress, uint8 hubPort);
472 
473 virtual	uint32							Type() const { return USB_OBJECT_PIPE
474 											| USB_OBJECT_BULK_PIPE; }
475 virtual	const char *					TypeName() const { return "bulk pipe"; }
476 
477 		status_t						QueueBulk(void *data,
478 											size_t dataLength,
479 											usb_callback_func callback,
480 											void *callbackCookie);
481 		status_t						QueueBulkV(iovec *vector, size_t vectorCount,
482 											usb_callback_func callback, void *callbackCookie);
483 		status_t						QueueBulkV(physical_entry *vector, size_t vectorCount,
484 											usb_callback_func callback, void *callbackCookie);};
485 
486 
487 class IsochronousPipe : public Pipe {
488 public:
489 										IsochronousPipe(Object *parent);
490 
491 virtual	uint32							Type() const { return USB_OBJECT_PIPE
492 											| USB_OBJECT_ISO_PIPE; }
493 virtual	const char *					TypeName() const { return "iso pipe"; }
494 
495 		status_t						QueueIsochronous(void *data,
496 											size_t dataLength,
497 											usb_iso_packet_descriptor *
498 												packetDescriptor,
499 											uint32 packetCount,
500 											uint32 *startingFrameNumber,
501 											uint32 flags,
502 											usb_callback_func callback,
503 											void *callbackCookie);
504 
505 		status_t						SetPipePolicy(uint8 maxQueuedPackets,
506 											uint16 maxBufferDurationMS,
507 											uint16 sampleSize);
508 		status_t						GetPipePolicy(uint8 *maxQueuedPackets,
509 											uint16 *maxBufferDurationMS,
510 											uint16 *sampleSize);
511 
512 private:
513 		uint8							fMaxQueuedPackets;
514 		uint16							fMaxBufferDuration;
515 		uint16							fSampleSize;
516 };
517 
518 
519 class Interface : public Object {
520 public:
521 										Interface(Object *parent,
522 											uint8 interfaceIndex);
523 
524 virtual	uint32							Type() const
525 											{ return USB_OBJECT_INTERFACE; }
526 virtual	const char *					TypeName() const { return "interface"; }
527 
528 		// Convenience functions for standard requests
529 virtual	status_t						SetFeature(uint16 selector);
530 virtual	status_t						ClearFeature(uint16 selector);
531 virtual	status_t						GetStatus(uint16 *status);
532 
533 private:
534 		uint8							fInterfaceIndex;
535 };
536 
537 
538 class Device : public Object {
539 public:
540 										Device(Object *parent, int8 hubAddress,
541 											uint8 hubPort,
542 											usb_device_descriptor &desc,
543 											int8 deviceAddress,
544 											usb_speed speed, bool isRootHub,
545 											void *controllerCookie = NULL);
546 virtual									~Device();
547 
548 		status_t						InitCheck();
549 
550 virtual	status_t						Changed(change_item **changeList,
551 											bool added);
552 
553 virtual	uint32							Type() const
554 											{ return USB_OBJECT_DEVICE; }
555 virtual	const char *					TypeName() const { return "device"; }
556 
557 		ControlPipe *					DefaultPipe() const
558 											{ return fDefaultPipe; }
559 
560 virtual	status_t						GetDescriptor(uint8 descriptorType,
561 											uint8 index, uint16 languageID,
562 											void *data, size_t dataLength,
563 											size_t *actualLength);
564 
565 		int8							DeviceAddress() const
566 											{ return fDeviceAddress; }
567 		const usb_device_descriptor *	DeviceDescriptor() const;
568 		usb_speed						Speed() const { return fSpeed; }
569 
570 		const usb_configuration_info *	Configuration() const;
571 		const usb_configuration_info *	ConfigurationAt(uint8 index) const;
572 		status_t						SetConfiguration(
573 											const usb_configuration_info *
574 												configuration);
575 		status_t						SetConfigurationAt(uint8 index);
576 		status_t						Unconfigure(bool atDeviceLevel);
577 
578 		status_t						SetAltInterface(
579 											const usb_interface_info *
580 												interface);
581 
582 		void							InitEndpoints(int32 interfaceIndex);
583 		void							ClearEndpoints(int32 interfaceIndex);
584 
585 virtual	status_t						ReportDevice(
586 											usb_support_descriptor *
587 												supportDescriptors,
588 											uint32 supportDescriptorCount,
589 											const usb_notify_hooks *hooks,
590 											usb_driver_cookie **cookies,
591 											bool added, bool recursive);
592 virtual	status_t						BuildDeviceName(char *string,
593 											uint32 *index, size_t bufferSize,
594 											Device *device);
595 
596 		device_node *					RegisterNode(device_node* parent = NULL);
597 
598 		int8							HubAddress() const
599 											{ return fHubAddress; }
600 		uint8							HubPort() const { return fHubPort; }
601 
602 		void							SetControllerCookie(void *cookie)
603 											{ fControllerCookie = cookie; }
604 		void *							ControllerCookie() const
605 											{ return fControllerCookie; }
606 		device_node *					Node() const
607 											{ return fNode; }
608 		void							SetNode(device_node* node) { fNode = node; }
609 
610 		// Convenience functions for standard requests
611 virtual	status_t						SetFeature(uint16 selector);
612 virtual	status_t						ClearFeature(uint16 selector);
613 virtual	status_t						GetStatus(uint16 *status);
614 
615 protected:
616 		usb_device_descriptor			fDeviceDescriptor;
617 		bool							fInitOK;
618 
619 private:
620 		bool							fAvailable;
621 		bool							fIsRootHub;
622 		usb_configuration_info *		fConfigurations;
623 		usb_configuration_info *		fCurrentConfiguration;
624 		usb_speed						fSpeed;
625 		int8							fDeviceAddress;
626 		int8							fHubAddress;
627 		uint8							fHubPort;
628 		ControlPipe *					fDefaultPipe;
629 		void *							fControllerCookie;
630 		device_node*					fNode;
631 };
632 
633 
634 class Hub : public Device {
635 public:
636 										Hub(Object *parent, int8 hubAddress,
637 											uint8 hubPort,
638 											usb_device_descriptor &desc,
639 											int8 deviceAddress,
640 											usb_speed speed, bool isRootHub,
641 											void *controllerCookie = NULL);
642 virtual									~Hub();
643 
644 virtual	status_t						Changed(change_item **changeList,
645 											bool added);
646 
647 virtual	uint32							Type() const { return USB_OBJECT_DEVICE
648 											| USB_OBJECT_HUB; }
649 virtual	const char *					TypeName() const { return "hub"; }
650 
651 virtual	status_t						GetDescriptor(uint8 descriptorType,
652 											uint8 index, uint16 languageID,
653 											void *data, size_t dataLength,
654 											size_t *actualLength);
655 
656 		Device *						ChildAt(uint8 index) const
657 											{ return fChildren[index]; }
658 
659 		status_t						UpdatePortStatus(uint8 index);
660 		status_t						ResetPort(uint8 index);
661 		status_t						DisablePort(uint8 index);
662 
663 		void							Explore(change_item **changeList);
664 static	void							InterruptCallback(void *cookie,
665 											status_t status, void *data,
666 											size_t actualLength);
667 
668 virtual	status_t						ReportDevice(
669 											usb_support_descriptor *
670 												supportDescriptors,
671 											uint32 supportDescriptorCount,
672 											const usb_notify_hooks *hooks,
673 											usb_driver_cookie **cookies,
674 											bool added, bool recursive);
675 virtual	status_t						BuildDeviceName(char *string,
676 											uint32 *index, size_t bufferSize,
677 											Device *device);
678 
679 private:
680 		status_t						_DebouncePort(uint8 index);
681 
682 		InterruptPipe *					fInterruptPipe;
683 		usb_hub_descriptor				fHubDescriptor;
684 
685 		usb_port_status					fInterruptStatus[USB_MAX_PORT_COUNT];
686 		usb_port_status					fPortStatus[USB_MAX_PORT_COUNT];
687 		Device *						fChildren[USB_MAX_PORT_COUNT];
688 };
689 
690 
691 /*
692  * A Transfer is allocated on the heap and passed to the Host Controller in
693  * SubmitTransfer(). It is generated for all queued transfers. If queuing
694  * succeds (SubmitTransfer() returns with >= B_OK) the Host Controller takes
695  * ownership of the Transfer and will delete it as soon as it has called the
696  * set callback function. If SubmitTransfer() failes, the calling function is
697  * responsible for deleting the Transfer.
698  * Also, the transfer takes ownership of the usb_request_data passed to it in
699  * SetRequestData(), but does not take ownership of the data buffer set by
700  * SetData().
701  */
702 class Transfer {
703 public:
704 									Transfer(Pipe *pipe);
705 									~Transfer();
706 
707 		Pipe *						TransferPipe() const { return fPipe; }
708 
709 		void						SetRequestData(usb_request_data *data);
710 		usb_request_data *			RequestData() const { return fRequestData; }
711 
712 		void						SetIsochronousData(
713 										usb_isochronous_data *data);
714 		usb_isochronous_data *		IsochronousData() const
715 										{ return fIsochronousData; }
716 
717 		void						SetData(uint8 *buffer, size_t length);
718 		uint8 *						Data() const
719 										{ return fPhysical ? NULL : (uint8 *)fData.base; }
720 		size_t						DataLength() const { return fData.length; }
721 
722 		bool						IsPhysical() const { return fPhysical; }
723 
724 		void						SetVector(iovec *vector, size_t vectorCount);
725 		void						SetVector(physical_entry *vector, size_t vectorCount);
726 		generic_io_vec *			Vector() { return fVector; }
727 		size_t						VectorCount() const { return fVectorCount; }
728 
729 		uint16						Bandwidth() const { return fBandwidth; }
730 
731 		bool						IsFragmented() const { return fFragmented; }
732 		void						AdvanceByFragment(size_t actualLength);
733 		size_t						FragmentLength() const;
734 
735 		status_t					InitKernelAccess();
736 		status_t					PrepareKernelAccess();
737 
738 		void						SetCallback(usb_callback_func callback,
739 										void *cookie);
740 		usb_callback_func			Callback() const
741 										{ return fCallback; }
742 		void *						CallbackCookie() const
743 										{ return fCallbackCookie; }
744 
745 		void						Finished(uint32 status,
746 										size_t actualLength);
747 
748 		usb_id						USBID() const { return 0; }
749 		const char *				TypeName() const { return "transfer"; }
750 
751 private:
752 		void						_CheckFragmented();
753 		status_t					_CalculateBandwidth();
754 
755 		// Data that is related to the transfer
756 		Pipe *						fPipe;
757 		generic_io_vec				fData;
758 		generic_io_vec *			fVector;
759 		size_t						fVectorCount;
760 		void *						fBaseAddress;
761 		bool						fPhysical;
762 		bool						fFragmented;
763 		size_t						fActualLength;
764 		area_id						fUserArea;
765 		area_id						fClonedArea;
766 
767 		usb_callback_func			fCallback;
768 		void *						fCallbackCookie;
769 
770 		// For control transfers
771 		usb_request_data *			fRequestData;
772 
773 		// For isochronous transfers
774 		usb_isochronous_data *		fIsochronousData;
775 
776 		// For bandwidth management.
777 		// It contains the bandwidth necessary in microseconds
778 		// for either isochronous, interrupt or control transfers.
779 		// Not used for bulk transactions.
780 		uint16						fBandwidth;
781 };
782 
783 
784 // Interface between usb_bus and underlying implementation (xhci_pci)
785 typedef struct usb_bus_interface {
786 	driver_module_info info;
787 } usb_bus_interface;
788 
789 
790 typedef struct {
791 	driver_module_info info;
792 	status_t           (*get_stack)(void** stack);
793 } usb_for_controller_interface;
794 
795 #define USB_FOR_CONTROLLER_MODULE_NAME "bus_managers/usb/controller/driver_v1"
796 
797 // bus manager device interface for peripheral driver
798 typedef struct {
799 	driver_module_info info;
800 
801 } usb_device_interface;
802 
803 
804 #define USB_DEVICE_MODULE_NAME "bus_managers/usb/device/driver_v1"
805 
806 #endif // _USB_PRIVATE_H
807