winebus.sys: Move mouse and keyboard devices to unixlib.c.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-08-30 11:22:55 +02:00 committed by Alexandre Julliard
parent 2457113970
commit 5e0c1ce443
6 changed files with 208 additions and 166 deletions

View File

@ -25,6 +25,8 @@
#include <ddk/hidclass.h>
#include <hidusage.h>
#include "unixlib.h"
typedef int(*enum_func)(DEVICE_OBJECT *device, void *context);
/* Native device function table */
@ -56,23 +58,5 @@ BOOL is_xbox_gamepad(WORD vid, WORD pid) DECLSPEC_HIDDEN;
extern HANDLE driver_key DECLSPEC_HIDDEN;
extern DEVICE_OBJECT *bus_pdo DECLSPEC_HIDDEN;
struct hid_descriptor
{
BYTE *data;
SIZE_T size;
SIZE_T max_size;
};
extern BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffer, SIZE_T size) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_begin(struct hid_descriptor *desc, USAGE usage_page, USAGE usage) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_end(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
extern void hid_descriptor_free(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page,
USAGE usage_min, USAGE usage_max) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page,
const USAGE *usages, BOOL rel, INT size, LONG min, LONG max) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_haptics(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
extern const platform_vtbl mouse_vtbl DECLSPEC_HIDDEN;
extern const platform_vtbl keyboard_vtbl DECLSPEC_HIDDEN;

View File

@ -27,9 +27,9 @@
#include "hidusage.h"
#include "ddk/wdm.h"
#include "bus.h"
#include "unix_private.h"
BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffer, SIZE_T size)
static BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffer, SIZE_T size)
{
BYTE *tmp = desc->data;

View File

@ -95,9 +95,7 @@ static const struct product_desc XBOX_CONTROLLERS[] = {
static DRIVER_OBJECT *driver_obj;
static DEVICE_OBJECT *mouse_obj;
static struct hid_descriptor mouse_desc;
static DEVICE_OBJECT *keyboard_obj;
static struct hid_descriptor keyboard_desc;
/* The root-enumerated device stack. */
DEVICE_OBJECT *bus_pdo;
@ -483,157 +481,23 @@ static NTSTATUS handle_IRP_MN_QUERY_ID(DEVICE_OBJECT *device, IRP *irp)
return status;
}
static void mouse_free_device(DEVICE_OBJECT *device)
{
}
static NTSTATUS mouse_start_device(DEVICE_OBJECT *device)
{
if (!hid_descriptor_begin(&mouse_desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_MOUSE))
return STATUS_NO_MEMORY;
if (!hid_descriptor_add_buttons(&mouse_desc, HID_USAGE_PAGE_BUTTON, 1, 3))
return STATUS_NO_MEMORY;
if (!hid_descriptor_end(&mouse_desc))
return STATUS_NO_MEMORY;
return STATUS_SUCCESS;
}
static NTSTATUS mouse_get_reportdescriptor(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *ret_length)
{
TRACE("buffer %p, length %u.\n", buffer, length);
*ret_length = mouse_desc.size;
if (length < mouse_desc.size) return STATUS_BUFFER_TOO_SMALL;
memcpy(buffer, mouse_desc.data, mouse_desc.size);
return STATUS_SUCCESS;
}
static NTSTATUS mouse_get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD length)
{
static const WCHAR nameW[] = {'W','i','n','e',' ','H','I','D',' ','m','o','u','s','e',0};
if (index != HID_STRING_ID_IPRODUCT)
return STATUS_NOT_IMPLEMENTED;
if (length < ARRAY_SIZE(nameW))
return STATUS_BUFFER_TOO_SMALL;
strcpyW(buffer, nameW);
return STATUS_SUCCESS;
}
static void mouse_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
static void mouse_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
static void mouse_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
static const platform_vtbl mouse_vtbl =
{
.free_device = mouse_free_device,
.start_device = mouse_start_device,
.get_reportdescriptor = mouse_get_reportdescriptor,
.get_string = mouse_get_string,
.set_output_report = mouse_set_output_report,
.get_feature_report = mouse_get_feature_report,
.set_feature_report = mouse_set_feature_report,
};
static void mouse_device_create(void)
{
static const WCHAR busidW[] = {'W','I','N','E','M','O','U','S','E',0};
mouse_obj = bus_create_hid_device(busidW, 0, 0, -1, 0, 0, busidW, FALSE, &mouse_vtbl, 0);
struct device_create_params params = {0};
if (winebus_call(mouse_create, &params)) return;
mouse_obj = bus_create_hid_device(busidW, 0, 0, -1, 0, 0, busidW, FALSE, &mouse_vtbl, params.device);
IoInvalidateDeviceRelations(bus_pdo, BusRelations);
}
static void keyboard_free_device(DEVICE_OBJECT *device)
{
}
static NTSTATUS keyboard_start_device(DEVICE_OBJECT *device)
{
if (!hid_descriptor_begin(&keyboard_desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_KEYBOARD))
return STATUS_NO_MEMORY;
if (!hid_descriptor_add_buttons(&keyboard_desc, HID_USAGE_PAGE_KEYBOARD, 0, 101))
return STATUS_NO_MEMORY;
if (!hid_descriptor_end(&keyboard_desc))
return STATUS_NO_MEMORY;
return STATUS_SUCCESS;
}
static NTSTATUS keyboard_get_reportdescriptor(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *ret_length)
{
TRACE("buffer %p, length %u.\n", buffer, length);
*ret_length = keyboard_desc.size;
if (length < keyboard_desc.size) return STATUS_BUFFER_TOO_SMALL;
memcpy(buffer, keyboard_desc.data, keyboard_desc.size);
return STATUS_SUCCESS;
}
static NTSTATUS keyboard_get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD length)
{
static const WCHAR nameW[] = {'W','i','n','e',' ','H','I','D',' ','k','e','y','b','o','a','r','d',0};
if (index != HID_STRING_ID_IPRODUCT)
return STATUS_NOT_IMPLEMENTED;
if (length < ARRAY_SIZE(nameW))
return STATUS_BUFFER_TOO_SMALL;
strcpyW(buffer, nameW);
return STATUS_SUCCESS;
}
static void keyboard_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
static void keyboard_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
static void keyboard_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
static const platform_vtbl keyboard_vtbl =
{
.free_device = keyboard_free_device,
.start_device = keyboard_start_device,
.get_reportdescriptor = keyboard_get_reportdescriptor,
.get_string = keyboard_get_string,
.set_output_report = keyboard_set_output_report,
.get_feature_report = keyboard_get_feature_report,
.set_feature_report = keyboard_set_feature_report,
};
static void keyboard_device_create(void)
{
static const WCHAR busidW[] = {'W','I','N','E','K','E','Y','B','O','A','R','D',0};
keyboard_obj = bus_create_hid_device(busidW, 0, 0, -1, 0, 0, busidW, FALSE, &keyboard_vtbl, 0);
struct device_create_params params = {0};
if (winebus_call(keyboard_create, &params)) return;
keyboard_obj = bus_create_hid_device(busidW, 0, 0, -1, 0, 0, busidW, FALSE, &keyboard_vtbl, params.device);
IoInvalidateDeviceRelations(bus_pdo, BusRelations);
}

View File

@ -49,4 +49,24 @@ extern void bus_event_queue_destroy(struct list *queue) DECLSPEC_HIDDEN;
extern BOOL bus_event_queue_device_removed(struct list *queue, const WCHAR *bus_id, void *context) DECLSPEC_HIDDEN;
extern BOOL bus_event_queue_pop(struct list *queue, struct bus_event *event) DECLSPEC_HIDDEN;
struct hid_descriptor
{
BYTE *data;
SIZE_T size;
SIZE_T max_size;
};
extern BOOL hid_descriptor_begin(struct hid_descriptor *desc, USAGE usage_page, USAGE usage) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_end(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
extern void hid_descriptor_free(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page,
USAGE usage_min, USAGE usage_max) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_padding(struct hid_descriptor *desc, BYTE bitcount) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page,
const USAGE *usages, BOOL rel, INT size, LONG min, LONG max) DECLSPEC_HIDDEN;
extern BOOL hid_descriptor_add_haptics(struct hid_descriptor *desc) DECLSPEC_HIDDEN;
#endif /* __WINEBUS_UNIX_PRIVATE_H */

View File

@ -24,13 +24,178 @@
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "ddk/hidtypes.h"
#include "wine/debug.h"
#include "wine/list.h"
#include "wine/unixlib.h"
#include "bus.h"
#include "unix_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(plugplay);
static struct hid_descriptor mouse_desc;
static struct hid_descriptor keyboard_desc;
static void mouse_free_device(DEVICE_OBJECT *device)
{
}
static NTSTATUS mouse_start_device(DEVICE_OBJECT *device)
{
if (!hid_descriptor_begin(&mouse_desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_MOUSE))
return STATUS_NO_MEMORY;
if (!hid_descriptor_add_buttons(&mouse_desc, HID_USAGE_PAGE_BUTTON, 1, 3))
return STATUS_NO_MEMORY;
if (!hid_descriptor_end(&mouse_desc))
return STATUS_NO_MEMORY;
return STATUS_SUCCESS;
}
static NTSTATUS mouse_get_reportdescriptor(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *ret_length)
{
TRACE("buffer %p, length %u.\n", buffer, length);
*ret_length = mouse_desc.size;
if (length < mouse_desc.size) return STATUS_BUFFER_TOO_SMALL;
memcpy(buffer, mouse_desc.data, mouse_desc.size);
return STATUS_SUCCESS;
}
static NTSTATUS mouse_get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD length)
{
static const WCHAR nameW[] = {'W','i','n','e',' ','H','I','D',' ','m','o','u','s','e',0};
if (index != HID_STRING_ID_IPRODUCT)
return STATUS_NOT_IMPLEMENTED;
if (length < ARRAY_SIZE(nameW))
return STATUS_BUFFER_TOO_SMALL;
lstrcpyW(buffer, nameW);
return STATUS_SUCCESS;
}
static void mouse_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
static void mouse_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
static void mouse_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
const platform_vtbl mouse_vtbl =
{
.free_device = mouse_free_device,
.start_device = mouse_start_device,
.get_reportdescriptor = mouse_get_reportdescriptor,
.get_string = mouse_get_string,
.set_output_report = mouse_set_output_report,
.get_feature_report = mouse_get_feature_report,
.set_feature_report = mouse_set_feature_report,
};
static struct unix_device mouse_device;
static NTSTATUS mouse_device_create(void *args)
{
struct device_create_params *params = args;
params->device = &mouse_device;
return STATUS_SUCCESS;
}
static void keyboard_free_device(DEVICE_OBJECT *device)
{
}
static NTSTATUS keyboard_start_device(DEVICE_OBJECT *device)
{
if (!hid_descriptor_begin(&keyboard_desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_KEYBOARD))
return STATUS_NO_MEMORY;
if (!hid_descriptor_add_buttons(&keyboard_desc, HID_USAGE_PAGE_KEYBOARD, 0, 101))
return STATUS_NO_MEMORY;
if (!hid_descriptor_end(&keyboard_desc))
return STATUS_NO_MEMORY;
return STATUS_SUCCESS;
}
static NTSTATUS keyboard_get_reportdescriptor(DEVICE_OBJECT *device, BYTE *buffer, DWORD length, DWORD *ret_length)
{
TRACE("buffer %p, length %u.\n", buffer, length);
*ret_length = keyboard_desc.size;
if (length < keyboard_desc.size) return STATUS_BUFFER_TOO_SMALL;
memcpy(buffer, keyboard_desc.data, keyboard_desc.size);
return STATUS_SUCCESS;
}
static NTSTATUS keyboard_get_string(DEVICE_OBJECT *device, DWORD index, WCHAR *buffer, DWORD length)
{
static const WCHAR nameW[] = {'W','i','n','e',' ','H','I','D',' ','k','e','y','b','o','a','r','d',0};
if (index != HID_STRING_ID_IPRODUCT)
return STATUS_NOT_IMPLEMENTED;
if (length < ARRAY_SIZE(nameW))
return STATUS_BUFFER_TOO_SMALL;
lstrcpyW(buffer, nameW);
return STATUS_SUCCESS;
}
static void keyboard_set_output_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
static void keyboard_get_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
static void keyboard_set_feature_report(DEVICE_OBJECT *device, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io)
{
FIXME("id %u, stub!\n", packet->reportId);
io->Information = 0;
io->Status = STATUS_NOT_IMPLEMENTED;
}
const platform_vtbl keyboard_vtbl =
{
.free_device = keyboard_free_device,
.start_device = keyboard_start_device,
.get_reportdescriptor = keyboard_get_reportdescriptor,
.get_string = keyboard_get_string,
.set_output_report = keyboard_set_output_report,
.get_feature_report = keyboard_get_feature_report,
.set_feature_report = keyboard_set_feature_report,
};
static struct unix_device keyboard_device;
static NTSTATUS keyboard_device_create(void *args)
{
struct device_create_params *params = args;
params->device = &keyboard_device;
return STATUS_SUCCESS;
}
const unixlib_entry_t __wine_unix_call_funcs[] =
{
sdl_bus_init,
@ -42,6 +207,8 @@ const unixlib_entry_t __wine_unix_call_funcs[] =
iohid_bus_init,
iohid_bus_wait,
iohid_bus_stop,
mouse_device_create,
keyboard_device_create,
};
void bus_event_queue_destroy(struct list *queue)

View File

@ -68,6 +68,11 @@ struct bus_event
};
};
struct device_create_params
{
struct unix_device *device;
};
enum unix_funcs
{
sdl_init,
@ -79,6 +84,8 @@ enum unix_funcs
iohid_init,
iohid_wait,
iohid_stop,
mouse_create,
keyboard_create,
};
extern const unixlib_entry_t __wine_unix_call_funcs[] DECLSPEC_HIDDEN;