win-pvdrivers

view xenpci/memory.c @ 906:9be11a753ca2

indicate small packets with STATUS_RESOURCES as Windows is lazy about returning them.
checksum fixes
maintian a freelist of packets
author James Harper <james.harper@bendigoit.com.au>
date Fri Apr 15 16:01:34 2011 +1000 (2011-04-15)
parents 95159ee58473
children da0e40d12a9c
line source
1 #include "xenpci.h"
3 /* must be called at <= DISPATCH_LEVEL if hypercall_stubs == NULL */
5 #define XEN_SIGNATURE_LOWER 0x40000000
6 #define XEN_SIGNATURE_UPPER 0x4000FFFF
8 PVOID
9 hvm_get_hypercall_stubs()
10 {
11 PVOID hypercall_stubs;
12 ULONG base;
13 DWORD32 cpuid_output[4];
14 char xensig[13];
15 ULONG i;
16 ULONG pages;
17 ULONG msr;
19 for (base = XEN_SIGNATURE_LOWER; base < XEN_SIGNATURE_UPPER; base += 0x100)
20 {
21 __cpuid(cpuid_output, base);
22 *(ULONG*)(xensig + 0) = cpuid_output[1];
23 *(ULONG*)(xensig + 4) = cpuid_output[2];
24 *(ULONG*)(xensig + 8) = cpuid_output[3];
25 xensig[12] = '\0';
26 KdPrint((__DRIVER_NAME " base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]));
27 if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2))
28 break;
29 }
30 if (base > XEN_SIGNATURE_UPPER)
31 {
32 KdPrint((__DRIVER_NAME " Cannot find Xen signature\n"));
33 return NULL;
34 }
36 __cpuid(cpuid_output, base + 2);
37 pages = cpuid_output[0];
38 msr = cpuid_output[1];
40 hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
41 KdPrint((__DRIVER_NAME " Hypercall area at %p\n", hypercall_stubs));
43 if (!hypercall_stubs)
44 return NULL;
45 for (i = 0; i < pages; i++) {
46 ULONGLONG pfn;
47 pfn = (MmGetPhysicalAddress((PUCHAR)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 hypercall_stubs;
52 }
54 VOID
55 hvm_free_hypercall_stubs(PVOID hypercall_stubs)
56 {
57 ExFreePoolWithTag(hypercall_stubs, XENPCI_POOL_TAG);
58 }