blob: ebdfe5e98d75e57cb77ba01a1f617225ce3e1203 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: BSD-2-Clause */
Harinarayan Bhatta57de1ea2016-11-29 16:33:23 -06002/*
3 * OP-TEE related definitions
4 *
5 * (C) Copyright 2016 Linaro Limited
6 * Andrew F. Davis <andrew.davis@linaro.org>
Harinarayan Bhatta57de1ea2016-11-29 16:33:23 -06007 */
8
9#ifndef _OPTEE_H
10#define _OPTEE_H
11
Bryan O'Donoghue32ce6172018-03-13 16:50:27 +000012#include <linux/errno.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060013#include <image.h>
Bryan O'Donoghue32ce6172018-03-13 16:50:27 +000014
Harinarayan Bhatta57de1ea2016-11-29 16:33:23 -060015#define OPTEE_MAGIC 0x4554504f
16#define OPTEE_VERSION 1
17#define OPTEE_ARCH_ARM32 0
18#define OPTEE_ARCH_ARM64 1
19
20struct optee_header {
21 uint32_t magic;
22 uint8_t version;
23 uint8_t arch;
24 uint16_t flags;
25 uint32_t init_size;
26 uint32_t init_load_addr_hi;
27 uint32_t init_load_addr_lo;
28 uint32_t init_mem_usage;
29 uint32_t paged_size;
30};
31
Simon Glass4d72caa2020-05-10 11:40:01 -060032static inline uint32_t
33optee_image_get_entry_point(const struct image_header *hdr)
Bryan O'Donoghuef7944362018-03-13 16:50:31 +000034{
35 struct optee_header *optee_hdr = (struct optee_header *)(hdr + 1);
36
37 return optee_hdr->init_load_addr_lo;
38}
39
Simon Glass4d72caa2020-05-10 11:40:01 -060040static inline uint32_t
41optee_image_get_load_addr(const struct image_header *hdr)
Bryan O'Donoghuedd5a12e2018-03-13 16:50:32 +000042{
43 return optee_image_get_entry_point(hdr) - sizeof(struct optee_header);
44}
45
Bryan O'Donoghue32ce6172018-03-13 16:50:27 +000046#if defined(CONFIG_OPTEE)
47int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start,
48 unsigned long tzdram_len, unsigned long image_len);
49#else
50static inline int optee_verify_image(struct optee_header *hdr,
51 unsigned long tzdram_start,
52 unsigned long tzdram_len,
53 unsigned long image_len)
54{
55 return -EPERM;
56}
57
58#endif
59
Bryan O'Donoghuec5a6e8b2018-03-13 16:50:33 +000060#if defined(CONFIG_OPTEE)
61int optee_verify_bootm_image(unsigned long image_addr,
62 unsigned long image_load_addr,
63 unsigned long image_len);
64#else
65static inline int optee_verify_bootm_image(unsigned long image_addr,
66 unsigned long image_load_addr,
67 unsigned long image_len)
68{
69 return -EPERM;
70}
71#endif
72
Heiko Stuebner6ccb05e2019-10-23 16:46:40 +020073#if defined(CONFIG_OPTEE) && defined(CONFIG_OF_LIBFDT)
Patrick Delaunaya2535242021-02-08 13:54:31 +010074int optee_copy_fdt_nodes(void *new_blob);
Heiko Stuebner6ccb05e2019-10-23 16:46:40 +020075#else
Patrick Delaunaya2535242021-02-08 13:54:31 +010076static inline int optee_copy_fdt_nodes(void *new_blob)
Heiko Stuebner6ccb05e2019-10-23 16:46:40 +020077{
78 return 0;
79}
80#endif
81
Harinarayan Bhatta57de1ea2016-11-29 16:33:23 -060082#endif /* _OPTEE_H */