win-pvdrivers

annotate xenstub/xenstub.c @ 698:ec4a20a75657

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