win-pvdrivers

view xenpci/xenpci.c @ 324:39e1a87d9189

get rid of unneeded (?) stuff that gcc complains about
Add DDKAPI to dispatch routines. These resolve to __stdcall on MinGW, which apparently it needs.
author Andy Grover <andy.grover@oracle.com>
date Thu Jun 19 15:22:00 2008 -0700 (2008-06-19)
parents 873944504204
children 2705232c28d9
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 #pragma alloc_text (INIT, DriverEntry)
29 #endif
31 #pragma warning(disable : 4200) // zero-sized array
33 #ifndef __MINGW32__
34 #define DDKAPI
35 #endif
37 static DDKAPI NTSTATUS
38 XenPci_Pnp(PDEVICE_OBJECT device_object, PIRP irp)
39 {
40 NTSTATUS status;
41 PXENPCI_COMMON common = device_object->DeviceExtension;
43 if (common->lower_do)
44 status = XenPci_Pnp_Fdo(device_object, irp);
45 else
46 status = XenPci_Pnp_Pdo(device_object, irp);
48 return status;
49 }
51 static DDKAPI NTSTATUS
52 XenPci_Power(PDEVICE_OBJECT device_object, PIRP irp)
53 {
54 NTSTATUS status;
55 PXENPCI_COMMON common = device_object->DeviceExtension;
57 if (common->lower_do)
58 status = XenPci_Power_Fdo(device_object, irp);
59 else
60 status = XenPci_Power_Pdo(device_object, irp);
62 return status;
63 }
65 static DDKAPI NTSTATUS
66 XenPci_Irp_Create(PDEVICE_OBJECT device_object, PIRP irp)
67 {
68 NTSTATUS status;
69 PXENPCI_COMMON common = device_object->DeviceExtension;
71 if (common->lower_do)
72 status = XenPci_Irp_Create_Fdo(device_object, irp);
73 else
74 status = XenPci_Irp_Create_Pdo(device_object, irp);
76 return status;
77 }
79 static DDKAPI NTSTATUS
80 XenPci_Irp_Close(PDEVICE_OBJECT device_object, PIRP irp)
81 {
82 NTSTATUS status;
83 PXENPCI_COMMON common = device_object->DeviceExtension;
85 if (common->lower_do)
86 status = XenPci_Irp_Close_Fdo(device_object, irp);
87 else
88 status = XenPci_Irp_Close_Pdo(device_object, irp);
90 return status;
91 }
93 static DDKAPI NTSTATUS
94 XenPci_Irp_Read(PDEVICE_OBJECT device_object, PIRP irp)
95 {
96 NTSTATUS status;
97 PXENPCI_COMMON common = device_object->DeviceExtension;
99 if (common->lower_do)
100 status = XenPci_Irp_Read_Fdo(device_object, irp);
101 else
102 status = XenPci_Irp_Read_Pdo(device_object, irp);
104 return status;
105 }
107 static DDKAPI NTSTATUS
108 XenPci_Irp_Cleanup(PDEVICE_OBJECT device_object, PIRP irp)
109 {
110 NTSTATUS status;
111 PXENPCI_COMMON common = device_object->DeviceExtension;
113 if (common->lower_do)
114 status = XenPci_Irp_Cleanup_Fdo(device_object, irp);
115 else
116 status = XenPci_Irp_Cleanup_Pdo(device_object, irp);
118 return status;
119 }
121 static DDKAPI NTSTATUS
122 XenPci_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
123 {
124 NTSTATUS status;
125 PDEVICE_OBJECT fdo = NULL;
126 // PNP_BUS_INFORMATION busInfo;
127 // DECLARE_CONST_UNICODE_STRING(DeviceName, L"\\Device\\XenShutdown");
128 // DECLARE_CONST_UNICODE_STRING(SymbolicName, L"\\DosDevices\\XenShutdown");
129 // WDFDEVICE Device;
130 PXENPCI_DEVICE_DATA xpdd;
131 //PWSTR InterfaceList;
133 KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
135 status = IoCreateDevice(DriverObject,
136 sizeof(XENPCI_DEVICE_DATA),
137 NULL,
138 FILE_DEVICE_BUS_EXTENDER,
139 FILE_DEVICE_SECURE_OPEN,
140 FALSE,
141 &fdo);
143 if (!NT_SUCCESS(status))
144 {
145 KdPrint((__DRIVER_NAME " IoCreateDevice failed 0x%08x\n", status));
146 return status;
147 }
149 fdo->Flags |= DO_BUFFERED_IO;
151 xpdd = (PXENPCI_DEVICE_DATA)fdo->DeviceExtension;
153 RtlZeroMemory(xpdd, sizeof(XENPCI_DEVICE_DATA));
155 xpdd->shutdown_prod = 0;
156 xpdd->shutdown_cons = 0;
157 KeInitializeSpinLock(&xpdd->shutdown_ring_lock);
159 xpdd->common.fdo = fdo;
160 xpdd->common.pdo = PhysicalDeviceObject;
161 xpdd->common.lower_do = IoAttachDeviceToDeviceStack(fdo, PhysicalDeviceObject);
162 if(xpdd->common.lower_do == NULL) {
163 IoDeleteDevice(fdo);
164 return STATUS_NO_SUCH_DEVICE;
165 }
166 INIT_PNP_STATE(&xpdd->common);
167 xpdd->common.device_usage_paging = 0;
168 xpdd->common.device_usage_dump = 0;
169 xpdd->common.device_usage_hibernation = 0;
171 InitializeListHead(&xpdd->child_list);
173 status = IoRegisterDeviceInterface(
174 PhysicalDeviceObject,
175 (LPGUID)&GUID_XEN_IFACE,
176 NULL,
177 &xpdd->interface_name);
179 if (!NT_SUCCESS(status))
180 {
181 KdPrint((__DRIVER_NAME " IoRegisterDeviceInterface failed with status 0x%08x\n", status));
182 }
183 else
184 {
185 KdPrint((__DRIVER_NAME " IoRegisterDeviceInterface succeeded - %wZ\n", &xpdd->interface_name));
186 }
188 fdo->Flags &= ~DO_DEVICE_INITIALIZING;
190 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
191 return status;
192 }
194 NTSTATUS
195 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
196 {
197 NTSTATUS status = STATUS_SUCCESS;
199 UNREFERENCED_PARAMETER(RegistryPath);
201 KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
203 //InitializeListHead(&ShutdownMsgList);
204 //KeInitializeSpinLock(&ShutdownMsgLock);
206 DriverObject->DriverExtension->AddDevice = XenPci_AddDevice;
207 DriverObject->MajorFunction[IRP_MJ_PNP] = XenPci_Pnp;
208 DriverObject->MajorFunction[IRP_MJ_POWER] = XenPci_Power;
209 DriverObject->MajorFunction[IRP_MJ_CREATE] = XenPci_Irp_Create;
210 DriverObject->MajorFunction[IRP_MJ_CLOSE] = XenPci_Irp_Close;
211 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = XenPci_Irp_Cleanup;
212 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NULL; //XenPci_Dummy;
213 DriverObject->MajorFunction[IRP_MJ_READ] = XenPci_Irp_Read;
214 DriverObject->MajorFunction[IRP_MJ_WRITE] = NULL; //XenPci_Dummy;
215 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = NULL; //XenPci_Dummy;
217 KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
219 return status;
220 }