cppc.rs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. use sbi_spec::binary::SbiRet;
  2. /// SBI CPPC support extension.
  3. ///
  4. /// ACPI defines the Collaborative Processor Performance Control (CPPC) mechanism,
  5. /// which is an abstract and flexible mechanism for the supervisor-mode
  6. /// power-management software to collaborate with an entity in the platform to
  7. /// manage the performance of the processors.
  8. ///
  9. /// The SBI CPPC extension provides an abstraction to access the CPPC registers
  10. /// through SBI calls. The CPPC registers can be memory locations shared with a
  11. /// separate platform entity such as a BMC. Even though CPPC is defined in the ACPI
  12. /// specification, it may be possible to implement a CPPC driver based on
  13. /// Device Tree.
  14. ///
  15. /// The table below defines 32-bit identifiers for all CPPC registers
  16. /// to be used by the SBI CPPC functions. The first half of the 32-bit register
  17. /// space corresponds to the registers as defined by the ACPI specification.
  18. /// The second half provides the information not defined in the ACPI specification,
  19. /// but is additionally required by the supervisor-mode power-management software.
  20. ///
  21. /// | Register ID | Register | Bit Width | Attribute | Description
  22. /// | ----------------------- | ------------------------------------- | --------- | ------------ | ---------------------------
  23. /// | 0x00000000 | HighestPerformance | 32 | Read-only | ACPI Spec 6.5: 8.4.6.1.1.1
  24. /// | 0x00000001 | NominalPerformance | 32 | Read-only | ACPI Spec 6.5: 8.4.6.1.1.2
  25. /// | 0x00000002 | LowestNonlinearPerformance | 32 | Read-only | ACPI Spec 6.5: 8.4.6.1.1.4
  26. /// | 0x00000003 | LowestPerformance | 32 | Read-only | ACPI Spec 6.5: 8.4.6.1.1.5
  27. /// | 0x00000004 | GuaranteedPerformanceRegister | 32 | Read-only | ACPI Spec 6.5: 8.4.6.1.1.6
  28. /// | 0x00000005 | DesiredPerformanceRegister | 32 | Read / Write | ACPI Spec 6.5: 8.4.6.1.2.3
  29. /// | 0x00000006 | MinimumPerformanceRegister | 32 | Read / Write | ACPI Spec 6.5: 8.4.6.1.2.2
  30. /// | 0x00000007 | MaximumPerformanceRegister | 32 | Read / Write | ACPI Spec 6.5: 8.4.6.1.2.1
  31. /// | 0x00000008 | PerformanceReductionToleranceRegister | 32 | Read / Write | ACPI Spec 6.5: 8.4.6.1.2.4
  32. /// | 0x00000009 | TimeWindowRegister | 32 | Read / Write | ACPI Spec 6.5: 8.4.6.1.2.5
  33. /// | 0x0000000A | CounterWraparoundTime | 32 / 64 | Read-only | ACPI Spec 6.5: 8.4.6.1.3.1
  34. /// | 0x0000000B | ReferencePerformanceCounterRegister | 32 / 64 | Read-only | ACPI Spec 6.5: 8.4.6.1.3.1
  35. /// | 0x0000000C | DeliveredPerformanceCounterRegister | 32 / 64 | Read-only | ACPI Spec 6.5: 8.4.6.1.3.1
  36. /// | 0x0000000D | PerformanceLimitedRegister | 32 | Read / Write | ACPI Spec 6.5: 8.4.6.1.3.2
  37. /// | 0x0000000E | CPPCEnableRegister | 32 | Read / Write | ACPI Spec 6.5: 8.4.6.1.4
  38. /// | 0x0000000F | AutonomousSelectionEnable | 32 | Read / Write | ACPI Spec 6.5: 8.4.6.1.5
  39. /// | 0x00000010 | AutonomousActivityWindowRegister | 32 | Read / Write | ACPI Spec 6.5: 8.4.6.1.6
  40. /// | 0x00000011 | EnergyPerformancePreferenceRegister | 32 | Read / Write | ACPI Spec 6.5: 8.4.6.1.7
  41. /// | 0x00000012 | ReferencePerformance | 32 | Read-only | ACPI Spec 6.5: 8.4.6.1.1.3
  42. /// | 0x00000013 | LowestFrequency | 32 | Read-only | ACPI Spec 6.5: 8.4.6.1.1.7
  43. /// | 0x00000014 | NominalFrequency | 32 | Read-only | ACPI Spec 6.5: 8.4.6.1.1.7
  44. /// | 0x00000015 - 0x7FFFFFFF | | | | Reserved for future use.
  45. /// | 0x80000000 | TransitionLatency | 32 | Read-only | Provides the maximum (worst-case) performance state transition latency in nanoseconds.
  46. /// | 0x80000001 - 0xFFFFFFFF | | | | Reserved for future use.
  47. ///
  48. pub trait Cppc {
  49. /// Probe whether the CPPC register as specified by the `reg_id` parameter
  50. /// is implemented or not by the platform.
  51. ///
  52. /// # Return value
  53. ///
  54. /// If the register is implemented, `SbiRet.value` will contain the register
  55. /// width. If the register is not implemented, `SbiRet.value` will be set to 0.
  56. ///
  57. /// The possible return error codes returned in `SbiRet.error` are shown in the table below:
  58. ///
  59. /// | Error code | Description
  60. /// | ------------------------- | ---------------
  61. /// | `SbiRet::success()` | Probe completed successfully.
  62. /// | `SbiRet::invalid_param()` | `reg_id` is reserved.
  63. /// | `SbiRet::failed()` | The probe request failed for unspecified or unknown other reasons.
  64. fn probe(&self, reg_id: u32) -> SbiRet;
  65. /// Reads the register as specified in the `reg_id` parameter.
  66. ///
  67. /// # Return value
  68. ///
  69. /// Returns the value of the register in `SbiRet.value`. When supervisor mode XLEN is 32,
  70. /// the `SbiRet.value` will only contain the lower 32 bits of the CPPC register value.
  71. ///
  72. /// The possible return error codes returned in `SbiRet.error` are shown in the table below:
  73. ///
  74. /// | Error code | Description
  75. /// | ------------------------- | -------------------
  76. /// | `SbiRet::success()` | Read completed successfully.
  77. /// | `SbiRet::invalid_param()` | `reg_id` is reserved.
  78. /// | `SbiRet::not_supported()` | `reg_id` is not implemented by the platform.
  79. /// | `SbiRet::denied()` | `reg_id` is a write-only register.
  80. /// | `SbiRet::failed()` | The read request failed for unspecified or unknown other reasons.
  81. fn read(&self, reg_id: u32) -> SbiRet;
  82. /// Reads the upper 32-bit value of the register specified in the `reg_id`
  83. /// parameter.
  84. ///
  85. /// # Return value
  86. ///
  87. /// Returns the value of the register in `SbiRet.value`. This function always
  88. /// returns zero in `SbiRet.value` when supervisor mode XLEN is 64 or higher.
  89. ///
  90. /// The possible return error codes returned in `SbiRet.error` are shown in the table below:
  91. ///
  92. /// | Error code | Description
  93. /// | ------------------------- | -------------------
  94. /// | `SbiRet::success()` | Read completed successfully.
  95. /// | `SbiRet::invalid_param()` | `reg_id` is reserved.
  96. /// | `SbiRet::not_supported()` | `reg_id` is not implemented by the platform.
  97. /// | `SbiRet::denied()` | `reg_id` is a write-only register.
  98. /// | `SbiRet::failed()` | The read request failed for unspecified or unknown other reasons.
  99. fn read_hi(&self, reg_id: u32) -> SbiRet;
  100. /// Writes the value passed in the `val` parameter to the register as
  101. /// specified in the `reg_id` parameter.
  102. ///
  103. /// # Return value
  104. ///
  105. /// The possible return error codes returned in `SbiRet.error` are shown in the table below:
  106. ///
  107. /// | Error code | Description
  108. /// | ------------------------- | -------------------
  109. /// | `SbiRet::success()` | Write completed successfully.
  110. /// | `SbiRet::invalid_param()` | `reg_id` is reserved.
  111. /// | `SbiRet::not_supported()` | `reg_id` is not implemented by the platform.
  112. /// | `SbiRet::denied()` | `reg_id` is a read-only register.
  113. /// | `SbiRet::failed()` | The write request failed for unspecified or unknown other reasons.
  114. fn write(&self, reg_id: u32, val: u64) -> SbiRet;
  115. }
  116. impl<T: Cppc> Cppc for &T {
  117. #[inline]
  118. fn probe(&self, reg_id: u32) -> SbiRet {
  119. T::probe(self, reg_id)
  120. }
  121. #[inline]
  122. fn read(&self, reg_id: u32) -> SbiRet {
  123. T::read(self, reg_id)
  124. }
  125. #[inline]
  126. fn read_hi(&self, reg_id: u32) -> SbiRet {
  127. T::read_hi(self, reg_id)
  128. }
  129. #[inline]
  130. fn write(&self, reg_id: u32, val: u64) -> SbiRet {
  131. T::write(self, reg_id, val)
  132. }
  133. }