smc_internal_types_mac.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_POWER_METRICS_SMC_INTERNAL_TYPES_MAC_H_
  5. #define COMPONENTS_POWER_METRICS_SMC_INTERNAL_TYPES_MAC_H_
  6. #import <Foundation/Foundation.h>
  7. #include <stdint.h>
  8. // List of known SMC key identifiers.
  9. //
  10. // This is a good reference: https://logi.wiki/index.php/SMC_Sensor_Codes
  11. // Additional keys can be discovered with
  12. // https://github.com/theopolis/smc-fuzzer
  13. enum class SMCKeyIdentifier : uint32_t {
  14. TotalPower = 'PSTR', // Power: System Total Rail (watts)
  15. CPUPower = 'PCPC', // Power: CPU Package CPU (watts)
  16. iGPUPower = 'PCPG', // Power: CPU Package GPU (watts)
  17. GPU0Power = 'PG0R', // Power: GPU 0 Rail (watts)
  18. GPU1Power = 'PG1R', // Power: GPU 1 Rail (watts)
  19. CPUTemperature = 'TC0F', // Temperature: CPU Die PECI (Celsius)
  20. };
  21. // Types from PowerManagement/pmconfigd/PrivateLib.c
  22. // (https://opensource.apple.com/source/PowerManagement/PowerManagement-494.1.2/pmconfigd/PrivateLib.c.auto.html)
  23. struct SMCVersion {
  24. unsigned char major;
  25. unsigned char minor;
  26. unsigned char build;
  27. unsigned char reserved;
  28. unsigned short release;
  29. };
  30. struct SMCPLimitData {
  31. uint16_t version;
  32. uint16_t length;
  33. uint32_t cpuPLimit;
  34. uint32_t gpuPLimit;
  35. uint32_t memPLimit;
  36. };
  37. enum class SMCDataType : uint32_t {
  38. flt = 'flt ', // Floating point
  39. sp78 = 'sp78', // Fixed point: SIIIIIIIFFFFFFFF
  40. sp87 = 'sp87', // Fixed point: SIIIIIIIIFFFFFFF
  41. spa5 = 'spa5', // Fixed point: SIIIIIIIIIIFFFFF
  42. };
  43. struct SMCKeyInfoData {
  44. IOByteCount dataSize;
  45. SMCDataType dataType;
  46. uint8_t dataAttributes;
  47. };
  48. struct SMCParamStruct {
  49. SMCKeyIdentifier key;
  50. SMCVersion vers;
  51. SMCPLimitData pLimitData;
  52. SMCKeyInfoData keyInfo;
  53. uint8_t result;
  54. uint8_t status;
  55. uint8_t data8;
  56. uint32_t data32;
  57. uint8_t bytes[32];
  58. };
  59. enum {
  60. kSMCUserClientOpen = 0,
  61. kSMCUserClientClose = 1,
  62. kSMCHandleYPCEvent = 2,
  63. kSMCReadKey = 5,
  64. kSMCWriteKey = 6,
  65. kSMCGetKeyCount = 7,
  66. kSMCGetKeyFromIndex = 8,
  67. kSMCGetKeyInfo = 9
  68. };
  69. #endif // COMPONENTS_POWER_METRICS_SMC_INTERNAL_TYPES_MAC_H_