forked from minoca/os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kdusb.h
607 lines (393 loc) · 14.3 KB
/
kdusb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
/*++
Copyright (c) 2014 Minoca Corp.
This file is licensed under the terms of the GNU General Public License
version 3. Alternative licensing terms are available. Contact
[email protected] for details. See the LICENSE file at the root of this
project for complete licensing information.
Module Name:
kdusb.h
Abstract:
This header contains definitions for USB debug devices.
Author:
Evan Green 26-Mar-2014
--*/
//
// ------------------------------------------------------------------- Includes
//
//
// ---------------------------------------------------------------- Definitions
//
#define DEBUG_USB_HOST_DESCRIPTION_VERSION 1
//
// Define USB port status bits.
//
#define DEBUG_USB_PORT_STATUS_CONNECTED 0x00000001
#define DEBUG_USB_PORT_STATUS_ENABLED 0x00000002
#define DEBUG_USB_PORT_STATUS_SUSPENDED 0x00000004
#define DEBUG_USB_PORT_STATUS_OVER_CURRENT 0x00000008
#define DEBUG_USB_PORT_STATUS_RESET 0x00000010
#define DEBUG_USB_PORT_STATUS_LOW_SPEED 0x00000100
#define DEBUG_USB_PORT_STATUS_FULL_SPEED 0x00000200
#define DEBUG_USB_PORT_STATUS_HIGH_SPEED 0x00000400
#define DEBUG_USB_PORT_STATUS_SUPER_SPEED 0x00000800
#define DEBUG_USB_SETUP_PACKET_SIZE 8
#define DEBUG_USB_ENDPOINT_ADDRESS_MASK 0x0F
//
// ------------------------------------------------------ Data Type Definitions
//
typedef enum _DEBUG_USB_DEVICE_SPEED {
DebugUsbDeviceSpeedInvalid,
DebugUsbDeviceSpeedLow,
DebugUsbDeviceSpeedFull,
DebugUsbDeviceSpeedHigh,
DebugUsbDeviceSpeedSuper,
} DEBUG_USB_DEVICE_SPEED, *PDEBUG_USB_DEVICE_SPEED;
typedef enum _DEBUG_USB_TRANSFER_TYPE {
DebugUsbTransferTypeInvalid,
DebugUsbTransferTypeControl,
DebugUsbTransferTypeInterrupt,
DebugUsbTransferTypeBulk,
DebugUsbTransferTypeIsochronous,
DebugUsbTransferTypeCount
} DEBUG_USB_TRANSFER_TYPE, *PDEBUG_USB_TRANSFER_TYPE;
typedef enum _DEBUG_USB_TRANSFER_DIRECTION {
DebugUsbTransferDirectionInvalid,
DebugUsbTransferDirectionIn,
DebugUsbTransferDirectionOut,
DebugUsbTransferBidirectional,
DebugUsbTransferDirectionCount
} DEBUG_USB_TRANSFER_DIRECTION, *PDEBUG_USB_TRANSFER_DIRECTION;
/*++
Structure Description:
This structure stores information about a debug USB transfer request.
Members:
Type - Stores the type of USB request that this transfer is.
Direction - Stores the direction of the USB endpoint.
Speed - Stores the speed of the destination device.
HubAddress - Stores the address of the hub this device is connected to.
This is only required for full or low speed devices on a high speed
bus.
HubPort - Stores the one-based port number of the hub this device is
connected to. This is only required for full or low speed devices on a
high speed bus.
EndpointNumber - Stores the endpoint number, including the high 0x80 bit.
DeviceAddress - Stores the device address of the device that owns this
endpoint.
DataToggle - Stores the data toggle value of the next transfer descriptor
to be filled out.
Halted - Stores a boolean indicating if the endpoint is halted.
MaxPacketSize - Stores the maximum packet size of this endpoint.
--*/
typedef struct _DEBUG_USB_ENDPOINT {
DEBUG_USB_TRANSFER_TYPE Type;
DEBUG_USB_TRANSFER_DIRECTION Direction;
DEBUG_USB_DEVICE_SPEED Speed;
UCHAR HubAddress;
UCHAR HubPort;
UCHAR EndpointNumber;
UCHAR DeviceAddress;
BOOL DataToggle;
BOOL Halted;
ULONG MaxPacketSize;
} DEBUG_USB_ENDPOINT, *PDEBUG_USB_ENDPOINT;
/*++
Structure Description:
This structure stores information about a debug USB transfer request.
Members:
Endpoint - Stores a pointer to the endpoint this transfer is associated
with.
Direction - Stores the direction of the USB transfer. This must be
consistent with the endpoint being sent to.
Length - Stores the length of the request, in bytes.
LengthTransferred - Stores the number of bytes that have actually been
transferred.
Buffer - Stores a pointer to the data buffer.
BufferPhysicalAddress - Stores the physical address of the data buffer.
HostContext - Stores a pointer of context for the host controller.
HostDescriptorCount - Stores a value used optionally and internally by the
host controller. Consumers should not use this value.
Status - Stores the completion status of the request.
--*/
typedef struct _DEBUG_USB_TRANSFER {
PDEBUG_USB_ENDPOINT Endpoint;
DEBUG_USB_TRANSFER_DIRECTION Direction;
ULONG Length;
ULONG LengthTransferred;
PVOID Buffer;
PHYSICAL_ADDRESS BufferPhysicalAddress;
PVOID HostContext;
ULONG HostDescriptorCount;
KSTATUS Status;
} DEBUG_USB_TRANSFER, *PDEBUG_USB_TRANSFER;
typedef
KSTATUS
(*PDEBUG_USB_HOST_INITIALIZE) (
PVOID Context
);
/*++
Routine Description:
This routine initializes a USB debug device, preparing it to return the
root hub status and ultimately send and receive transfers.
Arguments:
Context - Supplies a pointer to the device context.
Return Value:
Status code.
--*/
typedef
KSTATUS
(*PDEBUG_USB_HOST_GET_ROOT_HUB_STATUS) (
PVOID Context,
ULONG PortIndex,
PULONG PortStatus
);
/*++
Routine Description:
This routine queries the host controller for the status of a root hub port.
Arguments:
Context - Supplies a pointer to the device context.
PortIndex - Supplies the zero-based port number to query.
PortStatus - Supplies a pointer where the port status is returned.
Return Value:
STATUS_SUCCESS if the hub status was successfully queried.
STATUS_OUT_OF_BOUNDS if the controller port index is out of range.
STATUS_DEVICE_IO_ERROR if a device error occurred.
--*/
typedef
KSTATUS
(*PDEBUG_USB_HOST_SET_ROOT_HUB_STATUS) (
PVOID Context,
ULONG PortIndex,
ULONG PortStatus
);
/*++
Routine Description:
This routine sets the host controller for the status of a root hub port.
Arguments:
Context - Supplies a pointer to the device context.
PortIndex - Supplies the zero-based port number to set.
PortStatus - Supplies the port status to set.
Return Value:
STATUS_SUCCESS if the hub status was successfully queried.
STATUS_OUT_OF_BOUNDS if the controller port index is out of range.
STATUS_DEVICE_IO_ERROR if a device error occurred.
--*/
typedef
KSTATUS
(*PDEBUG_USB_HOST_SETUP_TRANSFER) (
PVOID Context,
PDEBUG_USB_TRANSFER Transfer
);
/*++
Routine Description:
This routine allocates a buffer and initializes the given USB transfer.
Arguments:
Context - Supplies a pointer to the device context.
Transfer - Supplies a pointer to the transfer to initialize to. The caller
must have filled out the endpoint, direction, and length members. This
routine will allocate buffer space for the transfer data.
Return Value:
STATUS_SUCCESS if the hub status was successfully queried.
STATUS_INVALID_PARAMETER if the given transfer was not filled out correctly.
STATUS_INSUFFICIENT_RESOURCES if a buffer for the transfer could not be
allocated.
STATUS_DEVICE_IO_ERROR if a device error occurred.
--*/
typedef
KSTATUS
(*PDEBUG_USB_HOST_SUBMIT_TRANSFER) (
PVOID Context,
PDEBUG_USB_TRANSFER Transfer,
BOOL WaitForCompletion
);
/*++
Routine Description:
This routine submits a previously set up USB transfer.
Arguments:
Context - Supplies a pointer to the device context.
Transfer - Supplies a pointer to the transfer to submit.
WaitForCompletion - Supplies a boolean indicating if the routine should
block until the transfer completes.
Return Value:
STATUS_SUCCESS if the hub status was successfully queried.
STATUS_INVALID_PARAMETER if the given transfer was not initialized
correctly.
STATUS_DEVICE_IO_ERROR if a device error occurred.
STATUS_TIMEOUT if the caller wanted to wait for the transfer but it
never completed.
--*/
typedef
KSTATUS
(*PDEBUG_USB_HOST_CHECK_TRANSFER) (
PVOID Context,
PDEBUG_USB_TRANSFER Transfer
);
/*++
Routine Description:
This routine checks on the completion status of a transfer.
Arguments:
Context - Supplies a pointer to the device context.
Transfer - Supplies a pointer to the transfer to check.
Return Value:
STATUS_SUCCESS if the hub status was successfully queried.
STATUS_INVALID_PARAMETER if the given transfer was not initialized
correctly.
STATUS_DEVICE_IO_ERROR if a device error occurred.
STATUS_MORE_PROCESSING_REQUIRED if the transfer is still in progress.
--*/
typedef
KSTATUS
(*PDEBUG_USB_HOST_RETIRE_TRANSFER) (
PVOID Context,
PDEBUG_USB_TRANSFER Transfer
);
/*++
Routine Description:
This routine retires an EHCI. This frees the buffer allocated during setup.
Arguments:
Context - Supplies a pointer to the device context.
Transfer - Supplies a pointer to the transfer to retire.
Return Value:
STATUS_SUCCESS if the hub status was successfully queried.
STATUS_INVALID_PARAMETER if the given transfer was not initialized
correctly.
STATUS_DEVICE_IO_ERROR if a device error occurred.
--*/
typedef
KSTATUS
(*PDEBUG_USB_HOST_STALL) (
PVOID Context,
ULONG Milliseconds
);
/*++
Routine Description:
This routine burns time using the frame index register to mark time.
Arguments:
Context - Supplies a pointer to the device context.
Milliseconds - Supplies the number of milliseconds to stall for.
Return Value:
STATUS_SUCCESS if the hub status was successfully queried.
STATUS_DEVICE_IO_ERROR if a device error occurred.
--*/
typedef
KSTATUS
(*PDEBUG_USB_HOST_GET_HANDOFF_DATA) (
PVOID Context,
PDEBUG_USB_HANDOFF_DATA HandoffData
);
/*++
Routine Description:
This routine returns the controller specific handoff data in preparation
for the real USB driver taking over primary functionality.
Arguments:
Context - Supplies a pointer to the device context.
HandoffData - Supplies a pointer to the handoff data. The controller should
fill in the host controller specific data and size fields.
Return Value:
Status code.
--*/
/*++
Structure Description:
This structure contains the function table for a debug USB host device.
Members:
Initialize - Stores a pointer to a function used to initialize the USB
host controller.
GetRootHubStatus - Stores a pointer to a function used to get the status
of a port on the root hub of the USB host controller.
SetRootHubStatus - Stores a pointer to a function used to set the status
of a port on the root hub of the USB host controller.
SetupTransfer - Stores a pointer to a function used to allocate and
initialize a transfer that will be submitted to the USB host controller.
SubmitTransfer - Stores a pointer to a function use to submit a transfer
to the USB host controller.
CheckTransfer - Stores a pointer to a function used to check the completion
status of a submitted transfer.
RetireTransfer - Stores a pointer to a function used to deschedule and
deallocate a previously set up usb transfer.
Stall - Stores a pointer to a function that provides time-based busy
spinning using the USB host controller's frame counter.
GetHandoffData - Stores a pointer to a function used to get the handoff
data in preparation for the official USB host controller driver taking
over.
--*/
typedef struct _DEBUG_USB_HOST_FUNCTION_TABLE {
PDEBUG_USB_HOST_INITIALIZE Initialize;
PDEBUG_USB_HOST_GET_ROOT_HUB_STATUS GetRootHubStatus;
PDEBUG_USB_HOST_SET_ROOT_HUB_STATUS SetRootHubStatus;
PDEBUG_USB_HOST_SETUP_TRANSFER SetupTransfer;
PDEBUG_USB_HOST_SUBMIT_TRANSFER SubmitTransfer;
PDEBUG_USB_HOST_CHECK_TRANSFER CheckTransfer;
PDEBUG_USB_HOST_RETIRE_TRANSFER RetireTransfer;
PDEBUG_USB_HOST_STALL Stall;
PDEBUG_USB_HOST_GET_HANDOFF_DATA GetHandoffData;
} DEBUG_USB_HOST_FUNCTION_TABLE, *PDEBUG_USB_HOST_FUNCTION_TABLE;
/*++
Structure Description:
This structure is used to describe a USB host controller implementation
that can be used for kernel debugging.
Members:
TableVersion - Stores the version of the USB host controller description
table as understood by the hardware module. Set this to
DEBUG_USB_HOST_DESCRIPTION_VERSION.
FunctionTable - Stores the table of pointers to the hardware module's
functions.
Context - Stores a pointer's worth of data specific to this instance. This
pointer will be passed back to the hardware module on each call.
Identifier - Stores the unique identifier of the controller.
PortSubType - Stores the host controller sub-type, as defined by the Debug
Port Table 2 specification.
--*/
typedef struct _DEBUG_USB_HOST_DESCRIPTION {
ULONG TableVersion;
DEBUG_USB_HOST_FUNCTION_TABLE FunctionTable;
PVOID Context;
ULONGLONG Identifier;
USHORT PortSubType;
} DEBUG_USB_HOST_DESCRIPTION, *PDEBUG_USB_HOST_DESCRIPTION;
/*++
Structure Description:
This structure stores the information about a USB debug device.
Members:
Host - Stores a pointer to the host controller.
--*/
typedef struct _HARDWARE_USB_DEBUG_DEVICE {
PDEBUG_USB_HOST_DESCRIPTION Host;
} HARDWARE_USB_DEBUG_DEVICE, *PHARDWARE_USB_DEBUG_DEVICE;
//
// -------------------------------------------------------------------- Globals
//
//
// -------------------------------------------------------- Function Prototypes
//
KSTATUS
KdUsbInitialize (
PDEBUG_USB_HOST_DESCRIPTION Host,
BOOL TestInterface
);
/*++
Routine Description:
This routine initializes a USB debug based transport.
Arguments:
Host - Supplies a pointer to the host controller.
TestInterface - Supplies a boolean indicating if the interface test should
be run. This is only true under debugging scenarios where the USB
debug transport itself is being debugged.
Return Value:
Status code.
--*/
//
// Host controller module initialization functions.
//
VOID
KdEhciModuleEntry (
VOID
);
/*++
Routine Description:
This routine is the entry point for a hardware module. Its role is to
detect the prescense of any of the hardware modules it contains
implementations for and instantiate them with the kernel.
Arguments:
None.
Return Value:
None.
--*/