win-pvdrivers

view xenstub/xenstub.c @ 1058:8b6500e0ebfc

Rename to fix case issue on shutdownmon directory
author James Harper <james.harper@bendigoit.com.au>
date Mon Sep 30 19:46:16 2013 +1000 (2013-09-30)
parents ee82244eed7c
children
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2007 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #include "xenstub.h"
21 #include <stdlib.h>
23 DRIVER_INITIALIZE DriverEntry;
25 static NTSTATUS
26 XenStub_Pnp_IoCompletion(PDEVICE_OBJECT device_object, PIRP irp, PVOID context)
27 {
28 PKEVENT event = (PKEVENT)context;
30 UNREFERENCED_PARAMETER(device_object);
32 //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
34 if (irp->PendingReturned)
35 {
36 KeSetEvent(event, IO_NO_INCREMENT, FALSE);
37 }
39 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
41 return STATUS_MORE_PROCESSING_REQUIRED;
42 }
44 #if 0
45 static NTSTATUS
46 XenStub_QueueWorkItem(PDEVICE_OBJECT device_object, PIO_WORKITEM_ROUTINE routine, PVOID context)
47 {
48 PIO_WORKITEM work_item;
49 NTSTATUS status = STATUS_SUCCESS;
51 work_item = IoAllocateWorkItem(device_object);
52 IoQueueWorkItem(work_item, routine, DelayedWorkQueue, context);
54 return status;
55 }
56 #endif
58 static NTSTATUS
59 XenStub_SendAndWaitForIrp(PDEVICE_OBJECT device_object, PIRP irp)
60 {
61 NTSTATUS status;
62 PXENSTUB_DEVICE_DATA xsdd = (PXENSTUB_DEVICE_DATA)device_object->DeviceExtension;
63 KEVENT event;
65 UNREFERENCED_PARAMETER(device_object);
67 //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
69 KeInitializeEvent(&event, NotificationEvent, FALSE);
71 IoCopyCurrentIrpStackLocationToNext(irp);
72 IoSetCompletionRoutine(irp, XenStub_Pnp_IoCompletion, &event, TRUE, TRUE, TRUE);
74 status = IoCallDriver(xsdd->lower_do, irp);
76 if (status == STATUS_PENDING)
77 {
78 //KdPrint((__DRIVER_NAME " waiting ...\n"));
79 KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
80 //KdPrint((__DRIVER_NAME " ... done\n"));
81 status = irp->IoStatus.Status;
82 }
84 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
86 return status;
87 }
89 NTSTATUS
90 XenStub_Irp_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
91 {
92 PIO_STACK_LOCATION stack;
93 NTSTATUS status;
94 PXENSTUB_DEVICE_DATA xsdd;
96 //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
98 xsdd = (PXENSTUB_DEVICE_DATA)device_object->DeviceExtension;
100 stack = IoGetCurrentIrpStackLocation(irp);
102 switch (stack->MinorFunction)
103 {
104 case IRP_MN_START_DEVICE:
105 //KdPrint((__DRIVER_NAME " IRP_MN_START_DEVICE\n"));
106 status = XenStub_SendAndWaitForIrp(device_object, irp);
107 status = irp->IoStatus.Status = STATUS_SUCCESS;
108 IoCompleteRequest(irp, IO_NO_INCREMENT);
109 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
110 return status;
112 case IRP_MN_QUERY_STOP_DEVICE:
113 //KdPrint((__DRIVER_NAME " IRP_MN_QUERY_STOP_DEVICE\n"));
114 IoSkipCurrentIrpStackLocation(irp);
115 irp->IoStatus.Status = STATUS_SUCCESS;
116 break;
118 case IRP_MN_STOP_DEVICE:
119 //KdPrint((__DRIVER_NAME " IRP_MN_STOP_DEVICE\n"));
120 IoSkipCurrentIrpStackLocation(irp);
121 irp->IoStatus.Status = STATUS_SUCCESS;
122 break;
124 case IRP_MN_CANCEL_STOP_DEVICE:
125 //KdPrint((__DRIVER_NAME " IRP_MN_CANCEL_STOP_DEVICE\n"));
126 IoSkipCurrentIrpStackLocation(irp);
127 irp->IoStatus.Status = STATUS_SUCCESS;
128 break;
130 case IRP_MN_QUERY_REMOVE_DEVICE:
131 //KdPrint((__DRIVER_NAME " IRP_MN_QUERY_REMOVE_DEVICE\n"));
132 IoSkipCurrentIrpStackLocation(irp);
133 irp->IoStatus.Status = STATUS_SUCCESS;
134 break;
136 case IRP_MN_REMOVE_DEVICE:
137 //KdPrint((__DRIVER_NAME " IRP_MN_REMOVE_DEVICE\n"));
138 IoSkipCurrentIrpStackLocation(irp);
139 irp->IoStatus.Status = STATUS_SUCCESS;
140 break;
142 case IRP_MN_CANCEL_REMOVE_DEVICE:
143 //KdPrint((__DRIVER_NAME " IRP_MN_CANCEL_REMOVE_DEVICE\n"));
144 IoSkipCurrentIrpStackLocation(irp);
145 //irp->IoStatus.Status = STATUS_SUCCESS;
146 break;
148 case IRP_MN_SURPRISE_REMOVAL:
149 //KdPrint((__DRIVER_NAME " IRP_MN_SURPRISE_REMOVAL\n"));
150 IoSkipCurrentIrpStackLocation(irp);
151 //irp->IoStatus.Status = STATUS_SUCCESS;
152 break;
154 case IRP_MN_DEVICE_USAGE_NOTIFICATION:
155 //KdPrint((__DRIVER_NAME " IRP_MN_DEVICE_USAGE_NOTIFICATION\n"));
156 IoSkipCurrentIrpStackLocation(irp);
157 irp->IoStatus.Status = STATUS_SUCCESS;
158 break;
160 case IRP_MN_QUERY_DEVICE_RELATIONS:
161 //KdPrint((__DRIVER_NAME " IRP_MN_QUERY_DEVICE_RELATIONS\n"));
162 IoSkipCurrentIrpStackLocation(irp);
163 //irp->IoStatus.Information = 0;
164 //irp->IoStatus.Status = STATUS_SUCCESS;
165 break;
167 case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
168 /* we actually want to do this - no need for interrupt here */
169 //KdPrint((__DRIVER_NAME " IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n"));
170 IoSkipCurrentIrpStackLocation(irp);
171 //irp->IoStatus.Status = STATUS_SUCCESS;
172 break;
174 case IRP_MN_QUERY_PNP_DEVICE_STATE:
175 //KdPrint((__DRIVER_NAME " IRP_MN_QUERY_PNP_DEVICE_STATE\n"));
176 status = XenStub_SendAndWaitForIrp(device_object, irp);
177 irp->IoStatus.Information |= PNP_DEVICE_DONT_DISPLAY_IN_UI;
178 status = irp->IoStatus.Status = STATUS_SUCCESS;
179 IoCompleteRequest(irp, IO_NO_INCREMENT);
180 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
181 return status;
183 default:
184 //KdPrint((__DRIVER_NAME " Unhandled Minor = %d\n", stack->MinorFunction));
185 IoSkipCurrentIrpStackLocation(irp);
186 break;
187 }
189 status = IoCallDriver(xsdd->lower_do, irp);
191 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
193 return status;
194 }
196 NTSTATUS
197 XenStub_Irp_Power(PDEVICE_OBJECT device_object, PIRP irp)
198 {
199 NTSTATUS status;
200 PXENSTUB_DEVICE_DATA xsdd = device_object->DeviceExtension;
202 UNREFERENCED_PARAMETER(device_object);
204 //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
206 PoStartNextPowerIrp(irp);
207 IoSkipCurrentIrpStackLocation(irp);
209 status = PoCallDriver (xsdd->lower_do, irp);
211 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
213 return status;
214 }
216 static NTSTATUS
217 XenStub_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
218 {
219 NTSTATUS status;
220 PDEVICE_OBJECT fdo = NULL;
221 PXENSTUB_DEVICE_DATA xsdd;
223 //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
225 status = IoCreateDevice(DriverObject,
226 sizeof(XENSTUB_DEVICE_DATA),
227 NULL,
228 FILE_DEVICE_NULL,
229 FILE_DEVICE_SECURE_OPEN,
230 FALSE,
231 &fdo);
233 if (!NT_SUCCESS(status))
234 {
235 //KdPrint((__DRIVER_NAME " IoCreateDevice failed 0x%08x\n", status));
236 return status;
237 }
239 xsdd = (PXENSTUB_DEVICE_DATA)fdo->DeviceExtension;
241 RtlZeroMemory(xsdd, sizeof(XENSTUB_DEVICE_DATA));
243 xsdd->fdo = fdo;
244 xsdd->pdo = PhysicalDeviceObject;
245 xsdd->lower_do = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
246 if(xsdd->lower_do == NULL) {
247 IoDeleteDevice(fdo);
248 return STATUS_NO_SUCH_DEVICE;
249 }
251 fdo->Flags &= ~DO_DEVICE_INITIALIZING;
253 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
254 return status;
255 }
257 NTSTATUS
258 XenStub_Pass(PDEVICE_OBJECT device_object, PIRP irp)
259 {
260 NTSTATUS status;
261 PIO_STACK_LOCATION stack;
262 PXENSTUB_DEVICE_DATA xsdd = device_object->DeviceExtension;
264 FUNCTION_ENTER();
266 UNREFERENCED_PARAMETER(device_object);
268 stack = IoGetCurrentIrpStackLocation(irp);
269 //KdPrint((__DRIVER_NAME " Minor = %d\n", stack->MinorFunction));
270 IoSkipCurrentIrpStackLocation(irp);
271 status = IoCallDriver(xsdd->lower_do, irp);
273 FUNCTION_EXIT();
275 return status;
276 }
279 NTSTATUS
280 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
281 {
282 NTSTATUS status = STATUS_SUCCESS;
284 UNREFERENCED_PARAMETER(RegistryPath);
286 //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
288 DriverObject->DriverExtension->AddDevice = XenStub_AddDevice;
289 DriverObject->MajorFunction[IRP_MJ_PNP] = XenStub_Irp_Pnp;
290 DriverObject->MajorFunction[IRP_MJ_POWER] = XenStub_Irp_Power;
291 DriverObject->MajorFunction[IRP_MJ_CREATE] = XenStub_Pass;
292 DriverObject->MajorFunction[IRP_MJ_CLOSE] = XenStub_Pass;
293 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = XenStub_Pass;
294 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = XenStub_Pass;
295 DriverObject->MajorFunction[IRP_MJ_READ] = XenStub_Pass;
296 DriverObject->MajorFunction[IRP_MJ_WRITE] = XenStub_Pass;
297 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = XenStub_Pass;
299 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
301 return status;