blob: e55ea97a22ab476db0e342bc90188350fabec694 [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;
Andrew Walbranc6d23c42019-06-26 13:30:42 +010071
72/** The index of a vCPU within a particular VM. */
Andrew Walbranb037d5b2019-06-25 17:19:41 +010073typedef uint16_t spci_vcpu_index_t;
Andrew Walbran52d99672019-06-25 15:51:11 +010074
Andrew Walbranc6d23c42019-06-26 13:30:42 +010075/**
76 * A count of vCPUs. This has the same range as the vCPU indices but we give it
77 * a different name to make the different semantics clear.
78 */
79typedef spci_vcpu_index_t spci_vcpu_count_t;
80
Jose Marinho4e4e4d52019-02-22 16:23:51 +000081/** SPCI common message header. */
82struct spci_message {
83 /*
84 * TODO: version is part of SPCI alpha2 but will be
85 * removed in the next spec revision hence we are not
86 * including it in the header.
87 */
88
89 /**
90 * flags[0]:
91 * 0: Architected message payload;
92 * 1: Implementation defined message payload.
93 * flags[15:1] reserved (MBZ).
94 */
95 uint16_t flags;
96
97 /*
98 * TODO: Padding is present to ensure controlled offset
99 * of the length field. SPCI spec must be updated
100 * to reflect this (TBD).
101 */
102 uint16_t reserved_1;
Andrew Sculla1aa2ba2019-04-05 11:49:02 +0100103
Jose Marinho4e4e4d52019-02-22 16:23:51 +0000104 uint32_t length;
Jose Marinho4e4e4d52019-02-22 16:23:51 +0000105 spci_vm_id_t target_vm_id;
Jose Marinho4e4e4d52019-02-22 16:23:51 +0000106 spci_vm_id_t source_vm_id;
107
108 /*
109 * TODO: Padding is present to ensure that the field
110 * payload alignment is 64B. SPCI spec must be updated
111 * to reflect this.
112 */
113 uint32_t reserved_2;
114
115 uint8_t payload[];
116};
117
118/**
119 * Set the SPCI common message header fields.
120 */
121static inline void spci_message_init(struct spci_message *message,
122 uint32_t message_length,
123 spci_vm_id_t target_vm_id,
124 spci_vm_id_t source_vm_id)
125{
126 message->flags = SPCI_MESSAGE_IMPDEF_MASK;
127 message->length = message_length;
128 message->target_vm_id = target_vm_id;
129 message->source_vm_id = source_vm_id;
130
131 /*
132 * TODO: Reserved fields in the common message header will be
133 * defined as MBZ in next SPCI spec updates.
134 */
135 message->reserved_1 = 0;
136 message->reserved_2 = 0;
137}