From beed6d3c2b51f472ce3f3de120e841d8ceceeb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konsta=20H=C3=B6ltt=C3=A4?= Date: Wed, 23 Feb 2022 12:10:08 +0200 Subject: [PATCH] gpu: nvgpu: add nvgpu_get_v2_user_class() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a function to find the nvgpu_class of the v2 user device nodes. This is the last entry in the class list, as the devices are created in that order. The v2 user class is not defined when MIG is enabled because there are multiple logical devices; bigger changes would be needed for this. Jira NVGPU-6788 Change-Id: I2177c1e5b4d0bbec77a4e258391859242b4f20d6 Signed-off-by: Konsta Hölttä Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2674427 Reviewed-by: svcacv Reviewed-by: Alex Waterman GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/os/linux/ioctl.c | 19 +++++++++++++++++++ drivers/gpu/nvgpu/os/linux/ioctl.h | 1 + 2 files changed, 20 insertions(+) diff --git a/drivers/gpu/nvgpu/os/linux/ioctl.c b/drivers/gpu/nvgpu/os/linux/ioctl.c index adb8602d6..5539d835c 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl.c @@ -511,6 +511,8 @@ static int nvgpu_prepare_default_dev_node_class_list(struct gk20a *g, * V2 device node names hierarchy. * This hierarchy will replace above hierarchy in second phase. * Both legacy and V2 device node hierarchies will co-exist until then. + * + * Note: nvgpu_get_v2_user_class() assumes this order in the class list. */ if (g->pci_class != 0U) { if (power_node) { @@ -546,6 +548,23 @@ static int nvgpu_prepare_default_dev_node_class_list(struct gk20a *g, return 0; } +struct nvgpu_class *nvgpu_get_v2_user_class(struct gk20a *g) +{ + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); + struct nvgpu_class *class; + + if (nvgpu_grmgr_is_multi_gr_enabled(g)) { + /* Ambiguous with multiple fractional GPUs */ + return NULL; + } + + nvgpu_assert(!nvgpu_list_empty(&l->class_list_head)); + /* this must match nvgpu_prepare_default_dev_node_class_list() */ + class = nvgpu_list_last_entry(&l->class_list_head, nvgpu_class, list_entry); + nvgpu_assert(!class->power_node); + return class; +} + static int nvgpu_prepare_dev_node_class_list(struct gk20a *g, u32 *num_classes, bool power_node) { diff --git a/drivers/gpu/nvgpu/os/linux/ioctl.h b/drivers/gpu/nvgpu/os/linux/ioctl.h index b39d84b50..2e230eea7 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl.h +++ b/drivers/gpu/nvgpu/os/linux/ioctl.h @@ -80,5 +80,6 @@ int nvgpu_create_device( const char *cdev_name, struct cdev *cdev, struct device **out, struct nvgpu_class *class); +struct nvgpu_class *nvgpu_get_v2_user_class(struct gk20a *g); #endif