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