win-pvdrivers

view xenaddresource/xenaddresource.c @ 1041:4016afe45e7b

update ignore file to exclude TAG_HG
author James Harper <james.harper@bendigoit.com.au>
date Sun Mar 03 16:19:43 2013 +1100 (2013-03-03)
parents 58d13f9f8ef3
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 "xenaddresource.h"
21 #include <stdlib.h>
23 DRIVER_INITIALIZE DriverEntry;
24 static NTSTATUS
25 XenAddResource_AddDevice(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit);
26 static NTSTATUS
27 XenAddResource_PreprocessWdmIrpPNP(WDFDEVICE Device, PIRP Irp);
28 //static VOID
29 //XenAddResource_IoInternalDeviceControl(WDFQUEUE Queue, WDFREQUEST Request, size_t OutputBufferLength, size_t InputBufferLength, ULONG IoControlCode);
30 static NTSTATUS
31 XenAddResource_EvtDeviceFilterAddResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST IoResourceRequirementsList);
33 #ifdef ALLOC_PRAGMA
34 #pragma alloc_text (INIT, DriverEntry)
35 #pragma alloc_text (PAGE, XenAddResource_AddDevice)
36 #endif
38 static BOOLEAN AutoEnumerate;
40 static WDFDEVICE Device;
42 NTSTATUS
43 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
44 {
45 WDF_DRIVER_CONFIG config;
46 NTSTATUS status;
48 KdPrint((__DRIVER_NAME " --> DriverEntry\n"));
50 WDF_DRIVER_CONFIG_INIT(&config, XenAddResource_AddDevice);
51 status = WdfDriverCreate(
52 DriverObject,
53 RegistryPath,
54 WDF_NO_OBJECT_ATTRIBUTES,
55 &config,
56 WDF_NO_HANDLE);
57 if(!NT_SUCCESS(status))
58 {
59 KdPrint((__DRIVER_NAME " WdfDriverCreate failed with status 0x%08x\n", status));
60 }
62 KdPrint((__DRIVER_NAME " <-- DriverEntry\n"));
64 return status;
65 }
67 static NTSTATUS
68 XenAddResource_AddDevice(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit)
69 {
70 NTSTATUS Status;
71 WDF_OBJECT_ATTRIBUTES attributes;
72 UCHAR PnpMinors[2] = { IRP_MN_START_DEVICE, IRP_MN_STOP_DEVICE };
74 UNREFERENCED_PARAMETER(Driver);
76 KdPrint((__DRIVER_NAME " --> DeviceAdd\n"));
78 WdfFdoInitSetFilter(DeviceInit);
80 Status = WdfDeviceInitAssignWdmIrpPreprocessCallback(DeviceInit, XenAddResource_PreprocessWdmIrpPNP, IRP_MJ_PNP, PnpMinors, 2);
81 if (!NT_SUCCESS(Status))
82 KdPrint((__DRIVER_NAME " WdfDeviceInitAssignWdmIrpPreprocessCallback(IRP_MJ_PNP) Status = %08X\n", Status));
84 WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
85 Status = WdfDeviceCreate(&DeviceInit, &attributes, &Device);
86 if(!NT_SUCCESS(Status))
87 {
88 KdPrint((__DRIVER_NAME " WdfDeviceCreate failed with status 0x%08x)\n", Status));
89 return Status;
90 }
92 KdPrint((__DRIVER_NAME " <-- DeviceAdd\n"));
94 return Status;
95 }
97 static NTSTATUS
98 XenAddResource_PreprocessWdmIrpPNP(WDFDEVICE Device, PIRP Irp)
99 {
100 NTSTATUS Status = STATUS_SUCCESS;
101 PIO_STACK_LOCATION Stack;
102 PXENPCI_XEN_DEVICE_DATA XenDeviceData;
103 //PXENADDRESOURCE_DEVICE_DATA XenAddResourcesDeviceData;
105 KdPrint((__DRIVER_NAME " --> WdmIrpPreprocessPNP\n"));
107 Stack = IoGetCurrentIrpStackLocation(Irp);
109 switch (Stack->MinorFunction) {
110 case IRP_MN_START_DEVICE:
111 KdPrint((__DRIVER_NAME " IRP_MN_START_DEVICE\n"));
113 if (Stack->Parameters.StartDevice.AllocatedResources != NULL)
114 {
115 // free stuff here... or maybe just exit
116 }
117 if (Stack->Parameters.StartDevice.AllocatedResourcesTranslated != NULL)
118 {
119 // free stuff here... or maybe just exit
120 }
122 XenDeviceData = WdfDeviceWdmGetPhysicalDevice(Device)->DeviceExtension;
123 // verify Magic here
125 Stack->Parameters.StartDevice.AllocatedResources = ExAllocatePoolWithTag(NonPagedPool, sizeof(CM_RESOURCE_LIST) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1, XENADDRESOURCE_POOL_TAG);
126 Stack->Parameters.StartDevice.AllocatedResourcesTranslated = ExAllocatePoolWithTag(NonPagedPool, sizeof(CM_RESOURCE_LIST) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1, XENADDRESOURCE_POOL_TAG);
128 Stack->Parameters.StartDevice.AllocatedResources->Count = 1;
129 Stack->Parameters.StartDevice.AllocatedResources->List[0].InterfaceType = Internal;
130 Stack->Parameters.StartDevice.AllocatedResources->List[0].BusNumber = 0;
131 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.Version = 1;
132 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.Revision = 1;
133 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.Count = 2;
134 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].Type = CmResourceTypeMemory;
135 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareDeviceExclusive;
136 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].Flags = CM_RESOURCE_MEMORY_READ_WRITE;
137 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Memory.Start.QuadPart = (ULONGLONG)XenDeviceData;
138 Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Memory.Length = sizeof(XENPCI_XEN_DEVICE_DATA);
139 memcpy(&Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1], &XenDeviceData->InterruptRaw, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
141 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->Count = 1;
142 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].InterfaceType = Internal;
143 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].BusNumber = 0;
144 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.Version = 1;
145 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.Revision = 1;
146 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.Count = 2;
147 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[0].Type = CmResourceTypeMemory;
148 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareDeviceExclusive;
149 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[0].Flags = CM_RESOURCE_MEMORY_READ_WRITE;
150 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[0].u.Memory.Start.QuadPart = (ULONGLONG)XenDeviceData;
151 Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[0].u.Memory.Length = sizeof(XENPCI_XEN_DEVICE_DATA);
152 memcpy(&Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[1], &XenDeviceData->InterruptTranslated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
154 IoSkipCurrentIrpStackLocation(Irp);
155 Status = WdfDeviceWdmDispatchPreprocessedIrp(Device, Irp);
156 break;
157 default:
158 IoSkipCurrentIrpStackLocation(Irp);
159 Status = WdfDeviceWdmDispatchPreprocessedIrp(Device, Irp);
160 KdPrint((__DRIVER_NAME " Unknown Minor %d\n", Stack->MinorFunction));
161 break;
162 }
164 KdPrint((__DRIVER_NAME " <-- WdmIrpPreprocessPNP (returning with status %08x\n", Status));
166 return Status;
167 }