]> xenbits.xensource.com Git - people/pauldu/xenbus.git/commitdiff
Get XENVIF up and running.
authorPaul Durrant <paul.durrant@citrix.com>
Thu, 29 Aug 2013 08:26:43 +0000 (09:26 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Thu, 29 Aug 2013 08:26:43 +0000 (09:26 +0100)
Create a new stub EMULATED interface and make some other tweaks to get
XENVIF to come up and enumerate child devices.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
18 files changed:
include/emulated_interface.h [new file with mode: 0644]
include/util.h [new file with mode: 0644]
proj/xenfilt/xenfilt.vcxproj
src/common/util.h [deleted file]
src/xen/xen.rc
src/xenbus.inf
src/xenbus/bus.c
src/xenbus/dma.c
src/xenbus/driver.c
src/xenbus/fdo.c
src/xenbus/fdo.h
src/xenbus/pdo.c
src/xenbus/pdo.h
src/xenbus/xenbus.rc
src/xenfilt/driver.c
src/xenfilt/emulated.c [new file with mode: 0644]
src/xenfilt/emulated.h [new file with mode: 0644]
src/xenfilt/xenfilt.rc

diff --git a/include/emulated_interface.h b/include/emulated_interface.h
new file mode 100644 (file)
index 0000000..ec25019
--- /dev/null
@@ -0,0 +1,105 @@
+/* Copyright (c) Citrix Systems Inc.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, 
+ * with or without modification, are permitted provided 
+ * that the following conditions are met:
+ * 
+ * *   Redistributions of source code must retain the above 
+ *     copyright notice, this list of conditions and the 
+ *     following disclaimer.
+ * *   Redistributions in binary form must reproduce the above 
+ *     copyright notice, this list of conditions and the 
+ *     following disclaimer in the documentation and/or other 
+ *     materials provided with the distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+ * SUCH DAMAGE.
+ */
+
+#ifndef _XENFILT_EMULATED_INTERFACE_H
+#define _XENFILT_EMULATED_INTERFACE_H
+
+#define DEFINE_EMULATED_OPERATIONS                                      \
+        EMULATED_OPERATION(VOID,                                        \
+                           Acquire,                                     \
+                           (                                            \
+                           IN  PXENFILT_EMULATED_CONTEXT Context        \
+                           )                                            \
+                           )                                            \
+        EMULATED_OPERATION(VOID,                                        \
+                           Release,                                     \
+                           (                                            \
+                           IN  PXENFILT_EMULATED_CONTEXT Context        \
+                           )                                            \
+                           )                                            \
+        EMULATED_OPERATION(BOOLEAN,                                     \
+                           IsDevicePresent,                             \
+                           (                                            \
+                           IN  PXENFILT_EMULATED_CONTEXT Context,       \
+                           IN  PCHAR                     DeviceID,      \
+                           IN  PCHAR                     InstanceID     \
+                           )                                            \
+                           )                                            \
+        EMULATED_OPERATION(BOOLEAN,                                     \
+                           IsDiskPresent,                               \
+                           (                                            \
+                           IN  PXENFILT_EMULATED_CONTEXT Context,       \
+                           IN  ULONG                     Controller,    \
+                           IN  ULONG                     Target,        \
+                           IN  ULONG                     Lun            \
+                           )                                            \
+                           )
+
+typedef struct _XENFILT_EMULATED_CONTEXT    XENFILT_EMULATED_CONTEXT, *PXENFILT_EMULATED_CONTEXT;
+
+#define EMULATED_OPERATION(_Type, _Name, _Arguments) \
+        _Type (*EMULATED_ ## _Name) _Arguments;
+
+typedef struct _XENFILT_EMULATED_OPERATIONS {
+    DEFINE_EMULATED_OPERATIONS
+} XENFILT_EMULATED_OPERATIONS, *PXENFILT_EMULATED_OPERATIONS;
+
+#undef EMULATED_OPERATION
+
+typedef struct _XENFILT_EMULATED_INTERFACE   XENFILT_EMULATED_INTERFACE, *PXENFILT_EMULATED_INTERFACE;
+
+// {062AAC96-2BF8-4A69-AD6B-154CF051E977}
+DEFINE_GUID(GUID_EMULATED_INTERFACE, 
+            0x62aac96,
+            0x2bf8,
+            0x4a69,
+            0xad,
+            0x6b,
+            0x15,
+            0x4c,
+            0xf0,
+            0x51,
+            0xe9,
+            0x77);
+
+#define EMULATED_INTERFACE_VERSION    4
+
+#define EMULATED_OPERATIONS(_Interface) \
+        (PXENFILT_EMULATED_OPERATIONS *)((ULONG_PTR)(_Interface))
+
+#define EMULATED_CONTEXT(_Interface) \
+        (PXENFILT_EMULATED_CONTEXT *)((ULONG_PTR)(_Interface) + sizeof (PVOID))
+
+#define EMULATED(_Operation, _Interface, ...) \
+        (*EMULATED_OPERATIONS(_Interface))->EMULATED_ ## _Operation((*EMULATED_CONTEXT(_Interface)), __VA_ARGS__)
+
+#endif  // _XENFILT_EMULATED_INTERFACE_H
+
diff --git a/include/util.h b/include/util.h
new file mode 100644 (file)
index 0000000..6abad93
--- /dev/null
@@ -0,0 +1,343 @@
+/* Copyright (c) Citrix Systems Inc.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, 
+ * with or without modification, are permitted provided 
+ * that the following conditions are met:
+ * 
+ * *   Redistributions of source code must retain the above 
+ *     copyright notice, this list of conditions and the 
+ *     following disclaimer.
+ * *   Redistributions in binary form must reproduce the above 
+ *     copyright notice, this list of conditions and the 
+ *     following disclaimer in the documentation and/or other 
+ *     materials provided with the distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+ * SUCH DAMAGE.
+ */
+
+#ifndef _UTIL_H
+#define _UTIL_H
+
+#include <ntddk.h>
+
+#include "assert.h"
+
+#define        P2ROUNDUP(_x, _a)   \
+        (-(-(_x) & -(_a)))
+
+static FORCEINLINE LONG
+__ffs(
+    IN  unsigned long long  mask
+    )
+{
+    unsigned char           *array = (unsigned char *)&mask;
+    unsigned int            byte;
+    unsigned int            bit;
+    unsigned char           val;
+
+    val = 0;
+
+    byte = 0;
+    while (byte < 8) {
+        val = array[byte];
+
+        if (val != 0)
+            break;
+
+        byte++;
+    }
+    if (byte == 8)
+        return -1;
+
+    bit = 0;
+    while (bit < 8) {
+        if (val & 0x01)
+            break;
+
+        val >>= 1;
+        bit++;
+    }
+
+    return (byte * 8) + bit;
+}
+
+#define __ffu(_mask)  \
+        __ffs(~(_mask))
+
+static FORCEINLINE VOID
+__CpuId(
+    IN  ULONG   Leaf,
+    OUT PULONG  EAX OPTIONAL,
+    OUT PULONG  EBX OPTIONAL,
+    OUT PULONG  ECX OPTIONAL,
+    OUT PULONG  EDX OPTIONAL
+    )
+{
+    ULONG       Value[4] = {0};
+
+    __cpuid(Value, Leaf);
+
+    if (EAX)
+        *EAX = Value[0];
+
+    if (EBX)
+        *EBX = Value[1];
+
+    if (ECX)
+        *ECX = Value[2];
+
+    if (EDX)
+        *EDX = Value[3];
+}
+
+static FORCEINLINE LONG
+__InterlockedAdd(
+    IN  LONG    *Value,
+    IN  LONG    Delta
+    )
+{
+    LONG        New;
+    LONG        Old;
+
+    do {
+        Old = *Value;
+        New = Old + Delta;
+    } while (InterlockedCompareExchange(Value, New, Old) != Old);
+
+    return New;
+}
+
+static FORCEINLINE LONG
+__InterlockedSubtract(
+    IN  LONG    *Value,
+    IN  LONG    Delta
+    )
+{
+    LONG        New;
+    LONG        Old;
+
+    do {
+        Old = *Value;
+        New = Old - Delta;
+    } while (InterlockedCompareExchange(Value, New, Old) != Old);
+
+    return New;
+}
+
+typedef struct _NON_PAGED_BUFFER_HEADER {
+    SIZE_T  Length;
+    ULONG   Tag;
+} NON_PAGED_BUFFER_HEADER, *PNON_PAGED_BUFFER_HEADER;
+
+typedef struct _NON_PAGED_BUFFER_TRAILER {
+    ULONG   Tag;
+} NON_PAGED_BUFFER_TRAILER, *PNON_PAGED_BUFFER_TRAILER;
+
+static FORCEINLINE PVOID
+__AllocateNonPagedPoolWithTag(
+    IN  SIZE_T                  Length,
+    IN  ULONG                   Tag
+    )
+{
+    PUCHAR                      Buffer;
+    PNON_PAGED_BUFFER_HEADER    Header;
+    PNON_PAGED_BUFFER_TRAILER   Trailer;
+
+    ASSERT(Length != 0);
+
+    Buffer = ExAllocatePoolWithTag(NonPagedPool,
+                                   sizeof (NON_PAGED_BUFFER_HEADER) +
+                                   Length +
+                                   sizeof (NON_PAGED_BUFFER_TRAILER),
+                                   Tag);
+    if (Buffer == NULL)
+        goto done;
+
+    RtlZeroMemory(Buffer, 
+                  sizeof (NON_PAGED_BUFFER_HEADER) +
+                  Length +
+                  sizeof (NON_PAGED_BUFFER_TRAILER));
+
+    Header = (PNON_PAGED_BUFFER_HEADER)Buffer;
+    Header->Length = Length;
+    Header->Tag = Tag;
+
+    Buffer += sizeof (NON_PAGED_BUFFER_HEADER);
+
+    Trailer = (PNON_PAGED_BUFFER_TRAILER)(Buffer + Length);
+    Trailer->Tag = Tag;
+
+done:
+    return Buffer;
+}
+
+static FORCEINLINE VOID
+__FreePoolWithTag(
+    IN  PVOID                   _Buffer,
+    IN  ULONG                   Tag
+    )
+{
+    PUCHAR                      Buffer = _Buffer;
+    SIZE_T                      Length;
+    PNON_PAGED_BUFFER_HEADER    Header;
+    PNON_PAGED_BUFFER_TRAILER   Trailer;
+
+    ASSERT(Buffer != NULL);
+
+    Buffer -= sizeof (NON_PAGED_BUFFER_HEADER);
+
+    Header = (PNON_PAGED_BUFFER_HEADER)Buffer;
+    ASSERT3U(Tag, ==, Header->Tag);
+    Length = Header->Length;
+
+    Buffer += sizeof (NON_PAGED_BUFFER_HEADER);
+
+    Trailer = (PNON_PAGED_BUFFER_TRAILER)(Buffer + Length);
+    ASSERT3U(Tag, ==, Trailer->Tag);
+
+    Buffer -= sizeof (NON_PAGED_BUFFER_HEADER);
+
+    RtlFillMemory(Buffer, 
+                  sizeof (NON_PAGED_BUFFER_HEADER) +
+                  Length +
+                  sizeof (NON_PAGED_BUFFER_TRAILER),
+                  0xAA);
+
+    ExFreePoolWithTag(Buffer, Tag);
+}
+
+static FORCEINLINE PMDL
+__AllocatePage(
+    VOID
+    )
+{
+    PHYSICAL_ADDRESS    LowAddress;
+    PHYSICAL_ADDRESS    HighAddress;
+    LARGE_INTEGER       SkipBytes;
+    SIZE_T              TotalBytes;
+    PMDL                Mdl;
+    PUCHAR              MdlMappedSystemVa;
+    NTSTATUS            status;
+
+    LowAddress.QuadPart = 0ull;
+    HighAddress.QuadPart = ~0ull;
+    SkipBytes.QuadPart = 0ull;
+    TotalBytes = (SIZE_T)PAGE_SIZE;
+
+    Mdl = MmAllocatePagesForMdlEx(LowAddress,
+                                  HighAddress,
+                                  SkipBytes,
+                                  TotalBytes,
+                                  MmCached,
+                                  0);
+
+    status = STATUS_NO_MEMORY;
+    if (Mdl == NULL)
+        goto fail1;
+
+    ASSERT((Mdl->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA |
+                             MDL_PARTIAL_HAS_BEEN_MAPPED |
+                             MDL_PARTIAL |
+                             MDL_PARENT_MAPPED_SYSTEM_VA |
+                             MDL_SOURCE_IS_NONPAGED_POOL |
+                             MDL_IO_SPACE)) == 0);
+
+    MdlMappedSystemVa = MmMapLockedPagesSpecifyCache(Mdl,
+                                                     KernelMode,
+                                                                            MmCached,   
+                                                                            NULL,
+                                                                            FALSE,
+                                                                            NormalPagePriority);
+
+    status = STATUS_UNSUCCESSFUL;
+    if (MdlMappedSystemVa == NULL)
+        goto fail2;
+
+    ASSERT3P(MdlMappedSystemVa, ==, Mdl->MappedSystemVa);
+
+    RtlZeroMemory(MdlMappedSystemVa, PAGE_SIZE);
+
+    return Mdl;
+
+fail2:
+    Error("fail2\n");
+
+    MmFreePagesFromMdl(Mdl);
+    ExFreePool(Mdl);
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return NULL;
+}
+
+static FORCEINLINE VOID
+__FreePage(
+    IN PMDL    Mdl
+    )
+{
+    PUCHAR     MdlMappedSystemVa;
+
+    ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA);
+    MdlMappedSystemVa = Mdl->MappedSystemVa;
+
+    RtlFillMemory(MdlMappedSystemVa, PAGE_SIZE, 0xAA);
+    
+    MmUnmapLockedPages(MdlMappedSystemVa, Mdl);
+
+    MmFreePagesFromMdl(Mdl);
+}
+
+static FORCEINLINE PWCHAR
+__wcstok_r(
+    IN      PWCHAR  Buffer,
+    IN      PWCHAR  Delimiter,
+    IN OUT  PWCHAR  *Context
+    )
+{
+    PWCHAR          Token;
+    PWCHAR          End;
+
+    if (Buffer != NULL)
+        *Context = Buffer;
+
+    Token = *Context;
+
+    if (Token == NULL)
+        return NULL;
+
+    while (*Token != L'\0' &&
+           wcschr(Delimiter, *Token) != NULL)
+        Token++;
+
+    if (*Token == L'\0')
+        return NULL;
+
+    End = Token + 1;
+    while (*End != L'\0' &&
+           wcschr(Delimiter, *End) == NULL)
+        End++;
+
+    if (*End != L'\0')
+        *End++ = L'\0';
+
+    *Context = End;
+
+    return Token;
+}
+
+#endif  // _UTIL_H
index 1c60d10dc0f545c886744091076cafad2c6ec32d..7cb9131720c293e7d7418cef54ba23e8e3b18e74 100644 (file)
@@ -76,6 +76,7 @@
        <ItemGroup>
                <ClCompile Include="../../src/common/registry.c" />
                <ClCompile Include="../../src/xenfilt/driver.c" />
+               <ClCompile Include="../../src/xenfilt/emulated.c" />
                <ClCompile Include="../../src/xenfilt/fdo.c" />
                <ClCompile Include="../../src/xenfilt/pdo.c" />
                <ClCompile Include="../../src/xenfilt/thread.c" />
diff --git a/src/common/util.h b/src/common/util.h
deleted file mode 100644 (file)
index 4665e36..0000000
+++ /dev/null
@@ -1,343 +0,0 @@
-/* Copyright (c) Citrix Systems Inc.
- * All rights reserved.
- * 
- * Redistribution and use in source and binary forms, 
- * with or without modification, are permitted provided 
- * that the following conditions are met:
- * 
- * *   Redistributions of source code must retain the above 
- *     copyright notice, this list of conditions and the 
- *     following disclaimer.
- * *   Redistributions in binary form must reproduce the above 
- *     copyright notice, this list of conditions and the 
- *     following disclaimer in the documentation and/or other 
- *     materials provided with the distribution.
- * 
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
- * SUCH DAMAGE.
- */
-
-#ifndef _COMMON_UTIL_H
-#define _COMMON_UTIL_H
-
-#include <ntddk.h>
-
-#include "assert.h"
-
-#define        P2ROUNDUP(_x, _a)   \
-        (-(-(_x) & -(_a)))
-
-static FORCEINLINE LONG
-__ffs(
-    IN  unsigned long long  mask
-    )
-{
-    unsigned char           *array = (unsigned char *)&mask;
-    unsigned int            byte;
-    unsigned int            bit;
-    unsigned char           val;
-
-    val = 0;
-
-    byte = 0;
-    while (byte < 8) {
-        val = array[byte];
-
-        if (val != 0)
-            break;
-
-        byte++;
-    }
-    if (byte == 8)
-        return -1;
-
-    bit = 0;
-    while (bit < 8) {
-        if (val & 0x01)
-            break;
-
-        val >>= 1;
-        bit++;
-    }
-
-    return (byte * 8) + bit;
-}
-
-#define __ffu(_mask)  \
-        __ffs(~(_mask))
-
-static FORCEINLINE VOID
-__CpuId(
-    IN  ULONG   Leaf,
-    OUT PULONG  EAX OPTIONAL,
-    OUT PULONG  EBX OPTIONAL,
-    OUT PULONG  ECX OPTIONAL,
-    OUT PULONG  EDX OPTIONAL
-    )
-{
-    ULONG       Value[4] = {0};
-
-    __cpuid(Value, Leaf);
-
-    if (EAX)
-        *EAX = Value[0];
-
-    if (EBX)
-        *EBX = Value[1];
-
-    if (ECX)
-        *ECX = Value[2];
-
-    if (EDX)
-        *EDX = Value[3];
-}
-
-static FORCEINLINE LONG
-__InterlockedAdd(
-    IN  LONG    *Value,
-    IN  LONG    Delta
-    )
-{
-    LONG        New;
-    LONG        Old;
-
-    do {
-        Old = *Value;
-        New = Old + Delta;
-    } while (InterlockedCompareExchange(Value, New, Old) != Old);
-
-    return New;
-}
-
-static FORCEINLINE LONG
-__InterlockedSubtract(
-    IN  LONG    *Value,
-    IN  LONG    Delta
-    )
-{
-    LONG        New;
-    LONG        Old;
-
-    do {
-        Old = *Value;
-        New = Old - Delta;
-    } while (InterlockedCompareExchange(Value, New, Old) != Old);
-
-    return New;
-}
-
-typedef struct _NON_PAGED_BUFFER_HEADER {
-    SIZE_T  Length;
-    ULONG   Tag;
-} NON_PAGED_BUFFER_HEADER, *PNON_PAGED_BUFFER_HEADER;
-
-typedef struct _NON_PAGED_BUFFER_TRAILER {
-    ULONG   Tag;
-} NON_PAGED_BUFFER_TRAILER, *PNON_PAGED_BUFFER_TRAILER;
-
-static FORCEINLINE PVOID
-__AllocateNonPagedPoolWithTag(
-    IN  SIZE_T                  Length,
-    IN  ULONG                   Tag
-    )
-{
-    PUCHAR                      Buffer;
-    PNON_PAGED_BUFFER_HEADER    Header;
-    PNON_PAGED_BUFFER_TRAILER   Trailer;
-
-    ASSERT(Length != 0);
-
-    Buffer = ExAllocatePoolWithTag(NonPagedPool,
-                                   sizeof (NON_PAGED_BUFFER_HEADER) +
-                                   Length +
-                                   sizeof (NON_PAGED_BUFFER_TRAILER),
-                                   Tag);
-    if (Buffer == NULL)
-        goto done;
-
-    RtlZeroMemory(Buffer, 
-                  sizeof (NON_PAGED_BUFFER_HEADER) +
-                  Length +
-                  sizeof (NON_PAGED_BUFFER_TRAILER));
-
-    Header = (PNON_PAGED_BUFFER_HEADER)Buffer;
-    Header->Length = Length;
-    Header->Tag = Tag;
-
-    Buffer += sizeof (NON_PAGED_BUFFER_HEADER);
-
-    Trailer = (PNON_PAGED_BUFFER_TRAILER)(Buffer + Length);
-    Trailer->Tag = Tag;
-
-done:
-    return Buffer;
-}
-
-static FORCEINLINE VOID
-__FreePoolWithTag(
-    IN  PVOID                   _Buffer,
-    IN  ULONG                   Tag
-    )
-{
-    PUCHAR                      Buffer = _Buffer;
-    SIZE_T                      Length;
-    PNON_PAGED_BUFFER_HEADER    Header;
-    PNON_PAGED_BUFFER_TRAILER   Trailer;
-
-    ASSERT(Buffer != NULL);
-
-    Buffer -= sizeof (NON_PAGED_BUFFER_HEADER);
-
-    Header = (PNON_PAGED_BUFFER_HEADER)Buffer;
-    ASSERT3U(Tag, ==, Header->Tag);
-    Length = Header->Length;
-
-    Buffer += sizeof (NON_PAGED_BUFFER_HEADER);
-
-    Trailer = (PNON_PAGED_BUFFER_TRAILER)(Buffer + Length);
-    ASSERT3U(Tag, ==, Trailer->Tag);
-
-    Buffer -= sizeof (NON_PAGED_BUFFER_HEADER);
-
-    RtlFillMemory(Buffer, 
-                  sizeof (NON_PAGED_BUFFER_HEADER) +
-                  Length +
-                  sizeof (NON_PAGED_BUFFER_TRAILER),
-                  0xAA);
-
-    ExFreePoolWithTag(Buffer, Tag);
-}
-
-static FORCEINLINE PMDL
-__AllocatePage(
-    VOID
-    )
-{
-    PHYSICAL_ADDRESS    LowAddress;
-    PHYSICAL_ADDRESS    HighAddress;
-    LARGE_INTEGER       SkipBytes;
-    SIZE_T              TotalBytes;
-    PMDL                Mdl;
-    PUCHAR              MdlMappedSystemVa;
-    NTSTATUS            status;
-
-    LowAddress.QuadPart = 0ull;
-    HighAddress.QuadPart = ~0ull;
-    SkipBytes.QuadPart = 0ull;
-    TotalBytes = (SIZE_T)PAGE_SIZE;
-
-    Mdl = MmAllocatePagesForMdlEx(LowAddress,
-                                  HighAddress,
-                                  SkipBytes,
-                                  TotalBytes,
-                                  MmCached,
-                                  0);
-
-    status = STATUS_NO_MEMORY;
-    if (Mdl == NULL)
-        goto fail1;
-
-    ASSERT((Mdl->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA |
-                             MDL_PARTIAL_HAS_BEEN_MAPPED |
-                             MDL_PARTIAL |
-                             MDL_PARENT_MAPPED_SYSTEM_VA |
-                             MDL_SOURCE_IS_NONPAGED_POOL |
-                             MDL_IO_SPACE)) == 0);
-
-    MdlMappedSystemVa = MmMapLockedPagesSpecifyCache(Mdl,
-                                                     KernelMode,
-                                                                            MmCached,   
-                                                                            NULL,
-                                                                            FALSE,
-                                                                            NormalPagePriority);
-
-    status = STATUS_UNSUCCESSFUL;
-    if (MdlMappedSystemVa == NULL)
-        goto fail2;
-
-    ASSERT3P(MdlMappedSystemVa, ==, Mdl->MappedSystemVa);
-
-    RtlZeroMemory(MdlMappedSystemVa, PAGE_SIZE);
-
-    return Mdl;
-
-fail2:
-    Error("fail2\n");
-
-    MmFreePagesFromMdl(Mdl);
-    ExFreePool(Mdl);
-
-fail1:
-    Error("fail1 (%08x)\n", status);
-
-    return NULL;
-}
-
-static FORCEINLINE VOID
-__FreePage(
-    IN PMDL    Mdl
-    )
-{
-    PUCHAR     MdlMappedSystemVa;
-
-    ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA);
-    MdlMappedSystemVa = Mdl->MappedSystemVa;
-
-    RtlFillMemory(MdlMappedSystemVa, PAGE_SIZE, 0xAA);
-    
-    MmUnmapLockedPages(MdlMappedSystemVa, Mdl);
-
-    MmFreePagesFromMdl(Mdl);
-}
-
-static FORCEINLINE PWCHAR
-__wcstok_r(
-    IN      PWCHAR  Buffer,
-    IN      PWCHAR  Delimiter,
-    IN OUT  PWCHAR  *Context
-    )
-{
-    PWCHAR          Token;
-    PWCHAR          End;
-
-    if (Buffer != NULL)
-        *Context = Buffer;
-
-    Token = *Context;
-
-    if (Token == NULL)
-        return NULL;
-
-    while (*Token != L'\0' &&
-           wcschr(Delimiter, *Token) != NULL)
-        Token++;
-
-    if (*Token == L'\0')
-        return NULL;
-
-    End = Token + 1;
-    while (*End != L'\0' &&
-           wcschr(Delimiter, *End) == NULL)
-        End++;
-
-    if (*End != L'\0')
-        *End++ = L'\0';
-
-    *Context = End;
-
-    return Token;
-}
-
-#endif  // _COMMON_UTIL_H
index a155d574f96b049321922ab86aee617afec4a68f..8d81b69b370fc722c110efd8567b7d8ae7665008 100644 (file)
 
 #include <version.h>
 
-#define VER_PRODUCTNAME_STR         "Citrix PV Tools for Virtual Machines"
+#define VER_PRODUCTNAME_STR         "XEN"
 #define VER_PRODUCTVERSION          MAJOR_VERSION,MINOR_VERSION,MICRO_VERSION,BUILD_NUMBER
 #define VER_PRODUCTVERSION_STR      MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR
 
 #define VER_INTERNALNAME_STR        "XEN.SYS"
-#define VER_FILEDESCRIPTION_STR     "Citrix Xen Hypervisor Interface"
+#define VER_FILEDESCRIPTION_STR     "XEN"
 
 #define VER_FILETYPE                VFT_DRV
 #define VER_FILESUBTYPE             VFT2_DRV_SYSTEM
index a9f89f1c35a6ed4987f56b5e93748b048e2e6be2..674af5ebd94a3ec9ee4f5866ba947dce97843f3e 100644 (file)
@@ -85,6 +85,7 @@ LoadOrderGroup="Boot Bus Extender"
 AddReg = XenBus_Parameters
 
 [XenBus_Parameters]
+HKR,"Parameters",,0x00000010
 HKR,"Parameters","SupportedClasses",0x00010000,"VIF","VBD","IFACE"
 HKR,"Parameters","SyntheticClasses",0x00010000,"IFACE"
 
index 376564cc0d0c3dd1d534c61b2862d73e358f5239..4f86d8bec57ff291f5b641623567d0c5cebea90c 100644 (file)
@@ -101,11 +101,11 @@ BusTranslateAddress(
 {
     PXENBUS_BUS_CONTEXT         Context = _Context;
 
-    return PdoTranslateAddress(Context->Pdo,
-                               BusAddress,
-                               Length,
-                               AddressSpace,
-                               TranslatedAddress);
+    return PdoTranslateBusAddress(Context->Pdo,
+                                  BusAddress,
+                                  Length,
+                                  AddressSpace,
+                                  TranslatedAddress);
 }
 
 static
@@ -145,7 +145,7 @@ BusGetDmaAdapter(
 static
 __drv_functionClass(GET_SET_DEVICE_DATA)
 ULONG
-BusSetDeviceData(
+BusSetData(
     IN  PVOID           _Context,
     IN  ULONG           DataType,
     IN  PVOID           Buffer,
@@ -155,17 +155,17 @@ BusSetDeviceData(
 {
     PXENBUS_BUS_CONTEXT Context = _Context;
 
-    return PdoSetData(Context->Pdo,
-                      DataType,
-                      Buffer,
-                      Offset,
-                      Length);
+    return PdoSetBusData(Context->Pdo,
+                         DataType,
+                         Buffer,
+                         Offset,
+                         Length);
 }
 
 static
 __drv_functionClass(GET_SET_DEVICE_DATA)
 ULONG
-BusGetDeviceData(
+BusGetData(
     IN  PVOID           _Context,
     IN  ULONG           DataType,
     IN  PVOID           Buffer,
@@ -175,11 +175,11 @@ BusGetDeviceData(
 {
     PXENBUS_BUS_CONTEXT Context = _Context;
 
-    return PdoGetData(Context->Pdo,
-                      DataType,
-                      Buffer,
-                      Offset,
-                      Length);
+    return PdoGetBusData(Context->Pdo,
+                         DataType,
+                         Buffer,
+                         Offset,
+                         Length);
 }
 
 NTSTATUS
@@ -223,8 +223,8 @@ BusInitialize(
     Interface->InterfaceDereference = BusDereference;
     Interface->TranslateBusAddress = BusTranslateAddress;
     Interface->GetDmaAdapter = BusGetDmaAdapter;
-    Interface->SetBusData = BusSetDeviceData;
-    Interface->GetBusData = BusGetDeviceData;
+    Interface->SetBusData = BusSetData;
+    Interface->GetBusData = BusGetData;
 
     Trace("<====\n");
 
index defdfbee8194a0aa965925df5222f9963a90cbfc..f0c19d8482ece22b1ac13c618b8290e3258b327b 100644 (file)
@@ -1609,7 +1609,7 @@ DmaGetAdapter(
     // map register related races in Windows 2008
     DeviceDescription->InterfaceType = PCIBus;
 
-    LowerAdapter = FdoGetDmaAdapter(PdoGetFdo(Pdo),
+    LowerAdapter = PdoGetDmaAdapter(Pdo,
                                     DeviceDescription,
                                     NumberOfMapRegisters);
 
index 8e957a3ef248d96620e761f85bc7b42f874e9697..0baea621b1a3fdfe7e76e78bbf6b17a475f88a50 100644 (file)
@@ -249,12 +249,12 @@ AddDevice(
 
     ParametersKey = __DriverGetParametersKey();
 
-    ActiveDeviceInstance = NULL;
     if (ParametersKey != NULL) {
         status = RegistryQuerySzValue(ParametersKey,
                                       "ActiveDeviceInstance",
                                       &ActiveDeviceInstance);
-        ASSERT(IMPLY(!NT_SUCCESS(status), ActiveDeviceInstance == NULL));
+        if (!NT_SUCCESS(status))
+            ActiveDeviceInstance = NULL;
     } else {
         ActiveDeviceInstance = NULL;
     }
index 9e77c7de4b0e88456727005e7d199daa64fa418d..15ad59515bfb00d179017d2a5ec977cfd527e585 100644 (file)
@@ -260,6 +260,66 @@ FdoGetDmaAdapter(
                                             NumberOfMapRegisters);
 }
 
+BOOLEAN
+FdoTranslateBusAddress(
+    IN      PXENBUS_FDO         Fdo,
+    IN      PHYSICAL_ADDRESS    BusAddress,
+    IN      ULONG               Length,
+    IN OUT  PULONG              AddressSpace,
+    OUT     PPHYSICAL_ADDRESS   TranslatedAddress
+    )
+{
+    PBUS_INTERFACE_STANDARD LowerBusInterface;
+
+    LowerBusInterface = &Fdo->LowerBusInterface;
+
+    return LowerBusInterface->TranslateBusAddress(LowerBusInterface->Context,
+                                                  BusAddress,
+                                                  Length,
+                                                  AddressSpace,
+                                                  TranslatedAddress);
+}
+
+ULONG
+FdoSetBusData(
+    IN  PXENBUS_FDO     Fdo,
+    IN  ULONG           DataType,
+    IN  PVOID           Buffer,
+    IN  ULONG           Offset,
+    IN  ULONG           Length
+    )
+{
+    PBUS_INTERFACE_STANDARD LowerBusInterface;
+
+    LowerBusInterface = &Fdo->LowerBusInterface;
+
+    return LowerBusInterface->SetBusData(LowerBusInterface->Context,
+                                         DataType,
+                                         Buffer,
+                                         Offset,
+                                         Length);
+}
+
+ULONG
+FdoGetBusData(
+    IN  PXENBUS_FDO     Fdo,
+    IN  ULONG           DataType,
+    IN  PVOID           Buffer,
+    IN  ULONG           Offset,
+    IN  ULONG           Length
+    )
+{
+    PBUS_INTERFACE_STANDARD LowerBusInterface;
+
+    LowerBusInterface = &Fdo->LowerBusInterface;
+
+    return LowerBusInterface->GetBusData(LowerBusInterface->Context,
+                                         DataType,
+                                         Buffer,
+                                         Offset,
+                                         Length);
+}
+
 static FORCEINLINE VOID
 __FdoSetVendorName(
     IN  PXENBUS_FDO Fdo,
@@ -301,7 +361,7 @@ __FdoSetName(
 
     status = RtlStringCbPrintfA(Dx->Name,
                                 MAXNAMELEN,
-                                "%s XEN",
+                                "%s XENBUS",
                                 __FdoGetVendorName(Fdo));
     ASSERT(NT_SUCCESS(status));
 }
@@ -872,7 +932,8 @@ FdoScan(
             status = RegistryQuerySzValue(ParametersKey,
                                           "SyntheticClasses",
                                           &SyntheticClasses);
-            ASSERT(IMPLY(!NT_SUCCESS(status), SyntheticClasses == NULL));
+            if (!NT_SUCCESS(status))
+                SyntheticClasses = NULL;
         } else {
             SyntheticClasses = NULL;
         }
@@ -892,7 +953,8 @@ FdoScan(
             status = RegistryQuerySzValue(ParametersKey,
                                           "SupportedClasses",
                                           &SupportedClasses);
-            ASSERT(IMPLY(!NT_SUCCESS(status), SyntheticClasses == NULL));
+            if (!NT_SUCCESS(status))
+                SupportedClasses = NULL;
         } else {
             SupportedClasses = NULL;
         }
index def509f83512580a2d0ce729adc904906a6ec646..32b9b8d9136dfcbcaefa78bd3e0f068e33c320e5 100644 (file)
@@ -99,13 +99,40 @@ FdoGetDmaAdapter(
     OUT PULONG              NumberOfMapRegisters
     );
 
+extern BOOLEAN
+FdoTranslateBusAddress(
+    IN      PXENBUS_FDO         Fdo,
+    IN      PHYSICAL_ADDRESS    BusAddress,
+    IN      ULONG               Length,
+    IN OUT  PULONG              AddressSpace,
+    OUT     PPHYSICAL_ADDRESS   TranslatedAddress
+    );
+
+extern ULONG
+FdoSetBusData(
+    IN  PXENBUS_FDO     Fdo,
+    IN  ULONG           DataType,
+    IN  PVOID           Buffer,
+    IN  ULONG           Offset,
+    IN  ULONG           Length
+    );
+
+extern ULONG
+FdoGetBusData(
+    IN  PXENBUS_FDO     Fdo,
+    IN  ULONG           DataType,
+    IN  PVOID           Buffer,
+    IN  ULONG           Offset,
+    IN  ULONG           Length
+    );
+
 extern PCHAR
-FdoGetName(
+FdoGetVendorName(
     IN  PXENBUS_FDO Fdo
     );
 
-PCHAR
-FdoGetVendorName(
+extern PCHAR
+FdoGetName(
     IN  PXENBUS_FDO Fdo
     );
 
index c371f61f1a15ae6e8b6853d260207b7b28a52e95..61af0f498d86cbc1101d5babe7c51478a8f2427b 100644 (file)
@@ -63,8 +63,6 @@ struct _XENBUS_PDO {
     PXENBUS_THREAD              DevicePowerThread;
     PIRP                        DevicePowerIrp;
 
-    CHAR                        Class[MAXNAMELEN];
-
     PXENBUS_FDO                 Fdo;
     BOOLEAN                     Missing;
     const CHAR                  *Reason;
@@ -224,26 +222,37 @@ PdoIsMissing(
 }
 
 static FORCEINLINE VOID
-__PdoSetClass(
+__PdoSetName(
     IN  PXENBUS_PDO     Pdo,
-    IN  PANSI_STRING    Class
+    IN  PANSI_STRING    Name
     )
 {
+    PXENBUS_DX          Dx = Pdo->Dx;
     NTSTATUS            status;
 
-    status = RtlStringCbPrintfA(Pdo->Class,
-                                MAXNAMELEN,
+    status = RtlStringCbPrintfA(Dx->Name,
+                                MAX_DEVICE_ID_LEN,
                                 "%Z",
-                                Class);
+                                Name);
     ASSERT(NT_SUCCESS(status));
 }
 
 static FORCEINLINE PCHAR
-__PdoGetClass(
+__PdoGetName(
+    IN  PXENBUS_PDO Pdo
+    )
+{
+    PXENBUS_DX      Dx = Pdo->Dx;
+
+    return Dx->Name;
+}
+
+PCHAR
+PdoGetName(
     IN  PXENBUS_PDO Pdo
     )
 {
-    return Pdo->Class;
+    return __PdoGetName(Pdo);
 }
 
 struct _REVISION_ENTRY {
@@ -268,7 +277,7 @@ __PdoGetRevision(
     
     Revision = 0;
     for (Entry = PdoRevisionTable; Entry->Name != NULL; Entry++) {
-        if (strcmp(__PdoGetClass(Pdo), Entry->Name) == 0) {
+        if (strcmp(__PdoGetName(Pdo), Entry->Name) == 0) {
             Revision = Entry->Revision;
             break;
         }
@@ -277,42 +286,6 @@ __PdoGetRevision(
     return Revision;
 }
 
-static FORCEINLINE VOID
-__PdoSetName(
-    IN  PXENBUS_PDO     Pdo,
-    IN  PCHAR           VendorName
-    )
-{
-    PXENBUS_DX          Dx = Pdo->Dx;
-    NTSTATUS            status;
-
-    status = RtlStringCbPrintfA(Dx->Name,
-                                MAX_DEVICE_ID_LEN,
-                                "VEN_%s&DEV_%s&REV_%08X",
-                                VendorName,
-                                __PdoGetClass(Pdo),
-                                __PdoGetRevision(Pdo));
-    ASSERT(NT_SUCCESS(status));
-}
-
-static FORCEINLINE PCHAR
-__PdoGetName(
-    IN  PXENBUS_PDO Pdo
-    )
-{
-    PXENBUS_DX      Dx = Pdo->Dx;
-
-    return Dx->Name;
-}
-
-PCHAR
-PdoGetName(
-    IN  PXENBUS_PDO Pdo
-    )
-{
-    return __PdoGetName(Pdo);
-}
-
 static FORCEINLINE PDEVICE_OBJECT
 __PdoGetDeviceObject(
     IN  PXENBUS_PDO Pdo
@@ -371,6 +344,14 @@ PdoGetFdo(
     return __PdoGetFdo(Pdo);
 }
 
+static FORCEINLINE PCHAR
+__PdoGetVendorName(
+    IN  PXENBUS_PDO Pdo
+    )
+{
+    return FdoGetVendorName(__PdoGetFdo(Pdo));
+}
+
 static FORCEINLINE PXENBUS_EVTCHN_INTERFACE
 __PdoGetEvtchnInterface(
     IN  PXENBUS_PDO Pdo
@@ -467,8 +448,22 @@ PdoGetSharedInfoInterface(
     return __PdoGetSharedInfoInterface(Pdo);
 }
 
+PDMA_ADAPTER
+PdoGetDmaAdapter(
+    IN  PXENBUS_PDO         Pdo,
+    IN  PDEVICE_DESCRIPTION DeviceDescriptor,
+    OUT PULONG              NumberOfMapRegisters
+    )
+{
+    Trace("<===>\n");
+
+    return FdoGetDmaAdapter(__PdoGetFdo(Pdo),
+                            DeviceDescriptor,
+                            NumberOfMapRegisters);
+}
+
 BOOLEAN
-PdoTranslateAddress(
+PdoTranslateBusAddress(
     IN      PXENBUS_PDO         Pdo,
     IN      PHYSICAL_ADDRESS    BusAddress,
     IN      ULONG               Length,
@@ -476,19 +471,17 @@ PdoTranslateAddress(
     OUT     PPHYSICAL_ADDRESS   TranslatedAddress
     )
 {
-    UNREFERENCED_PARAMETER(Pdo);
-    UNREFERENCED_PARAMETER(BusAddress);
-    UNREFERENCED_PARAMETER(Length);
-    UNREFERENCED_PARAMETER(AddressSpace);
-    UNREFERENCED_PARAMETER(TranslatedAddress);
-
     Trace("<===>\n");
 
-    return FALSE;
+    return FdoTranslateBusAddress(__PdoGetFdo(Pdo),
+                                  BusAddress,
+                                  Length,
+                                  AddressSpace,
+                                  TranslatedAddress);
 }
 
 ULONG
-PdoSetData(
+PdoSetBusData(
     IN  PXENBUS_PDO     Pdo,
     IN  ULONG           DataType,
     IN  PVOID           Buffer,
@@ -496,20 +489,17 @@ PdoSetData(
     IN  ULONG           Length
     )
 {
-    UNREFERENCED_PARAMETER(Pdo);
-    UNREFERENCED_PARAMETER(DataType);
-    UNREFERENCED_PARAMETER(Buffer);
-    UNREFERENCED_PARAMETER(Offset);
-    UNREFERENCED_PARAMETER(Length);
-
-    // This function should not be called. Shout if it is.
-    Warning("<===>\n");
+    Trace("<===>\n");
 
-    return 0;
+    return FdoSetBusData(__PdoGetFdo(Pdo),
+                         DataType,
+                         Buffer,
+                         Offset,
+                         Length);
 }
 
 ULONG
-PdoGetData(
+PdoGetBusData(
     IN  PXENBUS_PDO     Pdo,
     IN  ULONG           DataType,
     IN  PVOID           Buffer,
@@ -517,16 +507,13 @@ PdoGetData(
     IN  ULONG           Length
     )
 {
-    UNREFERENCED_PARAMETER(Pdo);
-    UNREFERENCED_PARAMETER(DataType);
-    UNREFERENCED_PARAMETER(Buffer);
-    UNREFERENCED_PARAMETER(Offset);
-    UNREFERENCED_PARAMETER(Length);
-
-    // This function should not be called. Shout if it is.
-    Warning("<===>\n");
+    Trace("<===>\n");
 
-    return 0;
+    return FdoGetBusData(__PdoGetFdo(Pdo),
+                         DataType,
+                         Buffer,
+                         Offset,
+                         Length);
 }
 
 static FORCEINLINE VOID
@@ -1514,7 +1501,7 @@ PdoQueryDeviceText(
                                     MAXTEXTLEN,
                                     L"%hs %hs",
                                     FdoGetName(__PdoGetFdo(Pdo)),
-                                    __PdoGetClass(Pdo));
+                                    __PdoGetName(Pdo));
         ASSERT(NT_SUCCESS(status));
 
         Buffer += wcslen(Buffer);
@@ -1525,7 +1512,7 @@ PdoQueryDeviceText(
         status = RtlStringCbPrintfW(Buffer,
                                     MAXTEXTLEN,
                                     L"%hs",
-                                    __PdoGetClass(Pdo));
+                                    __PdoGetName(Pdo));
         ASSERT(NT_SUCCESS(status));
 
         Buffer += wcslen(Buffer);
@@ -1642,8 +1629,10 @@ PdoQueryId(
 
         status = RtlStringCbPrintfW(Buffer,
                                     MAX_DEVICE_ID_LEN,
-                                    L"XENBUS\\%hs",
-                                    __PdoGetName(Pdo));
+                                    L"XENBUS\\VEN_%hs&DEV_%hs&REV_%08X",
+                                    __PdoGetVendorName(Pdo),
+                                    __PdoGetName(Pdo),
+                                    __PdoGetRevision(Pdo));
         ASSERT(NT_SUCCESS(status));
 
         Buffer += wcslen(Buffer);
@@ -1659,8 +1648,10 @@ PdoQueryId(
         Length = MAX_DEVICE_ID_LEN;
         status = RtlStringCbPrintfW(Buffer,
                                     Length,
-                                    L"XENBUS\\%hs",
-                                    __PdoGetName(Pdo));
+                                    L"XENBUS\\VEN_%hs&DEV_%hs&REV_%08X",
+                                    __PdoGetVendorName(Pdo),
+                                    __PdoGetName(Pdo),
+                                    __PdoGetRevision(Pdo));
         ASSERT(NT_SUCCESS(status));
 
         Buffer += wcslen(Buffer);
@@ -2258,7 +2249,7 @@ PdoSuspend(
 NTSTATUS
 PdoCreate(
     IN  PXENBUS_FDO     Fdo,
-    IN  PANSI_STRING    Class
+    IN  PANSI_STRING    Name
     )
 {
     PDEVICE_OBJECT      PhysicalDeviceObject;
@@ -2295,21 +2286,20 @@ PdoCreate(
 
     Pdo->Dx = Dx;
 
-    status = BusInitialize(Pdo, &Pdo->BusInterface);
+    status = ThreadCreate(PdoSystemPower, Pdo, &Pdo->SystemPowerThread);
     if (!NT_SUCCESS(status))
         goto fail3;
 
-    status = ThreadCreate(PdoSystemPower, Pdo, &Pdo->SystemPowerThread);
+    status = ThreadCreate(PdoDevicePower, Pdo, &Pdo->DevicePowerThread);
     if (!NT_SUCCESS(status))
         goto fail4;
 
-    status = ThreadCreate(PdoDevicePower, Pdo, &Pdo->DevicePowerThread);
+    __PdoSetName(Pdo, Name);
+
+    status = BusInitialize(Pdo, &Pdo->BusInterface);
     if (!NT_SUCCESS(status))
         goto fail5;
 
-    __PdoSetClass(Pdo, Class);
-    __PdoSetName(Pdo, FdoGetVendorName(Fdo));
-
     Info("%p (%s)\n",
          PhysicalDeviceObject,
          __PdoGetName(Pdo));
@@ -2324,14 +2314,16 @@ PdoCreate(
 fail5:
     Error("fail5\n");
 
-    ThreadAlert(Pdo->SystemPowerThread);
-    ThreadJoin(Pdo->SystemPowerThread);
-    Pdo->SystemPowerThread = NULL;
+    ThreadAlert(Pdo->DevicePowerThread);
+    ThreadJoin(Pdo->DevicePowerThread);
+    Pdo->DevicePowerThread = NULL;
 
 fail4:
     Error("fail4\n");
 
-    BusTeardown(&Pdo->BusInterface);
+    ThreadAlert(Pdo->SystemPowerThread);
+    ThreadJoin(Pdo->SystemPowerThread);
+    Pdo->SystemPowerThread = NULL;
 
 fail3:
     Error("fail3\n");
@@ -2375,7 +2367,7 @@ PdoDestroy(
 
     Dx->Pdo = NULL;
 
-    RtlZeroMemory(Pdo->Class, MAXNAMELEN);
+    BusTeardown(&Pdo->BusInterface);
 
     ThreadAlert(Pdo->DevicePowerThread);
     ThreadJoin(Pdo->DevicePowerThread);
@@ -2385,8 +2377,6 @@ PdoDestroy(
     ThreadJoin(Pdo->SystemPowerThread);
     Pdo->SystemPowerThread = NULL;
 
-    BusTeardown(&Pdo->BusInterface);
-
     Pdo->Dx = NULL;
 
     ASSERT(IsZeroMemory(Pdo, sizeof (XENBUS_PDO)));
index 3c5d7482558030246d0195ab75a3fce39c061c54..798abdbb9d124f96460b8082595418b8f10b29c8 100644 (file)
@@ -69,8 +69,20 @@ PdoGetDeviceObject(
     IN  PXENBUS_PDO Pdo
     );
 
+extern PXENBUS_FDO
+PdoGetFdo(
+    IN  PXENBUS_PDO Pdo
+    );
+
+extern PDMA_ADAPTER
+PdoGetDmaAdapter(
+    IN  PXENBUS_PDO         Pdo,
+    IN  PDEVICE_DESCRIPTION DeviceDescriptor,
+    OUT PULONG              NumberOfMapRegisters
+    );
+
 extern BOOLEAN
-PdoTranslateAddress(
+PdoTranslateBusAddress(
     IN      PXENBUS_PDO         Pdo,
     IN      PHYSICAL_ADDRESS    BusAddress,
     IN      ULONG               Length,
@@ -78,13 +90,8 @@ PdoTranslateAddress(
     OUT     PPHYSICAL_ADDRESS   TranslatedAddress
     );
 
-extern PXENBUS_FDO
-PdoGetFdo(
-    IN  PXENBUS_PDO Pdo
-    );
-
 extern ULONG
-PdoSetData(
+PdoSetBusData(
     IN  PXENBUS_PDO     Pdo,
     IN  ULONG           DataType,
     IN  PVOID           Buffer,
@@ -93,7 +100,7 @@ PdoSetData(
     );
 
 extern ULONG
-PdoGetData(
+PdoGetBusData(
     IN  PXENBUS_PDO     Pdo,
     IN  ULONG           DataType,
     IN  PVOID           Buffer,
index cd66cb2ab737c457c4092ddf5272dd370df1d9fc..a1644e1c1f9acd70d788ec2b6cf5829af6a675cf 100644 (file)
 
 #include <version.h>
 
-#define VER_PRODUCTNAME_STR         "Citrix PV Tools for Virtual Machines"
+#define VER_PRODUCTNAME_STR         "XENBUS"
 #define VER_PRODUCTVERSION          MAJOR_VERSION,MINOR_VERSION,MICRO_VERSION,BUILD_NUMBER
 #define VER_PRODUCTVERSION_STR      MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR
 
 #define VER_INTERNALNAME_STR        "XENBUS.SYS"
-#define VER_FILEDESCRIPTION_STR     "Citrix PV Bus Driver"
+#define VER_FILEDESCRIPTION_STR     "XENBUS"
 
 #define VER_FILETYPE                VFT_DRV
 #define VER_FILESUBTYPE             VFT2_DRV_SYSTEM
index 702551b8f003cf27aa58e10d867536e75ecc6590..81c5e5385770eac6ec49b0279fd940615d0ae871 100644 (file)
@@ -36,6 +36,7 @@
 #include "fdo.h"
 #include "pdo.h"
 #include "registry.h"
+#include "emulated.h"
 #include "driver.h"
 #include "dbg_print.h"
 #include "assert.h"
@@ -44,8 +45,9 @@
 extern PULONG       InitSafeBootMode;
 
 typedef struct _XENFILT_DRIVER {
-    PDRIVER_OBJECT      DriverObject;
-    HANDLE              ParametersKey;
+    PDRIVER_OBJECT              DriverObject;
+    HANDLE                      ParametersKey;
+    XENFILT_EMULATED_INTERFACE  EmulatedInterface;
 } XENFILT_DRIVER, *PXENFILT_DRIVER;
 
 static XENFILT_DRIVER   Driver;
@@ -98,6 +100,22 @@ DriverGetParametersKey(
     return __DriverGetParametersKey();
 }
 
+static FORCEINLINE PXENFILT_EMULATED_INTERFACE
+__DriverGetEmulatedInterface(
+    VOID
+    )
+{
+    return &Driver.EmulatedInterface;
+}
+
+PXENFILT_EMULATED_INTERFACE
+DriverGetEmulatedInterface(
+    VOID
+    )
+{
+    return __DriverGetEmulatedInterface();
+}
+
 DRIVER_UNLOAD                       DriverUnload;
 
 VOID
@@ -114,6 +132,8 @@ DriverUnload(
     if (*InitSafeBootMode > 0)
         goto done;
 
+    EmulatedTeardown(&Driver.EmulatedInterface);
+
     ParametersKey = __DriverGetParametersKey();
     if (ParametersKey != NULL) {
         RegistryCloseKey(ParametersKey);
@@ -390,6 +410,10 @@ DriverEntry(
     if (NT_SUCCESS(status))
         __DriverSetParametersKey(ParametersKey);
 
+    status = EmulatedInitialize(&Driver.EmulatedInterface);
+    if (!NT_SUCCESS(status))
+        goto fail3;
+
     RegistryCloseKey(ServiceKey);
 
     DriverObject->DriverExtension->AddDevice = AddDevice;
@@ -404,6 +428,14 @@ done:
     Trace("<====\n");
     return STATUS_SUCCESS;
 
+fail3:
+    Error("fail3\n");
+
+    if (ParametersKey != NULL) {
+        RegistryCloseKey(ParametersKey);
+        __DriverSetParametersKey(NULL);
+    }
+
 fail2:
     Error("fail2\n");
 
diff --git a/src/xenfilt/emulated.c b/src/xenfilt/emulated.c
new file mode 100644 (file)
index 0000000..dd040fc
--- /dev/null
@@ -0,0 +1,166 @@
+/* Copyright (c) Citrix Systems Inc.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, 
+ * with or without modification, are permitted provided 
+ * that the following conditions are met:
+ * 
+ * *   Redistributions of source code must retain the above 
+ *     copyright notice, this list of conditions and the 
+ *     following disclaimer.
+ * *   Redistributions in binary form must reproduce the above 
+ *     copyright notice, this list of conditions and the 
+ *     following disclaimer in the documentation and/or other 
+ *     materials provided with the distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+ * SUCH DAMAGE.
+ */
+
+#include <ntddk.h>
+#include <ntstrsafe.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <xen.h>
+#include <util.h>
+
+#include "registry.h"
+#include "emulated.h"
+#include "dbg_print.h"
+#include "assert.h"
+
+struct _XENFILT_EMULATED_CONTEXT {
+    LONG                References;
+};
+
+#define EMULATED_TAG    'LUME'
+
+static FORCEINLINE PVOID
+__EmulatedAllocate(
+    IN  ULONG   Length
+    )
+{
+    return __AllocateNonPagedPoolWithTag(Length, EMULATED_TAG);
+}
+
+static FORCEINLINE VOID
+__EmulatedFree(
+    IN  PVOID   Buffer
+    )
+{
+    __FreePoolWithTag(Buffer, EMULATED_TAG);
+}
+
+static BOOLEAN
+EmulatedIsDevicePresent(
+    IN  PXENFILT_EMULATED_CONTEXT   Context,
+    IN  PCHAR                       DeviceID,
+    IN  PCHAR                       InstanceID
+    )
+{
+    UNREFERENCED_PARAMETER(Context);
+    UNREFERENCED_PARAMETER(DeviceID);
+    UNREFERENCED_PARAMETER(InstanceID);
+
+    return TRUE;
+}
+
+static BOOLEAN
+EmulatedIsDiskPresent(
+    IN  PXENFILT_EMULATED_CONTEXT   Context,
+    IN  ULONG                       Controller,
+    IN  ULONG                       Target,
+    IN  ULONG                       Lun
+    )
+{
+    UNREFERENCED_PARAMETER(Context);
+    UNREFERENCED_PARAMETER(Controller);
+    UNREFERENCED_PARAMETER(Target);
+    UNREFERENCED_PARAMETER(Lun);
+
+    return TRUE;
+}
+
+static VOID
+EmulatedAcquire(
+    IN  PXENFILT_EMULATED_CONTEXT   Context
+    )
+{
+    InterlockedIncrement(&Context->References);
+}
+
+static VOID
+EmulatedRelease(
+    IN  PXENFILT_EMULATED_CONTEXT   Context
+    )
+{
+    ASSERT(Context->References != 0);
+    InterlockedDecrement(&Context->References);
+}
+
+#define EMULATED_OPERATION(_Type, _Name, _Arguments) \
+        Emulated ## _Name,
+
+static XENFILT_EMULATED_OPERATIONS  Operations = {
+    DEFINE_EMULATED_OPERATIONS
+};
+
+#undef EMULATED_OPERATION
+
+NTSTATUS
+EmulatedInitialize(
+    OUT PXENFILT_EMULATED_INTERFACE Interface
+    )
+{
+    PXENFILT_EMULATED_CONTEXT       Context;
+    NTSTATUS                        status;
+
+    Trace("====>\n");
+
+    Context = __EmulatedAllocate(sizeof (XENFILT_EMULATED_CONTEXT));
+
+    status = STATUS_NO_MEMORY;
+    if (Context == NULL)
+        goto fail1;
+
+    Interface->Context = Context;
+    Interface->Operations = &Operations;
+
+    Trace("<====\n");
+
+    return STATUS_SUCCESS;
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
+}
+
+VOID
+EmulatedTeardown(
+    IN OUT  PXENFILT_EMULATED_INTERFACE Interface
+    )
+{
+    PXENFILT_EMULATED_CONTEXT           Context = Interface->Context;
+
+    Trace("====>\n");
+
+    ASSERT(IsZeroMemory(Context, sizeof (XENFILT_EMULATED_CONTEXT)));
+    __EmulatedFree(Context);
+
+    RtlZeroMemory(Interface, sizeof (XENFILT_EMULATED_INTERFACE));
+
+    Trace("<====\n");
+}
diff --git a/src/xenfilt/emulated.h b/src/xenfilt/emulated.h
new file mode 100644 (file)
index 0000000..e1038a5
--- /dev/null
@@ -0,0 +1,57 @@
+/* Copyright (c) Citrix Systems Inc.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, 
+ * with or without modification, are permitted provided 
+ * that the following conditions are met:
+ * 
+ * *   Redistributions of source code must retain the above 
+ *     copyright notice, this list of conditions and the 
+ *     following disclaimer.
+ * *   Redistributions in binary form must reproduce the above 
+ *     copyright notice, this list of conditions and the 
+ *     following disclaimer in the documentation and/or other 
+ *     materials provided with the distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+ * SUCH DAMAGE.
+ */
+
+#ifndef _XENFILT_EMULATED_H
+#define _XENFILT_EMULATED_H
+
+#include <ntddk.h>
+#include <xen.h>
+#include <emulated_interface.h>
+
+struct _XENFILT_EMULATED_INTERFACE {
+    PXENFILT_EMULATED_OPERATIONS    Operations;
+    PXENFILT_EMULATED_CONTEXT       Context;
+};
+
+C_ASSERT(FIELD_OFFSET(XENFILT_EMULATED_INTERFACE, Operations) == (ULONG_PTR)EMULATED_OPERATIONS(NULL));
+C_ASSERT(FIELD_OFFSET(XENFILT_EMULATED_INTERFACE, Context) == (ULONG_PTR)EMULATED_CONTEXT(NULL));
+
+extern NTSTATUS
+EmulatedInitialize(
+    OUT PXENFILT_EMULATED_INTERFACE Interface
+    );
+
+extern VOID
+EmulatedTeardown(
+    IN OUT  PXENFILT_EMULATED_INTERFACE Interface
+    );
+
+#endif  // _XENFILT_EMULATED_H
index 3a998e01c522580a70db7967d4673349f531da01..2b3103e2d780d8ae9304dbfccc35fb5c6d87ba76 100644 (file)
 
 #include <version.h>
 
-#define VER_PRODUCTNAME_STR         "Citrix PV Tools for Virtual Machines"
+#define VER_PRODUCTNAME_STR         "XENFILT"
 #define VER_PRODUCTVERSION          MAJOR_VERSION,MINOR_VERSION,MICRO_VERSION,BUILD_NUMBER
 #define VER_PRODUCTVERSION_STR      MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR
 
 #define VER_INTERNALNAME_STR        "XENFILT.SYS"
-#define VER_FILEDESCRIPTION_STR     "Citrix Bus Filter Driver"
+#define VER_FILEDESCRIPTION_STR     "XENFILT"
 
 #define VER_FILETYPE                VFT_DRV
 #define VER_FILESUBTYPE             VFT2_DRV_SYSTEM