win-pvdrivers

view xenpci/xenpci.c @ 327:2705232c28d9

re-add bit needed for alloc_text
author Andy Grover <andy.grover@oracle.com>
date Thu Jun 19 15:30:47 2008 -0700 (2008-06-19)
parents 39e1a87d9189
children c563a0f32b2f
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 "xenpci.h"
21 #include <stdlib.h>
23 #define SYSRQ_PATH "control/sysrq"
24 #define SHUTDOWN_PATH "control/shutdown"
25 #define BALLOON_PATH "memory/target"
27 #ifdef ALLOC_PRAGMA
28 DRIVER_INITIALIZE DriverEntry;
29 #pragma alloc_text (INIT, DriverEntry)
30 #endif
32 #pragma warning(disable : 4200) // zero-sized array
34 #ifndef __MINGW32__
35 #define DDKAPI
36 #endif
38 static DDKAPI NTSTATUS
39 XenPci_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
40 {
41 NTSTATUS status;
42 PXENPCI_COMMON common = device_object->DeviceExtension;
44 if (common->lower_do)
45 status = XenPci_Pnp_Fdo(device_object, irp);
46 else
47 status = XenPci_Pnp_Pdo(device_object, irp);
49 return status;
50 }
52 static DDKAPI NTSTATUS
53 XenPci_Power(PDEVICE_OBJECT device_object, PIRP irp)
54 {
55 NTSTATUS status;
56 PXENPCI_COMMON common = device_object->DeviceExtension;
58 if (common->lower_do)
59 status = XenPci_Power_Fdo(device_object, irp);
60 else
61 status = XenPci_Power_Pdo(device_object, irp);
63 return status;
64 }
66 static DDKAPI NTSTATUS
67 XenPci_Irp_Create(PDEVICE_OBJECT device_object, PIRP irp)
68 {
69 NTSTATUS status;
70 PXENPCI_COMMON common = device_object->DeviceExtension;
72 if (common->lower_do)
73 status = XenPci_Irp_Create_Fdo(device_object, irp);
74 else
75 status = XenPci_Irp_Create_Pdo(device_object, irp);
77 return status;
78 }
80 static DDKAPI NTSTATUS
81 XenPci_Irp_Close(PDEVICE_OBJECT device_object, PIRP irp)
82 {
83 NTSTATUS status;
84 PXENPCI_COMMON common = device_object->DeviceExtension;
86 if (common->lower_do)
87 status = XenPci_Irp_Close_Fdo(device_object, irp);
88 else
89 status = XenPci_Irp_Close_Pdo(device_object, irp);
91 return status;
92 }
94 static DDKAPI NTSTATUS
95 XenPci_Irp_Read(PDEVICE_OBJECT device_object, PIRP irp)
96 {
97 NTSTATUS status;
98 PXENPCI_COMMON common = device_object->DeviceExtension;
100 if (common->lower_do)
101 status = XenPci_Irp_Read_Fdo(device_object, irp);
102 else
103 status = XenPci_Irp_Read_Pdo(device_object, irp);
105 return status;
106 }
108 static DDKAPI NTSTATUS
109 XenPci_Irp_Cleanup(PDEVICE_OBJECT device_object, PIRP irp)
110 {
111 NTSTATUS status;
112 PXENPCI_COMMON common = device_object->DeviceExtension;
114 if (common->lower_do)
115 status = XenPci_Irp_Cleanup_Fdo(device_object, irp);
116 else
117 status = XenPci_Irp_Cleanup_Pdo(device_object, irp);
119 return status;
120 }
122 static DDKAPI NTSTATUS
123 XenPci_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
124 {
125 NTSTATUS status;
126 PDEVICE_OBJECT fdo = NULL;
127 // PNP_BUS_INFORMATION busInfo;
128 // DECLARE_CONST_UNICODE_STRING(DeviceName, L"\\Device\\XenShutdown");
129 // DECLARE_CONST_UNICODE_STRING(SymbolicName, L"\\DosDevices\\XenShutdown");
130 // WDFDEVICE Device;
131 PXENPCI_DEVICE_DATA xpdd;
132 //PWSTR InterfaceList;
134 KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
136 status = IoCreateDevice(DriverObject,
137 sizeof(XENPCI_DEVICE_DATA),
138 NULL,
139 FILE_DEVICE_BUS_EXTENDER,
140 FILE_DEVICE_SECURE_OPEN,
141 FALSE,
142 &fdo);
144 if (!NT_SUCCESS(status))
145 {
146 KdPrint((__DRIVER_NAME " IoCreateDevice failed 0x%08x\n", status));
147 return status;
148 }
150 fdo->Flags |= DO_BUFFERED_IO;
152 xpdd = (PXENPCI_DEVICE_DATA)fdo->DeviceExtension;
154 RtlZeroMemory(xpdd, sizeof(XENPCI_DEVICE_DATA));
156 xpdd->shutdown_prod = 0;
157 xpdd->shutdown_cons = 0;
158 KeInitializeSpinLock(&xpdd->shutdown_ring_lock);
160 xpdd->common.fdo = fdo;
161 xpdd->common.pdo = PhysicalDeviceObject;
162 xpdd->common.lower_do = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
163 if(xpdd->common.lower_do == NULL) {
164 IoDeleteDevice(fdo);
165 return STATUS_NO_SUCH_DEVICE;
166 }
167 INIT_PNP_STATE(&xpdd->common);
168 xpdd->common.device_usage_paging = 0;
169 xpdd->common.device_usage_dump = 0;
170 xpdd->common.device_usage_hibernation = 0;
172 InitializeListHead(&xpdd->child_list);
174 status = IoRegisterDeviceInterface(
175 PhysicalDeviceObject,
176 (LPGUID)&GUID_XEN_IFACE,
177 NULL,
178 &xpdd->interface_name);
180 if (!NT_SUCCESS(status))
181 {
182 KdPrint((__DRIVER_NAME " IoRegisterDeviceInterface failed with status 0x%08x\n", status));
183 }
184 else
185 {
186 KdPrint((__DRIVER_NAME " IoRegisterDeviceInterface succeeded - %wZ\n", &xpdd->interface_name));
187 }
189 fdo->Flags &= ~DO_DEVICE_INITIALIZING;
191 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
192 return status;
193 }
195 NTSTATUS
196 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
197 {
198 NTSTATUS status = STATUS_SUCCESS;
200 UNREFERENCED_PARAMETER(RegistryPath);
202 KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
204 //InitializeListHead(&ShutdownMsgList);
205 //KeInitializeSpinLock(&ShutdownMsgLock);
207 DriverObject->DriverExtension->AddDevice = XenPci_AddDevice;
208 DriverObject->MajorFunction[IRP_MJ_PNP] = XenPci_Pnp;
209 DriverObject->MajorFunction[IRP_MJ_POWER] = XenPci_Power;
210 DriverObject->MajorFunction[IRP_MJ_CREATE] = XenPci_Irp_Create;
211 DriverObject->MajorFunction[IRP_MJ_CLOSE] = XenPci_Irp_Close;
212 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = XenPci_Irp_Cleanup;
213 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NULL; //XenPci_Dummy;
214 DriverObject->MajorFunction[IRP_MJ_READ] = XenPci_Irp_Read;
215 DriverObject->MajorFunction[IRP_MJ_WRITE] = NULL; //XenPci_Dummy;
216 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = NULL; //XenPci_Dummy;
218 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
220 return status;
221 }