xref: /rk3399_ARM-atf/drivers/nxp/scmi/vendor/scmi_imx9.c (revision 480e8dd9df291cc0e31695983fa6ff235e1671cd)
1*dbfe9df8SPeng Fan /*
2*dbfe9df8SPeng Fan  * Copyright 2023-2025 NXP
3*dbfe9df8SPeng Fan  *
4*dbfe9df8SPeng Fan  * SPDX-License-Identifier: BSD-3-Clause
5*dbfe9df8SPeng Fan  */
6*dbfe9df8SPeng Fan 
7*dbfe9df8SPeng Fan #include <assert.h>
8*dbfe9df8SPeng Fan 
9*dbfe9df8SPeng Fan #include <arch_helpers.h>
10*dbfe9df8SPeng Fan #include <common/debug.h>
11*dbfe9df8SPeng Fan #include <drivers/arm/css/scmi.h>
12*dbfe9df8SPeng Fan #include "scmi_imx9.h"
13*dbfe9df8SPeng Fan #include <scmi_private.h>
14*dbfe9df8SPeng Fan 
15*dbfe9df8SPeng Fan /*
16*dbfe9df8SPeng Fan  * API to set the SCMI AP core reset address and attributes
17*dbfe9df8SPeng Fan  */
scmi_core_set_reset_addr(void * p,uint64_t reset_addr,uint32_t cpu_id,uint32_t attr)18*dbfe9df8SPeng Fan int scmi_core_set_reset_addr(void *p, uint64_t reset_addr, uint32_t cpu_id,
19*dbfe9df8SPeng Fan 			     uint32_t attr)
20*dbfe9df8SPeng Fan {
21*dbfe9df8SPeng Fan 	mailbox_mem_t *mbx_mem;
22*dbfe9df8SPeng Fan 	unsigned int token = 0U;
23*dbfe9df8SPeng Fan 	int ret;
24*dbfe9df8SPeng Fan 	scmi_channel_t *ch = (scmi_channel_t *)p;
25*dbfe9df8SPeng Fan 
26*dbfe9df8SPeng Fan 	validate_scmi_channel(ch);
27*dbfe9df8SPeng Fan 
28*dbfe9df8SPeng Fan 	scmi_get_channel(ch);
29*dbfe9df8SPeng Fan 
30*dbfe9df8SPeng Fan 	mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
31*dbfe9df8SPeng Fan 	mbx_mem->msg_header = SCMI_MSG_CREATE(IMX9_SCMI_CORE_PROTO_ID,
32*dbfe9df8SPeng Fan 			IMX9_SCMI_CORE_RESET_ADDR_SET_MSG, token);
33*dbfe9df8SPeng Fan 	mbx_mem->len = IMX9_SCMI_CORE_RESET_ADDR_SET_MSG_LEN;
34*dbfe9df8SPeng Fan 	mbx_mem->flags = SCMI_FLAG_RESP_POLL;
35*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_ARG4(mbx_mem->payload, cpu_id, attr,
36*dbfe9df8SPeng Fan 			  reset_addr & 0xffffffff, reset_addr >> 32);
37*dbfe9df8SPeng Fan 
38*dbfe9df8SPeng Fan 	scmi_send_sync_command(ch);
39*dbfe9df8SPeng Fan 
40*dbfe9df8SPeng Fan 	/* Get the return values */
41*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
42*dbfe9df8SPeng Fan 	assert(mbx_mem->len == IMX9_SCMI_CORE_RESET_ADDR_SET_RESP_LEN);
43*dbfe9df8SPeng Fan 	assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
44*dbfe9df8SPeng Fan 
45*dbfe9df8SPeng Fan 	scmi_put_channel(ch);
46*dbfe9df8SPeng Fan 
47*dbfe9df8SPeng Fan 	return ret;
48*dbfe9df8SPeng Fan }
49*dbfe9df8SPeng Fan 
scmi_core_start(void * p,uint32_t cpu_id)50*dbfe9df8SPeng Fan int scmi_core_start(void *p, uint32_t cpu_id)
51*dbfe9df8SPeng Fan {
52*dbfe9df8SPeng Fan 	mailbox_mem_t *mbx_mem;
53*dbfe9df8SPeng Fan 	unsigned int token = 0U;
54*dbfe9df8SPeng Fan 	int ret;
55*dbfe9df8SPeng Fan 	scmi_channel_t *ch = (scmi_channel_t *)p;
56*dbfe9df8SPeng Fan 
57*dbfe9df8SPeng Fan 	validate_scmi_channel(ch);
58*dbfe9df8SPeng Fan 
59*dbfe9df8SPeng Fan 	scmi_get_channel(ch);
60*dbfe9df8SPeng Fan 
61*dbfe9df8SPeng Fan 	mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
62*dbfe9df8SPeng Fan 	mbx_mem->msg_header = SCMI_MSG_CREATE(IMX9_SCMI_CORE_PROTO_ID,
63*dbfe9df8SPeng Fan 			IMX9_SCMI_CORE_START_MSG, token);
64*dbfe9df8SPeng Fan 	mbx_mem->len = IMX9_SCMI_CORE_START_MSG_LEN;
65*dbfe9df8SPeng Fan 	mbx_mem->flags = SCMI_FLAG_RESP_POLL;
66*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_ARG1(mbx_mem->payload, cpu_id);
67*dbfe9df8SPeng Fan 
68*dbfe9df8SPeng Fan 	scmi_send_sync_command(ch);
69*dbfe9df8SPeng Fan 
70*dbfe9df8SPeng Fan 	/* Get the return values */
71*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
72*dbfe9df8SPeng Fan 	assert(mbx_mem->len == IMX9_SCMI_CORE_START_RESP_LEN);
73*dbfe9df8SPeng Fan 	assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
74*dbfe9df8SPeng Fan 
75*dbfe9df8SPeng Fan 	scmi_put_channel(ch);
76*dbfe9df8SPeng Fan 
77*dbfe9df8SPeng Fan 	return ret;
78*dbfe9df8SPeng Fan }
79*dbfe9df8SPeng Fan 
scmi_core_stop(void * p,uint32_t cpu_id)80*dbfe9df8SPeng Fan int scmi_core_stop(void *p, uint32_t cpu_id)
81*dbfe9df8SPeng Fan {
82*dbfe9df8SPeng Fan 	mailbox_mem_t *mbx_mem;
83*dbfe9df8SPeng Fan 	unsigned int token = 0U;
84*dbfe9df8SPeng Fan 	int ret;
85*dbfe9df8SPeng Fan 	scmi_channel_t *ch = (scmi_channel_t *)p;
86*dbfe9df8SPeng Fan 
87*dbfe9df8SPeng Fan 	validate_scmi_channel(ch);
88*dbfe9df8SPeng Fan 
89*dbfe9df8SPeng Fan 	scmi_get_channel(ch);
90*dbfe9df8SPeng Fan 
91*dbfe9df8SPeng Fan 	mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
92*dbfe9df8SPeng Fan 	mbx_mem->msg_header = SCMI_MSG_CREATE(IMX9_SCMI_CORE_PROTO_ID,
93*dbfe9df8SPeng Fan 			IMX9_SCMI_CORE_STOP_MSG, token);
94*dbfe9df8SPeng Fan 	mbx_mem->len = IMX9_SCMI_CORE_STOP_MSG_LEN;
95*dbfe9df8SPeng Fan 	mbx_mem->flags = SCMI_FLAG_RESP_POLL;
96*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_ARG1(mbx_mem->payload, cpu_id);
97*dbfe9df8SPeng Fan 
98*dbfe9df8SPeng Fan 	scmi_send_sync_command(ch);
99*dbfe9df8SPeng Fan 
100*dbfe9df8SPeng Fan 	/* Get the return values */
101*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
102*dbfe9df8SPeng Fan 	assert(mbx_mem->len == IMX9_SCMI_CORE_STOP_RESP_LEN);
103*dbfe9df8SPeng Fan 	assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
104*dbfe9df8SPeng Fan 
105*dbfe9df8SPeng Fan 	scmi_put_channel(ch);
106*dbfe9df8SPeng Fan 
107*dbfe9df8SPeng Fan 	return ret;
108*dbfe9df8SPeng Fan }
109*dbfe9df8SPeng Fan 
scmi_core_set_sleep_mode(void * p,uint32_t cpu_id,uint32_t wakeup,uint32_t mode)110*dbfe9df8SPeng Fan int scmi_core_set_sleep_mode(void *p, uint32_t cpu_id, uint32_t wakeup,
111*dbfe9df8SPeng Fan 			     uint32_t mode)
112*dbfe9df8SPeng Fan {
113*dbfe9df8SPeng Fan 	mailbox_mem_t *mbx_mem;
114*dbfe9df8SPeng Fan 	unsigned int token = 0U;
115*dbfe9df8SPeng Fan 	int ret;
116*dbfe9df8SPeng Fan 	scmi_channel_t *ch = (scmi_channel_t *)p;
117*dbfe9df8SPeng Fan 
118*dbfe9df8SPeng Fan 	validate_scmi_channel(ch);
119*dbfe9df8SPeng Fan 
120*dbfe9df8SPeng Fan 	scmi_get_channel(ch);
121*dbfe9df8SPeng Fan 
122*dbfe9df8SPeng Fan 	mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
123*dbfe9df8SPeng Fan 	mbx_mem->msg_header = SCMI_MSG_CREATE(IMX9_SCMI_CORE_PROTO_ID,
124*dbfe9df8SPeng Fan 			IMX9_SCMI_CORE_SETSLEEPMODE_MSG, token);
125*dbfe9df8SPeng Fan 	mbx_mem->len = IMX9_SCMI_CORE_SETSLEEPMODE_MSG_LEN;
126*dbfe9df8SPeng Fan 	mbx_mem->flags = SCMI_FLAG_RESP_POLL;
127*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_ARG3(mbx_mem->payload, cpu_id, wakeup, mode);
128*dbfe9df8SPeng Fan 
129*dbfe9df8SPeng Fan 	scmi_send_sync_command(ch);
130*dbfe9df8SPeng Fan 
131*dbfe9df8SPeng Fan 	/* Get the return values */
132*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
133*dbfe9df8SPeng Fan 	assert(mbx_mem->len == IMX9_SCMI_CORE_SETSLEEPMODE_RESP_LEN);
134*dbfe9df8SPeng Fan 	assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
135*dbfe9df8SPeng Fan 
136*dbfe9df8SPeng Fan 	scmi_put_channel(ch);
137*dbfe9df8SPeng Fan 
138*dbfe9df8SPeng Fan 	return ret;
139*dbfe9df8SPeng Fan }
140*dbfe9df8SPeng Fan 
scmi_core_Irq_wake_set(void * p,uint32_t cpu_id,uint32_t mask_idx,uint32_t num_mask,uint32_t * mask)141*dbfe9df8SPeng Fan int scmi_core_Irq_wake_set(void *p, uint32_t cpu_id, uint32_t mask_idx,
142*dbfe9df8SPeng Fan 		uint32_t num_mask, uint32_t *mask)
143*dbfe9df8SPeng Fan {
144*dbfe9df8SPeng Fan 	mailbox_mem_t *mbx_mem;
145*dbfe9df8SPeng Fan 	unsigned int token = 0U;
146*dbfe9df8SPeng Fan 	int ret;
147*dbfe9df8SPeng Fan 	scmi_channel_t *ch = (scmi_channel_t *)p;
148*dbfe9df8SPeng Fan 
149*dbfe9df8SPeng Fan 	validate_scmi_channel(ch);
150*dbfe9df8SPeng Fan 
151*dbfe9df8SPeng Fan 	scmi_get_channel(ch);
152*dbfe9df8SPeng Fan 
153*dbfe9df8SPeng Fan 	mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
154*dbfe9df8SPeng Fan 	mbx_mem->msg_header = SCMI_MSG_CREATE(IMX9_SCMI_CORE_PROTO_ID,
155*dbfe9df8SPeng Fan 			IMX9_SCMI_CORE_SETIRQWAKESET_MSG, token);
156*dbfe9df8SPeng Fan 	mbx_mem->len = IMX9_SCMI_CORE_SETIRQWAKESET_MSG_LEN;
157*dbfe9df8SPeng Fan 	mbx_mem->flags = SCMI_FLAG_RESP_POLL;
158*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_ARG3(mbx_mem->payload, cpu_id, mask_idx, num_mask);
159*dbfe9df8SPeng Fan 
160*dbfe9df8SPeng Fan 	for (unsigned int i = 0U; i < num_mask; i++) {
161*dbfe9df8SPeng Fan 		mbx_mem->payload[3U + i] = mask[i];
162*dbfe9df8SPeng Fan 	}
163*dbfe9df8SPeng Fan 
164*dbfe9df8SPeng Fan 	scmi_send_sync_command(ch);
165*dbfe9df8SPeng Fan 
166*dbfe9df8SPeng Fan 	/* Get the return values */
167*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
168*dbfe9df8SPeng Fan 	assert(mbx_mem->len == IMX9_SCMI_CORE_SETIRQWAKESET_RESP_LEN);
169*dbfe9df8SPeng Fan 	assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
170*dbfe9df8SPeng Fan 
171*dbfe9df8SPeng Fan 	scmi_put_channel(ch);
172*dbfe9df8SPeng Fan 
173*dbfe9df8SPeng Fan 	return ret;
174*dbfe9df8SPeng Fan }
175*dbfe9df8SPeng Fan 
scmi_core_nonIrq_wake_set(void * p,uint32_t cpu_id,uint32_t mask_idx,uint32_t num_mask,uint32_t mask)176*dbfe9df8SPeng Fan int scmi_core_nonIrq_wake_set(void *p, uint32_t cpu_id, uint32_t mask_idx,
177*dbfe9df8SPeng Fan 		uint32_t num_mask, uint32_t mask)
178*dbfe9df8SPeng Fan {
179*dbfe9df8SPeng Fan 	mailbox_mem_t *mbx_mem;
180*dbfe9df8SPeng Fan 	unsigned int token = 0U;
181*dbfe9df8SPeng Fan 	int ret;
182*dbfe9df8SPeng Fan 	scmi_channel_t *ch = (scmi_channel_t *)p;
183*dbfe9df8SPeng Fan 
184*dbfe9df8SPeng Fan 	validate_scmi_channel(ch);
185*dbfe9df8SPeng Fan 	scmi_get_channel(ch);
186*dbfe9df8SPeng Fan 
187*dbfe9df8SPeng Fan 	mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
188*dbfe9df8SPeng Fan 	mbx_mem->msg_header = SCMI_MSG_CREATE(IMX9_SCMI_CORE_PROTO_ID,
189*dbfe9df8SPeng Fan 			IMX9_SCMI_CORE_NONIRQWAKESET_MSG, token);
190*dbfe9df8SPeng Fan 	mbx_mem->len = IMX9_SCMI_CORE_NONIRQWAKESET_MSG_LEN;
191*dbfe9df8SPeng Fan 	mbx_mem->flags = SCMI_FLAG_RESP_POLL;
192*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_ARG4(mbx_mem->payload, cpu_id, mask_idx, num_mask, mask);
193*dbfe9df8SPeng Fan 
194*dbfe9df8SPeng Fan 	scmi_send_sync_command(ch);
195*dbfe9df8SPeng Fan 
196*dbfe9df8SPeng Fan 	/* Get the return values */
197*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
198*dbfe9df8SPeng Fan 	assert(mbx_mem->len == IMX9_SCMI_CORE_NONIRQWAKESET_RESP_LEN);
199*dbfe9df8SPeng Fan 	assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
200*dbfe9df8SPeng Fan 
201*dbfe9df8SPeng Fan 	scmi_put_channel(ch);
202*dbfe9df8SPeng Fan 
203*dbfe9df8SPeng Fan 	return ret;
204*dbfe9df8SPeng Fan }
205*dbfe9df8SPeng Fan 
scmi_core_lpm_mode_set(void * p,uint32_t cpu_id,uint32_t num_configs,struct scmi_lpm_config * cfg)206*dbfe9df8SPeng Fan int scmi_core_lpm_mode_set(void *p, uint32_t cpu_id,
207*dbfe9df8SPeng Fan 			   uint32_t num_configs,
208*dbfe9df8SPeng Fan 			   struct scmi_lpm_config *cfg)
209*dbfe9df8SPeng Fan {
210*dbfe9df8SPeng Fan 	mailbox_mem_t *mbx_mem;
211*dbfe9df8SPeng Fan 	unsigned int token = 0U;
212*dbfe9df8SPeng Fan 	int ret;
213*dbfe9df8SPeng Fan 	scmi_channel_t *ch = (scmi_channel_t *)p;
214*dbfe9df8SPeng Fan 
215*dbfe9df8SPeng Fan 	validate_scmi_channel(ch);
216*dbfe9df8SPeng Fan 
217*dbfe9df8SPeng Fan 	scmi_get_channel(ch);
218*dbfe9df8SPeng Fan 
219*dbfe9df8SPeng Fan 	mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
220*dbfe9df8SPeng Fan 	mbx_mem->msg_header = SCMI_MSG_CREATE(IMX9_SCMI_CORE_PROTO_ID,
221*dbfe9df8SPeng Fan 			IMX9_SCMI_CORE_LPMMODESET_MSG, token);
222*dbfe9df8SPeng Fan 	mbx_mem->len = IMX9_SCMI_CORE_LPMMODESET_MSG_LEN +
223*dbfe9df8SPeng Fan 		       (num_configs * sizeof(struct scmi_lpm_config));
224*dbfe9df8SPeng Fan 	mbx_mem->flags = SCMI_FLAG_RESP_POLL;
225*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_ARG2(mbx_mem->payload, cpu_id, num_configs);
226*dbfe9df8SPeng Fan 
227*dbfe9df8SPeng Fan 	/* The lpm config starts from byte 2 in the payload memory */
228*dbfe9df8SPeng Fan 	unsigned int j = 2U;
229*dbfe9df8SPeng Fan 
230*dbfe9df8SPeng Fan 	for (unsigned int i = 0U; i < num_configs; i++) {
231*dbfe9df8SPeng Fan 		mmio_write_32((uintptr_t)&mbx_mem->payload[j++],
232*dbfe9df8SPeng Fan 			      cfg[i].power_domain);
233*dbfe9df8SPeng Fan 		mmio_write_32((uintptr_t)&mbx_mem->payload[j++],
234*dbfe9df8SPeng Fan 			      cfg[i].lpmsetting);
235*dbfe9df8SPeng Fan 		mmio_write_32((uintptr_t)&mbx_mem->payload[j++],
236*dbfe9df8SPeng Fan 			      cfg[i].retentionmask);
237*dbfe9df8SPeng Fan 	}
238*dbfe9df8SPeng Fan 	scmi_send_sync_command(ch);
239*dbfe9df8SPeng Fan 
240*dbfe9df8SPeng Fan 	/* Get the return values */
241*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
242*dbfe9df8SPeng Fan 	assert(mbx_mem->len == IMX9_SCMI_CORE_LPMMODESET_RESP_LEN);
243*dbfe9df8SPeng Fan 	assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
244*dbfe9df8SPeng Fan 
245*dbfe9df8SPeng Fan 	scmi_put_channel(ch);
246*dbfe9df8SPeng Fan 
247*dbfe9df8SPeng Fan 	return ret;
248*dbfe9df8SPeng Fan }
249*dbfe9df8SPeng Fan 
scmi_per_lpm_mode_set(void * p,uint32_t cpu_id,uint32_t num_configs,struct scmi_per_lpm_config * cfg)250*dbfe9df8SPeng Fan int scmi_per_lpm_mode_set(void *p, uint32_t cpu_id, uint32_t num_configs,
251*dbfe9df8SPeng Fan 		struct scmi_per_lpm_config *cfg)
252*dbfe9df8SPeng Fan {
253*dbfe9df8SPeng Fan 	mailbox_mem_t *mbx_mem;
254*dbfe9df8SPeng Fan 	unsigned int token = 0U;
255*dbfe9df8SPeng Fan 	int ret;
256*dbfe9df8SPeng Fan 	scmi_channel_t *ch = (scmi_channel_t *)p;
257*dbfe9df8SPeng Fan 	struct scmi_per_lpm_config *tmp = cfg;
258*dbfe9df8SPeng Fan 
259*dbfe9df8SPeng Fan 	validate_scmi_channel(ch);
260*dbfe9df8SPeng Fan 
261*dbfe9df8SPeng Fan 	scmi_get_channel(ch);
262*dbfe9df8SPeng Fan 
263*dbfe9df8SPeng Fan 	do {
264*dbfe9df8SPeng Fan 		mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
265*dbfe9df8SPeng Fan 		mbx_mem->msg_header = SCMI_MSG_CREATE(IMX9_SCMI_CORE_PROTO_ID,
266*dbfe9df8SPeng Fan 				IMX9_SCMI_PER_LPMMODESET_MSG, token);
267*dbfe9df8SPeng Fan 		mbx_mem->len = IMX9_SCMI_PER_LPMMODESET_MSG_LEN +
268*dbfe9df8SPeng Fan 			       (num_configs * sizeof(struct scmi_per_lpm_config));
269*dbfe9df8SPeng Fan 		mbx_mem->flags = SCMI_FLAG_RESP_POLL;
270*dbfe9df8SPeng Fan 		SCMI_PAYLOAD_ARG2(mbx_mem->payload, cpu_id, num_configs);
271*dbfe9df8SPeng Fan 
272*dbfe9df8SPeng Fan 		/* The lpm config starts from byte 2 in the payload memory */
273*dbfe9df8SPeng Fan 		unsigned int j = 2U;
274*dbfe9df8SPeng Fan 
275*dbfe9df8SPeng Fan 		for (unsigned int i = 0U; i < num_configs; i++) {
276*dbfe9df8SPeng Fan 			mmio_write_32((uintptr_t)&mbx_mem->payload[j++],
277*dbfe9df8SPeng Fan 				      cfg[i].perId);
278*dbfe9df8SPeng Fan 			mmio_write_32((uintptr_t)&mbx_mem->payload[j++],
279*dbfe9df8SPeng Fan 				      cfg[i].lpmSetting);
280*dbfe9df8SPeng Fan 		}
281*dbfe9df8SPeng Fan 		scmi_send_sync_command(ch);
282*dbfe9df8SPeng Fan 
283*dbfe9df8SPeng Fan 		/* Get the return values */
284*dbfe9df8SPeng Fan 		SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
285*dbfe9df8SPeng Fan 		assert(mbx_mem->len == IMX9_SCMI_PER_LPMMODESET_RESP_LEN);
286*dbfe9df8SPeng Fan 		assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
287*dbfe9df8SPeng Fan 
288*dbfe9df8SPeng Fan 		if (num_configs > MAX_PER_LPI_CONFIGS_PER_CMD) {
289*dbfe9df8SPeng Fan 			num_configs -= MAX_PER_LPI_CONFIGS_PER_CMD;
290*dbfe9df8SPeng Fan 			tmp += MAX_PER_LPI_CONFIGS_PER_CMD;
291*dbfe9df8SPeng Fan 		} else {
292*dbfe9df8SPeng Fan 			break;
293*dbfe9df8SPeng Fan 		}
294*dbfe9df8SPeng Fan 	} while (num_configs);
295*dbfe9df8SPeng Fan 
296*dbfe9df8SPeng Fan 	scmi_put_channel(ch);
297*dbfe9df8SPeng Fan 
298*dbfe9df8SPeng Fan 	return ret;
299*dbfe9df8SPeng Fan }
300*dbfe9df8SPeng Fan 
scmi_perf_mode_set(void * p,uint32_t domain_id,uint32_t perf_level)301*dbfe9df8SPeng Fan int scmi_perf_mode_set(void *p, uint32_t domain_id, uint32_t perf_level)
302*dbfe9df8SPeng Fan {
303*dbfe9df8SPeng Fan 	mailbox_mem_t *mbx_mem;
304*dbfe9df8SPeng Fan 	unsigned int token = 0U;
305*dbfe9df8SPeng Fan 	int ret;
306*dbfe9df8SPeng Fan 	scmi_channel_t *ch = (scmi_channel_t *)p;
307*dbfe9df8SPeng Fan 
308*dbfe9df8SPeng Fan 	validate_scmi_channel(ch);
309*dbfe9df8SPeng Fan 
310*dbfe9df8SPeng Fan 	scmi_get_channel(ch);
311*dbfe9df8SPeng Fan 
312*dbfe9df8SPeng Fan 	mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
313*dbfe9df8SPeng Fan 	mbx_mem->msg_header = SCMI_MSG_CREATE(IMX9_SCMI_PERF_PROTO_ID,
314*dbfe9df8SPeng Fan 			IMX9_SCMI_CORE_PERFLEVELSET_MSG, token);
315*dbfe9df8SPeng Fan 	mbx_mem->len = IMX9_SCMI_CORE_PERFLEVELSET_MSG_LEN;
316*dbfe9df8SPeng Fan 	mbx_mem->flags = SCMI_FLAG_RESP_POLL;
317*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_ARG2(mbx_mem->payload, domain_id, perf_level);
318*dbfe9df8SPeng Fan 
319*dbfe9df8SPeng Fan 	scmi_send_sync_command(ch);
320*dbfe9df8SPeng Fan 
321*dbfe9df8SPeng Fan 	/* Get the return values */
322*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
323*dbfe9df8SPeng Fan 	assert(mbx_mem->len == IMX9_SCMI_CORE_PERFLEVELSET_RESP_LEN);
324*dbfe9df8SPeng Fan 	assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
325*dbfe9df8SPeng Fan 
326*dbfe9df8SPeng Fan 	scmi_put_channel(ch);
327*dbfe9df8SPeng Fan 
328*dbfe9df8SPeng Fan 	return ret;
329*dbfe9df8SPeng Fan 
330*dbfe9df8SPeng Fan }
331*dbfe9df8SPeng Fan 
scmi_core_info_get(void * p,uint32_t cpu_id,uint32_t * runmode,uint32_t * sleepmode,uint64_t * vector)332*dbfe9df8SPeng Fan int scmi_core_info_get(void *p, uint32_t cpu_id, uint32_t *runmode,
333*dbfe9df8SPeng Fan 		       uint32_t *sleepmode, uint64_t *vector)
334*dbfe9df8SPeng Fan {
335*dbfe9df8SPeng Fan 	mailbox_mem_t *mbx_mem;
336*dbfe9df8SPeng Fan 	unsigned int token = 0U;
337*dbfe9df8SPeng Fan 	int ret;
338*dbfe9df8SPeng Fan 	scmi_channel_t *ch = (scmi_channel_t *)p;
339*dbfe9df8SPeng Fan 	uint32_t lo_addr, hi_addr;
340*dbfe9df8SPeng Fan 
341*dbfe9df8SPeng Fan 	validate_scmi_channel(ch);
342*dbfe9df8SPeng Fan 
343*dbfe9df8SPeng Fan 	scmi_get_channel(ch);
344*dbfe9df8SPeng Fan 
345*dbfe9df8SPeng Fan 	mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
346*dbfe9df8SPeng Fan 	mbx_mem->msg_header = SCMI_MSG_CREATE(IMX9_SCMI_CORE_PROTO_ID,
347*dbfe9df8SPeng Fan 			IMX9_SCMI_CORE_GETINFO_MSG, token);
348*dbfe9df8SPeng Fan 	mbx_mem->len = IMX9_SCMI_CORE_GETINFO_MSG_LEN;
349*dbfe9df8SPeng Fan 	mbx_mem->flags = SCMI_FLAG_RESP_POLL;
350*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_ARG1(mbx_mem->payload, cpu_id);
351*dbfe9df8SPeng Fan 
352*dbfe9df8SPeng Fan 	scmi_send_sync_command(ch);
353*dbfe9df8SPeng Fan 
354*dbfe9df8SPeng Fan 	/* Get the return values */
355*dbfe9df8SPeng Fan 	SCMI_PAYLOAD_RET_VAL5(mbx_mem->payload, ret, *runmode, *sleepmode,
356*dbfe9df8SPeng Fan 			      lo_addr, hi_addr);
357*dbfe9df8SPeng Fan 	*vector = lo_addr | (uint64_t)hi_addr << 32;
358*dbfe9df8SPeng Fan 	assert(mbx_mem->len == IMX9_SCMI_CORE_START_RESP_LEN);
359*dbfe9df8SPeng Fan 	assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header));
360*dbfe9df8SPeng Fan 
361*dbfe9df8SPeng Fan 	scmi_put_channel(ch);
362*dbfe9df8SPeng Fan 
363*dbfe9df8SPeng Fan 	return ret;
364*dbfe9df8SPeng Fan }
365