win-pvdrivers

view xenpci/memory.c @ 651:8b3dae86a7f6

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