[1/2] usbd.sys: add beginnings of USB driver infrastructure

Damjan Jovanovic damjan.jov at gmail.com
Mon Nov 15 14:02:12 CST 2010


Changelog:
* usbd.sys: add beginnings of USB driver infrastructure

Wine's current kernel driver architecture is process per service. The
only SYS file that most drivers that use USB load is usbd.sys. Tests
on Windows show DriverEntry() only called on the driver loaded by the
service, not on any other SYS files loaded through that driver's DLL
import table.

However the USB system needs:
* to be given its own DRIVER_OBJECT, so it can create physical device
objects for USB devices
* to know which driver it was loaded for
* to scan the USB devices and detect added/removed devices
* to notify the driver it was loaded with of devices belonging to it

To facilitate that:
* a special entrypoint on usbd.sys is made, which receives a
DRIVER_OBJECT for usbd.sys and the DRIVER_OBJECT of the driver it is
being loaded for
* changes in winedevice (next patch) generate the needed objects and
call that entrypoint
* the entrypoint creates a thread, which will in future scan the USB
bus and create device objects as necessary

Damjan Jovanovic
-------------- next part --------------
diff --git a/dlls/usbd.sys/Makefile.in b/dlls/usbd.sys/Makefile.in
index 8eb8164..7b7e5ab 100644
--- a/dlls/usbd.sys/Makefile.in
+++ b/dlls/usbd.sys/Makefile.in
@@ -4,6 +4,7 @@ IMPORTS   = ntoskrnl.exe
 EXTRADLLFLAGS = -Wb,--subsystem,native
 
 C_SRCS = \
-	usbd.c
+	usbd.c \
+	usbhub.c
 
 @MAKE_DLL_RULES@
diff --git a/dlls/usbd.sys/usbd.sys.spec b/dlls/usbd.sys/usbd.sys.spec
index 1cb507e..c876d85 100644
--- a/dlls/usbd.sys/usbd.sys.spec
+++ b/dlls/usbd.sys/usbd.sys.spec
@@ -31,3 +31,4 @@
 @ stub USBD_RestoreDevice
 @ stub USBD_SetSuspendPowerState
 @ stub USBD_WaitDeviceMutex
+@ stdcall __wine_usbd_init(ptr ptr)
diff --git a/dlls/usbd.sys/usbhub.c b/dlls/usbd.sys/usbhub.c
new file mode 100644
index 0000000..00d0cee
--- /dev/null
+++ b/dlls/usbd.sys/usbhub.c
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 Damjan Jovanovic
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+
+#define NONAMELESSUNION
+#define NONAMELESSSTRUCT
+
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
+#include "windef.h"
+#include "winbase.h"
+#include "winternl.h"
+#include "ddk/wdm.h"
+#include "ddk/usb.h"
+#include "ddk/usbdlib.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(usbd);
+
+static DRIVER_OBJECT *owning_driver;
+
+static WINAPI DWORD usb_thread(LPVOID arg)
+{
+    /* TODO: detect USB devices, match those belong to the driver, AddDevice() them, ... */
+    return 0;
+}
+
+WINAPI VOID __wine_usbd_init( DRIVER_OBJECT *driver, DRIVER_OBJECT *main_driver )
+{
+    TRACE( "(%p, %p)\n", driver, main_driver );
+
+    owning_driver = main_driver;
+    CreateThread(NULL, 0, usb_thread, NULL, 0, NULL);
+}


More information about the wine-patches mailing list