blob: 8f44d69404ed62e7f2fb286b0287dde9fe1d74bf [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
2 * Copyright (C) 2015 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
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010017#define LOG_TAG "hwc-drm-device"
Sean Paul6a55e9f2015-04-30 15:31:06 -040018
Roman Stratiienko13cc3662020-08-29 21:35:39 +030019#include "DrmDevice.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040020
Sean Paul6a55e9f2015-04-30 15:31:06 -040021#include <fcntl.h>
Sean Paul6a55e9f2015-04-30 15:31:06 -040022#include <xf86drm.h>
23#include <xf86drmMode.h>
24
Roman Kovalivskyid07c3702019-11-04 17:54:31 +020025#include <algorithm>
26#include <array>
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020027#include <cerrno>
Roman Stratiienko13cc3662020-08-29 21:35:39 +030028#include <cinttypes>
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020029#include <cstdint>
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030030#include <sstream>
Roman Kovalivskyid07c3702019-11-04 17:54:31 +020031#include <string>
32
Roman Stratiienko24a7fc42021-12-23 16:25:20 +020033#include "drm/DrmPlane.h"
Roman Stratiienkod518a052021-02-25 19:15:14 +020034#include "utils/log.h"
35#include "utils/properties.h"
36
Sean Paul6a55e9f2015-04-30 15:31:06 -040037namespace android {
38
Roman Stratiienko1e053b42021-10-25 22:54:20 +030039DrmDevice::DrmDevice() {
Roman Stratiienko8666dc92021-02-09 17:49:55 +020040 self.reset(this);
41 mDrmFbImporter = std::make_unique<DrmFbImporter>(self);
Sean Paul047b9b22015-07-28 14:15:42 -040042}
43
Roman Stratiienko5f2f3ce2021-12-22 11:46:03 +020044// NOLINTNEXTLINE (readability-function-cognitive-complexity): Fixme
Alexandru Gheorghec5463582018-03-27 15:52:02 +010045std::tuple<int, int> DrmDevice::Init(const char *path, int num_displays) {
Sean Paul6a55e9f2015-04-30 15:31:06 -040046 /* TODO: Use drmOpenControl here instead */
Roman Stratiienko0fade372021-02-20 13:59:55 +020047 fd_ = UniqueFd(open(path, O_RDWR | O_CLOEXEC));
Zach Reiznerff30b522015-10-28 19:08:45 -070048 if (fd() < 0) {
Roman Stratiienko5f2f3ce2021-12-22 11:46:03 +020049 // NOLINTNEXTLINE(concurrency-mt-unsafe): Fixme
Peter Collingbournec77052e2020-02-19 11:25:08 -080050 ALOGE("Failed to open dri %s: %s", path, strerror(errno));
Alexandru Gheorghec5463582018-03-27 15:52:02 +010051 return std::make_tuple(-ENODEV, 0);
Sean Paul6a55e9f2015-04-30 15:31:06 -040052 }
53
Zach Reiznerff30b522015-10-28 19:08:45 -070054 int ret = drmSetClientCap(fd(), DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
Sean Paul6a55e9f2015-04-30 15:31:06 -040055 if (ret) {
56 ALOGE("Failed to set universal plane cap %d", ret);
Alexandru Gheorghec5463582018-03-27 15:52:02 +010057 return std::make_tuple(ret, 0);
Sean Paul6a55e9f2015-04-30 15:31:06 -040058 }
59
Zach Reiznerff30b522015-10-28 19:08:45 -070060 ret = drmSetClientCap(fd(), DRM_CLIENT_CAP_ATOMIC, 1);
Sean Paul6a55e9f2015-04-30 15:31:06 -040061 if (ret) {
62 ALOGE("Failed to set atomic cap %d", ret);
Alexandru Gheorghec5463582018-03-27 15:52:02 +010063 return std::make_tuple(ret, 0);
Sean Paul6a55e9f2015-04-30 15:31:06 -040064 }
65
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +000066#ifdef DRM_CLIENT_CAP_WRITEBACK_CONNECTORS
67 ret = drmSetClientCap(fd(), DRM_CLIENT_CAP_WRITEBACK_CONNECTORS, 1);
68 if (ret) {
69 ALOGI("Failed to set writeback cap %d", ret);
70 ret = 0;
71 }
72#endif
73
Roman Stratiienko8666dc92021-02-09 17:49:55 +020074 uint64_t cap_value = 0;
75 if (drmGetCap(fd(), DRM_CAP_ADDFB2_MODIFIERS, &cap_value)) {
76 ALOGW("drmGetCap failed. Fallback to no modifier support.");
77 cap_value = 0;
78 }
79 HasAddFb2ModifiersSupport_ = cap_value != 0;
80
John Stultzfa002332021-02-02 01:34:45 +000081 drmSetMaster(fd());
82 if (!drmIsMaster(fd())) {
83 ALOGE("DRM/KMS master access required");
84 return std::make_tuple(-EACCES, 0);
Roman Stratiienko3b24cd92021-01-13 10:32:04 +020085 }
86
Roman Stratiienko3e8ce572021-09-29 12:46:28 +030087 auto res = MakeDrmModeResUnique(fd());
Sean Paul6a55e9f2015-04-30 15:31:06 -040088 if (!res) {
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010089 ALOGE("Failed to get DrmDevice resources");
Alexandru Gheorghec5463582018-03-27 15:52:02 +010090 return std::make_tuple(-ENODEV, 0);
Sean Paul6a55e9f2015-04-30 15:31:06 -040091 }
92
Sean Paulf72cccd2018-08-27 13:59:08 -040093 min_resolution_ = std::pair<uint32_t, uint32_t>(res->min_width,
94 res->min_height);
95 max_resolution_ = std::pair<uint32_t, uint32_t>(res->max_width,
96 res->max_height);
Sean Paul406dbfc2016-02-10 15:35:17 -080097
Roman Stratiienko10be8752022-01-30 20:28:46 +020098 for (int i = 0; i < res->count_crtcs; ++i) {
99 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
100 auto crtc = DrmCrtc::CreateInstance(*this, res->crtcs[i], i);
101 if (crtc) {
102 crtcs_.emplace_back(std::move(crtc));
Sean Paul6a55e9f2015-04-30 15:31:06 -0400103 }
Sean Paul6a55e9f2015-04-30 15:31:06 -0400104 }
105
Roman Stratiienkod26619b2021-08-04 19:55:37 +0300106 std::vector<uint32_t> possible_clones;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400107 for (int i = 0; !ret && i < res->count_encoders; ++i) {
Roman Stratiienko3e8ce572021-09-29 12:46:28 +0300108 auto e = MakeDrmModeEncoderUnique(fd(), res->encoders[i]);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400109 if (!e) {
110 ALOGE("Failed to get encoder %d", res->encoders[i]);
111 ret = -ENODEV;
112 break;
113 }
114
115 std::vector<DrmCrtc *> possible_crtcs;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200116 DrmCrtc *current_crtc = nullptr;
Zach Reiznerff30b522015-10-28 19:08:45 -0700117 for (auto &crtc : crtcs_) {
Roman Stratiienko10be8752022-01-30 20:28:46 +0200118 if ((1 << crtc->GetIndexInResArray()) & e->possible_crtcs)
Zach Reiznerff30b522015-10-28 19:08:45 -0700119 possible_crtcs.push_back(crtc.get());
Sean Paul6a55e9f2015-04-30 15:31:06 -0400120
Roman Stratiienko10be8752022-01-30 20:28:46 +0200121 if (crtc->GetId() == e->crtc_id)
Zach Reiznerff30b522015-10-28 19:08:45 -0700122 current_crtc = crtc.get();
Sean Paul6a55e9f2015-04-30 15:31:06 -0400123 }
124
Zach Reiznerff30b522015-10-28 19:08:45 -0700125 std::unique_ptr<DrmEncoder> enc(
Roman Stratiienko3e8ce572021-09-29 12:46:28 +0300126 new DrmEncoder(e.get(), current_crtc, possible_crtcs));
Alexandru Gheorghee8b668c2018-03-22 11:31:29 +0000127 possible_clones.push_back(e->possible_clones);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400128
Zach Reiznerff30b522015-10-28 19:08:45 -0700129 encoders_.emplace_back(std::move(enc));
Sean Paul6a55e9f2015-04-30 15:31:06 -0400130 }
131
Alexandru Gheorghee8b668c2018-03-22 11:31:29 +0000132 for (unsigned int i = 0; i < encoders_.size(); i++) {
133 for (unsigned int j = 0; j < encoders_.size(); j++)
134 if (possible_clones[i] & (1 << j))
135 encoders_[i]->AddPossibleClone(encoders_[j].get());
136 }
137
Sean Paul6a55e9f2015-04-30 15:31:06 -0400138 for (int i = 0; !ret && i < res->count_connectors; ++i) {
Roman Stratiienko3e8ce572021-09-29 12:46:28 +0300139 auto c = MakeDrmModeConnectorUnique(fd(), res->connectors[i]);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400140 if (!c) {
141 ALOGE("Failed to get connector %d", res->connectors[i]);
142 ret = -ENODEV;
143 break;
144 }
145
146 std::vector<DrmEncoder *> possible_encoders;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200147 DrmEncoder *current_encoder = nullptr;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400148 for (int j = 0; j < c->count_encoders; ++j) {
Zach Reiznerff30b522015-10-28 19:08:45 -0700149 for (auto &encoder : encoders_) {
150 if (encoder->id() == c->encoders[j])
151 possible_encoders.push_back(encoder.get());
152 if (encoder->id() == c->encoder_id)
153 current_encoder = encoder.get();
Sean Paul6a55e9f2015-04-30 15:31:06 -0400154 }
155 }
156
Zach Reiznerff30b522015-10-28 19:08:45 -0700157 std::unique_ptr<DrmConnector> conn(
Roman Stratiienko3e8ce572021-09-29 12:46:28 +0300158 new DrmConnector(this, c.get(), current_encoder, possible_encoders));
Sean Paul6a55e9f2015-04-30 15:31:06 -0400159
Sean Paul6a55e9f2015-04-30 15:31:06 -0400160 ret = conn->Init();
161 if (ret) {
162 ALOGE("Init connector %d failed", res->connectors[i]);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400163 break;
164 }
Sean Paul6a55e9f2015-04-30 15:31:06 -0400165
Alexandru Gheorgheb46b9302018-03-21 14:19:58 +0000166 if (conn->writeback())
167 writeback_connectors_.emplace_back(std::move(conn));
168 else
169 connectors_.emplace_back(std::move(conn));
Robert Foss610d9892017-11-01 12:50:04 -0500170 }
171
Roman Stratiienkoedb97ed2022-01-29 19:53:14 +0200172 auto add_displays = [this, &num_displays](bool internal, bool connected) {
173 for (auto &conn : connectors_) {
174 bool is_connected = conn->state() == DRM_MODE_CONNECTED;
175 if ((internal ? conn->internal() : conn->external()) &&
176 (connected ? is_connected : !is_connected)) {
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100177 conn->set_display(num_displays);
178 displays_[num_displays] = num_displays;
179 ++num_displays;
180 }
Robert Foss610d9892017-11-01 12:50:04 -0500181 }
Roman Stratiienkoedb97ed2022-01-29 19:53:14 +0200182 };
183
184 /* Put internal first to ensure Primary display will be internal
185 * in case at least 1 internal is available
186 */
187 add_displays(/*internal = */ true, /*connected = */ true);
188 add_displays(/*internal = */ false, /*connected = */ true);
189 add_displays(/*internal = */ true, /*connected = */ false);
190 add_displays(/*internal = */ false, /*connected = */ false);
Robert Foss610d9892017-11-01 12:50:04 -0500191
Sean Paul6a55e9f2015-04-30 15:31:06 -0400192 // Catch-all for the above loops
193 if (ret)
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100194 return std::make_tuple(ret, 0);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400195
Roman Stratiienko3e8ce572021-09-29 12:46:28 +0300196 auto plane_res = MakeDrmModePlaneResUnique(fd());
Sean Paul6a55e9f2015-04-30 15:31:06 -0400197 if (!plane_res) {
198 ALOGE("Failed to get plane resources");
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100199 return std::make_tuple(-ENOENT, 0);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400200 }
201
202 for (uint32_t i = 0; i < plane_res->count_planes; ++i) {
Roman Stratiienkob671fab2022-01-29 00:50:22 +0200203 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
204 auto plane = DrmPlane::CreateInstance(*this, plane_res->planes[i]);
205
206 if (plane) {
207 planes_.emplace_back(std::move(plane));
Sean Paul6a55e9f2015-04-30 15:31:06 -0400208 }
Sean Paul6a55e9f2015-04-30 15:31:06 -0400209 }
Sean Paul6a55e9f2015-04-30 15:31:06 -0400210
Zach Reiznerff30b522015-10-28 19:08:45 -0700211 for (auto &conn : connectors_) {
212 ret = CreateDisplayPipe(conn.get());
Sean Paul57355412015-09-19 09:14:34 -0400213 if (ret) {
Zach Reiznerff30b522015-10-28 19:08:45 -0700214 ALOGE("Failed CreateDisplayPipe %d with %d", conn->id(), ret);
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100215 return std::make_tuple(ret, 0);
Sean Paul57355412015-09-19 09:14:34 -0400216 }
217 }
Alexandru Gheorghec5463582018-03-27 15:52:02 +0100218 return std::make_tuple(ret, displays_.size());
219}
220
221bool DrmDevice::HandlesDisplay(int display) const {
222 return displays_.find(display) != displays_.end();
Sean Paul6a55e9f2015-04-30 15:31:06 -0400223}
224
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100225DrmConnector *DrmDevice::GetConnectorForDisplay(int display) const {
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200226 for (const auto &conn : connectors_) {
Zach Reiznerff30b522015-10-28 19:08:45 -0700227 if (conn->display() == display)
228 return conn.get();
Sean Paul6a55e9f2015-04-30 15:31:06 -0400229 }
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200230 return nullptr;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400231}
232
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100233DrmCrtc *DrmDevice::GetCrtcForDisplay(int display) const {
Roman Stratiienko10be8752022-01-30 20:28:46 +0200234 return bound_crtcs_.at(display);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400235}
236
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100237const std::vector<std::unique_ptr<DrmCrtc>> &DrmDevice::crtcs() const {
Robert Foss0690c1c2016-10-20 11:07:57 -0400238 return crtcs_;
239}
240
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100241uint32_t DrmDevice::next_mode_id() {
Sean Paul6a55e9f2015-04-30 15:31:06 -0400242 return ++mode_id_;
243}
244
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100245int DrmDevice::TryEncoderForDisplay(int display, DrmEncoder *enc) {
Sean Paul6a55e9f2015-04-30 15:31:06 -0400246 /* First try to use the currently-bound crtc */
247 DrmCrtc *crtc = enc->crtc();
Roman Stratiienko10be8752022-01-30 20:28:46 +0200248 if (crtc && bound_crtcs_.count(display) == 0) {
249 bound_crtcs_[display] = crtc;
250 enc->set_crtc(crtc, display);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400251 return 0;
252 }
253
254 /* Try to find a possible crtc which will work */
Zach Reiznerff30b522015-10-28 19:08:45 -0700255 for (DrmCrtc *crtc : enc->possible_crtcs()) {
Sean Paul6a55e9f2015-04-30 15:31:06 -0400256 /* We've already tried this earlier */
Zach Reiznerff30b522015-10-28 19:08:45 -0700257 if (crtc == enc->crtc())
Sean Paul6a55e9f2015-04-30 15:31:06 -0400258 continue;
259
Roman Stratiienko10be8752022-01-30 20:28:46 +0200260 if (bound_crtcs_.count(display) == 0) {
261 bound_crtcs_[display] = crtc;
262 enc->set_crtc(crtc, display);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400263 return 0;
264 }
265 }
266
267 /* We can't use the encoder, but nothing went wrong, try another one */
268 return -EAGAIN;
269}
270
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100271int DrmDevice::CreateDisplayPipe(DrmConnector *connector) {
Sean Paul877be972015-06-03 14:08:27 -0400272 int display = connector->display();
273 /* Try to use current setup first */
274 if (connector->encoder()) {
275 int ret = TryEncoderForDisplay(display, connector->encoder());
276 if (!ret) {
277 return 0;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200278 }
279
280 if (ret != -EAGAIN) {
Sean Paul877be972015-06-03 14:08:27 -0400281 ALOGE("Could not set mode %d/%d", display, ret);
282 return ret;
283 }
284 }
Sean Paul6a55e9f2015-04-30 15:31:06 -0400285
Zach Reiznerff30b522015-10-28 19:08:45 -0700286 for (DrmEncoder *enc : connector->possible_encoders()) {
287 int ret = TryEncoderForDisplay(display, enc);
Sean Paul877be972015-06-03 14:08:27 -0400288 if (!ret) {
Zach Reiznerff30b522015-10-28 19:08:45 -0700289 connector->set_encoder(enc);
Sean Paul877be972015-06-03 14:08:27 -0400290 return 0;
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200291 }
292
293 if (ret != -EAGAIN) {
Sean Paul877be972015-06-03 14:08:27 -0400294 ALOGE("Could not set mode %d/%d", display, ret);
295 return ret;
296 }
297 }
298 ALOGE("Could not find a suitable encoder/crtc for display %d",
299 connector->display());
300 return -ENODEV;
301}
302
Roman Stratiienko6ede4662021-09-30 10:18:28 +0300303auto DrmDevice::RegisterUserPropertyBlob(void *data, size_t length) const
304 -> DrmModeUserPropertyBlobUnique {
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +0200305 struct drm_mode_create_blob create_blob {};
Sean Paul877be972015-06-03 14:08:27 -0400306 create_blob.length = length;
307 create_blob.data = (__u64)data;
308
Zach Reiznerff30b522015-10-28 19:08:45 -0700309 int ret = drmIoctl(fd(), DRM_IOCTL_MODE_CREATEPROPBLOB, &create_blob);
Sean Paul877be972015-06-03 14:08:27 -0400310 if (ret) {
311 ALOGE("Failed to create mode property blob %d", ret);
Roman Stratiienko780f7da2022-01-10 16:04:15 +0200312 return {};
Sean Paul877be972015-06-03 14:08:27 -0400313 }
Sean Paul877be972015-06-03 14:08:27 -0400314
Roman Stratiienko6ede4662021-09-30 10:18:28 +0300315 return DrmModeUserPropertyBlobUnique(
316 new uint32_t(create_blob.blob_id), [this](const uint32_t *it) {
317 struct drm_mode_destroy_blob destroy_blob {};
318 destroy_blob.blob_id = (__u32)*it;
319 int err = drmIoctl(fd(), DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy_blob);
320 if (err != 0) {
321 ALOGE("Failed to destroy mode property blob %" PRIu32 "/%d", *it,
322 err);
323 }
324 // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
325 delete it;
326 });
Sean Paul877be972015-06-03 14:08:27 -0400327}
328
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100329int DrmDevice::GetProperty(uint32_t obj_id, uint32_t obj_type,
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200330 const char *prop_name, DrmProperty *property) const {
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +0200331 drmModeObjectPropertiesPtr props = nullptr;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400332
Zach Reiznerff30b522015-10-28 19:08:45 -0700333 props = drmModeObjectGetProperties(fd(), obj_id, obj_type);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400334 if (!props) {
335 ALOGE("Failed to get properties for %d/%x", obj_id, obj_type);
336 return -ENODEV;
337 }
338
339 bool found = false;
340 for (int i = 0; !found && (size_t)i < props->count_props; ++i) {
Zach Reiznerff30b522015-10-28 19:08:45 -0700341 drmModePropertyPtr p = drmModeGetProperty(fd(), props->props[i]);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400342 if (!strcmp(p->name, prop_name)) {
Roman Stratiienko7fd8f882021-09-29 12:46:54 +0300343 property->Init(obj_id, p, props->prop_values[i]);
Sean Paul6a55e9f2015-04-30 15:31:06 -0400344 found = true;
345 }
346 drmModeFreeProperty(p);
347 }
348
349 drmModeFreeObjectProperties(props);
350 return found ? 0 : -ENOENT;
351}
352
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100353int DrmDevice::GetConnectorProperty(const DrmConnector &connector,
354 const char *prop_name,
Roman Stratiienko0b063882021-09-30 10:15:05 +0300355 DrmProperty *property) const {
Sean Paul6a55e9f2015-04-30 15:31:06 -0400356 return GetProperty(connector.id(), DRM_MODE_OBJECT_CONNECTOR, prop_name,
357 property);
358}
Matvii Zorinef3c7972020-08-11 15:15:44 +0300359
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200360std::string DrmDevice::GetName() const {
Roman Stratiienko0fade372021-02-20 13:59:55 +0200361 auto *ver = drmGetVersion(fd());
Matvii Zorinef3c7972020-08-11 15:15:44 +0300362 if (!ver) {
Roman Stratiienko0fade372021-02-20 13:59:55 +0200363 ALOGW("Failed to get drm version for fd=%d", fd());
Matvii Zorinef3c7972020-08-11 15:15:44 +0300364 return "generic";
365 }
366
367 std::string name(ver->name);
368 drmFreeVersion(ver);
369 return name;
370}
Roman Stratiienko56f4adc2021-09-29 12:47:12 +0300371
372auto DrmDevice::IsKMSDev(const char *path) -> bool {
373 auto fd = UniqueFd(open(path, O_RDWR | O_CLOEXEC));
374 if (!fd) {
375 return false;
376 }
377
378 auto res = MakeDrmModeResUnique(fd.Get());
379 if (!res) {
380 return false;
381 }
382
383 bool is_kms = res->count_crtcs > 0 && res->count_connectors > 0 &&
384 res->count_encoders > 0;
385
386 return is_kms;
387}
388
Sean Paulf72cccd2018-08-27 13:59:08 -0400389} // namespace android