win-pvdrivers

view xenpci/xenpci.c @ 398:e7292fd9e55a

Fixup xenpci for mingw build with DBG enabled.

add FUNCTION_EXIT_STATUS macro
run unix2dos to fix line endings
update mingw makefiles
use FUNCTION_* macros in xenpci
author Andy Grover <andy.grover@oracle.com>
date Thu Jul 17 10:33:40 2008 -0700 (2008-07-17)
parents a3e81bb18d0b
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 #define INITGUID
21 #include "xenpci.h"
22 #include <stdlib.h>
24 #define SYSRQ_PATH "control/sysrq"
25 #define SHUTDOWN_PATH "control/shutdown"
26 #define BALLOON_PATH "memory/target"
28 #ifdef ALLOC_PRAGMA
29 DRIVER_INITIALIZE DriverEntry;
30 #pragma alloc_text (INIT, DriverEntry)
31 #endif
33 #pragma warning(disable : 4200) // zero-sized array
35 static DDKAPI NTSTATUS
36 XenPci_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
37 {
38 NTSTATUS status;
39 PXENPCI_COMMON common = device_object->DeviceExtension;
41 if (common->lower_do)
42 status = XenPci_Pnp_Fdo(device_object, irp);
43 else
44 status = XenPci_Pnp_Pdo(device_object, irp);
46 return status;
47 }
49 static DDKAPI NTSTATUS
50 XenPci_Power(PDEVICE_OBJECT device_object, PIRP irp)
51 {
52 NTSTATUS status;
53 PXENPCI_COMMON common = device_object->DeviceExtension;
55 if (common->lower_do)
56 status = XenPci_Power_Fdo(device_object, irp);
57 else
58 status = XenPci_Power_Pdo(device_object, irp);
60 return status;
61 }
63 static DDKAPI NTSTATUS
64 XenPci_Irp_Create(PDEVICE_OBJECT device_object, PIRP irp)
65 {
66 NTSTATUS status;
67 PXENPCI_COMMON common = device_object->DeviceExtension;
69 if (common->lower_do)
70 status = XenPci_Irp_Create_Fdo(device_object, irp);
71 else
72 status = XenPci_Irp_Create_Pdo(device_object, irp);
74 return status;
75 }
77 static DDKAPI NTSTATUS
78 XenPci_Irp_Close(PDEVICE_OBJECT device_object, PIRP irp)
79 {
80 NTSTATUS status;
81 PXENPCI_COMMON common = device_object->DeviceExtension;
83 if (common->lower_do)
84 status = XenPci_Irp_Close_Fdo(device_object, irp);
85 else
86 status = XenPci_Irp_Close_Pdo(device_object, irp);
88 return status;
89 }
91 static DDKAPI NTSTATUS
92 XenPci_Irp_Read(PDEVICE_OBJECT device_object, PIRP irp)
93 {
94 NTSTATUS status;
95 PXENPCI_COMMON common = device_object->DeviceExtension;
97 if (common->lower_do)
98 status = XenPci_Irp_Read_Fdo(device_object, irp);
99 else
100 status = XenPci_Irp_Read_Pdo(device_object, irp);
102 return status;
103 }
105 static DDKAPI NTSTATUS
106 XenPci_Irp_Cleanup(PDEVICE_OBJECT device_object, PIRP irp)
107 {
108 NTSTATUS status;
109 PXENPCI_COMMON common = device_object->DeviceExtension;
111 if (common->lower_do)
112 status = XenPci_Irp_Cleanup_Fdo(device_object, irp);
113 else
114 status = XenPci_Irp_Cleanup_Pdo(device_object, irp);
116 return status;
117 }
119 static DDKAPI NTSTATUS
120 XenPci_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
121 {
122 NTSTATUS status;
123 PDEVICE_OBJECT fdo = NULL;
124 // PNP_BUS_INFORMATION busInfo;
125 // DECLARE_CONST_UNICODE_STRING(DeviceName, L"\\Device\\XenShutdown");
126 // DECLARE_CONST_UNICODE_STRING(SymbolicName, L"\\DosDevices\\XenShutdown");
127 // WDFDEVICE Device;
128 PXENPCI_DEVICE_DATA xpdd;
129 //PWSTR InterfaceList;
131 FUNCTION_ENTER();
133 status = IoCreateDevice(DriverObject,
134 sizeof(XENPCI_DEVICE_DATA),
135 NULL,
136 FILE_DEVICE_BUS_EXTENDER,
137 FILE_DEVICE_SECURE_OPEN,
138 FALSE,
139 &fdo);
141 if (!NT_SUCCESS(status))
142 {
143 KdPrint((__DRIVER_NAME " IoCreateDevice failed 0x%08x\n", status));
144 return status;
145 }
147 fdo->Flags |= DO_BUFFERED_IO;
149 xpdd = (PXENPCI_DEVICE_DATA)fdo->DeviceExtension;
151 RtlZeroMemory(xpdd, sizeof(XENPCI_DEVICE_DATA));
153 xpdd->shutdown_prod = 0;
154 xpdd->shutdown_cons = 0;
155 KeInitializeSpinLock(&xpdd->shutdown_ring_lock);
157 xpdd->common.fdo = fdo;
158 xpdd->common.pdo = PhysicalDeviceObject;
159 xpdd->common.lower_do = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
160 if(xpdd->common.lower_do == NULL) {
161 IoDeleteDevice(fdo);
162 return STATUS_NO_SUCH_DEVICE;
163 }
164 INIT_PNP_STATE(&xpdd->common);
165 xpdd->common.device_usage_paging = 0;
166 xpdd->common.device_usage_dump = 0;
167 xpdd->common.device_usage_hibernation = 0;
169 InitializeListHead(&xpdd->child_list);
171 status = IoRegisterDeviceInterface(
172 PhysicalDeviceObject,
173 &GUID_XEN_IFACE,
174 NULL,
175 &xpdd->interface_name);
177 if (!NT_SUCCESS(status))
178 {
179 KdPrint((__DRIVER_NAME " IoRegisterDeviceInterface failed with status 0x%08x\n", status));
180 }
181 else
182 {
183 KdPrint((__DRIVER_NAME " IoRegisterDeviceInterface succeeded - %wZ\n", &xpdd->interface_name));
184 }
186 fdo->Flags &= ~DO_DEVICE_INITIALIZING;
188 FUNCTION_EXIT();
189 return status;
190 }
192 NTSTATUS DDKAPI
193 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
194 {
195 NTSTATUS status = STATUS_SUCCESS;
197 UNREFERENCED_PARAMETER(RegistryPath);
199 FUNCTION_ENTER();
201 //InitializeListHead(&ShutdownMsgList);
202 //KeInitializeSpinLock(&ShutdownMsgLock);
204 DriverObject->DriverExtension->AddDevice = XenPci_AddDevice;
205 DriverObject->MajorFunction[IRP_MJ_PNP] = XenPci_Pnp;
206 DriverObject->MajorFunction[IRP_MJ_POWER] = XenPci_Power;
207 DriverObject->MajorFunction[IRP_MJ_CREATE] = XenPci_Irp_Create;
208 DriverObject->MajorFunction[IRP_MJ_CLOSE] = XenPci_Irp_Close;
209 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = XenPci_Irp_Cleanup;
210 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NULL; //XenPci_Dummy;
211 DriverObject->MajorFunction[IRP_MJ_READ] = XenPci_Irp_Read;
212 DriverObject->MajorFunction[IRP_MJ_WRITE] = NULL; //XenPci_Dummy;
213 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = NULL; //XenPci_Dummy;
215 FUNCTION_EXIT();
217 return status;
218 }