win-pvdrivers

view xenpci/memory.c @ 538:e75bb8d68370

Lots more changes...
author James Harper <james.harper@bendigoit.com.au>
date Tue Mar 03 09:51:24 2009 +1100 (2009-03-03)
parents 1d39de3ab8d6
children 4698fce07251
line source
1 #include "xenpci.h"
3 /* must be called at <= DISPATCH_LEVEL if hypercall_stubs == NULL */
5 NTSTATUS
6 hvm_get_stubs(PXENPCI_DEVICE_DATA xpdd)
7 {
8 ULONG base;
9 DWORD32 cpuid_output[4];
10 char xensig[13];
11 ULONG i;
12 ULONG pages;
13 ULONG msr;
15 for (base = 0x40000000; base < 0x40001000; base += 0x100)
16 {
17 __cpuid(cpuid_output, 0x40000000);
18 *(ULONG*)(xensig + 0) = cpuid_output[1];
19 *(ULONG*)(xensig + 4) = cpuid_output[2];
20 *(ULONG*)(xensig + 8) = cpuid_output[3];
21 xensig[12] = '\0';
22 KdPrint((__DRIVER_NAME " base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]));
23 if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2))
24 break;
25 }
26 if (base >= 0x40001000)
27 {
28 KdPrint((__DRIVER_NAME " Cannot find Xen signature\n"));
29 return STATUS_UNSUCCESSFUL;
30 }
32 __cpuid(cpuid_output, base + 2);
33 pages = cpuid_output[0];
34 msr = cpuid_output[1];
36 if (!xpdd->hypercall_stubs)
37 {
38 ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
39 xpdd->hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
40 }
41 KdPrint((__DRIVER_NAME " Hypercall area at %p\n", xpdd->hypercall_stubs));
43 if (!xpdd->hypercall_stubs)
44 return 1;
45 for (i = 0; i < pages; i++) {
46 ULONGLONG pfn;
47 pfn = (MmGetPhysicalAddress(xpdd->hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
48 KdPrint((__DRIVER_NAME " pfn = %16lX\n", pfn));
49 __writemsr(msr, (pfn << PAGE_SHIFT) + i);
50 }
51 return STATUS_SUCCESS;
52 }
54 NTSTATUS
55 hvm_free_stubs(PXENPCI_DEVICE_DATA xpdd)
56 {
57 ExFreePoolWithTag(xpdd->hypercall_stubs, XENPCI_POOL_TAG);
59 return STATUS_SUCCESS;
60 }