David Brazdil | 7a462ec | 2019-08-15 12:27:47 +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 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 19 | #include "hf/fdt.h" |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 20 | #include "hf/memiter.h" |
| 21 | #include "hf/spci.h" |
| 22 | |
| 23 | /** |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 24 | * Maximum length of a string parsed from the FDT, including NULL terminator. |
| 25 | */ |
| 26 | #define MANIFEST_MAX_STRING_LENGTH 32 |
| 27 | |
| 28 | /** |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 29 | * Holds information about one of the VMs described in the manifest. |
| 30 | */ |
| 31 | struct manifest_vm { |
| 32 | /* Properties defined for both primary and secondary VMs. */ |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 33 | char debug_name[MANIFEST_MAX_STRING_LENGTH]; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 34 | |
| 35 | /* Properties specific to secondary VMs. */ |
| 36 | struct { |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 37 | char kernel_filename[MANIFEST_MAX_STRING_LENGTH]; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 38 | uint64_t mem_size; |
| 39 | spci_vcpu_count_t vcpu_count; |
| 40 | } secondary; |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * Hafnium manifest parsed from FDT. |
| 45 | */ |
| 46 | struct manifest { |
David Brazdil | 0251b94 | 2019-09-10 15:59:50 +0100 | [diff] [blame^] | 47 | spci_vm_count_t vm_count; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 48 | struct manifest_vm vm[MAX_VMS]; |
| 49 | }; |
| 50 | |
| 51 | enum manifest_return_code { |
| 52 | MANIFEST_SUCCESS = 0, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 53 | MANIFEST_ERROR_NO_HYPERVISOR_FDT_NODE, |
David Brazdil | 74e9c3b | 2019-08-28 11:09:08 +0100 | [diff] [blame] | 54 | MANIFEST_ERROR_NOT_COMPATIBLE, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 55 | MANIFEST_ERROR_RESERVED_VM_ID, |
| 56 | MANIFEST_ERROR_NO_PRIMARY_VM, |
| 57 | MANIFEST_ERROR_TOO_MANY_VMS, |
| 58 | MANIFEST_ERROR_PROPERTY_NOT_FOUND, |
| 59 | MANIFEST_ERROR_MALFORMED_STRING, |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 60 | MANIFEST_ERROR_STRING_TOO_LONG, |
David Brazdil | 74e9c3b | 2019-08-28 11:09:08 +0100 | [diff] [blame] | 61 | MANIFEST_ERROR_MALFORMED_STRING_LIST, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 62 | MANIFEST_ERROR_MALFORMED_INTEGER, |
| 63 | MANIFEST_ERROR_INTEGER_OVERFLOW, |
| 64 | }; |
| 65 | |
| 66 | enum manifest_return_code manifest_init(struct manifest *manifest, |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 67 | const struct fdt_node *fdt_root); |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 68 | |
| 69 | const char *manifest_strerror(enum manifest_return_code ret_code); |