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 <interface/secure_fb/secure_fb.h>
20 #include <lk/compiler.h>
21 #include <stdint.h>
22 #include <trusty_ipc.h>
23 
24 __BEGIN_CDECLS
25 
26 /**
27  *  DOC: API notes
28  *
29  *  This header defines an API for implementing hardware-specific secure
30  *  framebuffer driver. It is expected that it will be working in conjunction
31  *  with a higher level service that will make calls described here.
32  */
33 
34 typedef void* secure_fb_handle_t;
35 
36 struct secure_fb_impl_buffers {
37     size_t num_fbs;
38     struct secure_fb_desc fbs[SECURE_FB_MAX_FBS];
39     size_t num_handles;
40     handle_t handles[SECURE_FB_MAX_FBS];
41 };
42 
43 /*
44  * struct secure_fb_impl_ops - secure_fb_impl ops (callbacks)
45  * @init:       is invoked when the client init the secure_fb resource.
46  * @get_fbs:    is invoked when the client requests the framebuffer
47  * @display_fb: is invoked when the client requests to draw the framebuffer to
48  *              display
49  * @release:    is invoked when the client request to release all requested
50  *              resources.
51  *
52  * init() - This function together with release()
53  * frames the life cycle of a secure_fb session. The life cycle begins with this
54  * function, and the session is represented by the returned handle.
55  * Return: Session handle for the secure_fb session or NULL on failure.
56  *
57  * get_fbs() - Gets a set of up to %SECURE_FB_MAX_FBS buffers
58  * that can be used for rendering. The number of buffers is implementation
59  * defined.
60  * @session: The active session as returned by a previous call to
61  *           init().
62  * @buffers: Describes the buffers returned.
63  *
64  * Return: SECURE_FB_ERROR_OK on success, or an error code < 0 on failure.
65  *
66  * display_fb() - Select one of the buffers returned by get_fbs() as active
67  * buffer. If only one buffer was returned this function doubles as render
68  * complete barrier indicating to the driver that the screen may be updated.
69  * @session:   The active session as returned by a previous call to
70  *             init().
71  * @buffer_id: Indicates one of the buffers returned by get_fbs(). The
72  * @buffer_id is not an index. It can be found at @buffers.fbs[index].buffer_id
73  *             with @buffers being the structure returned by get_fbs().
74  * Return: SECURE_FB_ERROR_OK on success, or an error code < 0 on failure.
75  *
76  * release() - Ends the life cycle of the a secure_fb session.
77  * It must relinquish all resources associated with the secure_fb session.
78  *
79  * @session: The active session as returned by a previous call to
80  *           init().
81  *
82  * Return: SECURE_FB_ERROR_OK on success, or an error code < 0 on failure.
83  */
84 struct secure_fb_impl_ops {
85     secure_fb_handle_t (*init)(void);
86     int (*get_fbs)(secure_fb_handle_t session,
87                    struct secure_fb_impl_buffers* buffers);
88     int (*display_fb)(secure_fb_handle_t session, uint32_t buffer_id);
89     int (*release)(secure_fb_handle_t session);
90 };
91 __END_CDECLS
92