aboutsummaryrefslogtreecommitdiffstats
path: root/nvdebug.h
diff options
context:
space:
mode:
Diffstat (limited to 'nvdebug.h')
-rw-r--r--nvdebug.h118
1 files changed, 20 insertions, 98 deletions
diff --git a/nvdebug.h b/nvdebug.h
index eff1470..ff35f70 100644
--- a/nvdebug.h
+++ b/nvdebug.h
@@ -7,13 +7,11 @@
7 * - Detailed GPU information (PTOP, FUSE, and CE) 7 * - Detailed GPU information (PTOP, FUSE, and CE)
8 * - PRAMIN, BAR1/2, and page table status 8 * - PRAMIN, BAR1/2, and page table status
9 * - Helper functions for nvdebug 9 * - Helper functions for nvdebug
10 *
11 * This function should not depend on any Linux-internal headers, and may be
12 * included outside of nvdebug.
10 */ 13 */
11 14#include <linux/types.h>
12#include <linux/device.h> // For dev_get_drvdata()
13#include <linux/seq_file.h> // For struct seq_file
14#include <linux/proc_fs.h> // For PDE_DATA() macro
15#include <linux/version.h> // For KERNEL_VERSION and LINUX_VERSION_CODE
16#include <asm/io.h>
17 15
18// Fully defined in include/nvgpu/gk20a.h. We only pass around pointers to 16// Fully defined in include/nvgpu/gk20a.h. We only pass around pointers to
19// this, so declare as incomplete type to avoid pulling in the nvgpu headers. 17// this, so declare as incomplete type to avoid pulling in the nvgpu headers.
@@ -1147,8 +1145,11 @@ typedef union {
1147} page_tbl_entry_v0_t; 1145} page_tbl_entry_v0_t;
1148*/ 1146*/
1149 1147
1150// TODO(jbakita): Maybe put the above GPU types in a different file.
1151 1148
1149
1150/* Begin nvdebug types and functions */
1151
1152// Vendor ID for PCI devices manufactured by NVIDIA
1152#define NV_PCI_VENDOR 0x10de 1153#define NV_PCI_VENDOR 0x10de
1153struct nvdebug_state { 1154struct nvdebug_state {
1154 // Pointer to the mapped base address of the GPU control registers (obtained 1155 // Pointer to the mapped base address of the GPU control registers (obtained
@@ -1195,7 +1196,6 @@ struct nvdebug_state {
1195 const struct gk110_runlist_ ## _ENTRY_TYPE *entry = (struct gk110_runlist_ ## _ENTRY_TYPE*)raw; \ 1196 const struct gk110_runlist_ ## _ENTRY_TYPE *entry = (struct gk110_runlist_ ## _ENTRY_TYPE*)raw; \
1196 return entry->prop; \ 1197 return entry->prop; \
1197 } else { \ 1198 } else { \
1198 printk(KERN_WARNING "[nvdebug] " #prop " unavailable on GPU ID %x, which is older than Kepler.\n", g->chip_id); \
1199 return (type)0; \ 1199 return (type)0; \
1200 } \ 1200 } \
1201 } 1201 }
@@ -1250,96 +1250,18 @@ uint64_t search_v1_page_directory(
1250 struct nvdebug_state *g, 1250 struct nvdebug_state *g,
1251 page_dir_config_t pd_config, 1251 page_dir_config_t pd_config,
1252 uint64_t addr_to_find); 1252 uint64_t addr_to_find);
1253
1254
1255static inline struct gk20a *get_gk20a(struct device *dev) {
1256 // XXX: Only works because gk20a* is the first member of gk20a_platform
1257 return *((struct gk20a**)dev_get_drvdata(dev));
1258}
1259
1260// We us the data field of the proc_dir_entry ("PDE" in this function) to store
1261// our index into the g_nvdebug_state array
1262static inline int seq2gpuidx(struct seq_file *s) {
1263 const struct file *f = s->file;
1264 return (uintptr_t)PDE_DATA(file_inode(f));
1265}
1266static inline int file2gpuidx(const struct file *f) {
1267 return (uintptr_t)PDE_DATA(file_inode(f));
1268}
1269static inline int file2parentgpuidx(const struct file *f) {
1270 // Should be safe to call on ProcFS entries, as our parent should (?)
1271 // still exist if we're called. If not, there are worse races in this
1272 // module.
1273 return (uintptr_t)PDE_DATA(file_dentry(f)->d_parent->d_inode);
1274}
1275
1276#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0)
1277// Commit 643eb158a3 in nvgpu moved the mapped registers to the second entry
1278// of the gk20a struct (after a function pointer). This change was made as L4T
1279// was upgraded from Linux 4.9 to 5.10 (r32 -> r34+)
1280// Note that this is wrong if nvgpu was built without CONFIG_NVGPU_NON_FUSA
1281// i.e. if FUSA was enabled, this is wrong.
1282#define gk20a_regs(gk20a) (*(void**)((void*)gk20a + sizeof(void(*)(void))))
1283#else
1284#include <os/linux/os_linux.h> // For struct nvgpu_os_linux, which holds regs
1285#define gk20a_regs(gk20a) (container_of(gk20a, struct nvgpu_os_linux, g)->regs)
1286#endif
1287
1288// Similar to nvgpu_readl()
1289// (except we don't try to resolve situations where regs is NULL)
1290static inline u32 nvdebug_readl(struct nvdebug_state *s, u32 r) {
1291 u32 ret;
1292 if (unlikely(!s->regs || (s->g && !gk20a_regs(s->g)))) {
1293 printk(KERN_ERR "[nvdebug] nvdebug_readl: Unable to read; registers unavailable. Is GPU on?\n");
1294 return -1;
1295 }
1296 ret = readl(s->regs + r);
1297 // It seems like the GPU returns this as a flag value for bad addresses
1298 if (ret == 0xbadf5040) {
1299 printk(KERN_ERR "[nvdebug] nvdebug_readl: Unable to read from register offset %#x; bad data\n", r);
1300 return -1;
1301 }
1302 return ret;
1303}
1304
1305// quadword version of nvdebug_readl()
1306static inline u64 nvdebug_readq(struct nvdebug_state *s, u32 r) {
1307 u64 ret;
1308 if (unlikely(!s->regs || (s->g && !gk20a_regs(s->g)))) {
1309 printk(KERN_ERR "[nvdebug] nvdebug_readq: Unable to read; registers unavailable. Is GPU on?\n");
1310 return -1;
1311 }
1312 // readq seems to always return the uppermost 32 bits as 0, so workaround with readl
1313 ret = readl(s->regs + r);
1314 ret |= ((u64)readl(s->regs + r + 4)) << 32;
1315 // It seems like the GPU returns this as a flag value for bad addresses
1316 if ((ret & 0xffffffffull) == 0xbadf5040ull) {
1317 printk(KERN_ERR "[nvdebug] nvdebug_readq: Unable to read from register offset %#x; bad data\n", r);
1318 return -1;
1319 }
1320 return ret;
1321}
1322
1323// Similar to nvgpu_writel()
1324static inline void nvdebug_writel(struct nvdebug_state *s, u32 r, u32 v) {
1325 if (unlikely(!s->regs || (s->g && !gk20a_regs(s->g)))) {
1326 printk(KERN_ERR "[nvdebug] nvdebug_writel: Unable to write; registers unavailable. Is GPU on?\n");
1327 return;
1328 }
1329 writel_relaxed(v, s->regs + r);
1330 wmb();
1331}
1332
1333// quadword version of nvdebug_writel()
1334// XXX: This probably doesn't work XXX: Untested
1335static inline void nvdebug_writeq(struct nvdebug_state *s, u32 r, u64 v) {
1336 if (unlikely(!s->regs || (s->g && !gk20a_regs(s->g)))) {
1337 printk(KERN_ERR "[nvdebug] nvdebug_writeq: Unable to write; registers unavailable. Is GPU on?\n");
1338 return;
1339 }
1340 writeq_relaxed(v, s->regs + r);
1341 wmb();
1342}
1343// Defined in bus.c 1253// Defined in bus.c
1344int addr_to_pramin_mut(struct nvdebug_state *g, uint64_t addr, enum INST_TARGET target); 1254int addr_to_pramin_mut(struct nvdebug_state *g, uint64_t addr, enum INST_TARGET target);
1345int get_bar2_pdb(struct nvdebug_state *g, page_dir_config_t* pd); 1255int get_bar2_pdb(struct nvdebug_state *g, page_dir_config_t* pd);
1256
1257// Some portions of nvdebug can be included from kernel- or user-space (just
1258// this file at present). In order for these compiled object files to be
1259// usable in either setting, the appropriate version of the following functions
1260// must be selected at link-time. Unfortunately, this precludes inlining (as
1261// the implementation of an inline function must be known at compile time)
1262// Implementations of these functions are provided for kernel-space by
1263// nvdebug_linux.c.
1264uint32_t nvdebug_readl(struct nvdebug_state *s, uint32_t r);
1265uint64_t nvdebug_readq(struct nvdebug_state *s, uint32_t r);
1266void nvdebug_writel(struct nvdebug_state *s, uint32_t r, uint32_t v);
1267void nvdebug_writeq(struct nvdebug_state *s, uint32_t r, uint64_t v);