From 6c8c5c70a885395afae4e7dd49d6abd9c470bc9e Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Sat, 13 Apr 2024 14:19:10 -0400 Subject: Add /proc/gpu#/local_memory API for getting VRAM size --- device_info_procfs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'device_info_procfs.c') diff --git a/device_info_procfs.c b/device_info_procfs.c index 8fe9709..c8903fc 100644 --- a/device_info_procfs.c +++ b/device_info_procfs.c @@ -61,6 +61,30 @@ struct file_operations nvdebug_read_reg_range_file_ops = { .llseek = default_llseek, }; +static ssize_t local_memory_read(struct file *f, char __user *buf, size_t size, loff_t *off) { + struct nvdebug_state *g = &g_nvdebug_state[file2parentgpuidx(f)]; + char out[30]; + int chars_written; + memory_range_t mem_range; + if (size < 30 || *off != 0) + return 0; + mem_range.raw = nvdebug_readl(g, NV_FB_MMU_LOCAL_MEMORY_RANGE); + if (mem_range.raw == -1) + return -EIO; + // 64-bit size has at most 19 characters + 8 for text and termination + chars_written = scnprintf(out, 30, "%lld bytes\n", memory_range_to_bytes(mem_range)); + if (copy_to_user(buf, out, chars_written)) + printk(KERN_WARNING "Unable to copy all data for %s\n", file_dentry(f)->d_name.name); + *off += chars_written; + return chars_written; +} + +// Read out size of on-device VRAM +struct file_operations local_memory_file_ops = { + .read = local_memory_read, + .llseek = default_llseek, +}; + typedef struct { int idx; // Current index in the device_info table int length; // Length of device_info table (including unpopulated entries) -- cgit v1.2.2