mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 13:02:59 +00:00
[SDK][USB] Delete old USB drivers and libusb
This commit is contained in:
parent
0685e02d9e
commit
83c07f4e4c
52 changed files with 0 additions and 26396 deletions
|
@ -4,7 +4,6 @@ add_subdirectory(copysup)
|
|||
add_subdirectory(csq)
|
||||
add_subdirectory(hidparser)
|
||||
add_subdirectory(ip)
|
||||
add_subdirectory(libusb)
|
||||
add_subdirectory(lwip)
|
||||
add_subdirectory(ntoskrnl_vista)
|
||||
add_subdirectory(rdbsslib)
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
|
||||
set_cpp()
|
||||
|
||||
remove_definitions(-D_WIN32_WINNT=0x502)
|
||||
add_definitions(-D_WIN32_WINNT=0x600)
|
||||
|
||||
add_definitions(-DUNICODE -D_UNICODE)
|
||||
|
||||
list(APPEND SOURCE
|
||||
hcd_controller.cpp
|
||||
hub_controller.cpp
|
||||
memory_manager.cpp
|
||||
misc.cpp
|
||||
usb_device.cpp
|
||||
purecall.cpp
|
||||
libusb.cpp
|
||||
libusb.h)
|
||||
|
||||
add_library(libusb ${SOURCE})
|
||||
add_dependencies(libusb bugcodes xdk)
|
||||
add_pch(libusb libusb.h SOURCE)
|
|
@ -1,691 +0,0 @@
|
|||
|
||||
#ifndef COMMON_INTERFACES_HPP
|
||||
#define COMMON_INTERFACES_HPP
|
||||
|
||||
typedef struct _USB_ENDPOINT
|
||||
{
|
||||
USB_ENDPOINT_DESCRIPTOR EndPointDescriptor;
|
||||
UCHAR HubAddress;
|
||||
UCHAR HubPort;
|
||||
UCHAR DataToggle;
|
||||
} USB_ENDPOINT, *PUSB_ENDPOINT;
|
||||
|
||||
typedef struct _USB_INTERFACE
|
||||
{
|
||||
LIST_ENTRY ListEntry;
|
||||
PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
|
||||
USB_ENDPOINT EndPoints[1];
|
||||
} USB_INTERFACE, *PUSB_INTERFACE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
|
||||
LIST_ENTRY InterfaceList;
|
||||
}USB_CONFIGURATION, *PUSB_CONFIGURATION;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Object Hierarchy
|
||||
// --------------------------------------------------------------------
|
||||
// | IRootHCDController |
|
||||
// | IHCDController Intel USB Universal Host Controller - 3A37 |
|
||||
// | IHCDController - Intel USB Universal HostController - 3A38 |
|
||||
// | IHCDController - Intel USB Universal HostController - 3A38 |
|
||||
// |------------------------------------------------------------------|
|
||||
//
|
||||
//
|
||||
// IHCDController Intel USB Universal Host Controller - 3A37
|
||||
// IHubController
|
||||
// IUSBHardwareDevice
|
||||
// IDMAMemoryManager
|
||||
// IUSBQueue <- interacts with -> IUSBRequest
|
||||
//
|
||||
//
|
||||
// Each IHCDController creates an IUSBHardwareDevice class upon initialization. The
|
||||
// IUSBHardwardeDevice class is used to abstract usb controller specifics. The IHubController
|
||||
// manages all attached devices and handles hub control ioctl requests.
|
||||
//
|
||||
// Each IUSBHardwareDevice has one IDMAMemoryManager and one IUSBQueue. The IDMAMemoryManager
|
||||
// is used to handle dma memory allocations. The IUSBQueue manages requests which are send to the
|
||||
// usb hardware. See IUSBRequest class for details.
|
||||
//
|
||||
|
||||
|
||||
//=========================================================================================
|
||||
//
|
||||
// class IRootHCDController
|
||||
//
|
||||
// Description: This class serves as the root host controller. The host controller mantains
|
||||
// a list of registered controllers and provides support functions for the host controllers
|
||||
|
||||
struct IHCDController;
|
||||
|
||||
DECLARE_INTERFACE_(IRootHCDController, IUnknown)
|
||||
{
|
||||
DEFINE_ABSTRACT_UNKNOWN()
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// Initialize
|
||||
//
|
||||
// Description: This function initializes the root host controller. It allocates the resources
|
||||
// required to manage the registered controllers
|
||||
|
||||
virtual NTSTATUS Initialize() = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// RegisterHCD
|
||||
//
|
||||
// Description: this function registers a host controller with the root host controller
|
||||
|
||||
virtual NTSTATUS RegisterHCD(struct IHCDController * Controller) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// UnregisterHCD
|
||||
//
|
||||
// Description: this function unregistes a host controller
|
||||
|
||||
virtual NTSTATUS UnregisterHCD(struct IHCDController * Controller) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetControllerCount
|
||||
//
|
||||
// Description: returns the number of host controllers registered
|
||||
|
||||
virtual ULONG GetControllerCount() = 0;
|
||||
|
||||
};
|
||||
|
||||
typedef IRootHCDController *PROOTHDCCONTROLLER;
|
||||
|
||||
//=========================================================================================
|
||||
//
|
||||
// class IHCDController
|
||||
//
|
||||
// Description: This class is used to manage a single USB host controller
|
||||
//
|
||||
|
||||
DECLARE_INTERFACE_(IHCDController, IUnknown)
|
||||
{
|
||||
DEFINE_ABSTRACT_UNKNOWN()
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// Initialize
|
||||
//
|
||||
// Description: This function initializes the IHCDController implementation.
|
||||
// It creates an IUSBHardwareDevice object and initializes it. It also registeres itself with
|
||||
// the IRootHCDController
|
||||
//
|
||||
virtual NTSTATUS Initialize(IN PROOTHDCCONTROLLER RootHCDController,
|
||||
IN PDRIVER_OBJECT DriverObject,
|
||||
IN PDEVICE_OBJECT PhysicalDeviceObject) = 0;
|
||||
|
||||
};
|
||||
|
||||
typedef IHCDController *PHCDCONTROLLER;
|
||||
|
||||
|
||||
//=========================================================================================
|
||||
//
|
||||
// class IUSBHardwareDevice
|
||||
//
|
||||
// Description: This class provides access to the usb hardware controller
|
||||
//
|
||||
|
||||
struct IDMAMemoryManager;
|
||||
struct IUSBQueue;
|
||||
|
||||
#define DEFINE_ABSTRACT_USBHARDWAREDEVICE() \
|
||||
STDMETHOD_(NTSTATUS, Initialize)( THIS_ \
|
||||
IN PDRIVER_OBJECT DriverObject, \
|
||||
IN PDEVICE_OBJECT FunctionalDeviceObject, \
|
||||
IN PDEVICE_OBJECT PhysicalDeviceObject, \
|
||||
IN PDEVICE_OBJECT LowerDeviceObject) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, PnpStart)( THIS_ \
|
||||
IN PCM_RESOURCE_LIST RawResources, \
|
||||
IN PCM_RESOURCE_LIST TranslatedResources) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, PnpStop)( THIS) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, GetDeviceDetails)( THIS_ \
|
||||
OUT OPTIONAL PUSHORT VendorId, \
|
||||
OUT OPTIONAL PUSHORT DeviceId, \
|
||||
OUT OPTIONAL PULONG NumberOfPorts, \
|
||||
OUT OPTIONAL PULONG Speed) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, GetUSBQueue)( THIS_ \
|
||||
OUT struct IUSBQueue **OutUsbQueue) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, GetDMA)( THIS_ \
|
||||
OUT struct IDMAMemoryManager **OutDMA) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, ResetPort)( THIS_ \
|
||||
IN ULONG PortNumber) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, GetPortStatus)( THIS_ \
|
||||
IN ULONG PortId, \
|
||||
OUT USHORT *PortStatus, \
|
||||
OUT USHORT *PortChange) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, ClearPortStatus)( THIS_ \
|
||||
IN ULONG PortId, \
|
||||
IN ULONG Status) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, SetPortFeature)( THIS_ \
|
||||
IN ULONG PortId, \
|
||||
IN ULONG Feature) PURE; \
|
||||
\
|
||||
STDMETHOD_(VOID, SetStatusChangeEndpointCallBack)( THIS_ \
|
||||
IN PVOID CallBack, \
|
||||
IN PVOID Context) PURE; \
|
||||
\
|
||||
STDMETHOD_(LPCSTR, GetUSBType)(THIS) PURE;
|
||||
|
||||
|
||||
#define IMP_IUSBHARDWAREDEVICE \
|
||||
STDMETHODIMP_(NTSTATUS) Initialize( \
|
||||
IN PDRIVER_OBJECT DriverObject, \
|
||||
IN PDEVICE_OBJECT FunctionalDeviceObject, \
|
||||
IN PDEVICE_OBJECT PhysicalDeviceObject, \
|
||||
IN PDEVICE_OBJECT LowerDeviceObject); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) PnpStart( \
|
||||
IN PCM_RESOURCE_LIST RawResources, \
|
||||
IN PCM_RESOURCE_LIST TranslatedResources); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) PnpStop(VOID); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) GetDeviceDetails( \
|
||||
OUT OPTIONAL PUSHORT VendorId, \
|
||||
OUT OPTIONAL PUSHORT DeviceId, \
|
||||
OUT OPTIONAL PULONG NumberOfPorts, \
|
||||
OUT OPTIONAL PULONG Speed); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) GetUSBQueue( \
|
||||
OUT struct IUSBQueue **OutUsbQueue); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) GetDMA( \
|
||||
OUT struct IDMAMemoryManager **OutDMA); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) ResetPort( \
|
||||
IN ULONG PortNumber); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) GetPortStatus( \
|
||||
IN ULONG PortId, \
|
||||
OUT USHORT *PortStatus, \
|
||||
OUT USHORT *PortChange); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) ClearPortStatus( \
|
||||
IN ULONG PortId, \
|
||||
IN ULONG Status); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) SetPortFeature( \
|
||||
IN ULONG PortId, \
|
||||
IN ULONG Feature); \
|
||||
\
|
||||
STDMETHODIMP_(VOID) SetStatusChangeEndpointCallBack( \
|
||||
IN PVOID CallBack, \
|
||||
IN PVOID Context); \
|
||||
\
|
||||
STDMETHODIMP_(LPCSTR) GetUSBType();
|
||||
|
||||
DECLARE_INTERFACE_(IUSBHardwareDevice, IUnknown)
|
||||
{
|
||||
DEFINE_ABSTRACT_UNKNOWN()
|
||||
DEFINE_ABSTRACT_USBHARDWAREDEVICE()
|
||||
};
|
||||
|
||||
typedef IUSBHardwareDevice *PUSBHARDWAREDEVICE;
|
||||
|
||||
|
||||
//=========================================================================================
|
||||
//
|
||||
// class IDMAMemoryManager
|
||||
//
|
||||
// Description: This class provides access to the dma buffer. It provides methods to
|
||||
// allocate and free from the dma buffer
|
||||
//
|
||||
|
||||
DECLARE_INTERFACE_(IDMAMemoryManager, IUnknown)
|
||||
{
|
||||
DEFINE_ABSTRACT_UNKNOWN()
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// Initialize
|
||||
//
|
||||
// Description: initializes the memory manager
|
||||
|
||||
virtual NTSTATUS Initialize(IN PUSBHARDWAREDEVICE Device,
|
||||
IN PKSPIN_LOCK Lock,
|
||||
IN ULONG DmaBufferSize,
|
||||
IN PVOID VirtualBase,
|
||||
IN PHYSICAL_ADDRESS PhysicalAddress,
|
||||
IN ULONG DefaultBlockSize) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// Allocate
|
||||
//
|
||||
// Description: allocates block of memory from allocator
|
||||
|
||||
virtual NTSTATUS Allocate(IN ULONG Size,
|
||||
OUT PVOID *OutVirtualBase,
|
||||
OUT PPHYSICAL_ADDRESS OutPhysicalAddress) = 0;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// Free
|
||||
//
|
||||
// Description: releases memory block
|
||||
|
||||
virtual NTSTATUS Release(IN PVOID VirtualBase,
|
||||
IN ULONG Size) = 0;
|
||||
|
||||
};
|
||||
|
||||
typedef IDMAMemoryManager *PDMAMEMORYMANAGER;
|
||||
|
||||
|
||||
//=========================================================================================
|
||||
//
|
||||
// class IUSBRequest
|
||||
//
|
||||
// Description: This class is used to issue request to usb controller. The class is
|
||||
// initialized using InitializeXXX methods. You also need to call SetEndpoint to define the endpoint
|
||||
// In addition you can call SetCompletionDetails if you need to wait for the end of
|
||||
// the request or want to complete an irp. You call AddUSBRequest to add the request to the queue.
|
||||
// Once the request is completed the CompletionCallback is invoked. The CompletionCallback
|
||||
// will take care of any completion details which have been set. If the request is cancelled, the
|
||||
// CancelCallback routine is invoked.
|
||||
//
|
||||
|
||||
struct IUSBDevice;
|
||||
|
||||
#define DEFINE_ABSTRACT_USBREQUEST() \
|
||||
STDMETHOD_(NTSTATUS, InitializeWithSetupPacket)( THIS_ \
|
||||
IN PDMAMEMORYMANAGER DmaManager, \
|
||||
IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket, \
|
||||
IN struct IUSBDevice *Device, \
|
||||
IN OPTIONAL struct _USB_ENDPOINT *EndpointDescriptor, \
|
||||
IN OUT ULONG TransferBufferLength, \
|
||||
IN OUT PMDL TransferBuffer) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, InitializeWithIrp)( THIS_ \
|
||||
IN PDMAMEMORYMANAGER DmaManager, \
|
||||
IN struct IUSBDevice *Device, \
|
||||
IN OUT PIRP Irp) PURE; \
|
||||
\
|
||||
STDMETHOD_(BOOLEAN, IsRequestComplete)( THIS) PURE; \
|
||||
\
|
||||
STDMETHOD_(ULONG, GetTransferType)( THIS) PURE; \
|
||||
\
|
||||
STDMETHOD_(VOID, GetResultStatus)( THIS_ \
|
||||
OUT OPTIONAL NTSTATUS * NtStatusCode, \
|
||||
OUT OPTIONAL PULONG UrbStatusCode) PURE;
|
||||
|
||||
#define IMP_IUSBREQUEST \
|
||||
STDMETHODIMP_(NTSTATUS) InitializeWithSetupPacket( \
|
||||
IN PDMAMEMORYMANAGER DmaManager, \
|
||||
IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket, \
|
||||
IN struct IUSBDevice *Device, \
|
||||
IN OPTIONAL struct _USB_ENDPOINT *EndpointDescriptor, \
|
||||
IN OUT ULONG TransferBufferLength, \
|
||||
IN OUT PMDL TransferBuffer); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) InitializeWithIrp( \
|
||||
IN PDMAMEMORYMANAGER DmaManager, \
|
||||
IN struct IUSBDevice *Device, \
|
||||
IN OUT PIRP Irp); \
|
||||
\
|
||||
STDMETHODIMP_(BOOLEAN) IsRequestComplete(VOID); \
|
||||
\
|
||||
STDMETHODIMP_(ULONG) GetTransferType(VOID); \
|
||||
\
|
||||
STDMETHODIMP_(VOID) GetResultStatus( \
|
||||
OUT OPTIONAL NTSTATUS * NtStatusCode, \
|
||||
OUT OPTIONAL PULONG UrbStatusCode);
|
||||
|
||||
DECLARE_INTERFACE_(IUSBRequest, IUnknown)
|
||||
{
|
||||
DEFINE_ABSTRACT_UNKNOWN()
|
||||
DEFINE_ABSTRACT_USBREQUEST()
|
||||
};
|
||||
|
||||
|
||||
typedef IUSBRequest *PUSBREQUEST;
|
||||
|
||||
//=========================================================================================
|
||||
//
|
||||
// class IUSBQueue
|
||||
//
|
||||
// Description: This class manages pending requests
|
||||
//
|
||||
|
||||
#define DEFINE_ABSTRACT_USBQUEUE() \
|
||||
STDMETHOD_(NTSTATUS, Initialize)( THIS_ \
|
||||
IN PUSBHARDWAREDEVICE Hardware, \
|
||||
IN PDMA_ADAPTER AdapterObject, \
|
||||
IN PDMAMEMORYMANAGER MemManager, \
|
||||
IN OPTIONAL PKSPIN_LOCK Lock) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, AddUSBRequest)( THIS_ \
|
||||
IN IUSBRequest * Request) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, CreateUSBRequest)( THIS_ \
|
||||
IN IUSBRequest **OutRequest) PURE; \
|
||||
\
|
||||
STDMETHOD_(NTSTATUS, AbortDevicePipe)( THIS_ \
|
||||
IN UCHAR DeviceAddress, \
|
||||
IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor) PURE;
|
||||
|
||||
#define IMP_IUSBQUEUE \
|
||||
STDMETHODIMP_(NTSTATUS) Initialize( \
|
||||
IN PUSBHARDWAREDEVICE Hardware, \
|
||||
IN PDMA_ADAPTER AdapterObject, \
|
||||
IN PDMAMEMORYMANAGER MemManager, \
|
||||
IN OPTIONAL PKSPIN_LOCK Lock); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) AddUSBRequest( \
|
||||
IN IUSBRequest * Request); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) CreateUSBRequest( \
|
||||
OUT IUSBRequest **OutRequest); \
|
||||
\
|
||||
STDMETHODIMP_(NTSTATUS) AbortDevicePipe( \
|
||||
IN UCHAR DeviceAddress, \
|
||||
IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor);
|
||||
|
||||
DECLARE_INTERFACE_(IUSBQueue, IUnknown)
|
||||
{
|
||||
DEFINE_ABSTRACT_UNKNOWN()
|
||||
DEFINE_ABSTRACT_USBQUEUE()
|
||||
};
|
||||
|
||||
typedef IUSBQueue *PUSBQUEUE;
|
||||
|
||||
//=========================================================================================
|
||||
//
|
||||
// class IHubController
|
||||
//
|
||||
// Description: This class implements a hub controller
|
||||
//
|
||||
|
||||
DECLARE_INTERFACE_(IHubController, IUnknown)
|
||||
{
|
||||
DEFINE_ABSTRACT_UNKNOWN()
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// Initialize
|
||||
//
|
||||
// Description: Initializes the hub controller
|
||||
|
||||
virtual NTSTATUS Initialize(IN PDRIVER_OBJECT DriverObject,
|
||||
IN PHCDCONTROLLER Controller,
|
||||
IN PUSBHARDWAREDEVICE Device,
|
||||
IN BOOLEAN IsRootHubDevice,
|
||||
IN ULONG DeviceAddress) = 0;
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetHubControllerDeviceObject
|
||||
//
|
||||
// Description: Returns the hub controller device object
|
||||
|
||||
virtual NTSTATUS GetHubControllerDeviceObject(PDEVICE_OBJECT * HubDeviceObject) = 0;
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetHubControllerSymbolicLink
|
||||
//
|
||||
// Description: Returns the symbolic link of the root hub
|
||||
|
||||
virtual NTSTATUS GetHubControllerSymbolicLink(ULONG BufferLength, PVOID Buffer, PULONG RequiredLength) = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
typedef IHubController *PHUBCONTROLLER;
|
||||
|
||||
//=========================================================================================
|
||||
//
|
||||
// class IDispatchIrp
|
||||
//
|
||||
// Description: This class is used to handle irp dispatch requests
|
||||
//
|
||||
|
||||
DECLARE_INTERFACE_(IDispatchIrp, IUnknown)
|
||||
{
|
||||
DEFINE_ABSTRACT_UNKNOWN()
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// HandlePnp
|
||||
//
|
||||
// Description: This function handles all pnp requests
|
||||
|
||||
virtual NTSTATUS HandlePnp(IN PDEVICE_OBJECT DeviceObject,
|
||||
IN OUT PIRP Irp) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// HandlePower
|
||||
//
|
||||
// Description: This function handles all power pnp requests
|
||||
//
|
||||
virtual NTSTATUS HandlePower(IN PDEVICE_OBJECT DeviceObject,
|
||||
IN OUT PIRP Irp) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// HandleDeviceControl
|
||||
//
|
||||
// Description: handles device io control requests
|
||||
|
||||
virtual NTSTATUS HandleDeviceControl(IN PDEVICE_OBJECT DeviceObject,
|
||||
IN OUT PIRP Irp) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// HandleSystemControl
|
||||
//
|
||||
// Description: handles WMI system control requests
|
||||
|
||||
virtual NTSTATUS HandleSystemControl(IN PDEVICE_OBJECT DeviceObject,
|
||||
IN OUT PIRP Irp) = 0;
|
||||
};
|
||||
|
||||
typedef IDispatchIrp *PDISPATCHIRP;
|
||||
|
||||
//=========================================================================================
|
||||
//
|
||||
// class IUSBDevice
|
||||
//
|
||||
// Description: This class is used to abstract details of a usb device
|
||||
//
|
||||
|
||||
DECLARE_INTERFACE_(IUSBDevice, IUnknown)
|
||||
{
|
||||
DEFINE_ABSTRACT_UNKNOWN()
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
//
|
||||
// Initialize
|
||||
//
|
||||
// Description: Initializes the usb device
|
||||
|
||||
virtual NTSTATUS Initialize(IN PHUBCONTROLLER HubController,
|
||||
IN PUSBHARDWAREDEVICE Device,
|
||||
IN PVOID Parent,
|
||||
IN ULONG Port,
|
||||
IN ULONG PortStatus) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// IsHub
|
||||
//
|
||||
// Description: returns true when device is a hub
|
||||
|
||||
virtual BOOLEAN IsHub() = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetParent
|
||||
//
|
||||
// Description: gets the parent device of the this device
|
||||
|
||||
virtual NTSTATUS GetParent(PVOID * Parent) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetDeviceAddress
|
||||
//
|
||||
// Description: gets the device address of the this device
|
||||
|
||||
virtual UCHAR GetDeviceAddress() = 0;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetPort
|
||||
//
|
||||
// Description: gets the port to which this device is connected
|
||||
|
||||
virtual ULONG GetPort() = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetSpeed
|
||||
//
|
||||
// Description: gets the speed of the device
|
||||
|
||||
virtual USB_DEVICE_SPEED GetSpeed() = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetType
|
||||
//
|
||||
// Description: gets the type of the device, either 1.1 or 2.0 device
|
||||
|
||||
virtual USB_DEVICE_TYPE GetType() = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetState
|
||||
//
|
||||
// Description: gets the device state
|
||||
|
||||
virtual ULONG GetState() = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// SetDeviceHandleData
|
||||
//
|
||||
// Description: sets device handle data
|
||||
|
||||
virtual void SetDeviceHandleData(PVOID Data) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// SetDeviceAddress
|
||||
//
|
||||
// Description: sets device handle data
|
||||
|
||||
virtual NTSTATUS SetDeviceAddress(UCHAR DeviceAddress) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetDeviceDescriptor
|
||||
//
|
||||
// Description: sets device handle data
|
||||
|
||||
virtual void GetDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetConfigurationValue
|
||||
//
|
||||
// Description: gets current selected configuration index
|
||||
|
||||
virtual UCHAR GetConfigurationValue() = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// SubmitIrp
|
||||
//
|
||||
// Description: submits an irp containing an urb
|
||||
|
||||
virtual NTSTATUS SubmitIrp(PIRP Irp) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetConfigurationDescriptors
|
||||
//
|
||||
// Description: returns one or more configuration descriptors
|
||||
|
||||
virtual VOID GetConfigurationDescriptors(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptorBuffer,
|
||||
IN ULONG BufferLength,
|
||||
OUT PULONG OutBufferLength) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// Description: returns length of configuration descriptors
|
||||
//
|
||||
virtual ULONG GetConfigurationDescriptorsLength() = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// SubmitSetupPacket
|
||||
//
|
||||
// Description: submits an setup packet. The usb device will then create an usb request from it and submit it to the queue
|
||||
|
||||
virtual NTSTATUS SubmitSetupPacket(IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket,
|
||||
IN OUT ULONG BufferLength,
|
||||
OUT PVOID Buffer) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// SelectConfiguration
|
||||
//
|
||||
// Description: selects a configuration
|
||||
|
||||
virtual NTSTATUS SelectConfiguration(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
|
||||
IN PUSBD_INTERFACE_INFORMATION Interface,
|
||||
OUT USBD_CONFIGURATION_HANDLE *ConfigurationHandle) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// SelectConfiguration
|
||||
//
|
||||
// Description: selects a interface of an configuration
|
||||
|
||||
virtual NTSTATUS SelectInterface(IN USBD_CONFIGURATION_HANDLE ConfigurationHandle,
|
||||
IN OUT PUSBD_INTERFACE_INFORMATION Interface) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// AbortPipe
|
||||
//
|
||||
// Description: aborts all pending requests
|
||||
|
||||
virtual NTSTATUS AbortPipe(IN PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor) = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
//
|
||||
// GetMaxPacketSize
|
||||
//
|
||||
// Description: aborts all pending requests
|
||||
|
||||
virtual UCHAR GetMaxPacketSize() = 0;
|
||||
};
|
||||
|
||||
typedef IUSBDevice *PUSBDEVICE;
|
||||
|
||||
#endif
|
|
@ -1,791 +0,0 @@
|
|||
/*
|
||||
* PROJECT: ReactOS Universal Serial Bus Bulk Driver Library
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: lib/drivers/libusb/hcd_controller.cpp
|
||||
* PURPOSE: USB Common Driver Library.
|
||||
* PROGRAMMERS:
|
||||
* Michael Martin (michael.martin@reactos.org)
|
||||
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
||||
*/
|
||||
|
||||
#include "libusb.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
class CHCDController : public IHCDController,
|
||||
public IDispatchIrp
|
||||
{
|
||||
public:
|
||||
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
|
||||
|
||||
STDMETHODIMP_(ULONG) AddRef()
|
||||
{
|
||||
InterlockedIncrement(&m_Ref);
|
||||
return m_Ref;
|
||||
}
|
||||
STDMETHODIMP_(ULONG) Release()
|
||||
{
|
||||
InterlockedDecrement(&m_Ref);
|
||||
|
||||
if (!m_Ref)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return m_Ref;
|
||||
}
|
||||
|
||||
// IHCDController interface functions
|
||||
NTSTATUS Initialize(IN PROOTHDCCONTROLLER RootHCDController, IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject);
|
||||
|
||||
// IDispatchIrp interface functions
|
||||
NTSTATUS HandlePnp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp);
|
||||
NTSTATUS HandlePower(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp);
|
||||
NTSTATUS HandleDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp);
|
||||
NTSTATUS HandleSystemControl(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp);
|
||||
|
||||
// local functions
|
||||
NTSTATUS CreateFDO(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT * OutDeviceObject);
|
||||
NTSTATUS SetSymbolicLink(BOOLEAN Enable);
|
||||
|
||||
// constructor / destructor
|
||||
CHCDController(IUnknown *OuterUnknown){}
|
||||
virtual ~CHCDController(){}
|
||||
|
||||
protected:
|
||||
LONG m_Ref;
|
||||
PROOTHDCCONTROLLER m_RootController;
|
||||
PDRIVER_OBJECT m_DriverObject;
|
||||
PDEVICE_OBJECT m_PhysicalDeviceObject;
|
||||
PDEVICE_OBJECT m_FunctionalDeviceObject;
|
||||
PDEVICE_OBJECT m_NextDeviceObject;
|
||||
PUSBHARDWAREDEVICE m_Hardware;
|
||||
PHUBCONTROLLER m_HubController;
|
||||
ULONG m_FDODeviceNumber;
|
||||
LPCSTR m_USBType;
|
||||
};
|
||||
|
||||
//=================================================================================================
|
||||
// COM
|
||||
//
|
||||
NTSTATUS
|
||||
STDMETHODCALLTYPE
|
||||
CHCDController::QueryInterface(
|
||||
IN REFIID refiid,
|
||||
OUT PVOID* Output)
|
||||
{
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
NTSTATUS
|
||||
CHCDController::Initialize(
|
||||
IN PROOTHDCCONTROLLER RootHCDController,
|
||||
IN PDRIVER_OBJECT DriverObject,
|
||||
IN PDEVICE_OBJECT PhysicalDeviceObject)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PCOMMON_DEVICE_EXTENSION DeviceExtension;
|
||||
|
||||
//
|
||||
// create usb hardware
|
||||
//
|
||||
Status = CreateUSBHardware(&m_Hardware);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// failed to create hardware object
|
||||
//
|
||||
DPRINT1("Failed to create hardware object\n");
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// initialize members
|
||||
//
|
||||
m_DriverObject = DriverObject;
|
||||
m_PhysicalDeviceObject = PhysicalDeviceObject;
|
||||
m_RootController = RootHCDController;
|
||||
|
||||
//
|
||||
// create FDO
|
||||
//
|
||||
Status = CreateFDO(m_DriverObject, &m_FunctionalDeviceObject);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// failed to create PDO
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// now attach to device stack
|
||||
//
|
||||
m_NextDeviceObject = IoAttachDeviceToDeviceStack(m_FunctionalDeviceObject, m_PhysicalDeviceObject);
|
||||
if (!m_NextDeviceObject)
|
||||
{
|
||||
//
|
||||
// failed to attach to device stack
|
||||
//
|
||||
IoDeleteDevice(m_FunctionalDeviceObject);
|
||||
m_FunctionalDeviceObject = 0;
|
||||
|
||||
return STATUS_NO_SUCH_DEVICE;
|
||||
}
|
||||
|
||||
//
|
||||
// initialize hardware object
|
||||
//
|
||||
Status = m_Hardware->Initialize(m_DriverObject, m_FunctionalDeviceObject, m_PhysicalDeviceObject, m_NextDeviceObject);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("[%s] Failed to initialize hardware object %x\n", m_Hardware->GetUSBType(), Status);
|
||||
|
||||
//
|
||||
// failed to initialize hardware object, detach from device stack
|
||||
//
|
||||
IoDetachDevice(m_NextDeviceObject);
|
||||
|
||||
//
|
||||
// now delete the device
|
||||
//
|
||||
IoDeleteDevice(m_FunctionalDeviceObject);
|
||||
|
||||
//
|
||||
// nullify pointers :)
|
||||
//
|
||||
m_FunctionalDeviceObject = 0;
|
||||
m_NextDeviceObject = 0;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// get usb controller type
|
||||
//
|
||||
m_USBType = m_Hardware->GetUSBType();
|
||||
|
||||
|
||||
//
|
||||
// set device flags
|
||||
//
|
||||
m_FunctionalDeviceObject->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE;
|
||||
|
||||
|
||||
//
|
||||
// get device extension
|
||||
//
|
||||
DeviceExtension = (PCOMMON_DEVICE_EXTENSION)m_FunctionalDeviceObject->DeviceExtension;
|
||||
PC_ASSERT(DeviceExtension);
|
||||
|
||||
//
|
||||
// initialize device extension
|
||||
//
|
||||
DeviceExtension->IsFDO = TRUE;
|
||||
DeviceExtension->IsHub = FALSE;
|
||||
DeviceExtension->Dispatcher = PDISPATCHIRP(this);
|
||||
|
||||
//
|
||||
// device is initialized
|
||||
//
|
||||
m_FunctionalDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
||||
|
||||
|
||||
//
|
||||
// is there a root controller
|
||||
//
|
||||
if (m_RootController)
|
||||
{
|
||||
//
|
||||
// add reference
|
||||
//
|
||||
m_RootController->AddRef();
|
||||
|
||||
//
|
||||
// register with controller
|
||||
//
|
||||
m_RootController->RegisterHCD(this);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// done
|
||||
//
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
NTSTATUS
|
||||
CHCDController::HandleDeviceControl(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
IN PIRP Irp)
|
||||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PCOMMON_DEVICE_EXTENSION DeviceExtension;
|
||||
NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
|
||||
PUSB_HCD_DRIVERKEY_NAME DriverKey;
|
||||
ULONG ResultLength;
|
||||
|
||||
//
|
||||
// get current stack location
|
||||
//
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
|
||||
//
|
||||
// get device extension
|
||||
//
|
||||
DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
|
||||
//
|
||||
// sanity check
|
||||
//
|
||||
PC_ASSERT(DeviceExtension->IsFDO);
|
||||
|
||||
DPRINT1("[%s] HandleDeviceControl>Type: IoCtl %x InputBufferLength %lu OutputBufferLength %lu\n", m_USBType,
|
||||
IoStack->Parameters.DeviceIoControl.IoControlCode,
|
||||
IoStack->Parameters.DeviceIoControl.InputBufferLength,
|
||||
IoStack->Parameters.DeviceIoControl.OutputBufferLength);
|
||||
|
||||
//
|
||||
// perform ioctl for FDO
|
||||
//
|
||||
if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_GET_HCD_DRIVERKEY_NAME)
|
||||
{
|
||||
//
|
||||
// check if sizee is at least >= USB_HCD_DRIVERKEY_NAME
|
||||
//
|
||||
if(IoStack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(USB_HCD_DRIVERKEY_NAME))
|
||||
{
|
||||
//
|
||||
// get device property size
|
||||
//
|
||||
Status = IoGetDeviceProperty(m_PhysicalDeviceObject, DevicePropertyDriverKeyName, 0, NULL, &ResultLength);
|
||||
|
||||
//
|
||||
// get input buffer
|
||||
//
|
||||
DriverKey = (PUSB_HCD_DRIVERKEY_NAME)Irp->AssociatedIrp.SystemBuffer;
|
||||
|
||||
//
|
||||
// check result
|
||||
//
|
||||
if (Status == STATUS_BUFFER_TOO_SMALL)
|
||||
{
|
||||
//
|
||||
// does the caller provide enough buffer space
|
||||
//
|
||||
if (IoStack->Parameters.DeviceIoControl.OutputBufferLength >= ResultLength)
|
||||
{
|
||||
//
|
||||
// it does
|
||||
//
|
||||
Status = IoGetDeviceProperty(m_PhysicalDeviceObject, DevicePropertyDriverKeyName, IoStack->Parameters.DeviceIoControl.OutputBufferLength - sizeof(ULONG), DriverKey->DriverKeyName, &ResultLength);
|
||||
}
|
||||
|
||||
//
|
||||
// store result
|
||||
//
|
||||
DriverKey->ActualLength = ResultLength + FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + sizeof(WCHAR);
|
||||
Irp->IoStatus.Information = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// buffer is certainly too small
|
||||
//
|
||||
Status = STATUS_BUFFER_OVERFLOW;
|
||||
Irp->IoStatus.Information = sizeof(USB_HCD_DRIVERKEY_NAME);
|
||||
}
|
||||
}
|
||||
else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_USB_GET_ROOT_HUB_NAME)
|
||||
{
|
||||
//
|
||||
// check if sizee is at least >= USB_HCD_DRIVERKEY_NAME
|
||||
//
|
||||
if(IoStack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(USB_HCD_DRIVERKEY_NAME))
|
||||
{
|
||||
//
|
||||
// sanity check
|
||||
//
|
||||
PC_ASSERT(m_HubController);
|
||||
|
||||
//
|
||||
// get input buffer
|
||||
//
|
||||
DriverKey = (PUSB_HCD_DRIVERKEY_NAME)Irp->AssociatedIrp.SystemBuffer;
|
||||
|
||||
//
|
||||
// get symbolic link
|
||||
//
|
||||
Status = m_HubController->GetHubControllerSymbolicLink(IoStack->Parameters.DeviceIoControl.OutputBufferLength - sizeof(ULONG), DriverKey->DriverKeyName, &ResultLength);
|
||||
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// null terminate it
|
||||
//
|
||||
PC_ASSERT(IoStack->Parameters.DeviceIoControl.OutputBufferLength - sizeof(ULONG) - sizeof(WCHAR) >= ResultLength);
|
||||
|
||||
DriverKey->DriverKeyName[ResultLength / sizeof(WCHAR)] = L'\0';
|
||||
}
|
||||
|
||||
//
|
||||
// store result
|
||||
//
|
||||
DriverKey->ActualLength = ResultLength + FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + sizeof(WCHAR);
|
||||
Irp->IoStatus.Information = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// buffer is certainly too small
|
||||
//
|
||||
Status = STATUS_BUFFER_OVERFLOW;
|
||||
Irp->IoStatus.Information = sizeof(USB_HCD_DRIVERKEY_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// complete the request
|
||||
//
|
||||
Irp->IoStatus.Status = Status;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
//
|
||||
// done
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
CHCDController::HandlePnp(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
IN PIRP Irp)
|
||||
{
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
PCOMMON_DEVICE_EXTENSION DeviceExtension;
|
||||
PCM_RESOURCE_LIST RawResourceList;
|
||||
PCM_RESOURCE_LIST TranslatedResourceList;
|
||||
PDEVICE_RELATIONS DeviceRelations;
|
||||
NTSTATUS Status;
|
||||
|
||||
//
|
||||
// get device extension
|
||||
//
|
||||
DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
|
||||
//
|
||||
// sanity check
|
||||
//
|
||||
PC_ASSERT(DeviceExtension->IsFDO);
|
||||
|
||||
//
|
||||
// get current stack location
|
||||
//
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
|
||||
switch(IoStack->MinorFunction)
|
||||
{
|
||||
case IRP_MN_START_DEVICE:
|
||||
{
|
||||
DPRINT("[%s] HandlePnp IRP_MN_START FDO\n", m_USBType);
|
||||
|
||||
//
|
||||
// first start lower device object
|
||||
//
|
||||
Status = SyncForwardIrp(m_NextDeviceObject, Irp);
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// operation succeeded, lets start the device
|
||||
//
|
||||
RawResourceList = IoStack->Parameters.StartDevice.AllocatedResources;
|
||||
TranslatedResourceList = IoStack->Parameters.StartDevice.AllocatedResourcesTranslated;
|
||||
|
||||
if (m_Hardware)
|
||||
{
|
||||
//
|
||||
// start the hardware
|
||||
//
|
||||
Status = m_Hardware->PnpStart(RawResourceList, TranslatedResourceList);
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// enable symbolic link
|
||||
//
|
||||
Status = SetSymbolicLink(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
DPRINT("[%s] HandlePnp IRP_MN_START FDO: Status %x\n", m_USBType ,Status);
|
||||
break;
|
||||
}
|
||||
case IRP_MN_QUERY_DEVICE_RELATIONS:
|
||||
{
|
||||
DPRINT("[%s] HandlePnp IRP_MN_QUERY_DEVICE_RELATIONS Type %lx\n", m_USBType, IoStack->Parameters.QueryDeviceRelations.Type);
|
||||
|
||||
if (m_HubController == NULL)
|
||||
{
|
||||
//
|
||||
// create hub controller
|
||||
//
|
||||
Status = CreateHubController(&m_HubController);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// failed to create hub controller
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// initialize hub controller
|
||||
//
|
||||
Status = m_HubController->Initialize(m_DriverObject, PHCDCONTROLLER(this), m_Hardware, TRUE, 0 /* FIXME*/);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// failed to initialize hub controller
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// add reference to prevent it from getting deleting while hub driver adds / removes references
|
||||
//
|
||||
m_HubController->AddRef();
|
||||
}
|
||||
|
||||
if (IoStack->Parameters.QueryDeviceRelations.Type == BusRelations)
|
||||
{
|
||||
//
|
||||
// allocate device relations
|
||||
//
|
||||
DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePool(PagedPool, sizeof(DEVICE_RELATIONS));
|
||||
|
||||
if (!DeviceRelations)
|
||||
{
|
||||
//
|
||||
// no memory
|
||||
//
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// init device relations
|
||||
//
|
||||
DeviceRelations->Count = 1;
|
||||
Status = m_HubController->GetHubControllerDeviceObject(&DeviceRelations->Objects [0]);
|
||||
|
||||
//
|
||||
// sanity check
|
||||
//
|
||||
PC_ASSERT(Status == STATUS_SUCCESS);
|
||||
|
||||
ObReferenceObject(DeviceRelations->Objects [0]);
|
||||
|
||||
//
|
||||
// store result
|
||||
//
|
||||
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// not supported
|
||||
//
|
||||
Status = STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IRP_MN_STOP_DEVICE:
|
||||
{
|
||||
DPRINT("[%s] HandlePnp IRP_MN_STOP_DEVICE\n", m_USBType);
|
||||
|
||||
if (m_Hardware)
|
||||
{
|
||||
//
|
||||
// stop the hardware
|
||||
//
|
||||
Status = m_Hardware->PnpStop();
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// fake success
|
||||
//
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// stop lower device
|
||||
//
|
||||
Status = SyncForwardIrp(m_NextDeviceObject, Irp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IRP_MN_QUERY_REMOVE_DEVICE:
|
||||
case IRP_MN_QUERY_STOP_DEVICE:
|
||||
{
|
||||
#if 0
|
||||
//
|
||||
// sure
|
||||
//
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
|
||||
//
|
||||
// forward irp to next device object
|
||||
//
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
return IoCallDriver(m_NextDeviceObject, Irp);
|
||||
#else
|
||||
DPRINT1("[%s] Denying controller removal due to reinitialization bugs\n", m_USBType);
|
||||
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
#endif
|
||||
}
|
||||
case IRP_MN_REMOVE_DEVICE:
|
||||
{
|
||||
DPRINT("[%s] HandlePnp IRP_MN_REMOVE_DEVICE FDO\n", m_USBType);
|
||||
|
||||
//
|
||||
// delete the symbolic link
|
||||
//
|
||||
SetSymbolicLink(FALSE);
|
||||
|
||||
//
|
||||
// forward irp to next device object
|
||||
//
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
IoCallDriver(m_NextDeviceObject, Irp);
|
||||
|
||||
//
|
||||
// detach device from device stack
|
||||
//
|
||||
IoDetachDevice(m_NextDeviceObject);
|
||||
|
||||
//
|
||||
// delete device
|
||||
//
|
||||
IoDeleteDevice(m_FunctionalDeviceObject);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
default:
|
||||
{
|
||||
//
|
||||
// forward irp to next device object
|
||||
//
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
return IoCallDriver(m_NextDeviceObject, Irp);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// store result and complete request
|
||||
//
|
||||
Irp->IoStatus.Status = Status;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
CHCDController::HandlePower(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
IN PIRP Irp)
|
||||
{
|
||||
PoStartNextPowerIrp(Irp);
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
return PoCallDriver(m_NextDeviceObject, Irp);
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
CHCDController::HandleSystemControl(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
IN PIRP Irp)
|
||||
{
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
return IoCallDriver(m_NextDeviceObject, Irp);
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
CHCDController::CreateFDO(
|
||||
PDRIVER_OBJECT DriverObject,
|
||||
PDEVICE_OBJECT * OutDeviceObject)
|
||||
{
|
||||
WCHAR CharDeviceName[64];
|
||||
NTSTATUS Status;
|
||||
ULONG UsbDeviceNumber = 0;
|
||||
UNICODE_STRING DeviceName;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
//
|
||||
// construct device name
|
||||
//
|
||||
swprintf(CharDeviceName, L"\\Device\\USBFDO-%d", UsbDeviceNumber);
|
||||
|
||||
//
|
||||
// initialize device name
|
||||
//
|
||||
RtlInitUnicodeString(&DeviceName, CharDeviceName);
|
||||
|
||||
//
|
||||
// create device
|
||||
//
|
||||
Status = IoCreateDevice(DriverObject,
|
||||
sizeof(COMMON_DEVICE_EXTENSION),
|
||||
&DeviceName,
|
||||
FILE_DEVICE_CONTROLLER,
|
||||
0,
|
||||
FALSE,
|
||||
OutDeviceObject);
|
||||
|
||||
//
|
||||
// check for success
|
||||
//
|
||||
if (NT_SUCCESS(Status))
|
||||
break;
|
||||
|
||||
//
|
||||
// is there a device object with that same name
|
||||
//
|
||||
if ((Status == STATUS_OBJECT_NAME_EXISTS) || (Status == STATUS_OBJECT_NAME_COLLISION))
|
||||
{
|
||||
//
|
||||
// Try the next name
|
||||
//
|
||||
UsbDeviceNumber++;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// bail out on other errors
|
||||
//
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("[%s] CreateFDO: Failed to create %wZ, Status %x\n", m_USBType, &DeviceName, Status);
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// store FDO number
|
||||
//
|
||||
m_FDODeviceNumber = UsbDeviceNumber;
|
||||
|
||||
DPRINT("[%s] CreateFDO: DeviceName %wZ\n", m_USBType, &DeviceName);
|
||||
|
||||
/* done */
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
CHCDController::SetSymbolicLink(
|
||||
BOOLEAN Enable)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
WCHAR LinkName[32];
|
||||
WCHAR FDOName[32];
|
||||
UNICODE_STRING Link, FDO;
|
||||
|
||||
if (Enable)
|
||||
{
|
||||
//
|
||||
// create legacy link
|
||||
//
|
||||
swprintf(LinkName, L"\\DosDevices\\HCD%d", m_FDODeviceNumber);
|
||||
swprintf(FDOName, L"\\Device\\USBFDO-%d", m_FDODeviceNumber);
|
||||
RtlInitUnicodeString(&Link, LinkName);
|
||||
RtlInitUnicodeString(&FDO, FDOName);
|
||||
|
||||
//
|
||||
// create symbolic link
|
||||
//
|
||||
Status = IoCreateSymbolicLink(&Link, &FDO);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// FIXME: handle me
|
||||
//
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// create legacy link
|
||||
//
|
||||
swprintf(LinkName, L"\\DosDevices\\HCD%d", m_FDODeviceNumber);
|
||||
RtlInitUnicodeString(&Link, LinkName);
|
||||
|
||||
//
|
||||
// now delete the symbolic link
|
||||
//
|
||||
Status = IoDeleteSymbolicLink(&Link);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
//
|
||||
// FIXME: handle me
|
||||
//
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// done
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CreateHCDController(
|
||||
PHCDCONTROLLER *OutHcdController)
|
||||
{
|
||||
PHCDCONTROLLER This;
|
||||
|
||||
//
|
||||
// allocate controller
|
||||
//
|
||||
This = new(NonPagedPool, TAG_USBLIB) CHCDController(0);
|
||||
if (!This)
|
||||
{
|
||||
//
|
||||
// failed to allocate
|
||||
//
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// add reference count
|
||||
//
|
||||
This->AddRef();
|
||||
|
||||
//
|
||||
// return result
|
||||
//
|
||||
*OutHcdController = (PHCDCONTROLLER)This;
|
||||
|
||||
//
|
||||
// done
|
||||
//
|
||||
return STATUS_SUCCESS;
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,170 +0,0 @@
|
|||
/*
|
||||
* PROJECT: ReactOS Universal Serial Bus Bulk Driver Library
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: lib/drivers/libusb/libusb.cpp
|
||||
* PURPOSE: USB Common Driver Library.
|
||||
* PROGRAMMERS:
|
||||
* Michael Martin (michael.martin@reactos.org)
|
||||
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
||||
*/
|
||||
|
||||
#include "libusb.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
//
|
||||
// driver verifier
|
||||
//
|
||||
DRIVER_ADD_DEVICE USBLIB_AddDevice;
|
||||
|
||||
PVOID
|
||||
__cdecl
|
||||
operator new(
|
||||
size_t iSize,
|
||||
POOL_TYPE poolType,
|
||||
ULONG tag)
|
||||
{
|
||||
PVOID result = ExAllocatePoolWithTag(poolType, iSize, tag);
|
||||
if (result) {
|
||||
RtlZeroMemory(result, iSize);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
__cdecl
|
||||
operator delete(
|
||||
PVOID pVoid)
|
||||
{
|
||||
if (pVoid) ExFreePool(pVoid);
|
||||
}
|
||||
|
||||
void
|
||||
__cdecl
|
||||
operator delete(
|
||||
PVOID pVoid, UINT_PTR)
|
||||
{
|
||||
if (pVoid) ExFreePool(pVoid);
|
||||
}
|
||||
|
||||
extern
|
||||
"C"
|
||||
{
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
USBLIB_AddDevice(
|
||||
PDRIVER_OBJECT DriverObject,
|
||||
PDEVICE_OBJECT PhysicalDeviceObject)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PHCDCONTROLLER HcdController;
|
||||
|
||||
DPRINT("USBLIB_AddDevice\n");
|
||||
|
||||
/* first create the controller object */
|
||||
Status = CreateHCDController(&HcdController);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* failed to create hcd */
|
||||
DPRINT1("AddDevice: Failed to create hcd with %x\n", Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* initialize the hcd */
|
||||
Status = HcdController->Initialize(NULL, // FIXME
|
||||
DriverObject,
|
||||
PhysicalDeviceObject);
|
||||
|
||||
/* check for success */
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* failed to initialize device */
|
||||
DPRINT1("AddDevice: failed to initialize\n");
|
||||
|
||||
/* release object */
|
||||
HcdController->Release();
|
||||
}
|
||||
|
||||
return Status;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extern
|
||||
"C"
|
||||
{
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
USBLIB_Dispatch(
|
||||
PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PCOMMON_DEVICE_EXTENSION DeviceExtension;
|
||||
PIO_STACK_LOCATION IoStack;
|
||||
NTSTATUS Status;
|
||||
|
||||
//
|
||||
// get common device extension
|
||||
//
|
||||
DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
|
||||
//
|
||||
// get current stack location
|
||||
//
|
||||
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
||||
|
||||
//
|
||||
// sanity checks
|
||||
//
|
||||
PC_ASSERT(DeviceExtension->Dispatcher);
|
||||
|
||||
switch(IoStack->MajorFunction)
|
||||
{
|
||||
case IRP_MJ_PNP:
|
||||
{
|
||||
//
|
||||
// dispatch pnp
|
||||
//
|
||||
return DeviceExtension->Dispatcher->HandlePnp(DeviceObject, Irp);
|
||||
}
|
||||
|
||||
case IRP_MJ_POWER:
|
||||
{
|
||||
//
|
||||
// dispatch power
|
||||
//
|
||||
return DeviceExtension->Dispatcher->HandlePower(DeviceObject, Irp);
|
||||
}
|
||||
case IRP_MJ_INTERNAL_DEVICE_CONTROL:
|
||||
case IRP_MJ_DEVICE_CONTROL:
|
||||
{
|
||||
//
|
||||
// dispatch io control
|
||||
//
|
||||
return DeviceExtension->Dispatcher->HandleDeviceControl(DeviceObject, Irp);
|
||||
}
|
||||
case IRP_MJ_SYSTEM_CONTROL:
|
||||
{
|
||||
//
|
||||
// dispatch system control
|
||||
//
|
||||
return DeviceExtension->Dispatcher->HandleSystemControl(DeviceObject, Irp);
|
||||
}
|
||||
default:
|
||||
{
|
||||
DPRINT1("USBLIB_Dispatch> Major %lu Minor %lu unhandeled\n", IoStack->MajorFunction, IoStack->MinorFunction);
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// complete request
|
||||
//
|
||||
Irp->IoStatus.Information = 0;
|
||||
Irp->IoStatus.Status = Status;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return Status;
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
#ifndef LIBUSB_H__
|
||||
#define LIBUSB_H__
|
||||
|
||||
#include <ntddk.h>
|
||||
#include <hubbusif.h>
|
||||
#include <usbbusif.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <usbdlib.h>
|
||||
}
|
||||
|
||||
//
|
||||
// FIXME:
|
||||
// #include <usbprotocoldefs.h>
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <wdmguid.h>
|
||||
|
||||
//
|
||||
// FIXME:
|
||||
// the following includes are required to get kcom to compile
|
||||
//
|
||||
#include <portcls.h>
|
||||
#include <kcom.h>
|
||||
|
||||
PVOID
|
||||
__cdecl
|
||||
operator new(
|
||||
size_t iSize,
|
||||
POOL_TYPE poolType,
|
||||
ULONG tag);
|
||||
|
||||
|
||||
#include "common_interfaces.h"
|
||||
|
||||
//
|
||||
// flags for handling USB_REQUEST_SET_FEATURE / USB_REQUEST_GET_FEATURE
|
||||
//
|
||||
#define PORT_ENABLE 1
|
||||
#define PORT_SUSPEND 2
|
||||
#define PORT_OVER_CURRENT 3
|
||||
#define PORT_RESET 4
|
||||
#define PORT_POWER 8
|
||||
#define C_PORT_CONNECTION 16
|
||||
#define C_PORT_ENABLE 17
|
||||
#define C_PORT_SUSPEND 18
|
||||
#define C_PORT_OVER_CURRENT 19
|
||||
#define C_PORT_RESET 20
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BOOLEAN IsFDO; // is device a FDO or PDO
|
||||
BOOLEAN IsHub; // is device a hub / child - not yet used
|
||||
PDISPATCHIRP Dispatcher; // dispatches the code
|
||||
}COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
|
||||
|
||||
|
||||
typedef struct _WORK_ITEM_DATA
|
||||
{
|
||||
WORK_QUEUE_ITEM WorkItem; // work item
|
||||
PVOID CallbackContext; // callback context
|
||||
PRH_INIT_CALLBACK CallbackRoutine; // callback routine
|
||||
} INIT_ROOT_HUB_CONTEXT, *PINIT_ROOT_HUB_CONTEXT;
|
||||
|
||||
//
|
||||
// tag for allocations
|
||||
//
|
||||
#define TAG_USBLIB 'LBSU'
|
||||
|
||||
//
|
||||
// assert for c++ - taken from portcls
|
||||
//
|
||||
#define PC_ASSERT(exp) \
|
||||
(VOID)((!(exp)) ? \
|
||||
RtlAssert((PVOID) #exp, (PVOID)__FILE__, __LINE__, NULL ), FALSE : TRUE)
|
||||
|
||||
// hcd_controller.cpp
|
||||
extern "C"
|
||||
{
|
||||
NTSTATUS NTAPI CreateHCDController(PHCDCONTROLLER *HcdController);
|
||||
|
||||
// hardware.cpp
|
||||
NTSTATUS NTAPI CreateUSBHardware(PUSBHARDWAREDEVICE *OutHardware);
|
||||
|
||||
// misc.cpp
|
||||
NTSTATUS NTAPI SyncForwardIrp(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
NTSTATUS NTAPI GetBusInterface(PDEVICE_OBJECT DeviceObject, PBUS_INTERFACE_STANDARD busInterface);
|
||||
|
||||
// root_hub_controller.cpp
|
||||
NTSTATUS NTAPI CreateHubController(PHUBCONTROLLER * OutHubController);
|
||||
|
||||
// memory_manager.cpp
|
||||
NTSTATUS NTAPI CreateDMAMemoryManager(PDMAMEMORYMANAGER *OutMemoryManager);
|
||||
|
||||
// usb_device.cpp
|
||||
NTSTATUS NTAPI CreateUSBDevice(PUSBDEVICE *OutDevice);
|
||||
|
||||
// libusb.cpp
|
||||
NTSTATUS NTAPI USBLIB_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject);
|
||||
NTSTATUS NTAPI USBLIB_Dispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
|
||||
}
|
||||
|
||||
#endif /* LIBUSB_H__ */
|
|
@ -1,372 +0,0 @@
|
|||
/*
|
||||
* PROJECT: ReactOS Universal Serial Bus Bulk Driver Library
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: lib/drivers/libusb/memory_manager.cpp
|
||||
* PURPOSE: USB Common Driver Library.
|
||||
* PROGRAMMERS:
|
||||
* Michael Martin (michael.martin@reactos.org)
|
||||
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
||||
*/
|
||||
|
||||
#include "libusb.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
class CDMAMemoryManager : public IDMAMemoryManager
|
||||
{
|
||||
public:
|
||||
STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
|
||||
|
||||
STDMETHODIMP_(ULONG) AddRef()
|
||||
{
|
||||
InterlockedIncrement(&m_Ref);
|
||||
return m_Ref;
|
||||
}
|
||||
STDMETHODIMP_(ULONG) Release()
|
||||
{
|
||||
InterlockedDecrement(&m_Ref);
|
||||
|
||||
if (!m_Ref)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return m_Ref;
|
||||
}
|
||||
|
||||
// IDMAMemoryManager interface functions
|
||||
virtual NTSTATUS Initialize(IN PUSBHARDWAREDEVICE Device, IN PKSPIN_LOCK Lock, IN ULONG DmaBufferSize, IN PVOID VirtualBase, IN PHYSICAL_ADDRESS PhysicalAddress, IN ULONG DefaultBlockSize);
|
||||
virtual NTSTATUS Allocate(IN ULONG Size, OUT PVOID *OutVirtualBase, OUT PPHYSICAL_ADDRESS OutPhysicalAddress);
|
||||
virtual NTSTATUS Release(IN PVOID VirtualBase, IN ULONG Size);
|
||||
|
||||
// constructor / destructor
|
||||
CDMAMemoryManager(IUnknown *OuterUnknown){}
|
||||
virtual ~CDMAMemoryManager(){}
|
||||
|
||||
protected:
|
||||
LONG m_Ref;
|
||||
PUSBHARDWAREDEVICE m_Device;
|
||||
PKSPIN_LOCK m_Lock;
|
||||
LONG m_DmaBufferSize;
|
||||
PVOID m_VirtualBase;
|
||||
PHYSICAL_ADDRESS m_PhysicalAddress;
|
||||
ULONG m_BlockSize;
|
||||
|
||||
PULONG m_BitmapBuffer;
|
||||
RTL_BITMAP m_Bitmap;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NTSTATUS
|
||||
STDMETHODCALLTYPE
|
||||
CDMAMemoryManager::QueryInterface(
|
||||
IN REFIID refiid,
|
||||
OUT PVOID* Output)
|
||||
{
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
CDMAMemoryManager::Initialize(
|
||||
IN PUSBHARDWAREDEVICE Device,
|
||||
IN PKSPIN_LOCK Lock,
|
||||
IN ULONG DmaBufferSize,
|
||||
IN PVOID VirtualBase,
|
||||
IN PHYSICAL_ADDRESS PhysicalAddress,
|
||||
IN ULONG DefaultBlockSize)
|
||||
{
|
||||
ULONG BitmapLength;
|
||||
|
||||
//
|
||||
// sanity checks
|
||||
//
|
||||
PC_ASSERT(DmaBufferSize >= PAGE_SIZE);
|
||||
PC_ASSERT(DmaBufferSize % PAGE_SIZE == 0);
|
||||
PC_ASSERT(DefaultBlockSize == 32 || DefaultBlockSize == 64 || DefaultBlockSize == 128);
|
||||
|
||||
//
|
||||
// calculate bitmap length
|
||||
//
|
||||
BitmapLength = (DmaBufferSize / DefaultBlockSize) / 8;
|
||||
|
||||
//
|
||||
// allocate bitmap buffer
|
||||
//
|
||||
m_BitmapBuffer = (PULONG)ExAllocatePoolWithTag(NonPagedPool, BitmapLength, TAG_USBLIB);
|
||||
if (!m_BitmapBuffer)
|
||||
{
|
||||
//
|
||||
// no memory
|
||||
//
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// initialize bitmap
|
||||
//
|
||||
RtlInitializeBitMap(&m_Bitmap, m_BitmapBuffer, BitmapLength * 8);
|
||||
|
||||
//
|
||||
// clear all bits
|
||||
//
|
||||
RtlClearAllBits(&m_Bitmap);
|
||||
|
||||
//
|
||||
// initialize rest of memory allocator
|
||||
//
|
||||
m_PhysicalAddress = PhysicalAddress;
|
||||
m_VirtualBase = VirtualBase;
|
||||
m_DmaBufferSize = DmaBufferSize;
|
||||
m_Lock = Lock;
|
||||
m_BlockSize = DefaultBlockSize;
|
||||
|
||||
/* done */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
CDMAMemoryManager::Allocate(
|
||||
IN ULONG Size,
|
||||
OUT PVOID *OutVirtualAddress,
|
||||
OUT PPHYSICAL_ADDRESS OutPhysicalAddress)
|
||||
{
|
||||
ULONG Length, BlockCount, FreeIndex, StartPage, EndPage;
|
||||
KIRQL OldLevel;
|
||||
ULONG BlocksPerPage;
|
||||
|
||||
//
|
||||
// sanity checks
|
||||
//
|
||||
ASSERT(Size <= PAGE_SIZE);
|
||||
//ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
|
||||
|
||||
//
|
||||
// align request
|
||||
//
|
||||
Length = (Size + m_BlockSize -1) & ~(m_BlockSize -1);
|
||||
|
||||
//
|
||||
// sanity check
|
||||
//
|
||||
ASSERT(Length);
|
||||
|
||||
//
|
||||
// convert to block count
|
||||
//
|
||||
BlockCount = Length / m_BlockSize;
|
||||
|
||||
//
|
||||
// acquire lock
|
||||
//
|
||||
KeAcquireSpinLock(m_Lock, &OldLevel);
|
||||
|
||||
//
|
||||
// helper variable
|
||||
//
|
||||
BlocksPerPage = PAGE_SIZE / m_BlockSize;
|
||||
|
||||
//
|
||||
// start search
|
||||
//
|
||||
FreeIndex = 0;
|
||||
do
|
||||
{
|
||||
//
|
||||
// search for an free index
|
||||
//
|
||||
FreeIndex = RtlFindClearBits(&m_Bitmap, BlockCount, FreeIndex);
|
||||
|
||||
//
|
||||
// check if there was a block found
|
||||
//
|
||||
if (FreeIndex == MAXULONG)
|
||||
{
|
||||
//
|
||||
// no free block found
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// check that the allocation does not spawn over page boundaries
|
||||
//
|
||||
StartPage = (FreeIndex * m_BlockSize);
|
||||
StartPage = (StartPage != 0 ? StartPage / PAGE_SIZE : 0);
|
||||
EndPage = ((FreeIndex + BlockCount) * m_BlockSize) / PAGE_SIZE;
|
||||
|
||||
//
|
||||
// does the request start and end on the same page
|
||||
//
|
||||
if (StartPage == EndPage)
|
||||
{
|
||||
//
|
||||
// reserve block
|
||||
//
|
||||
RtlSetBits(&m_Bitmap, FreeIndex, BlockCount);
|
||||
|
||||
//
|
||||
// reserve block
|
||||
//
|
||||
break;
|
||||
}
|
||||
else if ((BlockCount == BlocksPerPage) && (FreeIndex % BlocksPerPage == 0))
|
||||
{
|
||||
//
|
||||
// the request equals PAGE_SIZE and is aligned at page boundary
|
||||
// reserve block
|
||||
//
|
||||
RtlSetBits(&m_Bitmap, FreeIndex, BlockCount);
|
||||
|
||||
//
|
||||
// reserve block
|
||||
//
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// request spawned over page boundary
|
||||
// restart search on next page
|
||||
//
|
||||
FreeIndex = (EndPage * PAGE_SIZE) / m_BlockSize;
|
||||
}
|
||||
}
|
||||
while(TRUE);
|
||||
|
||||
//
|
||||
// release lock
|
||||
//
|
||||
KeReleaseSpinLock(m_Lock, OldLevel);
|
||||
|
||||
//
|
||||
// did allocation succeed
|
||||
//
|
||||
if (FreeIndex == MAXULONG)
|
||||
{
|
||||
//
|
||||
// failed to allocate block, requestor must retry
|
||||
//
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
//
|
||||
// return result
|
||||
//
|
||||
*OutVirtualAddress = (PVOID)((ULONG_PTR)m_VirtualBase + FreeIndex * m_BlockSize);
|
||||
OutPhysicalAddress->QuadPart = m_PhysicalAddress.QuadPart + FreeIndex * m_BlockSize;
|
||||
|
||||
//
|
||||
// clear block
|
||||
//
|
||||
RtlZeroMemory(*OutVirtualAddress, Length);
|
||||
|
||||
//
|
||||
// done
|
||||
//
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
CDMAMemoryManager::Release(
|
||||
IN PVOID VirtualAddress,
|
||||
IN ULONG Size)
|
||||
{
|
||||
KIRQL OldLevel;
|
||||
ULONG BlockOffset = 0, BlockLength, BlockCount;
|
||||
|
||||
//
|
||||
// sanity checks
|
||||
//
|
||||
PC_ASSERT(VirtualAddress);
|
||||
PC_ASSERT((ULONG_PTR)VirtualAddress >= (ULONG_PTR)m_VirtualBase);
|
||||
PC_ASSERT((ULONG_PTR)m_VirtualBase + m_DmaBufferSize > (ULONG_PTR)m_VirtualBase);
|
||||
|
||||
//
|
||||
// calculate block length
|
||||
//
|
||||
BlockLength = ((ULONG_PTR)VirtualAddress - (ULONG_PTR)m_VirtualBase);
|
||||
|
||||
//
|
||||
// check if its the first block
|
||||
//
|
||||
if (BlockLength)
|
||||
{
|
||||
//
|
||||
// divide by base block size
|
||||
//
|
||||
BlockOffset = BlockLength / m_BlockSize;
|
||||
}
|
||||
|
||||
//
|
||||
// align length to block size
|
||||
//
|
||||
Size = (Size + m_BlockSize - 1) & ~(m_BlockSize - 1);
|
||||
|
||||
//
|
||||
// convert to blocks
|
||||
//
|
||||
BlockCount = Size / m_BlockSize;
|
||||
ASSERT(BlockCount);
|
||||
|
||||
//
|
||||
// acquire lock
|
||||
//
|
||||
KeAcquireSpinLock(m_Lock, &OldLevel);
|
||||
|
||||
//
|
||||
// sanity check
|
||||
//
|
||||
ASSERT(RtlAreBitsSet(&m_Bitmap, BlockOffset, BlockCount));
|
||||
|
||||
//
|
||||
// release buffer
|
||||
//
|
||||
RtlClearBits(&m_Bitmap, BlockOffset, BlockCount);
|
||||
|
||||
//
|
||||
// release lock
|
||||
//
|
||||
KeReleaseSpinLock(m_Lock, OldLevel);
|
||||
|
||||
//
|
||||
// done
|
||||
//
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CreateDMAMemoryManager(
|
||||
PDMAMEMORYMANAGER *OutMemoryManager)
|
||||
{
|
||||
CDMAMemoryManager* This;
|
||||
|
||||
//
|
||||
// allocate controller
|
||||
//
|
||||
This = new(NonPagedPool, TAG_USBLIB) CDMAMemoryManager(0);
|
||||
if (!This)
|
||||
{
|
||||
//
|
||||
// failed to allocate
|
||||
//
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
//
|
||||
// add reference count
|
||||
//
|
||||
This->AddRef();
|
||||
|
||||
//
|
||||
// return result
|
||||
//
|
||||
*OutMemoryManager = (PDMAMEMORYMANAGER)This;
|
||||
|
||||
//
|
||||
// done
|
||||
//
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
/*
|
||||
* PROJECT: ReactOS Universal Serial Bus Bulk Driver Library
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: lib/drivers/libusb/misc.cpp
|
||||
* PURPOSE: USB Common Driver Library.
|
||||
* PROGRAMMERS:
|
||||
* Michael Martin (michael.martin@reactos.org)
|
||||
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
||||
*/
|
||||
|
||||
#include "libusb.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
//
|
||||
// driver verifier
|
||||
//
|
||||
IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine;
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
SyncForwardIrpCompletionRoutine(
|
||||
PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp,
|
||||
PVOID Context)
|
||||
{
|
||||
if (Irp->PendingReturned)
|
||||
{
|
||||
KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
|
||||
}
|
||||
return STATUS_MORE_PROCESSING_REQUIRED;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
SyncForwardIrp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||
{
|
||||
KEVENT Event;
|
||||
NTSTATUS Status;
|
||||
|
||||
//
|
||||
// initialize event
|
||||
//
|
||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||
|
||||
//
|
||||
// copy irp stack location
|
||||
//
|
||||
IoCopyCurrentIrpStackLocationToNext(Irp);
|
||||
|
||||
//
|
||||
// set completion routine
|
||||
//
|
||||
IoSetCompletionRoutine(Irp, SyncForwardIrpCompletionRoutine, &Event, TRUE, TRUE, TRUE);
|
||||
|
||||
|
||||
//
|
||||
// call driver
|
||||
//
|
||||
Status = IoCallDriver(DeviceObject, Irp);
|
||||
|
||||
|
||||
//
|
||||
// check if pending
|
||||
//
|
||||
if (Status == STATUS_PENDING)
|
||||
{
|
||||
//
|
||||
// wait for the request to finish
|
||||
//
|
||||
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
||||
|
||||
//
|
||||
// copy status code
|
||||
//
|
||||
Status = Irp->IoStatus.Status;
|
||||
}
|
||||
|
||||
//
|
||||
// done
|
||||
//
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
GetBusInterface(
|
||||
PDEVICE_OBJECT DeviceObject,
|
||||
PBUS_INTERFACE_STANDARD busInterface)
|
||||
{
|
||||
KEVENT Event;
|
||||
NTSTATUS Status;
|
||||
PIRP Irp;
|
||||
IO_STATUS_BLOCK IoStatus;
|
||||
PIO_STACK_LOCATION Stack;
|
||||
|
||||
if ((!DeviceObject) || (!busInterface))
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
|
||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||
|
||||
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP,
|
||||
DeviceObject,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
&Event,
|
||||
&IoStatus);
|
||||
|
||||
if (Irp == NULL)
|
||||
{
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
Stack=IoGetNextIrpStackLocation(Irp);
|
||||
Stack->MajorFunction = IRP_MJ_PNP;
|
||||
Stack->MinorFunction = IRP_MN_QUERY_INTERFACE;
|
||||
Stack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD);
|
||||
Stack->Parameters.QueryInterface.InterfaceType = (LPGUID)&GUID_BUS_INTERFACE_STANDARD;
|
||||
Stack->Parameters.QueryInterface.Version = 1;
|
||||
Stack->Parameters.QueryInterface.Interface = (PINTERFACE)busInterface;
|
||||
Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
|
||||
Irp->IoStatus.Status=STATUS_NOT_SUPPORTED ;
|
||||
|
||||
Status=IoCallDriver(DeviceObject, Irp);
|
||||
|
||||
if (Status == STATUS_PENDING)
|
||||
{
|
||||
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
||||
|
||||
Status=IoStatus.Status;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* PROJECT: ReactOS Universal Serial Bus Bulk Driver Library
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: lib/drivers/libusb/purecall.cpp
|
||||
* PURPOSE: USB Common Driver Library.
|
||||
* PROGRAMMERS:
|
||||
* Michael Martin (michael.martin@reactos.org)
|
||||
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
||||
*/
|
||||
|
||||
#include "libusb.h"
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
extern "C" {
|
||||
void
|
||||
__cxa_pure_virtual()
|
||||
{
|
||||
// put error handling here
|
||||
|
||||
DbgBreakPoint();
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue