Compare commits

..

7 Commits

Author SHA1 Message Date
vasukis
ebfe0e9c4b tegra: hwpm: Fix EMC Fuse Mask calculation.
A recent change has led to EMC fuse mask calculation regression.
This is being corrected in this patch. The emc_fuse_disable mask is
set in such a way that, each bit corresponds to 4 MSS Channels.
For example, emc_fuse_disable mask=1100, corresponds to MSS_Channel0
to MSS_Channel7 being present, while MSS_Channel8 to MSS_Channel15
are floorswept. However, in HWPM Driver, the logic to represent
a floorswept IP element is indicated by '1'. Correct the logic to
indicate this.

Bug 5247662

Signed-off-by: vasukis <vasukis@nvidia.com>
Change-Id: Ia3825db29715e04aa43822283b160252d00f0a81
(cherry picked from commit 89426a7e0a)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/3358321
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Reviewed-by: Yifei Wan <ywan@nvidia.com>
Reviewed-by: svcacv <svcacv@nvidia.com>
Reviewed-by: Besar Wicaksono <bwicaksono@nvidia.com>
2025-05-27 08:53:54 -07:00
Jon Hunter
d47dc62f40 tegra: hwpm: Fix build for Linux v6.11
In Linux v6.11, the 'platform_driver' structure 'remove' callback was
updated to return void instead of 'int'. Update the Tegra HWPM driver
as necessary to fix this.

Bug 4749580

Change-Id: Ide44224bb3e5d0a000a252b4a8117ca203904a54
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/3183043
(cherry picked from commit 11de2bc045)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/3185776
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>
2024-08-01 10:24:36 -07:00
Jon Hunter
1e751f52f0 tegra: hwpm: Use conftest for get_user_pages
The conftest script already has a test for checking which variant of the
get_user_pages() function is present in the kernel. So use the
definition generated by conftest to select which function variant is
used.

Bug 4276500

Change-Id: I29d216c8cead657c1daca4ce11b3dc3f74928467
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/3015357
(cherry picked from commit f9360f364f)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/3017317
Reviewed-by: Vedashree Vidwans <vvidwans@nvidia.com>
2023-11-20 05:09:26 -08:00
Jon Hunter
ee08de6166 tegra: hwpm: Remove class owner
The owner member of the class structure was removed in upstream Linux
v6.4 because it was never used. Therefore, just remove this from the
HWPM driver completely because it is not needed.

Bug 4276500

Change-Id: I50f7e59e08edbea26f7ceaa701e4abfe5cc71c71
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/3015339
(cherry picked from commit 13a7312154)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/3017316
Reviewed-by: Vedashree Vidwans <vvidwans@nvidia.com>
2023-11-20 05:09:21 -08:00
Shardar Mohammed
c7c63cd0fe hwpm: Remove module owner parameter
Remove the module owner from the struct class based
on following change in core kernel

=====
    Upstream commit "6e30a66433af"

    driver core: class: remove struct module owner out of struct class

    The module owner field for a struct class was never actually used, so
    remove it as it is not doing anything at all.

    Cc: "Rafael J. Wysocki" <rafael@kernel.org>
    Link: https://lore.kernel.org/r/20230313181843.1207845-3-gregkh@linuxfoundation.org
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
=====

Bug 4276500

Change-Id: I0b68273e38f79ee6d903172b8f4d9d1807202abe
Signed-off-by: Shardar Mohammed <smohammed@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/2978633
(cherry picked from commit f116216688)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/3015718
Tested-by: Jonathan Hunter <jonathanh@nvidia.com>
Reviewed-by: Vedashree Vidwans <vvidwans@nvidia.com>
Reviewed-by: Jonathan Hunter <jonathanh@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2023-11-17 00:24:27 -08:00
Shardar Mohammed
4f84731a0a hwpm: remove unused vmas parameter from get_user_pages()
Remove unused vmas parameter from get_user_pages() based
on following change in core kernel.

=====
    Upstream commit "54d020692b34"

    mm/gup: remove unused vmas parameter from get_user_pages()

    Patch series "remove the vmas parameter from GUP APIs", v6.

    (pin_/get)_user_pages[_remote]() each provide an optional output parameter
    for an array of VMA objects associated with each page in the input range.

    These provide the means for VMAs to be returned, as long as mm->mmap_lock
    is never released during the GUP operation (i.e.  the internal flag
    FOLL_UNLOCKABLE is not specified).

    In addition, these VMAs can only be accessed with the mmap_lock held and
    become invalidated the moment it is released.

    The vast majority of invocations do not use this functionality and of
    those that do, all but one case retrieve a single VMA to perform checks
    upon.

    It is not egregious in the single VMA cases to simply replace the
    operation with a vma_lookup().  In these cases we duplicate the (fast)
    lookup on a slow path already under the mmap_lock, abstracted to a new
    get_user_page_vma_remote() inline helper function which also performs
    error checking and reference count maintenance.

    The special case is io_uring, where io_pin_pages() specifically needs to
    assert that the VMAs underlying the range do not result in broken
    long-term GUP file-backed mappings.

    As GUP now internally asserts that FOLL_LONGTERM mappings are not
    file-backed in a broken fashion (i.e.  requiring dirty tracking) - as
    implemented in "mm/gup: disallow FOLL_LONGTERM GUP-nonfast writing to
    file-backed mappings" - this logic is no longer required and so we can
    simply remove it altogether from io_uring.

    Eliminating the vmas parameter eliminates an entire class of danging
    pointer errors that might have occured should the lock have been
    incorrectly released.

    In addition, the API is simplified and now clearly expresses what it is
    intended for - applying the specified GUP flags and (if pinning) returning
    pinned pages.

    This change additionally opens the door to further potential improvements
    in GUP and the possible marrying of disparate code paths.

    I have run this series against gup_test with no issues.

    Thanks to Matthew Wilcox for suggesting this refactoring!

    This patch (of 6):

    No invocation of get_user_pages() use the vmas parameter, so remove it.

    The GUP API is confusing and caveated.  Recent changes have done much to
    improve that, however there is more we can do.  Exporting vmas is a prime
    target as the caller has to be extremely careful to preclude their use
    after the mmap_lock has expired or otherwise be left with dangling
    pointers.

    Removing the vmas parameter focuses the GUP functions upon their primary
    purpose - pinning (and outputting) pages as well as performing the actions
    implied by the input flags.

    This is part of a patch series aiming to remove the vmas parameter
    altogether.

    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
=====

Bug 4276500

Change-Id: Ie2833b7aa4e8fef1362694de6e8a27bba553e3d4
Signed-off-by: Shardar Mohammed <smohammed@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/2978634
(cherry picked from commit 85732c9084)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/3015717
Tested-by: Jonathan Hunter <jonathanh@nvidia.com>
Reviewed-by: Vedashree Vidwans <vvidwans@nvidia.com>
Reviewed-by: Jonathan Hunter <jonathanh@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2023-11-17 00:24:21 -08:00
Jon Hunter
4b2fd8250d tegra: hwpm: Use conftest for 'struct class' changes
In Linux v6.2, the 'struct class.devnode()' function was updated to take
a 'const struct device *' instead of a 'struct device *'. A test has
been added to the conftest script to check for this and so instead of
relying on kernel version, use the definition generated by conftest to
select the appropriate function to use.

This is beneficial for working with 3rd party Linux kernels that may
have back-ported upstream changes into their kernel and so the kernel
version checks do not work.

Bug 4119327

Change-Id: I751b7401adee7b337192e255253b974cbd803642
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/2991966
Reviewed-by: Vedashree Vidwans <vvidwans@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2023-10-10 11:54:25 -07:00
3 changed files with 30 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
/*
* Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -212,6 +212,7 @@ static int t234_hwpm_validate_emc_config(struct tegra_soc_hwpm *hwpm)
u32 emc_disable_fuse_val = 0U;
u32 emc_disable_fuse_val_mask = 0xFU;
u32 emc_element_floorsweep_mask = 0U;
u32 emc_disable_fuse_bit_idx = 0U;
u32 idx = 0U;
int err;
@@ -235,11 +236,11 @@ static int t234_hwpm_validate_emc_config(struct tegra_soc_hwpm *hwpm)
* Convert floorsweep fuse value to available EMC elements.
*/
do {
if (emc_disable_fuse_val & 0x1U) {
emc_element_floorsweep_mask =
(emc_element_floorsweep_mask << 4U) | 0xFU;
if (!(emc_disable_fuse_val & (0x1U << emc_disable_fuse_bit_idx))) {
emc_element_floorsweep_mask |=
(0xFU << (emc_disable_fuse_bit_idx * 4U));
}
emc_disable_fuse_val = (emc_disable_fuse_val >> 1U);
emc_disable_fuse_bit_idx++;
emc_disable_fuse_val_mask = (emc_disable_fuse_val_mask >> 1U);
} while (emc_disable_fuse_val_mask != 0U);

View File

@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2021-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* Copyright (c) 2021-2024 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,
@@ -14,6 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <nvidia/conftest.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/module.h>
@@ -21,7 +23,6 @@
#include <linux/slab.h>
#include <linux/dma-buf.h>
#include <linux/debugfs.h>
#include <linux/version.h>
#include <tegra_hwpm.h>
#include <tegra_hwpm_ip.h>
@@ -50,10 +51,10 @@ static const struct of_device_id tegra_soc_hwpm_of_match[] = {
};
MODULE_DEVICE_TABLE(of, tegra_soc_hwpm_of_match);
#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0))
static char *tegra_hwpm_get_devnode(struct device *dev, umode_t *mode)
#else
#if defined(NV_CLASS_STRUCT_DEVNODE_HAS_CONST_DEV_ARG)
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)
#endif
{
if (!mode) {
@@ -110,7 +111,6 @@ static int tegra_hwpm_probe(struct platform_device *pdev)
hwpm_linux->pdev = pdev;
hwpm_linux->dev = &pdev->dev;
hwpm_linux->np = pdev->dev.of_node;
hwpm_linux->class.owner = THIS_MODULE;
hwpm_linux->class.name = TEGRA_SOC_HWPM_MODULE_NAME;
hwpm = &hwpm_linux->hwpm;
@@ -251,9 +251,21 @@ static int tegra_hwpm_remove(struct platform_device *pdev)
return 0;
}
#if defined(NV_PLATFORM_DRIVER_STRUCT_REMOVE_RETURNS_VOID) /* Linux v6.11 */
static inline void tegra_hwpm_remove_wrapper(struct platform_device *pdev)
{
tegra_hwpm_remove(pdev);
}
#else
static inline int tegra_hwpm_remove_wrapper(struct platform_device *pdev)
{
return tegra_hwpm_remove(pdev);
}
#endif
static struct platform_driver tegra_soc_hwpm_pdrv = {
.probe = tegra_hwpm_probe,
.remove = tegra_hwpm_remove,
.remove = tegra_hwpm_remove_wrapper,
.driver = {
.name = TEGRA_SOC_HWPM_MODULE_NAME,
.of_match_table = of_match_ptr(tegra_soc_hwpm_of_match),

View File

@@ -457,8 +457,13 @@ 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 */
pinned_pages = get_user_pages(user_va & PAGE_MASK,
hwpm->alist_map->num_pages, 0, hwpm->alist_map->pages);
#else
pinned_pages = get_user_pages(user_va & PAGE_MASK,
hwpm->alist_map->num_pages, 0, hwpm->alist_map->pages, NULL);
#endif
if (pinned_pages != hwpm->alist_map->num_pages) {
tegra_hwpm_err(hwpm, "Requested %llu pages / Got %ld pages",
hwpm->alist_map->num_pages, pinned_pages);