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> |
| 13 | |
Harinarayan Bhatta | 57de1ea | 2016-11-29 16:33:23 -0600 | [diff] [blame] | 14 | #define OPTEE_MAGIC 0x4554504f |
| 15 | #define OPTEE_VERSION 1 |
| 16 | #define OPTEE_ARCH_ARM32 0 |
| 17 | #define OPTEE_ARCH_ARM64 1 |
| 18 | |
| 19 | struct optee_header { |
| 20 | uint32_t magic; |
| 21 | uint8_t version; |
| 22 | uint8_t arch; |
| 23 | uint16_t flags; |
| 24 | uint32_t init_size; |
| 25 | uint32_t init_load_addr_hi; |
| 26 | uint32_t init_load_addr_lo; |
| 27 | uint32_t init_mem_usage; |
| 28 | uint32_t paged_size; |
| 29 | }; |
| 30 | |
Bryan O'Donoghue | f794436 | 2018-03-13 16:50:31 +0000 | [diff] [blame] | 31 | static inline uint32_t optee_image_get_entry_point(const image_header_t *hdr) |
| 32 | { |
| 33 | struct optee_header *optee_hdr = (struct optee_header *)(hdr + 1); |
| 34 | |
| 35 | return optee_hdr->init_load_addr_lo; |
| 36 | } |
| 37 | |
Bryan O'Donoghue | dd5a12e | 2018-03-13 16:50:32 +0000 | [diff] [blame] | 38 | static inline uint32_t optee_image_get_load_addr(const image_header_t *hdr) |
| 39 | { |
| 40 | return optee_image_get_entry_point(hdr) - sizeof(struct optee_header); |
| 41 | } |
| 42 | |
Bryan O'Donoghue | 32ce617 | 2018-03-13 16:50:27 +0000 | [diff] [blame] | 43 | #if defined(CONFIG_OPTEE) |
| 44 | int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start, |
| 45 | unsigned long tzdram_len, unsigned long image_len); |
| 46 | #else |
| 47 | static inline int optee_verify_image(struct optee_header *hdr, |
| 48 | unsigned long tzdram_start, |
| 49 | unsigned long tzdram_len, |
| 50 | unsigned long image_len) |
| 51 | { |
| 52 | return -EPERM; |
| 53 | } |
| 54 | |
| 55 | #endif |
| 56 | |
Bryan O'Donoghue | c5a6e8b | 2018-03-13 16:50:33 +0000 | [diff] [blame] | 57 | #if defined(CONFIG_OPTEE) |
| 58 | int optee_verify_bootm_image(unsigned long image_addr, |
| 59 | unsigned long image_load_addr, |
| 60 | unsigned long image_len); |
| 61 | #else |
| 62 | static inline int optee_verify_bootm_image(unsigned long image_addr, |
| 63 | unsigned long image_load_addr, |
| 64 | unsigned long image_len) |
| 65 | { |
| 66 | return -EPERM; |
| 67 | } |
| 68 | #endif |
| 69 | |
Harinarayan Bhatta | 57de1ea | 2016-11-29 16:33:23 -0600 | [diff] [blame] | 70 | #endif /* _OPTEE_H */ |