From 547508653da5c401b07a7529aa4fc7dde71524e5 Mon Sep 17 00:00:00 2001 From: Besar Wicaksono Date: Wed, 19 Feb 2025 22:18:18 +0000 Subject: [PATCH] tegra: hwpm: os: linux: update kernel vers. check This is needed when building HWPM driver locally without NVIDIA build system. - driver.c: use kernel version check to select the correct signature of class:devnode - mem_mgmt_utils.c: - use kernel version check to provide correct parameter of MODULE_IMPORT_NS macro - use kernel version check to select the correct signature of get_user_pages function - mem_mgmt_utils.h: use kernel version check to select between iosys-map or dma-buf-map Bug 5120925 Change-Id: Ib33afc4d99056d5b872f0d4362e0e6c25eb7b64a Signed-off-by: Besar Wicaksono Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/3306471 GVS: buildbot_gerritrpt Reviewed-by: Yifei Wan Reviewed-by: Vasuki Shankar --- drivers/tegra/hwpm/os/linux/driver.c | 6 ++++-- drivers/tegra/hwpm/os/linux/mem_mgmt_utils.c | 7 ++++--- drivers/tegra/hwpm/os/linux/mem_mgmt_utils.h | 10 +++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/tegra/hwpm/os/linux/driver.c b/drivers/tegra/hwpm/os/linux/driver.c index ef0d754..a20e47b 100644 --- a/drivers/tegra/hwpm/os/linux/driver.c +++ b/drivers/tegra/hwpm/os/linux/driver.c @@ -1,4 +1,4 @@ -/* SPDX-FileCopyrightText: Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +/* SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: GPL-2.0-only * * This program is free software; you can redistribute it and/or modify it @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -53,7 +54,8 @@ static const struct of_device_id tegra_soc_hwpm_of_match[] = { }; MODULE_DEVICE_TABLE(of, tegra_soc_hwpm_of_match); -#if defined(NV_CLASS_STRUCT_DEVNODE_HAS_CONST_DEV_ARG) +#if defined(NV_CLASS_STRUCT_DEVNODE_HAS_CONST_DEV_ARG) || \ + LINUX_VERSION_CODE >= KERNEL_VERSION(6, 2, 0) static char *tegra_hwpm_get_devnode(const struct device *dev, umode_t *mode) #else static char *tegra_hwpm_get_devnode(struct device *dev, umode_t *mode) diff --git a/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.c b/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.c index b475602..f772068 100644 --- a/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.c +++ b/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-only -// SPDX-FileCopyrightText: Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. #include @@ -25,7 +25,8 @@ #include -#if defined(NV_MODULE_IMPORT_NS_CALLS_STRINGIFY) +#if defined(NV_MODULE_IMPORT_NS_CALLS_STRINGIFY) || \ + LINUX_VERSION_CODE < KERNEL_VERSION(6, 13, 0) MODULE_IMPORT_NS(DMA_BUF); #else MODULE_IMPORT_NS("DMA_BUF"); @@ -460,7 +461,7 @@ int tegra_hwpm_map_update_allowlist(struct tegra_soc_hwpm *hwpm, goto fail; } -#if defined(NV_GET_USER_PAGES_HAS_ARGS_FLAGS) /* Linux v6.5 */ +#if defined(NV_GET_USER_PAGES_HAS_ARGS_FLAGS) || LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0) pinned_pages = get_user_pages(user_va & PAGE_MASK, hwpm->alist_map->num_pages, 0, hwpm->alist_map->pages); #else diff --git a/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.h b/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.h index 52751db..ff3288d 100644 --- a/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.h +++ b/drivers/tegra/hwpm/os/linux/mem_mgmt_utils.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -23,8 +23,10 @@ #include #include -#if defined(NV_LINUX_IOSYS_MAP_H_PRESENT) +#if defined(NV_LINUX_IOSYS_MAP_H_PRESENT) || \ + LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0) #include +#define HWPM_IOSYS_MAP_PRESENT 1 #else #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0) #include @@ -53,13 +55,11 @@ struct tegra_hwpm_mem_mgmt { struct dma_buf *mem_bytes_dma_buf; struct dma_buf_attachment *mem_bytes_attach; void *mem_bytes_kernel; -#if defined(NV_LINUX_IOSYS_MAP_H_PRESENT) +#if defined(HWPM_IOSYS_MAP_PRESENT) struct iosys_map mem_bytes_map; #else -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0) struct dma_buf_map mem_bytes_map; #endif -#endif }; struct tegra_hwpm_allowlist_map {