xref: /rk3399_ARM-atf/drivers/arm/css/scmi/vendor/scmi_sq.c (revision fd7b287cbe9147ca9e07dd9f30c49c58bbdd92a8)
1 /*
2  * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 
9 #include <arch_helpers.h>
10 #include <common/debug.h>
11 #include <drivers/arm/css/scmi.h>
12 
13 #include "scmi_private.h"
14 #include "scmi_sq.h"
15 
16 #include <sq_common.h>
17 
18 /* SCMI messge ID to get the available DRAM region */
19 #define SCMI_VENDOR_EXT_MEMINFO_GET_MSG		0x3
20 
21 /*
22  * API to get the available DRAM region
23  */
24 int scmi_get_draminfo(void *p, struct draminfo *info)
25 {
26 	mailbox_mem_t *mbx_mem;
27 	int token = 0, ret;
28 	scmi_channel_t *ch = (scmi_channel_t *)p;
29 	struct dram_info_resp response;
30 
31 	validate_scmi_channel(ch);
32 
33 	scmi_get_channel(ch);
34 
35 	mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
36 	mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_VENDOR_EXT_PROTO_ID,
37 			SCMI_VENDOR_EXT_MEMINFO_GET_MSG, token);
38 	mbx_mem->len = 8;
39 	mbx_mem->flags = SCMI_FLAG_RESP_POLL;
40 
41 	scmi_send_sync_command(ch);
42 
43 	/*
44 	 * Ensure that any read to the SCPI payload area is done after reading
45 	 * the MHU register. If these 2 reads were reordered then the CPU would
46 	 * read invalid payload data
47 	 */
48 	dmbld();
49 
50 	/* Get the return values */
51 	SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
52 
53 	memcpy(&response, (void *)mbx_mem->payload, sizeof(response));
54 
55 	scmi_put_channel(ch);
56 
57 	*info = response.info;
58 
59 	return ret;
60 }
61