win-pvdrivers

view xenpci/memory.c @ 332:52533409dbbd

get things compiling again under DDK
author Andy Grover <andy.grover@oracle.com>
date Thu Jun 19 17:20:16 2008 -0700 (2008-06-19)
parents daa0a9b0fef0
children 72acaf6e4668
line source
1 #include "xenpci.h"
3 //static pgentry_t *demand_map_pgt;
4 static void *demand_map_area_start;
6 NTSTATUS
7 hvm_get_stubs(PXENPCI_DEVICE_DATA xpdd)
8 {
9 DWORD32 cpuid_output[4];
10 char xensig[13];
11 ULONG i;
12 ULONG pages;
13 ULONG msr;
15 __cpuid(cpuid_output, 0x40000000);
16 *(ULONG*)(xensig + 0) = cpuid_output[1];
17 *(ULONG*)(xensig + 4) = cpuid_output[2];
18 *(ULONG*)(xensig + 8) = cpuid_output[3];
19 xensig[12] = '\0';
20 KdPrint((__DRIVER_NAME " Xen Signature = %s, EAX = 0x%08x\n", xensig, cpuid_output[0]));
22 __cpuid(cpuid_output, 0x40000002);
23 pages = cpuid_output[0];
24 msr = cpuid_output[1];
25 //KdPrint((__DRIVER_NAME " Hypercall area is %u pages.\n", pages));
27 xpdd->hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
28 KdPrint((__DRIVER_NAME " Hypercall area at %p\n", xpdd->hypercall_stubs));
30 if (!xpdd->hypercall_stubs)
31 return 1;
32 for (i = 0; i < pages; i++) {
33 ULONGLONG pfn;
34 pfn = (MmGetPhysicalAddress(xpdd->hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
35 KdPrint((__DRIVER_NAME " pfn = %16lX\n", pfn));
36 __writemsr(msr, (pfn << PAGE_SHIFT) + i);
37 }
38 return STATUS_SUCCESS;
39 }
41 NTSTATUS
42 hvm_free_stubs(PXENPCI_DEVICE_DATA xpdd)
43 {
44 ExFreePoolWithTag(xpdd->hypercall_stubs, XENPCI_POOL_TAG);
46 return STATUS_SUCCESS;
47 }
49 #if 0
50 PVOID
51 map_frames(PULONG f, ULONG n)
52 {
53 unsigned long x;
54 unsigned long y = 0;
55 mmu_update_t mmu_updates[16];
56 int rc;
58 for (x = 0; x <= 1024 - n; x += y + 1) {
59 for (y = 0; y < n; y++)
60 if (demand_map_pgt[x+y] & _PAGE_PRESENT)
61 break;
62 if (y == n)
63 break;
64 }
65 if (y != n) {
66 KdPrint((__DRIVER_NAME " Failed to map %ld frames!\n", n));
67 return NULL;
68 }
70 for (y = 0; y < n; y++) {
71 //mmu_updates[y].ptr = virt_to_mach(&demand_map_pgt[x + y]);
72 mmu_updates[y].ptr = MmGetPhysicalAddress(&demand_map_pgt[x + y]).QuadPart;
73 mmu_updates[y].val = (f[y] << PAGE_SHIFT) | L1_PROT;
74 }
76 rc = HYPERVISOR_mmu_update(mmu_updates, n, NULL, DOMID_SELF);
77 if (rc < 0) {
78 KdPrint((__DRIVER_NAME " Map %ld failed: %d.\n", n, rc));
79 return NULL;
80 } else {
81 return (PVOID)(ULONG)((ULONG)demand_map_area_start + x * PAGE_SIZE);
82 }
83 }
84 #endif