Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
Harinarayan Bhatta | 57de1ea | 2016-11-29 16:33:23 -0600 | [diff] [blame] | 2 | /* |
| 3 | * OP-TEE related definitions |
| 4 | * |
| 5 | * (C) Copyright 2016 Linaro Limited |
| 6 | * Andrew F. Davis <andrew.davis@linaro.org> |
Harinarayan Bhatta | 57de1ea | 2016-11-29 16:33:23 -0600 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _OPTEE_H |
| 10 | #define _OPTEE_H |
| 11 | |
Bryan O'Donoghue | 32ce617 | 2018-03-13 16:50:27 +0000 | [diff] [blame] | 12 | #include <linux/errno.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 13 | #include <image.h> |
Bryan O'Donoghue | 32ce617 | 2018-03-13 16:50:27 +0000 | [diff] [blame] | 14 | |
Harinarayan Bhatta | 57de1ea | 2016-11-29 16:33:23 -0600 | [diff] [blame] | 15 | #define OPTEE_MAGIC 0x4554504f |
| 16 | #define OPTEE_VERSION 1 |
| 17 | #define OPTEE_ARCH_ARM32 0 |
| 18 | #define OPTEE_ARCH_ARM64 1 |
| 19 | |
| 20 | struct 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 Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 32 | static inline uint32_t |
Simon Glass | f3543e6 | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 33 | optee_image_get_entry_point(const struct legacy_img_hdr *hdr) |
Bryan O'Donoghue | f794436 | 2018-03-13 16:50:31 +0000 | [diff] [blame] | 34 | { |
| 35 | struct optee_header *optee_hdr = (struct optee_header *)(hdr + 1); |
| 36 | |
| 37 | return optee_hdr->init_load_addr_lo; |
| 38 | } |
| 39 | |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 40 | static inline uint32_t |
Simon Glass | f3543e6 | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 41 | optee_image_get_load_addr(const struct legacy_img_hdr *hdr) |
Bryan O'Donoghue | dd5a12e | 2018-03-13 16:50:32 +0000 | [diff] [blame] | 42 | { |
| 43 | return optee_image_get_entry_point(hdr) - sizeof(struct optee_header); |
| 44 | } |
| 45 | |
Patrick Delaunay | 51827f9 | 2021-09-02 11:56:16 +0200 | [diff] [blame] | 46 | #if defined(CONFIG_OPTEE_IMAGE) |
Bryan O'Donoghue | c5a6e8b | 2018-03-13 16:50:33 +0000 | [diff] [blame] | 47 | int optee_verify_bootm_image(unsigned long image_addr, |
| 48 | unsigned long image_load_addr, |
| 49 | unsigned long image_len); |
| 50 | #else |
| 51 | static inline int optee_verify_bootm_image(unsigned long image_addr, |
| 52 | unsigned long image_load_addr, |
| 53 | unsigned long image_len) |
| 54 | { |
| 55 | return -EPERM; |
| 56 | } |
| 57 | #endif |
| 58 | |
Patrick Delaunay | 51827f9 | 2021-09-02 11:56:16 +0200 | [diff] [blame] | 59 | #if defined(CONFIG_OPTEE_LIB) && defined(CONFIG_OF_LIBFDT) |
Patrick Delaunay | a253524 | 2021-02-08 13:54:31 +0100 | [diff] [blame] | 60 | int optee_copy_fdt_nodes(void *new_blob); |
Heiko Stuebner | 6ccb05e | 2019-10-23 16:46:40 +0200 | [diff] [blame] | 61 | #else |
Patrick Delaunay | a253524 | 2021-02-08 13:54:31 +0100 | [diff] [blame] | 62 | static inline int optee_copy_fdt_nodes(void *new_blob) |
Heiko Stuebner | 6ccb05e | 2019-10-23 16:46:40 +0200 | [diff] [blame] | 63 | { |
| 64 | return 0; |
| 65 | } |
| 66 | #endif |
| 67 | |
Harinarayan Bhatta | 57de1ea | 2016-11-29 16:33:23 -0600 | [diff] [blame] | 68 | #endif /* _OPTEE_H */ |