1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <stdint.h>
20 
21 #define APPLOADER_SECURE_PORT "com.android.trusty.apploader.secure"
22 
23 /**
24  * Secure world-only commands
25  */
26 enum apploader_secure_command : uint32_t {
27     APPLOADER_SECURE_REQ_SHIFT = 1,
28     APPLOADER_SECURE_RESP_BIT = 1,
29 
30     APPLOADER_SECURE_CMD_GET_MEMORY = (0 << APPLOADER_SECURE_REQ_SHIFT),
31     APPLOADER_SECURE_CMD_LOAD_APPLICATION = (1 << APPLOADER_SECURE_REQ_SHIFT),
32 };
33 
34 /**
35  * apploader_secure_header - Serial header for communicating with apploader
36  * @cmd: the command; one of &enum apploader_secure_command values.
37  */
38 struct apploader_secure_header {
39     uint32_t cmd;
40 } __PACKED;
41 
42 /**
43  * apploader_secure_get_memory_req - Serial header for GET_MEMORY command
44  * @package_size: the size of the application package.
45  *
46  * Request a kernel memory region of size @package_size from the service.
47  *
48  * The response is a &struct apploader_secure_resp with the error code or
49  * %APPLOADER_NO_ERROR on success. The response also contains exactly one
50  * handle to the memref for the allocated region.
51  */
52 struct apploader_secure_get_memory_req {
53     uint64_t package_size;
54 } __PACKED;
55 
56 /**
57  * apploader_secure_load_app_req - Serial header for LOAD_APPLICATION command
58  * @manifest_start: offset of the start of the manifest, relative to the start
59  *                  of the package.
60  * @manifest_end: offset of the end of the manifest.
61  * @img_start: offset of the start of the ELF image.
62  * @img_end: offset of the end of the ELF image.
63  *
64  * Load an application from a memory region previously returned by
65  * apploader_secure_get_memory_req. The service will internally keep a
66  * reference to this region across requests. @manifest_start and the other
67  * offsets point into this region.
68  *
69  * The response is a &struct apploader_secure_resp with the error code or
70  * %APPLOADER_NO_ERROR on success.
71  */
72 struct apploader_secure_load_app_req {
73     uint64_t manifest_start;
74     uint64_t manifest_end;
75     uint64_t img_start;
76     uint64_t img_end;
77 } __PACKED;
78 
79 /**
80  * apploader_resp - Common header for all secure world apploader responses
81  * @hdr - header with command value.
82  * @error - error code returned by peer; one of &enum apploader_error values.
83  *
84  * This structure is followed by the response-specific payload, if the command
85  * has one.
86  */
87 struct apploader_secure_resp {
88     struct apploader_secure_header hdr;
89     uint32_t error;
90 } __PACKED;
91