Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: ui/ozone/platform/drm/host/drm_native_display_delegate.cc

Issue 1100973002: [2/4]Allow hotplugging of primary DRM device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-hotplug
Patch Set: unittests Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_native_display_delegate.h" 5 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <xf86drm.h>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
11 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
12 #include "base/threading/worker_pool.h" 13 #include "base/threading/worker_pool.h"
13 #include "ui/display/types/display_snapshot.h" 14 #include "ui/display/types/display_snapshot.h"
14 #include "ui/display/types/native_display_observer.h" 15 #include "ui/display/types/native_display_observer.h"
15 #include "ui/events/ozone/device/device_event.h" 16 #include "ui/events/ozone/device/device_event.h"
16 #include "ui/events/ozone/device/device_manager.h" 17 #include "ui/events/ozone/device/device_manager.h"
17 #include "ui/ozone/common/display_snapshot_proxy.h" 18 #include "ui/ozone/common/display_snapshot_proxy.h"
18 #include "ui/ozone/common/display_util.h" 19 #include "ui/ozone/common/display_util.h"
19 #include "ui/ozone/common/gpu/ozone_gpu_messages.h" 20 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
20 #include "ui/ozone/platform/drm/host/display_manager.h" 21 #include "ui/ozone/platform/drm/host/display_manager.h"
21 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h" 22 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
22 23
23 namespace ui { 24 namespace ui {
24 25
25 namespace { 26 namespace {
26 27
27 typedef base::Callback<void(const base::FilePath&, base::File)> 28 typedef base::Callback<void(const base::FilePath&, base::File)>
28 OnOpenDeviceReplyCallback; 29 OnOpenDeviceReplyCallback;
29 30
30 const char* kDisplayActionString[] = { 31 const char* kDisplayActionString[] = {
31 "ADD", 32 "ADD",
32 "REMOVE", 33 "REMOVE",
33 "CHANGE", 34 "CHANGE",
34 }; 35 };
35 36
37 bool Authenticate(int fd) {
38 drm_magic_t magic = 0;
39 // We need to make sure the DRM device has enough privilege. Use the DRM
40 // authentication logic to figure out if the device has enough permissions.
41 return !drmGetMagic(fd, &magic) && !drmAuthMagic(fd, magic);
42 }
43
36 base::File OpenDrmDevice(const base::FilePath& path) { 44 base::File OpenDrmDevice(const base::FilePath& path) {
37 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ | 45 base::File file;
38 base::File::FLAG_WRITE); 46 bool print_warning = true;
47 while (true) {
48 file = base::File(path, base::File::FLAG_OPEN | base::File::FLAG_READ |
49 base::File::FLAG_WRITE);
39 50
40 base::File::Info info; 51 base::File::Info info;
41 file.GetInfo(&info); 52 file.GetInfo(&info);
42 53
43 CHECK(!info.is_directory); 54 CHECK(!info.is_directory);
44 CHECK(path.DirName() == base::FilePath("/dev/dri")); 55 CHECK(path.DirName() == base::FilePath("/dev/dri"));
45 56
46 if (!file.IsValid()) { 57 if (!file.IsValid()) {
47 LOG(ERROR) << "Failed to open " << path.value() << ": " 58 LOG(ERROR) << "Failed to open " << path.value() << ": "
48 << base::File::ErrorToString(file.error_details()); 59 << base::File::ErrorToString(file.error_details());
60 return file.Pass();
61 }
62
63 if (Authenticate(file.GetPlatformFile()))
64 break;
65
66 LOG_IF(WARNING, print_warning) << "Failed to authenticate " << path.value();
67
68 print_warning = false;
69 usleep(100000);
49 } 70 }
50 71
72 VLOG(1) << "Succeeded authenticating " << path.value();
51 return file.Pass(); 73 return file.Pass();
52 } 74 }
53 75
54 void OpenDeviceOnWorkerThread( 76 void OpenDeviceOnWorkerThread(
55 const base::FilePath& path, 77 const base::FilePath& path,
56 const scoped_refptr<base::TaskRunner>& reply_runner, 78 const scoped_refptr<base::TaskRunner>& reply_runner,
57 const OnOpenDeviceReplyCallback& callback) { 79 const OnOpenDeviceReplyCallback& callback) {
58 base::File file = OpenDrmDevice(path); 80 base::File file = OpenDrmDevice(path);
59 reply_runner->PostTask(FROM_HERE, 81 reply_runner->PostTask(FROM_HERE,
60 base::Bind(callback, path, base::Passed(file.Pass()))); 82 base::Bind(callback, path, base::Passed(file.Pass())));
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 task_pending_ = false; 338 task_pending_ = false;
317 ProcessEvent(); 339 ProcessEvent();
318 } 340 }
319 341
320 void DrmNativeDisplayDelegate::OnChannelEstablished( 342 void DrmNativeDisplayDelegate::OnChannelEstablished(
321 int host_id, 343 int host_id,
322 scoped_refptr<base::SingleThreadTaskRunner> send_runner, 344 scoped_refptr<base::SingleThreadTaskRunner> send_runner,
323 const base::Callback<void(IPC::Message*)>& send_callback) { 345 const base::Callback<void(IPC::Message*)>& send_callback) {
324 drm_devices_.clear(); 346 drm_devices_.clear();
325 drm_devices_.insert(primary_graphics_card_path_); 347 drm_devices_.insert(primary_graphics_card_path_);
348 {
349 // First device needs to be treated specially. We need to open this
350 // synchronously since the GPU process will need it to initialize the
351 // graphics state.
352 base::ThreadRestrictions::ScopedAllowIO allow_io;
353 base::File file = OpenDrmDevice(primary_graphics_card_path_);
354 if (!file.IsValid()) {
355 LOG(FATAL) << "Failed to open primary graphics card";
356 return;
357 }
358 proxy_->Send(new OzoneGpuMsg_AddGraphicsDevice(
359 primary_graphics_card_path_, base::FileDescriptor(file.Pass())));
360 }
361
326 device_manager_->ScanDevices(this); 362 device_manager_->ScanDevices(this);
327 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_, 363 FOR_EACH_OBSERVER(NativeDisplayObserver, observers_,
328 OnConfigurationChanged()); 364 OnConfigurationChanged());
329 } 365 }
330 366
331 void DrmNativeDisplayDelegate::OnChannelDestroyed(int host_id) { 367 void DrmNativeDisplayDelegate::OnChannelDestroyed(int host_id) {
332 // If the channel got destroyed in the middle of a configuration then just 368 // If the channel got destroyed in the middle of a configuration then just
333 // respond with failure. 369 // respond with failure.
334 if (!get_displays_callback_.is_null()) { 370 if (!get_displays_callback_.is_null()) {
335 base::ThreadTaskRunnerHandle::Get()->PostTask( 371 base::ThreadTaskRunnerHandle::Get()->PostTask(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 set_hdcp_state_callback_map_.erase(it); 443 set_hdcp_state_callback_map_.erase(it);
408 } 444 }
409 } 445 }
410 446
411 void DrmNativeDisplayDelegate::RunUpdateDisplaysCallback( 447 void DrmNativeDisplayDelegate::RunUpdateDisplaysCallback(
412 const GetDisplaysCallback& callback) const { 448 const GetDisplaysCallback& callback) const {
413 callback.Run(displays_.get()); 449 callback.Run(displays_.get());
414 } 450 }
415 451
416 } // namespace ui 452 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/screen_manager_unittest.cc ('k') | ui/ozone/platform/drm/ozone_platform_drm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698