blob: 1ba09bc06efe391094947338ee3f9a8d581c3ca1 [file] [log] [blame]
Hadi Asyrafi616da772019-06-27 11:34:03 +08001/*
2 * Copyright (c) 2019, Intel Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Hadi Asyrafi6f8a2b22019-10-23 18:34:14 +08007#ifndef SOCFPGA_MBOX_H
8#define SOCFPGA_MBOX_H
Hadi Asyrafi616da772019-06-27 11:34:03 +08009
Ambroise Vincenta724e432019-07-23 11:10:27 +010010#include <lib/utils_def.h>
11
Hadi Asyrafi616da772019-06-27 11:34:03 +080012#define MBOX_OFFSET 0xffa30000
13
14#define MBOX_ATF_CLIENT_ID 0x1
15#define MBOX_JOB_ID 0x1
16
17/* Mailbox interrupt flags and masks */
18#define MBOX_INT_FLAG_COE 0x1
19#define MBOX_INT_FLAG_RIE 0x2
20#define MBOX_INT_FLAG_UAE 0x100
21#define MBOX_COE_BIT(INTERRUPT) ((INTERRUPT) & 0x3)
22#define MBOX_UAE_BIT(INTERRUPT) (((INTERRUPT) & (1<<8)))
23
24/* Mailbox response and status */
25#define MBOX_RESP_BUFFER_SIZE 16
26#define MBOX_RESP_ERR(BUFFER) ((BUFFER) & 0x00000fff)
27#define MBOX_RESP_LEN(BUFFER) (((BUFFER) & 0x007ff000) >> 12)
28#define MBOX_RESP_CLIENT_ID(BUFFER) (((BUFFER) & 0xf0000000) >> 28)
29#define MBOX_RESP_JOB_ID(BUFFER) (((BUFFER) & 0x0f000000) >> 24)
30#define MBOX_STATUS_UA_MASK (1<<8)
31
32/* Mailbox command and response */
33#define MBOX_CMD_FREE_OFFSET 0x14
34#define MBOX_CMD_BUFFER_SIZE 32
35#define MBOX_CLIENT_ID_CMD(CLIENT_ID) ((CLIENT_ID) << 28)
36#define MBOX_JOB_ID_CMD(JOB_ID) (JOB_ID<<24)
37#define MBOX_CMD_LEN_CMD(CMD_LEN) ((CMD_LEN) << 12)
38#define MBOX_INDIRECT (1 << 11)
39#define MBOX_INSUFFICIENT_BUFFER -2
40#define MBOX_CIN 0x00
41#define MBOX_ROUT 0x04
42#define MBOX_URG 0x08
43#define MBOX_INT 0x0C
44#define MBOX_COUT 0x20
45#define MBOX_RIN 0x24
46#define MBOX_STATUS 0x2C
47#define MBOX_CMD_BUFFER 0x40
48#define MBOX_RESP_BUFFER 0xC0
49
50#define MBOX_RESP_BUFFER_SIZE 16
51#define MBOX_RESP_OK 0
52#define MBOX_RESP_INVALID_CMD 1
53#define MBOX_RESP_UNKNOWN_BR 2
54#define MBOX_RESP_UNKNOWN 3
55#define MBOX_RESP_NOT_CONFIGURED 256
56
57/* Mailbox SDM doorbell */
58#define MBOX_DOORBELL_TO_SDM 0x400
59#define MBOX_DOORBELL_FROM_SDM 0x480
60
61/* Mailbox QSPI commands */
62#define MBOX_CMD_RESTART 2
63#define MBOX_CMD_QSPI_OPEN 50
64#define MBOX_CMD_QSPI_CLOSE 51
65#define MBOX_CMD_QSPI_DIRECT 59
66#define MBOX_CMD_GET_IDCODE 16
67#define MBOX_CMD_QSPI_SET_CS 52
68
69/* Mailbox REBOOT commands */
70#define MBOX_CMD_REBOOT_HPS 71
71
72/* Generic error handling */
73#define MBOX_TIMEOUT -2047
74#define MBOX_NO_RESPONSE -2
75#define MBOX_WRONG_ID -3
76
77/* Mailbox status */
78#define RECONFIG_STATUS_STATE 0
79#define RECONFIG_STATUS_PIN_STATUS 2
80#define RECONFIG_STATUS_SOFTFUNC_STATUS 3
Ambroise Vincenta724e432019-07-23 11:10:27 +010081#define PIN_STATUS_NSTATUS (U(1) << 31)
Hadi Asyrafi616da772019-06-27 11:34:03 +080082#define SOFTFUNC_STATUS_SEU_ERROR (1 << 3)
83#define SOFTFUNC_STATUS_INIT_DONE (1 << 1)
84#define SOFTFUNC_STATUS_CONF_DONE (1 << 0)
85#define MBOX_CFGSTAT_STATE_CONFIG 0x10000000
86
Hadi Asyrafi616da772019-06-27 11:34:03 +080087/* Mailbox reconfiguration commands */
88#define MBOX_RECONFIG 6
89#define MBOX_RECONFIG_DATA 8
90#define MBOX_RECONFIG_STATUS 9
91
Hadi Asyrafi616da772019-06-27 11:34:03 +080092
93void mailbox_set_int(int interrupt_input);
94int mailbox_init(void);
95void mailbox_set_qspi_close(void);
96void mailbox_set_qspi_open(void);
97void mailbox_set_qspi_direct(void);
98int mailbox_send_cmd(int job_id, unsigned int cmd, uint32_t *args,
99 int len, int urgent, uint32_t *response);
100void mailbox_send_cmd_async(int job_id, unsigned int cmd, uint32_t *args,
101 int len, int urgent);
102int mailbox_read_response(int job_id, uint32_t *response);
103int mailbox_get_qspi_clock(void);
104void mailbox_reset_cold(void);
105
Hadi Asyrafi6f8a2b22019-10-23 18:34:14 +0800106#endif /* SOCFPGA_MBOX_H */