blob: 5dab898697162746fade7a8dd0d3158258a23ab0 [file] [log] [blame]
Jacky Bai4d93d1d2020-07-02 14:39:58 +08001/*
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
10#ifndef INTERNAL_SCMI_SENSOR_H
11#define INTERNAL_SCMI_SENSOR_H
12
13#include <stdint.h>
14
15#define SCMI_PROTOCOL_VERSION_SENSOR UINT32_C(0x10000)
16
17/*
18 * PROTOCOL_ATTRIBUTES
19 */
20struct scmi_sensor_protocol_attributes_p2a {
21 int32_t status;
22 uint32_t attributes;
23 uint32_t sensor_reg_address_low;
24 uint32_t sensor_reg_address_high;
25 uint32_t sensor_reg_len;
26};
27
28/*
29 * SENSOR_READING_GET
30 */
31#define SCMI_SENSOR_PROTOCOL_READING_GET_ASYNC_FLAG_MASK (1 << 0)
32
33struct scmi_sensor_protocol_reading_get_a2p {
34 uint32_t sensor_id;
35 uint32_t flags;
36};
37
38struct scmi_sensor_protocol_reading_get_p2a {
39 int32_t status;
40 uint32_t sensor_value_low;
41 uint32_t sensor_value_high;
42};
43
44/*
45 * SENSOR_DESCRIPTION_GET
46 */
47 #define SCMI_SENSOR_DESCS_MAX(MAILBOX_SIZE) \
48 ((sizeof(struct scmi_sensor_protocol_description_get_p2a) < MAILBOX_SIZE) \
49 ? ((MAILBOX_SIZE - \
50 sizeof(struct scmi_sensor_protocol_description_get_p2a)) \
51 / sizeof(struct scmi_sensor_desc)) \
52 : 0)
53
54#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_TYPE_POS 0
55#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_POS 11
56#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_POS 22
57#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_POS 27
58
59#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_TYPE_MASK \
60 (UINT32_C(0xFF) << SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_TYPE_POS)
61#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MASK \
62 (UINT32_C(0x1F) << SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_POS)
63#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_MASK \
64 (UINT32_C(0x1F) << \
65 SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_POS)
66#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_MASK \
67 (UINT32_C(0x1F) << SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_POS)
68
69#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MAX \
70 (int32_t)(SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MASK >> 1)
71#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MIN \
72 (-(SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MAX + 1))
73
74#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_MAX \
75 (int32_t)(SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_MASK >> 1)
76#define SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_MIN \
77 (-(SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_MAX + 1))
78
79#define SCMI_SENSOR_DESC_ATTRIBUTES_HIGH(SENSOR_TYPE, UNIT_MULTIPLIER, \
80 UPDATE_MULTIPLIER, UPDATE_INTERVAL) \
81 ( \
82 (((SENSOR_TYPE) << \
83 SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_TYPE_POS) & \
84 SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_TYPE_MASK) | \
85 (((UNIT_MULTIPLIER) << \
86 SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_POS) & \
87 SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UNIT_MULTIPLIER_MASK) | \
88 (((UPDATE_MULTIPLIER) << \
89 SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_POS) & \
90 SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_MULTIPLIER_MASK) | \
91 (((UPDATE_INTERVAL) << \
92 SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_POS) & \
93 SCMI_SENSOR_DESC_ATTRS_HIGH_SENSOR_UPDATE_INTERVAL_MASK) \
94 )
95
96#define SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_DESCS_POS 0
97#define SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_REMAINING_DESCS_POS 16
98
99#define SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_DESCS_MASK \
100 (UINT32_C(0xFFF) << SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_DESCS_POS)
101#define SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_REMAINING_DESCS_MASK \
102 (UINT32_C(0xFFFF) << SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_REMAINING_DESCS_POS)
103
104#define SCMI_SENSOR_NUM_SENSOR_FLAGS(NUM_DESCS, NUM_REMAINING_DESCS) \
105 ( \
106 (((NUM_DESCS) << \
107 SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_DESCS_POS) & \
108 SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_DESCS_MASK) | \
109 (((NUM_REMAINING_DESCS) << \
110 SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_REMAINING_DESCS_POS) & \
111 SCMI_SENSOR_NUM_SENSOR_FLAGS_NUM_REMAINING_DESCS_MASK) \
112 )
113
114#define SCMI_SENSOR_NAME_LEN 16
115
116struct scmi_sensor_desc {
117 uint32_t sensor_id;
118 uint32_t sensor_attributes_low;
119 uint32_t sensor_attributes_high;
120 char sensor_name[SCMI_SENSOR_NAME_LEN];
121};
122
123struct scmi_sensor_protocol_description_get_a2p {
124 uint32_t desc_index;
125};
126
127struct scmi_sensor_protocol_description_get_p2a {
128 int32_t status;
129 uint32_t num_sensor_flags;
130 struct scmi_sensor_desc sensor_desc[];
131};
132
133/* Event indices */
134enum scmi_sensor_api_idx {
135 SCMI_SENSOR_EVENT_IDX_REQUEST,
136 SCMI_SENSOR_EVENT_IDX_COUNT,
137};
138
139#endif /* INTERNAL_SCMI_SENSOR_H */