blob: 209d9f697e7bb4eed35d54e7aa79c4046489779f [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. */
50#define SPCI_MSG_RECV_BLOCK_MASK 0x1
51#define SPCI_MSG_SEND_NOTIFY_MASK 0x1
52
53#define SPCI_MESSAGE_IMPDEF_MASK 0x1
54
55#define SPCI_MSG_SEND_NOTIFY 0x1
56#define SPCI_MSG_RECV_BLOCK 0x1
57
58/* clang-format on */
59
60typedef uint16_t spci_vm_id_t;
61
62/** SPCI common message header. */
63struct spci_message {
64 /*
65 * TODO: version is part of SPCI alpha2 but will be
66 * removed in the next spec revision hence we are not
67 * including it in the header.
68 */
69
70 /**
71 * flags[0]:
72 * 0: Architected message payload;
73 * 1: Implementation defined message payload.
74 * flags[15:1] reserved (MBZ).
75 */
76 uint16_t flags;
77
78 /*
79 * TODO: Padding is present to ensure controlled offset
80 * of the length field. SPCI spec must be updated
81 * to reflect this (TBD).
82 */
83 uint16_t reserved_1;
84 uint32_t length;
85
86 spci_vm_id_t target_vm_id;
87
88 spci_vm_id_t source_vm_id;
89
90 /*
91 * TODO: Padding is present to ensure that the field
92 * payload alignment is 64B. SPCI spec must be updated
93 * to reflect this.
94 */
95 uint32_t reserved_2;
96
97 uint8_t payload[];
98};
99
100/**
101 * Set the SPCI common message header fields.
102 */
103static inline void spci_message_init(struct spci_message *message,
104 uint32_t message_length,
105 spci_vm_id_t target_vm_id,
106 spci_vm_id_t source_vm_id)
107{
108 message->flags = SPCI_MESSAGE_IMPDEF_MASK;
109 message->length = message_length;
110 message->target_vm_id = target_vm_id;
111 message->source_vm_id = source_vm_id;
112
113 /*
114 * TODO: Reserved fields in the common message header will be
115 * defined as MBZ in next SPCI spec updates.
116 */
117 message->reserved_1 = 0;
118 message->reserved_2 = 0;
119}