mshyperv.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * HyperV Detection code.
  3. *
  4. * Copyright (C) 2010, Novell, Inc.
  5. * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. */
  12. #include <linux/types.h>
  13. #include <asm/processor.h>
  14. #include <asm/hyperv.h>
  15. #include <asm/mshyperv.h>
  16. int ms_hyperv_platform(void)
  17. {
  18. u32 eax, ebx, ecx, edx;
  19. char hyp_signature[13];
  20. cpuid(1, &eax, &ebx, &ecx, &edx);
  21. if (!(ecx & HYPERV_HYPERVISOR_PRESENT_BIT))
  22. return 0;
  23. cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS, &eax, &ebx, &ecx, &edx);
  24. *(u32 *)(hyp_signature + 0) = ebx;
  25. *(u32 *)(hyp_signature + 4) = ecx;
  26. *(u32 *)(hyp_signature + 8) = edx;
  27. if ((eax < HYPERV_CPUID_MIN) || (memcmp("Microsoft Hv", hyp_signature, 12)))
  28. return 0;
  29. return 1;
  30. }
  31. void __cpuinit ms_hyperv_set_feature_bits(struct cpuinfo_x86 *c)
  32. {
  33. u32 eax, ebx, ecx, edx;
  34. c->x86_hyper_features = 0;
  35. /*
  36. * Extract the features, recommendations etc.
  37. * The first 9 bits will be used to track hypervisor features.
  38. * The next 6 bits will be used to track the hypervisor
  39. * recommendations.
  40. */
  41. cpuid(HYPERV_CPUID_FEATURES, &eax, &ebx, &ecx, &edx);
  42. c->x86_hyper_features |= (eax & 0x1ff);
  43. cpuid(HYPERV_CPUID_ENLIGHTMENT_INFO, &eax, &ebx, &ecx, &edx);
  44. c->x86_hyper_features |= ((eax & 0x3f) << 9);
  45. printk(KERN_INFO "Detected HyperV with features: %x\n",
  46. c->x86_hyper_features);
  47. }