From bfb4dcf0e78954c0163f3a06a5a088c4d1b437a8 Mon Sep 17 00:00:00 2001 From: Benjamin Hadad IV Date: Thu, 13 Jul 2023 12:13:17 -0400 Subject: This commit is to update the repo for display during a meeting. - Added an Ampere version of the device info data. - Added Ampere versions of auxillary functions. - Modified display functions to accommodate Ampere data. - Made other various small modifications. --- nvdebug_entry.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'nvdebug_entry.c') diff --git a/nvdebug_entry.c b/nvdebug_entry.c index 8e8266c..d82c648 100644 --- a/nvdebug_entry.c +++ b/nvdebug_entry.c @@ -23,12 +23,14 @@ extern struct file_operations preempt_tsg_file_ops; extern struct file_operations disable_channel_file_ops; extern struct file_operations enable_channel_file_ops; extern struct file_operations switch_to_tsg_file_ops; -extern struct file_operations device_info_file_ops; +extern struct file_operations device_info_file_ops_previous; +extern struct file_operations device_info_file_ops_ampere; extern struct file_operations nvdebug_read_reg32_file_ops; // Bus types are global symbols in the kernel extern struct bus_type platform_bus_type; struct nvdebug_state g_nvdebug_state[NVDEBUG_MAX_DEVICES]; +int g_architectures[NVDEBUG_MAX_DEVICES]; unsigned int g_nvdebug_devices = 0; // Starting in Kernel 5.6, proc_ops is required instead of file_operations @@ -123,6 +125,7 @@ int probe_and_cache_device(void) { return -EADDRNOTAVAIL; } g_nvdebug_state[i].chip_id = ids.chip_id; + g_architectures[i] = ids.architecture; printk(KERN_INFO "[nvdebug] Chip ID %x (architecture %s) detected on PCI bus and initialized.", ids.chip_id, ARCH2NAME(ids.architecture)); // TEMP @@ -138,7 +141,7 @@ int probe_and_cache_device(void) { } // Create files `/proc/gpu#/runlist#`, world readable -int create_runlist_files(int device_id, struct proc_dir_entry *dir) { +int create_runlist_files_previous(int device_id, struct proc_dir_entry *dir) { ptop_device_info_t info; struct proc_dir_entry *rl_entry; int i, rl_id; @@ -148,7 +151,7 @@ int create_runlist_files(int device_id, struct proc_dir_entry *dir) { // registers. Runlists are always numbered sequentially, so we just have // to find the highest-valued one and add 1 to get the number of runlists. for (i = 0; i < NV_PTOP_DEVICE_INFO__SIZE_1; i++) { - info.raw = nvdebug_readl(&g_nvdebug_state[device_id], NV_PTOP_DEVICE_INFO(i)); + info.raw = nvdebug_readl(&g_nvdebug_state[device_id], NV_PTOP_DEVICE_INFO_PREVIOUS(i)); if (info.info_type != INFO_TYPE_ENUM || !info.runlist_is_valid) continue; if (info.runlist_enum > max_rl_id) @@ -167,6 +170,34 @@ int create_runlist_files(int device_id, struct proc_dir_entry *dir) { return 0; } +// Create files `/proc/gpu#/runlist#`, world readable +int create_runlist_files_ampere(int device_id, struct proc_dir_entry *dir) { + ptop_device_info_t info; + struct proc_dir_entry *rl_entry; + int i, rl_id; + char runlist_name[12]; + int max_rl_id = 0; // Always at least one runlist + // Figure out how many runlists there are by checking the device info + // registers. Runlists are always numbered sequentially, so we just have + // to find the highest-valued one and add 1 to get the number of runlists. + for (i = 0; i < (nvdebug_readl(&g_nvdebug_state[device_id], 0x0224fc) >> 20); i++) { + info.raw = nvdebug_readl(&g_nvdebug_state[device_id], NV_PTOP_DEVICE_INFO_AMPERE(i)); + if (info.runlist_enum_ampere > max_rl_id) + max_rl_id = info.runlist_enum; + } + // Create files to read each runlist. The read handling code looks at the + // PDE_DATA associated with the file to determine what the runlist ID is. + for (rl_id = 0; rl_id <= max_rl_id; rl_id++) { + snprintf(runlist_name, 12, "runlist%d", rl_id); + rl_entry = proc_create_data( + runlist_name, 0444, dir, compat_ops(&runlist_file_ops), + (void*)(uintptr_t)rl_id); + if (!rl_entry) + return -ENOMEM; + } + return 0; +} + // Create files /proc/gpu# // TODO: Don't run this on unsupported GPUs int create_tpc_mask_files(int device_id, struct proc_dir_entry *dir) { @@ -212,7 +243,7 @@ int __init nvdebug_init(void) { if (!(dir = proc_mkdir_data(device_id_str, 0555, NULL, (void*)device_id))) goto out_nomem; // Create files `/proc/gpu#/runlist#`, world readable - rl_create_err = create_runlist_files(device_id, dir); + rl_create_err = g_architectures[device_id] == 0x17 ? create_runlist_files_ampere(device_id, dir) : create_runlist_files_previous(device_id, dir); // Create files `/proc/gpu#/gpc#_tpc_mask`, world readable tpc_masks_create_err = create_tpc_mask_files(device_id, dir); // Create file `/proc/gpu#/preempt_tsg`, world writable @@ -233,7 +264,7 @@ int __init nvdebug_init(void) { (void*)device_id); // Create file `/proc/gpu#/device_info`, world readable device_info_entry = proc_create_data( - "device_info", 0444, dir, compat_ops(&device_info_file_ops), + "device_info", 0444, dir, compat_ops(g_architectures[device_id] == 0x17 ? &device_info_file_ops_previous : &device_info_file_ops_ampere), (void*)device_id); // Create file `/proc/gpu#/num_gpcs`, world readable num_gpcs_entry = proc_create_data( -- cgit v1.2.2