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