J-Alves | 2f86c1e | 2022-02-23 18:44:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 The Hafnium Authors. |
| 3 | * |
| 4 | * 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. |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "hf/check.h" |
| 12 | #include "hf/mm.h" |
| 13 | #include "hf/types.h" |
| 14 | |
| 15 | #define SP_PKG_HEADER_MAGIC 0x474b5053U |
J-Alves | 60984ce | 2022-04-27 15:27:29 +0100 | [diff] [blame] | 16 | #define SP_PKG_HEADER_VERSION_1 0x1U |
| 17 | #define SP_PKG_HEADER_VERSION_2 0x2U |
J-Alves | 2f86c1e | 2022-02-23 18:44:19 +0000 | [diff] [blame] | 18 | |
Olivier Deprez | b76307d | 2022-06-09 17:17:45 +0200 | [diff] [blame] | 19 | #define SP_PKG_FLAG_BOOT_INFO (UINT32_C(1) << 0) |
J-Alves | 2f86c1e | 2022-02-23 18:44:19 +0000 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Header for a SP Partition Package. |
| 23 | */ |
| 24 | struct sp_pkg_header { |
| 25 | /** Magic used to identify a SP package. Value is "SPKG". */ |
| 26 | uint32_t magic; |
| 27 | /** Version number of the header. */ |
| 28 | uint32_t version; |
| 29 | /** Offset in bytes to the partition manifests. */ |
| 30 | uint32_t pm_offset; |
| 31 | /** Size in bytes of the partition manifest. */ |
| 32 | uint32_t pm_size; |
| 33 | /** Offset in bytes to the base address of the partition binary. */ |
| 34 | uint32_t img_offset; |
| 35 | /** Size in bytes of the partition binary. */ |
| 36 | uint32_t img_size; |
| 37 | }; |
| 38 | |
| 39 | static inline size_t sp_pkg_get_mem_size(struct sp_pkg_header *sp_pkg) |
| 40 | { |
| 41 | assert(SIZE_MAX - sp_pkg->img_offset >= (size_t)sp_pkg->img_size); |
| 42 | return (size_t)(sp_pkg->img_offset + sp_pkg->img_size); |
| 43 | } |
| 44 | |
J-Alves | 7e67d10 | 2022-04-13 13:22:39 +0100 | [diff] [blame] | 45 | /** Get the size of the boot information descriptors section. */ |
| 46 | static inline size_t sp_pkg_get_boot_info_size(struct sp_pkg_header *sp_pkg) |
| 47 | { |
| 48 | return sp_pkg->pm_offset; |
| 49 | } |
| 50 | |
J-Alves | 2f86c1e | 2022-02-23 18:44:19 +0000 | [diff] [blame] | 51 | bool sp_pkg_init(struct mm_stage1_locked stage1_locked, paddr_t pkg_start, |
| 52 | struct sp_pkg_header *header, struct mpool *ppool); |
| 53 | |
| 54 | void sp_pkg_deinit(struct mm_stage1_locked stage1_locked, vaddr_t pkg_start, |
| 55 | struct sp_pkg_header *header, struct mpool *ppool); |