Debian Codegraph @

opencl/source/sharings/va/va_device_shared.cpp

raw
1 /*
2 * Copyright (C) 2021-2022 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/source/device/device.h"
9 #include "shared/source/execution_environment/root_device_environment.h"
10 #include "shared/source/os_interface/linux/drm_neo.h"
11 #include "shared/source/os_interface/linux/pci_path.h"
12 #include "shared/source/os_interface/os_interface.h"
13
14 #include "opencl/source/cl_device/cl_device.h"
15 #include "opencl/source/platform/platform.h"
16 #include "opencl/source/sharings/va/va_device.h"
17
18 #include <sys/stat.h>
19 #include <system_error>
20 #include <unistd.h>
21 #include <va/va_backend.h>
22
23 namespace NEO {
24 ClDevice *VADevice::getRootDeviceFromVaDisplay(Platform *pPlatform, VADisplay vaDisplay) {
25 VADisplayContextP pDisplayContextTest = reinterpret_cast<VADisplayContextP>(vaDisplay);
26 UNRECOVERABLE_IF(pDisplayContextTest->vadpy_magic != 0x56414430);
27 VADriverContextP pDriverContextTest = pDisplayContextTest->pDriverContext;
28 int deviceFd = *static_cast<int *>(pDriverContextTest->drm_state);
29
30 UNRECOVERABLE_IF(deviceFd < 0);
31
32 auto devicePath = NEO::getPciPath(deviceFd);
33
34 if (devicePath == std::nullopt) {
35 return nullptr;
36 }
37
38 for (size_t i = 0; i < pPlatform->getNumDevices(); ++i) {
39 auto device = pPlatform->getClDevice(i);
40 NEO::Device *neoDevice = &device->getDevice();
41
42 auto *drm = neoDevice->getRootDeviceEnvironment().osInterface->getDriverModel()->as<Drm>();
43 auto pciPath = drm->getPciPath();
44 if (devicePath == pciPath) {
45 return device;
46 }
47 }
48 return nullptr;
49 }
50 } // namespace NEO