win-pvdrivers

view xenpci/memory.c @ 1013:43e76afb2398

Fix compiler warnings under 2000
author James Harper <james.harper@bendigoit.com.au>
date Mon Feb 11 20:59:11 2013 +1100 (2013-02-11)
parents da0e40d12a9c
children
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2011 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #include "xenpci.h"
22 /* must be called at <= DISPATCH_LEVEL if hypercall_stubs == NULL */
24 #define XEN_SIGNATURE_LOWER 0x40000000
25 #define XEN_SIGNATURE_UPPER 0x4000FFFF
27 USHORT xen_version_major = (USHORT)-1;
28 USHORT xen_version_minor = (USHORT)-1;
30 PVOID
31 hvm_get_hypercall_stubs()
32 {
33 PVOID hypercall_stubs;
34 ULONG base;
35 DWORD32 cpuid_output[4];
36 char xensig[13];
37 ULONG i;
38 ULONG pages;
39 ULONG msr;
41 for (base = XEN_SIGNATURE_LOWER; base < XEN_SIGNATURE_UPPER; base += 0x100)
42 {
43 __cpuid(cpuid_output, base);
44 *(ULONG*)(xensig + 0) = cpuid_output[1];
45 *(ULONG*)(xensig + 4) = cpuid_output[2];
46 *(ULONG*)(xensig + 8) = cpuid_output[3];
47 xensig[12] = '\0';
48 FUNCTION_MSG("base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]);
49 if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2))
50 break;
51 }
52 if (base > XEN_SIGNATURE_UPPER)
53 {
54 FUNCTION_MSG("Cannot find Xen signature\n");
55 return NULL;
56 }
58 __cpuid(cpuid_output, base + 1);
59 xen_version_major = (USHORT)(cpuid_output[0] >> 16);
60 xen_version_minor = (USHORT)(cpuid_output[0] & 0xFFFF);
61 FUNCTION_MSG("Xen Version %d.%d\n", xen_version_major, xen_version_minor);
63 __cpuid(cpuid_output, base + 2);
64 pages = cpuid_output[0];
65 msr = cpuid_output[1];
67 hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
68 FUNCTION_MSG("Hypercall area at %p\n", hypercall_stubs);
70 if (!hypercall_stubs)
71 return NULL;
72 for (i = 0; i < pages; i++) {
73 ULONGLONG pfn;
74 pfn = (MmGetPhysicalAddress((PUCHAR)hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
75 //KdPrint((__DRIVER_NAME " pfn = %16lX\n", pfn));
76 __writemsr(msr, (pfn << PAGE_SHIFT) + i);
77 }
78 return hypercall_stubs;
79 }
81 VOID
82 hvm_free_hypercall_stubs(PVOID hypercall_stubs)
83 {
84 ExFreePoolWithTag(hypercall_stubs, XENPCI_POOL_TAG);
85 }