From: Ankit Agrawal 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 Signed-off-by: Ankit Agrawal --- 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 +#include + +#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