1 /*
2 * TISCI Protocol header file.
3 *
4 * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
5 * Lokesh Vutla <lokeshvutla@ti.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the
17 * distribution.
18 *
19 * Neither the name of Texas Instruments Incorporated nor the names of
20 * its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
36 #ifndef __TISCI_P_H
37 #define __TISCI_P_H
39 #include <stdint.h>
40 #include <sec_proxy.h>
42 #define TI_SCI_MSG_VERSION 0x0002
43 /* Device requests */
44 #define TI_SCI_MSG_SET_DEVICE_STATE 0x0200
45 #define TI_SCI_MSG_GET_DEVICE_STATE 0x0201
46 /* Clock requests */
47 #define TI_SCI_MSG_SET_CLOCK_STATE 0x0100
48 #define TI_SCI_MSG_GET_CLOCK_STATE 0x0101
49 #define TI_SCI_MSG_SET_CLOCK_FREQ 0x010c
50 #define TI_SCI_MSG_QUERY_CLOCK_FREQ 0x010d
51 #define TI_SCI_MSG_GET_CLOCK_FREQ 0x010e
52 /* Resource Management Requests */
53 #define TI_SCI_MSG_GET_RESOURCE_RANGE 0x1500
55 #define TI_SCI_MSG_FLAG(val) (1 << (val))
56 #define TI_SCI_FLAG_REQ_GENERIC_NORESPONSE 0x0
57 #define TI_SCI_FLAG_REQ_ACK_ON_RECEIVED TI_SCI_MSG_FLAG(0)
58 #define TI_SCI_FLAG_REQ_ACK_ON_PROCESSED TI_SCI_MSG_FLAG(1)
59 #define TI_SCI_FLAG_RESP_GENERIC_NACK 0x0
60 #define TI_SCI_FLAG_RESP_GENERIC_ACK TI_SCI_MSG_FLAG(1)
62 struct ti_sci_msg_hdr {
63 uint16_t type;
64 uint8_t host;
65 uint8_t seq;
66 uint32_t flags;
67 } __attribute__ ((__packed__));
69 struct ti_sci_msg_resp_version {
70 struct ti_sci_msg_hdr hdr;
71 char firmware_description[32];
72 uint16_t version;
73 uint8_t abi_major;
74 uint8_t abi_minor;
75 } __attribute__ ((__packed__));
77 struct ti_sci_secure_msg_hdr {
78 uint16_t checksum;
79 uint16_t reserved;
80 } __attribute__ ((__packed__));
82 struct ti_sci_msg_req_set_device_state {
83 /* Additional hdr->flags options */
84 #define MSG_FLAG_DEVICE_WAKE_ENABLED TI_SCI_MSG_FLAG(8)
85 #define MSG_FLAG_DEVICE_RESET_ISO TI_SCI_MSG_FLAG(9)
86 #define MSG_FLAG_DEVICE_EXCLUSIVE TI_SCI_MSG_FLAG(10)
87 struct ti_sci_msg_hdr hdr;
88 uint32_t id;
89 uint32_t reserved;
90 #define MSG_DEVICE_SW_STATE_AUTO_OFF 0
91 #define MSG_DEVICE_SW_STATE_RETENTION 1
92 #define MSG_DEVICE_SW_STATE_ON 2
93 uint8_t state;
94 } __attribute__ ((__packed__));
96 struct ti_sci_msg_req_get_device_state {
97 struct ti_sci_msg_hdr hdr;
98 uint32_t id;
99 } __attribute__ ((__packed__));
101 struct ti_sci_msg_resp_get_device_state {
102 struct ti_sci_msg_hdr hdr;
103 uint32_t context_loss_count;
104 uint32_t resets;
105 uint8_t programmed_state;
106 #define MSG_DEVICE_HW_STATE_OFF 0
107 #define MSG_DEVICE_HW_STATE_ON 1
108 #define MSG_DEVICE_HW_STATE_TRANS 2
109 #define MAX_DEVICE_HW_STATES 3
110 uint8_t current_state;
111 } __attribute__ ((__packed__));
113 struct ti_sci_msg_req_get_resource_range {
114 struct ti_sci_msg_hdr hdr;
115 #define MSG_RM_RESOURCE_TYPE_MASK 0x3ff
116 #define MSG_RM_RESOURCE_SUBTYPE_MASK 0x3f
117 uint16_t type;
118 uint8_t subtype;
119 uint8_t secondary_host;
120 } __attribute__ ((__packed__));
122 struct ti_sci_msg_resp_get_resource_range {
123 struct ti_sci_msg_hdr hdr;
124 uint16_t range_start;
125 uint16_t range_num;
126 uint16_t range_start_sec;
127 uint16_t range_num_sec;
128 } __attribute__ ((__packed__));
130 struct ti_sci_msg_req_set_clock_state {
131 /* Additional hdr->flags options */
132 #define MSG_FLAG_CLOCK_ALLOW_SSC TI_SCI_MSG_FLAG(8)
133 #define MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE TI_SCI_MSG_FLAG(9)
134 #define MSG_FLAG_CLOCK_INPUT_TERM TI_SCI_MSG_FLAG(10)
135 struct ti_sci_msg_hdr hdr;
136 uint32_t dev_id;
137 uint8_t clk_id;
138 #define MSG_CLOCK_SW_STATE_UNREQ 0
139 #define MSG_CLOCK_SW_STATE_AUTO 1
140 #define MSG_CLOCK_SW_STATE_REQ 2
141 uint8_t request_state;
142 uint32_t clk_id_32;
143 } __attribute__ ((__packed__));
145 struct ti_sci_msg_req_get_clock_state {
146 struct ti_sci_msg_hdr hdr;
147 uint32_t dev_id;
148 uint8_t clk_id;
149 uint32_t clk_id_32;
150 } __attribute__ ((__packed__));
152 struct ti_sci_msg_resp_get_clock_state {
153 struct ti_sci_msg_hdr hdr;
154 uint8_t programmed_state;
155 #define MSG_CLOCK_HW_STATE_NOT_READY 0
156 #define MSG_CLOCK_HW_STATE_READY 1
157 #define MAX_CLOCK_HW_STATES 2
158 uint8_t current_state;
159 } __attribute__ ((__packed__));
161 struct ti_sci_msg_req_query_clock_freq {
162 struct ti_sci_msg_hdr hdr;
163 uint32_t dev_id;
164 uint64_t min_freq_hz;
165 uint64_t target_freq_hz;
166 uint64_t max_freq_hz;
167 uint8_t clk_id;
168 uint32_t clk_id_32;
169 } __attribute__ ((__packed__));
171 struct ti_sci_msg_resp_query_clock_freq {
172 struct ti_sci_msg_hdr hdr;
173 uint64_t freq_hz;
174 } __attribute__ ((__packed__));
176 struct ti_sci_msg_req_set_clock_freq {
177 struct ti_sci_msg_hdr hdr;
178 uint32_t dev_id;
179 uint64_t min_freq_hz;
180 uint64_t target_freq_hz;
181 uint64_t max_freq_hz;
182 uint8_t clk_id;
183 uint32_t clk_id_32;
184 } __attribute__ ((__packed__));
186 struct ti_sci_msg_req_get_clock_freq {
187 struct ti_sci_msg_hdr hdr;
188 uint32_t dev_id;
189 uint8_t clk_id;
190 uint32_t clk_id_32;
191 } __attribute__ ((__packed__));
193 struct ti_sci_msg_resp_get_clock_freq {
194 struct ti_sci_msg_hdr hdr;
195 uint64_t freq_hz;
196 } __attribute__ ((__packed__));
198 void ti_sci_setup_header(struct ti_sci_msg_hdr *hdr, uint16_t type,
199 uint32_t flags);
200 int ti_sci_xfer_msg(struct k3_sec_proxy_msg *msg);
202 static inline uint8_t ti_sci_is_response_ack(uint8_t *resp)
203 {
204 struct ti_sci_msg_hdr *hdr = (struct ti_sci_msg_hdr *)resp;
206 return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? 1 : 0;
207 }
209 #endif