diff --git a/drivers/gpu/nvgpu/os/linux/fecs_trace_linux.c b/drivers/gpu/nvgpu/os/linux/fecs_trace_linux.c index b00271d27..8a04392ec 100644 --- a/drivers/gpu/nvgpu/os/linux/fecs_trace_linux.c +++ b/drivers/gpu/nvgpu/os/linux/fecs_trace_linux.c @@ -34,6 +34,7 @@ #include "platform_gk20a.h" #include "os_linux.h" #include "fecs_trace_linux.h" +#include "ioctl.h" /* Userland-facing FIFO (one global + eventually one per VM) */ struct gk20a_ctxsw_dev { @@ -321,7 +322,7 @@ int gk20a_ctxsw_dev_open(struct inode *inode, struct file *filp) struct nvgpu_cdev *cdev; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); - g = get_gk20a(cdev->node->parent); + g = nvgpu_get_gk20a_from_cdev(cdev); g = nvgpu_get(g); if (!g) diff --git a/drivers/gpu/nvgpu/os/linux/ioctl.c b/drivers/gpu/nvgpu/os/linux/ioctl.c index 8e440171a..a123b38b7 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl.c @@ -30,6 +30,7 @@ #include "ioctl_tsg.h" #include "ioctl_dbg.h" #include "ioctl_prof.h" +#include "ioctl.h" #include "module.h" #include "os_linux.h" #include "fecs_trace_linux.h" @@ -559,6 +560,11 @@ fail: return err; } +struct gk20a *nvgpu_get_gk20a_from_cdev(struct nvgpu_cdev *cdev) +{ + return get_gk20a(cdev->node->parent); +} + u32 nvgpu_get_gpu_instance_id_from_cdev(struct gk20a *g, struct nvgpu_cdev *cdev) { struct nvgpu_cdev_class_priv_data *priv_data; diff --git a/drivers/gpu/nvgpu/os/linux/ioctl.h b/drivers/gpu/nvgpu/os/linux/ioctl.h index f5aaec6c5..406e62bbe 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl.h +++ b/drivers/gpu/nvgpu/os/linux/ioctl.h @@ -13,12 +13,56 @@ #ifndef __NVGPU_IOCTL_H__ #define __NVGPU_IOCTL_H__ +#include + +#include +#include + struct device; -struct nvgpu_cdev; +struct class; + +struct nvgpu_cdev { + struct cdev cdev; + struct device *node; + struct class *class; + struct nvgpu_list_node list_entry; +}; + +static inline struct nvgpu_cdev * +nvgpu_cdev_from_list_entry(struct nvgpu_list_node *node) +{ + return (struct nvgpu_cdev *) + ((uintptr_t)node - offsetof(struct nvgpu_cdev, list_entry)); +}; + +struct nvgpu_cdev_class_priv_data { + char class_name[64]; + u32 local_instance_id; + u32 major_instance_id; + u32 minor_instance_id; + bool pci; +}; + +struct nvgpu_class { + struct class *class; + struct nvgpu_list_node list_entry; + + struct nvgpu_cdev_class_priv_data *priv_data; + + enum nvgpu_mig_gpu_instance_type instance_type; +}; + +static inline struct nvgpu_class * +nvgpu_class_from_list_entry(struct nvgpu_list_node *node) +{ + return (struct nvgpu_class *) + ((uintptr_t)node - offsetof(struct nvgpu_class, list_entry)); +}; int gk20a_user_init(struct device *dev); void gk20a_user_deinit(struct device *dev); +struct gk20a *nvgpu_get_gk20a_from_cdev(struct nvgpu_cdev *cdev); u32 nvgpu_get_gpu_instance_id_from_cdev(struct gk20a *g, struct nvgpu_cdev *cdev); #endif diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_as.c b/drivers/gpu/nvgpu/os/linux/ioctl_as.c index 212f2b861..88c51861c 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_as.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_as.c @@ -33,6 +33,7 @@ #include "platform_gk20a.h" #include "ioctl_as.h" #include "ioctl_channel.h" +#include "ioctl.h" #include "os_linux.h" static u32 gk20a_as_translate_as_alloc_space_flags(struct gk20a *g, u32 flags) @@ -308,7 +309,7 @@ int gk20a_as_dev_open(struct inode *inode, struct file *filp) struct nvgpu_cdev *cdev; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); - g = get_gk20a(cdev->node->parent); + g = nvgpu_get_gk20a_from_cdev(cdev); nvgpu_log_fn(g, " "); diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_channel.c b/drivers/gpu/nvgpu/os/linux/ioctl_channel.c index 92e8848fe..f4b5b6e5f 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_channel.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_channel.c @@ -539,7 +539,7 @@ int gk20a_channel_open(struct inode *inode, struct file *filp) struct nvgpu_cdev *cdev; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); - g = get_gk20a(cdev->node->parent); + g = nvgpu_get_gk20a_from_cdev(cdev); nvgpu_log_fn(g, "start"); ret = __gk20a_channel_open(g, cdev, filp, -1); diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c index d9128d18f..8b6bdb9db 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c @@ -61,6 +61,7 @@ #include "ioctl_as.h" #include "ioctl_tsg.h" #include "ioctl_channel.h" +#include "ioctl.h" #include "platform_gk20a.h" #include "os_linux.h" @@ -117,7 +118,7 @@ int gk20a_ctrl_dev_open(struct inode *inode, struct file *filp) struct nvgpu_cdev *cdev; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); - g = get_gk20a(cdev->node->parent); + g = nvgpu_get_gk20a_from_cdev(cdev); g = nvgpu_get(g); if (!g) diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c b/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c index 35b55ce68..e63c831b8 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c @@ -53,6 +53,7 @@ #include "platform_gk20a.h" #include "ioctl_dbg.h" #include "ioctl_channel.h" +#include "ioctl.h" #include "dmabuf_vidmem.h" struct dbg_session_gk20a_linux { @@ -234,7 +235,7 @@ int gk20a_prof_gpu_dev_open(struct inode *inode, struct file *filp) struct nvgpu_cdev *cdev; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); - g = get_gk20a(cdev->node->parent); + g = nvgpu_get_gk20a_from_cdev(cdev); nvgpu_log(g, gpu_dbg_fn | gpu_dbg_gpu_dbg, " "); return gk20a_dbg_gpu_do_dev_open(g, filp, true /* is profiler */); @@ -2011,7 +2012,7 @@ int gk20a_dbg_gpu_dev_open(struct inode *inode, struct file *filp) struct nvgpu_cdev *cdev; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); - g = get_gk20a(cdev->node->parent); + g = nvgpu_get_gk20a_from_cdev(cdev); nvgpu_log(g, gpu_dbg_fn | gpu_dbg_gpu_dbg, " "); return gk20a_dbg_gpu_do_dev_open(g, filp, false /* not profiler */); diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_prof.c b/drivers/gpu/nvgpu/os/linux/ioctl_prof.c index 0ceea35ae..fe284a531 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_prof.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_prof.c @@ -36,6 +36,7 @@ #include "ioctl_prof.h" #include "ioctl_dbg.h" #include "ioctl_tsg.h" +#include "ioctl.h" #define NVGPU_PROF_UMD_COPY_WINDOW_SIZE SZ_4K @@ -135,7 +136,7 @@ int nvgpu_prof_dev_fops_open(struct inode *inode, struct file *filp) struct nvgpu_cdev *cdev; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); - g = get_gk20a(cdev->node->parent); + g = nvgpu_get_gk20a_from_cdev(cdev); g = nvgpu_get(g); if (!g) { @@ -163,7 +164,7 @@ int nvgpu_prof_ctx_fops_open(struct inode *inode, struct file *filp) struct nvgpu_cdev *cdev; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); - g = get_gk20a(cdev->node->parent); + g = nvgpu_get_gk20a_from_cdev(cdev); g = nvgpu_get(g); if (!g) { diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_tsg.c b/drivers/gpu/nvgpu/os/linux/ioctl_tsg.c index a1c1d7ac9..632e23036 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_tsg.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_tsg.c @@ -37,6 +37,7 @@ #include "platform_gk20a.h" #include "ioctl_tsg.h" #include "ioctl_channel.h" +#include "ioctl.h" #include "os_linux.h" struct tsg_private { @@ -471,7 +472,7 @@ int nvgpu_ioctl_tsg_dev_open(struct inode *inode, struct file *filp) struct nvgpu_cdev *cdev; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); - g = get_gk20a(cdev->node->parent); + g = nvgpu_get_gk20a_from_cdev(cdev); nvgpu_log_fn(g, " "); diff --git a/drivers/gpu/nvgpu/os/linux/os_linux.h b/drivers/gpu/nvgpu/os/linux/os_linux.h index 3e3fd4d88..5a851d9e6 100644 --- a/drivers/gpu/nvgpu/os/linux/os_linux.h +++ b/drivers/gpu/nvgpu/os/linux/os_linux.h @@ -17,7 +17,6 @@ #ifndef NVGPU_OS_LINUX_H #define NVGPU_OS_LINUX_H -#include #include #include #include @@ -29,8 +28,6 @@ #include "cde.h" #include "sched.h" -struct class; - struct nvgpu_os_linux_ops { struct { void (*get_program_numbers)(struct gk20a *g, @@ -73,44 +70,6 @@ struct dgpu_thermal_alert { u32 event_delay; }; -struct nvgpu_cdev { - struct cdev cdev; - struct device *node; - struct class *class; - struct nvgpu_list_node list_entry; -}; - -static inline struct nvgpu_cdev * -nvgpu_cdev_from_list_entry(struct nvgpu_list_node *node) -{ - return (struct nvgpu_cdev *) - ((uintptr_t)node - offsetof(struct nvgpu_cdev, list_entry)); -}; - -struct nvgpu_cdev_class_priv_data { - char class_name[64]; - u32 local_instance_id; - u32 major_instance_id; - u32 minor_instance_id; - bool pci; -}; - -struct nvgpu_class { - struct class *class; - struct nvgpu_list_node list_entry; - - struct nvgpu_cdev_class_priv_data *priv_data; - - enum nvgpu_mig_gpu_instance_type instance_type; -}; - -static inline struct nvgpu_class * -nvgpu_class_from_list_entry(struct nvgpu_list_node *node) -{ - return (struct nvgpu_class *) - ((uintptr_t)node - offsetof(struct nvgpu_class, list_entry)); -}; - struct nvgpu_os_linux { struct gk20a g; struct device *dev; diff --git a/drivers/gpu/nvgpu/os/linux/sched.c b/drivers/gpu/nvgpu/os/linux/sched.c index 39a3a11dd..935d21af9 100644 --- a/drivers/gpu/nvgpu/os/linux/sched.c +++ b/drivers/gpu/nvgpu/os/linux/sched.c @@ -32,6 +32,7 @@ #include "sched.h" #include "os_linux.h" #include "ioctl_tsg.h" +#include "ioctl.h" ssize_t gk20a_sched_dev_read(struct file *filp, char __user *buf, size_t size, loff_t *off) @@ -394,7 +395,7 @@ int gk20a_sched_dev_open(struct inode *inode, struct file *filp) struct nvgpu_cdev *cdev; cdev = container_of(inode->i_cdev, struct nvgpu_cdev, cdev); - g = get_gk20a(cdev->node->parent); + g = nvgpu_get_gk20a_from_cdev(cdev); g = nvgpu_get(g); if (!g)