Commit Graph

9 Commits

Author SHA1 Message Date
Jon Hunter
f9360f364f 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
Reviewed-by: Vedashree Vidwans <vvidwans@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2023-11-15 15:35:05 -08:00
Vedashree Vidwans
da3bda1364 tegra: hwpm: improve common function readability
- HALs get_rtr_int_idx and get_ip_max_idx return the chip specific
router index and number of IPs. This information is static for a chip
and doesn't require any input. Hence, update the HAL definition to not
require hwpm pointer as an argument. Update definition and references
for these HALs.
- Add new HAL to get PMA and RTR structure pointers. Implement and
update other chip specific functions to use new HAL.
- Add new timer macro to check a condition and timeout after given
retries. Update necessary code to use new timer macro.
- Correct validate_emc_config function to compute correct available mss
channel mask based on fuse value.
- Update tegra_hwpm_readl and tegra_hwpm_writel macros to assert error
value. This way error checks are added at one spot and not sprinkled all
over the driver code.
- Update get_mem_bytes_put_ptr() and membuf_overflow_status() to return
error as function return and accept arguments to return mem_head pointer
and overflow status respectively. Add overflow status macros to use
throughout driver. Update HAL definition and references accordingly.
- conftest is only compiled for OOT config atm. Add OOT config check to
include conftest header.

Jira THWPM-109

Change-Id: I77d150e860fa344a1604d241e27718150fdb8647
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/2982555
Reviewed-by: Adeel Raza <araza@nvidia.com>
Reviewed-by: Vishal Aslot <vaslot@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2023-10-05 04:30:46 -07:00
Shardar Mohammed
85732c9084 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
Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2023-09-12 15:01:06 -07:00
Jon Hunter
afce55ed44 tegra: hwpm: Fix build for Linux v5.14
Building HWPM with Linux v5.14 currently fails because the arguments
passed to the dma_buf_vmap and dma_buf_vunmap functions is incorrect.
The arguments passed to the dma_buf_vmap and dma_buf_vunmap functions
were actually updated in Linux kernel version v5.11 and not v5.15. So
correct the kernel version in the HWPM driver so that the correct
version of the APIs are used for Linux kernels v5.11+.

Finally, drop the kernel version check around the inclusion of module.h
and the import of the module namespace because this is not necessary.

Bug 3918909

Change-Id: I98eef5c69af058abfd5ac925614954404371175c
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2860794
(cherry picked from commit 72f00b64c3871e69e7242516849a76bde106ae17)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/2888555
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
2023-05-04 11:41:29 -07:00
Vedashree Vidwans
4ecc672c3e tegra: hwpm: clean up code and add bug fixes
- Create tegra_hwpm_element_enable() instead of directly using
perfmon_enable() HAL. This will allow us to expand
tegra_hwpm_element_enable in future.
- Update log messages in ip structure init code and floorsweep info
function.
- It is possible that IP instances and elements to have 0 start range
address. So, modify check for available elements to use range end
instead.
- Use tegra_hwpm_fake_readl() and tegra_hwpm_fake_writel() macros
instead of fake_readl() and fake_write() functions. That way we have
similar implementation of IO functions and macros can be used across
OSes.
- Check that reserve perfmon function is invoked only for HWPM
components. This check will be useful for expansion in types of
components in the future.
- Clean up and rearrange tegra_hwpm_regops_readl_impl() and
tegra_hwpm_regops_writel_impl() to have designated code corresponding to
the element type.
- Currently, device open and release functions are incorrectly using
clock enable/disable functions instead of using HALs. Correct open and
close functions to use lock HALs.
- Currently, tegra_hwpm_update_mem_bytes() doesn't validate mem_mgmt
structure allocation before accessing mem_bytes_kernel pointer. This can
lead to kernel crash. Update tegra_hwpm_update_mem_bytes() to return
error if mem_mgmt structure s not allocated.

Jira THWPM-74

Change-Id: Ia40bd51187e5ea08572dbee81e577dacf5fb66b6
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
(cherry picked from commit 411f07484d68dfde0d350a5c67f2748e876b11b8)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/2888553
Reviewed-by: Adeel Raza <araza@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2023-05-04 03:12:54 -07:00
Vedashree Vidwans
8b861518c4 tegra: hwpm: update licenses for all files
Modify OS agnostic files in common, hal and include folder to use MIT
license. This will allow the files to be shared between different OSes.
Modify OS specific files in os/linux and uapi folders to add SPDX
identifier for GPLv2.

Jira THWPM-69

Change-Id: I4fef142354a46fc23b67616204ccf0712a99caec
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/2797453
Reviewed-by: Seema Khowala <seemaj@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2023-02-08 03:16:24 -08:00
Vedashree Vidwans
dd4f96e5c9 tegra: hwpm: fix kernel crash on TOT
Currently on TOT, stream buffer map functions results in kernel crash.
The kernel crash is an effect of incorrect conditions in the mapping
function. Fix the code logic to use correct kernel version conditions to
use appropriate DMA buffer structures.

Bug 3893741

Change-Id: I3888ec01fdb2025f6d9c3a22296ca9d1abbcadb0
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
(cherry picked from commit 5a3476cfb6574eb5ace29801a4f428ce9d694ce9)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/2853211
Reviewed-by: Seema Khowala <seemaj@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2023-02-08 03:16:11 -08:00
Vedashree Vidwans
f010cf5956 tegra: hwpm: update dma vmap for kernel > 5.10
Kernel version beyond 5.10 introduces dma_buf_map structure (called
iosys_map in later versions). Kernel virtual address corresponding to a
dma_buf is stored in the dma_buf_map structure.
- This patch updates memory management function to use correct mem bytes
buffer kernel virtual address stored in the corresponding dma_buf_map
structure.
- Use dma_buf_map structure pointer to unmap kernel virtual address.
- During release, poll mem bytes buffer with finite timeout value.
- Add description for use of dma_set_mask_and_coherent.

Bug 3893741

Change-Id: I42ace2fe70b36d7d5d1a4c5fee21786826f24a07
Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
(cherry picked from commit ce852be6b39ef39affccdee41ad436fc70bf86b5)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-hwpm/+/2847007
Reviewed-by: Seema Khowala <seemaj@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
2023-02-08 03:15:58 -08:00
Vedashree Vidwans
7c1ae11f78 tegra: hwpm: move files to appropriate path
HWPM files are copied from the previous source in linux-nvidia repo
withgit history. Create folders and move files to obtain expected folder
structure.

Bug 3787076

Signed-off-by: Vedashree Vidwans <vvidwans@nvidia.com>
2022-10-05 16:05:20 -07:00