From 82df5b0219bf77ce880adb9b18e4b0966f8cf616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konsta=20H=C3=B6ltt=C3=A4?= Date: Wed, 23 Feb 2022 12:09:34 +0200 Subject: [PATCH] gpu: nvgpu: track cdev minor numbers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing Linux character device nodes are statically configured once. For other dynamically created devices, track the next minor number in nvgpu_os_linux as a rudimentary allocator. Only a small number of increments are expected at this time; in the future, a bitmap might be more appropriate for tracking out-of-order deallocations too. Jira NVGPU-6788 Change-Id: I016ee8471313086620f9ab371583d6763848b0e2 Signed-off-by: Konsta Hölttä Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2651163 Reviewed-by: svcacv Reviewed-by: Alex Waterman GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/os/linux/ioctl.c | 10 ++++++++++ drivers/gpu/nvgpu/os/linux/ioctl.h | 3 ++- drivers/gpu/nvgpu/os/linux/os_linux.h | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/ioctl.c b/drivers/gpu/nvgpu/os/linux/ioctl.c index cf52de071..02b0b08de 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl.c @@ -667,6 +667,7 @@ int gk20a_user_nodes_init(struct device *dev) goto fail; } l->cdev_region = devno; + atomic_set(&l->next_cdev_minor, MINOR(devno) + total_cdevs); nvgpu_list_for_each_entry(class, &l->class_list_head, nvgpu_class, list_entry) { if (!check_valid_class(g, class)) { @@ -711,6 +712,15 @@ fail: return err; } +unsigned int nvgpu_allocate_cdev_minor(struct gk20a *g) +{ + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); + unsigned int next = (unsigned int)atomic_add_return(1, &l->next_cdev_minor); + + WARN_ON(next >= MINOR(UINT_MAX)); + return next; +} + struct gk20a *nvgpu_get_gk20a_from_cdev(struct nvgpu_cdev *cdev) { return get_gk20a(cdev->node->parent); diff --git a/drivers/gpu/nvgpu/os/linux/ioctl.h b/drivers/gpu/nvgpu/os/linux/ioctl.h index 89b0b6a73..9805a7d8d 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl.h +++ b/drivers/gpu/nvgpu/os/linux/ioctl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2022, 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, @@ -71,6 +71,7 @@ int gk20a_power_node_init(struct device *dev); void gk20a_user_nodes_deinit(struct device *dev); void gk20a_power_node_deinit(struct device *dev); +unsigned int nvgpu_allocate_cdev_minor(struct gk20a *g); 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); diff --git a/drivers/gpu/nvgpu/os/linux/os_linux.h b/drivers/gpu/nvgpu/os/linux/os_linux.h index a7ef5319b..a57b39930 100644 --- a/drivers/gpu/nvgpu/os/linux/os_linux.h +++ b/drivers/gpu/nvgpu/os/linux/os_linux.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2021, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2022, 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, @@ -87,6 +87,7 @@ struct nvgpu_os_linux { dev_t power_cdev_region; dev_t cdev_region; + atomic_t next_cdev_minor; /* see gk20a_ctrl_priv */ struct nvgpu_list_node ctrl_privs;