mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
Historically, nvgpu has supported a struct gk20a_dmabuf_priv and associated it with a dmabuf instance. This was aided by Nvmap's dma_buf_set_drv_data() and dma_buf_get_drvdata() APIs. gk20a_dmabuf_priv is used to store Comptag IDs i.e. (1 per 64 kb) as well as can store the dmabuf attachments to avoid multiple attach/detach calls. dma_buf_set_drv_data() allows Nvgpu to associate an instance of struct gk20a_dmabuf_priv with the instance of the dmabuf and also provide a release callback to delete the instance when the last reference to the dmabuf is put. Nvmap accomplishes this by modifying the struct dma_buf_ops definition to include the set_drv_data and get_drv_data callbacks in the kernel code. The above approach won't work for upstream Kstable and Nvmap plans to remove these APIs for upcoming newer downstream kernels as well. In order to implement the same functionality without depending on Nvmap, Nvgpu will implement a release chaining mechanism. Dmabuf's 'ops' pointer points to a constant struct and hence a whole copy of the ops is made followed by altering the new copy's release pointer. struct gk20a_dmabuf_priv stores the new copy and the dmabuf's 'ops' is changed to point to this. This allows Nvgpu to retrieve the corresponding gk20a_dmabuf_priv instance using container_of. Nvgpu's custom release callback will invoke the original release callback of the dmabuf's producer as a last step, thus completing the full circle. In case, the driver is removed, Nvgpu restores the dmabuf's 'ops' back to the original state. In order to accomplish this, every instance of a struct nvgpu_os_linux maintains a linkedlist of the gk20a_dma_buf instances. During the driver removal, this linkedlist is traversed and the corresponding dmabuf's 'ops' pointer is put back to its original state followed by freeing of this instance. Nvgpu is a producer of dmabuf's for vidmem and needs a way to check whether the given dmabuf belongs to itself. Its no longer reliable to depend on a comparision of the 'ops' pointer. Instead dmabuf_export_info() allows a name to be set by the exporter and this can be used to compare with a memory location that belongs to Nvgpu. Similarly for sysmem dmabufs, Nvmap makes a similar change in the way it identifies whether a dmabuf belongs to itself. Removed NVGPU_DMABUF_HAS_DRVDATA and moved to a unified mechanism for both downstream as well as upstream kernel. Some of the other changes in this file include the following. 1) Deletion of dmabuf.c and moving its contents over to dmabuf_priv.c 2) Replacing gk20a_mm_pin_has_drvdata with nvgpu_mm_pin_privdata and vice-versa for unpin. Bug 2878569 Change-Id: Icf8e79b05a25ad5a85f478c3ee0fc1eb7747e22d Signed-off-by: Debarshi Dutta <ddutta@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2341001 Reviewed-by: automaticguardword <automaticguardword@nvidia.com> Reviewed-by: Puneet Saxena <puneets@nvidia.com> Reviewed-by: Konsta Holtta <kholtta@nvidia.com> Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
202 lines
4.4 KiB
C
202 lines
4.4 KiB
C
/*
|
|
* Copyright (c) 2017-2020, NVIDIA CORPORATION. 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,
|
|
* version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef NVGPU_OS_LINUX_H
|
|
#define NVGPU_OS_LINUX_H
|
|
|
|
#include <linux/cdev.h>
|
|
#include <linux/iommu.h>
|
|
#include <linux/hashtable.h>
|
|
#include <linux/notifier.h>
|
|
#include <linux/version.h>
|
|
|
|
#include <nvgpu/gk20a.h>
|
|
|
|
#include "cde.h"
|
|
#include "sched.h"
|
|
|
|
struct nvgpu_os_linux_ops {
|
|
struct {
|
|
void (*get_program_numbers)(struct gk20a *g,
|
|
u32 block_height_log2,
|
|
u32 shader_parameter,
|
|
int *hprog, int *vprog);
|
|
bool (*need_scatter_buffer)(struct gk20a *g);
|
|
int (*populate_scatter_buffer)(struct gk20a *g,
|
|
struct sg_table *sgt,
|
|
size_t surface_size,
|
|
void *scatter_buffer_ptr,
|
|
size_t scatter_buffer_size);
|
|
} cde;
|
|
|
|
struct {
|
|
int (*init_debugfs)(struct gk20a *g);
|
|
} clk;
|
|
|
|
struct {
|
|
int (*init_debugfs)(struct gk20a *g);
|
|
} therm;
|
|
|
|
struct {
|
|
int (*init_debugfs)(struct gk20a *g);
|
|
} fecs_trace;
|
|
|
|
struct {
|
|
int (*init_debugfs)(struct gk20a *g);
|
|
} volt;
|
|
|
|
struct {
|
|
int (*init_debugfs)(struct gk20a *g);
|
|
} s_param;
|
|
};
|
|
|
|
struct dgpu_thermal_alert {
|
|
struct workqueue_struct *workqueue;
|
|
struct work_struct work;
|
|
u32 therm_alert_irq;
|
|
u32 event_delay;
|
|
};
|
|
|
|
struct nvgpu_os_linux {
|
|
struct gk20a g;
|
|
struct device *dev;
|
|
struct dgpu_thermal_alert thermal_alert;
|
|
struct {
|
|
struct cdev cdev;
|
|
struct device *node;
|
|
} channel;
|
|
|
|
struct {
|
|
struct cdev cdev;
|
|
struct device *node;
|
|
/* see gk20a_ctrl_priv */
|
|
struct nvgpu_list_node privs;
|
|
/* guards modifications to the list and its contents */
|
|
struct nvgpu_mutex privs_lock;
|
|
} ctrl;
|
|
|
|
struct {
|
|
struct cdev cdev;
|
|
struct device *node;
|
|
} as_dev;
|
|
|
|
struct {
|
|
struct cdev cdev;
|
|
struct device *node;
|
|
} dbg;
|
|
|
|
struct {
|
|
struct cdev cdev;
|
|
struct device *node;
|
|
} prof;
|
|
|
|
struct {
|
|
struct cdev cdev;
|
|
struct device *node;
|
|
} tsg;
|
|
|
|
struct {
|
|
struct cdev cdev;
|
|
struct device *node;
|
|
} ctxsw;
|
|
|
|
struct {
|
|
struct cdev cdev;
|
|
struct device *node;
|
|
} sched;
|
|
|
|
dev_t cdev_region;
|
|
|
|
struct devfreq *devfreq;
|
|
|
|
struct device_dma_parameters dma_parms;
|
|
|
|
atomic_t nonstall_ops;
|
|
|
|
struct work_struct nonstall_fn_work;
|
|
struct workqueue_struct *nonstall_work_queue;
|
|
|
|
struct resource *reg_mem;
|
|
void __iomem *regs;
|
|
void __iomem *regs_saved;
|
|
u64 regs_bus_addr;
|
|
|
|
struct resource *bar1_mem;
|
|
void __iomem *bar1;
|
|
void __iomem *bar1_saved;
|
|
|
|
void __iomem *usermode_regs;
|
|
void __iomem *usermode_regs_saved;
|
|
u64 usermode_regs_bus_addr;
|
|
|
|
struct nvgpu_os_linux_ops ops;
|
|
|
|
struct notifier_block nvgpu_reboot_nb;
|
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
struct dentry *debugfs;
|
|
struct dentry *debugfs_alias;
|
|
|
|
struct dentry *debugfs_ltc_enabled;
|
|
struct dentry *debugfs_timeouts_enabled;
|
|
struct dentry *debugfs_disable_bigpage;
|
|
|
|
struct dentry *debugfs_runlist_interleave;
|
|
struct dentry *debugfs_allocators;
|
|
struct dentry *debugfs_xve;
|
|
struct dentry *debugfs_kmem;
|
|
struct dentry *debugfs_hal;
|
|
struct dentry *debugfs_ltc;
|
|
|
|
struct dentry *debugfs_dump_ctxsw_stats;
|
|
#endif
|
|
DECLARE_HASHTABLE(ecc_sysfs_stats_htable, 5);
|
|
struct dev_ext_attribute *ecc_attrs;
|
|
|
|
struct gk20a_cde_app cde_app;
|
|
|
|
struct rw_semaphore busy_lock;
|
|
|
|
struct nvgpu_mutex dmabuf_priv_list_lock;
|
|
struct nvgpu_list_node dmabuf_priv_list;
|
|
|
|
bool init_done;
|
|
|
|
/** Debugfs knob for forcing syncpt support off in runtime. */
|
|
bool disable_syncpoints;
|
|
bool enable_platform_dbg;
|
|
};
|
|
|
|
static inline struct nvgpu_os_linux *nvgpu_os_linux_from_gk20a(struct gk20a *g)
|
|
{
|
|
return container_of(g, struct nvgpu_os_linux, g);
|
|
}
|
|
|
|
static inline struct device *dev_from_gk20a(struct gk20a *g)
|
|
{
|
|
return nvgpu_os_linux_from_gk20a(g)->dev;
|
|
}
|
|
|
|
#define INTERFACE_NAME "nvhost%s-gpu"
|
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
|
|
#define totalram_size_in_mb (totalram_pages() >> (10 - (PAGE_SHIFT - 10)))
|
|
#else
|
|
#define totalram_size_in_mb (totalram_pages >> (10 - (PAGE_SHIFT - 10)))
|
|
#endif
|
|
|
|
#endif
|