File: create_eudebug_interface.cpp

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (32 lines) | stat: -rw-r--r-- 1,209 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Copyright (C) 2024 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/os_interface/linux/xe/eudebug/eudebug_interface.h"
#include "shared/source/utilities/io_functions.h"
namespace NEO {
const char *eudebugSysfsEntry[static_cast<uint32_t>(EuDebugInterfaceType::maxValue)]{};
EuDebugInterfaceCreateFunctionType eudebugInterfaceFactory[static_cast<uint32_t>(EuDebugInterfaceType::maxValue)]{};

std::unique_ptr<EuDebugInterface> EuDebugInterface::create(const std::string &sysFsPciPath) {
    char enabledEuDebug = '0';

    for (auto i = 0u; i < static_cast<uint32_t>(EuDebugInterfaceType::maxValue); i++) {
        if (eudebugSysfsEntry[i]) {
            auto path = sysFsPciPath + eudebugSysfsEntry[i];
            FILE *fileDescriptor = IoFunctions::fopenPtr(path.c_str(), "r");
            if (fileDescriptor) {
                [[maybe_unused]] auto bytesRead = IoFunctions::freadPtr(&enabledEuDebug, 1, 1, fileDescriptor);
                IoFunctions::fclosePtr(fileDescriptor);
                if (enabledEuDebug == '1') {
                    return eudebugInterfaceFactory[i]();
                }
            }
        }
    }
    return {};
}
} // namespace NEO