winebus.sys: Use the winebus driver to create all devices.

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2019-05-29 23:02:28 -05:00 committed by Alexandre Julliard
parent a2d26ae822
commit 50b9456e87
5 changed files with 27 additions and 47 deletions

View File

@ -41,13 +41,11 @@ typedef struct
void *get_platform_private(DEVICE_OBJECT *device) DECLSPEC_HIDDEN;
/* HID Plug and Play Bus */
NTSTATUS WINAPI common_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp) DECLSPEC_HIDDEN;
DEVICE_OBJECT *bus_create_hid_device(DRIVER_OBJECT *driver, const WCHAR *busidW, WORD vid, WORD pid,
DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid,
WORD input, DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad,
const GUID *class, const platform_vtbl *vtbl, DWORD platform_data_size) DECLSPEC_HIDDEN;
DEVICE_OBJECT *bus_find_hid_device(const platform_vtbl *vtbl, void *platform_dev) DECLSPEC_HIDDEN;
void bus_remove_hid_device(DEVICE_OBJECT *device) DECLSPEC_HIDDEN;
NTSTATUS WINAPI hid_internal_dispatch(DEVICE_OBJECT *device, IRP *irp) DECLSPEC_HIDDEN;
void process_hid_report(DEVICE_OBJECT *device, BYTE *report, DWORD length) DECLSPEC_HIDDEN;
DEVICE_OBJECT* bus_enumerate_hid_devices(const platform_vtbl *vtbl, enum_func function, void* context) DECLSPEC_HIDDEN;

View File

@ -96,7 +96,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
#ifdef HAVE_IOHIDMANAGERCREATE
static DRIVER_OBJECT *iohid_driver_obj = NULL;
static IOHIDManagerRef hid_manager;
static CFRunLoopRef run_loop;
static HANDLE run_loop_handle;
@ -348,7 +347,7 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void *
if (is_gamepad)
input = 0;
device = bus_create_hid_device(iohid_driver_obj, busidW, vid, pid, input,
device = bus_create_hid_device(busidW, vid, pid, input,
version, uid, str?serial_string:NULL, is_gamepad, &GUID_DEVCLASS_IOHID,
&iohid_vtbl, sizeof(struct platform_private));
if (!device)
@ -404,14 +403,10 @@ NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registr
{
TRACE("(%p, %s)\n", driver, debugstr_w(registry_path->Buffer));
iohid_driver_obj = driver;
driver->MajorFunction[IRP_MJ_PNP] = common_pnp_dispatch;
driver->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = hid_internal_dispatch;
hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, 0L);
if (!(run_loop_handle = CreateThread(NULL, 0, runloop_thread, NULL, 0, NULL)))
{
ERR("Failed to initialize IOHID Manager thread\n");
iohid_driver_obj = NULL;
CFRelease(hid_manager);
return STATUS_UNSUCCESSFUL;
}
@ -422,16 +417,13 @@ NTSTATUS WINAPI iohid_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registr
void iohid_driver_unload( void )
{
TRACE("Unloading Driver\n");
if (iohid_driver_obj != NULL)
{
IOHIDManagerUnscheduleFromRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode);
CFRunLoopStop(run_loop);
WaitForSingleObject(run_loop_handle, INFINITE);
CloseHandle(run_loop_handle);
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL);
CFRelease(hid_manager);
}
IOHIDManagerUnscheduleFromRunLoop(hid_manager, run_loop, kCFRunLoopDefaultMode);
CFRunLoopStop(run_loop);
WaitForSingleObject(run_loop_handle, INFINITE);
CloseHandle(run_loop_handle);
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, NULL, NULL);
IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, NULL, NULL);
CFRelease(hid_manager);
TRACE("Driver Unloaded\n");
}

View File

@ -62,8 +62,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
WINE_DECLARE_DEBUG_CHANNEL(hid_report);
static DRIVER_OBJECT *sdl_driver_obj = NULL;
static const WCHAR sdl_busidW[] = {'S','D','L','J','O','Y',0};
static DWORD map_controllers = 0;
@ -951,7 +949,7 @@ static void try_add_device(SDL_JoystickID index)
if (is_xbox_gamepad)
input = 0;
device = bus_create_hid_device(sdl_driver_obj, sdl_busidW, vid, pid,
device = bus_create_hid_device(sdl_busidW, vid, pid,
input, version, id, serial, is_xbox_gamepad, &GUID_DEVCLASS_SDL,
&sdl_vtbl, sizeof(struct platform_private));
@ -1095,7 +1093,6 @@ NTSTATUS WINAPI sdl_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_
sdl_handle = wine_dlopen(SONAME_LIBSDL2, RTLD_NOW, NULL, 0);
if (!sdl_handle) {
WARN("could not load %s\n", SONAME_LIBSDL2);
sdl_driver_obj = NULL;
return STATUS_UNSUCCESSFUL;
}
#define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(sdl_handle, #f, NULL, 0)) == NULL){WARN("Can't find symbol %s\n", #f); goto sym_not_found;}
@ -1139,20 +1136,16 @@ NTSTATUS WINAPI sdl_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_
pSDL_JoystickGetVendor = wine_dlsym(sdl_handle, "SDL_JoystickGetVendor", NULL, 0);
}
sdl_driver_obj = driver;
driver->MajorFunction[IRP_MJ_PNP] = common_pnp_dispatch;
driver->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = hid_internal_dispatch;
map_controllers = check_bus_option(registry_path, &controller_mode, 1);
if (!(events[0] = CreateEventW(NULL, TRUE, FALSE, NULL)))
goto error;
return STATUS_UNSUCCESSFUL;
args.event = events[0];
args.registry_path = registry_path;
if (!(events[1] = CreateThread(NULL, 0, deviceloop_thread, &args, 0, NULL)))
{
CloseHandle(events[0]);
goto error;
return STATUS_UNSUCCESSFUL;
}
result = WaitForMultipleObjects(2, events, FALSE, INFINITE);
@ -1164,9 +1157,6 @@ NTSTATUS WINAPI sdl_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry_
return STATUS_SUCCESS;
}
error:
sdl_driver_obj = NULL;
return STATUS_UNSUCCESSFUL;
sym_not_found:
wine_dlclose(sdl_handle, NULL, 0);
sdl_handle = NULL;

View File

@ -90,7 +90,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
WINE_DECLARE_DEBUG_CHANNEL(hid_report);
static struct udev *udev_context = NULL;
static DRIVER_OBJECT *udev_driver_obj = NULL;
static DWORD disable_hidraw = 0;
static DWORD disable_input = 0;
@ -1214,13 +1213,13 @@ static void try_add_device(struct udev_device *dev)
if (strcmp(subsystem, "hidraw") == 0)
{
device = bus_create_hid_device(udev_driver_obj, hidraw_busidW, vid, pid, input, version, 0, serial, is_gamepad,
device = bus_create_hid_device(hidraw_busidW, vid, pid, input, version, 0, serial, is_gamepad,
&GUID_DEVCLASS_HIDRAW, &hidraw_vtbl, sizeof(struct platform_private));
}
#ifdef HAS_PROPER_INPUT_HEADER
else if (strcmp(subsystem, "input") == 0)
{
device = bus_create_hid_device(udev_driver_obj, lnxev_busidW, vid, pid, input, version, 0, serial, is_gamepad,
device = bus_create_hid_device(lnxev_busidW, vid, pid, input, version, 0, serial, is_gamepad,
&GUID_DEVCLASS_LINUXEVENT, &lnxev_vtbl, sizeof(struct wine_input_private));
}
#endif
@ -1469,10 +1468,6 @@ NTSTATUS WINAPI udev_driver_init(DRIVER_OBJECT *driver, UNICODE_STRING *registry
return STATUS_UNSUCCESSFUL;
}
udev_driver_obj = driver;
driver->MajorFunction[IRP_MJ_PNP] = common_pnp_dispatch;
driver->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = hid_internal_dispatch;
disable_hidraw = check_bus_option(registry_path, &hidraw_disabled, 0);
if (disable_hidraw)
TRACE("UDEV hidraw devices disabled in registry\n");
@ -1504,7 +1499,6 @@ error:
ERR("Failed to initialize udev device thread\n");
udev_unref(udev_context);
udev_context = NULL;
udev_driver_obj = NULL;
return STATUS_UNSUCCESSFUL;
}

View File

@ -61,6 +61,8 @@ static const WORD PID_XBOX_CONTROLLERS[] = {
0x0719, /* Xbox 360 Wireless Adapter */
};
static DRIVER_OBJECT *driver_obj;
struct pnp_device
{
struct list entry;
@ -208,7 +210,7 @@ static WCHAR *get_compatible_ids(DEVICE_OBJECT *device)
return dst;
}
DEVICE_OBJECT *bus_create_hid_device(DRIVER_OBJECT *driver, const WCHAR *busidW, WORD vid, WORD pid,
DEVICE_OBJECT *bus_create_hid_device(const WCHAR *busidW, WORD vid, WORD pid,
WORD input, DWORD version, DWORD uid, const WCHAR *serialW, BOOL is_gamepad,
const GUID *class, const platform_vtbl *vtbl, DWORD platform_data_size)
{
@ -224,7 +226,7 @@ DEVICE_OBJECT *bus_create_hid_device(DRIVER_OBJECT *driver, const WCHAR *busidW,
NTSTATUS status;
DWORD length;
TRACE("(%p, %s, %04x, %04x, %04x, %u, %u, %s, %u, %s, %p, %u)\n", driver,
TRACE("(%s, %04x, %04x, %04x, %u, %u, %s, %u, %s, %p, %u)\n",
debugstr_w(busidW), vid, pid, input, version, uid, debugstr_w(serialW),
is_gamepad, debugstr_guid(class), vtbl, platform_data_size);
@ -234,7 +236,7 @@ DEVICE_OBJECT *bus_create_hid_device(DRIVER_OBJECT *driver, const WCHAR *busidW,
sprintfW(dev_name, device_name_fmtW, busidW, pnp_dev);
RtlInitUnicodeString(&nameW, dev_name);
length = FIELD_OFFSET(struct device_extension, platform_private[platform_data_size]);
status = IoCreateDevice(driver, length, &nameW, 0, 0, FALSE, &device);
status = IoCreateDevice(driver_obj, length, &nameW, 0, 0, FALSE, &device);
if (status)
{
FIXME("failed to create device error %x\n", status);
@ -469,7 +471,7 @@ static NTSTATUS handle_IRP_MN_QUERY_ID(DEVICE_OBJECT *device, IRP *irp)
return status;
}
NTSTATUS WINAPI common_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp)
static NTSTATUS WINAPI common_pnp_dispatch(DEVICE_OBJECT *device, IRP *irp)
{
NTSTATUS status = irp->IoStatus.u.Status;
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp);
@ -514,7 +516,7 @@ static NTSTATUS deliver_last_report(struct device_extension *ext, DWORD buffer_l
}
}
NTSTATUS WINAPI hid_internal_dispatch(DEVICE_OBJECT *device, IRP *irp)
static NTSTATUS WINAPI hid_internal_dispatch(DEVICE_OBJECT *device, IRP *irp)
{
NTSTATUS status = irp->IoStatus.u.Status;
IO_STACK_LOCATION *irpsp = IoGetCurrentIrpStackLocation(irp);
@ -795,6 +797,12 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
TRACE( "(%p, %s)\n", driver, debugstr_w(path->Buffer) );
driver_obj = driver;
driver->MajorFunction[IRP_MJ_PNP] = common_pnp_dispatch;
driver->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = hid_internal_dispatch;
driver->DriverUnload = driver_unload;
if (check_bus_option(path, &SDL_enabled, 1))
{
if (IoCreateDriver(&sdl, sdl_driver_init) == STATUS_SUCCESS)
@ -803,7 +811,5 @@ NTSTATUS WINAPI DriverEntry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
IoCreateDriver(&udev, udev_driver_init);
IoCreateDriver(&iohid, iohid_driver_init);
driver->DriverUnload = driver_unload;
return STATUS_SUCCESS;
}