• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2019-2020 Collabora, Ltd.
3  * Author: Antonio Caggiano <antonio.caggiano@collabora.com>
4  * Author: Rohan Garg <rohan.garg@collabora.com>
5  * Author: Robert Beckett <bob.beckett@collabora.com>
6  * Author: Corentin Noël <corentin.noel@collabora.com>
7  *
8  * SPDX-License-Identifier: MIT
9  */
10 
11 #include "pps_driver.h"
12 
13 #include <iterator>
14 #include <sstream>
15 
16 #ifdef PPS_FREEDRENO
17 #include "freedreno/ds/fd_pps_driver.h"
18 #endif // PPS_FREEDRENO
19 
20 #ifdef PPS_INTEL
21 #include "intel/ds/intel_pps_driver.h"
22 #endif // PPS_INTEL
23 
24 #ifdef PPS_PANFROST
25 #include "panfrost/ds/pan_pps_driver.h"
26 #endif // PPS_PANFROST
27 
28 #include "pps.h"
29 #include "pps_algorithm.h"
30 
31 namespace pps
32 {
create_supported_drivers()33 std::unordered_map<std::string, std::unique_ptr<Driver>> create_supported_drivers()
34 {
35    std::unordered_map<std::string, std::unique_ptr<Driver>> map;
36 
37 #ifdef PPS_FREEDRENO
38    map.emplace("msm", std::make_unique<FreedrenoDriver>());
39 #endif // PPS_FREEDRENO
40 
41 #ifdef PPS_INTEL
42    map.emplace("i915", std::make_unique<IntelDriver>());
43 #endif // PPS_INTEL
44 
45 #ifdef PPS_PANFROST
46    map.emplace("panfrost", std::make_unique<PanfrostDriver>());
47 #endif // PPS_PANFROST
48 
49    return map;
50 }
51 
get_supported_drivers()52 const std::unordered_map<std::string, std::unique_ptr<Driver>> &Driver::get_supported_drivers()
53 {
54    static auto map = create_supported_drivers();
55    return map;
56 }
57 
supported_device_names()58 const std::vector<std::string> Driver::supported_device_names()
59 {
60    std::vector<std::string> supported_device_names;
61 
62    for (auto &entry : get_supported_drivers()) {
63       supported_device_names.emplace_back(entry.first);
64    }
65 
66    return supported_device_names;
67 }
68 
get_driver(DrmDevice && drm_device)69 Driver *Driver::get_driver(DrmDevice &&drm_device)
70 {
71    auto &supported_drivers = get_supported_drivers();
72    auto it = supported_drivers.find(drm_device.name);
73    if (it == std::end(supported_drivers)) {
74       PERFETTO_FATAL("Failed to find a driver for DRM device %s", drm_device.name.c_str());
75    }
76 
77    Driver *driver = it->second.get();
78    driver->drm_device = std::move(drm_device);
79    return driver;
80 }
81 
default_driver_name()82 std::string Driver::default_driver_name()
83 {
84    auto supported_devices = Driver::supported_device_names();
85    auto devices = DrmDevice::create_all();
86    for (auto &device : devices) {
87       if (CONTAINS(supported_devices, device.name)) {
88          PPS_LOG_IMPORTANT("Driver selected: %s", device.name.c_str());
89          return device.name;
90       }
91    }
92    PPS_LOG_FATAL("Failed to find any driver");
93 }
94 
find_driver_name(const char * requested)95 std::string Driver::find_driver_name(const char *requested)
96 {
97    auto supported_devices = Driver::supported_device_names();
98    auto devices = DrmDevice::create_all();
99    for (auto &device : devices) {
100       if (device.name == requested) {
101          PPS_LOG_IMPORTANT("Driver selected: %s", device.name.c_str());
102          return device.name;
103       }
104    }
105 
106    std::ostringstream drivers_os;
107    std::copy(supported_devices.begin(),
108       supported_devices.end() - 1,
109       std::ostream_iterator<std::string>(drivers_os, ", "));
110    drivers_os << supported_devices.back();
111 
112    PPS_LOG_ERROR(
113       "Device '%s' not found (supported drivers: %s)", requested, drivers_os.str().c_str());
114 
115    return default_driver_name();
116 }
117 
118 } // namespace pps
119