|
|
|
/* change kmem_cache_t to kmem_cache */ |
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) |
|
# define kmem_cache_compat struct kmem_cache |
|
# if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) |
|
# define compat_kmem_cache_create(a, b, c, d, e, f) (kmem_cache_create(a, b, c, d, e)) |
|
# else |
|
# define compat_kmem_cache_create(a, b, c, d, e, f) (kmem_cache_create(a, b, c, d, e, f)) |
|
# endif |
|
#else |
|
# define kmem_cache_compat kmem_cache_t |
|
# define compat_kmem_cache_create(a, b, c, d, e, f) (kmem_cache_create(a, b, c, d, e, f)) |
|
#endif |
|
|
|
|
KSRC=/lib/modules/$(shell uname -r)/build |
KSRC ?= /lib/modules/$(shell uname -r)/build |
|
|
|
#include <linux/sched.h> |
|
|
vmGlobal.vmPmms.pmmRegionsSlab = kmem_cache_create("vmRegions", sizeof(struct pmm_region_t), 0, |
vmGlobal.vmPmms.pmmRegionsSlab = compat_kmem_cache_create("vmRegions", sizeof(struct pmm_region_t), 0, |
|
|
|
#include <linux/sched.h> |
|
|
|
#include "compat/compat_memory.h" |
|
|
kmem_cache_t *pmmRegionsSlab; |
kmem_cache_compat *pmmRegionsSlab; |
|
|
// $Id: prlnet.c,v 1.6 2006/07/21 09:05:36 sergeyv Exp $ |
// $Id: prlnet.c 28219 2007-07-27 08:03:39Z anatolykh $ |
|
|
|
#include <linux/mm.h> |
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
|
#include <net/ip.h> |
|
#endif |
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
|
skb_reset_mac_header(skb); |
|
skb_set_network_header(skb, sizeof(skb->mac_header)); |
|
#else |
|
|
|
#endif |
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
|
eth = (eth_header_t *)skb_mac_header(skbout); |
|
#else |
|
|
|
#endif |
|
|
prlnet_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt) |
prlnet_recv( |
|
struct sk_buff *skb, struct net_device *dev, struct packet_type *pt |
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14) |
|
, struct net_device *origdev |
|
#endif |
|
) |
|
|
&& skb->ip_summed == CHECKSUM_HW; |
&& skb->ip_summed == |
|
#ifdef CHECKSUM_HW |
|
CHECKSUM_HW; |
|
#else |
|
CHECKSUM_PARTIAL; |
|
#endif |
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
|
int len = skb->data - skb_mac_header(skb) + skb->len; |
|
#else |
|
|
|
#endif |
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
|
// can't use skb_copy_and_csum_dev(skb, buf + 2) here |
|
// because skb->h == skb->nh. opensource rules! |
|
int hoff = sizeof(struct ethhdr) + ip_hdrlen(skb); |
|
// IP header checksum is done by the kernel |
|
skb_copy_bits(skb, |
|
skb_mac_header(skb) - skb->data, buf + 2, hoff); |
|
|
|
// skb->csum is an offset from true skb->h.raw |
|
*(unsigned short *)(buf + 2 + hoff + skb->csum) = |
|
csum_fold( |
|
// kernel does conceptual header too |
|
skb_copy_and_csum_bits(skb, |
|
skb_mac_header(skb) + hoff - skb->data, |
|
buf + 2 + hoff, len - hoff, 0)); |
|
#else |
|
|
|
|
|
|
|
#endif |
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
|
skb_copy_bits(skb, |
|
skb_mac_header(skb) - skb->data, buf + 2, len); |
|
#else |
|
|
|
#endif |
|
|
|
kfree(buf); |
|
|
kfree(buf); |
|
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
|
hw_recv(hw, skb_mac_header(skb), skb->data - skb_mac_header(skb) + skb->len); |
|
#else |
|
|
|
#endif |
|
|
|
#if WIRELESS_EXT < 19 |
|
|
|
#endif |
|
|
// $Id: prlnet.h,v 1.2 2006/02/06 13:46:49 mihailsi Exp $ |
// $Id: prlnet.h 6855 2006-02-06 13:46:49Z mihailsi $ |
|
|
MODULE_DESCRIPTION("Transparen ethernet bridge"); |
MODULE_DESCRIPTION("Virtual ethernet card"); |
|
|
// Version |
|
//static const char *version = "VMVirtualNIC.c:v1.01 VirtualNIC driver from Parallels Inc. http://www.parallelssoft.com/"; |
|
|
|
|
|
struct net_device* dev; |
struct net_device* devs[5]; |
|
|
|
|
|
|
}; |
} |
|
|
|
|
|
|
}; |
} |
|
|
|
int maxdev = 1; |
|
#if defined(module_param) |
|
module_param(maxdev, int, 0); |
|
#elif defined(MODULE_PARM) |
|
MODULE_PARM(maxdev, "i"); |
|
#endif |
|
|
|
|
// MAC address is hardwired to that value as in windows version |
// MAC address is hardwired to that value as in windows version |
unsigned char station_addr[6] = { 0x00, 0x01, 0x23, 0x45, 0xBE, 0xEF }; |
static const unsigned char station_addr[5][6] = { |
#if 0 |
{ 0x00, 0x01, 0x23, 0x45, 0xBE, 0xEF }, |
hypervisorPresentInSystem(); /* fake call to hypervisor -- ms */ |
{ 0x00, 0x01, 0x23, 0x45, 0xCA, 0xFE }, |
#endif |
{ 0x00, 0x01, 0x23, 0x45, 0xDA, 0xCE }, |
|
{ 0x00, 0x01, 0x23, 0x45, 0xEC, 0xAE }, |
|
{ 0x00, 0x01, 0x23, 0x45, 0xFA, 0xDE } |
|
}; |
|
int i; |
|
|
|
if (maxdev < 0) |
|
maxdev = 1; |
|
if (maxdev > 5) |
|
maxdev = 5; |
|
for (i = 0; i < maxdev; ++i) { |
|
|
dev = alloc_etherdev(sizeof(struct net_device_stats)); |
devs[i] = alloc_etherdev(sizeof(struct net_device_stats)); |
|
|
dev = init_etherdev(0, 0); |
devs[i] = init_etherdev(0, 0); |
// May be it needed ? |
ether_setup(devs[i]); |
ether_setup(dev); |
devs[i]->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL); |
dev->priv = kmalloc(sizeof(struct net_device_stats), GFP_KERNEL); |
|
|
|
dev_alloc_name(dev, "vnic%d"); |
dev_alloc_name(devs[i], "vnic%d"); |
// Set MAC address |
// Set MAC address |
memcpy(dev->dev_addr, station_addr, ETH_ALEN); |
memcpy(devs[i]->dev_addr, station_addr[i], ETH_ALEN); |
memset(dev->priv, 0, sizeof(struct net_device_stats)); |
memset(devs[i]->priv, 0, sizeof(struct net_device_stats)); |
|
|
// Set functions |
// Set functions |
dev->hard_start_xmit = &VNICXmit; |
devs[i]->hard_start_xmit = VNICXmit; |
dev->get_stats = &VNICGetStats; |
devs[i]->get_stats = VNICGetStats; |
dev->open = &VNICOpen; |
devs[i]->open = VNICOpen; |
dev->stop = &VNICClose; |
devs[i]->stop = VNICClose; |
dev->set_mac_address = &VNICSetMAC; |
devs[i]->set_mac_address = VNICSetMAC; |
|
|
SET_MODULE_OWNER(dev); |
SET_MODULE_OWNER(devs[i]); |
|
|
register_netdev(dev); |
register_netdev(devs[i]); |
|
|
|
} |
return(0); |
return 0; |
}; |
} |
|
|
|
int i; |
|
|
if (dev) |
for (i = 0; i < 5; ++i) { |
{ |
if (devs[i]) { |
ndstat = dev->priv; |
ndstat = devs[i]->priv; |
|
|
unregister_netdev(dev); |
unregister_netdev(devs[i]); |
|
|
free_netdev(dev); |
free_netdev(devs[i]); |
|
|
kfree(ndstat); |
kfree(ndstat); |
dev->priv = NULL; |
devs[i]->priv = NULL; |
kfree(dev); |
kfree(devs[i]); |
|
|
|
devs[i] = NULL; |
|
} |
|
|
#ifndef __HYPERCALL_H__ |
|
#define __HYPERCALL_H__ |
|
|
#ifndef __PRL_HYPERCALL_H__ |
|
#define __PRL_HYPERCALL_H__ |
|
|
|
#endif /* __PRL_HYPERCALL_H__ */ |
#endif /* __HYPERCALL_H__ */ |
|
|
|
#ifndef __HYPERVISOR_H__ |
#ifndef __PRL_HYPERVISOR_H__ |
#define __HYPERVISOR_H__ |
#define __PRL_HYPERVISOR_H__ |
|
|
|
# include "compat_memory.h" |
|
|
kmem_cache_t *vmStateCache; |
kmem_cache_compat *vmStateCache; |
|
|
#endif /* __HYPERVISOR_H__ */ |
#endif /* __PRL_HYPERVISOR_H__ */ |
|
|
|
#include "compat_memory.h" |
|
|
if (!(hypState.vmStateCache = kmem_cache_create(VMSTATE_SLABNAME, sizeof(struct hyp_vmstate_t), 0, |
if (!(hypState.vmStateCache = compat_kmem_cache_create(VMSTATE_SLABNAME, sizeof(struct hyp_vmstate_t), 0, |
|
|
|
/// Definitions of AMD CPUID function to get SVM revision and feature identification |
|
#define CPUID_SVM_REV 0x8000000a |
|
|
|
|
|
|
|
/// Definition of bit SVM_LOCK in edx after CPUID_SVM_REV fn |
|
#define SVM_LOCK (1 << 2) |
|
|
|
/// Definition of bit SVM Disabled in VM_CR SMR |
|
#define VM_CR_SVMDIS (1 << 4) |
|
|
|
|
|
|
|
/// Definition of address of VM_CR SMR |
|
#define SMR_VM_CR 0xc0010114 |
|
|
|
|
|
|
|
/** |
|
* Check CPU provider. |
|
*/ |
|
static __inline__ int is_amd() |
|
{ |
|
unsigned int _ebx, _ecx, _edx; |
|
|
|
__asm__ __volatile__( |
|
"cpuid \n\t" |
|
: /* out */ "=b" (_ebx), "=c" (_ecx), "=d" (_edx) |
|
: /* in */ "a" (0) |
|
: /* clo */ "memory" |
|
); |
|
|
|
// "AuthenticAMD" |
|
if ((_ebx == 0x68747541) && |
|
(_ecx == 0x444D4163) && |
|
(_edx == 0x69746E65)) |
|
return 1; |
|
|
|
return 0; |
|
} |
|
|
/* Check SVM bit in CPUID extended features */ |
// Don't initialize this variables !!! |
return cpuid_ecx(CPUID_PROCESSOR_SIGNATURE) & CPUID_SVM; |
// because gcc on OSx remove all checks with this variables |
|
// and we can get wrmsr on locked msr register (which cause GP#) -- ms |
|
unsigned long msr_edx, msr_eax; |
|
unsigned int cpuid_1_ecx; |
|
unsigned int cpuid_2_edx; |
|
|
|
|
|
if (!is_amd()) |
|
return 0; |
|
|
|
msr_edx = 0; |
|
msr_eax = 0; |
|
|
|
// Check SVM bit in CPUID extended features |
|
cpuid_1_ecx = cpuid_ecx(CPUID_PROCESSOR_SIGNATURE); |
|
|
|
cpuid_2_edx = 0; |
|
|
|
// Check SVM bit in CPUID feature indentifiers |
|
if ((cpuid_1_ecx & CPUID_SVM) == 0) |
|
return 0; // SVM not available |
|
|
|
|
|
// Get VM_CR MSR value |
|
rdmsr(SMR_VM_CR, msr_eax, msr_edx); |
|
|
|
if((msr_eax & VM_CR_SVMDIS) == 0) |
|
{ |
|
// set EFER.SVME |
|
rdmsr(MSR_IA32_EFER, msr_eax, msr_edx); |
|
wrmsr(MSR_IA32_EFER, msr_eax | EFER_SVME, msr_edx); |
|
return 1; // SVM allowed |
|
} |
|
|
|
// CPUID SVM Revision and Feature Identification EDX |
|
cpuid_2_edx = cpuid_edx(CPUID_SVM_REV); |
|
|
|
if((cpuid_2_edx & SVM_LOCK) == 0) |
|
{ |
|
return 0; // SVM disabled at bios not unlockable |
|
} |
|
|
|
return 0; // SVM disabled with key |
|
|
|
|
|
|
|
/** |
|
* Check CPU provider. |
|
*/ |
|
static __inline__ int is_intelPW22() |
|
{ |
|
unsigned int _ebx, _ecx, _edx; |
|
|
|
__asm__ __volatile__( |
|
"cpuid \n\t" |
|
: /* out */ "=b" (_ebx), "=c" (_ecx), "=d" (_edx) |
|
: /* in */ "a" (0) |
|
: /* clo */ "memory" |
|
); |
|
|
|
// "GenuineIntel" |
|
if ((_ebx == 0x756e6547) && |
|
(_ecx == 0x6c65746e) && |
|
(_edx == 0x49656e69)) |
|
return 1; |
|
|
|
return 0; |
|
} |
|
|
|
if (!is_intelPW22()) |
|
return 0; |
|
|
|
|
|
KSRC ?= /lib/modules/$(shell uname -r)/build |
|
|
cd drv_main/ && $(MAKE) && cd .. |
cd drv_main/ && $(MAKE) KSRC=${KSRC} && cd .. |