ntdll: Fix SMT CPU flag reporting.
[wine/zf.git] / dlls / hidclass.sys / main.c
blob1c7a3ca82afd1163485281f9386623b54953a6ad
1 /*
2 * WINE Hid device services
4 * Copyright 2015 Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #include <unistd.h>
23 #include <stdarg.h>
24 #include "hid.h"
25 #include "wine/debug.h"
26 #include "wine/list.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(hid);
30 static struct list minidriver_list = LIST_INIT(minidriver_list);
32 minidriver* find_minidriver(DRIVER_OBJECT *driver)
34 minidriver *md;
35 LIST_FOR_EACH_ENTRY(md, &minidriver_list, minidriver, entry)
37 if (md->minidriver.DriverObject == driver)
38 return md;
40 return NULL;
43 static VOID WINAPI UnloadDriver(DRIVER_OBJECT *driver)
45 minidriver *md;
47 TRACE("Driver Unload\n");
48 md = find_minidriver(driver);
49 if (md)
51 hid_device *device, *next;
52 TRACE("%i devices to unload\n", list_count(&md->device_list));
53 LIST_FOR_EACH_ENTRY_SAFE(device, next, &md->device_list, hid_device, entry)
55 PNP_RemoveDevice(md, device->device, NULL);
57 if (md->DriverUnload)
58 md->DriverUnload(md->minidriver.DriverObject);
59 list_remove(&md->entry);
60 HeapFree( GetProcessHeap(), 0, md );
64 NTSTATUS WINAPI HidRegisterMinidriver(HID_MINIDRIVER_REGISTRATION *registration)
66 minidriver *driver;
67 driver = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*driver));
69 if (!driver)
70 return STATUS_NO_MEMORY;
72 driver->DriverUnload = registration->DriverObject->DriverUnload;
73 registration->DriverObject->DriverUnload = UnloadDriver;
75 registration->DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = HID_Device_ioctl;
76 registration->DriverObject->MajorFunction[IRP_MJ_READ] = HID_Device_read;
77 registration->DriverObject->MajorFunction[IRP_MJ_WRITE] = HID_Device_write;
78 registration->DriverObject->MajorFunction[IRP_MJ_CREATE] = HID_Device_create;
79 registration->DriverObject->MajorFunction[IRP_MJ_CLOSE] = HID_Device_close;
81 driver->PNPDispatch = registration->DriverObject->MajorFunction[IRP_MJ_PNP];
82 registration->DriverObject->MajorFunction[IRP_MJ_PNP] = HID_PNP_Dispatch;
84 driver->AddDevice = registration->DriverObject->DriverExtension->AddDevice;
85 registration->DriverObject->DriverExtension->AddDevice = PNP_AddDevice;
87 driver->minidriver = *registration;
88 list_add_tail(&minidriver_list, &driver->entry);
90 list_init(&driver->device_list);
92 return STATUS_SUCCESS;
95 static NTSTATUS WINAPI internalComplete(DEVICE_OBJECT *deviceObject, IRP *irp,
96 void *context)
98 HANDLE event = context;
99 SetEvent(event);
100 return STATUS_MORE_PROCESSING_REQUIRED;
103 NTSTATUS call_minidriver(ULONG code, DEVICE_OBJECT *device, void *in_buff, ULONG in_size, void *out_buff, ULONG out_size)
105 IRP *irp;
106 IO_STATUS_BLOCK irp_status;
107 NTSTATUS status;
108 HANDLE event = CreateEventA(NULL, FALSE, FALSE, NULL);
110 irp = IoBuildDeviceIoControlRequest(code, device, in_buff, in_size,
111 out_buff, out_size, TRUE, NULL, &irp_status);
113 IoSetCompletionRoutine(irp, internalComplete, event, TRUE, TRUE, TRUE);
114 status = IoCallDriver(device, irp);
116 if (status == STATUS_PENDING)
117 WaitForSingleObject(event, INFINITE);
119 status = irp->IoStatus.u.Status;
121 IoCompleteRequest(irp, IO_NO_INCREMENT );
122 CloseHandle(event);
124 return status;