From 92c43deefca150854193c6720717d56b61989c23 Mon Sep 17 00:00:00 2001 From: Terje Bergstrom Date: Tue, 20 Jun 2017 12:18:47 -0700 Subject: gpu: nvgpu: Remove Linux devnode fields from gk20a Move Linux devnode related fields to a new header file os_linux.h. The class structure is defined in module.c, so move its declaration to module.h. JIRA NVGPU-38 Change-Id: I5d8920169064f4289ff61004f7f81543a9aba221 Signed-off-by: Terje Bergstrom Reviewed-on: http://git-master/r/1505927 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/ioctl.c | 74 +++++++++++++------------ drivers/gpu/nvgpu/common/linux/ioctl_as.c | 5 +- drivers/gpu/nvgpu/common/linux/ioctl_channel.c | 9 ++- drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c | 14 +++-- drivers/gpu/nvgpu/common/linux/ioctl_tsg.c | 9 +-- drivers/gpu/nvgpu/common/linux/module.c | 7 ++- drivers/gpu/nvgpu/common/linux/module.h | 2 + drivers/gpu/nvgpu/common/linux/os_linux.h | 76 ++++++++++++++++++++++++++ drivers/gpu/nvgpu/common/linux/pci.c | 11 +++- 9 files changed, 154 insertions(+), 53 deletions(-) create mode 100644 drivers/gpu/nvgpu/common/linux/os_linux.h (limited to 'drivers/gpu/nvgpu/common') diff --git a/drivers/gpu/nvgpu/common/linux/ioctl.c b/drivers/gpu/nvgpu/common/linux/ioctl.c index 5a2753a5..8262c326 100644 --- a/drivers/gpu/nvgpu/common/linux/ioctl.c +++ b/drivers/gpu/nvgpu/common/linux/ioctl.c @@ -28,6 +28,8 @@ #include "ioctl_ctrl.h" #include "ioctl_as.h" #include "ioctl_tsg.h" +#include "module.h" +#include "os_linux.h" #define GK20A_NUM_CDEVS 7 @@ -162,49 +164,50 @@ static int gk20a_create_device( void gk20a_user_deinit(struct device *dev, struct class *class) { struct gk20a *g = gk20a_from_dev(dev); + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); - if (g->channel.node) { - device_destroy(class, g->channel.cdev.dev); - cdev_del(&g->channel.cdev); + if (l->channel.node) { + device_destroy(class, l->channel.cdev.dev); + cdev_del(&l->channel.cdev); } - if (g->as_dev.node) { - device_destroy(class, g->as_dev.cdev.dev); - cdev_del(&g->as_dev.cdev); + if (l->as_dev.node) { + device_destroy(class, l->as_dev.cdev.dev); + cdev_del(&l->as_dev.cdev); } - if (g->ctrl.node) { - device_destroy(class, g->ctrl.cdev.dev); - cdev_del(&g->ctrl.cdev); + if (l->ctrl.node) { + device_destroy(class, l->ctrl.cdev.dev); + cdev_del(&l->ctrl.cdev); } - if (g->dbg.node) { - device_destroy(class, g->dbg.cdev.dev); - cdev_del(&g->dbg.cdev); + if (l->dbg.node) { + device_destroy(class, l->dbg.cdev.dev); + cdev_del(&l->dbg.cdev); } - if (g->prof.node) { - device_destroy(class, g->prof.cdev.dev); - cdev_del(&g->prof.cdev); + if (l->prof.node) { + device_destroy(class, l->prof.cdev.dev); + cdev_del(&l->prof.cdev); } - if (g->tsg.node) { - device_destroy(class, g->tsg.cdev.dev); - cdev_del(&g->tsg.cdev); + if (l->tsg.node) { + device_destroy(class, l->tsg.cdev.dev); + cdev_del(&l->tsg.cdev); } - if (g->ctxsw.node) { - device_destroy(class, g->ctxsw.cdev.dev); - cdev_del(&g->ctxsw.cdev); + if (l->ctxsw.node) { + device_destroy(class, l->ctxsw.cdev.dev); + cdev_del(&l->ctxsw.cdev); } - if (g->sched.node) { - device_destroy(class, g->sched.cdev.dev); - cdev_del(&g->sched.cdev); + if (l->sched.node) { + device_destroy(class, l->sched.cdev.dev); + cdev_del(&l->sched.cdev); } - if (g->cdev_region) - unregister_chrdev_region(g->cdev_region, GK20A_NUM_CDEVS); + if (l->cdev_region) + unregister_chrdev_region(l->cdev_region, GK20A_NUM_CDEVS); } int gk20a_user_init(struct device *dev, const char *interface_name, @@ -213,51 +216,52 @@ int gk20a_user_init(struct device *dev, const char *interface_name, int err; dev_t devno; struct gk20a *g = gk20a_from_dev(dev); + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); err = alloc_chrdev_region(&devno, 0, GK20A_NUM_CDEVS, dev_name(dev)); if (err) { dev_err(dev, "failed to allocate devno\n"); goto fail; } - g->cdev_region = devno; + l->cdev_region = devno; err = gk20a_create_device(dev, devno++, interface_name, "", - &g->channel.cdev, &g->channel.node, + &l->channel.cdev, &l->channel.node, &gk20a_channel_ops, class); if (err) goto fail; err = gk20a_create_device(dev, devno++, interface_name, "-as", - &g->as_dev.cdev, &g->as_dev.node, + &l->as_dev.cdev, &l->as_dev.node, &gk20a_as_ops, class); if (err) goto fail; err = gk20a_create_device(dev, devno++, interface_name, "-ctrl", - &g->ctrl.cdev, &g->ctrl.node, + &l->ctrl.cdev, &l->ctrl.node, &gk20a_ctrl_ops, class); if (err) goto fail; err = gk20a_create_device(dev, devno++, interface_name, "-dbg", - &g->dbg.cdev, &g->dbg.node, + &l->dbg.cdev, &l->dbg.node, &gk20a_dbg_ops, class); if (err) goto fail; err = gk20a_create_device(dev, devno++, interface_name, "-prof", - &g->prof.cdev, &g->prof.node, + &l->prof.cdev, &l->prof.node, &gk20a_prof_ops, class); if (err) goto fail; err = gk20a_create_device(dev, devno++, interface_name, "-tsg", - &g->tsg.cdev, &g->tsg.node, + &l->tsg.cdev, &l->tsg.node, &gk20a_tsg_ops, class); if (err) @@ -265,7 +269,7 @@ int gk20a_user_init(struct device *dev, const char *interface_name, #ifdef CONFIG_GK20A_CTXSW_TRACE err = gk20a_create_device(dev, devno++, interface_name, "-ctxsw", - &g->ctxsw.cdev, &g->ctxsw.node, + &l->ctxsw.cdev, &l->ctxsw.node, &gk20a_ctxsw_ops, class); if (err) @@ -273,7 +277,7 @@ int gk20a_user_init(struct device *dev, const char *interface_name, #endif err = gk20a_create_device(dev, devno++, interface_name, "-sched", - &g->sched.cdev, &g->sched.node, + &l->sched.cdev, &l->sched.node, &gk20a_sched_ops, class); if (err) diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_as.c b/drivers/gpu/nvgpu/common/linux/ioctl_as.c index 1d6410cc..405301ee 100644 --- a/drivers/gpu/nvgpu/common/linux/ioctl_as.c +++ b/drivers/gpu/nvgpu/common/linux/ioctl_as.c @@ -30,6 +30,7 @@ #include "gk20a/platform_gk20a.h" #include "ioctl_as.h" #include "vm_priv.h" +#include "os_linux.h" static int gk20a_as_ioctl_bind_channel( struct gk20a_as_share *as_share, @@ -253,13 +254,15 @@ static int gk20a_as_ioctl_map_buffer_compbits( int gk20a_as_dev_open(struct inode *inode, struct file *filp) { + struct nvgpu_os_linux *l; struct gk20a_as_share *as_share; struct gk20a *g; int err; gk20a_dbg_fn(""); - g = container_of(inode->i_cdev, struct gk20a, as_dev.cdev); + l = container_of(inode->i_cdev, struct nvgpu_os_linux, as_dev.cdev); + g = &l->g; err = gk20a_as_alloc_share(g, 0, 0, &as_share); if (err) { diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_channel.c b/drivers/gpu/nvgpu/common/linux/ioctl_channel.c index 17340e8c..2466db40 100644 --- a/drivers/gpu/nvgpu/common/linux/ioctl_channel.c +++ b/drivers/gpu/nvgpu/common/linux/ioctl_channel.c @@ -33,6 +33,7 @@ #include "gk20a/dbg_gpu_gk20a.h" #include "gk20a/fence_gk20a.h" #include "ioctl_channel.h" +#include "os_linux.h" static void gk20a_channel_trace_sched_param( void (*trace)(int chid, int tsgid, pid_t pid, u32 timeslice, @@ -359,8 +360,9 @@ free_ref: int gk20a_channel_open(struct inode *inode, struct file *filp) { - struct gk20a *g = container_of(inode->i_cdev, - struct gk20a, channel.cdev); + struct nvgpu_os_linux *l = container_of(inode->i_cdev, + struct nvgpu_os_linux, channel.cdev); + struct gk20a *g = &l->g; int ret; gk20a_dbg_fn("start"); @@ -378,6 +380,7 @@ int gk20a_channel_open_ioctl(struct gk20a *g, struct file *file; char name[64]; s32 runlist_id = args->in.runlist_id; + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); err = get_unused_fd_flags(O_RDWR); if (err < 0) @@ -387,7 +390,7 @@ int gk20a_channel_open_ioctl(struct gk20a *g, snprintf(name, sizeof(name), "nvhost-%s-fd%d", dev_name(g->dev), fd); - file = anon_inode_getfile(name, g->channel.cdev.ops, NULL, O_RDWR); + file = anon_inode_getfile(name, l->channel.cdev.ops, NULL, O_RDWR); if (IS_ERR(file)) { err = PTR_ERR(file); goto clean_up; diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c index caf8d309..5c5ac645 100644 --- a/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c +++ b/drivers/gpu/nvgpu/common/linux/ioctl_ctrl.c @@ -31,6 +31,7 @@ #include "gk20a/gk20a.h" #include "gk20a/platform_gk20a.h" #include "gk20a/fence_gk20a.h" +#include "os_linux.h" #include @@ -48,15 +49,16 @@ struct gk20a_ctrl_priv { int gk20a_ctrl_dev_open(struct inode *inode, struct file *filp) { + struct nvgpu_os_linux *l; struct gk20a *g; struct gk20a_ctrl_priv *priv; int err = 0; gk20a_dbg_fn(""); - g = container_of(inode->i_cdev, - struct gk20a, ctrl.cdev); - g = gk20a_get(g); + l = container_of(inode->i_cdev, + struct nvgpu_os_linux, ctrl.cdev); + g = gk20a_get(&l->g); if (!g) return -ENODEV; @@ -199,6 +201,7 @@ static int gk20a_ctrl_alloc_as( struct gk20a *g, struct nvgpu_alloc_as_args *args) { + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); struct gk20a_as_share *as_share; int err; int fd; @@ -212,7 +215,7 @@ static int gk20a_ctrl_alloc_as( snprintf(name, sizeof(name), "nvhost-%s-fd%d", g->name, fd); - file = anon_inode_getfile(name, g->as_dev.cdev.ops, NULL, O_RDWR); + file = anon_inode_getfile(name, l->as_dev.cdev.ops, NULL, O_RDWR); if (IS_ERR(file)) { err = PTR_ERR(file); goto clean_up; @@ -239,6 +242,7 @@ clean_up: static int gk20a_ctrl_open_tsg(struct gk20a *g, struct nvgpu_gpu_open_tsg_args *args) { + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); int err; int fd; struct file *file; @@ -251,7 +255,7 @@ static int gk20a_ctrl_open_tsg(struct gk20a *g, snprintf(name, sizeof(name), "nvgpu-%s-tsg%d", g->name, fd); - file = anon_inode_getfile(name, g->tsg.cdev.ops, NULL, O_RDWR); + file = anon_inode_getfile(name, l->tsg.cdev.ops, NULL, O_RDWR); if (IS_ERR(file)) { err = PTR_ERR(file); goto clean_up; diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c b/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c index 9b722e9e..46bc5f59 100644 --- a/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c +++ b/drivers/gpu/nvgpu/common/linux/ioctl_tsg.c @@ -29,6 +29,7 @@ #include "gk20a/tsg_gk20a.h" #include "ioctl_tsg.h" #include "ioctl_channel.h" +#include "os_linux.h" struct tsg_private { struct gk20a *g; @@ -240,13 +241,13 @@ free_ref: int nvgpu_ioctl_tsg_dev_open(struct inode *inode, struct file *filp) { - struct gk20a *g; + struct nvgpu_os_linux *l; int ret; - g = container_of(inode->i_cdev, - struct gk20a, tsg.cdev); + l = container_of(inode->i_cdev, + struct nvgpu_os_linux, tsg.cdev); gk20a_dbg_fn(""); - ret = nvgpu_ioctl_tsg_open(g, filp); + ret = nvgpu_ioctl_tsg_open(&l->g, filp); gk20a_dbg_fn("done"); return ret; } diff --git a/drivers/gpu/nvgpu/common/linux/module.c b/drivers/gpu/nvgpu/common/linux/module.c index af137c19..bfd2c790 100644 --- a/drivers/gpu/nvgpu/common/linux/module.c +++ b/drivers/gpu/nvgpu/common/linux/module.c @@ -42,6 +42,7 @@ #ifdef CONFIG_TEGRA_19x_GPU #include "nvgpu_gpuid_t19x.h" #endif +#include "os_linux.h" #define CLASS_NAME "nvidia-gpu" /* TODO: Change to e.g. "nvidia-gpu%s" once we have symlinks in place. */ @@ -849,6 +850,7 @@ static inline void set_gk20a(struct platform_device *pdev, struct gk20a *gk20a) static int gk20a_probe(struct platform_device *dev) { + struct nvgpu_os_linux *l; struct gk20a *gk20a; int err; struct gk20a_platform *platform = NULL; @@ -874,12 +876,13 @@ static int gk20a_probe(struct platform_device *dev) if (gk20a_gpu_is_virtual(&dev->dev)) return vgpu_probe(dev); - gk20a = kzalloc(sizeof(struct gk20a), GFP_KERNEL); - if (!gk20a) { + l = kzalloc(sizeof(*l), GFP_KERNEL); + if (!l) { dev_err(&dev->dev, "couldn't allocate gk20a support"); return -ENOMEM; } + gk20a = &l->g; set_gk20a(dev, gk20a); gk20a->dev = &dev->dev; gk20a->log_mask = NVGPU_DEFAULT_DBG_MASK; diff --git a/drivers/gpu/nvgpu/common/linux/module.h b/drivers/gpu/nvgpu/common/linux/module.h index 45fa2f5c..0fde0b41 100644 --- a/drivers/gpu/nvgpu/common/linux/module.h +++ b/drivers/gpu/nvgpu/common/linux/module.h @@ -19,4 +19,6 @@ struct device; int gk20a_pm_finalize_poweron(struct device *dev); void gk20a_remove_support(struct gk20a *g); +extern struct class nvgpu_class; + #endif diff --git a/drivers/gpu/nvgpu/common/linux/os_linux.h b/drivers/gpu/nvgpu/common/linux/os_linux.h new file mode 100644 index 00000000..f23926b3 --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/os_linux.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017, 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 . + */ +#ifndef NVGPU_OS_LINUX_H +#define NVGPU_OS_LINUX_H + +#include + +#include "gk20a/gk20a.h" + +struct nvgpu_os_linux { + struct gk20a g; + + struct { + struct cdev cdev; + struct device *node; + } channel; + + struct { + struct cdev cdev; + struct device *node; + } 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; +}; + +static inline struct nvgpu_os_linux *nvgpu_os_linux_from_gk20a(struct gk20a *g) +{ + return container_of(g, struct nvgpu_os_linux, g); +} + +#define INTERFACE_NAME "nvhost%s-gpu" + +#endif diff --git a/drivers/gpu/nvgpu/common/linux/pci.c b/drivers/gpu/nvgpu/common/linux/pci.c index 94ef340d..cb315973 100644 --- a/drivers/gpu/nvgpu/common/linux/pci.c +++ b/drivers/gpu/nvgpu/common/linux/pci.c @@ -32,6 +32,8 @@ #include "pci.h" +#include "os_linux.h" + #define PCI_INTERFACE_NAME "card-%s%%s" static int nvgpu_pci_tegra_probe(struct device *dev) @@ -346,6 +348,7 @@ static int nvgpu_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pent) { struct gk20a_platform *platform = NULL; + struct nvgpu_os_linux *l; struct gk20a *g; int err; char nodefmt[64]; @@ -359,12 +362,14 @@ static int nvgpu_pci_probe(struct pci_dev *pdev, platform = &nvgpu_pci_device[pent->driver_data]; pci_set_drvdata(pdev, platform); - g = kzalloc(sizeof(struct gk20a), GFP_KERNEL); - if (!g) { - nvgpu_err(g, "couldn't allocate gk20a support"); + l = kzalloc(sizeof(*l), GFP_KERNEL); + if (!l) { + dev_err(&pdev->dev, "couldn't allocate gk20a support"); return -ENOMEM; } + g = &l->g; + nvgpu_kmem_init(g); err = nvgpu_init_enabled_flags(g); -- cgit v1.2.2