librapl.c 607 B

12345678910111213141516171819202122232425262728293031323334
  1. // SPDX-License-Identifier: MIT
  2. /*
  3. * Copyright © 2020 Intel Corporation
  4. */
  5. #include <asm/msr.h>
  6. #include "i915_drv.h"
  7. #include "librapl.h"
  8. bool librapl_supported(const struct drm_i915_private *i915)
  9. {
  10. /* Discrete cards require hwmon integration */
  11. if (IS_DGFX(i915))
  12. return false;
  13. return librapl_energy_uJ();
  14. }
  15. u64 librapl_energy_uJ(void)
  16. {
  17. unsigned long long power;
  18. u32 units;
  19. if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power))
  20. return 0;
  21. units = (power & 0x1f00) >> 8;
  22. if (rdmsrl_safe(MSR_PP1_ENERGY_STATUS, &power))
  23. return 0;
  24. return (1000000 * power) >> units; /* convert to uJ */
  25. }