123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607 |
- /*++
- 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
- info@minocacorp.com 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.
- --*/
|