diff options
Diffstat (limited to 'nvdebug_linux.h')
-rw-r--r-- | nvdebug_linux.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/nvdebug_linux.h b/nvdebug_linux.h new file mode 100644 index 0000000..022d1cf --- /dev/null +++ b/nvdebug_linux.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /* Copyright 2024 Joshua Bakita | ||
2 | * SPDX-License-Identifier: MIT | ||
3 | * | ||
4 | * Helpers which are kernel-specific | ||
5 | */ | ||
6 | #include "nvdebug.h" | ||
7 | |||
8 | #include <linux/device.h> // For dev_get_drvdata() | ||
9 | #include <linux/seq_file.h> // For struct seq_file | ||
10 | #include <linux/proc_fs.h> // For pde_data() macro | ||
11 | #include <linux/version.h> // For KERNEL_VERSION and LINUX_VERSION_CODE | ||
12 | |||
13 | static inline struct gk20a *get_gk20a(struct device *dev) { | ||
14 | // Only works because gk20a* is the first member of gk20a_platform | ||
15 | return *((struct gk20a**)dev_get_drvdata(dev)); | ||
16 | } | ||
17 | |||
18 | // PDE_DATA was Renamed to pde_data in Linux 5.17 to deconflict with a driver | ||
19 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,17,0) | ||
20 | #define pde_data PDE_DATA | ||
21 | #endif | ||
22 | |||
23 | // We us the data field of the proc_dir_entry ("PDE" in this function) to store | ||
24 | // our index into the g_nvdebug_state array | ||
25 | static inline int seq2gpuidx(struct seq_file *s) { | ||
26 | const struct file *f = s->file; | ||
27 | return (uintptr_t)pde_data(file_inode(f)); | ||
28 | } | ||
29 | static inline int file2gpuidx(const struct file *f) { | ||
30 | return (uintptr_t)pde_data(file_inode(f)); | ||
31 | } | ||
32 | static inline int file2parentgpuidx(const struct file *f) { | ||
33 | // Should be safe to call on ProcFS entries, as our parent should (?) | ||
34 | // still exist if we're called. If not, there are worse races in this | ||
35 | // module. | ||
36 | return (uintptr_t)pde_data(file_dentry(f)->d_parent->d_inode); | ||
37 | } | ||
38 | |||
39 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) | ||
40 | // Commit 643eb158a3 in nvgpu moved the mapped registers to the second entry | ||
41 | // of the gk20a struct (after a function pointer). This change was made as L4T | ||
42 | // was upgraded from Linux 4.9 to 5.10 (r32 -> r34+) | ||
43 | // Note that this is wrong if nvgpu was built without CONFIG_NVGPU_NON_FUSA | ||
44 | // i.e. if FUSA was enabled, this is wrong. | ||
45 | #define gk20a_regs(gk20a) (*(void**)((void*)gk20a + sizeof(void(*)(void)))) | ||
46 | #else | ||
47 | #include <os/linux/os_linux.h> // For struct nvgpu_os_linux, which holds regs | ||
48 | #define gk20a_regs(gk20a) (container_of(gk20a, struct nvgpu_os_linux, g)->regs) | ||
49 | #endif | ||