• 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 #ifdef PPS_V3D
29 #include "broadcom/ds/v3d_pps_driver.h"
30 #endif
31 
32 #include "pps.h"
33 #include "pps_algorithm.h"
34 
35 namespace pps
36 {
create_supported_drivers()37 std::unordered_map<std::string, std::unique_ptr<Driver>> create_supported_drivers()
38 {
39    std::unordered_map<std::string, std::unique_ptr<Driver>> map;
40 
41 #ifdef PPS_FREEDRENO
42    map.emplace("msm", std::make_unique<FreedrenoDriver>());
43 #endif // PPS_FREEDRENO
44 
45 #ifdef PPS_INTEL
46    map.emplace("i915", std::make_unique<IntelDriver>());
47    map.emplace("xe", std::make_unique<IntelDriver>());
48 #endif // PPS_INTEL
49 
50 #ifdef PPS_PANFROST
51    map.emplace("panfrost", std::make_unique<PanfrostDriver>());
52 #endif // PPS_PANFROST
53 
54 #ifdef PPS_V3D
55    map.emplace("v3d", std::make_unique<V3DDriver>());
56 #endif
57 
58    return map;
59 }
60 
get_supported_drivers()61 const std::unordered_map<std::string, std::unique_ptr<Driver>> &Driver::get_supported_drivers()
62 {
63    static auto map = create_supported_drivers();
64    return map;
65 }
66 
supported_device_names()67 const std::vector<std::string> Driver::supported_device_names()
68 {
69    std::vector<std::string> supported_device_names;
70 
71    for (auto &entry : get_supported_drivers()) {
72       supported_device_names.emplace_back(entry.first);
73    }
74 
75    return supported_device_names;
76 }
77 
get_driver(DrmDevice && drm_device)78 Driver *Driver::get_driver(DrmDevice &&drm_device)
79 {
80    auto &supported_drivers = get_supported_drivers();
81    auto it = supported_drivers.find(drm_device.name);
82    if (it == std::end(supported_drivers)) {
83       PERFETTO_FATAL("Failed to find a driver for DRM device %s", drm_device.name.c_str());
84    }
85 
86    Driver *driver = it->second.get();
87    driver->drm_device = std::move(drm_device);
88    return driver;
89 }
90 
default_driver_name()91 std::string Driver::default_driver_name()
92 {
93    auto supported_devices = Driver::supported_device_names();
94    auto devices = DrmDevice::create_all();
95    for (auto &device : devices) {
96       if (CONTAINS(supported_devices, device.name)) {
97          PPS_LOG_IMPORTANT("Driver selected: %s", device.name.c_str());
98          return device.name;
99       }
100    }
101    PPS_LOG_FATAL("Failed to find any driver");
102 }
103 
find_driver_name(const char * requested)104 std::string Driver::find_driver_name(const char *requested)
105 {
106    auto supported_devices = Driver::supported_device_names();
107    auto devices = DrmDevice::create_all();
108    for (auto &device : devices) {
109       if (device.name == requested) {
110          PPS_LOG_IMPORTANT("Driver selected: %s", device.name.c_str());
111          return device.name;
112       }
113    }
114 
115    std::ostringstream drivers_os;
116    std::copy(supported_devices.begin(),
117       supported_devices.end() - 1,
118       std::ostream_iterator<std::string>(drivers_os, ", "));
119    drivers_os << supported_devices.back();
120 
121    PPS_LOG_ERROR(
122       "Device '%s' not found (supported drivers: %s)", requested, drivers_os.str().c_str());
123 
124    return default_driver_name();
125 }
126 
127 } // namespace pps
128