diff options
| author | Joshua Bakita <bakitajoshua@gmail.com> | 2023-06-28 18:24:25 -0400 |
|---|---|---|
| committer | Joshua Bakita <bakitajoshua@gmail.com> | 2023-06-28 18:24:25 -0400 |
| commit | 01e6fac4d61fdd7fff5433942ec93fc2ea1e4df1 (patch) | |
| tree | 4ef34501728a087be24f4ba0af90f91486bf780b /include/os/linux/debug_hal.c | |
| parent | 306a03d18b305e4e573be3b2931978fa10679eb9 (diff) | |
Include nvgpu headers
These are needed to build on NVIDIA's Jetson boards for the time
being. Only a couple structs are required, so it should be fairly
easy to remove this dependency at some point in the future.
Diffstat (limited to 'include/os/linux/debug_hal.c')
| -rw-r--r-- | include/os/linux/debug_hal.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/include/os/linux/debug_hal.c b/include/os/linux/debug_hal.c new file mode 100644 index 0000000..031e335 --- /dev/null +++ b/include/os/linux/debug_hal.c | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2017 NVIDIA Corporation. All rights reserved. | ||
| 3 | * | ||
| 4 | * This software is licensed under the terms of the GNU General Public | ||
| 5 | * License version 2, as published by the Free Software Foundation, and | ||
| 6 | * may be copied, distributed, and modified under those terms. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include "debug_hal.h" | ||
| 16 | #include "os_linux.h" | ||
| 17 | |||
| 18 | #include <linux/debugfs.h> | ||
| 19 | #include <linux/seq_file.h> | ||
| 20 | |||
| 21 | /* Format and print a single function pointer to the specified seq_file. */ | ||
| 22 | static void __hal_print_op(struct seq_file *s, void *op_ptr) | ||
| 23 | { | ||
| 24 | seq_printf(s, "%pF\n", op_ptr); | ||
| 25 | } | ||
| 26 | |||
| 27 | /* | ||
| 28 | * Prints an array of function pointer addresses in op_ptrs to the | ||
| 29 | * specified seq_file | ||
| 30 | */ | ||
| 31 | static void __hal_print_ops(struct seq_file *s, void **op_ptrs, int num_ops) | ||
| 32 | { | ||
| 33 | int i; | ||
| 34 | |||
| 35 | for (i = 0; i < num_ops; i++) | ||
| 36 | __hal_print_op(s, op_ptrs[i]); | ||
| 37 | } | ||
| 38 | |||
| 39 | /* | ||
| 40 | * Show file operation, which generates content of the file once. Prints a list | ||
| 41 | * of gpu operations as defined by gops and the corresponding function pointer | ||
| 42 | * destination addresses. Relies on no compiler reordering of struct fields and | ||
| 43 | * assumption that all members are function pointers. | ||
| 44 | */ | ||
| 45 | static int __hal_show(struct seq_file *s, void *unused) | ||
| 46 | { | ||
| 47 | struct gpu_ops *gops = s->private; | ||
| 48 | |||
| 49 | __hal_print_ops(s, (void **)gops, sizeof(*gops) / sizeof(void *)); | ||
| 50 | |||
| 51 | return 0; | ||
| 52 | } | ||
| 53 | |||
| 54 | static int __hal_open(struct inode *inode, struct file *file) | ||
| 55 | { | ||
| 56 | return single_open(file, __hal_show, inode->i_private); | ||
| 57 | } | ||
| 58 | |||
| 59 | static const struct file_operations __hal_fops = { | ||
| 60 | .open = __hal_open, | ||
| 61 | .read = seq_read, | ||
| 62 | .llseek = seq_lseek, | ||
| 63 | .release = single_release, | ||
| 64 | }; | ||
| 65 | |||
| 66 | void nvgpu_hal_debugfs_fini(struct gk20a *g) | ||
| 67 | { | ||
| 68 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
| 69 | |||
| 70 | if (!(l->debugfs_hal == NULL)) | ||
| 71 | debugfs_remove_recursive(l->debugfs_hal); | ||
| 72 | } | ||
| 73 | |||
| 74 | void nvgpu_hal_debugfs_init(struct gk20a *g) | ||
| 75 | { | ||
| 76 | struct dentry *d; | ||
| 77 | struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); | ||
| 78 | |||
| 79 | if (!l->debugfs) | ||
| 80 | return; | ||
| 81 | l->debugfs_hal = debugfs_create_dir("hal", l->debugfs); | ||
| 82 | if (IS_ERR_OR_NULL(l->debugfs_hal)) { | ||
| 83 | l->debugfs_hal = NULL; | ||
| 84 | return; | ||
| 85 | } | ||
| 86 | |||
| 87 | /* Pass along reference to the gpu_ops struct as private data */ | ||
| 88 | d = debugfs_create_file("gops", S_IRUGO, l->debugfs_hal, | ||
| 89 | &g->ops, &__hal_fops); | ||
| 90 | if (!d) { | ||
| 91 | nvgpu_err(g, "%s: Failed to make debugfs node\n", __func__); | ||
| 92 | debugfs_remove_recursive(l->debugfs_hal); | ||
| 93 | return; | ||
| 94 | } | ||
| 95 | } | ||
