blob: f18542487e47578415c283d9bc5eb0979a2696c0 [file] [log] [blame]
Masahisa Kojimaebfd8eb2019-03-07 10:41:54 +09001/*
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
Masahisa Kojimaa4cf67e2019-05-23 14:41:35 +090021#define SCMI_VENDOR_EXT_MEMINFO_GET_MSG_LEN 4
22
Masahisa Kojimaebfd8eb2019-03-07 10:41:54 +090023/*
24 * API to get the available DRAM region
25 */
26int scmi_get_draminfo(void *p, struct draminfo *info)
27{
28 mailbox_mem_t *mbx_mem;
29 int token = 0, ret;
30 scmi_channel_t *ch = (scmi_channel_t *)p;
31 struct dram_info_resp response;
32
33 validate_scmi_channel(ch);
34
35 scmi_get_channel(ch);
36
37 mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem);
38 mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_VENDOR_EXT_PROTO_ID,
39 SCMI_VENDOR_EXT_MEMINFO_GET_MSG, token);
Masahisa Kojimaa4cf67e2019-05-23 14:41:35 +090040 mbx_mem->len = SCMI_VENDOR_EXT_MEMINFO_GET_MSG_LEN;
Masahisa Kojimaebfd8eb2019-03-07 10:41:54 +090041 mbx_mem->flags = SCMI_FLAG_RESP_POLL;
42
43 scmi_send_sync_command(ch);
44
45 /*
46 * Ensure that any read to the SCPI payload area is done after reading
47 * the MHU register. If these 2 reads were reordered then the CPU would
48 * read invalid payload data
49 */
50 dmbld();
51
52 /* Get the return values */
53 SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret);
54
55 memcpy(&response, (void *)mbx_mem->payload, sizeof(response));
56
57 scmi_put_channel(ch);
58
59 *info = response.info;
60
61 return ret;
62}