win-pvdrivers

view xenstub/xenstub.c @ 387:48df739c66d4

Removed some debugging calls to the HLT instruction
author James Harper <james.harper@bendigoit.com.au>
date Fri Jul 11 14:05:34 2008 +1000 (2008-07-11)
parents 691c6ebe92cf
children ee82244eed7c
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 IoMarkIrpPending(irp);
107 status = XenStub_SendAndWaitForIrp(device_object, irp);
108 status = irp->IoStatus.Status = STATUS_SUCCESS;
109 IoCompleteRequest(irp, IO_NO_INCREMENT);
110 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
111 return status;
113 case IRP_MN_QUERY_STOP_DEVICE:
114 //KdPrint((__DRIVER_NAME " IRP_MN_QUERY_STOP_DEVICE\n"));
115 IoSkipCurrentIrpStackLocation(irp);
116 irp->IoStatus.Status = STATUS_SUCCESS;
117 break;
119 case IRP_MN_STOP_DEVICE:
120 //KdPrint((__DRIVER_NAME " IRP_MN_STOP_DEVICE\n"));
121 IoSkipCurrentIrpStackLocation(irp);
122 irp->IoStatus.Status = STATUS_SUCCESS;
123 break;
125 case IRP_MN_CANCEL_STOP_DEVICE:
126 //KdPrint((__DRIVER_NAME " IRP_MN_CANCEL_STOP_DEVICE\n"));
127 IoSkipCurrentIrpStackLocation(irp);
128 irp->IoStatus.Status = STATUS_SUCCESS;
129 break;
131 case IRP_MN_QUERY_REMOVE_DEVICE:
132 //KdPrint((__DRIVER_NAME " IRP_MN_QUERY_REMOVE_DEVICE\n"));
133 IoSkipCurrentIrpStackLocation(irp);
134 irp->IoStatus.Status = STATUS_SUCCESS;
135 break;
137 case IRP_MN_REMOVE_DEVICE:
138 //KdPrint((__DRIVER_NAME " IRP_MN_REMOVE_DEVICE\n"));
139 IoSkipCurrentIrpStackLocation(irp);
140 irp->IoStatus.Status = STATUS_SUCCESS;
141 break;
143 case IRP_MN_CANCEL_REMOVE_DEVICE:
144 //KdPrint((__DRIVER_NAME " IRP_MN_CANCEL_REMOVE_DEVICE\n"));
145 IoSkipCurrentIrpStackLocation(irp);
146 //irp->IoStatus.Status = STATUS_SUCCESS;
147 break;
149 case IRP_MN_SURPRISE_REMOVAL:
150 //KdPrint((__DRIVER_NAME " IRP_MN_SURPRISE_REMOVAL\n"));
151 IoSkipCurrentIrpStackLocation(irp);
152 //irp->IoStatus.Status = STATUS_SUCCESS;
153 break;
155 case IRP_MN_DEVICE_USAGE_NOTIFICATION:
156 //KdPrint((__DRIVER_NAME " IRP_MN_DEVICE_USAGE_NOTIFICATION\n"));
157 IoSkipCurrentIrpStackLocation(irp);
158 irp->IoStatus.Status = STATUS_SUCCESS;
159 break;
161 case IRP_MN_QUERY_DEVICE_RELATIONS:
162 //KdPrint((__DRIVER_NAME " IRP_MN_QUERY_DEVICE_RELATIONS\n"));
163 IoSkipCurrentIrpStackLocation(irp);
164 //irp->IoStatus.Information = 0;
165 //irp->IoStatus.Status = STATUS_SUCCESS;
166 break;
168 case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
169 /* we actually want to do this - no need for interrupt here */
170 //KdPrint((__DRIVER_NAME " IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n"));
171 IoSkipCurrentIrpStackLocation(irp);
172 //irp->IoStatus.Status = STATUS_SUCCESS;
173 break;
175 case IRP_MN_QUERY_PNP_DEVICE_STATE:
176 //KdPrint((__DRIVER_NAME " IRP_MN_QUERY_PNP_DEVICE_STATE\n"));
177 status = XenStub_SendAndWaitForIrp(device_object, irp);
178 irp->IoStatus.Information |= PNP_DEVICE_DONT_DISPLAY_IN_UI;
179 status = irp->IoStatus.Status = STATUS_SUCCESS;
180 IoCompleteRequest(irp, IO_NO_INCREMENT);
181 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
182 return status;
184 default:
185 //KdPrint((__DRIVER_NAME " Unhandled Minor = %d\n", stack->MinorFunction));
186 IoSkipCurrentIrpStackLocation(irp);
187 break;
188 }
190 status = IoCallDriver(xsdd->lower_do, irp);
192 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
194 return status;
195 }
197 NTSTATUS
198 XenStub_Irp_Power(PDEVICE_OBJECT device_object, PIRP irp)
199 {
200 NTSTATUS status;
201 PXENSTUB_DEVICE_DATA xsdd = device_object->DeviceExtension;
203 UNREFERENCED_PARAMETER(device_object);
205 //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
207 PoStartNextPowerIrp(irp);
208 IoSkipCurrentIrpStackLocation(irp);
210 status = PoCallDriver (xsdd->lower_do, irp);
212 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
214 return status;
215 }
217 static NTSTATUS
218 XenStub_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
219 {
220 NTSTATUS status;
221 PDEVICE_OBJECT fdo = NULL;
222 PXENSTUB_DEVICE_DATA xsdd;
224 //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
226 status = IoCreateDevice(DriverObject,
227 sizeof(XENSTUB_DEVICE_DATA),
228 NULL,
229 FILE_DEVICE_NULL,
230 FILE_DEVICE_SECURE_OPEN,
231 FALSE,
232 &fdo);
234 if (!NT_SUCCESS(status))
235 {
236 //KdPrint((__DRIVER_NAME " IoCreateDevice failed 0x%08x\n", status));
237 return status;
238 }
240 xsdd = (PXENSTUB_DEVICE_DATA)fdo->DeviceExtension;
242 RtlZeroMemory(xsdd, sizeof(XENSTUB_DEVICE_DATA));
244 xsdd->fdo = fdo;
245 xsdd->pdo = PhysicalDeviceObject;
246 xsdd->lower_do = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
247 if(xsdd->lower_do == NULL) {
248 IoDeleteDevice(fdo);
249 return STATUS_NO_SUCH_DEVICE;
250 }
252 fdo->Flags &= ~DO_DEVICE_INITIALIZING;
254 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
255 return status;
256 }
258 NTSTATUS
259 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
260 {
261 NTSTATUS status = STATUS_SUCCESS;
263 UNREFERENCED_PARAMETER(RegistryPath);
265 //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
267 DriverObject->DriverExtension->AddDevice = XenStub_AddDevice;
268 DriverObject->MajorFunction[IRP_MJ_PNP] = XenStub_Irp_Pnp;
269 DriverObject->MajorFunction[IRP_MJ_POWER] = XenStub_Irp_Power;
270 DriverObject->MajorFunction[IRP_MJ_CREATE] = NULL;
271 DriverObject->MajorFunction[IRP_MJ_CLOSE] = NULL;
272 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = NULL;
273 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NULL;
274 DriverObject->MajorFunction[IRP_MJ_READ] = NULL;
275 DriverObject->MajorFunction[IRP_MJ_WRITE] = NULL;
276 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = NULL;
278 //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
280 return status;