mshyperv.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  15. * NON INFRINGEMENT. See the GNU General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. */
  23. #include <linux/types.h>
  24. #include <asm/processor.h>
  25. #include <asm/hyperv.h>
  26. #include <asm/mshyperv.h>
  27. int ms_hyperv_platform(void)
  28. {
  29. u32 eax, ebx, ecx, edx;
  30. char hyp_signature[13];
  31. cpuid(1, &eax, &ebx, &ecx, &edx);
  32. if (!(ecx & HYPERV_HYPERVISOR_PRESENT_BIT))
  33. return 0;
  34. cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS, &eax, &ebx, &ecx, &edx);
  35. *(u32 *)(hyp_signature + 0) = ebx;
  36. *(u32 *)(hyp_signature + 4) = ecx;
  37. *(u32 *)(hyp_signature + 8) = edx;
  38. if ((eax < HYPERV_CPUID_MIN) || (memcmp("Microsoft Hv", hyp_signature, 12)))
  39. return 0;
  40. return 1;
  41. }
  42. void __cpuinit ms_hyperv_set_feature_bits(struct cpuinfo_x86 *c)
  43. {
  44. u32 eax, ebx, ecx, edx;
  45. c->x86_hyper_features = 0;
  46. /*
  47. * Extract the features, recommendations etc.
  48. * The first 9 bits will be used to track hypervisor features.
  49. * The next 6 bits will be used to track the hypervisor
  50. * recommendations.
  51. */
  52. cpuid(HYPERV_CPUID_FEATURES, &eax, &ebx, &ecx, &edx);
  53. c->x86_hyper_features |= (eax & 0x1ff);
  54. cpuid(HYPERV_CPUID_ENLIGHTMENT_INFO, &eax, &ebx, &ecx, &edx);
  55. c->x86_hyper_features |= ((eax & 0x3f) << 9);
  56. printk(KERN_INFO "Detected HyperV with features: %x\n",
  57. c->x86_hyper_features);
  58. }