1 /*
2  * Copyright 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 /**
22  * DOC: Secure DPU
23  *
24  * The Secure DPU works as the persistent channel between the non-secure and the
25  * secure world. The channel is established during the boot up stage of the
26  * non-secure world system. In general, the established channel allows the
27  * secure world applications initiate requests or notifications to the non-secure
28  * world.
29  *
30  * For particular devices, the secure world can only perform operations on the
31  * display when in the TUI session if device-specific setup is done by the
32  * non-secure world. Besides, the non-secure world could allocate framebuffer
33  * for the secure world application if the memory is limited in the secure world
34  * on specific devices.
35  *
36  * Currently, supported requests are to start / stop the secure display mode and
37  * to allocate framebuffer.
38  *
39  * This header file needs to be synced on both the Trusty and the Android
40  * codebase.
41  */
42 
43 #define SECURE_DPU_PORT_NAME "com.android.trusty.secure_dpu"
44 #define SECURE_DPU_MAX_MSG_SIZE 64
45 
46 /**
47  * enum secure_dpu_cmd - command identifiers for secure_fb interface
48  * @SECURE_DPU_CMD_RESP_BIT:
49  *      Message is a response.
50  * @SECURE_DPU_CMD_REQ_SHIFT:
51  *      Number of bits used by @SECURE_DPU_CMD_RESP_BIT.
52  * @SECURE_DPU_CMD_START_SECURE_DISPLAY:
53  *      Notify the system to start secure display mode
54  * @SECURE_DPU_CMD_STOP_SECURE_DISPLAY:
55  *      Notify the system to stop secure display mode
56  * @SECURE_DPU_CMD_ALLOCATE_BUFFER:
57  *      Request non-secure world to allocate the buffer
58  */
59 enum secure_dpu_cmd {
60     SECURE_DPU_CMD_RESP_BIT = 1,
61     SECURE_DPU_CMD_REQ_SHIFT = 1,
62     SECURE_DPU_CMD_START_SECURE_DISPLAY = (1 << SECURE_DPU_CMD_REQ_SHIFT),
63     SECURE_DPU_CMD_STOP_SECURE_DISPLAY = (2 << SECURE_DPU_CMD_REQ_SHIFT),
64     SECURE_DPU_CMD_ALLOCATE_BUFFER = (3 << SECURE_DPU_CMD_REQ_SHIFT),
65 };
66 
67 /**
68  * struct secure_dpu_allocate_buffer_req - payload for
69  *                                         %SECURE_DPU_CMD_ALLOCATE_BUFFER
70  *                                         request
71  * @buffer_len: Requested length
72  */
73 struct secure_dpu_allocate_buffer_req {
74     uint64_t buffer_len;
75 };
76 
77 /**
78  * struct secure_dpu_allocate_buffer_resp - payload for
79  *                                          %SECURE_DPU_CMD_ALLOCATE_BUFFER
80  *                                          response
81  * @buffer_len: Allocated length
82  */
83 struct secure_dpu_allocate_buffer_resp {
84     uint64_t buffer_len;
85 };
86 
87 /**
88  * struct secure_fb_req - common structure for secure_fb requests.
89  * @cmd: Command identifier - one of &enum secure_dpu_cmd.
90  */
91 struct secure_dpu_req {
92     uint32_t cmd;
93 };
94 
95 /**
96  * struct secure_dpu_resp - common structure for secure_dpu responses.
97  * @cmd:    Command identifier - %SECURE_DPU_CMD_RESP_BIT or'ed with the
98  *                               command identifier of the corresponding
99  *                               request.
100  * @status: Status of requested operation. One of &enum secure_dpu_error.
101  */
102 struct secure_dpu_resp {
103     uint32_t cmd;
104     int32_t status;
105 };
106 
107 enum secure_dpu_error {
108     SECURE_DPU_ERROR_OK = 0,
109     SECURE_DPU_ERROR_FAIL = -1,
110     SECURE_DPU_ERROR_UNINITIALIZED = -2,
111     SECURE_DPU_ERROR_PARAMETERS = -3,
112     SECURE_DPU_ERROR_NO_MEMORY = -4,
113 };
114