From: Ankit Agrawal <ankita@xxxxxxxxxx> To allocate the EGM, the userspace need to know its size. Currently, there is no easy way for the userspace to determine that. Make nvgrace-egm expose the size through sysfs that can be queried by the userspace from <aux_dev_path>/egm_size. On a 2-socket, 4 GPU Grace Blackwell setup, it shows up as: Socket0: /sys/devices/pci0008:00/0008:00:00.0/0008:01:00.0/nvgrace_gpu_vfio_pci.egm.4/egm/egm4/egm_size /sys/devices/pci0009:00/0009:00:00.0/0009:01:00.0/nvgrace_gpu_vfio_pci.egm.4/egm/egm4/egm_size Socket1: /sys/devices/pci0018:00/0018:00:00.0/0018:01:00.0/nvgrace_gpu_vfio_pci.egm.5/egm/egm5/egm_size /sys/devices/pci0019:00/0019:00:00.0/0019:01:00.0/nvgrace_gpu_vfio_pci.egm.5/egm/egm5/egm_size Signed-off-by: Ankit Agrawal <ankita@xxxxxxxxxx> --- drivers/vfio/pci/nvgrace-gpu/egm.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/vfio/pci/nvgrace-gpu/egm.c b/drivers/vfio/pci/nvgrace-gpu/egm.c index 2cb100e39c4b..346607eeb0f9 100644 --- a/drivers/vfio/pci/nvgrace-gpu/egm.c +++ b/drivers/vfio/pci/nvgrace-gpu/egm.c @@ -343,6 +343,32 @@ static char *egm_devnode(const struct device *device, umode_t *mode) return NULL; } +static ssize_t egm_size_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct chardev *egm_chardev = container_of(dev, struct chardev, device); + struct nvgrace_egm_dev *egm_dev = + egm_chardev_to_nvgrace_egm_dev(egm_chardev); + + return sysfs_emit(buf, "0x%lx\n", egm_dev->egmlength); +} + +static DEVICE_ATTR_RO(egm_size); + +static struct attribute *attrs[] = { + &dev_attr_egm_size.attr, + NULL, +}; + +static struct attribute_group attr_group = { + .attrs = attrs, +}; + +static const struct attribute_group *attr_groups[2] = { + &attr_group, + NULL +}; + static int __init nvgrace_egm_init(void) { int ret; @@ -364,6 +390,7 @@ static int __init nvgrace_egm_init(void) } class->devnode = egm_devnode; + class->dev_groups = attr_groups; ret = auxiliary_driver_register(&egm_driver); if (!ret) -- 2.34.1