refactor: added "sp_pkg" module
Added module "sp_pkg" to init and help operate the SP pkg, such that
hafnium can cleanly retrieve the FF-A manifest's and the boot info's
base address.
Change-Id: Ieb6925c487a4dac9b460353ba82a00d670176037
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/inc/hf/sp_pkg.h b/inc/hf/sp_pkg.h
new file mode 100644
index 0000000..5e5f545
--- /dev/null
+++ b/inc/hf/sp_pkg.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2022 The Hafnium Authors.
+ *
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file or at
+ * https://opensource.org/licenses/BSD-3-Clause.
+ */
+
+#pragma once
+
+#include "hf/check.h"
+#include "hf/mm.h"
+#include "hf/types.h"
+
+#define SP_PKG_HEADER_MAGIC 0x474b5053U
+#define SP_PKG_HEADER_VERSION 0x2U
+
+#define SP_PKG_FLAG_BOOT_INFO UINT32_C(0x1U << 0)
+
+/**
+ * Header for a SP Partition Package.
+ */
+struct sp_pkg_header {
+ /** Magic used to identify a SP package. Value is "SPKG". */
+ uint32_t magic;
+ /** Version number of the header. */
+ uint32_t version;
+ /** Offset in bytes to the partition manifests. */
+ uint32_t pm_offset;
+ /** Size in bytes of the partition manifest. */
+ uint32_t pm_size;
+ /** Offset in bytes to the base address of the partition binary. */
+ uint32_t img_offset;
+ /** Size in bytes of the partition binary. */
+ uint32_t img_size;
+};
+
+static inline size_t sp_pkg_get_mem_size(struct sp_pkg_header *sp_pkg)
+{
+ assert(SIZE_MAX - sp_pkg->img_offset >= (size_t)sp_pkg->img_size);
+ return (size_t)(sp_pkg->img_offset + sp_pkg->img_size);
+}
+
+bool sp_pkg_init(struct mm_stage1_locked stage1_locked, paddr_t pkg_start,
+ struct sp_pkg_header *header, struct mpool *ppool);
+
+void sp_pkg_deinit(struct mm_stage1_locked stage1_locked, vaddr_t pkg_start,
+ struct sp_pkg_header *header, struct mpool *ppool);