blob: 8551808b10ed32adfd9d39ceb466b31ad14c305c [file] [log] [blame]
Jose Marinho4e4e4d52019-02-22 16:23:51 +00001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "hf/types.h"
18
19#pragma once
20
21/* clang-format off */
22
23#define SPCI_LOW_32_ID 0x84000060
24#define SPCI_HIGH_32_ID 0x8400007F
25#define SPCI_LOW_64_ID 0xC4000060
26#define SPCI_HIGH_32_ID 0x8400007F
27
28/* SPCI function identifiers. */
29#define SPCI_VERSION_32 0x84000060
30#define SPCI_MSG_BUF_LIST_EXCHANGE_32 0x84000061
31#define SPCI_MSG_RECV_32 0x84000062
32#define SPCI_MSG_PUT_32 0x84000063
33#define SPCI_MSG_SEND_32 0x84000064
34#define SPCI_MSG_SEND_REC_32 0x84000065
35#define SPCI_RUN_32 0x84000066
36#define SPCI_YIELD_32 0x84000067
37
38/* SPCI return codes. */
39#define SPCI_SUCCESS INT32_C(0)
40#define SPCI_NOT_SUPPORTED INT32_C(-1)
41#define SPCI_INVALID_PARAMETERS INT32_C(-2)
42#define SPCI_NO_MEMORY INT32_C(-3)
43#define SPCI_BUSY INT32_C(-4)
44#define SPCI_INTERRUPTED INT32_C(-5)
45#define SPCI_DENIED INT32_C(-6)
46/* TODO: return code currently undefined in SPCI alpha2. */
47#define SPCI_RETRY INT32_C(-7)
48
49/* SPCI function specific constants. */
Andrew Scull1262ac22019-04-05 12:44:26 +010050#define SPCI_MSG_RECV_BLOCK_MASK 0x1
Jose Marinho4e4e4d52019-02-22 16:23:51 +000051#define SPCI_MSG_SEND_NOTIFY_MASK 0x1
52
53#define SPCI_MESSAGE_IMPDEF_MASK 0x1
54
55#define SPCI_MSG_SEND_NOTIFY 0x1
Andrew Scull1262ac22019-04-05 12:44:26 +010056#define SPCI_MSG_RECV_BLOCK 0x1
57
58/* The maximum length possible for a single message. */
59#define SPCI_MSG_PAYLOAD_MAX (HF_MAILBOX_SIZE - sizeof(struct spci_message))
Jose Marinho4e4e4d52019-02-22 16:23:51 +000060
61/* clang-format on */
62
63typedef uint16_t spci_vm_id_t;
64
65/** SPCI common message header. */
66struct spci_message {
67 /*
68 * TODO: version is part of SPCI alpha2 but will be
69 * removed in the next spec revision hence we are not
70 * including it in the header.
71 */
72
73 /**
74 * flags[0]:
75 * 0: Architected message payload;
76 * 1: Implementation defined message payload.
77 * flags[15:1] reserved (MBZ).
78 */
79 uint16_t flags;
80
81 /*
82 * TODO: Padding is present to ensure controlled offset
83 * of the length field. SPCI spec must be updated
84 * to reflect this (TBD).
85 */
86 uint16_t reserved_1;
87 uint32_t length;
88
89 spci_vm_id_t target_vm_id;
90
91 spci_vm_id_t source_vm_id;
92
93 /*
94 * TODO: Padding is present to ensure that the field
95 * payload alignment is 64B. SPCI spec must be updated
96 * to reflect this.
97 */
98 uint32_t reserved_2;
99
100 uint8_t payload[];
101};
102
103/**
104 * Set the SPCI common message header fields.
105 */
106static inline void spci_message_init(struct spci_message *message,
107 uint32_t message_length,
108 spci_vm_id_t target_vm_id,
109 spci_vm_id_t source_vm_id)
110{
111 message->flags = SPCI_MESSAGE_IMPDEF_MASK;
112 message->length = message_length;
113 message->target_vm_id = target_vm_id;
114 message->source_vm_id = source_vm_id;
115
116 /*
117 * TODO: Reserved fields in the common message header will be
118 * defined as MBZ in next SPCI spec updates.
119 */
120 message->reserved_1 = 0;
121 message->reserved_2 = 0;
122}