blob: c387e6271c9fddafb4987f6f8c4549833d88d5a7 [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
Andrew Walbran52d99672019-06-25 15:51:11 +010063/** The ID of a VM. These are assigned sequentially. */
Jose Marinho4e4e4d52019-02-22 16:23:51 +000064typedef uint16_t spci_vm_id_t;
65
Andrew Walbran52d99672019-06-25 15:51:11 +010066/**
67 * A count of VMs. This has the same range as the VM IDs but we give it a
68 * different name to make the different semantics clear.
69 */
70typedef spci_vm_id_t spci_vm_count_t;
71
Jose Marinho4e4e4d52019-02-22 16:23:51 +000072/** SPCI common message header. */
73struct spci_message {
74 /*
75 * TODO: version is part of SPCI alpha2 but will be
76 * removed in the next spec revision hence we are not
77 * including it in the header.
78 */
79
80 /**
81 * flags[0]:
82 * 0: Architected message payload;
83 * 1: Implementation defined message payload.
84 * flags[15:1] reserved (MBZ).
85 */
86 uint16_t flags;
87
88 /*
89 * TODO: Padding is present to ensure controlled offset
90 * of the length field. SPCI spec must be updated
91 * to reflect this (TBD).
92 */
93 uint16_t reserved_1;
Andrew Sculla1aa2ba2019-04-05 11:49:02 +010094
Jose Marinho4e4e4d52019-02-22 16:23:51 +000095 uint32_t length;
Jose Marinho4e4e4d52019-02-22 16:23:51 +000096 spci_vm_id_t target_vm_id;
Jose Marinho4e4e4d52019-02-22 16:23:51 +000097 spci_vm_id_t source_vm_id;
98
99 /*
100 * TODO: Padding is present to ensure that the field
101 * payload alignment is 64B. SPCI spec must be updated
102 * to reflect this.
103 */
104 uint32_t reserved_2;
105
106 uint8_t payload[];
107};
108
109/**
110 * Set the SPCI common message header fields.
111 */
112static inline void spci_message_init(struct spci_message *message,
113 uint32_t message_length,
114 spci_vm_id_t target_vm_id,
115 spci_vm_id_t source_vm_id)
116{
117 message->flags = SPCI_MESSAGE_IMPDEF_MASK;
118 message->length = message_length;
119 message->target_vm_id = target_vm_id;
120 message->source_vm_id = source_vm_id;
121
122 /*
123 * TODO: Reserved fields in the common message header will be
124 * defined as MBZ in next SPCI spec updates.
125 */
126 message->reserved_1 = 0;
127 message->reserved_2 = 0;
128}