aboutsummaryrefslogtreecommitdiff
path: root/driver_library/src
diff options
context:
space:
mode:
authorMikael Olsson <mikael.olsson@arm.com>2023-06-12 15:00:55 +0200
committerMikael Olsson <mikael.olsson@arm.com>2023-08-09 15:11:11 +0200
commit308e7f1352bfdab8cc90be78a82b7ce4195301bc (patch)
treee64ebb166ff2cf63f5bb9e26ecc88314f859f8de /driver_library/src
parentf1cfe19a5fd6ccc07e6e86cbe5ab863f4b372418 (diff)
downloadethos-u-linux-driver-stack-308e7f1352bfdab8cc90be78a82b7ce4195301bc.tar.gz
Add kernel driver version check in driver library
The driver library will now check that it's compatible with the kernel driver in use by checking the kernel driver's version. The kernel driver version has also been made available to the library users and the Python wrapper has been updated accordingly. Change-Id: Ieae8c0bfc323f945038e7264eceeab90c833f76d Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
Diffstat (limited to 'driver_library/src')
-rw-r--r--driver_library/src/ethosu.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/driver_library/src/ethosu.cpp b/driver_library/src/ethosu.cpp
index e425e52..1758b07 100644
--- a/driver_library/src/ethosu.cpp
+++ b/driver_library/src/ethosu.cpp
@@ -1,5 +1,5 @@
/*
- * SPDX-FileCopyrightText: Copyright 2020-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+ * SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -25,6 +25,7 @@
#include <fstream>
#include <iomanip>
#include <iostream>
+#include <utility>
#include <fcntl.h>
#include <poll.h>
@@ -36,6 +37,9 @@
using namespace std;
namespace {
+std::string driverVersionToString(const EthosU::ethosu_uapi_kernel_driver_version &version) {
+ return std::to_string(version.major) + "." + std::to_string(version.minor) + "." + std::to_string(version.patch);
+}
enum class Severity { Error, Warning, Info, Debug };
@@ -214,9 +218,27 @@ ostream &operator<<(ostream &out, const SemanticVersion &v) {
/****************************************************************************
* Device
****************************************************************************/
-Device::Device(const char *device) {
- fd = eopen(device, O_RDWR | O_NONBLOCK);
+Device::Device(const char *device) : fd(eopen(device, O_RDWR | O_NONBLOCK)) {
+ ethosu_uapi_kernel_driver_version version = {};
+
Log(Severity::Info) << "Device(\"" << device << "\"). this=" << this << ", fd=" << fd << endl;
+
+ try {
+ eioctl(fd, ETHOSU_IOCTL_DRIVER_VERSION_GET, &version);
+
+ if (MAX_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION < version.major ||
+ MIN_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION > version.major) {
+ throw Exception(
+ std::string("Unsupported kernel driver version: ").append(driverVersionToString(version)).c_str());
+ }
+ } catch (std::exception &e) {
+ try {
+ eclose(fd);
+ } catch (...) { std::throw_with_nested(e); }
+ throw;
+ }
+
+ driverVersion = {version.major, version.minor, version.patch};
}
Device::~Device() noexcept(false) {
@@ -228,6 +250,10 @@ int Device::ioctl(unsigned long cmd, void *data) const {
return eioctl(fd, cmd, data);
}
+const SemanticVersion &Device::getDriverVersion() const {
+ return driverVersion;
+}
+
Capabilities Device::capabilities() const {
ethosu_uapi_device_capabilities uapi;
(void)eioctl(fd, ETHOSU_IOCTL_CAPABILITIES_REQ, static_cast<void *>(&uapi));
@@ -568,4 +594,7 @@ vector<shared_ptr<Buffer>> &Inference::getOfmBuffers() {
return ofmBuffers;
}
+static_assert(MAX_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION >= ETHOSU_KERNEL_DRIVER_VERSION_MAJOR &&
+ MIN_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION <= ETHOSU_KERNEL_DRIVER_VERSION_MAJOR,
+ "Unsupported major kernel driver version in UAPI");
} // namespace EthosU