1 // Copyright (C) 2023 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License") override;
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <lib/magma/magma_common_defs.h>
18 
19 #include <optional>
20 #include <memory>
21 
22 #include "DrmBuffer.h"
23 #include "DrmContext.h"
24 #include "MonotonicMap.h"
25 #include "aemu/base/Compiler.h"
26 #include "aemu/base/ManagedDescriptor.hpp"
27 
28 namespace gfxstream {
29 namespace magma {
30 
31 class DrmBuffer;
32 
33 class DrmDevice {
34    public:
35     ~DrmDevice();
36     DISALLOW_COPY_AND_ASSIGN(DrmDevice);
37     DrmDevice(DrmDevice&&) = default;
38     DrmDevice& operator=(DrmDevice&&) = default;
39 
40     // Creates a new device using the first available DRM render node. Returns null if none are
41     // found.
42     static std::unique_ptr<DrmDevice> create();
43 
44     // Invokes ioctl on the device's fd with DRM's semantics, i.e. implicitly repeat ioctls that
45     // fail with EINTR or EGAIN.
46     int ioctl(unsigned long request, void* arg);
47 
48     // Returns the result of a I915_GETPARAM call, or nullopt if an error occurs.
49     std::optional<int> getParam(int param);
50 
51    private:
52     DrmDevice() = default;
53 
54     android::base::ManagedDescriptor mFd;
55 };
56 
57 }  // namespace magma
58 }  // namespace gfxstream
59