|
| 1 | +/* |
| 2 | + * Copyright (C) 2021 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#include "shared/source/device/device.h" |
| 9 | +#include "shared/source/os_interface/linux/drm_neo.h" |
| 10 | +#include "shared/source/os_interface/linux/os_interface.h" |
| 11 | +#include "shared/source/os_interface/linux/sys_calls.h" |
| 12 | + |
| 13 | +#include "opencl/source/cl_device/cl_device.h" |
| 14 | +#include "opencl/source/platform/platform.h" |
| 15 | +#include "opencl/source/sharings/va/va_device.h" |
| 16 | + |
| 17 | +#include <sys/stat.h> |
| 18 | +#include <system_error> |
| 19 | +#include <unistd.h> |
| 20 | +#include <va/va_backend.h> |
| 21 | + |
| 22 | +namespace NEO { |
| 23 | +ClDevice *VADevice::getRootDeviceFromVaDisplay(Platform *pPlatform, VADisplay vaDisplay) { |
| 24 | + VADisplayContextP pDisplayContext_test = reinterpret_cast<VADisplayContextP>(vaDisplay); |
| 25 | + UNRECOVERABLE_IF(pDisplayContext_test->vadpy_magic != 0x56414430); |
| 26 | + VADriverContextP pDriverContext_test = pDisplayContext_test->pDriverContext; |
| 27 | + int deviceFd = *(int *)pDriverContext_test->drm_state; |
| 28 | + |
| 29 | + UNRECOVERABLE_IF(deviceFd < 0); |
| 30 | + |
| 31 | + char path[256] = {0}; |
| 32 | + size_t pathlen = 256; |
| 33 | + |
| 34 | + if (SysCalls::getDevicePath(deviceFd, path, pathlen)) { |
| 35 | + return nullptr; |
| 36 | + } |
| 37 | + |
| 38 | + if (SysCalls::access(path, F_OK)) { |
| 39 | + return nullptr; |
| 40 | + } |
| 41 | + |
| 42 | + int readLinkSize = 0; |
| 43 | + char devicePath[256] = {0}; |
| 44 | + readLinkSize = SysCalls::readlink(path, devicePath, pathlen); |
| 45 | + |
| 46 | + if (readLinkSize == -1) { |
| 47 | + return nullptr; |
| 48 | + } |
| 49 | + |
| 50 | + std::string_view prefixView = "../../devices/pci0000:00/0000:"; |
| 51 | + std::string_view devicePathView(devicePath, static_cast<size_t>(readLinkSize)); |
| 52 | + devicePathView.remove_prefix(prefixView.size()); |
| 53 | + devicePathView = devicePathView.substr(0, 7); |
| 54 | + |
| 55 | + for (size_t i = 0; i < pPlatform->getNumDevices(); ++i) { |
| 56 | + auto device = pPlatform->getClDevice(i); |
| 57 | + NEO::Device *neoDevice = &device->getDevice(); |
| 58 | + |
| 59 | + auto *drm = neoDevice->getRootDeviceEnvironment().osInterface->get()->getDrm(); |
| 60 | + auto pciPath = drm->getPciPath(); |
| 61 | + if (devicePathView == pciPath) { |
| 62 | + return device; |
| 63 | + } |
| 64 | + } |
| 65 | + return nullptr; |
| 66 | +} |
| 67 | +} // namespace NEO |
0 commit comments