[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250904040828.319452-7-ankita@nvidia.com>
Date: Thu, 4 Sep 2025 04:08:20 +0000
From: <ankita@...dia.com>
To: <ankita@...dia.com>, <jgg@...dia.com>, <alex.williamson@...hat.com>,
<yishaih@...dia.com>, <skolothumtho@...dia.com>, <kevin.tian@...el.com>,
<yi.l.liu@...el.com>, <zhiw@...dia.com>
CC: <aniketa@...dia.com>, <cjia@...dia.com>, <kwankhede@...dia.com>,
<targupta@...dia.com>, <vsethi@...dia.com>, <acurrid@...dia.com>,
<apopple@...dia.com>, <jhubbard@...dia.com>, <danw@...dia.com>,
<anuaggarwal@...dia.com>, <mochs@...dia.com>, <kjaju@...dia.com>,
<dnigam@...dia.com>, <kvm@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [RFC 06/14] vfio/nvgrace-egm: Introduce egm class and register char device numbers
From: Ankit Agrawal <ankita@...dia.com>
The EGM regions are exposed to the userspace as char devices. A unique
char device with a different minor number is assigned to EGM region
belonging to a different Grace socket.
Add a new egm class and register a range of char device numbers for
the same.
Setting MAX_EGM_NODES as 4 as the 4-socket is the largest configuration
on Grace based systems.
Suggested-by: Aniket Agashe <aniketa@...dia.com>
Signed-off-by: Ankit Agrawal <ankita@...dia.com>
---
drivers/vfio/pci/nvgrace-gpu/egm.c | 36 ++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/drivers/vfio/pci/nvgrace-gpu/egm.c b/drivers/vfio/pci/nvgrace-gpu/egm.c
index 999808807019..6bab4d94cb99 100644
--- a/drivers/vfio/pci/nvgrace-gpu/egm.c
+++ b/drivers/vfio/pci/nvgrace-gpu/egm.c
@@ -4,14 +4,50 @@
*/
#include <linux/vfio_pci_core.h>
+#include <linux/nvgrace-egm.h>
+
+#define MAX_EGM_NODES 4
+
+static dev_t dev;
+static struct class *class;
+
+static char *egm_devnode(const struct device *device, umode_t *mode)
+{
+ if (mode)
+ *mode = 0600;
+
+ return NULL;
+}
static int __init nvgrace_egm_init(void)
{
+ int ret;
+
+ /*
+ * Each EGM region on a system is represented with a unique
+ * char device with a different minor number. Allow a range
+ * of char device creation.
+ */
+ ret = alloc_chrdev_region(&dev, 0, MAX_EGM_NODES,
+ NVGRACE_EGM_DEV_NAME);
+ if (ret < 0)
+ return ret;
+
+ class = class_create(NVGRACE_EGM_DEV_NAME);
+ if (IS_ERR(class)) {
+ unregister_chrdev_region(dev, MAX_EGM_NODES);
+ return PTR_ERR(class);
+ }
+
+ class->devnode = egm_devnode;
+
return 0;
}
static void __exit nvgrace_egm_cleanup(void)
{
+ class_destroy(class);
+ unregister_chrdev_region(dev, MAX_EGM_NODES);
}
module_init(nvgrace_egm_init);
--
2.34.1
Powered by blists - more mailing lists