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