win-pvdrivers

view xenpci/memory.c @ 804:6ea80e94e8cf

Added tag 0.11.0.218 for changeset bbc6c94b9621
author James Harper <james.harper@bendigoit.com.au>
date Sun Jun 27 16:15:21 2010 +1000 (2010-06-27)
parents dacb06e01653
children 95159ee58473
line source
1 #include "xenpci.h"
3 /* must be called at <= DISPATCH_LEVEL if hypercall_stubs == NULL */
5 #if !defined(__ia64__)
7 #define XEN_SIGNATURE_LOWER 0x40000000
8 #define XEN_SIGNATURE_UPPER 0x4000FFFF
10 NTSTATUS
11 hvm_get_stubs(PXENPCI_DEVICE_DATA xpdd)
12 {
13 ULONG base;
14 DWORD32 cpuid_output[4];
15 char xensig[13];
16 ULONG i;
17 ULONG pages;
18 ULONG msr;
20 for (base = XEN_SIGNATURE_LOWER; base < XEN_SIGNATURE_UPPER; base += 0x100)
21 {
22 __cpuid(cpuid_output, base);
23 *(ULONG*)(xensig + 0) = cpuid_output[1];
24 *(ULONG*)(xensig + 4) = cpuid_output[2];
25 *(ULONG*)(xensig + 8) = cpuid_output[3];
26 xensig[12] = '\0';
27 KdPrint((__DRIVER_NAME " base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]));
28 if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2))
29 break;
30 }
31 if (base > XEN_SIGNATURE_UPPER)
32 {
33 KdPrint((__DRIVER_NAME " Cannot find Xen signature\n"));
34 return STATUS_UNSUCCESSFUL;
35 }
37 __cpuid(cpuid_output, base + 2);
38 pages = cpuid_output[0];
39 msr = cpuid_output[1];
41 if (!xpdd->hypercall_stubs)
42 {
43 ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
44 xpdd->hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
45 }
46 KdPrint((__DRIVER_NAME " Hypercall area at %p\n", xpdd->hypercall_stubs));
48 if (!xpdd->hypercall_stubs)
49 return 1;
50 for (i = 0; i < pages; i++) {
51 ULONGLONG pfn;
52 pfn = (MmGetPhysicalAddress(xpdd->hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
53 //KdPrint((__DRIVER_NAME " pfn = %16lX\n", pfn));
54 __writemsr(msr, (pfn << PAGE_SHIFT) + i);
55 }
56 return STATUS_SUCCESS;
57 }
59 NTSTATUS
60 hvm_free_stubs(PXENPCI_DEVICE_DATA xpdd)
61 {
62 ExFreePoolWithTag(xpdd->hypercall_stubs, XENPCI_POOL_TAG);
64 return STATUS_SUCCESS;
65 }
67 #else
69 NTSTATUS
70 hvm_get_stubs(PXENPCI_DEVICE_DATA xpdd)
71 {
72 UNREFERENCED_PARAMETER(xpdd);
73 return STATUS_SUCCESS;
74 }
76 NTSTATUS
77 hvm_free_stubs(PXENPCI_DEVICE_DATA xpdd)
78 {
79 UNREFERENCED_PARAMETER(xpdd);
80 return STATUS_SUCCESS;
81 }
83 #endif