1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/drm/host/drm_device_handle.h"
9 #include <xf86drmMode.h>
11 #include "base/files/file_path.h"
12 #include "base/posix/eintr_wrapper.h"
13 #include "base/threading/thread_restrictions.h"
19 bool Authenticate(int fd
) {
21 memset(&magic
, 0, sizeof(magic
));
22 // We need to make sure the DRM device has enough privilege. Use the DRM
23 // authentication logic to figure out if the device has enough permissions.
24 return !drmGetMagic(fd
, &magic
) && !drmAuthMagic(fd
, magic
);
29 DrmDeviceHandle::DrmDeviceHandle() {
32 DrmDeviceHandle::~DrmDeviceHandle() {
34 base::ThreadRestrictions::AssertIOAllowed();
37 bool DrmDeviceHandle::Initialize(const base::FilePath
& path
) {
38 CHECK(path
.DirName() == base::FilePath("/dev/dri"));
39 base::ThreadRestrictions::AssertIOAllowed();
40 bool print_warning
= true;
43 int fd
= HANDLE_EINTR(open(path
.value().c_str(), O_RDWR
| O_CLOEXEC
));
45 PLOG(ERROR
) << "Failed to open " << path
.value();
51 if (Authenticate(file_
.get()))
54 LOG_IF(WARNING
, print_warning
) << "Failed to authenticate " << path
.value();
55 print_warning
= false;
59 VLOG(1) << "Succeeded authenticating " << path
.value();
63 bool DrmDeviceHandle::IsValid() const {
64 return file_
.is_valid();
67 base::ScopedFD
DrmDeviceHandle::PassFD() {