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 "trusty/secure_dpu/SecureDpu.h"
20 #include <android-base/result.h>
21 #include <string>
22 #include <trusty/tipc.h>
23 
24 #include <BufferAllocator/BufferAllocatorWrapper.h>
25 
26 namespace android {
27 namespace trusty {
28 namespace secure_dpu {
29 
30 class DPUHandler {
31   private:
32     static constexpr const int kInvalidFd = -1;
33 
34     int dpu_handle_;
35     BufferAllocator* buf_allocator_;
36 
37     android::base::Result<void> HandleStartSecureDisplay();
38     android::base::Result<void> HandleStopSecureDisplay();
39     android::base::Result<void> AllocateBuffer(size_t req_buffer_len, size_t* allocated_buffer_len,
40                                                int* buf_fd);
41     android::base::Result<void> HandleAllocateBuffer(const secure_dpu_allocate_buffer_req* req);
42     android::base::Result<void> HandleCmd(const void* in_buf, const size_t in_size);
43 
44   public:
45     DPUHandler();
46     ~DPUHandler();
47     android::base::Result<void> Init(std::string device_name);
48     android::base::Result<void> Handle();
49 };
50 
51 }  // namespace secure_dpu
52 }  // namespace trusty
53 }  // namespace android
54