blob: 182840abfcc3a3a8c3e40b4d2474c72676c6838e [file] [log] [blame]
J-Alves2f86c1e2022-02-23 18:44:19 +00001/*
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-Alves60984ce2022-04-27 15:27:29 +010016#define SP_PKG_HEADER_VERSION_1 0x1U
17#define SP_PKG_HEADER_VERSION_2 0x2U
J-Alves2f86c1e2022-02-23 18:44:19 +000018
Olivier Deprezb76307d2022-06-09 17:17:45 +020019#define SP_PKG_FLAG_BOOT_INFO (UINT32_C(1) << 0)
J-Alves2f86c1e2022-02-23 18:44:19 +000020
21/**
22 * Header for a SP Partition Package.
23 */
24struct 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
39static 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-Alves7e67d102022-04-13 13:22:39 +010045/** Get the size of the boot information descriptors section. */
46static 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-Alves2f86c1e2022-02-23 18:44:19 +000051bool sp_pkg_init(struct mm_stage1_locked stage1_locked, paddr_t pkg_start,
52 struct sp_pkg_header *header, struct mpool *ppool);
53
54void sp_pkg_deinit(struct mm_stage1_locked stage1_locked, vaddr_t pkg_start,
55 struct sp_pkg_header *header, struct mpool *ppool);