scmi_sensor.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. * Description:
  7. * System Control and Management Interface (SCMI) support.
  8. */
  9. #ifndef INTERNAL_SCMI_SENSOR_H
  10. #define INTERNAL_SCMI_SENSOR_H
  11. #include <stdint.h>
  12. #define SCMI_PROTOCOL_VERSION_SENSOR UINT32_C(0x10000)
  13. /*
  14. * PROTOCOL_ATTRIBUTES
  15. */
  16. struct scmi_sensor_protocol_attributes_p2a {
  17. int32_t status;
  18. uint32_t attributes;
  19. uint32_t sensor_reg_address_low;
  20. uint32_t sensor_reg_address_high;
  21. uint32_t sensor_reg_len;
  22. };
  23. /*
  24. * SENSOR_READING_GET
  25. */
  26. #define SCMI_SENSOR_PROTOCOL_READING_GET_ASYNC_FLAG_MASK (1 << 0)
  27. struct scmi_sensor_protocol_reading_get_a2p {
  28. uint32_t sensor_id;
  29. uint32_t flags;
  30. };
  31. struct scmi_sensor_protocol_reading_get_p2a {
  32. int32_t status;
  33. uint32_t sensor_value_low;
  34. uint32_t sensor_value_high;
  35. };
  36. /*
  37. * SENSOR_DESCRIPTION_GET
  38. */
  39. #define SCMI_SENSOR_DESCS_MAX(MAILBOX_SIZE) \
  40. ((sizeof(struct scmi_sensor_protocol_description_get_p2a) < MAILBOX_SIZE) \
  41. ? ((MAILBOX_SIZE - \
  42. sizeof(struct scmi_sensor_protocol_description_get_p2a)) \
  43. / sizeof(struct scmi_sensor_desc)) \
  44. : 0)
  45. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_TYPE_POS 0
  46. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_POS 11
  47. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_POS 22
  48. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_POS 27
  49. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_TYPE_MASK \
  50. (UINT32_C(0xFF) << SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_TYPE_POS)
  51. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MASK \
  52. (UINT32_C(0x1F) << SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_POS)
  53. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_MASK \
  54. (UINT32_C(0x1F) << \
  55. SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_POS)
  56. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_MASK \
  57. (UINT32_C(0x1F) << SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_POS)
  58. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MAX \
  59. (int32_t)(SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MASK >> 1)
  60. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MIN \
  61. (-(SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MAX + 1))
  62. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_MAX \
  63. (int32_t)(SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_MASK >> 1)
  64. #define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_MIN \
  65. (-(SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_MAX + 1))
  66. #define SCMI_SENSOR_DESC_ATTRIBUTES_HIGH(SENSOR_TYPE, UNIT_MULTIPLIER, \
  67. UPDATE_MULTIPLIER, UPDATE_INTERVAL) \
  68. ( \
  69. (((SENSOR_TYPE) << \
  70. SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_TYPE_POS) & \
  71. SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_TYPE_MASK) | \
  72. (((UNIT_MULTIPLIER) << \
  73. SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_POS) & \
  74. SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MASK) | \
  75. (((UPDATE_MULTIPLIER) << \
  76. SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_POS) & \
  77. SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_MASK) | \
  78. (((UPDATE_INTERVAL) << \
  79. SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_POS) & \
  80. SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_MASK) \
  81. )
  82. #define SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_DESCS_POS 0
  83. #define SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_REMAINING_DESCS_POS 16
  84. #define SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_DESCS_MASK \
  85. (UINT32_C(0xFFF) << SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_DESCS_POS)
  86. #define SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_REMAINING_DESCS_MASK \
  87. (UINT32_C(0xFFFF) << SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_REMAINING_DESCS_POS)
  88. #define SCMI_SENSOR_NUM_SENSOR_FLAGS(NUM_DESCS, NUM_REMAINING_DESCS) \
  89. ( \
  90. (((NUM_DESCS) << \
  91. SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_DESCS_POS) & \
  92. SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_DESCS_MASK) | \
  93. (((NUM_REMAINING_DESCS) << \
  94. SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_REMAINING_DESCS_POS) & \
  95. SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_REMAINING_DESCS_MASK) \
  96. )
  97. #define SCMI_SENSOR_NAME_LEN 16
  98. struct scmi_sensor_desc {
  99. uint32_t sensor_id;
  100. uint32_t sensor_attributes_low;
  101. uint32_t sensor_attributes_high;
  102. char sensor_name[SCMI_SENSOR_NAME_LEN];
  103. };
  104. struct scmi_sensor_protocol_description_get_a2p {
  105. uint32_t desc_index;
  106. };
  107. struct scmi_sensor_protocol_description_get_p2a {
  108. int32_t status;
  109. uint32_t num_sensor_flags;
  110. struct scmi_sensor_desc sensor_desc[];
  111. };
  112. /* Event indices */
  113. enum scmi_sensor_api_idx {
  114. SCMI_SENSOR_EVENT_IDX_REQUEST,
  115. SCMI_SENSOR_EVENT_IDX_COUNT,
  116. };
  117. #endif /* INTERNAL_SCMI_SENSOR_H */