| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/ozone/platform/drm/host/drm_device_handle.h" | 5 #include "ui/ozone/platform/drm/host/drm_device_handle.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <xf86drm.h> | 8 #include <xf86drm.h> |
| 9 #include <xf86drmMode.h> | 9 #include <xf86drmMode.h> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/posix/eintr_wrapper.h" | 12 #include "base/posix/eintr_wrapper.h" |
| 13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 14 | 14 |
| 15 namespace ui { | 15 namespace ui { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 bool Authenticate(int fd) { | 19 bool Authenticate(int fd) { |
| 20 drm_magic_t magic; | 20 drm_magic_t magic; |
| 21 memset(&magic, 0, sizeof(magic)); | 21 memset(&magic, 0, sizeof(magic)); |
| 22 // We need to make sure the DRM device has enough privilege. Use the DRM | 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. | 23 // authentication logic to figure out if the device has enough permissions. |
| 24 return !drmGetMagic(fd, &magic) && !drmAuthMagic(fd, magic); | 24 return !drmGetMagic(fd, &magic) && !drmAuthMagic(fd, magic); |
| 25 } | 25 } |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 DrmDeviceHandle::DrmDeviceHandle() { | 29 DrmDeviceHandle::DrmDeviceHandle() : is_vgem_(false) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 DrmDeviceHandle::~DrmDeviceHandle() { | 32 DrmDeviceHandle::~DrmDeviceHandle() { |
| 33 if (file_.is_valid()) | 33 if (file_.is_valid()) |
| 34 base::ThreadRestrictions::AssertIOAllowed(); | 34 base::ThreadRestrictions::AssertIOAllowed(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool DrmDeviceHandle::Initialize(const base::FilePath& path) { | 37 bool DrmDeviceHandle::Initialize(const base::FilePath& path, bool is_vgem) { |
| 38 CHECK(path.DirName() == base::FilePath("/dev/dri")); | 38 CHECK(path.DirName() == base::FilePath("/dev/dri")); |
| 39 base::ThreadRestrictions::AssertIOAllowed(); | 39 base::ThreadRestrictions::AssertIOAllowed(); |
| 40 is_vgem_ = is_vgem; |
| 40 bool print_warning = true; | 41 bool print_warning = true; |
| 41 while (true) { | 42 while (true) { |
| 42 file_.reset(); | 43 file_.reset(); |
| 43 int fd = HANDLE_EINTR(open(path.value().c_str(), O_RDWR | O_CLOEXEC)); | 44 int fd = HANDLE_EINTR(open(path.value().c_str(), O_RDWR | O_CLOEXEC)); |
| 44 if (fd < 0) { | 45 if (fd < 0) { |
| 45 PLOG(ERROR) << "Failed to open " << path.value(); | 46 PLOG(ERROR) << "Failed to open " << path.value(); |
| 46 return false; | 47 return false; |
| 47 } | 48 } |
| 48 | 49 |
| 49 file_.reset(fd); | 50 file_.reset(fd); |
| 51 if (is_vgem_) |
| 52 break; |
| 50 | 53 |
| 51 if (Authenticate(file_.get())) | 54 if (Authenticate(file_.get())) |
| 52 break; | 55 break; |
| 53 | 56 |
| 54 LOG_IF(WARNING, print_warning) << "Failed to authenticate " << path.value(); | 57 LOG_IF(WARNING, print_warning) << "Failed to authenticate " << path.value(); |
| 55 print_warning = false; | 58 print_warning = false; |
| 56 usleep(100000); | 59 usleep(100000); |
| 57 } | 60 } |
| 58 | 61 |
| 59 VLOG(1) << "Succeeded authenticating " << path.value(); | 62 VLOG(1) << "Succeeded authenticating " << path.value(); |
| 60 return true; | 63 return true; |
| 61 } | 64 } |
| 62 | 65 |
| 63 bool DrmDeviceHandle::IsValid() const { | 66 bool DrmDeviceHandle::IsValid() const { |
| 64 return file_.is_valid(); | 67 return file_.is_valid(); |
| 65 } | 68 } |
| 66 | 69 |
| 67 base::ScopedFD DrmDeviceHandle::PassFD() { | 70 base::ScopedFD DrmDeviceHandle::PassFD() { |
| 68 return file_.Pass(); | 71 return file_.Pass(); |
| 69 } | 72 } |
| 70 | 73 |
| 71 } // namespace ui | 74 } // namespace ui |
| OLD | NEW |