gpu: nvgpu: track cdev minor numbers

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ä <kholtta@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2651163
Reviewed-by: svcacv <svcacv@nvidia.com>
Reviewed-by: Alex Waterman <alexw@nvidia.com>
GVS: Gerrit_Virtual_Submit
This commit is contained in:
Konsta Hölttä
2022-02-23 12:09:34 +02:00
committed by mobile promotions
parent 79b37d7832
commit 82df5b0219
3 changed files with 14 additions and 2 deletions

View File

@@ -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);