Jose Marinho | fc0b2b6 | 2019-06-06 11:18:45 +0100 | [diff] [blame] | 1 | /* |
| 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 | #pragma once |
| 18 | |
Andrew Walbran | 475c145 | 2020-02-07 13:22:22 +0000 | [diff] [blame] | 19 | #include <stdint.h> |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 20 | |
Andrew Walbran | 352aa3d | 2020-05-01 17:51:33 +0100 | [diff] [blame^] | 21 | #include "hf/check.h" |
| 22 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 23 | #include "vmapi/hf/ffa.h" |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 24 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 25 | #define FFA_VERSION_MAJOR 0x1 |
| 26 | #define FFA_VERSION_MINOR 0x0 |
Jose Marinho | fc0b2b6 | 2019-06-06 11:18:45 +0100 | [diff] [blame] | 27 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 28 | #define FFA_VERSION_MAJOR_OFFSET 16 |
| 29 | #define FFA_VERSION_RESERVED_BIT UINT32_C(1U << 31) |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 30 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 31 | static inline struct ffa_value ffa_error(uint64_t error_code) |
Andrew Walbran | d4d2fa1 | 2019-10-01 16:47:25 +0100 | [diff] [blame] | 32 | { |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 33 | return (struct ffa_value){.func = FFA_ERROR_32, .arg2 = error_code}; |
Andrew Walbran | d4d2fa1 | 2019-10-01 16:47:25 +0100 | [diff] [blame] | 34 | } |
Andrew Walbran | 352aa3d | 2020-05-01 17:51:33 +0100 | [diff] [blame^] | 35 | |
| 36 | /** |
| 37 | * Return the offset to the first constituent within the |
| 38 | * `ffa_composite_memory_region` for the given receiver from an |
| 39 | * `ffa_memory_region`. The caller must check that the receiver_index is within |
| 40 | * bounds, and that it has a composite memory region offset. |
| 41 | */ |
| 42 | static inline uint32_t ffa_composite_constituent_offset( |
| 43 | struct ffa_memory_region *memory_region, uint32_t receiver_index) |
| 44 | { |
| 45 | CHECK(receiver_index < memory_region->receiver_count); |
| 46 | CHECK(memory_region->receivers[receiver_index] |
| 47 | .composite_memory_region_offset != 0); |
| 48 | |
| 49 | return memory_region->receivers[receiver_index] |
| 50 | .composite_memory_region_offset + |
| 51 | sizeof(struct ffa_composite_memory_region); |
| 52 | } |