Files
Mikko Perttunen f535883c6a drm/tegra: Introduce program_iommu_regs helper
The VIC and NVDEC drivers contain some duplicated code. Start chipping
away at that by introducing a helper for programming the TRANSCFG
and STREAMID registers.

Bug 3778105

Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
Change-Id: I30f9cf3fb8fb89fa5abf5f5e17ba41649a42097e
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2771766
(cherry picked from commit 27872b2f90d66d8706594f5903cff4d2b1e88be4)
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2759058
Reviewed-by: Jonathan Hunter <jonathanh@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
Tested-by: Jonathan Hunter <jonathanh@nvidia.com>
2023-04-03 09:18:59 +00:00

51 lines
1.2 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2022, NVIDIA Corporation.
*/
#include <linux/device.h>
#include <linux/iommu.h>
#include "util.h"
#define THI_STREAMID0 0x30
#define THI_STREAMID1 0x34
#define TRANSCFG_ATT(i, v) (((v) & 0x3) << (i * 4))
#define TRANSCFG_SID_HW 0
#define TRANSCFG_SID_PHY 1
#define TRANSCFG_SID_FALCON 2
void tegra_drm_program_iommu_regs(struct device *dev, void __iomem *regs, u32 transcfg_offset)
{
#ifdef CONFIG_IOMMU_API
struct iommu_fwspec *spec = dev_iommu_fwspec_get(dev);
if (spec) {
u32 value;
value = TRANSCFG_ATT(1, TRANSCFG_SID_FALCON) |
TRANSCFG_ATT(0, TRANSCFG_SID_HW);
writel(value, regs + transcfg_offset);
if (spec->num_ids > 0) {
value = spec->ids[0] & 0xffff;
/*
* STREAMID0 is used for input/output buffers.
* Initialize it to the firmware stream ID in case context isolation
* is not enabled, and the firmware stream ID is used for both firmware
* and data buffers.
*
* If context isolation is enabled, it will be
* overridden by the SETSTREAMID opcode as part of each job.
*/
writel(value, regs + THI_STREAMID0);
/* STREAMID1 is used usually for firmware loading. */
writel(value, regs + THI_STREAMID1);
}
}
#endif
}