win-pvdrivers

changeset 63:d458fc4371b9

Adding even more missing files
author James Harper <james.harper@bendigoit.com.au>
date Wed Dec 19 14:27:43 2007 +1100 (2007-12-19)
parents edd4a2ad5b44
children ed27484c3ab8 be0e5f13ec5f
files xenaddresource/makefile xenaddresource/makefile.inc xenaddresource/sources xenaddresource/xenaddresource.c xenaddresource/xenaddresource.h
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xenaddresource/makefile	Wed Dec 19 14:27:43 2007 +1100
     1.3 @@ -0,0 +1,1 @@
     1.4 +!INCLUDE $(NTMAKEENV)\makefile.def
     1.5 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/xenaddresource/makefile.inc	Wed Dec 19 14:27:43 2007 +1100
     2.3 @@ -0,0 +1,6 @@
     2.4 +#_LNG=$(LANGUAGE)
     2.5 +#STAMP=stampinf -f $@ -a $(_BUILDARCH) -d * -v $(VERSION)
     2.6 +#
     2.7 +#..\Target\$(DDK_TARGET_OS)\$(INF_NAME).inf: $(INF_NAME).inx sources
     2.8 +#    copy $(@B).inx $@
     2.9 +#    $(STAMP)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/xenaddresource/sources	Wed Dec 19 14:27:43 2007 +1100
     3.3 @@ -0,0 +1,12 @@
     3.4 +TARGETNAME=XENADDRESOURCE
     3.5 +TARGETTYPE=DRIVER
     3.6 +TARGETPATH=..\Target\$(DDK_TARGET_OS)
     3.7 +VERSION=0.4.0.0
     3.8 +KMDF_VERSION=1
     3.9 +MSC_WARNING_LEVEL=/W4
    3.10 +#INF_NAME=xenaddresource
    3.11 +INCLUDES = ..\common\include;..\common\include\public
    3.12 +TARGETLIBS=$(DDK_LIB_PATH)\ntstrsafe.lib
    3.13 +#MISCFILES=$(TARGETPATH)\$(INF_NAME).inf
    3.14 +#NTTARGETFILES=
    3.15 +SOURCES=xenaddresource.c
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/xenaddresource/xenaddresource.c	Wed Dec 19 14:27:43 2007 +1100
     4.3 @@ -0,0 +1,228 @@
     4.4 +/*
     4.5 +PV Drivers for Windows Xen HVM Domains
     4.6 +Copyright (C) 2007 James Harper
     4.7 +
     4.8 +This program is free software; you can redistribute it and/or
     4.9 +modify it under the terms of the GNU General Public License
    4.10 +as published by the Free Software Foundation; either version 2
    4.11 +of the License, or (at your option) any later version.
    4.12 +
    4.13 +This program is distributed in the hope that it will be useful,
    4.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.16 +GNU General Public License for more details.
    4.17 +
    4.18 +You should have received a copy of the GNU General Public License
    4.19 +along with this program; if not, write to the Free Software
    4.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    4.21 +*/
    4.22 +
    4.23 +#include "xenaddresource.h"
    4.24 +#include <stdlib.h>
    4.25 +
    4.26 +DRIVER_INITIALIZE DriverEntry;
    4.27 +static NTSTATUS
    4.28 +XenAddResource_AddDevice(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit);
    4.29 +static NTSTATUS
    4.30 +XenAddResource_PreprocessWdmIrpPNP(WDFDEVICE Device, PIRP Irp);
    4.31 +//static VOID
    4.32 +//XenAddResource_IoInternalDeviceControl(WDFQUEUE Queue, WDFREQUEST Request, size_t OutputBufferLength, size_t InputBufferLength, ULONG IoControlCode);
    4.33 +static NTSTATUS
    4.34 +XenAddResource_EvtDeviceFilterAddResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST IoResourceRequirementsList);
    4.35 +
    4.36 +#ifdef ALLOC_PRAGMA
    4.37 +#pragma alloc_text (INIT, DriverEntry)
    4.38 +#pragma alloc_text (PAGE, XenAddResource_AddDevice)
    4.39 +#endif
    4.40 +
    4.41 +static BOOLEAN AutoEnumerate;
    4.42 +
    4.43 +static WDFDEVICE Device;
    4.44 +
    4.45 +NTSTATUS
    4.46 +DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    4.47 +{
    4.48 +  WDF_DRIVER_CONFIG config;
    4.49 +  NTSTATUS status;
    4.50 +
    4.51 +  KdPrint((__DRIVER_NAME " --> DriverEntry\n"));
    4.52 +
    4.53 +  WDF_DRIVER_CONFIG_INIT(&config, XenAddResource_AddDevice);
    4.54 +  status = WdfDriverCreate(
    4.55 +                      DriverObject,
    4.56 +                      RegistryPath,
    4.57 +                      WDF_NO_OBJECT_ATTRIBUTES,
    4.58 +                      &config,
    4.59 +                      WDF_NO_HANDLE);
    4.60 +  if(!NT_SUCCESS(status))
    4.61 +  {
    4.62 +    KdPrint((__DRIVER_NAME " WdfDriverCreate failed with status 0x%08x\n", status));
    4.63 +  }
    4.64 +
    4.65 +  KdPrint((__DRIVER_NAME " <-- DriverEntry\n"));
    4.66 +
    4.67 +  return status;
    4.68 +}
    4.69 +
    4.70 +static NTSTATUS
    4.71 +XenAddResource_AddDevice(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit)
    4.72 +{
    4.73 +  NTSTATUS Status;
    4.74 +  WDF_OBJECT_ATTRIBUTES attributes;
    4.75 +  UCHAR PnpMinors[2] = { IRP_MN_START_DEVICE, IRP_MN_STOP_DEVICE };
    4.76 +
    4.77 +  UNREFERENCED_PARAMETER(Driver);
    4.78 +
    4.79 +  KdPrint((__DRIVER_NAME " --> DeviceAdd\n"));
    4.80 +
    4.81 +  WdfFdoInitSetFilter(DeviceInit);
    4.82 +
    4.83 +  Status = WdfDeviceInitAssignWdmIrpPreprocessCallback(DeviceInit, XenAddResource_PreprocessWdmIrpPNP, IRP_MJ_PNP, PnpMinors, 2);
    4.84 +  if (!NT_SUCCESS(Status))
    4.85 +    KdPrint((__DRIVER_NAME "     WdfDeviceInitAssignWdmIrpPreprocessCallback(IRP_MJ_PNP) Status = %08X\n", Status));
    4.86 +
    4.87 +  WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
    4.88 +  Status = WdfDeviceCreate(&DeviceInit, &attributes, &Device);  
    4.89 +  if(!NT_SUCCESS(Status))
    4.90 +  {
    4.91 +    KdPrint((__DRIVER_NAME "     WdfDeviceCreate failed with status 0x%08x)\n", Status));
    4.92 +    return Status;
    4.93 +  }
    4.94 +
    4.95 +  KdPrint((__DRIVER_NAME " <-- DeviceAdd\n"));
    4.96 +
    4.97 +  return Status;
    4.98 +}
    4.99 +
   4.100 +static NTSTATUS
   4.101 +XenAddResource_PreprocessWdmIrpPNP(WDFDEVICE Device, PIRP Irp)
   4.102 +{
   4.103 +  NTSTATUS Status = STATUS_SUCCESS;
   4.104 +  PIO_STACK_LOCATION Stack;
   4.105 +  PXENPCI_XEN_DEVICE_DATA XenDeviceData;
   4.106 +  //PXENADDRESOURCE_DEVICE_DATA XenAddResourcesDeviceData;
   4.107 +
   4.108 +  KdPrint((__DRIVER_NAME " --> WdmIrpPreprocessPNP\n"));
   4.109 +
   4.110 +  Stack = IoGetCurrentIrpStackLocation(Irp);
   4.111 +
   4.112 +  switch (Stack->MinorFunction) {
   4.113 +  case IRP_MN_START_DEVICE:
   4.114 +    KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE\n"));
   4.115 +
   4.116 +    if (Stack->Parameters.StartDevice.AllocatedResources != NULL)
   4.117 +    {
   4.118 +      // free stuff here... or maybe just exit
   4.119 +    }
   4.120 +    if (Stack->Parameters.StartDevice.AllocatedResourcesTranslated != NULL)
   4.121 +    {
   4.122 +      // free stuff here... or maybe just exit
   4.123 +    }
   4.124 +
   4.125 +    XenDeviceData = WdfDeviceWdmGetPhysicalDevice(Device)->DeviceExtension;
   4.126 +    // verify Magic here
   4.127 +
   4.128 +    Stack->Parameters.StartDevice.AllocatedResources = ExAllocatePoolWithTag(NonPagedPool, sizeof(CM_RESOURCE_LIST) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1, XENADDRESOURCE_POOL_TAG);
   4.129 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated = ExAllocatePoolWithTag(NonPagedPool, sizeof(CM_RESOURCE_LIST) + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1, XENADDRESOURCE_POOL_TAG);
   4.130 +
   4.131 +    Stack->Parameters.StartDevice.AllocatedResources->Count = 1;
   4.132 +    Stack->Parameters.StartDevice.AllocatedResources->List[0].InterfaceType = Internal;
   4.133 +    Stack->Parameters.StartDevice.AllocatedResources->List[0].BusNumber = 0;
   4.134 +    Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.Version = 1;
   4.135 +    Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.Revision = 1;
   4.136 +    Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.Count = 2;
   4.137 +    Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].Type = CmResourceTypeMemory;
   4.138 +    Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareDeviceExclusive;
   4.139 +    Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].Flags = CM_RESOURCE_MEMORY_READ_WRITE;
   4.140 +    Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Memory.Start.QuadPart = (ULONGLONG)XenDeviceData;
   4.141 +    Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Memory.Length = sizeof(XENPCI_XEN_DEVICE_DATA);
   4.142 +    memcpy(&Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1], &XenDeviceData->InterruptRaw, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
   4.143 +
   4.144 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->Count = 1;
   4.145 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].InterfaceType = Internal;
   4.146 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].BusNumber = 0;
   4.147 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.Version = 1;
   4.148 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.Revision = 1;
   4.149 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.Count = 2;
   4.150 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[0].Type = CmResourceTypeMemory;
   4.151 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareDeviceExclusive;
   4.152 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[0].Flags = CM_RESOURCE_MEMORY_READ_WRITE;
   4.153 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[0].u.Memory.Start.QuadPart = (ULONGLONG)XenDeviceData;
   4.154 +    Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[0].u.Memory.Length = sizeof(XENPCI_XEN_DEVICE_DATA);
   4.155 +    memcpy(&Stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[1], &XenDeviceData->InterruptTranslated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
   4.156 +
   4.157 +//    KdPrint((__DRIVER_NAME "     AllocatedResources[0].Count = %d\n", Stack->Parameters.StartDevice.AllocatedResources->Count));
   4.158 +//    KdPrint((__DRIVER_NAME "     AllocatedResources[0].List.PartialResourceList.Count = %d\n", Stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList.Count));
   4.159 +
   4.160 +    IoSkipCurrentIrpStackLocation(Irp);
   4.161 +    Status = WdfDeviceWdmDispatchPreprocessedIrp(Device, Irp);
   4.162 +    break;
   4.163 +  default:
   4.164 +    IoSkipCurrentIrpStackLocation(Irp);
   4.165 +    Status = WdfDeviceWdmDispatchPreprocessedIrp(Device, Irp);
   4.166 +    KdPrint((__DRIVER_NAME "     Unknown Minor %d\n", Stack->MinorFunction));
   4.167 +    break;
   4.168 +  }
   4.169 +
   4.170 +  KdPrint((__DRIVER_NAME " <-- WdmIrpPreprocessPNP (returning with status %08x\n", Status));
   4.171 +
   4.172 +  return Status;
   4.173 +}
   4.174 +
   4.175 +/*
   4.176 +static NTSTATUS
   4.177 +XenAddResource_EvtDeviceFilterAddResourceRequirements(WDFDEVICE Device, WDFIORESREQLIST IoResourceRequirementsList)
   4.178 +{
   4.179 +  NTSTATUS Status = STATUS_SUCCESS;
   4.180 +  WDFIORESLIST resourceList;
   4.181 +  IO_RESOURCE_DESCRIPTOR descriptor;
   4.182 +
   4.183 +  UNREFERENCED_PARAMETER(Device);
   4.184 +
   4.185 +  KdPrint((__DRIVER_NAME " --> DeviceResourceRequirementsQuery\n"));
   4.186 +
   4.187 +  Status = WdfIoResourceListCreate(IoResourceRequirementsList, WDF_NO_OBJECT_ATTRIBUTES, &resourceList);
   4.188 +  if (!NT_SUCCESS(Status))
   4.189 +    return Status;
   4.190 +
   4.191 +  RtlZeroMemory(&descriptor, sizeof(descriptor));
   4.192 +
   4.193 +  descriptor.Type = CmResourceTypeMemory;
   4.194 +  descriptor.ShareDisposition = CmResourceShareDeviceExclusive;
   4.195 +  descriptor.Flags = CM_RESOURCE_MEMORY_READ_WRITE;
   4.196 +  descriptor.u.Memory.Length = 0; //PAGE_SIZE;
   4.197 +  descriptor.u.Memory.Alignment = PAGE_SIZE;
   4.198 +  descriptor.u.Memory.MinimumAddress.QuadPart = 0x0000000000000000;
   4.199 +  descriptor.u.Memory.MaximumAddress.QuadPart = 0xFFFFFFFFFFFFFFFF;
   4.200 +
   4.201 +  KdPrint((__DRIVER_NAME "     MinimumAddress = %08x, MaximumAddress = %08x\n", descriptor.u.Memory.MinimumAddress.LowPart, descriptor.u.Memory.MaximumAddress.LowPart));
   4.202 +
   4.203 +  Status = WdfIoResourceListAppendDescriptor(resourceList, &descriptor);
   4.204 +  if (!NT_SUCCESS(Status))
   4.205 +    return Status;
   4.206 +
   4.207 +  RtlZeroMemory(&descriptor, sizeof(descriptor));
   4.208 +
   4.209 +  descriptor.Type = CmResourceTypeInterrupt;
   4.210 +  descriptor.ShareDisposition = CmResourceShareDeviceExclusive;
   4.211 +  descriptor.Flags = CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE;
   4.212 +  descriptor.u.Interrupt.MinimumVector = 16;
   4.213 +  descriptor.u.Interrupt.MaximumVector = 46;
   4.214 +
   4.215 +  KdPrint((__DRIVER_NAME "     MinimumVector = %d, MaximumVector = %d\n", descriptor.u.Interrupt.MinimumVector, descriptor.u.Interrupt.MaximumVector));
   4.216 +
   4.217 +  Status = WdfIoResourceListAppendDescriptor(resourceList, &descriptor);
   4.218 +  if (!NT_SUCCESS(Status))
   4.219 +    return Status;
   4.220 +
   4.221 +  Status = WdfIoResourceRequirementsListAppendIoResList(IoResourceRequirementsList, resourceList);
   4.222 +  if (!NT_SUCCESS(Status))
   4.223 +  {
   4.224 +    return Status;
   4.225 +  }
   4.226 +
   4.227 +  KdPrint((__DRIVER_NAME " <-- DeviceFilterAddResourceRequirements\n"));
   4.228 +
   4.229 +  return Status;
   4.230 +}
   4.231 +*/
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/xenaddresource/xenaddresource.h	Wed Dec 19 14:27:43 2007 +1100
     5.3 @@ -0,0 +1,75 @@
     5.4 +/*
     5.5 +PV Drivers for Windows Xen HVM Domains
     5.6 +Copyright (C) 2007 James Harper
     5.7 +
     5.8 +This program is free software; you can redistribute it and/or
     5.9 +modify it under the terms of the GNU General Public License
    5.10 +as published by the Free Software Foundation; either version 2
    5.11 +of the License, or (at your option) any later version.
    5.12 +
    5.13 +This program is distributed in the hope that it will be useful,
    5.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.16 +GNU General Public License for more details.
    5.17 +
    5.18 +You should have received a copy of the GNU General Public License
    5.19 +along with this program; if not, write to the Free Software
    5.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    5.21 +*/
    5.22 +
    5.23 +#if !defined(_XENADDRESOURCE_H_)
    5.24 +#define _XENADDRESOURCE_H_
    5.25 +
    5.26 +#define __attribute__(arg) /* empty */
    5.27 +
    5.28 +#include <ntddk.h>
    5.29 +#include <wdm.h>
    5.30 +#include <wdf.h>
    5.31 +#include <initguid.h>
    5.32 +#include <wdmguid.h>
    5.33 +#include <errno.h>
    5.34 +
    5.35 +#define NTSTRSAFE_LIB
    5.36 +#include <ntstrsafe.h>
    5.37 +
    5.38 +#include <xen_windows.h>
    5.39 +
    5.40 +#include <memory.h>
    5.41 +#include <grant_table.h>
    5.42 +#include <event_channel.h>
    5.43 +#include <hvm/params.h>
    5.44 +#include <hvm/hvm_op.h>
    5.45 +#include <evtchn_public.h>
    5.46 +#include <xenbus_public.h>
    5.47 +#include <xen_public.h>
    5.48 +#include <gnttbl_public.h>
    5.49 +
    5.50 +#define __DRIVER_NAME "XenAddResource"
    5.51 +#define XENADDRESOURCE_POOL_TAG (ULONG) 'XenR'
    5.52 +
    5.53 +#define NR_RESERVED_ENTRIES 8
    5.54 +#define NR_GRANT_FRAMES 4
    5.55 +#define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
    5.56 +
    5.57 +//#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
    5.58 +
    5.59 +#define ADDRESOURCE_DATA_MAGIC 0x12345678
    5.60 +
    5.61 +/*
    5.62 +typedef struct {
    5.63 +  ULONG Magic;
    5.64 +  PXENPCI_XEN_DEVICE_DATA XenDeviceData;
    5.65 +  XEN_IFACE_EVTCHN EvtChnInterface;
    5.66 +  XEN_IFACE_XENBUS XenBusInterface;
    5.67 +  //XEN_IFACE_XEN XenInterface;
    5.68 +  XEN_IFACE_GNTTBL GntTblInterface;
    5.69 +} XENADDRESOURCE_DEVICE_DATA, *PXENADDRESOURCE_DEVICE_DATA;
    5.70 +*/
    5.71 +/*
    5.72 +typedef unsigned long xenbus_transaction_t;
    5.73 +typedef uint32_t XENSTORE_RING_IDX;
    5.74 +
    5.75 +#define XBT_NIL ((xenbus_transaction_t)0)
    5.76 +*/
    5.77 +
    5.78 +#endif