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 <lk/compiler.h>
20 #include <stdint.h>
21 
22 #include <interface/secure_fb/secure_fb.h>
23 
24 __BEGIN_CDECLS
25 
26 typedef enum {
27     TTUI_ERROR_OK = 0,
28     TTUI_ERROR_NO_FRAMEBUFFER,
29     TTUI_ERROR_MEMORY_ALLOCATION_FAILED,
30     TTUI_ERROR_UNEXPECTED_NULL_PTR,
31     TTUI_ERROR_NO_SERVICE,
32 } secure_fb_error;
33 
34 typedef void* secure_fb_handle_t;
35 
36 /**
37  * secure_fb_open() - Open a new secure framebuffer session. If returns
38  * TUI_ERROR_OK, the given @fb_info is filled with valid framebuffer
39  * information. Valid means:
40  * * fb_info->buffer points to a writable region of memory of at least
41  *   fb_info->size bytes length.
42  * * fb_info->pixel_stride is greater or equal to the required width for the
43  *   pixel format indicated in fb_info->pixel_format.
44  * * fb_info->width * fb_info->pixel_stride <= fb_info->line_stride.
45  * * fb_info->height * fb_info->line_stride <= fb_info->size.
46  *
47  * Above this, the frame buffer dimensions must be such that the frame buffer
48  * fills the whole primary device screen.
49  *
50  * @session: A pointer that will be initialized with the new session context.
51  * @fb_info: Output parameter that holds the framebuffer description of the
52  *           next framebuffer that will be displayed on the next call to
53  *           secure_fb_display_next().
54  * @idx:     Index of the secure_fb corresponding to each physical display.
55  *           The index starts from 0 and up to SECURE_FB_MAX_INST-1. The client
56  *           should call the function with idx starting from 0 and keep
57  *           increasing the idx up to either SECURE_FB_MAX_INST-1 or the
58  *           function returns TTUI_ERROR_NO_SERVICE.
59  * Return:
60  * TTUI_ERROR_OK - on success.
61  * TTUI_ERROR_NO_FRAMEBUFFER - if no next framebuffer could be found.
62  * TTUI_ERROR_MEMORY_ALLOCATION_FAILED - if any memory allocation failed.
63  * TTUI_ERROR_UNEXPECTED_NULL_PTR - if the a parameter was NULL.
64  * TTUI_ERROR_NO_SERVICE - if the idx exceeds the maximum number of the physical
65  *                         display that the systen supports.
66  */
67 secure_fb_error secure_fb_open(secure_fb_handle_t* session,
68                                struct secure_fb_info* fb_info,
69                                uint32_t idx);
70 
71 /**
72  * secure_fb_display_next() - Indicates to the subsystem that the next buffer
73  * is ready to be displayed. The next buffer is always the last buffer returned
74  * by secure_fb_open() or secure_fb_display_next(). The content of the
75  * structure pointed to by @fb_info is ignored and replaced with a new
76  * off-screen framebuffer, that the caller can use to render the next frame. If
77  * return TUI_ERROR_OK:
78  * * The last buffer returned by secure_fb_open() or secure_fb_display_next()
79  *   gets displayed.
80  * * The first call to this routine starts the TUI session, i.e. the secure
81  *   output path is configured and verified:
82  * * The power supply to the display panel and controller gets sanitized and
83  *   locked.
84  * * The display controller's secure resources get locked and configured for
85  *   secure output.
86  * * The display controller's state gets sanitized.
87  * * The framebuffer gets configured as the secure scanout region.
88  *
89  * @session: A session handle as created by secure_fb_open().
90  * @fb_info: Output parameter that holds the frame buffer description for the
91  *           next frame buffer.
92  *
93  * Return:
94  * TTUI_ERROR_OK - on success.
95  * TTUI_ERROR_NO_FRAMEBUFFER - if no next framebuffer could be found.
96  * TTUI_ERROR_MEMORY_ALLOCATION_FAILED - if any memory allocation failed.
97  * TTUI_ERROR_UNEXPECTED_NULL_PTR - if the a parameter was NULL.
98  */
99 secure_fb_error secure_fb_display_next(secure_fb_handle_t session,
100                                        struct secure_fb_info* fb_info);
101 
102 /**
103  * secure_fb_close() -  Wipe the secure frame buffers. Relinquishes control over
104  * secure display resources. If secure_fb_close() encounters any irregularity it
105  * does not return but causes the SOC to reset.
106  *
107  * @session: A session handle as created by secure_fb_open.
108  */
109 void secure_fb_close(secure_fb_handle_t session);
110 
111 __END_CDECLS
112