blob: 83eeda29d48dd1c33f89cd6405c3492e50626444 [file] [log] [blame]
Antonio Nino Diaz272e8712018-09-18 01:36:00 +01001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
Antonio Nino Diaz272e8712018-09-18 01:36:00 +01008#include <string.h>
9
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <platform_def.h>
11
12#include <lib/mmio.h>
13#include <plat/common/platform.h>
14
Antonio Nino Diaz272e8712018-09-18 01:36:00 +010015#include "gxbb_private.h"
16
17#define SIZE_SHIFT 20
18#define SIZE_MASK 0x1FF
19
20/*
21 * Note: The Amlogic SCP firmware uses the legacy SCPI protocol.
22 */
23#define SCPI_CMD_SET_CSS_POWER_STATE 0x04
24#define SCPI_CMD_SET_SYS_POWER_STATE 0x08
25
26#define SCPI_CMD_JTAG_SET_STATE 0xC0
27#define SCPI_CMD_EFUSE_READ 0xC2
28
29static inline uint32_t scpi_cmd(uint32_t command, uint32_t size)
30{
31 return command | (size << SIZE_SHIFT);
32}
33
34void scpi_secure_message_send(uint32_t command, uint32_t size)
35{
36 mhu_secure_message_send(scpi_cmd(command, size));
37}
38
39uint32_t scpi_secure_message_receive(void **message_out, size_t *size_out)
40{
41 uint32_t response = mhu_secure_message_wait();
42
43 size_t size = (response >> SIZE_SHIFT) & SIZE_MASK;
44
45 response &= ~(SIZE_MASK << SIZE_SHIFT);
46
47 if (size_out != NULL)
48 *size_out = size;
49
50 if (message_out != NULL)
51 *message_out = (void *)GXBB_MHU_SECURE_SCP_TO_AP_PAYLOAD;
52
53 return response;
54}
55
56void scpi_set_css_power_state(u_register_t mpidr, uint32_t cpu_state,
57 uint32_t cluster_state, uint32_t css_state)
58{
59 uint32_t state = (mpidr & 0x0F) | /* CPU ID */
60 ((mpidr & 0xF00) >> 4) | /* Cluster ID */
61 (cpu_state << 8) |
62 (cluster_state << 12) |
63 (css_state << 16);
64
65 mhu_secure_message_start();
66 mmio_write_32(GXBB_MHU_SECURE_AP_TO_SCP_PAYLOAD, state);
67 mhu_secure_message_send(scpi_cmd(SCPI_CMD_SET_CSS_POWER_STATE, 4));
68 mhu_secure_message_wait();
69 mhu_secure_message_end();
70}
71
72uint32_t scpi_sys_power_state(uint64_t system_state)
73{
74 uint32_t *response;
75 size_t size;
76
77 mhu_secure_message_start();
78 mmio_write_8(GXBB_MHU_SECURE_AP_TO_SCP_PAYLOAD, system_state);
79 mhu_secure_message_send(scpi_cmd(SCPI_CMD_SET_SYS_POWER_STATE, 1));
80 scpi_secure_message_receive((void *)&response, &size);
81 mhu_secure_message_end();
82
83 return *response;
84}
85
86void scpi_jtag_set_state(uint32_t state, uint8_t select)
87{
88 assert(state <= GXBB_JTAG_STATE_OFF);
89
90 if (select > GXBB_JTAG_A53_EE) {
91 WARN("BL31: Invalid JTAG select (0x%x).\n", select);
92 return;
93 }
94
95 mhu_secure_message_start();
96 mmio_write_32(GXBB_MHU_SECURE_AP_TO_SCP_PAYLOAD,
97 (state << 8) | (uint32_t)select);
98 mhu_secure_message_send(scpi_cmd(SCPI_CMD_JTAG_SET_STATE, 4));
99 mhu_secure_message_wait();
100 mhu_secure_message_end();
101}
102
103uint32_t scpi_efuse_read(void *dst, uint32_t base, uint32_t size)
104{
105 uint32_t *response;
106 size_t resp_size;
107
108 if (size > 0x1FC)
109 return 0;
110
111 mhu_secure_message_start();
112 mmio_write_32(GXBB_MHU_SECURE_AP_TO_SCP_PAYLOAD, base);
113 mmio_write_32(GXBB_MHU_SECURE_AP_TO_SCP_PAYLOAD + 4, size);
114 mhu_secure_message_send(scpi_cmd(SCPI_CMD_EFUSE_READ, 8));
115 scpi_secure_message_receive((void *)&response, &resp_size);
116 mhu_secure_message_end();
117
118 /*
119 * response[0] is the size of the response message.
120 * response[1 ... N] are the contents.
121 */
122 if (*response != 0)
123 memcpy(dst, response + 1, *response);
124
125 return *response;
126}
127
128void scpi_unknown_thermal(uint32_t arg0, uint32_t arg1,
129 uint32_t arg2, uint32_t arg3)
130{
131 mhu_secure_message_start();
132 mmio_write_32(GXBB_MHU_SECURE_AP_TO_SCP_PAYLOAD + 0x0, arg0);
133 mmio_write_32(GXBB_MHU_SECURE_AP_TO_SCP_PAYLOAD + 0x4, arg1);
134 mmio_write_32(GXBB_MHU_SECURE_AP_TO_SCP_PAYLOAD + 0x8, arg2);
135 mmio_write_32(GXBB_MHU_SECURE_AP_TO_SCP_PAYLOAD + 0xC, arg3);
136 mhu_secure_message_send(scpi_cmd(0xC3, 16));
137 mhu_secure_message_wait();
138 mhu_secure_message_end();
139}