blob: 8a35ebef81029a36f0f902fb9403c6d9eafa3cf4 [file] [log] [blame]
Jose Marinhofc0b2b62019-06-06 11:18:45 +01001/*
2 * Copyright 2019 The Hafnium Authors.
3 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
Jose Marinhofc0b2b62019-06-06 11:18:45 +01007 */
8
9#pragma once
10
Andrew Walbran475c1452020-02-07 13:22:22 +000011#include <stdint.h>
Jose Marinho75509b42019-04-09 09:34:59 +010012
Andrew Walbran352aa3d2020-05-01 17:51:33 +010013#include "hf/check.h"
14
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010015#include "vmapi/hf/ffa.h"
Jose Marinho75509b42019-04-09 09:34:59 +010016
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010017#define FFA_VERSION_RESERVED_BIT UINT32_C(1U << 31)
Jose Marinho75509b42019-04-09 09:34:59 +010018
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010019static inline struct ffa_value ffa_error(uint64_t error_code)
Andrew Walbrand4d2fa12019-10-01 16:47:25 +010020{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010021 return (struct ffa_value){.func = FFA_ERROR_32, .arg2 = error_code};
Andrew Walbrand4d2fa12019-10-01 16:47:25 +010022}
Andrew Walbran352aa3d2020-05-01 17:51:33 +010023
24/**
25 * Return the offset to the first constituent within the
26 * `ffa_composite_memory_region` for the given receiver from an
27 * `ffa_memory_region`. The caller must check that the receiver_index is within
28 * bounds, and that it has a composite memory region offset.
29 */
30static inline uint32_t ffa_composite_constituent_offset(
31 struct ffa_memory_region *memory_region, uint32_t receiver_index)
32{
33 CHECK(receiver_index < memory_region->receiver_count);
34 CHECK(memory_region->receivers[receiver_index]
35 .composite_memory_region_offset != 0);
36
37 return memory_region->receivers[receiver_index]
38 .composite_memory_region_offset +
39 sizeof(struct ffa_composite_memory_region);
40}